chati-dev 1.3.3 → 2.0.1

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 (215) hide show
  1. package/README.md +7 -6
  2. package/framework/agents/build/dev.md +343 -0
  3. package/framework/agents/clarity/architect.md +113 -0
  4. package/framework/agents/clarity/brief.md +183 -0
  5. package/framework/agents/clarity/brownfield-wu.md +182 -0
  6. package/framework/agents/clarity/detail.md +111 -0
  7. package/framework/agents/clarity/greenfield-wu.md +154 -0
  8. package/framework/agents/clarity/phases.md +1 -0
  9. package/framework/agents/clarity/tasks.md +1 -0
  10. package/framework/agents/clarity/ux.md +113 -0
  11. package/framework/agents/deploy/devops.md +1 -0
  12. package/framework/agents/quality/qa-implementation.md +1 -0
  13. package/framework/agents/quality/qa-planning.md +1 -0
  14. package/framework/config.yaml +3 -3
  15. package/framework/constitution.md +58 -1
  16. package/framework/context/governance.md +37 -0
  17. package/framework/context/protocols.md +34 -0
  18. package/framework/context/quality.md +27 -0
  19. package/framework/context/root.md +24 -0
  20. package/framework/data/entity-registry.yaml +1 -1
  21. package/framework/domains/agents/architect.yaml +51 -0
  22. package/framework/domains/agents/brief.yaml +47 -0
  23. package/framework/domains/agents/brownfield-wu.yaml +49 -0
  24. package/framework/domains/agents/detail.yaml +47 -0
  25. package/framework/domains/agents/dev.yaml +49 -0
  26. package/framework/domains/agents/devops.yaml +43 -0
  27. package/framework/domains/agents/greenfield-wu.yaml +47 -0
  28. package/framework/domains/agents/orchestrator.yaml +49 -0
  29. package/framework/domains/agents/phases.yaml +47 -0
  30. package/framework/domains/agents/qa-implementation.yaml +43 -0
  31. package/framework/domains/agents/qa-planning.yaml +44 -0
  32. package/framework/domains/agents/tasks.yaml +48 -0
  33. package/framework/domains/agents/ux.yaml +50 -0
  34. package/framework/domains/constitution.yaml +77 -0
  35. package/framework/domains/global.yaml +64 -0
  36. package/framework/domains/workflows/brownfield-discovery.yaml +16 -0
  37. package/framework/domains/workflows/brownfield-fullstack.yaml +26 -0
  38. package/framework/domains/workflows/brownfield-service.yaml +22 -0
  39. package/framework/domains/workflows/brownfield-ui.yaml +22 -0
  40. package/framework/domains/workflows/greenfield-fullstack.yaml +26 -0
  41. package/framework/hooks/constitution-guard.js +101 -0
  42. package/framework/hooks/mode-governance.js +92 -0
  43. package/framework/hooks/model-governance.js +76 -0
  44. package/framework/hooks/prism-engine.js +89 -0
  45. package/framework/hooks/session-digest.js +60 -0
  46. package/framework/hooks/settings.json +44 -0
  47. package/framework/i18n/en.yaml +3 -3
  48. package/framework/i18n/es.yaml +3 -3
  49. package/framework/i18n/fr.yaml +3 -3
  50. package/framework/i18n/pt.yaml +3 -3
  51. package/framework/intelligence/context-engine.md +2 -2
  52. package/framework/intelligence/decision-engine.md +1 -1
  53. package/framework/migrations/v1.4-to-v2.0.yaml +167 -0
  54. package/framework/migrations/v2.0-to-v2.0.1.yaml +132 -0
  55. package/framework/orchestrator/chati.md +350 -7
  56. package/framework/schemas/session.schema.json +15 -0
  57. package/framework/tasks/architect-api-design.md +63 -0
  58. package/framework/tasks/architect-consolidate.md +47 -0
  59. package/framework/tasks/architect-db-design.md +73 -0
  60. package/framework/tasks/architect-design.md +95 -0
  61. package/framework/tasks/architect-security-review.md +62 -0
  62. package/framework/tasks/architect-stack-selection.md +53 -0
  63. package/framework/tasks/brief-consolidate.md +249 -0
  64. package/framework/tasks/brief-constraint-identify.md +277 -0
  65. package/framework/tasks/brief-extract-requirements.md +339 -0
  66. package/framework/tasks/brief-stakeholder-map.md +176 -0
  67. package/framework/tasks/brief-validate-completeness.md +121 -0
  68. package/framework/tasks/brownfield-wu-architecture-map.md +394 -0
  69. package/framework/tasks/brownfield-wu-deep-discovery.md +312 -0
  70. package/framework/tasks/brownfield-wu-dependency-scan.md +359 -0
  71. package/framework/tasks/brownfield-wu-migration-plan.md +483 -0
  72. package/framework/tasks/brownfield-wu-report.md +325 -0
  73. package/framework/tasks/brownfield-wu-risk-assess.md +424 -0
  74. package/framework/tasks/detail-acceptance-criteria.md +372 -0
  75. package/framework/tasks/detail-consolidate.md +138 -0
  76. package/framework/tasks/detail-edge-case-analysis.md +300 -0
  77. package/framework/tasks/detail-expand-prd.md +389 -0
  78. package/framework/tasks/detail-nfr-extraction.md +223 -0
  79. package/framework/tasks/dev-code-review.md +404 -0
  80. package/framework/tasks/dev-consolidate.md +543 -0
  81. package/framework/tasks/dev-debug.md +322 -0
  82. package/framework/tasks/dev-implement.md +252 -0
  83. package/framework/tasks/dev-iterate.md +411 -0
  84. package/framework/tasks/dev-pr-prepare.md +497 -0
  85. package/framework/tasks/dev-refactor.md +342 -0
  86. package/framework/tasks/dev-test-write.md +306 -0
  87. package/framework/tasks/devops-ci-setup.md +412 -0
  88. package/framework/tasks/devops-consolidate.md +712 -0
  89. package/framework/tasks/devops-deploy-config.md +598 -0
  90. package/framework/tasks/devops-monitoring-setup.md +658 -0
  91. package/framework/tasks/devops-release-prepare.md +673 -0
  92. package/framework/tasks/greenfield-wu-analyze-empty.md +169 -0
  93. package/framework/tasks/greenfield-wu-report.md +266 -0
  94. package/framework/tasks/greenfield-wu-scaffold-detection.md +203 -0
  95. package/framework/tasks/greenfield-wu-tech-stack-assess.md +255 -0
  96. package/framework/tasks/orchestrator-deviation.md +260 -0
  97. package/framework/tasks/orchestrator-escalate.md +276 -0
  98. package/framework/tasks/orchestrator-handoff.md +243 -0
  99. package/framework/tasks/orchestrator-health.md +372 -0
  100. package/framework/tasks/orchestrator-mode-switch.md +262 -0
  101. package/framework/tasks/orchestrator-resume.md +189 -0
  102. package/framework/tasks/orchestrator-route.md +169 -0
  103. package/framework/tasks/orchestrator-spawn-terminal.md +358 -0
  104. package/framework/tasks/orchestrator-status.md +260 -0
  105. package/framework/tasks/orchestrator-suggest-mode.md +372 -0
  106. package/framework/tasks/phases-breakdown.md +91 -0
  107. package/framework/tasks/phases-dependency-mapping.md +67 -0
  108. package/framework/tasks/phases-mvp-scoping.md +94 -0
  109. package/framework/tasks/qa-impl-consolidate.md +522 -0
  110. package/framework/tasks/qa-impl-performance-test.md +487 -0
  111. package/framework/tasks/qa-impl-regression-check.md +413 -0
  112. package/framework/tasks/qa-impl-sast-scan.md +402 -0
  113. package/framework/tasks/qa-impl-test-execute.md +344 -0
  114. package/framework/tasks/qa-impl-verdict.md +339 -0
  115. package/framework/tasks/qa-planning-consolidate.md +309 -0
  116. package/framework/tasks/qa-planning-coverage-plan.md +338 -0
  117. package/framework/tasks/qa-planning-gate-define.md +339 -0
  118. package/framework/tasks/qa-planning-risk-matrix.md +631 -0
  119. package/framework/tasks/qa-planning-test-strategy.md +217 -0
  120. package/framework/tasks/tasks-acceptance-write.md +75 -0
  121. package/framework/tasks/tasks-consolidate.md +57 -0
  122. package/framework/tasks/tasks-decompose.md +80 -0
  123. package/framework/tasks/tasks-estimate.md +66 -0
  124. package/framework/tasks/ux-a11y-check.md +49 -0
  125. package/framework/tasks/ux-component-map.md +55 -0
  126. package/framework/tasks/ux-consolidate.md +46 -0
  127. package/framework/tasks/ux-user-flow.md +46 -0
  128. package/framework/tasks/ux-wireframe.md +76 -0
  129. package/package.json +1 -1
  130. package/scripts/bundle-framework.js +2 -0
  131. package/scripts/changelog-generator.js +222 -0
  132. package/scripts/codebase-mapper.js +728 -0
  133. package/scripts/commit-message-generator.js +167 -0
  134. package/scripts/coverage-analyzer.js +260 -0
  135. package/scripts/dependency-analyzer.js +280 -0
  136. package/scripts/framework-analyzer.js +308 -0
  137. package/scripts/generate-constitution-domain.js +253 -0
  138. package/scripts/health-check.js +481 -0
  139. package/scripts/ide-sync.js +327 -0
  140. package/scripts/performance-analyzer.js +325 -0
  141. package/scripts/plan-tracker.js +278 -0
  142. package/scripts/populate-entity-registry.js +481 -0
  143. package/scripts/pr-review.js +317 -0
  144. package/scripts/rollback-manager.js +310 -0
  145. package/scripts/stuck-detector.js +343 -0
  146. package/scripts/test-quality-assessment.js +257 -0
  147. package/scripts/validate-agents.js +367 -0
  148. package/scripts/validate-tasks.js +465 -0
  149. package/src/autonomy/autonomous-gate.js +293 -0
  150. package/src/autonomy/index.js +51 -0
  151. package/src/autonomy/mode-manager.js +225 -0
  152. package/src/autonomy/mode-suggester.js +283 -0
  153. package/src/autonomy/progress-reporter.js +268 -0
  154. package/src/autonomy/safety-net.js +320 -0
  155. package/src/context/bracket-tracker.js +79 -0
  156. package/src/context/domain-loader.js +107 -0
  157. package/src/context/engine.js +144 -0
  158. package/src/context/formatter.js +184 -0
  159. package/src/context/index.js +4 -0
  160. package/src/context/layers/l0-constitution.js +28 -0
  161. package/src/context/layers/l1-global.js +37 -0
  162. package/src/context/layers/l2-agent.js +39 -0
  163. package/src/context/layers/l3-workflow.js +42 -0
  164. package/src/context/layers/l4-task.js +24 -0
  165. package/src/decision/analyzer.js +167 -0
  166. package/src/decision/engine.js +270 -0
  167. package/src/decision/index.js +38 -0
  168. package/src/decision/registry-healer.js +450 -0
  169. package/src/decision/registry-updater.js +330 -0
  170. package/src/gates/circuit-breaker.js +119 -0
  171. package/src/gates/g1-planning-complete.js +153 -0
  172. package/src/gates/g2-qa-planning.js +153 -0
  173. package/src/gates/g3-implementation.js +188 -0
  174. package/src/gates/g4-qa-implementation.js +207 -0
  175. package/src/gates/g5-deploy-ready.js +180 -0
  176. package/src/gates/gate-base.js +144 -0
  177. package/src/gates/index.js +46 -0
  178. package/src/installer/brownfield-upgrader.js +249 -0
  179. package/src/installer/core.js +55 -3
  180. package/src/installer/file-hasher.js +51 -0
  181. package/src/installer/manifest.js +117 -0
  182. package/src/installer/templates.js +17 -15
  183. package/src/installer/transaction.js +229 -0
  184. package/src/installer/validator.js +18 -1
  185. package/src/intelligence/registry-manager.js +2 -2
  186. package/src/memory/agent-memory.js +255 -0
  187. package/src/memory/gotchas-injector.js +72 -0
  188. package/src/memory/gotchas.js +361 -0
  189. package/src/memory/index.js +35 -0
  190. package/src/memory/search.js +233 -0
  191. package/src/memory/session-digest.js +239 -0
  192. package/src/merger/env-merger.js +112 -0
  193. package/src/merger/index.js +56 -0
  194. package/src/merger/replace-merger.js +51 -0
  195. package/src/merger/yaml-merger.js +127 -0
  196. package/src/orchestrator/agent-selector.js +285 -0
  197. package/src/orchestrator/deviation-handler.js +350 -0
  198. package/src/orchestrator/handoff-engine.js +271 -0
  199. package/src/orchestrator/index.js +67 -0
  200. package/src/orchestrator/intent-classifier.js +264 -0
  201. package/src/orchestrator/pipeline-manager.js +492 -0
  202. package/src/orchestrator/pipeline-state.js +223 -0
  203. package/src/orchestrator/session-manager.js +409 -0
  204. package/src/tasks/executor.js +195 -0
  205. package/src/tasks/handoff.js +226 -0
  206. package/src/tasks/index.js +4 -0
  207. package/src/tasks/loader.js +210 -0
  208. package/src/tasks/router.js +182 -0
  209. package/src/terminal/collector.js +216 -0
  210. package/src/terminal/index.js +30 -0
  211. package/src/terminal/isolation.js +129 -0
  212. package/src/terminal/monitor.js +277 -0
  213. package/src/terminal/spawner.js +269 -0
  214. package/src/upgrade/checker.js +1 -1
  215. package/src/wizard/i18n.js +3 -3
@@ -0,0 +1,322 @@
1
+ ---
2
+ id: dev-debug
3
+ agent: dev
4
+ trigger: dev-refactor
5
+ phase: build
6
+ requires_input: false
7
+ parallelizable: false
8
+ outputs: [debug-log]
9
+ handoff_to: dev-code-review
10
+ autonomous_gate: true
11
+ criteria:
12
+ - All tests passing
13
+ - No runtime errors
14
+ ---
15
+ # Debug and Fix
16
+
17
+ ## Purpose
18
+ Identify and resolve any failing tests, runtime errors, or unexpected behaviors discovered during or after refactoring.
19
+
20
+ ## Prerequisites
21
+ - Refactoring complete
22
+ - Test suite available
23
+ - Refactor report exists
24
+ - Source maps configured
25
+ - Debugging tools available
26
+
27
+ ## Steps
28
+
29
+ ### 1. Run Full Test Suite
30
+ Execute all tests to identify failures:
31
+ ```bash
32
+ npm test
33
+ ```
34
+ - Record which tests fail
35
+ - Note error messages
36
+ - Identify patterns in failures
37
+ - Check for flaky tests
38
+ - Document success rate
39
+
40
+ ### 2. Analyze Test Failures
41
+ Understand why tests are failing:
42
+ - Read error messages carefully
43
+ - Check stack traces
44
+ - Identify failed assertions
45
+ - Review test expectations
46
+ - Compare expected vs actual output
47
+
48
+ ### 3. Reproduce Issues Locally
49
+ Isolate failing tests:
50
+ ```bash
51
+ npm test -- --testNamePattern="specific test"
52
+ ```
53
+ - Run individual tests
54
+ - Add console.log for debugging
55
+ - Use debugger breakpoints
56
+ - Inspect intermediate values
57
+ - Verify test setup
58
+
59
+ ### 4. Check Recent Changes
60
+ Review what changed:
61
+ - Compare with last working state
62
+ - Check refactoring changes
63
+ - Review type changes
64
+ - Inspect renamed functions
65
+ - Verify imports updated
66
+
67
+ ### 5. Add Diagnostic Logging
68
+ Insert strategic log statements:
69
+ ```typescript
70
+ console.log('Input:', JSON.stringify(input, null, 2));
71
+ console.log('Processing step 1 complete');
72
+ console.log('Output:', JSON.stringify(output, null, 2));
73
+ ```
74
+ - Log function entry/exit
75
+ - Log intermediate values
76
+ - Log conditional branches taken
77
+ - Log error conditions
78
+ - Remove logs after debugging
79
+
80
+ ### 6. Use Interactive Debugger
81
+ For complex issues, use debugger:
82
+ - Set breakpoints in IDE
83
+ - Step through execution
84
+ - Inspect variable values
85
+ - Watch expressions
86
+ - Examine call stack
87
+
88
+ ### 7. Fix Root Causes
89
+ Address underlying issues:
90
+ - Fix logic errors
91
+ - Correct type mismatches
92
+ - Update broken references
93
+ - Repair data flow
94
+ - Resolve timing issues
95
+
96
+ Common fixes:
97
+ ```typescript
98
+ // Fix async handling
99
+ await someAsyncFunction(); // Don't forget await
100
+
101
+ // Fix null checks
102
+ if (value !== null && value !== undefined) { }
103
+
104
+ // Fix type assertions
105
+ const typed = value as ExpectedType;
106
+
107
+ // Fix array operations
108
+ const items = array.filter(item => item !== null);
109
+ ```
110
+
111
+ ### 8. Fix Flaky Tests
112
+ Address intermittent failures:
113
+ - Identify timing dependencies
114
+ - Add proper waits/delays
115
+ - Mock time-dependent functions
116
+ - Ensure proper cleanup
117
+ - Reset state between tests
118
+
119
+ ### 9. Update Tests if Needed
120
+ Sometimes tests need fixing, not code:
121
+ - Check if expectations are still valid
122
+ - Update mocks if interfaces changed
123
+ - Fix test setup
124
+ - Adjust assertions
125
+ - Update test data
126
+
127
+ ### 10. Verify Fixes
128
+ Confirm issues resolved:
129
+ - Run failing test multiple times
130
+ - Run full suite
131
+ - Check for new failures
132
+ - Verify coverage maintained
133
+ - Test in different scenarios
134
+
135
+ ### 11. Test Runtime Scenarios
136
+ Beyond unit tests, verify runtime behavior:
137
+ - Start the application
138
+ - Exercise the new feature
139
+ - Check console for errors
140
+ - Verify expected behavior
141
+ - Test error cases manually
142
+
143
+ ### 12. Document Debugging Process
144
+ Record issues and solutions:
145
+ - List bugs found
146
+ - Note root causes
147
+ - Document fixes applied
148
+ - Record lessons learned
149
+ - Update tests or code comments
150
+
151
+ ## Decision Points
152
+
153
+ ### When Root Cause is Unclear
154
+ If you can't identify the problem:
155
+ 1. Add more logging
156
+ 2. Simplify the test case
157
+ 3. Remove complexity incrementally
158
+ 4. Compare with working code
159
+ 5. Ask for user input if stuck
160
+
161
+ ### When Fix Would Be Major
162
+ If fix requires significant changes:
163
+ 1. Document the issue
164
+ 2. Assess impact
165
+ 3. Propose solution to user
166
+ 4. May need to revisit architecture
167
+ 5. Don't make large changes without approval
168
+
169
+ ### When Tests Need Updating
170
+ Determine if test or code is wrong:
171
+ 1. Review acceptance criteria
172
+ 2. Check if behavior intentionally changed
173
+ 3. Verify test assumptions
174
+ 4. Update test if refactor changed behavior correctly
175
+ 5. Fix code if behavior is wrong
176
+
177
+ ## Error Handling
178
+
179
+ ### Cannot Reproduce Failure
180
+ - Check test isolation
181
+ - Verify environment setup
182
+ - Clear caches and rebuild
183
+ - Check for timing issues
184
+ - Run tests multiple times
185
+
186
+ ### Debugger Not Working
187
+ - Verify source maps configured
188
+ - Check IDE debugger setup
189
+ - Use console.log as fallback
190
+ - Ensure breakpoints in executed code
191
+ - Check for minification issues
192
+
193
+ ### Cascading Failures
194
+ When one fix breaks other tests:
195
+ - Run tests after each fix
196
+ - Commit working states
197
+ - Use git to track changes
198
+ - Fix issues incrementally
199
+ - Consider reverting and retrying
200
+
201
+ ### Performance Issues
202
+ If debugging reveals performance problems:
203
+ - Profile the code
204
+ - Identify bottlenecks
205
+ - Note for optimization later
206
+ - Don't optimize prematurely
207
+ - Document performance concerns
208
+
209
+ ## Output Format
210
+
211
+ Create `.chati/artifacts/build/debug-log.yaml`:
212
+
213
+ ```yaml
214
+ task_id: "3.2.1"
215
+ agent: dev
216
+ action: debug
217
+ timestamp: "2026-02-13T12:45:00Z"
218
+ duration_minutes: 30
219
+
220
+ initial_test_status:
221
+ total_tests: 20
222
+ passing: 17
223
+ failing: 3
224
+ flaky: 0
225
+
226
+ failures_identified:
227
+ - test: "ChatService should emit message event on send"
228
+ file: "chat-service.test.ts"
229
+ error: "Expected emit to be called with 'message', but was not called"
230
+ category: logic_error
231
+ - test: "should sanitize HTML in messages"
232
+ file: "chat-service.test.ts"
233
+ error: "TypeError: sanitizeHtml is not a function"
234
+ category: refactor_issue
235
+ - test: "Integration: WebSocket receives new messages"
236
+ file: "chat-integration.test.ts"
237
+ error: "Timeout: async callback not invoked within 5000ms"
238
+ category: async_issue
239
+
240
+ debugging_steps:
241
+ - issue: "Missing emit call"
242
+ approach: "Added logging to trace execution flow"
243
+ finding: "Event emission code removed during refactoring"
244
+ fix: "Re-added this.emit('message', message) call"
245
+ - issue: "sanitizeHtml not a function"
246
+ approach: "Checked imports after refactoring"
247
+ finding: "Import statement not updated when function moved"
248
+ fix: "Updated import to reference new validators.ts module"
249
+ - issue: "WebSocket timeout"
250
+ approach: "Used debugger to step through async flow"
251
+ finding: "Promise never resolved due to missing await"
252
+ fix: "Added await to async WebSocket send call"
253
+
254
+ fixes_applied:
255
+ - file: "src/modules/chat/chat-service.ts"
256
+ change: "Re-added event emission after message save"
257
+ lines_changed: 2
258
+ - file: "src/modules/chat/chat-service.ts"
259
+ change: "Fixed import path for sanitizeHtml"
260
+ lines_changed: 1
261
+ - file: "src/modules/chat/chat-service.ts"
262
+ change: "Added await to WebSocket broadcast"
263
+ lines_changed: 1
264
+
265
+ tests_updated:
266
+ - file: "chat-service.test.ts"
267
+ change: "Updated mock setup for new module structure"
268
+ reason: "Test assumptions outdated after refactoring"
269
+ - file: "chat-integration.test.ts"
270
+ change: "Increased timeout to 10000ms for WebSocket test"
271
+ reason: "Integration test needs more time in CI environment"
272
+
273
+ runtime_verification:
274
+ - scenario: "Send message via API"
275
+ result: success
276
+ notes: "Message persisted and broadcast correctly"
277
+ - scenario: "Send message with HTML"
278
+ result: success
279
+ notes: "HTML properly sanitized"
280
+ - scenario: "Send empty message"
281
+ result: success
282
+ notes: "Validation error thrown as expected"
283
+
284
+ final_test_status:
285
+ total_tests: 20
286
+ passing: 20
287
+ failing: 0
288
+ flaky: 0
289
+ coverage: 89.2
290
+
291
+ lessons_learned:
292
+ - "Always update imports when moving functions during refactoring"
293
+ - "Verify async operations have proper await keywords"
294
+ - "Test event emission explicitly, don't assume it works"
295
+ - "Integration tests may need longer timeouts in CI"
296
+
297
+ remaining_issues:
298
+ - description: "WebSocket test still occasionally times out"
299
+ severity: low
300
+ status: monitoring
301
+ plan: "May need to mock WebSocket in tests"
302
+
303
+ code_quality_after_fixes:
304
+ lint_status: pass
305
+ type_check_status: pass
306
+ compilation_status: pass
307
+ test_status: pass
308
+
309
+ next_steps:
310
+ - "Perform self code review"
311
+ - "Check against architecture and standards"
312
+ - "Prepare for PR"
313
+ ```
314
+
315
+ ## Success Criteria
316
+ - All tests pass consistently
317
+ - No runtime errors when exercising features
318
+ - Code compiles without errors
319
+ - Type checking passes
320
+ - Linting passes
321
+ - Debug log documents all issues found and fixed
322
+ - No known bugs remain
@@ -0,0 +1,252 @@
1
+ ---
2
+ id: dev-implement
3
+ agent: dev
4
+ trigger: orchestrator
5
+ phase: build
6
+ requires_input: false
7
+ parallelizable: true
8
+ outputs: [source-code]
9
+ handoff_to: dev-test-write
10
+ autonomous_gate: true
11
+ criteria:
12
+ - Code compiles without errors
13
+ - All acceptance criteria implemented
14
+ - No lint errors
15
+ ---
16
+ # Implement Feature
17
+
18
+ ## Purpose
19
+ Transform acceptance criteria from the task specification into working source code, following the project's architecture and coding standards.
20
+
21
+ ## Prerequisites
22
+ - Task specification exists in `.chati/state/current-task.yaml`
23
+ - Architecture decisions documented in `.chati/artifacts/architecture/`
24
+ - Development environment configured
25
+ - Dependencies installed
26
+ - IDE ready with proper extensions
27
+
28
+ ## Steps
29
+
30
+ ### 1. Load Task Context
31
+ Read the current task specification to understand:
32
+ - Acceptance criteria (Given-When-Then format)
33
+ - Affected components
34
+ - Data models
35
+ - API contracts
36
+ - UI requirements
37
+
38
+ ### 2. Review Architecture Constraints
39
+ Examine architecture artifacts to ensure compliance with:
40
+ - Folder structure conventions
41
+ - Module boundaries
42
+ - Design patterns in use
43
+ - Technology stack choices
44
+ - State management approach
45
+
46
+ ### 3. Identify Existing Patterns
47
+ Search the codebase for similar implementations:
48
+ - Use Grep to find comparable features
49
+ - Analyze existing component structure
50
+ - Identify reusable utilities
51
+ - Note naming conventions
52
+ - Review error handling patterns
53
+
54
+ ### 4. Plan Implementation Approach
55
+ Create a mental model of:
56
+ - Which files need creation vs modification
57
+ - Component hierarchy
58
+ - Data flow
59
+ - Side effects and state changes
60
+ - Integration points
61
+
62
+ ### 5. Implement Core Logic
63
+ Write the primary functionality:
64
+ - Start with data layer (models, schemas, types)
65
+ - Implement business logic (services, utilities)
66
+ - Add API endpoints or handlers
67
+ - Follow single responsibility principle
68
+ - Keep functions focused and testable
69
+
70
+ ### 6. Implement User-Facing Layer
71
+ Add presentation or interface components:
72
+ - UI components (if applicable)
73
+ - CLI commands (if applicable)
74
+ - API response formatting
75
+ - Validation and sanitization
76
+ - User feedback mechanisms
77
+
78
+ ### 7. Add Error Handling
79
+ Implement comprehensive error management:
80
+ - Try-catch blocks around risky operations
81
+ - Meaningful error messages
82
+ - Proper error propagation
83
+ - Fallback behaviors
84
+ - Logging for debugging
85
+
86
+ ### 8. Add Type Safety
87
+ Ensure full type coverage:
88
+ - TypeScript interfaces for all data structures
89
+ - Type guards where needed
90
+ - Avoid `any` types
91
+ - Use generics appropriately
92
+ - Document complex types
93
+
94
+ ### 9. Add Documentation
95
+ Document the implementation:
96
+ - JSDoc comments for public APIs
97
+ - Inline comments for complex logic
98
+ - README updates if needed
99
+ - Code examples in comments
100
+ - Architecture decision records
101
+
102
+ ### 10. Verify Compilation
103
+ Check that code compiles:
104
+ - Run `npm run build` or equivalent
105
+ - Fix any TypeScript errors
106
+ - Resolve import issues
107
+ - Check for unused variables
108
+ - Validate syntax
109
+
110
+ ### 11. Run Linting
111
+ Ensure code style compliance:
112
+ - Run `npm run lint`
113
+ - Fix any style violations
114
+ - Apply auto-fixes where safe
115
+ - Verify naming conventions
116
+ - Check formatting
117
+
118
+ ### 12. Create Implementation Log
119
+ Document what was built:
120
+ - List files created
121
+ - List files modified
122
+ - Note design decisions
123
+ - Record any deviations from spec
124
+ - Flag items needing review
125
+
126
+ ## Decision Points
127
+
128
+ ### When Architecture is Unclear
129
+ If the architecture doesn't specify how to implement something:
130
+ 1. Document the ambiguity
131
+ 2. Propose 2-3 approaches
132
+ 3. Use AskUserQuestion tool
133
+ 4. Record decision in `.chati/artifacts/decisions/`
134
+
135
+ ### When Dependencies are Missing
136
+ If required libraries aren't available:
137
+ 1. Check package.json for alternatives
138
+ 2. Propose dependency additions
139
+ 3. Get user approval before installing
140
+ 4. Document dependency purpose
141
+
142
+ ### When Spec is Ambiguous
143
+ If acceptance criteria are unclear:
144
+ 1. Implement the most reasonable interpretation
145
+ 2. Add TODO comments marking assumptions
146
+ 3. Flag for QA review
147
+ 4. Document in implementation log
148
+
149
+ ## Error Handling
150
+
151
+ ### Compilation Errors
152
+ - Read error messages carefully
153
+ - Check import paths
154
+ - Verify type definitions exist
155
+ - Ensure all dependencies installed
156
+ - Review tsconfig.json settings
157
+
158
+ ### Lint Failures
159
+ - Apply auto-fix first: `npm run lint -- --fix`
160
+ - Review remaining errors manually
161
+ - Check for unused variables
162
+ - Verify naming conventions
163
+ - Fix formatting issues
164
+
165
+ ### Integration Issues
166
+ - Verify API contracts match
167
+ - Check data flow assumptions
168
+ - Test integration points manually
169
+ - Add logging to trace data
170
+ - Review component boundaries
171
+
172
+ ### Performance Concerns
173
+ - Profile critical paths if needed
174
+ - Avoid premature optimization
175
+ - Document performance decisions
176
+ - Flag expensive operations
177
+ - Consider lazy loading
178
+
179
+ ## Output Format
180
+
181
+ Create `.chati/artifacts/build/implementation-log.yaml`:
182
+
183
+ ```yaml
184
+ task_id: "3.2.1"
185
+ agent: dev
186
+ action: implement
187
+ timestamp: "2026-02-13T10:30:00Z"
188
+ duration_minutes: 45
189
+
190
+ files_created:
191
+ - path: "src/modules/chat/chat-service.ts"
192
+ lines: 156
193
+ purpose: "Core chat message handling"
194
+ - path: "src/modules/chat/types.ts"
195
+ lines: 42
196
+ purpose: "Chat domain types"
197
+
198
+ files_modified:
199
+ - path: "src/index.ts"
200
+ changes: "Added chat module export"
201
+ lines_added: 3
202
+ - path: "src/types/global.d.ts"
203
+ changes: "Extended global chat types"
204
+ lines_added: 12
205
+
206
+ acceptance_criteria_met:
207
+ - id: "AC-1"
208
+ description: "Chat messages persist to database"
209
+ status: implemented
210
+ - id: "AC-2"
211
+ description: "Real-time updates via WebSocket"
212
+ status: implemented
213
+ - id: "AC-3"
214
+ description: "Message validation and sanitization"
215
+ status: implemented
216
+
217
+ design_decisions:
218
+ - decision: "Used EventEmitter for message broadcasting"
219
+ rationale: "Simpler than Redux for this use case"
220
+ alternatives_considered: ["Redux", "MobX"]
221
+ - decision: "SQLite for message storage"
222
+ rationale: "Lightweight, embedded, sufficient for MVP"
223
+ alternatives_considered: ["PostgreSQL", "MongoDB"]
224
+
225
+ deviations_from_spec:
226
+ - description: "Added message edit capability"
227
+ reason: "User feedback indicated this was critical"
228
+ approved_by: "user"
229
+
230
+ technical_debt:
231
+ - description: "Message pagination not optimized"
232
+ impact: "May slow with 1000+ messages"
233
+ planned_fix: "Implement virtual scrolling in Phase 4"
234
+
235
+ compilation_status: success
236
+ lint_status: success
237
+ type_check_status: success
238
+
239
+ next_steps:
240
+ - "Write tests for chat-service.ts"
241
+ - "Add integration tests for WebSocket flow"
242
+ - "Document chat API in README"
243
+ ```
244
+
245
+ ## Success Criteria
246
+ - All code compiles without errors
247
+ - All lint checks pass
248
+ - All acceptance criteria have corresponding implementation
249
+ - Implementation log is complete and accurate
250
+ - Code follows project conventions
251
+ - Error handling is comprehensive
252
+ - Types are fully specified