@codeyam/codeyam-cli 0.1.0-staging.79ef713 → 0.1.0-staging.7c30edc

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 (195) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +101 -0
  4. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  5. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +6 -0
  6. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +176 -8
  7. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +46 -6
  8. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  9. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +32 -5
  10. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +38 -2
  11. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +359 -142
  12. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  13. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  14. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  15. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  16. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  17. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  18. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  19. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  20. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  21. package/analyzer-template/packages/database/src/lib/kysely/db.ts +6 -0
  22. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  23. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  24. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  25. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  26. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  27. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  28. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  29. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  30. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  31. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  32. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  33. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  34. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  35. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  36. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  37. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  38. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  39. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  40. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  41. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +3 -0
  42. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  43. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  44. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  45. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  46. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  47. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  48. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  49. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  50. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  51. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  52. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  53. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +4 -0
  54. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  55. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -1
  56. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +4 -0
  57. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  58. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  59. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  60. package/codeyam-cli/src/cli.js +2 -0
  61. package/codeyam-cli/src/cli.js.map +1 -1
  62. package/codeyam-cli/src/codeyam-cli.js +18 -2
  63. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  64. package/codeyam-cli/src/commands/analyze.js +2 -0
  65. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  66. package/codeyam-cli/src/commands/baseline.js +2 -0
  67. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  68. package/codeyam-cli/src/commands/debug.js +2 -0
  69. package/codeyam-cli/src/commands/debug.js.map +1 -1
  70. package/codeyam-cli/src/commands/default.js +25 -19
  71. package/codeyam-cli/src/commands/default.js.map +1 -1
  72. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  73. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  74. package/codeyam-cli/src/commands/init.js +49 -257
  75. package/codeyam-cli/src/commands/init.js.map +1 -1
  76. package/codeyam-cli/src/commands/memory.js +9 -9
  77. package/codeyam-cli/src/commands/memory.js.map +1 -1
  78. package/codeyam-cli/src/commands/recapture.js +2 -0
  79. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  80. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  81. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  82. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  83. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  84. package/codeyam-cli/src/commands/test-startup.js +2 -0
  85. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  86. package/codeyam-cli/src/commands/verify.js +2 -0
  87. package/codeyam-cli/src/commands/verify.js.map +1 -1
  88. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +127 -85
  89. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  90. package/codeyam-cli/src/utils/analyzer.js +7 -0
  91. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  92. package/codeyam-cli/src/utils/install-skills.js +41 -61
  93. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  94. package/codeyam-cli/src/utils/labsAutoCheck.js +48 -0
  95. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  96. package/codeyam-cli/src/utils/progress.js +7 -0
  97. package/codeyam-cli/src/utils/progress.js.map +1 -1
  98. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  99. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  100. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +4 -4
  101. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -1
  102. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +95 -2
  103. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -1
  104. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +4 -4
  105. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -1
  106. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +3 -3
  107. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -1
  108. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +23 -23
  109. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -1
  110. package/codeyam-cli/src/utils/rules/parser.js +5 -0
  111. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  112. package/codeyam-cli/src/utils/rules/ruleState.js +10 -10
  113. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -1
  114. package/codeyam-cli/src/utils/rules/staleness.js +6 -6
  115. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -1
  116. package/codeyam-cli/src/utils/serverState.js +37 -10
  117. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  118. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +19 -42
  119. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  120. package/codeyam-cli/src/webserver/app/lib/database.js +14 -3
  121. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  122. package/codeyam-cli/src/webserver/backgroundServer.js +31 -0
  123. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  124. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-CN61MOMa.js +11 -0
  125. package/codeyam-cli/src/webserver/build/client/assets/api.labs-survey-l0sNRNKZ.js +1 -0
  126. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  127. package/codeyam-cli/src/webserver/build/client/assets/globals-CuCsBc3b.css +1 -0
  128. package/codeyam-cli/src/webserver/build/client/assets/labs-CB3MGcys.js +1 -0
  129. package/codeyam-cli/src/webserver/build/client/assets/{manifest-87319d0f.js → manifest-de6ccaf4.js} +1 -1
  130. package/codeyam-cli/src/webserver/build/client/assets/memory-DCA-kLYt.js +81 -0
  131. package/codeyam-cli/src/webserver/build/client/assets/root-F7e6dvys.js +62 -0
  132. package/codeyam-cli/src/webserver/build/client/assets/settings-BejnUJ6R.js +1 -0
  133. package/codeyam-cli/src/webserver/build/server/assets/{index-9ox9LcrG.js → index-CFKHuovO.js} +1 -1
  134. package/codeyam-cli/src/webserver/build/server/assets/server-build-BQe9Dh4p.js +260 -0
  135. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  136. package/codeyam-cli/src/webserver/build-info.json +5 -5
  137. package/codeyam-cli/templates/codeyam-memory-hook.sh +14 -14
  138. package/codeyam-cli/templates/codeyam:diagnose.md +193 -515
  139. package/codeyam-cli/templates/codeyam:memory.md +9 -21
  140. package/codeyam-cli/templates/codeyam:setup.md +12 -0
  141. package/codeyam-cli/templates/rule-reflection-hook.py +64 -27
  142. package/codeyam-cli/templates/rules-instructions.md +50 -41
  143. package/package.json +1 -1
  144. package/packages/ai/src/lib/astScopes/processExpression.js +78 -1
  145. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  146. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  147. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  148. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +128 -7
  149. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  150. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +40 -6
  151. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  152. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  153. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  154. package/packages/ai/src/lib/generateEntityScenarioData.js +22 -3
  155. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  156. package/packages/ai/src/lib/generateExecutionFlows.js +16 -2
  157. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  158. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +242 -81
  159. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  160. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  161. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  162. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  163. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  164. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  165. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  166. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  167. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  168. package/packages/database/src/lib/analysisToDb.js +1 -1
  169. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  170. package/packages/database/src/lib/branchToDb.js +1 -1
  171. package/packages/database/src/lib/branchToDb.js.map +1 -1
  172. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  173. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  174. package/packages/database/src/lib/commitToDb.js +1 -1
  175. package/packages/database/src/lib/commitToDb.js.map +1 -1
  176. package/packages/database/src/lib/fileToDb.js +1 -1
  177. package/packages/database/src/lib/fileToDb.js.map +1 -1
  178. package/packages/database/src/lib/kysely/db.js +3 -0
  179. package/packages/database/src/lib/kysely/db.js.map +1 -1
  180. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  181. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  182. package/packages/database/src/lib/projectToDb.js +1 -1
  183. package/packages/database/src/lib/projectToDb.js.map +1 -1
  184. package/packages/database/src/lib/saveFiles.js +1 -1
  185. package/packages/database/src/lib/saveFiles.js.map +1 -1
  186. package/packages/database/src/lib/scenarioToDb.js +1 -1
  187. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  188. package/scripts/finalize-analyzer.cjs +8 -76
  189. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DfKzxuoe.js +0 -11
  190. package/codeyam-cli/src/webserver/build/client/assets/globals-Bh6jH0cL.css +0 -1
  191. package/codeyam-cli/src/webserver/build/client/assets/labs-CdVUfvji.js +0 -1
  192. package/codeyam-cli/src/webserver/build/client/assets/memory-CPIDnDEj.js +0 -76
  193. package/codeyam-cli/src/webserver/build/client/assets/root-D6oziHts.js +0 -62
  194. package/codeyam-cli/src/webserver/build/client/assets/settings-eBI36Yv5.js +0 -1
  195. package/codeyam-cli/src/webserver/build/server/assets/server-build-Cq5Vqcob.js +0 -260
@@ -2,100 +2,60 @@
2
2
 
3
3
  When a user asks to debug a scenario or analysis (e.g., `/codeyam:diagnose [ID]`), use this systematic process.
4
4
 
5
- ## Goal
5
+ ## Goal & Rules
6
6
 
7
- **Capture quality screenshots** by fixing all errors, then document what was wrong. Every issue can be fixed locally—the question is whether the fix is in the database (Categories 1-3) or in the tmp folder code (Category 4). Either way, you must capture screenshots before concluding.
7
+ **Goal:** Capture quality screenshots by fixing all errors, then document what was wrong.
8
8
 
9
- ## Definition of Done
9
+ **Definition of Done** — debugging is NOT complete until one of:
10
10
 
11
- **Debugging is NOT complete until one of these conditions is met:**
11
+ | Outcome | What's Required |
12
+ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
13
+ | **SUCCESS (DB Fix)** | Issue fixed via database/config changes, screenshots recaptured, all files verified on disk AND visually inspected |
14
+ | **SUCCESS (File Fix)** | Issue fixed via tmp folder edits, screenshots recaptured with `--capture-only`, all files verified AND visually inspected, changes documented |
15
+ | **UNFIXABLE** | Issue cannot be fixed locally (rare), documented in final report with full details |
12
16
 
13
- 1. **SUCCESS (Database Fix)**: Issue fixed via database/config changes, screenshots recaptured, ALL screenshot files verified on disk AND visually inspected
14
- 2. **SUCCESS (File Fix)**: Issue fixed via tmp folder edits, screenshots recaptured with `--capture-only`, ALL screenshot files verified AND visually inspected, changes documented for CodeYam team
15
- 3. **UNFIXABLE**: Issue cannot be fixed locally (rare), documented in final report with full details
17
+ ### KEY RULE 1: Never stop before capturing screenshots
16
18
 
17
- **CRITICAL: NEVER stop debugging before capturing quality screenshots.** Even if you identify the root cause as a "Category 4 engine bug", you MUST:
19
+ Category 4 ("engine bug") is a **diagnosis category, not a blocker**. You have full access to edit any file in `/tmp/codeyam/local-dev/{slug}/project/` — the "engine" just wrote those files as plain TypeScript/JavaScript. Every issue can be fixed locally.
18
20
 
19
- 1. Fix the issue manually in the tmp folder (this is always possible)
20
- 2. Run `codeyam recapture --capture-only` to capture screenshots with your fixes in place
21
- 3. Verify the screenshots show the component rendering correctly
22
- 4. ONLY THEN document the engine bug for the CodeYam team
21
+ If you find yourself thinking "this requires an engine-level fix" or "this is blocked by a code generation bug" — **STOP**.
23
22
 
24
- Stopping after identifying a bug category without capturing screenshots defeats the purpose of debugging.
23
+ - Fix the files in the tmp folder, then capture screenshots, THEN document the bug
24
+ - Try at least 3 different approaches before asking the user whether to continue
25
+ - Only stop when the user agrees or you've captured quality screenshots
25
26
 
26
- ## Critical: Persistence and User Communication
27
+ ### KEY RULE 2: Original Repo vs Tmp Folder
27
28
 
28
- **DO NOT give up prematurely.** Every issue can be fixed by editing files in the tmp folder. If you find yourself thinking:
29
+ | Location | What's There | Use For |
30
+ | --------------------------------------------------------- | ------------------------------------------------------------------- | ----------------------------------------------------- |
31
+ | **Original Repo** (your working directory) | Database (`.codeyam/db.sqlite3`), config, universal mocks, captures | **Run all `codeyam` commands here** |
32
+ | **Tmp Folder** (`/tmp/codeyam/local-dev/{slug}/project/`) | Copy of project with mock injections, generated scenario files | **Only edit files here — never run codeyam commands** |
29
33
 
30
- - "This requires an engine-level fix"
31
- - "This is blocked by a code generation bug"
32
- - "The engine doesn't properly handle X"
34
+ Running `codeyam recapture` from the tmp folder fails with "Not in a CodeYam project" because the database isn't there.
33
35
 
34
- **STOP.** These statements are incorrect. You have full access to edit any file in `/tmp/codeyam/local-dev/{slug}/project/`. The "engine" just wrote those files—they're plain TypeScript/JavaScript that you can edit directly.
36
+ ### KEY RULE 3: Never modify client code
35
37
 
36
- ### Before Stopping or Concluding
38
+ Fix the **mock data or mock code** — never the client's components or application code. The client's code is sacred. Our job is to make the simulation environment correct. You CAN modify:
37
39
 
38
- 1. **Try at least 3 different approaches** to fix the issue
39
- 2. **Never unilaterally decide to stop.** If you've been debugging and aren't making progress, ASK THE USER:
40
- > "I've tried X, Y, and Z but haven't resolved the issue yet. Would you like me to continue investigating other approaches, or should I document what I've found so far?"
41
- 3. **Only stop when the user agrees** or when you've successfully captured quality screenshots
40
+ - Database data (`.codeyam/db.sqlite3`) in Original Repo
41
+ - Universal mocks (`.codeyam/universal-mocks`) in Original Repo
42
+ - Generated files in tmp folder (`__codeyamMocks__/`, layouts, routes)
42
43
 
43
- ### The "Engine Bug" Misconception
44
+ ### KEY RULE 4: `--capture-only` preserves tmp folder edits
44
45
 
45
- When you identify a Category 4 issue (code generation bug), this does NOT mean you're blocked. It means:
46
+ - `codeyam recapture ID` regenerates files from database, then captures (overwrites tmp edits)
47
+ - `codeyam recapture ID --capture-only` — captures without regenerating (preserves your edits)
48
+ - `codeyam debug ID` — regenerates files only (also overwrites tmp edits)
46
49
 
47
- - The bug is in how CodeYam generates code (useful info for the CodeYam team)
48
- - You MUST still fix it manually by editing files in the tmp folder
49
- - You MUST still capture quality screenshots
50
- - You document what you fixed so the CodeYam team can improve the engine
51
-
52
- **"Engine bug" is a diagnosis category, not an excuse to stop.**
50
+ If you edited files in the tmp folder, you **MUST** use `--capture-only` when recapturing.
53
51
 
54
52
  ---
55
53
 
56
- ## Debug Flow Summary
54
+ ## Setup
57
55
 
58
- ```
59
- ┌─────────────────────────────────────────────────────────────────────┐
60
- │ Step 0: Query database for scenario status (DO THIS FIRST!) │
61
- │ Check ALL scenarios in the analysis for failures │
62
- │ Retrieve the analysis id to use in the debug command │
63
- │ │ │
64
- │ ▼ │
65
- │ Step 1: Copy the logs to a temporary location (see below). |
66
- | Step 2: codeyam debug [ANALYSIS ID] (generates files to inspect) │
67
- │ Step 3: Identify error type from logs/output │
68
- │ Step 4: Diagnose root cause category (1-4) │
69
- │ Step 5: Attempt fix (database edit or universal mock) │
70
- │ Step 6: Verify locally (curl returns 200) │
71
- │ │ │
72
- │ ┌─────────┴─────────┐ │
73
- │ ▼ ▼ │
74
- │ Fix worked Fix didn't work │
75
- │ (DB changes) │ │
76
- │ │ ▼ │
77
- │ │ Step 5a: Fix code in tmp folder │
78
- │ │ (edit files directly, track changes) │
79
- │ │ │ │
80
- │ │ ▼ │
81
- │ │ Verify without regenerating │
82
- │ │ │ │
83
- │ ▼ ▼ │
84
- │ Step 7: Recapture Step 7: Recapture --capture-only │
85
- │ (normal) (preserves file fixes) │
86
- │ │ │ │
87
- │ └─────────┬─────────┘ │
88
- │ ▼ │
89
- │ Step 8: Verify screenshots (check for client-side errors) │
90
- │ │ │
91
- │ ▼ │
92
- │ Verify ALL files exist on disk │
93
- │ │ │
94
- │ ▼ │
95
- │ ✅ DONE - Produce Final Debug Report │
96
- │ (document ALL changes for CodeYam team) │
97
- └─────────────────────────────────────────────────────────────────────┘
98
- ```
56
+ ### Note Key Locations
57
+
58
+ **Database:** The codeyam database relevant for this command should always be found in the repo where this command is called in the `.codeyam/db.sqlite3` file.
99
59
 
100
60
  **Logs:** Before debugging copy the original logs to a temorary location as the debugging will overwrite these logs and they are valuable for debugging issues.
101
61
 
@@ -117,15 +77,12 @@ At the **very start** of debugging, create `.codeyam/debug-session.md` in the **
117
77
  ```markdown
118
78
  # Debug Session Context
119
79
 
120
- **IMPORTANT**: Keep a todo item "📍 Re-read debug session context" that is NEVER marked complete.
121
- If the todo disappears, add it back immediately.
122
-
123
80
  ## Key Locations
124
81
 
125
- - **Original project**: [FULL PATH - run all codeyam commands here]
126
- - **Tmp folder**: /tmp/codeyam/local-dev/[SLUG]/project (edit files here, do NOT run codeyam commands)
127
- - **Database**: [ORIGINAL PROJECT]/.codeyam/db.sqlite3
128
- - **Logs**: /tmp/codeyam/local-dev/[SLUG]/codeyam/log.txt
82
+ - **Original Repo**: [FULL PATH]
83
+ - **Tmp Folder**: /tmp/codeyam/local-dev/[PROJECT SLUG]/project
84
+ - **Database**: [Original Repo]/.codeyam/db.sqlite3
85
+ - **Logs**: /tmp/codeyam/local-dev/[PROJECT SLUG]/codeyam/log.txt
129
86
 
130
87
  ## IDs
131
88
 
@@ -133,209 +90,109 @@ If the todo disappears, add it back immediately.
133
90
  - **Scenario ID**: [ID]
134
91
  - **Entity**: [NAME] at [FILE PATH]
135
92
 
136
- ## URLs (fill in after running codeyam debug)
93
+ ## URLs (fill in after codeyam debug)
137
94
 
138
95
  - **Scenario URL**: http://localhost:[PORT]/static/codeyam-sample
139
- - **Dev server port**: [PORT from codeyam debug output]
140
-
141
- ## Commands Reference
142
-
143
- All commands run from: [ORIGINAL PROJECT PATH]
144
-
145
- - `codeyam debug [ANALYSIS_ID]` - regenerate files (overwrites tmp folder!)
146
- - `codeyam recapture [ID]` - regenerate AND capture (overwrites tmp folder!)
147
- - `codeyam recapture [ID] --capture-only` - capture WITHOUT regenerating (preserves your edits)
148
- - `codeyam test-startup` - test startup (overwrites tmp folder!)
149
- ```
150
-
151
- ### Step 2: Create Persistent Todo
152
-
153
- Use TodoWrite to create this todo list with the first item being a persistent reminder:
154
-
155
- ```
156
- 📍 Re-read .codeyam/debug-session.md before any codeyam command (NEVER complete this)
157
- ```
158
-
159
- **CRITICAL**: The first todo item must NEVER be marked as completed. It serves as a constant reminder to check your session context before running commands. If you accidentally complete it or it disappears, add it back immediately.
160
-
161
- ### Step 3: Read Context Before Actions
162
-
163
- **Before running ANY of these commands**, re-read `.codeyam/debug-session.md`:
164
-
165
- - `codeyam debug`
166
- - `codeyam recapture`
167
- - `codeyam test-startup`
168
- - Any database queries
169
-
170
- This prevents running commands from the wrong directory or forgetting key IDs.
171
-
172
- ---
173
-
174
- ## Critical: Where to Run Commands
175
-
176
- **All `codeyam` commands MUST be run from the ORIGINAL PROJECT DIRECTORY**, not from the tmp folder.
177
-
178
- | Location | What's There | Run Commands Here? |
179
- | ---------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------------------------- |
180
- | **Original project** (e.g., `/Users/.../clients-codeyam/boltwise/app`) | Database (`.codeyam/db.sqlite3`), config, universal mocks | **YES - run all codeyam commands here** |
181
- | **Tmp folder** (`/tmp/codeyam/local-dev/{slug}/project/`) | Copy of project with mock injections, generated scenario files | **NO - only edit files here, don't run commands** |
182
-
183
- **Common mistake:** Running `codeyam recapture` from the tmp folder. This will fail with "Not in a CodeYam project" because the database doesn't exist there.
184
-
185
- ```bash
186
- # WRONG - running from tmp folder
187
- cd /tmp/codeyam/local-dev/boltwise-app/project
188
- codeyam recapture abc123 # ❌ Fails: "Not in a CodeYam project"
189
-
190
- # CORRECT - running from original project directory
191
- cd /Users/jaredcosulich/workspace/codeyam/clients-codeyam/boltwise/app
192
- codeyam recapture abc123 # ✅ Works
193
96
  ```
194
97
 
195
- **Workflow:**
196
-
197
- 1. Edit files in `/tmp/codeyam/local-dev/{slug}/project/` to fix issues
198
- 2. Test by curling the dev server running from the tmp folder
199
- 3. **Switch back to the original project directory** to run `codeyam recapture`
200
-
201
- ---
202
-
203
- ## What You Can and Cannot Modify
204
-
205
- **NEVER modify the client's original source code in the workspace.** Only modify files in the tmp folder.
206
-
207
- ### CRITICAL: Fix the Mocks, Never the Client Code
208
-
209
- When debugging errors, the fix is ALWAYS in the mock data or mock code—never in the client's components or application code.
98
+ Re-read this file before running any `codeyam` command to avoid running commands from the wrong directory.
210
99
 
211
- **If a component crashes due to unexpected data:**
100
+ ### Copy Original Logs
212
101
 
213
- - Fix the mock data to provide what the component expects
214
- - Do NOT modify the component to handle the bad data
102
+ Copy logs before debugging overwrites them:
215
103
 
216
- **The client's code is sacred.** Our job is to make the simulation environment correct, not to "improve" or "harden" the client's code. Even if a component could be more defensive, that's not our fix to make.
217
-
218
- **You CAN modify:**
219
-
220
- - Data in the local SQLite database (`.codeyam/db.sqlite3`) - in the **original project directory**
221
- - Universal mocks in `.codeyam/universal-mocks` - in the **original project directory**
222
- - **Files in `/tmp/codeyam/local-dev/{slug}/project/`** - These are temporary copies used for simulation
223
- - Generated mock files in `__codeyamMocks__/` directories
224
- - Layout/route files that wrap scenarios
225
- - Any generated code that has errors
226
- - Mock data files for testing
227
-
228
- **IMPORTANT**: When you edit files in the tmp folder, you MUST use `codeyam recapture --capture-only` when recapturing, otherwise your changes will be overwritten! Be sure to address all issues so that the simulation runs correctly. Then, if one of the issues required editing code in the tmp directory you MUST use `codeyam recapture --capture-only`, but if only data was changed then as long as that data is updated in the local database as well you can run `codeyam recapture` and have the system overwrite the tmp project code and use the valid data from the database.
104
+ - **From:** `/tmp/codeyam/local-dev/{slug}/codeyam/logs.txt`
105
+ - **To:** `/tmp/codeyam/local-dev/{slug}/debug/original-logs.txt`
229
106
 
230
107
  ---
231
108
 
232
- ## Step 0: Check for Other Failing Scenarios (MANDATORY FIRST STEP)
109
+ ## Step 1: Check Database (MANDATORY FIRST STEP)
233
110
 
234
- **DO NOT run `codeyam debug` yet!** First, query the database to check if other scenarios in the same analysis are also failing.
111
+ **DO NOT run `codeyam debug` yet!** First check if other scenarios in the same analysis are also failing.
235
112
 
236
113
  ```bash
237
- # First, get the analysis ID (if you have a scenario ID)
114
+ # Get analysis ID (if you have a scenario ID)
238
115
  sqlite3 .codeyam/db.sqlite3 "SELECT analysis_id FROM scenarios WHERE id = 'SCENARIO_ID'"
239
116
 
240
- # Then check ALL scenarios for that analysis
117
+ # Check ALL scenarios for that analysis
241
118
  sqlite3 .codeyam/db.sqlite3 "
242
- SELECT
243
- s.id,
244
- s.name,
245
- json_extract(s.metadata, '$.screenshotPaths') as screenshots
246
- FROM scenarios s
247
- WHERE s.analysis_id = 'ANALYSIS_ID'
248
- "
119
+ SELECT s.id, s.name, json_extract(s.metadata, '$.screenshotPaths') as screenshots
120
+ FROM scenarios s WHERE s.analysis_id = 'ANALYSIS_ID'"
249
121
 
250
122
  # Check for errors in scenario status
251
123
  sqlite3 .codeyam/db.sqlite3 "
252
- SELECT json_extract(status, '$.scenarios') FROM analyses WHERE id = 'ANALYSIS_ID'
253
- "
124
+ SELECT json_extract(status, '$.scenarios') FROM analyses WHERE id = 'ANALYSIS_ID'"
254
125
  ```
255
126
 
256
- **If multiple scenarios are failing, ASK THE USER** whether to fix just the requested scenario or all failing scenarios.
127
+ **If multiple scenarios failing, ASK THE USER** whether to fix just the requested one or all.
257
128
 
258
- ### Check for Client-Side Errors in Screenshots
129
+ ### Check Existing Screenshots for Client-Side Errors
259
130
 
260
- **IMPORTANT:** Even if the database shows no errors and screenshots exist, the scenario may still have a client-side error. Use the Read tool to view the screenshot file and check for:
131
+ Even if screenshots exist, view them with the Read tool and check for:
261
132
 
262
- - Red error boundaries or error messages in the rendered UI
133
+ - Red error boundaries or React error overlays
263
134
  - "Something went wrong" or similar error text
264
135
  - Blank/white screens that should have content
265
- - React error overlays
266
136
 
267
- ```bash
268
- # View the screenshot to check for client-side errors
269
- # Use the Read tool on the screenshot path from the database
270
- ```
271
-
272
- If the screenshot shows a client-side error, proceed to Step 1 to debug it.
137
+ If the screenshot shows errors, proceed to Step 2.
273
138
 
274
139
  ---
275
140
 
276
- ## Step 1: Run Debug Command
141
+ ## Step 2: Run Debug Command
277
142
 
278
143
  ```bash
279
144
  codeyam debug ANALYSIS_ID
280
145
  ```
281
146
 
282
- Output includes:
283
-
284
- - **Project path**: `/tmp/codeyam/local-dev/{slug}/project`
285
- - **Start command**: How to run the dev server
286
- - **URL**: Where to access the scenario
287
- - **Log path**: Where to watch for errors
147
+ Output includes: **project path**, **start command**, **URL**, **log path**. Update your session context file with these.
288
148
 
289
149
  ---
290
150
 
291
- ## Step 2: Identify the Error Type
151
+ ## Step 3: Identify Error Type
292
152
 
293
- Read the log file or error output to categorize the issue:
153
+ Read the log file or error output to categorize:
294
154
 
295
- | Error Type | Symptoms | Likely Category |
296
- | ---------------------------------- | ----------------------------------- | ---------------------------------------- |
297
- | **Syntax error in generated file** | `Unexpected token`, `Parse error` | Category 4 (mock code writing) |
298
- | **Runtime error** | `TypeError`, `ReferenceError` | Category 1-3 (data issue) or 4 |
299
- | **Missing mock** | `Cannot read property of undefined` | Category 1-2 (missing in data structure) |
300
- | **Wrong mock type** | `X is not a function` | Category 3-4 (wrong data or mock code) |
155
+ | Error Type | Symptoms | Likely Category |
156
+ | ---------------------------------- | ----------------------------------- | ----------------- |
157
+ | **Syntax error in generated file** | `Unexpected token`, `Parse error` | Category 4 |
158
+ | **Runtime error** | `TypeError`, `ReferenceError` | Category 1-3 or 4 |
159
+ | **Missing mock** | `Cannot read property of undefined` | Category 1-2 |
160
+ | **Wrong mock type** | `X is not a function` | Category 3-4 |
301
161
 
302
162
  ---
303
163
 
304
- ## Step 3: Diagnose Root Cause Category
164
+ ## Step 4: Diagnose Root Cause Category
305
165
 
306
- This is the most important step. Determine WHERE in the pipeline the bug originated.
166
+ Determine WHERE in the pipeline the bug originated.
307
167
 
308
168
  ### The 4 Error Categories
309
169
 
310
- | Category | What's Wrong | Where to Check | Fixable Locally? |
311
- | -------- | ---------------------------------------------------- | ------------------------- | ----------------------------- |
312
- | **1** | Missing attribute in `isolatedDataStructure` | `entities.metadata` | Sometimes (re-analyze) |
313
- | **2** | Attribute not merged into `mergedDataStructure` | `analyses.metadata` | Sometimes (re-analyze) |
314
- | **3** | Data structure complete, but scenario data wrong | `scenarios.metadata` | Yes (edit mockData) |
315
- | **4** | Data complete, but mock code/mock data written wrong | Generated files in `/tmp` | **Yes (edit files directly)** |
170
+ | Category | What's Wrong | Where to Check | Fix |
171
+ | -------- | ------------------------------------------------ | -------------------- | ------------------- |
172
+ | **1** | Missing attribute in `isolatedDataStructure` | `entities.metadata` | Re-analyze |
173
+ | **2** | Attribute not merged into `mergedDataStructure` | `analyses.metadata` | Re-analyze |
174
+ | **3** | Data structure complete, but scenario data wrong | `scenarios.metadata` | Edit mockData in DB |
175
+ | **4** | Data complete, but generated code wrong | Files in `/tmp` | Edit files directly |
316
176
 
317
177
  ### Diagnostic Queries
318
178
 
319
179
  ```bash
320
180
  # Category 1: Check isolatedDataStructure
321
- # Is the attribute traced at all in the entity?
322
181
  sqlite3 .codeyam/db.sqlite3 \
323
182
  "SELECT json_extract(metadata, '$.isolatedDataStructure') FROM entities WHERE sha = 'ENTITY_SHA'" \
324
183
  | python3 -m json.tool
325
184
 
326
185
  # Category 2: Check mergedDataStructure
327
- # Was the attribute properly merged from dependencies?
328
186
  sqlite3 .codeyam/db.sqlite3 \
329
187
  "SELECT json_extract(metadata, '$.mergedDataStructure') FROM analyses WHERE id = 'ANALYSIS_ID'" \
330
188
  | python3 -m json.tool
331
189
 
332
- # Category 2 (also check): scenariosDataStructure
190
+ # Category 2 (also): scenariosDataStructure
333
191
  sqlite3 .codeyam/db.sqlite3 \
334
192
  "SELECT json_extract(metadata, '$.scenariosDataStructure') FROM analyses WHERE id = 'ANALYSIS_ID'" \
335
193
  | python3 -m json.tool
336
194
 
337
195
  # Category 3: Check scenario mockData
338
- # Did the LLM generate correct mock data?
339
196
  sqlite3 .codeyam/db.sqlite3 \
340
197
  "SELECT json_extract(metadata, '$.data.mockData') FROM scenarios WHERE id = 'SCENARIO_ID'" \
341
198
  | python3 -m json.tool
@@ -343,49 +200,41 @@ sqlite3 .codeyam/db.sqlite3 \
343
200
 
344
201
  ### Diagnosis Flow
345
202
 
346
- 1. **Start with the error** - What attribute/value is missing or wrong at runtime?
347
- 2. **Check `isolatedDataStructure`** - Is the attribute traced in the entity? If missing → Category 1
348
- 3. **Check `mergedDataStructure`** - Is the attribute present after merging? If missing → Category 2
349
- 4. **Check `scenariosDataStructure`** - Is the data structure for mocks correct? If wrong → Category 2
350
- 5. **Check scenario `mockData`** - Does the scenario have correct mock values? If wrong → Category 3
351
- 6. **Check generated mock code** - Is the mock code syntactically/semantically correct? If wrong → **Category 4 (engine bug)**
352
- 7. **Check generated imports** - Are the imports correct? Are entities containing environment variables mocked out? If wrong → **Category 4 (engine bug)**
353
-
354
- ### Category 4 Indicators (Code Generation Issue)
203
+ Work through these checks in order stop at the first failure:
355
204
 
356
- The issue is Category 4 if:
205
+ | Step | Check | If wrong → |
206
+ | ---- | ------------------------------------------------------------------------------- | ---------- |
207
+ | 1 | **Start with the error** — what attribute/value is missing or wrong at runtime? | — |
208
+ | 2 | Is the attribute in `isolatedDataStructure`? | Category 1 |
209
+ | 3 | Is the attribute in `mergedDataStructure`? | Category 2 |
210
+ | 4 | Is `scenariosDataStructure` correct? | Category 2 |
211
+ | 5 | Does scenario `mockData` have correct values? | Category 3 |
212
+ | 6 | Is the generated mock code syntactically/semantically correct? | Category 4 |
213
+ | 7 | Are imports correct? Environment variable entities mocked out? | Category 4 |
357
214
 
358
- - All data structures in the database look correct
359
- - The scenario's mockData has the right keys and values
360
- - BUT the generated mock code has syntax errors, wrong structure, or doesn't match the data
361
- - Database edits don't fix the generated code (it regenerates wrong)
215
+ If all database data looks correct but the generated code has syntax errors, wrong structure, or doesn't match the data → **Category 4**.
362
216
 
363
- **Category 4 does NOT mean you are blocked.** You have full access to fix these issues:
364
-
365
- 1. **Edit the files directly** in `/tmp/codeyam/local-dev/{slug}/project/`
366
- 2. **Fix any syntax errors, wrong imports, missing mocks** - these are just TypeScript files
367
- 3. **Restart the dev server** and verify the fix works
368
- 4. **Capture quality screenshots** with `codeyam recapture --capture-only`
369
- 5. **Document what you fixed** for the CodeYam team to improve the engine
217
+ ---
370
218
 
371
- The term "engine bug" means the CodeYam code generation has a bug—it does NOT mean you cannot fix the issue locally. You always can.
219
+ ## Step 5: Fix the Issue
372
220
 
373
- ---
221
+ Jump to the subsection matching your category:
374
222
 
375
- ## Step 4: Attempt Fix
223
+ - **Categories 1-2** Re-analyze
224
+ - **Category 3** → Edit mockData in database
225
+ - **Category 4** → Edit generated files in tmp folder
376
226
 
377
- ### For Categories 1-2 (Data Structure Issues)
227
+ ### Categories 1-2 (Data Structure Issues)
378
228
 
379
- These usually require re-running analysis. You can try:
229
+ Re-run analysis:
380
230
 
381
231
  ```bash
382
- # Delete the analysis and re-analyze
383
232
  codeyam analyze --entity EntityName path/to/file.tsx
384
233
  ```
385
234
 
386
- ### For Category 3 (Scenario Data Issues)
235
+ ### Category 3 (Scenario Data Issues)
387
236
 
388
- Fix the mockData directly in the database:
237
+ Fix mockData directly in the database:
389
238
 
390
239
  ```bash
391
240
  # Export metadata
@@ -404,14 +253,11 @@ with open('/tmp/metadata_fixed.json', 'w') as f:
404
253
  f.write(json.dumps(data))
405
254
  EOF
406
255
 
407
- # Update database (use Python to avoid escaping issues)
256
+ # Update database
408
257
  python3 << 'EOF'
409
- import sqlite3
410
- import json
411
-
258
+ import sqlite3, json
412
259
  with open('/tmp/metadata_fixed.json') as f:
413
260
  metadata = f.read()
414
-
415
261
  conn = sqlite3.connect('.codeyam/db.sqlite3')
416
262
  conn.execute("UPDATE scenarios SET metadata = ? WHERE id = 'SCENARIO_ID'", (metadata,))
417
263
  conn.commit()
@@ -419,252 +265,141 @@ conn.close()
419
265
  EOF
420
266
  ```
421
267
 
422
- ### For Category 4 (Code Generation Issues)
423
-
424
- **MUST be fixed locally by editing files in the tmp folder.** This is a REQUIRED step, not optional.
425
-
426
- 1. Go to Step 5a and fix all code issues in the tmp folder
427
- 2. Verify the scenario loads correctly (curl returns 200)
428
- 3. Run `codeyam recapture --capture-only` to capture screenshots (this preserves your fixes)
429
- 4. Verify the screenshots look correct
430
- 5. THEN document the engine bug in your final report
431
-
432
- **DO NOT stop after identifying a Category 4 issue.** The goal is to capture quality screenshots, then document what you fixed.
433
-
434
- ### Universal Mocks (for infrastructure dependencies)
435
-
436
- You can use universal mocks to mock out functions that are not detected by the analysis (are not part of the dependency tree). This often includes things like middleware or functions that run on startup and require environment variables.
437
-
438
- ## Quick Reference: Mock Path Decision Tree
439
-
440
- ```
441
- Where is the error coming from?
442
-
443
- ├── node_modules package (e.g., @prisma/client, @supabase/supabase-js)
444
- │ └── Mock path: .codeyam/universal-mocks/node_modules/{package}.ts
445
- │ Example: .codeyam/universal-mocks/node_modules/@prisma/client.ts
446
-
447
- └── Project file (e.g., lib/db.ts, packages/prisma/index.ts)
448
- └── Mock path: .codeyam/universal-mocks/{same-path-as-original}
449
- Example: .codeyam/universal-mocks/lib/db.ts
450
- Example: .codeyam/universal-mocks/packages/prisma/index.ts
451
- ```
452
-
453
- ## Quick Reference: Mock Writing Rules
454
-
455
- **BEFORE writing any mock:**
456
-
457
- 1. Read the original file first
458
- 2. Note all its export names exactly
459
-
460
- **WHEN writing the mock:**
461
-
462
- 1. Export names MUST match exactly (case-sensitive)
463
- 2. ALL code MUST be inside exports (no helper variables outside)
464
- 3. Keep it minimal - empty methods are fine
465
-
466
- **AFTER writing the mock:**
467
-
468
- ```bash
469
- codeyam validate-mock .codeyam/universal-mocks/{path-to-your-mock}
470
- ```
471
-
472
- ---
473
-
474
- ## Step 5: Verify Database Fixes Locally
475
-
476
- After making **database changes** (Categories 1-3):
477
-
478
- 1. **Re-run `codeyam debug ID`** to regenerate scenario files with updated data
479
- 2. **Start the dev server** and curl the URL to check for errors:
480
- ```bash
481
- curl -s http://localhost:3112/static/... | head -50
482
- ```
483
- 3. **Check for 200 response** (no `statusCode:500`)
484
-
485
- **If verification fails and you've already tried database fixes:** Proceed to Step 5a to fix code directly.
486
-
487
- ---
488
-
489
- ## Step 5a: Fix Code Issues in Tmp Folder (Category 4)
268
+ ### Category 4 (Code Generation Issues) — Edit Files Directly
490
269
 
491
- If the error is in bad imports, generated code or mock files, you can fix them directly in the tmp folder.
492
-
493
- **REMINDER: Only fix GENERATED files (mocks, layouts, routes)—never the client's application code.** If a client component crashes, the fix is in the mock data or mock code, not in the component itself.
494
-
495
- ### Locate the Problematic File
496
-
497
- Files are in `/tmp/codeyam/local-dev/{slug}/project/`. Common locations:
270
+ Fix generated files in `/tmp/codeyam/local-dev/{slug}/project/`. Common locations:
498
271
 
499
272
  - **Generated mocks**: `__codeyamMocks__/MockData_*.tsx` or `__codeyamMocks__/MockCode_*.tsx`
500
273
  - **Scenario layouts**: `app/static/{projectSlug}/{analysisId}/{entitySlug}/{scenarioSlug}/`
501
274
  - **Route files**: `app/routes/` or `pages/` depending on framework
502
275
 
503
- ### Make the Fix
504
-
505
- Edit the problematic file directly using the Edit tool. Common fixes include:
506
-
507
- - **Syntax errors**: Fix missing brackets, commas, or quotes in generated code
508
- - **Wrong import paths**: Correct import statements
509
- - **Missing exports**: Add missing named or default exports
510
- - **Type errors**: Fix TypeScript type issues
511
- - **Wrong mock structure**: Adjust the shape of generated mock data
276
+ Common fixes:
512
277
 
513
- ### Track Your Changes (MANDATORY)
278
+ - Syntax errors (missing brackets, commas, quotes)
279
+ - Wrong import paths
280
+ - Missing named or default exports
281
+ - TypeScript type issues
282
+ - Wrong mock data shape
514
283
 
515
- For every file you edit, record:
284
+ **Only fix GENERATED files** (mocks, layouts, routes) — never the client's application code. If a client component crashes, the fix is in the mock data or mock code.
516
285
 
517
- - The full file path
518
- - What you changed (brief description)
519
- - The before/after code (for the final report)
520
-
521
- ### Verify Without Regenerating
286
+ ### Universal Mocks (for infrastructure dependencies)
522
287
 
523
- After editing files, **do NOT run `codeyam debug` again** (it would overwrite your changes).
288
+ Use universal mocks to mock functions not in the dependency tree (middleware, startup functions needing env vars).
524
289
 
525
- Instead, manually start the dev server:
290
+ **Mock path decision tree:**
526
291
 
527
- ```bash
528
- cd /tmp/codeyam/local-dev/{slug}/project
529
- npm run dev # or pnpm dev / yarn dev
292
+ ```
293
+ Error source?
294
+ ├── node_modules package .codeyam/universal-mocks/node_modules/{package}.ts
295
+ │ Example: .codeyam/universal-mocks/node_modules/@prisma/client.ts
296
+ └── Project file → .codeyam/universal-mocks/{same-path-as-original}
297
+ Example: .codeyam/universal-mocks/lib/db.ts
530
298
  ```
531
299
 
532
- Then verify the fix works. You can either:
300
+ **Mock writing rules:**
533
301
 
534
- 1. **Curl the URL** to check for errors:
302
+ 1. Read the original file first, note all export names exactly
303
+ 2. Export names MUST match exactly (case-sensitive)
304
+ 3. ALL code MUST be inside exports (no helper variables outside)
305
+ 4. Keep it minimal — empty methods are fine
306
+ 5. Validate: `codeyam validate-mock .codeyam/universal-mocks/{path}`
535
307
 
536
- ```bash
537
- curl -s http://localhost:3112/static/codeyam-sample | head -50
538
- ```
308
+ ### Track All Changes (MANDATORY)
539
309
 
540
- 2. **Ask the user to verify visually**: If the fix involves visual output or you're unsure if it worked, ask the user to visit the URL and confirm:
310
+ For every change, record for the final report:
541
311
 
542
- > "I've fixed the mock data. Can you visit http://localhost:3112/static/codeyam-sample and let me know if the component renders correctly now?"
312
+ **Database changes:**
543
313
 
544
- This is especially useful for client-side rendering issues that curl won't catch.
314
+ | Table | Record ID | Field Path | Before | After |
315
+ | ----------- | --------- | ---------------------------- | --------- | ----------- |
316
+ | `scenarios` | `abc123` | `metadata.data.mockData.key` | `"wrong"` | `"correct"` |
545
317
 
546
- ---
318
+ **File changes:**
547
319
 
548
- ## Change Tracking (MANDATORY)
320
+ | File Path | Change Description |
321
+ | ---------------------------------------------------- | ------------------- |
322
+ | `/tmp/.../project/__codeyamMocks__/MockData_xyz.tsx` | Fixed missing comma |
549
323
 
550
- **You MUST track all changes for the final report.** This is essential for the CodeYam team to fix engine bugs.
324
+ Include actual diffs for file changes.
551
325
 
552
- ### Database Changes
326
+ ---
553
327
 
554
- For each database modification, record:
328
+ ## Step 6: Verify Fix
555
329
 
556
- | Table | Record ID | Field Path | Before | After |
557
- | ----------- | --------- | ---------------------------- | --------- | ----------- |
558
- | `scenarios` | `abc123` | `metadata.data.mockData.key` | `"wrong"` | `"correct"` |
330
+ ### After Database Changes (Categories 1-3)
559
331
 
560
- ### File Changes
332
+ 1. Re-run `codeyam debug ANALYSIS_ID` to regenerate files with updated data
333
+ 2. Curl the URL to check for errors:
334
+ ```bash
335
+ curl -s http://localhost:PORT/static/codeyam-sample | head -50
336
+ ```
337
+ 3. Check for 200 response (no `statusCode:500`)
561
338
 
562
- For each file modification in the tmp folder, record:
339
+ If verification fails after database fixes, proceed to fix files directly (Category 4 approach).
563
340
 
564
- | File Path | Change Description |
565
- | ---------------------------------------------------- | ------------------------------------- |
566
- | `/tmp/.../project/__codeyamMocks__/MockData_xyz.tsx` | Fixed missing comma in object literal |
341
+ ### After File Changes (Category 4)
567
342
 
568
- Include the actual diff:
343
+ **Do NOT run `codeyam debug` again** — it overwrites your changes.
569
344
 
570
- ```diff
571
- --- before
572
- +++ after
573
- @@ -10,3 +10,3 @@
574
- - key: "value"
575
- + key: "value",
576
- anotherKey: "value2"
577
- ```
345
+ 1. Start the dev server manually from the tmp folder
346
+ 2. Curl the URL to check for errors
347
+ 3. For visual/rendering issues, ask the user to verify: _"Can you visit http://localhost:PORT/static/codeyam-sample and confirm the component renders correctly?"_
578
348
 
579
349
  ---
580
350
 
581
- ## Step 6: Recapture Screenshots
582
-
583
- **Only proceed here if Step 5 or 5a verification passed.**
351
+ ## Step 7: Recapture & Verify Screenshots
584
352
 
585
- ### Choose the Right Recapture Mode
353
+ ### Choose Recapture Mode
586
354
 
587
- **If you only made DATABASE changes (Categories 1-3):**
355
+ **Database-only changes:**
588
356
 
589
357
  ```bash
590
358
  codeyam recapture SCENARIO_ID
591
359
  ```
592
360
 
593
- This will regenerate the tmp folder files using the updated database data, then capture screenshots.
594
-
595
- **If you made FILE changes in the tmp folder (Category 4):**
361
+ **File changes (or mixed):**
596
362
 
597
363
  ```bash
598
364
  codeyam recapture SCENARIO_ID --capture-only
599
365
  ```
600
366
 
601
- **CRITICAL**: The `--capture-only` flag preserves your manual file fixes. Without this flag, your changes would be overwritten!
602
-
603
- ### Verify Files After Capture
367
+ ### Verify Files Exist
604
368
 
605
369
  ```bash
606
- # Check database for screenshot paths
607
370
  sqlite3 .codeyam/db.sqlite3 "SELECT name, json_extract(metadata, '$.screenshotPaths') FROM scenarios WHERE analysis_id = 'ANALYSIS_ID'"
608
-
609
- # Verify files actually exist
610
371
  find .codeyam/captures -name "*.png" -path "*ANALYSIS_ID*" -mmin -5
611
372
  ```
612
373
 
613
- ---
614
-
615
- ## Step 7: Verify Screenshots for Client-Side Errors
616
-
617
- **IMPORTANT**: Even if capture completes successfully, the screenshots may show client-side errors!
618
-
619
- ### View the Screenshots
620
-
621
- Use the Read tool to view each captured screenshot file:
622
-
623
- ```bash
624
- # Get the screenshot path from the database
625
- sqlite3 .codeyam/db.sqlite3 "SELECT json_extract(metadata, '$.screenshotPaths[0]') FROM scenarios WHERE id = 'SCENARIO_ID'"
626
- ```
627
-
628
- Then read the screenshot file to visually inspect it.
374
+ ### Visually Inspect Screenshots
629
375
 
630
- ### Check for These Issues
376
+ Use the Read tool to view each screenshot. Check for:
631
377
 
632
- - **Red error boundaries** or React error overlays
633
- - **"Something went wrong"** or similar error text
634
- - **Blank/white screens** that should have content
635
- - **Missing components** or broken layouts
636
- - **Console errors** shown in error overlays
637
-
638
- If the screenshot shows a dedicated 500 page with no clear error then you may want to find and comment out any error boundary logic that is catching errors and preventing you from easily reading them.
378
+ - Red error boundaries or React error overlays
379
+ - "Something went wrong" or similar error text
380
+ - Blank/white screens that should have content
381
+ - Missing components or broken layouts
639
382
 
640
- ### If Screenshot Shows Errors
383
+ If the screenshot shows a dedicated 500 page with no clear error, consider commenting out error boundary logic to expose the real error.
641
384
 
642
- 1. The fix didn't fully work - go back to Step 5 or 5a
643
- 2. Check the log file for additional error details:
644
- ```bash
645
- tail -100 /tmp/codeyam/local-dev/{slug}/codeyam/log.txt
646
- ```
647
- 3. Fix the remaining issues
648
- 4. Run recapture again (with `--capture-only` if you edited files)
385
+ **If screenshots show errors:** Go back to Step 5, check the log file (`tail -100 /tmp/codeyam/local-dev/{slug}/codeyam/log.txt`), fix remaining issues, and recapture again.
649
386
 
650
387
  ---
651
388
 
652
- ## Final Debug Report (MANDATORY)
389
+ ## Reference
653
390
 
654
- **Always produce this report**, whether the issue was fixed or identified as an engine bug.
391
+ ### Debug Report Template
655
392
 
656
- ---
393
+ **Always produce this report** after debugging. Save to `.codeyam/debug-report.md`.
657
394
 
395
+ ```markdown
658
396
  ## Debug Session Report
659
397
 
660
398
  ### Issue Summary
661
399
 
662
- **Error:** `[Exact error message, e.g., "Transform failed: Unexpected token at line 66"]`
663
-
400
+ **Error:** `[Exact error message]`
664
401
  **Entity:** `[Entity name]` in `[file/path.tsx]`
665
-
666
402
  **Root Cause Category:** [1, 2, 3, or 4]
667
-
668
403
  **Outcome:** [Fixed via database changes / Fixed via file edits (engine bug) / Unfixable]
669
404
 
670
405
  ### Affected Scenarios
@@ -676,115 +411,58 @@ If the screenshot shows a dedicated 500 page with no clear error then you may wa
676
411
  ### Root Cause Category Determination
677
412
 
678
413
  **Category identified:** [1 / 2 / 3 / 4]
679
-
680
414
  **Evidence:**
681
415
 
682
- - [ ] **Category 1** (isolatedDataStructure): [What was missing/wrong in entity metadata?]
683
- - [ ] **Category 2** (mergedDataStructure): [What was missing/wrong after merge?]
684
- - [ ] **Category 3** (scenario mockData): [What was wrong in the LLM-generated data?]
685
- - [ ] **Category 4** (mock code writing): [What was wrong in the generated code?]
416
+ - [ ] **Category 1** (isolatedDataStructure): [What was missing/wrong?]
417
+ - [ ] **Category 2** (mergedDataStructure): [What was missing/wrong?]
418
+ - [ ] **Category 3** (scenario mockData): [What was wrong in LLM-generated data?]
419
+ - [ ] **Category 4** (mock code writing): [What was wrong in generated code?]
686
420
 
687
- **How determined:**
688
- [Explain what you checked and what you found. Include relevant JSON snippets.]
421
+ **How determined:** [Explain what you checked. Include relevant JSON snippets.]
689
422
 
690
423
  ### Database Changes Made (if any)
691
424
 
692
- | Table | Record ID | Field Path | Before | After |
693
- | --------- | --------- | ---------- | ------------- | ------------- |
694
- | `[table]` | `[id]` | `[path]` | `[old value]` | `[new value]` |
425
+ | Table | Record ID | Field Path | Before | After |
426
+ | --------- | --------- | ---------- | ------- | ------- |
427
+ | `[table]` | `[id]` | `[path]` | `[old]` | `[new]` |
695
428
 
696
429
  **SQL/Python commands used:**
697
-
698
- ```sql
699
- [Include the exact commands]
700
- ```
430
+ [Include exact commands]
701
431
 
702
432
  ### File Changes Made (if any)
703
433
 
704
- If you edited files in the tmp folder to fix Category 4 issues:
705
-
706
- | File Path | Change Description |
707
- | -------------------------------------------------------- | -------------------------- |
708
- | `/tmp/codeyam/local-dev/{slug}/project/path/to/file.tsx` | [Brief description of fix] |
434
+ | File Path | Change Description |
435
+ | -------------------------------------------------------- | ------------------- |
436
+ | `/tmp/codeyam/local-dev/{slug}/project/path/to/file.tsx` | [Brief description] |
709
437
 
710
438
  **Diffs:**
711
-
712
- ```diff
713
- --- before
714
- +++ after
715
- @@ -line,count +line,count @@
716
- -[old code]
717
- +[new code]
718
- ```
439
+ [Include actual diffs]
719
440
 
720
441
  **Recapture command used:**
442
+ `codeyam recapture SCENARIO_ID [--capture-only]`
721
443
 
722
- ```bash
723
- codeyam recapture SCENARIO_ID --capture-only
724
- ```
725
-
726
- ### For Category 4 (Code Generation Bug) - Required Details
444
+ ### For Category 4 — Required Details
727
445
 
728
- If this is an engine bug, include:
729
-
730
- **What the data looks like (correct):**
731
-
732
- ```json
733
- [Show the relevant data structure from the database that looks correct]
734
- ```
735
-
736
- **What the generated code looks like (wrong):**
737
-
738
- ```javascript
739
- [Show the problematic generated mock code]
740
- ```
741
-
742
- **What the generated code should look like:**
743
-
744
- ```javascript
745
- [Show what correct code would look like]
746
- ```
747
-
748
- **Pattern/Edge case:**
749
- [Describe the pattern that causes this bug, e.g., "Function call signatures like '()' in array item schemas get converted to empty computed property keys"]
446
+ **What the data looks like (correct):** [database data structure]
447
+ **What the generated code looks like (wrong):** [problematic code]
448
+ **What the generated code should look like:** [correct code]
449
+ **Pattern/Edge case:** [Describe the pattern that causes this bug]
750
450
 
751
451
  ### Verification
752
452
 
753
- **All of these must be checked before the debug session is complete:**
754
-
755
453
  - [ ] Scenario loads without errors (curl returns 200)
756
- - [ ] Screenshots recaptured successfully (this is REQUIRED, not optional)
454
+ - [ ] Screenshots recaptured successfully
757
455
  - [ ] Used `--capture-only` flag (if file changes were made)
758
456
  - [ ] Screenshot files verified to exist on disk
759
- - [ ] Screenshots visually inspected - no client-side errors visible
760
- - [ ] All changes documented above for CodeYam team
761
-
762
- ---
763
-
764
- ## Saving and Uploading the Report (MANDATORY)
765
-
766
- After completing the debug session, **you MUST save the report**:
767
-
768
- 1. **Write the report to file:**
769
-
770
- ```bash
771
- # Write the full "Debug Session Report" section above to this file
772
- # Use the Write tool to save to:
773
- .codeyam/debug-report.md
774
- ```
775
-
776
- 2. **Ask user if they want to upload:**
777
- After saving, ask the user: "Would you like me to upload this debug report to CodeYam for the team to review?"
778
-
779
- - If the user response affirmatively then run `codeyam report --upload` to upload the report.
780
-
781
- The report will be:
457
+ - [ ] Screenshots visually inspected no client-side errors visible
458
+ - [ ] All changes documented for CodeYam team
459
+ ```
782
460
 
783
- - Included in the delta tarball at the root level for easy access
784
- - Stored in the database metadata for searchability
785
- - Available to CodeYam engineers when they download the report
461
+ ### Saving & Uploading Report
786
462
 
787
- ---
463
+ 1. Save report to `.codeyam/debug-report.md`
464
+ 2. Ask user: "Would you like me to upload this debug report to CodeYam for the team to review?"
465
+ 3. If yes: `codeyam report --upload`
788
466
 
789
467
  ### Helper Queries
790
468