chati-dev 1.4.0 → 2.0.2

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 (208) hide show
  1. package/README.md +40 -24
  2. package/framework/agents/build/dev.md +343 -0
  3. package/framework/agents/clarity/architect.md +112 -0
  4. package/framework/agents/clarity/brief.md +182 -0
  5. package/framework/agents/clarity/brownfield-wu.md +181 -0
  6. package/framework/agents/clarity/detail.md +110 -0
  7. package/framework/agents/clarity/greenfield-wu.md +153 -0
  8. package/framework/agents/clarity/ux.md +112 -0
  9. package/framework/config.yaml +3 -3
  10. package/framework/constitution.md +31 -1
  11. package/framework/context/governance.md +37 -0
  12. package/framework/context/protocols.md +34 -0
  13. package/framework/context/quality.md +27 -0
  14. package/framework/context/root.md +24 -0
  15. package/framework/data/entity-registry.yaml +1 -1
  16. package/framework/domains/agents/architect.yaml +51 -0
  17. package/framework/domains/agents/brief.yaml +47 -0
  18. package/framework/domains/agents/brownfield-wu.yaml +49 -0
  19. package/framework/domains/agents/detail.yaml +47 -0
  20. package/framework/domains/agents/dev.yaml +49 -0
  21. package/framework/domains/agents/devops.yaml +43 -0
  22. package/framework/domains/agents/greenfield-wu.yaml +47 -0
  23. package/framework/domains/agents/orchestrator.yaml +49 -0
  24. package/framework/domains/agents/phases.yaml +47 -0
  25. package/framework/domains/agents/qa-implementation.yaml +43 -0
  26. package/framework/domains/agents/qa-planning.yaml +44 -0
  27. package/framework/domains/agents/tasks.yaml +48 -0
  28. package/framework/domains/agents/ux.yaml +50 -0
  29. package/framework/domains/constitution.yaml +77 -0
  30. package/framework/domains/global.yaml +64 -0
  31. package/framework/domains/workflows/brownfield-discovery.yaml +16 -0
  32. package/framework/domains/workflows/brownfield-fullstack.yaml +26 -0
  33. package/framework/domains/workflows/brownfield-service.yaml +22 -0
  34. package/framework/domains/workflows/brownfield-ui.yaml +22 -0
  35. package/framework/domains/workflows/greenfield-fullstack.yaml +26 -0
  36. package/framework/hooks/constitution-guard.js +101 -0
  37. package/framework/hooks/mode-governance.js +92 -0
  38. package/framework/hooks/model-governance.js +76 -0
  39. package/framework/hooks/prism-engine.js +89 -0
  40. package/framework/hooks/session-digest.js +60 -0
  41. package/framework/hooks/settings.json +44 -0
  42. package/framework/i18n/en.yaml +3 -3
  43. package/framework/i18n/es.yaml +3 -3
  44. package/framework/i18n/fr.yaml +3 -3
  45. package/framework/i18n/pt.yaml +3 -3
  46. package/framework/intelligence/decision-engine.md +1 -1
  47. package/framework/migrations/v1.4-to-v2.0.yaml +167 -0
  48. package/framework/migrations/v2.0-to-v2.0.1.yaml +132 -0
  49. package/framework/orchestrator/chati.md +284 -6
  50. package/framework/tasks/architect-api-design.md +63 -0
  51. package/framework/tasks/architect-consolidate.md +47 -0
  52. package/framework/tasks/architect-db-design.md +73 -0
  53. package/framework/tasks/architect-design.md +95 -0
  54. package/framework/tasks/architect-security-review.md +62 -0
  55. package/framework/tasks/architect-stack-selection.md +53 -0
  56. package/framework/tasks/brief-consolidate.md +249 -0
  57. package/framework/tasks/brief-constraint-identify.md +277 -0
  58. package/framework/tasks/brief-extract-requirements.md +339 -0
  59. package/framework/tasks/brief-stakeholder-map.md +176 -0
  60. package/framework/tasks/brief-validate-completeness.md +121 -0
  61. package/framework/tasks/brownfield-wu-architecture-map.md +394 -0
  62. package/framework/tasks/brownfield-wu-deep-discovery.md +312 -0
  63. package/framework/tasks/brownfield-wu-dependency-scan.md +359 -0
  64. package/framework/tasks/brownfield-wu-migration-plan.md +483 -0
  65. package/framework/tasks/brownfield-wu-report.md +325 -0
  66. package/framework/tasks/brownfield-wu-risk-assess.md +424 -0
  67. package/framework/tasks/detail-acceptance-criteria.md +372 -0
  68. package/framework/tasks/detail-consolidate.md +138 -0
  69. package/framework/tasks/detail-edge-case-analysis.md +300 -0
  70. package/framework/tasks/detail-expand-prd.md +389 -0
  71. package/framework/tasks/detail-nfr-extraction.md +223 -0
  72. package/framework/tasks/dev-code-review.md +404 -0
  73. package/framework/tasks/dev-consolidate.md +543 -0
  74. package/framework/tasks/dev-debug.md +322 -0
  75. package/framework/tasks/dev-implement.md +252 -0
  76. package/framework/tasks/dev-iterate.md +411 -0
  77. package/framework/tasks/dev-pr-prepare.md +497 -0
  78. package/framework/tasks/dev-refactor.md +342 -0
  79. package/framework/tasks/dev-test-write.md +306 -0
  80. package/framework/tasks/devops-ci-setup.md +412 -0
  81. package/framework/tasks/devops-consolidate.md +712 -0
  82. package/framework/tasks/devops-deploy-config.md +598 -0
  83. package/framework/tasks/devops-monitoring-setup.md +658 -0
  84. package/framework/tasks/devops-release-prepare.md +673 -0
  85. package/framework/tasks/greenfield-wu-analyze-empty.md +169 -0
  86. package/framework/tasks/greenfield-wu-report.md +266 -0
  87. package/framework/tasks/greenfield-wu-scaffold-detection.md +203 -0
  88. package/framework/tasks/greenfield-wu-tech-stack-assess.md +255 -0
  89. package/framework/tasks/orchestrator-deviation.md +260 -0
  90. package/framework/tasks/orchestrator-escalate.md +276 -0
  91. package/framework/tasks/orchestrator-handoff.md +243 -0
  92. package/framework/tasks/orchestrator-health.md +372 -0
  93. package/framework/tasks/orchestrator-mode-switch.md +262 -0
  94. package/framework/tasks/orchestrator-resume.md +189 -0
  95. package/framework/tasks/orchestrator-route.md +169 -0
  96. package/framework/tasks/orchestrator-spawn-terminal.md +358 -0
  97. package/framework/tasks/orchestrator-status.md +260 -0
  98. package/framework/tasks/orchestrator-suggest-mode.md +372 -0
  99. package/framework/tasks/phases-breakdown.md +91 -0
  100. package/framework/tasks/phases-dependency-mapping.md +67 -0
  101. package/framework/tasks/phases-mvp-scoping.md +94 -0
  102. package/framework/tasks/qa-impl-consolidate.md +522 -0
  103. package/framework/tasks/qa-impl-performance-test.md +487 -0
  104. package/framework/tasks/qa-impl-regression-check.md +413 -0
  105. package/framework/tasks/qa-impl-sast-scan.md +402 -0
  106. package/framework/tasks/qa-impl-test-execute.md +344 -0
  107. package/framework/tasks/qa-impl-verdict.md +339 -0
  108. package/framework/tasks/qa-planning-consolidate.md +309 -0
  109. package/framework/tasks/qa-planning-coverage-plan.md +338 -0
  110. package/framework/tasks/qa-planning-gate-define.md +339 -0
  111. package/framework/tasks/qa-planning-risk-matrix.md +631 -0
  112. package/framework/tasks/qa-planning-test-strategy.md +217 -0
  113. package/framework/tasks/tasks-acceptance-write.md +75 -0
  114. package/framework/tasks/tasks-consolidate.md +57 -0
  115. package/framework/tasks/tasks-decompose.md +80 -0
  116. package/framework/tasks/tasks-estimate.md +66 -0
  117. package/framework/tasks/ux-a11y-check.md +49 -0
  118. package/framework/tasks/ux-component-map.md +55 -0
  119. package/framework/tasks/ux-consolidate.md +46 -0
  120. package/framework/tasks/ux-user-flow.md +46 -0
  121. package/framework/tasks/ux-wireframe.md +76 -0
  122. package/package.json +2 -2
  123. package/scripts/bundle-framework.js +2 -0
  124. package/scripts/changelog-generator.js +222 -0
  125. package/scripts/codebase-mapper.js +728 -0
  126. package/scripts/commit-message-generator.js +167 -0
  127. package/scripts/coverage-analyzer.js +260 -0
  128. package/scripts/dependency-analyzer.js +280 -0
  129. package/scripts/framework-analyzer.js +308 -0
  130. package/scripts/generate-constitution-domain.js +253 -0
  131. package/scripts/health-check.js +481 -0
  132. package/scripts/ide-sync.js +327 -0
  133. package/scripts/performance-analyzer.js +325 -0
  134. package/scripts/plan-tracker.js +278 -0
  135. package/scripts/populate-entity-registry.js +481 -0
  136. package/scripts/pr-review.js +317 -0
  137. package/scripts/rollback-manager.js +310 -0
  138. package/scripts/stuck-detector.js +343 -0
  139. package/scripts/test-quality-assessment.js +257 -0
  140. package/scripts/validate-agents.js +367 -0
  141. package/scripts/validate-tasks.js +465 -0
  142. package/src/autonomy/autonomous-gate.js +293 -0
  143. package/src/autonomy/index.js +51 -0
  144. package/src/autonomy/mode-manager.js +225 -0
  145. package/src/autonomy/mode-suggester.js +283 -0
  146. package/src/autonomy/progress-reporter.js +268 -0
  147. package/src/autonomy/safety-net.js +320 -0
  148. package/src/context/bracket-tracker.js +79 -0
  149. package/src/context/domain-loader.js +107 -0
  150. package/src/context/engine.js +144 -0
  151. package/src/context/formatter.js +184 -0
  152. package/src/context/index.js +4 -0
  153. package/src/context/layers/l0-constitution.js +28 -0
  154. package/src/context/layers/l1-global.js +37 -0
  155. package/src/context/layers/l2-agent.js +39 -0
  156. package/src/context/layers/l3-workflow.js +42 -0
  157. package/src/context/layers/l4-task.js +24 -0
  158. package/src/decision/analyzer.js +167 -0
  159. package/src/decision/engine.js +270 -0
  160. package/src/decision/index.js +38 -0
  161. package/src/decision/registry-healer.js +450 -0
  162. package/src/decision/registry-updater.js +330 -0
  163. package/src/gates/circuit-breaker.js +119 -0
  164. package/src/gates/g1-planning-complete.js +153 -0
  165. package/src/gates/g2-qa-planning.js +153 -0
  166. package/src/gates/g3-implementation.js +188 -0
  167. package/src/gates/g4-qa-implementation.js +207 -0
  168. package/src/gates/g5-deploy-ready.js +180 -0
  169. package/src/gates/gate-base.js +144 -0
  170. package/src/gates/index.js +46 -0
  171. package/src/installer/brownfield-upgrader.js +249 -0
  172. package/src/installer/core.js +82 -11
  173. package/src/installer/file-hasher.js +51 -0
  174. package/src/installer/manifest.js +117 -0
  175. package/src/installer/templates.js +17 -15
  176. package/src/installer/transaction.js +229 -0
  177. package/src/installer/validator.js +18 -1
  178. package/src/intelligence/registry-manager.js +2 -2
  179. package/src/memory/agent-memory.js +255 -0
  180. package/src/memory/gotchas-injector.js +72 -0
  181. package/src/memory/gotchas.js +361 -0
  182. package/src/memory/index.js +35 -0
  183. package/src/memory/search.js +233 -0
  184. package/src/memory/session-digest.js +239 -0
  185. package/src/merger/env-merger.js +112 -0
  186. package/src/merger/index.js +56 -0
  187. package/src/merger/replace-merger.js +51 -0
  188. package/src/merger/yaml-merger.js +127 -0
  189. package/src/orchestrator/agent-selector.js +285 -0
  190. package/src/orchestrator/deviation-handler.js +350 -0
  191. package/src/orchestrator/handoff-engine.js +271 -0
  192. package/src/orchestrator/index.js +67 -0
  193. package/src/orchestrator/intent-classifier.js +264 -0
  194. package/src/orchestrator/pipeline-manager.js +492 -0
  195. package/src/orchestrator/pipeline-state.js +223 -0
  196. package/src/orchestrator/session-manager.js +409 -0
  197. package/src/tasks/executor.js +195 -0
  198. package/src/tasks/handoff.js +226 -0
  199. package/src/tasks/index.js +4 -0
  200. package/src/tasks/loader.js +210 -0
  201. package/src/tasks/router.js +182 -0
  202. package/src/terminal/collector.js +216 -0
  203. package/src/terminal/index.js +30 -0
  204. package/src/terminal/isolation.js +129 -0
  205. package/src/terminal/monitor.js +277 -0
  206. package/src/terminal/spawner.js +269 -0
  207. package/src/upgrade/checker.js +1 -1
  208. package/src/wizard/i18n.js +3 -3
@@ -0,0 +1,276 @@
1
+ ---
2
+ id: orchestrator-escalate
3
+ agent: orchestrator
4
+ trigger: agent-failure
5
+ phase: all
6
+ requires_input: false
7
+ parallelizable: false
8
+ outputs: [escalation-report]
9
+ handoff_to: null
10
+ autonomous_gate: false
11
+ criteria:
12
+ - Failure correctly classified
13
+ - Context collected
14
+ - User notified
15
+ - Pipeline paused
16
+ ---
17
+
18
+ # Orchestrator Escalate Task
19
+
20
+ ## Purpose
21
+ Handle agent failures, blockers, and critical issues by collecting context, classifying severity, and escalating to the user with actionable options.
22
+
23
+ ## Prerequisites
24
+ - Failure signal from agent
25
+ - Session state at `.chati/session.yaml`
26
+ - Agent definition with failure handling rules
27
+ - Error logs or stack traces (if available)
28
+
29
+ ## Steps
30
+
31
+ ### 1. Receive Failure Signal
32
+ Capture the error from the agent:
33
+ - Agent name and failure timestamp
34
+ - Error type (exception, validation failure, blocker, timeout)
35
+ - Error message and stack trace
36
+ - Agent state at time of failure
37
+ - Partial outputs (if any)
38
+
39
+ ### 2. Classify Severity
40
+ Categorize the failure impact:
41
+ - **Warning**: Non-critical issue, can continue with caution
42
+ - **Error**: Agent cannot complete, requires intervention
43
+ - **Critical**: Pipeline cannot continue, requires immediate action
44
+ - **Blocker**: External dependency missing, user decision needed
45
+
46
+ ### 3. Collect Failure Context
47
+ Gather all relevant information:
48
+ - Agent's current task/step when failure occurred
49
+ - Inputs provided to the agent
50
+ - Previous agent outputs (handoff chain)
51
+ - Session state at failure time
52
+ - Related artifacts
53
+
54
+ ### 4. Identify Root Cause
55
+ Analyze the failure to determine likely cause:
56
+ - **Configuration**: Missing or invalid config values
57
+ - **Dependency**: Required tool/MCP not available
58
+ - **Data**: Invalid or missing input data
59
+ - **Logic**: Agent code error or unexpected state
60
+ - **External**: Third-party service failure
61
+
62
+ ### 5. Check Recovery Options
63
+ Evaluate possible recovery paths:
64
+ - **Retry**: Can the agent retry with same inputs?
65
+ - **Skip**: Can the agent be marked `skipped` and pipeline continue?
66
+ - **Rollback**: Should we revert to previous agent?
67
+ - **Manual**: Does user need to fix something externally?
68
+ - **Abort**: Is the entire project blocked?
69
+
70
+ ### 6. Format Escalation Report
71
+ Build a clear, actionable report:
72
+ - Summary: One-line description of what went wrong
73
+ - Details: Full error context
74
+ - Impact: What this means for the project
75
+ - Options: Specific actions user can take
76
+ - Recommendation: Suggested path forward
77
+
78
+ ### 7. Pause Pipeline
79
+ Prevent automatic progression:
80
+ - Set agent status to `blocked`
81
+ - Update session with escalation flag
82
+ - Prevent other agents from starting
83
+ - Log escalation event
84
+
85
+ ### 8. Notify User
86
+ Present the escalation clearly:
87
+ - Use attention-grabbing formatting
88
+ - Provide full context
89
+ - List options with pros/cons
90
+ - Include relevant file paths and error snippets
91
+
92
+ ### 9. Await User Decision
93
+ Wait for explicit user input:
94
+ - Do not auto-recover for errors or critical issues
95
+ - Timeout after 24 hours (session expires)
96
+ - Allow user to choose from options
97
+ - Validate user choice before proceeding
98
+
99
+ ### 10. Execute Recovery Action
100
+ Based on user decision:
101
+ - **Retry**: Re-invoke agent with same or updated inputs
102
+ - **Skip**: Mark agent as `skipped`, route to next
103
+ - **Rollback**: Revert to previous agent, update session
104
+ - **Manual Fix**: Pause pipeline, provide instructions
105
+ - **Abort**: Mark project as blocked, save state
106
+
107
+ ## Decision Points
108
+
109
+ ### When Failure is Recoverable
110
+ If agent can be retried successfully:
111
+ 1. Check retry count (max 3 attempts)
112
+ 2. Determine if inputs need modification
113
+ 3. Suggest retry with guidance
114
+
115
+ ### When Failure is Due to Missing Config
116
+ If agent failed because of invalid configuration:
117
+ 1. Identify the missing/invalid config key
118
+ 2. Show example of correct format
119
+ 3. Offer to re-run installer to fix config
120
+
121
+ ### When Failure is External
122
+ If agent failed due to third-party service:
123
+ 1. Check if service is critical or optional
124
+ 2. Suggest workaround if available
125
+ 3. Offer to skip agent if non-critical
126
+
127
+ ### When Multiple Failures Occur
128
+ If several agents fail in sequence:
129
+ 1. Look for common root cause
130
+ 2. Suggest fixing root cause first
131
+ 3. Offer full pipeline validation
132
+
133
+ ## Error Handling
134
+
135
+ ### Escalation During Escalation
136
+ If escalation process itself fails:
137
+ - Fall back to minimal text report
138
+ - Log to `.chati/logs/critical.log`
139
+ - Attempt to notify via stderr
140
+
141
+ ### Session Update Failure
142
+ If session can't be updated with escalation:
143
+ - Continue escalation anyway
144
+ - Store in-memory state
145
+ - Warn user about state persistence issue
146
+
147
+ ### User Response Timeout
148
+ If user doesn't respond within 24 hours:
149
+ - Mark session as stale
150
+ - Preserve all state
151
+ - Next invocation resumes escalation
152
+
153
+ ### Cannot Determine Root Cause
154
+ If failure is mysterious:
155
+ - Provide full error details
156
+ - Suggest framework validation
157
+ - Offer to collect debug logs
158
+
159
+ ### Recovery Action Fails
160
+ If user's chosen recovery also fails:
161
+ - Re-escalate with updated context
162
+ - Increment failure count
163
+ - Suggest more drastic action (rollback/abort)
164
+
165
+ ## Output Format
166
+
167
+ ```yaml
168
+ escalation_report:
169
+ timestamp: "2026-02-13T10:30:00Z"
170
+ escalation_id: "ESC-001"
171
+ severity: "error"
172
+ agent: "architect"
173
+ failure_type: "dependency-missing"
174
+
175
+ summary: "Architect agent failed: Required MCP 'gdrive' not available"
176
+
177
+ details:
178
+ error_message: "MCP server 'gdrive' is not configured or not responding"
179
+ error_code: "MCP_UNAVAILABLE"
180
+ stack_trace: null
181
+ failure_step: "load-existing-architecture-docs"
182
+ timestamp: "2026-02-13T10:28:45Z"
183
+
184
+ agent_state:
185
+ current_task: "Searching for existing architecture documentation"
186
+ inputs_provided:
187
+ - "handoff from detail agent"
188
+ - "functional requirements"
189
+ partial_outputs: []
190
+
191
+ context:
192
+ previous_agent: "detail"
193
+ session_mode: "clarity"
194
+ pipeline_position: "CLARITY/architect"
195
+
196
+ root_cause_analysis:
197
+ primary_cause: "dependency-missing"
198
+ explanation: |
199
+ Architect agent requires Google Drive MCP to search for existing
200
+ architecture documents. The MCP server is listed in agent definition
201
+ as 'required' but is not configured in the IDE.
202
+ related_config: "chati.dev/agents/architect.yaml > mcps.required"
203
+
204
+ impact:
205
+ pipeline_status: "paused"
206
+ affected_agents: ["architect"]
207
+ can_continue_without: false
208
+ affects_deliverables: true
209
+
210
+ recovery_options:
211
+ - id: "R1"
212
+ action: "configure-gdrive-mcp"
213
+ description: "Install and configure Google Drive MCP, then retry"
214
+ effort: "5-10 minutes"
215
+ risk: "low"
216
+ steps:
217
+ - "Follow Google Drive MCP setup: https://..."
218
+ - "Add server config to IDE MCP settings"
219
+ - "Restart IDE"
220
+ - "Run `/chati` to retry Architect agent"
221
+ recommended: true
222
+
223
+ - id: "R2"
224
+ action: "skip-gdrive-search"
225
+ description: "Skip Drive search, Architect uses only local docs"
226
+ effort: "immediate"
227
+ risk: "medium"
228
+ warning: "May miss important existing architecture documentation"
229
+ recommended: false
230
+
231
+ - id: "R3"
232
+ action: "manual-doc-collection"
233
+ description: "User manually collects architecture docs, provides to agent"
234
+ effort: "variable"
235
+ risk: "low"
236
+ steps:
237
+ - "Search Google Drive manually"
238
+ - "Download relevant architecture docs"
239
+ - "Place in .chati/artifacts/architecture/"
240
+ - "Run `/chati` to retry Architect agent"
241
+ recommended: false
242
+
243
+ recommendation: "R1"
244
+ recommendation_rationale: |
245
+ Configuring the Google Drive MCP is quick and ensures Architect has
246
+ full access to existing documentation. This is a one-time setup that
247
+ benefits future sessions.
248
+
249
+ session_updates:
250
+ agent_status: "blocked"
251
+ escalation_flag: true
252
+ pipeline_paused: true
253
+ retry_count: 0
254
+
255
+ user_prompt: |
256
+ ⚠️ ESCALATION: Architect agent blocked
257
+
258
+ The Architect agent requires Google Drive MCP but it's not configured.
259
+
260
+ Options:
261
+ 1. [Recommended] Configure Google Drive MCP (5-10 min)
262
+ - Follow setup: https://...
263
+ - Add to IDE MCP settings
264
+ - Restart IDE and retry
265
+
266
+ 2. Skip Drive search (less thorough, may miss docs)
267
+
268
+ 3. Manually collect architecture docs
269
+
270
+ What would you like to do? (1/2/3)
271
+
272
+ audit_trail:
273
+ logged_at: "2026-02-13T10:30:00Z"
274
+ logged_to: ".chati/logs/escalations.log"
275
+ session_state_saved: true
276
+ ```
@@ -0,0 +1,243 @@
1
+ ---
2
+ id: orchestrator-handoff
3
+ agent: orchestrator
4
+ trigger: agent-completion
5
+ phase: all
6
+ requires_input: false
7
+ parallelizable: false
8
+ outputs: [handoff-document]
9
+ handoff_to: null
10
+ autonomous_gate: true
11
+ criteria:
12
+ - Agent output validated against criteria
13
+ - Handoff document created
14
+ - Session state updated
15
+ - Next agent determined
16
+ ---
17
+
18
+ # Orchestrator Handoff Task
19
+
20
+ ## Purpose
21
+ Receive output from a completed agent, validate it, create a handoff document, update session state, and route to the next agent.
22
+
23
+ ## Prerequisites
24
+ - Agent has signaled completion
25
+ - Agent output available
26
+ - Session file at `.chati/session.yaml`
27
+ - Handoff directory at `.chati/artifacts/handoffs/`
28
+ - Agent definition with success criteria
29
+
30
+ ## Steps
31
+
32
+ ### 1. Receive Agent Output
33
+ Collect the completion signal from the agent:
34
+ - Agent name and completion timestamp
35
+ - Output artifacts (files, data structures)
36
+ - Decisions made during execution
37
+ - Quality self-assessment
38
+ - Open questions or blockers
39
+
40
+ ### 2. Load Agent Definition
41
+ Read the agent's YAML definition to get:
42
+ - Success criteria (acceptance conditions)
43
+ - Expected outputs
44
+ - Quality thresholds
45
+ - Next agent in sequence
46
+
47
+ ### 3. Validate Against Criteria
48
+ Check agent output against defined criteria:
49
+ - All required outputs present
50
+ - Quality score meets threshold (if applicable)
51
+ - Acceptance conditions satisfied
52
+ - No critical blockers
53
+
54
+ ### 4. Build Handoff Document
55
+ Create structured handoff in markdown with YAML frontmatter:
56
+ - Metadata: agent, timestamp, status, quality_score
57
+ - Summary: What was accomplished
58
+ - Outputs: List of artifacts with paths
59
+ - Decisions: Key choices made
60
+ - Open Questions: Unresolved items
61
+ - Recommendations: Guidance for next agent
62
+
63
+ ### 5. Save Handoff Artifact
64
+ Write handoff to file system:
65
+ - Path: `.chati/artifacts/handoffs/{YYYY-MM-DD}-{agent}.md`
66
+ - Ensure directory exists
67
+ - Validate write success
68
+ - Set appropriate permissions
69
+
70
+ ### 6. Update Session State
71
+ Modify `.chati/session.yaml`:
72
+ - Set agent status to `completed`
73
+ - Add completion timestamp
74
+ - Increment pipeline progress
75
+ - Log decision made during this agent
76
+ - Update `last_activity` timestamp
77
+
78
+ ### 7. Determine Next Agent
79
+ Based on pipeline position and mode:
80
+ - **CLARITY**: Follow sequence (wu → brief → detail → architect → ux → phases → tasks → qa-planning)
81
+ - **BUILD**: dev → qa-implementation
82
+ - **DEPLOY**: devops
83
+ - Handle special transitions (e.g., qa-planning → dev requires mode switch)
84
+
85
+ ### 8. Check Quality Gates
86
+ Evaluate if mode transition should occur:
87
+ - **After QA-Planning**: If score >= 95%, eligible for clarity → build
88
+ - **After Dev**: If complete, eligible for build → validate
89
+ - **After QA-Implementation**: If approved, eligible for validate → deploy
90
+
91
+ ### 9. Prepare Next Agent Context
92
+ Package context for the next agent:
93
+ - Current handoff document
94
+ - Relevant previous handoffs
95
+ - Session state excerpt
96
+ - Project configuration
97
+
98
+ ### 10. Dispatch Next Action
99
+ Execute the routing decision:
100
+ - If next agent in same mode: Route directly
101
+ - If mode transition needed: Trigger `orchestrator-mode-switch`
102
+ - If validation needed: Trigger `orchestrator-escalate`
103
+ - If end of pipeline: Mark project complete
104
+
105
+ ## Decision Points
106
+
107
+ ### When Validation Fails
108
+ If agent output doesn't meet criteria:
109
+ 1. Assess severity (minor vs. critical)
110
+ 2. For minor: Document in handoff, proceed with warning
111
+ 3. For critical: Set agent to `needs_revalidation`, escalate to user
112
+
113
+ ### When Quality Score is Below Threshold
114
+ If agent self-assessment is low:
115
+ 1. Check if this is a QA agent (requires >= 95%)
116
+ 2. For QA agents: Block mode transition, require rework
117
+ 3. For other agents: Note in handoff, continue with caution
118
+
119
+ ### When Next Agent is Ambiguous
120
+ If pipeline branching or user choice is needed:
121
+ 1. Pause automatic routing
122
+ 2. Escalate to user with options
123
+ 3. Wait for explicit direction
124
+
125
+ ### When Open Questions Exist
126
+ If agent has unresolved questions:
127
+ 1. Categorize: blocking vs. non-blocking
128
+ 2. For blocking: Escalate immediately
129
+ 3. For non-blocking: Include in handoff, continue
130
+
131
+ ## Error Handling
132
+
133
+ ### Agent Output Missing
134
+ If expected artifacts are not present:
135
+ - Attempt to locate in alternate paths
136
+ - Check if agent logged failure
137
+ - Escalate with missing artifact list
138
+
139
+ ### Handoff Write Failure
140
+ If handoff document can't be saved:
141
+ - Try alternate location (`.chati/backups/handoffs/`)
142
+ - Log to session decisions as fallback
143
+ - Escalate with write error details
144
+
145
+ ### Session Update Failure
146
+ If `.chati/session.yaml` update fails:
147
+ - Retry with backup creation
148
+ - If persistent: Continue with in-memory state
149
+ - Warn user about state persistence issue
150
+
151
+ ### Circular Routing Detected
152
+ If next agent would create a loop:
153
+ - Block the routing
154
+ - Escalate with loop details
155
+ - Request user intervention
156
+
157
+ ### Mode Transition Blocked
158
+ If quality gate fails for mode transition:
159
+ - Document the failure reason
160
+ - Set agent to `needs_revalidation`
161
+ - Notify user of required rework
162
+
163
+ ## Output Format
164
+
165
+ ```yaml
166
+ handoff_document:
167
+ metadata:
168
+ agent: "detail"
169
+ timestamp: "2026-02-13T02:15:00Z"
170
+ status: "completed"
171
+ quality_score: 8.5
172
+ duration_minutes: 45
173
+ mode: "clarity"
174
+ phase: "CLARITY"
175
+
176
+ summary: |
177
+ Completed detailed requirements analysis for HealthCare Portal.
178
+ Identified 12 user stories across 4 modules (Authentication, Patient Records,
179
+ Appointments, Billing). Mapped 3 external integrations (Payment Gateway,
180
+ Insurance API, Lab Results). Defined data model with 8 core entities.
181
+
182
+ outputs:
183
+ - path: ".chati/artifacts/requirements/functional-requirements.md"
184
+ type: "document"
185
+ description: "Complete functional requirements with use cases"
186
+ size_kb: 45
187
+ - path: ".chati/artifacts/requirements/user-stories.yaml"
188
+ type: "structured-data"
189
+ description: "12 user stories with acceptance criteria"
190
+ size_kb: 8
191
+ - path: ".chati/artifacts/requirements/integrations.yaml"
192
+ type: "structured-data"
193
+ description: "External integration specifications"
194
+ size_kb: 12
195
+
196
+ decisions:
197
+ - id: "D-008"
198
+ decision: "Use OAuth2 + RBAC for authentication"
199
+ rationale: "HIPAA compliance requires audit trails and role-based access"
200
+ alternatives_considered: ["Basic Auth", "API Keys"]
201
+ - id: "D-009"
202
+ decision: "PostgreSQL for primary database"
203
+ rationale: "Strong ACID compliance, JSON support for flexible fields"
204
+ alternatives_considered: ["MySQL", "MongoDB"]
205
+
206
+ open_questions:
207
+ - id: "Q-003"
208
+ question: "Should patient portal be mobile-first or desktop-first?"
209
+ blocking: false
210
+ context: "Affects UX design priorities"
211
+ - id: "Q-004"
212
+ question: "Maximum file size for document uploads?"
213
+ blocking: false
214
+ context: "Impacts storage infrastructure sizing"
215
+
216
+ recommendations:
217
+ - "Architect should prioritize HIPAA compliance in system design"
218
+ - "Consider microservices for Billing module (complex integrations)"
219
+ - "UX should validate mobile experience with healthcare workers"
220
+
221
+ next_agent: "architect"
222
+
223
+ validation:
224
+ criteria_met: true
225
+ all_outputs_present: true
226
+ quality_threshold_met: true # 8.5 >= 7.0
227
+ blockers: []
228
+
229
+ session_update:
230
+ agent_status: "completed"
231
+ pipeline_progress: 37.5 # 3 of 8 CLARITY agents done
232
+ mode_transition_check:
233
+ eligible: false
234
+ reason: "QA-Planning not yet complete"
235
+
236
+ routing_decision:
237
+ next_action: "route-to-architect"
238
+ mode: "clarity"
239
+ context_package:
240
+ - ".chati/artifacts/handoffs/2026-02-13-detail.md"
241
+ - ".chati/artifacts/handoffs/2026-02-12-brief.md"
242
+ - ".chati/artifacts/requirements/"
243
+ ```