self-evolve-framework 1.0.7 → 1.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.
Files changed (126) hide show
  1. package/README.md +12 -8
  2. package/bin/cli.js +63 -35
  3. package/package.json +1 -1
  4. package/template/rules/CodeGraph.mdc +23 -0
  5. package/template/rules/Svelte_5.mdc +167 -0
  6. package/template/rules/Svelte_Flow.mdc +176 -0
  7. package/template/rules/Tailwind_CSS_v4.mdc +187 -0
  8. package/template/rules/Tauri.mdc +145 -0
  9. package/template/rules/app-error-pattern.mdc +65 -0
  10. package/template/rules/invoke-safe-pattern.mdc +53 -0
  11. package/template/rules/js.mdc +10 -0
  12. package/template/rules/powershell.mdc +9 -0
  13. package/template/rules/self-evolve.mdc +4 -4
  14. package/template/rules//346/227/245/345/277/227.mdc +15 -0
  15. package/template/rules//350/257/267/346/261/202.mdc +49 -0
  16. package/template/skills/caveman/SKILL.md +49 -0
  17. package/template/skills/check/SKILL.md +393 -0
  18. package/template/skills/check/agents/reviewer-architecture.md +39 -0
  19. package/template/skills/check/agents/reviewer-security.md +39 -0
  20. package/template/skills/check/references/persona-catalog.md +56 -0
  21. package/template/skills/check/references/project-context.md +120 -0
  22. package/template/skills/check/references/public-reply.md +14 -0
  23. package/template/skills/check/scripts/audit_signals.py +666 -0
  24. package/template/skills/check/scripts/run-tests.sh +19 -0
  25. package/template/skills/design/SKILL.md +173 -0
  26. package/template/skills/design/references/design-aesthetic-quality.md +67 -0
  27. package/template/skills/design/references/design-data-viz.md +34 -0
  28. package/template/skills/design/references/design-reference.md +295 -0
  29. package/template/skills/design/references/design-tokens.md +45 -0
  30. package/template/skills/design/references/design-traps.md +43 -0
  31. package/template/skills/design-an-interface/SKILL.md +94 -0
  32. package/template/skills/diagnose/SKILL.md +117 -0
  33. package/template/skills/diagnose/scripts/hitl-loop.template.sh +41 -0
  34. package/template/skills/edit-article/SKILL.md +14 -0
  35. package/template/skills/git-guardrails-claude-code/SKILL.md +95 -0
  36. package/template/skills/git-guardrails-claude-code/scripts/block-dangerous-git.sh +25 -0
  37. package/template/skills/grill-me/SKILL.md +10 -0
  38. package/template/skills/grill-with-docs/ADR-FORMAT.md +47 -0
  39. package/template/skills/grill-with-docs/CONTEXT-FORMAT.md +60 -0
  40. package/template/skills/grill-with-docs/SKILL.md +88 -0
  41. package/template/skills/handoff/SKILL.md +15 -0
  42. package/template/skills/health/SKILL.md +260 -0
  43. package/template/skills/health/agents/inspector-context.md +119 -0
  44. package/template/skills/health/agents/inspector-control.md +84 -0
  45. package/template/skills/health/agents/inspector-maintainability.md +55 -0
  46. package/template/skills/health/scripts/check-agent-context.sh +5 -0
  47. package/template/skills/health/scripts/check-doc-refs.sh +8 -0
  48. package/template/skills/health/scripts/check-maintainability.sh +8 -0
  49. package/template/skills/health/scripts/check-verifier-output.sh +5 -0
  50. package/template/skills/health/scripts/check_agent_context.py +444 -0
  51. package/template/skills/health/scripts/check_doc_refs.py +110 -0
  52. package/template/skills/health/scripts/check_maintainability.py +635 -0
  53. package/template/skills/health/scripts/check_verifier_output.py +116 -0
  54. package/template/skills/health/scripts/collect-data.sh +751 -0
  55. package/template/skills/hunt/SKILL.md +232 -0
  56. package/template/skills/hunt/references/failure-patterns.md +138 -0
  57. package/template/skills/hunt/references/ime-unicode.md +58 -0
  58. package/template/skills/hunt/references/logging-techniques.md +72 -0
  59. package/template/skills/hunt/references/rendering-debug.md +34 -0
  60. package/template/skills/impeccable/SKILL.md +47 -0
  61. package/template/skills/improve-codebase-architecture/DEEPENING.md +37 -0
  62. package/template/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  63. package/template/skills/improve-codebase-architecture/INTERFACE-DESIGN.md +44 -0
  64. package/template/skills/improve-codebase-architecture/LANGUAGE.md +53 -0
  65. package/template/skills/improve-codebase-architecture/SKILL.md +81 -0
  66. package/template/skills/learn/SKILL.md +140 -0
  67. package/template/skills/migrate-to-shoehorn/SKILL.md +118 -0
  68. package/template/skills/obsidian-vault/SKILL.md +59 -0
  69. package/template/skills/prototype/LOGIC.md +79 -0
  70. package/template/skills/prototype/SKILL.md +30 -0
  71. package/template/skills/prototype/UI.md +112 -0
  72. package/template/skills/qa/SKILL.md +130 -0
  73. package/template/skills/read/SKILL.md +141 -0
  74. package/template/skills/read/references/read-methods.md +129 -0
  75. package/template/skills/read/scripts/fetch.sh +106 -0
  76. package/template/skills/read/scripts/fetch_feishu.py +251 -0
  77. package/template/skills/read/scripts/fetch_local.py +218 -0
  78. package/template/skills/read/scripts/fetch_weixin.py +107 -0
  79. package/template/skills/request-refactor-plan/SKILL.md +68 -0
  80. package/template/skills/review/SKILL.md +78 -0
  81. package/template/skills/rust-auto-fix/SKILL.md +94 -0
  82. package/template/skills/scaffold-exercises/SKILL.md +106 -0
  83. package/template/skills/sdd-dev/SKILL.md +114 -0
  84. package/template/skills/setup-matt-pocock-skills/SKILL.md +121 -0
  85. package/template/skills/setup-matt-pocock-skills/domain.md +51 -0
  86. package/template/skills/setup-matt-pocock-skills/issue-tracker-github.md +22 -0
  87. package/template/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +23 -0
  88. package/template/skills/setup-matt-pocock-skills/issue-tracker-local.md +19 -0
  89. package/template/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
  90. package/template/skills/setup-pre-commit/SKILL.md +91 -0
  91. package/template/skills/skillopt-sleep/SKILL.md +1 -1
  92. package/template/skills/svelte-warnings-fix/SKILL.md +94 -0
  93. package/template/skills/tauri-nsis-installer-icon/SKILL.md +92 -0
  94. package/template/skills/tauri-nsis-installer-icon/references/tauri-nsis-schema.md +71 -0
  95. package/template/skills/tb/SKILL.md +62 -0
  96. package/template/skills/tdd/SKILL.md +109 -0
  97. package/template/skills/tdd/deep-modules.md +33 -0
  98. package/template/skills/tdd/interface-design.md +31 -0
  99. package/template/skills/tdd/mocking.md +59 -0
  100. package/template/skills/tdd/refactoring.md +10 -0
  101. package/template/skills/tdd/tests.md +61 -0
  102. package/template/skills/teach/GLOSSARY-FORMAT.md +35 -0
  103. package/template/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  104. package/template/skills/teach/MISSION-FORMAT.md +31 -0
  105. package/template/skills/teach/RESOURCES-FORMAT.md +32 -0
  106. package/template/skills/teach/SKILL.md +91 -0
  107. package/template/skills/think/SKILL.md +184 -0
  108. package/template/skills/to-issues/SKILL.md +83 -0
  109. package/template/skills/to-prd/SKILL.md +74 -0
  110. package/template/skills/triage/AGENT-BRIEF.md +168 -0
  111. package/template/skills/triage/OUT-OF-SCOPE.md +101 -0
  112. package/template/skills/triage/SKILL.md +103 -0
  113. package/template/skills/ubiquitous-language/SKILL.md +93 -0
  114. package/template/skills/ver/SKILL.md +62 -0
  115. package/template/skills/write/SKILL.md +209 -0
  116. package/template/skills/write/references/write-en.md +199 -0
  117. package/template/skills/write/references/write-product-localization.md +43 -0
  118. package/template/skills/write/references/write-zh-bilingual.md +59 -0
  119. package/template/skills/write/references/write-zh-prose.md +50 -0
  120. package/template/skills/write/references/write-zh-release-notes.md +40 -0
  121. package/template/skills/write/references/write-zh.md +721 -0
  122. package/template/skills/write-a-skill/SKILL.md +117 -0
  123. package/template/skills/writing-beats/SKILL.md +52 -0
  124. package/template/skills/writing-fragments/SKILL.md +75 -0
  125. package/template/skills/writing-shape/SKILL.md +64 -0
  126. package/template/skills/zoom-out/SKILL.md +7 -0
@@ -0,0 +1,232 @@
1
+ ---
2
+ name: hunt
3
+ description: "Finds root cause before applying fixes for errors, crashes, regressions, failing tests, broken behavior, and screenshot-reported defects. Use when users ask 排查/报错/崩溃/不工作/回归/判断为什么报错, or say something used to work and now fails. Not for code review or new features."
4
+ when_to_use: "排查, 查查, 报错, 崩溃, 不工作, 不对, 跑不通, 以前是好的, 回归, 截图回归, 判断错误原因, 判断为什么报错, 反复修不好, debug, regression, used to work, broke after update, why broken, not working, what's wrong, fix error, stack trace"
5
+ dispatch_intent: "Error, crash, regression, screenshot-reported defect, test failure, stale cache, runtime boundary, why broken"
6
+ ---
7
+
8
+ # Hunt: Diagnose Before You Fix
9
+
10
+ Prefix your first line with 🥷 inline, not as its own paragraph.
11
+
12
+ **Update check (non-blocking).** Before starting, run `bash ../../scripts/check-update.sh` once; if it prints a line, relay it to the user, then continue. It runs at most once a day, only reads a public version file, sends no data, and fails silently.
13
+
14
+ A patch applied to a symptom creates a new bug somewhere else.
15
+
16
+ ## Outcome Contract
17
+
18
+ - Outcome: the root cause is identified before any fix is applied.
19
+ - Done when: one sentence explains the cause, every observed symptom fits it, and the fix or handoff is verified against a reproducible check.
20
+ - Evidence: source trace, repro command or UI path, logs or state, targeted test/build output, and runtime evidence for UI or native defects.
21
+ - Output: root cause, fix or handoff, verification result, and any unswept sibling risks.
22
+
23
+ **Do not touch code until you can state the root cause in one sentence:**
24
+ > "I believe the root cause is [X] because [evidence]."
25
+
26
+ Name a specific file, function, line, or condition. "A state management issue" is not testable. "Stale cache in `useUser` at `src/hooks/user.ts:42` because the dependency array is missing `userId`" is testable. If you cannot be that specific, you do not have a hypothesis yet.
27
+
28
+ ## Diagnosis Signals
29
+
30
+ Good progress: a log line matches the hypothesis, you can predict the next error before running it, you understand the propagation path from root cause to symptom, you can write a test that fails on the old code. At each of these signals, find one more independent piece of evidence before committing.
31
+
32
+ Hypothesis quality gate: before acting on a hypothesis, list all observable symptoms (not just the one the user reported first). The hypothesis must explain every symptom; if it only covers some, it is a symptom-level guess, not a root cause. For timing-dependent issues (flicker, intermittent failure, race condition), reproduce reliably before diagnosing.
33
+
34
+ Rationalization warning: "I'll just try this" means no hypothesis, write it first. "I'm confident" means run an instrument that proves it. "Probably the same issue" means re-read the execution path from scratch. "It works on my machine" means enumerate every env difference before dismissing. "One more restart" means read the last error verbatim; never restart more than twice without new evidence.
35
+
36
+ ## Durable Context Preflight
37
+
38
+ See [rules/durable-context.md](../../rules/durable-context.md) for when to read durable context, the read-order budget, and the memory-type mapping.
39
+
40
+ For `/hunt`, diagnostic constraints are `decision`, `preference`, and `principle` entries; `pattern` and `learning` can seed hypotheses. Current code, logs, repro steps, tests, environment versions, and remote state override memory. Durable context is hypothesis fuel only. It never replaces a fresh root-cause sentence, a reproducible symptom list, or evidence from the current state.
41
+
42
+ ## Hard Rules
43
+
44
+ - **Same symptom after a fix is a hard stop; so is "let me just try this."** Both mean the hypothesis is unfinished. Re-read the execution path from scratch before touching code again.
45
+ - **After three failed hypotheses, stop.** Use the Handoff format below to surface what was checked, what was ruled out, and what is unknown. Ask how to proceed.
46
+ - **Verify before claiming.** Never state versions, function names, or file locations from memory. Run `sw_vers` / `node --version` / grep first. No results = re-examine the path.
47
+ - **External tool failure: diagnose before switching.** When an MCP tool or API fails, determine why first (server running? API key valid? Config correct?) before trying an alternative.
48
+ - **System/tooling symptoms need a lower-layer baseline.** Before blaming the visible app, generated file, or top-level feature, measure the raw lower layer first: OS capture versus post-processing, runtime service versus UI, compiler/toolchain versus test assertion, network/API versus client handling. Retire hypotheses that the baseline disproves instead of circling them.
49
+ - **Pay attention to deflection.** When someone says "that part doesn't matter," treat it as a signal. The area someone avoids examining is often where the problem lives.
50
+ - **Visual/rendering bugs: static analysis first.** Trace paint layers, stacking contexts, and layer order in DevTools before adding console.log or visual debug overlays. Logs cannot capture what the compositor does. Only add instrumentation after static analysis fails.
51
+ - **Behavioral / lifecycle / async bugs: instrument first, not after failure.** Window lifecycle, event delivery, navigation, focus, timer, state-machine, and async-ordering bugs almost never yield to static reading alone. Do not wait for a failed fix to add logs. The moment your hypothesis involves "this callback fires before/after that one", "this state should be X when Y runs", or "this object should still be alive here", **add the log immediately as part of forming the hypothesis**, before writing any fix. A hypothesis without runtime evidence is a guess; two guesses in a row is the hard-stop signal. Distinguish from visual-rendering bugs (compositor behavior needs DevTools, not logs) and pure-logic bugs (wrong formula, off-by-one) where static analysis is sufficient.
52
+ - **Tuning magic numbers past round three: stop, unify.** When a spacing / sizing / threshold value has been adjusted three times and still looks wrong, the bug is structural, not numeric. Replace the N independent values with one named token (`Spacing.s4`, `--gap-content`, etc.) and verify the asymmetry was hiding a missing constraint. Asymmetry that survives tuning is structural; more tuning will not converge.
53
+ - **Fix the cause, not the symptom.** If the fix touches more than 5 files, pause and confirm scope with the user.
54
+
55
+ ## Fix Scope Discipline
56
+
57
+ If the bug genuinely needs a refactor first (e.g. the cause cannot be addressed without changing a shared interface), pause, name the refactor explicitly, and ask. Do not silently bundle it. A bug fix that grew into a refactor is a separate PR.
58
+
59
+ ## Bisect Mode
60
+
61
+ Activate when: "以前是好的", "之前是好的", "used to work", "上一次提交还是对的", "broke after update", or the user remembers a specific good commit or version.
62
+
63
+ 0. Protect the user's worktree first: run `git status --short --branch -uall`. If modified, staged, or untracked files exist, do not bisect in the current checkout. Create a temporary detached worktree from the same HEAD, run bisect there, then `git bisect reset` and remove the temporary worktree when done. If a temporary worktree is impossible, stop and ask for explicit cleanup/stash approval.
64
+ 1. Find candidate good tag: `git tag --sort=-version:refname | head -10` or ask the user for the last known-good commit.
65
+ 1b. If the last-good version is only one or a few releases back, `git diff <last-good-tag>..HEAD -- <suspect path>` and read the delta directly first. The regression is usually visible in that diff, and reading it costs far less than driving a full bisect. Fall through to bisect only when the diff is too large or the culprit is not obvious.
66
+ 2. Define a non-interactive pass/fail test command before starting bisect. Bisect is worthless without a reproducible check.
67
+ 3. Run: `git bisect start && git bisect bad HEAD && git bisect good <tag-or-hash>`
68
+ 4. At each step bisect checks out a commit. Run the test command. Mark: `git bisect good` or `git bisect bad`.
69
+ 5. Let bisect drive. Do not jump ahead or skip commits unless explicitly asked.
70
+ 6. When bisect names the culprit commit, read only that diff. Identify the specific line that introduced the regression.
71
+ 7. Run `git bisect reset` when done.
72
+
73
+ Read large files once and reference from notes rather than re-reading at each bisect step.
74
+
75
+ ## Repeated Regression / Screenshot Reference Mode
76
+
77
+ Activate when the user says the same issue is still wrong after a fix, provides a "good" screenshot/version/file, or describes a visual result as previously correct.
78
+
79
+ Treat the reference as evidence, not decoration:
80
+
81
+ 1. List every reported and visible symptom, preserving the user's concrete words where useful ("still slow", "not clear", "尖刺", "先显示上一个内容").
82
+ 2. Identify the reference oracle: last-good commit/tag, old build, fixture, screenshot, downloaded artifact, or expected state from the user's description.
83
+ 3. Define the pass/fail check before editing. For visual bugs, this may be a narrow screenshot checklist plus the command that renders the view; for behavioral bugs, prefer an automated regression test or deterministic repro.
84
+ 4. Compare current vs. reference and name the exact delta. Do not generalize a visual defect into "style polish" when the evidence points to a broken render, race, font pipeline, or state path.
85
+ 5. If the same symptom remains after one attempted fix, stop and rebuild the hypothesis from the evidence. Do not stack more patches onto a disproven explanation.
86
+
87
+ If the issue is purely subjective UI taste, route to `/design`. If it is rendering, state, timing, build output, font generation, or a regression from a known-good version, stay in `/hunt`.
88
+
89
+ ## Scope Blast Mode
90
+
91
+ Activate after fixing a root-cause pattern, before declaring the bug done; also when the user says "举一反三", "举一反三深入看看", or "其他地方有没有同样问题". The same shape often hides in N other places; one local fix that ignores the blast leaves N - 1 bugs in the tree.
92
+
93
+ 1. Extract the pattern signature: the specific function name, regex, API call, CSS selector, lock acquisition, validation skip, or input boundary that produced the bug.
94
+ 2. `grep -rn <pattern>` across the repo (exclude generated dirs, build output, vendored deps). For class-of-bug patterns (e.g. "any handler missing the lock"), grep for the surrounding shape, not just the literal text.
95
+ 3. List every match. For each one, answer in writing: same bug here? Pick fix / leave (explain why it is safe) / unsure (ask the user). Do not silently skip a match.
96
+ 4. Do not claim "fixed" until the blast report is in the Outcome block.
97
+
98
+ Common triggers:
99
+ - Visual bug fixed on one page: check every other page using the same component, layout, or media-query breakpoint.
100
+ - One race fixed in one handler: check every handler acquiring the same lock or touching the same shared state.
101
+ - One validation skip patched at one entry point: check every entry point that reaches the same downstream sink.
102
+ - One regex / parser fix for one input shape: check every caller of the same regex / parser.
103
+
104
+ If the blast surfaces unrelated bugs, list them but do not fix in this PR unless the user agrees; scope creep is its own anti-pattern.
105
+
106
+ ## Confirm or Discard
107
+
108
+ The instrument-first rule lives in Hard Rules (behavioral/async bugs) above; this is what to do with its result. Run the one probe that would fail if the hypothesis were wrong, then read it. If the evidence contradicts the hypothesis, discard it completely and re-orient on what the probe just showed. Do not stack a fix onto a disproven hypothesis, and do not keep one just because the code "looks like" the cause.
109
+
110
+ ## Runtime Evidence Ladder
111
+
112
+ Use this ladder before claiming a bug is fixed:
113
+
114
+ 1. Source trace: name the exact function, state transition, file, line, or condition that can produce the symptom.
115
+ 2. Deterministic repro: run or write the smallest command, fixture, UI path, or scenario that produces it.
116
+ 3. Logs/state/cache: inspect the runtime state that proves the path was reached, including queues, DB rows, caches, temp files, generated outputs, or external tool logs.
117
+ 4. Build/test: run the narrow test or build that exercises the fix.
118
+ 5. Real runtime check: for UI, native app, browser, rendering, or visual bugs, open the app/page/artifact and verify the visible result with a screenshot or concrete checklist.
119
+
120
+ Compile-only is not enough for UI, native-app, visual, rendering, or generated-artifact bugs. If the runtime check is impossible in the environment, say why and hand off the exact screen, command, or artifact to verify.
121
+
122
+ For recurring classes of failures, load `references/failure-patterns.md` before adding a second fix.
123
+
124
+ ## Native App Freeze Mode
125
+
126
+ Activate when a desktop or mobile native app reports beachball, not responding, tab-switch freeze, first-open lag, idle wake stall, overlay lockup, or a screenshot shows a frozen app.
127
+
128
+ Evidence to collect before changing code:
129
+
130
+ 1. Exact user path and version: first launch versus warm launch, the tab or window transition, idle duration, permissions, display count, and any setting that makes the freeze disappear.
131
+ 2. Runtime capture while frozen: `sample <process>`, recent app logs, CPU and memory footprint, thread count, and whether the main thread is blocked, spinning, or allocating.
132
+ 3. First-frame surface: view body work, first `.task`, synchronous icon or metadata lookup, filesystem scans, URL parent walks, notification callbacks, and app/window wake handlers.
133
+ 4. Blast search after the fix: grep the same API shape across the repo, especially path parent walks, synchronous icon loading, metadata reads in render paths, and callbacks that run on the main thread.
134
+
135
+ Common native freeze traps:
136
+
137
+ - Launch, terminate, permission, audio, display, or workspace notifications doing path walks, icon lookup, filesystem scans, or process enumeration on the main thread.
138
+ - First paint hydrating a full app list, directory tree, media thumbnail set, or system status table before showing an interactive shell.
139
+ - An input-lock or full-screen overlay without a guaranteed teardown path for Escape, app deactivation, permission denial, process termination, and window close.
140
+ - Timer or sampler work that survives hidden windows, long idle periods, sleep/wake, or app reactivation.
141
+
142
+ Compile-only and source-only checks are insufficient for this mode. The outcome must include the runtime capture, the root-cause frame or state transition, the focused regression guard, and any sibling matches that were fixed or explicitly left safe.
143
+
144
+ ## Targeted Logging
145
+
146
+ Use logs as a scalpel, not as noise. Before adding a log, write the question it answers:
147
+
148
+ > "If this log prints X before Y, hypothesis A is still possible; if it does not, hypothesis A is wrong."
149
+
150
+ Load `references/logging-techniques.md` for the full logging playbook: binary-search instrumentation, discriminating log content, boundary-first placement, timing bug logging, and removal discipline.
151
+
152
+ Quick rules:
153
+ 1. Place the first log at the midpoint of the execution path, not at the symptom. Binary search from there.
154
+ 2. Log discriminating facts only: sequence number, input key, branch taken, old/new state, error code.
155
+ 3. Remove temporary logs before finishing. Gate persistent diagnostics behind the project's debug flag.
156
+
157
+ If adding logs changes the behavior, treat that as evidence of a timing, lifecycle, or concurrency problem.
158
+
159
+ ## Gotchas
160
+
161
+ | What happened | Rule |
162
+ |---------------|------|
163
+ | Patched client pane instead of local pane | Trace the execution path backward before touching any file |
164
+ | MCP not loading, switched tools instead of diagnosing | Check server status, API key, config before switching methods |
165
+ | Blamed the visible app before measuring the raw system/tooling layer | Measure the lower layer first, then retire ruled-out hypotheses explicitly |
166
+ | Orchestrator said RUNNING but TTS vendor was misconfigured | In multi-stage pipelines, test each stage in isolation |
167
+ | Race condition diagnosed as a stale-state bug | For timing-sensitive issues, inspect event timestamps and ordering before state |
168
+ | Added logs everywhere and still could not explain the bug | Rewrite each log as a yes/no question. Delete logs that do not rule a hypothesis in or out |
169
+ | Reproduced locally but failed in CI | Align the environment first (runtime version, env vars, timezone), then chase the code |
170
+ | Stack trace points deep into a library | Walk back 3 frames into your own code; the bug is almost always there, not in the dependency |
171
+ | Worked when launched from app, broke when opened via file association / drag-drop / deep link / external proxy | Reproduce using the exact entry point the user described. App-internal init differs from cold-launch-with-file init; state may not be ready when the document arrives. |
172
+ | Build passed but UI still looked wrong | Move up the Runtime Evidence Ladder and verify the real rendered surface or artifact. |
173
+
174
+ ## Outcome
175
+
176
+ ### Success Format
177
+
178
+ ```
179
+ Root cause: [what was wrong, file:line]
180
+ Fix: [what changed, file:line]
181
+ Confirmed: [evidence or test that proves the fix]
182
+ Tests: [pass/fail count, regression test location]
183
+ Regression guard: [test file:line] or [none, reason]
184
+ ```
185
+
186
+ Status: **resolved**, **resolved with caveats** (state them), or **blocked** (state what is unknown).
187
+
188
+ **Regression guard rule**: for any bug that recurred or was previously "fixed", the fix is not done until:
189
+ 1. A regression test exists that fails on the unfixed code and passes on the fixed code.
190
+ 2. The test lives in the project's test suite, not a temporary file.
191
+ 3. The commit message states why the bug recurred and why this fix prevents it.
192
+
193
+ ### Handoff Format (after 3 failed hypotheses)
194
+
195
+ ```
196
+ Symptom:
197
+ [Original error description, one sentence]
198
+
199
+ Hypotheses Tested:
200
+ 1. [Hypothesis 1] → [Test method] → [Result: ruled out because...]
201
+ 2. [Hypothesis 2] → [Test method] → [Result: ruled out because...]
202
+ 3. [Hypothesis 3] → [Test method] → [Result: ruled out because...]
203
+
204
+ Evidence Collected:
205
+ - [Log snippets / stack traces / file content]
206
+ - [Reproduction steps]
207
+ - [Environment info: versions, config, runtime]
208
+
209
+ Ruled Out:
210
+ - [Root causes that have been eliminated]
211
+
212
+ Unknowns:
213
+ - [What is still unclear]
214
+ - [What information is missing]
215
+
216
+ Suggested Next Steps:
217
+ 1. [Next investigation direction]
218
+ 2. [External tools or permissions that may be needed]
219
+ 3. [Additional context the user should provide]
220
+ ```
221
+
222
+ Status: **blocked**
223
+
224
+ ## Rendering Bug Mode
225
+
226
+ Activate when: "PDF looks wrong", "page break issue", "font not rendering", broken PDF output, or print layout wrong.
227
+
228
+ Load `references/rendering-debug.md` for the full diagnosis checklist (WeasyPrint quirks, font loading, page overflow, browser print CSS). Static analysis first, then reproduce if needed.
229
+
230
+ ## IME / Unicode Issues
231
+
232
+ For input method, character rendering, or text encoding bugs (IME state, cursor drift, emoji splitting, composition events), check `references/ime-unicode.md` first before forming a hypothesis.
@@ -0,0 +1,138 @@
1
+ # Failure Pattern Reference
2
+
3
+ Use this when a bug has repeated, a first fix did not hold, or the symptom smells like runtime state rather than local code syntax.
4
+
5
+ ## Stale Verifier Or Tool Cache
6
+
7
+ Signals: verifier output points at deleted temp worktrees, old generated files, or paths outside the current repo; rerunning after a clean checkout changes the file path but not the current code.
8
+
9
+ Checks:
10
+ - Confirm the reported path exists.
11
+ - Clear the tool cache only after proving the path is stale.
12
+ - Re-run the same verifier from the current repo root.
13
+
14
+ ## Worker Queue Or DB Boundary
15
+
16
+ Signals: UI says work is running but no worker processes it; logs show scheduler activity but no queued row; retry fixes one item but not the pipeline.
17
+
18
+ Checks:
19
+ - Trace request -> enqueue -> worker pickup -> persistence -> UI refresh.
20
+ - Inspect queue rows or job state directly.
21
+ - Add a regression test around the enqueue boundary, not only the worker body.
22
+
23
+ ## Generated Rebuild Boundary
24
+
25
+ Signals: source changed but generated output, app bundle, CLI artifact, archive, checksum, or release package still contains old behavior.
26
+
27
+ Checks:
28
+ - Identify the source-to-artifact rule.
29
+ - Verify the build system watches the source path.
30
+ - Inspect the generated artifact contents, not just the source diff.
31
+
32
+ ## Guard Lifetime Race
33
+
34
+ Signals: permission, auth, or state guard looks correct locally but a delayed callback, app relaunch, or alternate entry point bypasses it.
35
+
36
+ Checks:
37
+ - Trace guard creation, retention, invalidation, and every alternate entry point.
38
+ - Verify cold launch, warm launch, deep link/file open, and retry paths when applicable.
39
+ - Prefer explicit durable state over transient flags when the guard must survive relaunch.
40
+
41
+ ## Atomic Temp Filename
42
+
43
+ Signals: concurrent runs collide, cleanup removes the wrong file, or a partially written output is observed.
44
+
45
+ Checks:
46
+ - Use unique temp directories or atomic rename.
47
+ - Keep cleanup scoped to files created by the current run.
48
+ - Test two concurrent or back-to-back runs when the tool supports it.
49
+
50
+ ## Path, Cwd, Or Symlink Escape
51
+
52
+ Signals: an operation intended for one root touches a sibling directory, follows a symlink unexpectedly, or behaves differently from another working directory.
53
+
54
+ Checks:
55
+ - Resolve and compare canonical roots before writing or deleting.
56
+ - Reject paths outside the allowed root after symlink resolution.
57
+ - Reproduce from a non-default cwd and through any UI entry point that supplies paths.
58
+
59
+ ## CLI Effect Scope Drift
60
+
61
+ Signals: preview, dry-run, size, count, or report output is computed from one predicate, but execution mutates a broader or different set.
62
+
63
+ Checks:
64
+ - Trace display, dry-run, and mutation predicates to the same source of truth.
65
+ - Compare planned paths or records with executor input in a regression test.
66
+ - Assert partial failures report the exact skipped and completed items.
67
+
68
+ ## CLI Wrapper Or PATH Drift
69
+
70
+ Signals: source-tree invocation works, but the installed command, package wrapper, PATH shim, completion, or package-manager install path runs old code or a different binary.
71
+
72
+ Checks:
73
+ - Inspect built package contents, shebang, executable bit, and wrapper target.
74
+ - Reproduce through a temp prefix or package-manager install path, not only from source.
75
+ - Check PATH order and use absolute system-tool paths where wrappers should not intercept.
76
+
77
+ ## Interactive Stdin Or TTY Hang
78
+
79
+ Signals: CI stalls, spinner never finishes, a subprocess reads from the script body, or an auth prompt appears in non-interactive mode.
80
+
81
+ Checks:
82
+ - Reproduce with stdin redirected and with TTY/non-TTY paths separated.
83
+ - Add test-mode or no-auth guards around real prompts and system changes.
84
+ - Stub external prompt tools through PATH when timeout wrappers exec real binaries.
85
+
86
+ ## Subprocess Pipe Backpressure
87
+
88
+ Signals: a long-running child process hangs only on large output, small fixtures pass, or the parent waits for exit before reading stdout/stderr. The child may be blocked on a full pipe buffer while the parent is blocked on `wait`.
89
+
90
+ Checks:
91
+ - Drain stdout and stderr while the process runs, or explicitly inherit/redirect streams when output is not needed.
92
+ - Test with output larger than a typical pipe buffer, not only tiny fixtures.
93
+ - Preserve stderr tails or structured error output for diagnostics without holding the whole stream in memory.
94
+
95
+ ## Signal Or Partial-Failure Mapping
96
+
97
+ Signals: cancel, timeout, SIGINT, or SIGTERM is reported as success or as a normal business failure; temp files, locks, or operation logs make retries look complete.
98
+
99
+ Checks:
100
+ - Classify interrupted execution separately from success and expected validation failures.
101
+ - Assert temp cleanup, lock release, and operation-log state after interruption.
102
+ - Test retry and idempotency after a partial write.
103
+
104
+ ## CLI Stream Contract Regression
105
+
106
+ Signals: automation breaks after human logs, progress output, JSON shape, stdout/stderr routing, or exit-code behavior changes.
107
+
108
+ Checks:
109
+ - Assert exit code, stdout, and stderr separately in CLI tests.
110
+ - Keep human diagnostics off stdout for machine-readable modes.
111
+ - Snapshot or parse JSON/schema output and include non-interactive coverage.
112
+
113
+ ## Snapshot Rebuild Drops Carried Field
114
+
115
+ Signals: live data shows up at the data source and on the wire but a downstream view sees it empty; the field has a default value (`var x: [T] = []`, `var y: Int? = nil`) that lets memberwise init compile without it; the symptom appears only on the path where the snapshot is rebuilt (icon resolution, decoration, redaction), not on a fresh fetch.
116
+
117
+ Checks:
118
+ - Trace whether every code path that constructs the snapshot type passes the field. The Swift compiler does not warn on default-value omission in memberwise init.
119
+ - Add a unit test that fetches the snapshot, runs the rebuild path, and asserts the carried field equals the input.
120
+ - Prefer `with(...)` mutating helpers or `inout` mutation over fresh memberwise init when only one field is changing.
121
+
122
+ ## Multi-Sample Command Cold Start
123
+
124
+ Signals: a CLI tool that takes `-l N` / `--samples N` / `--repeat N` returns one block of zeros and one block of real data; aggregating all blocks yields zeros; only the second sample carries real measurements.
125
+
126
+ Checks:
127
+ - Read the tool's man page for cold-start semantics. `top -l 2`, `iostat -d 2`, `vm_stat 1 2`, etc. all share this shape.
128
+ - Slice the output to the latest sample (`.suffix(perSampleSize)` on parsed lines, or look for the second instance of the header row).
129
+ - When in doubt, raise `-l` to 3 and confirm sample 2 and 3 agree; sample 1 stays zero.
130
+
131
+ ## Aggregation Key Variant
132
+
133
+ Signals: a count, log roll-up, event tally, or per-category breakdown is short by some entries; the missing items share a trait (a system-derived path, a localized string, a prefixed command name); the base-form key matches but a derived variant (`<base>-system`, a suffix, a prefix) is silently dropped.
134
+
135
+ Checks:
136
+ - Before adding a category, grep every write site that produces this class of key and enumerate the real variants, not just the base form.
137
+ - Match with `hasPrefix` / a regex / an explicit variant list rather than exact equality on the base key.
138
+ - Add a fixture row for each known variant so a future key shape that escapes the matcher fails the test instead of the aggregate.
@@ -0,0 +1,58 @@
1
+ # IME / Unicode Debugging Reference
2
+
3
+ Recurring patterns in Tauri and native macOS apps. Check these before forming a hypothesis.
4
+
5
+ ## IME State Desync
6
+
7
+ **Symptom**: Latin characters appear correctly but CJK input is dropped, doubled, or committed at the wrong time.
8
+
9
+ **Cause candidates**:
10
+ - Input method switch mid-composition: the IME commits the preedit with a stale target, then the new mode processes the same keystrokes again.
11
+ - `keydown` handler consuming events during active composition: check `event.isComposing` before acting on `keydown`/`keyup`. If `isComposing` is true, defer the action until `compositionend`.
12
+ - Webview + native frame split focus: in Tauri, the webview and the native window title bar can hold focus simultaneously. A click on a native control during IME composition triggers a focus-out, committing incomplete preedit text.
13
+
14
+ **Instruments**:
15
+ - Log `compositionstart`, `compositionupdate`, `compositionend` sequence; confirm they fire in order without gaps.
16
+ - Log the `data` field of each `compositionupdate`; a sudden empty string signals a forced commit.
17
+
18
+ ## Cursor Position Drift After IME Commit
19
+
20
+ **Symptom**: After confirming a CJK word, the cursor jumps to the wrong position or the selection collapses.
21
+
22
+ **Cause candidates**:
23
+ - DOM mutation during composition: React/Svelte/Vue re-rendering while `isComposing` is true will reset the selection. Batch state updates and flush only on `compositionend`.
24
+ - Counting bytes instead of code points in position math: CJK characters are multi-byte in UTF-8. Use `Array.from(str).length` or `[...str].length`, not `str.length`, for character-level offsets in positions.
25
+
26
+ ## Emoji ZWJ Sequence Splitting
27
+
28
+ **Symptom**: Multi-person or profession emoji (e.g. `👩‍🚒`) renders as two or three separate emoji, or the ZWJ (`U+200D`) appears as a visible character.
29
+
30
+ **Cause candidates**:
31
+ - String sliced at byte offset: `str.slice(0, n)` splits a ZWJ sequence if `n` falls inside the sequence. Use `Intl.Segmenter` with `granularity: 'grapheme'` to split at grapheme cluster boundaries.
32
+ - Font does not support the sequence: the font renders each code point individually. Verify with `canvas.measureText` or by checking which font is actually used via `document.fonts`.
33
+ - Serialization strips ZWJ: some JSON encoders normalize or escape `U+200D`. Verify the raw bytes of the stored string.
34
+
35
+ **Test**: `[...'👩‍🚒'].length` should be 1 (one grapheme cluster). If it returns 3, the runtime is iterating code points, not grapheme clusters.
36
+
37
+ ## `compositionend` / `keydown` Event Ordering
38
+
39
+ **Symptom**: The action bound to Enter or Tab fires during IME confirmation, submitting incomplete input.
40
+
41
+ **Cause**: On macOS + some IMEs, the sequence is `compositionend` → `keydown(Enter)`. On Windows + other IMEs it can be `keydown(Enter)` → `compositionend`. Code that blocks Enter only when `isComposing` is true will break on the macOS ordering because `isComposing` is already false when `keydown` fires.
42
+
43
+ **Fix**: Track composition state with a boolean flag set on `compositionstart`, cleared on `compositionend`. Guard the Enter handler with that flag rather than `event.isComposing`.
44
+
45
+ ## macOS Text System vs Webview Conflict
46
+
47
+ **Symptom**: Undo (`Cmd+Z`) reverts individual IME preedit characters instead of committed words, or system text shortcuts (Cmd+Shift+Left for word selection) behave differently inside vs outside the webview.
48
+
49
+ **Cause**: WKWebView has its own text system that partially overlaps with NSTextView conventions. Tauri's `preventDefaultFor` config can suppress system shortcuts; check `tauri.conf.json` (v1) or `app.json` (v2) for any `preventDefault` rules that may be too broad.
50
+
51
+ ## Quick Checklist
52
+
53
+ - [ ] `isComposing` checked before acting on keyboard events?
54
+ - [ ] No DOM mutation while `isComposing` is true?
55
+ - [ ] String position math uses grapheme clusters, not bytes or code points?
56
+ - [ ] ZWJ sequences verified with `Intl.Segmenter`?
57
+ - [ ] Enter/Tab guard uses a flag set by `compositionstart`, not `event.isComposing`?
58
+ - [ ] `tauri.conf.json` `preventDefaultFor` not too broad?
@@ -0,0 +1,72 @@
1
+ # Logging Techniques for Debugging
2
+
3
+ Use logs as a scalpel, not as noise. The goal is to answer a yes/no question about a hypothesis, not to dump state.
4
+
5
+ ## Binary Search Instrumentation
6
+
7
+ Place the first log at the midpoint of the execution path, not at the symptom. If it fires correctly, move downstream. If it does not fire, move upstream. This is binary search over the call graph.
8
+
9
+ ```
10
+ Entry → [midpoint log] → ... → symptom
11
+ ^
12
+ First log here, not at the symptom
13
+ ```
14
+
15
+ Repeat: each log cuts the remaining unknown path in half.
16
+
17
+ ## Log What Discriminates, Not What Is Convenient
18
+
19
+ Before adding a log, write the question it must answer:
20
+
21
+ > "If this prints X before Y, hypothesis A holds. If it prints Y first, A is wrong."
22
+
23
+ Discriminating log content:
24
+ - Sequence number or timestamp (ordering)
25
+ - Input identity key (which request/item)
26
+ - Branch taken (which `if` arm)
27
+ - Old vs. new state transition (not just new value)
28
+ - Error code plus context string (not just the exception message)
29
+
30
+ Never log: full request/response bodies, credentials, PII, or huge JSON blobs.
31
+
32
+ ## Log the Boundary, Not the Interior
33
+
34
+ Log at system boundaries where behavior should be predictable:
35
+
36
+ - Request handler entry/exit
37
+ - Cache read (hit or miss) with key
38
+ - State setter (old value, new value, caller)
39
+ - Async callback entry
40
+ - External API call result
41
+ - Build step start/end
42
+
43
+ Interior logs (inside tight loops or low-level helpers) are noise unless the hypothesis is specifically about that interior.
44
+
45
+ ## Prefix Discipline
46
+
47
+ Use a consistent log prefix to filter by context:
48
+
49
+ ```
50
+ [hunt:auth] token validate: user=42 result=expired
51
+ [hunt:cache] miss: key=user:42 latency=12ms
52
+ [hunt:render] phase=layout height=842px overflow=yes
53
+ ```
54
+
55
+ Gate verbose logging behind a debug flag when the project already has one. Remove temporary logs before finishing.
56
+
57
+ ## Timing Bug Logging
58
+
59
+ For race conditions, flicker, or intermittent failures, log:
60
+ - Event identity (which event source)
61
+ - Timestamp (or monotonic counter)
62
+ - Start and end (not just "it ran")
63
+ - Thread/task/queue identity when concurrency is involved
64
+
65
+ If adding a log changes the behavior, treat that as evidence of a timing, lifecycle, or concurrency problem. Do not dismiss it as "just logging side effects."
66
+
67
+ ## Removing Logs
68
+
69
+ After the root cause is confirmed:
70
+ 1. Remove all temporary logs.
71
+ 2. If a log is genuinely useful in production, move it behind the project's debug flag or logger level.
72
+ 3. Do not leave `console.log`, `print`, or `fmt.Println` in shipped code paths unless the project keeps debug instrumentation there.
@@ -0,0 +1,34 @@
1
+ # Rendering Bug Debug Reference
2
+
3
+ ## Rendering Bug Mode
4
+
5
+ Activate when: "PDF looks wrong", "page break issue", "font not rendering", broken PDF output, print layout wrong.
6
+
7
+ Static analysis first (CSS review), then reproduce if needed.
8
+
9
+ ### WeasyPrint
10
+
11
+ - `rgba()` causes double-rectangle bug: use solid hex colors instead
12
+ - `page-break-inside: avoid` is often ignored: use explicit breaks
13
+ - Float-based layouts often break at page boundaries: prefer flexbox or block
14
+ - External font URLs blocked at render time: embed fonts as base64 or host locally
15
+
16
+ ### Font Loading
17
+
18
+ - Check `@font-face` src paths (relative vs. absolute)
19
+ - CORS headers must allow the render origin for external fonts
20
+ - Format support: WeasyPrint prefers WOFF/TTF; WOFF2 support depends on version
21
+ - Missing font fallback = invisible text or system fallback glyph
22
+
23
+ ### Page Overflow
24
+
25
+ - Calculate content height vs. page height before debugging line-by-line
26
+ - Reduce `line-height`, `padding`, or `margin` to reclaim space
27
+ - Orphan/widow control: `orphans: 3; widows: 3` in `@page` body rule
28
+
29
+ ### Browser Print CSS
30
+
31
+ - Confirm `@media print` rules are present and not overridden
32
+ - `@page` margin must account for printer unprintable area (~6mm minimum)
33
+ - `break-before: page` / `break-after: page` on section dividers
34
+ - Test with `window.print()` in browser DevTools, not just visual preview
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: impeccable
3
+ description: AI 前端设计质量审计。检测 UI 反模式、可访问性、布局一致性。扫描 html/css/jsx/tsx/vue/svelte 文件。
4
+ ---
5
+
6
+ # Impeccable — 前端设计质量审计
7
+
8
+ > CodeBuddy 适配版(纯指令模式,底层调用 `npx impeccable` 执行)。
9
+
10
+ ## 核心命令
11
+
12
+ 通过在对话中输入以下命令触发。执行时会调用 `npx impeccable <command>` 底层 CLI。
13
+
14
+ | 对话输入 | 作用 | 底层调用 |
15
+ |----------|------|---------|
16
+ | `impeccable audit` | 五维度技术质量检查(P0-P3 严重性分级) | `npx impeccable audit` |
17
+ | `impeccable critique` | 设计评审(评分 + 可用性测试) | `npx impeccable critique` |
18
+ | `impeccable polish` | 页面最终润色打磨 | `npx impeccable polish` |
19
+ | `impeccable detect` | 自动检测反模式 | `npx impeccable detect` |
20
+ | `impeccable layout` | 修复布局、间距和视觉节奏 | `npx impeccable layout` |
21
+ | `impeccable typeset` | 修复排版问题 | `npx impeccable typeset` |
22
+ | `impeccable colorize` | 为单色界面添加颜色 | `npx impeccable colorize` |
23
+ | `impeccable clarify` | 重写混淆的 UX 文案 | `npx impeccable clarify` |
24
+ | `impeccable distill` | 简化界面,去除多余元素 | `npx impeccable distill` |
25
+ | `impeccable harden` | 使界面更健壮(处理边界情况) | `npx impeccable harden` |
26
+ | `impeccable optimize` | 诊断并修复 UI 性能问题 | `npx impeccable optimize` |
27
+ | `impeccable init` | 创建设计上下文(PRODUCT.md + DESIGN.md) | `npx impeccable init` |
28
+ | `impeccable craft` | 设计并构建一个新功能 | `npx impeccable craft` |
29
+ | `impeccable shape` | 生成设计简报 | `npx impeccable shape` |
30
+
31
+ ## 质量分级
32
+
33
+ ```
34
+ P0(阻断)→ 修复后才能继续
35
+ P1(严重)→ 当前会话修复
36
+ P2(一般)→ 记入记忆,下次处理
37
+ P3(建议)→ 记入记忆,下次处理
38
+ ```
39
+
40
+ ## 设计上下文
41
+
42
+ `impeccable init` 生成 `PRODUCT.md` 和 `DESIGN.md`。这两份文件作为设计上下文,能让后续审计更精准。
43
+
44
+ ## 在工作流中的位置
45
+
46
+ 详见 `.codebuddy/rules/self-evolve.mdc` 步骤 3(自动验证):
47
+ 每次修改前端文件后,自动检查设计质量,仅当发现 P0/P1 问题才中断流程。
@@ -0,0 +1,37 @@
1
+ # Deepening
2
+
3
+ How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in [LANGUAGE.md](LANGUAGE.md) — **module**, **interface**, **seam**, **adapter**.
4
+
5
+ ## Dependency categories
6
+
7
+ When assessing a candidate for deepening, classify its dependencies. The category determines how the deepened module is tested across its seam.
8
+
9
+ ### 1. In-process
10
+
11
+ Pure computation, in-memory state, no I/O. Always deepenable — merge the modules and test through the new interface directly. No adapter needed.
12
+
13
+ ### 2. Local-substitutable
14
+
15
+ Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable if the stand-in exists. The deepened module is tested with the stand-in running in the test suite. The seam is internal; no port at the module's external interface.
16
+
17
+ ### 3. Remote but owned (Ports & Adapters)
18
+
19
+ Your own services across a network boundary (microservices, internal APIs). Define a **port** (interface) at the seam. The deep module owns the logic; the transport is injected as an **adapter**. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.
20
+
21
+ Recommendation shape: *"Define a port at the seam, implement an HTTP adapter for production and an in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across a network."*
22
+
23
+ ### 4. True external (Mock)
24
+
25
+ Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the external dependency as an injected port; tests provide a mock adapter.
26
+
27
+ ## Seam discipline
28
+
29
+ - **One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a port unless at least two adapters are justified (typically production + test). A single-adapter seam is just indirection.
30
+ - **Internal seams vs external seams.** A deep module can have internal seams (private to its implementation, used by its own tests) as well as the external seam at its interface. Don't expose internal seams through the interface just because tests use them.
31
+
32
+ ## Testing strategy: replace, don't layer
33
+
34
+ - Old unit tests on shallow modules become waste once tests at the deepened module's interface exist — delete them.
35
+ - Write new tests at the deepened module's interface. The **interface is the test surface**.
36
+ - Tests assert on observable outcomes through the interface, not internal state.
37
+ - Tests should survive internal refactors — they describe behaviour, not implementation. If a test has to change when the implementation changes, it's testing past the interface.