trinity-method-sdk 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/LICENSE +21 -0
  3. package/README.md +555 -0
  4. package/dist/cli/commands/deploy/agents.d.ts +14 -0
  5. package/dist/cli/commands/deploy/agents.js +59 -0
  6. package/dist/cli/commands/deploy/ci-cd.d.ts +13 -0
  7. package/dist/cli/commands/deploy/ci-cd.js +50 -0
  8. package/dist/cli/commands/deploy/claude-setup.d.ts +17 -0
  9. package/dist/cli/commands/deploy/claude-setup.js +91 -0
  10. package/dist/cli/commands/deploy/configuration.d.ts +13 -0
  11. package/dist/cli/commands/deploy/configuration.js +215 -0
  12. package/dist/cli/commands/deploy/directories.d.ts +12 -0
  13. package/dist/cli/commands/deploy/directories.js +38 -0
  14. package/dist/cli/commands/deploy/gitignore.d.ts +12 -0
  15. package/dist/cli/commands/deploy/gitignore.js +53 -0
  16. package/dist/cli/commands/deploy/index.d.ts +38 -0
  17. package/dist/cli/commands/deploy/index.js +156 -0
  18. package/dist/cli/commands/deploy/knowledge-base.d.ts +16 -0
  19. package/dist/cli/commands/deploy/knowledge-base.js +75 -0
  20. package/dist/cli/commands/deploy/linting.d.ts +18 -0
  21. package/dist/cli/commands/deploy/linting.js +51 -0
  22. package/dist/cli/commands/deploy/metrics.d.ts +13 -0
  23. package/dist/cli/commands/deploy/metrics.js +34 -0
  24. package/dist/cli/commands/deploy/pre-flight.d.ts +13 -0
  25. package/dist/cli/commands/deploy/pre-flight.js +29 -0
  26. package/dist/cli/commands/deploy/root-files.d.ts +16 -0
  27. package/dist/cli/commands/deploy/root-files.js +178 -0
  28. package/dist/cli/commands/deploy/sdk-install.d.ts +12 -0
  29. package/dist/cli/commands/deploy/sdk-install.js +57 -0
  30. package/dist/cli/commands/deploy/summary.d.ts +14 -0
  31. package/dist/cli/commands/deploy/summary.js +130 -0
  32. package/dist/cli/commands/deploy/templates.d.ts +14 -0
  33. package/dist/cli/commands/deploy/templates.js +84 -0
  34. package/dist/cli/commands/deploy/types.d.ts +39 -0
  35. package/dist/cli/commands/deploy/types.js +5 -0
  36. package/dist/cli/commands/update/agents.d.ts +14 -0
  37. package/dist/cli/commands/update/agents.js +31 -0
  38. package/dist/cli/commands/update/backup.d.ts +31 -0
  39. package/dist/cli/commands/update/backup.js +97 -0
  40. package/dist/cli/commands/update/commands.d.ts +14 -0
  41. package/dist/cli/commands/update/commands.js +75 -0
  42. package/dist/cli/commands/update/index.d.ts +15 -0
  43. package/dist/cli/commands/update/index.js +118 -0
  44. package/dist/cli/commands/update/knowledge-base.d.ts +14 -0
  45. package/dist/cli/commands/update/knowledge-base.js +38 -0
  46. package/dist/cli/commands/update/pre-flight.d.ts +13 -0
  47. package/dist/cli/commands/update/pre-flight.js +37 -0
  48. package/dist/cli/commands/update/summary.d.ts +20 -0
  49. package/dist/cli/commands/update/summary.js +47 -0
  50. package/dist/cli/commands/update/templates.d.ts +14 -0
  51. package/dist/cli/commands/update/templates.js +25 -0
  52. package/dist/cli/commands/update/types.d.ts +13 -0
  53. package/dist/cli/commands/update/types.js +7 -0
  54. package/dist/cli/commands/update/utils.d.ts +11 -0
  55. package/dist/cli/commands/update/utils.js +19 -0
  56. package/dist/cli/commands/update/verification.d.ts +20 -0
  57. package/dist/cli/commands/update/verification.js +54 -0
  58. package/dist/cli/commands/update/version.d.ts +18 -0
  59. package/dist/cli/commands/update/version.js +36 -0
  60. package/dist/cli/commands/update.d.ts +7 -0
  61. package/dist/cli/commands/update.js +7 -0
  62. package/dist/cli/index.d.ts +3 -0
  63. package/dist/cli/index.js +36 -0
  64. package/dist/cli/types.d.ts +77 -0
  65. package/dist/cli/types.js +5 -0
  66. package/dist/cli/utils/deploy-ci.d.ts +22 -0
  67. package/dist/cli/utils/deploy-ci.js +138 -0
  68. package/dist/cli/utils/deploy-linting.d.ts +3 -0
  69. package/dist/cli/utils/deploy-linting.js +136 -0
  70. package/dist/cli/utils/detect-stack.d.ts +3 -0
  71. package/dist/cli/utils/detect-stack.js +270 -0
  72. package/dist/cli/utils/error-classes.d.ts +63 -0
  73. package/dist/cli/utils/error-classes.js +84 -0
  74. package/dist/cli/utils/error-handler.d.ts +59 -0
  75. package/dist/cli/utils/error-handler.js +127 -0
  76. package/dist/cli/utils/errors.d.ts +52 -0
  77. package/dist/cli/utils/errors.js +102 -0
  78. package/dist/cli/utils/get-sdk-path.d.ts +18 -0
  79. package/dist/cli/utils/get-sdk-path.js +31 -0
  80. package/dist/cli/utils/inject-dependencies.d.ts +2 -0
  81. package/dist/cli/utils/inject-dependencies.js +55 -0
  82. package/dist/cli/utils/linting-tools.d.ts +8 -0
  83. package/dist/cli/utils/linting-tools.js +206 -0
  84. package/dist/cli/utils/metrics/code-quality.d.ts +32 -0
  85. package/dist/cli/utils/metrics/code-quality.js +122 -0
  86. package/dist/cli/utils/metrics/dependency-parser.d.ts +21 -0
  87. package/dist/cli/utils/metrics/dependency-parser.js +153 -0
  88. package/dist/cli/utils/metrics/file-complexity.d.ts +26 -0
  89. package/dist/cli/utils/metrics/file-complexity.js +77 -0
  90. package/dist/cli/utils/metrics/framework-detector.d.ts +17 -0
  91. package/dist/cli/utils/metrics/framework-detector.js +120 -0
  92. package/dist/cli/utils/metrics/git-metrics.d.ts +30 -0
  93. package/dist/cli/utils/metrics/git-metrics.js +83 -0
  94. package/dist/cli/utils/metrics/index.d.ts +28 -0
  95. package/dist/cli/utils/metrics/index.js +100 -0
  96. package/dist/cli/utils/template-processor.d.ts +10 -0
  97. package/dist/cli/utils/template-processor.js +188 -0
  98. package/dist/cli/utils/validate-path.d.ts +80 -0
  99. package/dist/cli/utils/validate-path.js +180 -0
  100. package/dist/index.d.ts +6 -0
  101. package/dist/index.js +8 -0
  102. package/dist/templates/agents/aj-team/apo-documentation-specialist.md.template +572 -0
  103. package/dist/templates/agents/aj-team/bas-quality-gate.md.template +906 -0
  104. package/dist/templates/agents/aj-team/bon-dependency-manager.md.template +636 -0
  105. package/dist/templates/agents/aj-team/cap-configuration-specialist.md.template +670 -0
  106. package/dist/templates/agents/aj-team/dra-code-reviewer.md.template +768 -0
  107. package/dist/templates/agents/aj-team/kil-task-executor.md.template +764 -0
  108. package/dist/templates/agents/aj-team/uro-refactoring-specialist.md.template +759 -0
  109. package/dist/templates/agents/audit/juno-auditor.md.template +447 -0
  110. package/dist/templates/agents/deployment/ein-cicd.md.template +694 -0
  111. package/dist/templates/agents/deployment/ino-context.md.template +733 -0
  112. package/dist/templates/agents/deployment/tan-structure.md.template +661 -0
  113. package/dist/templates/agents/deployment/zen-knowledge.md.template +451 -0
  114. package/dist/templates/agents/leadership/aj-cc.md.template +462 -0
  115. package/dist/templates/agents/leadership/aj-maestro.md.template +943 -0
  116. package/dist/templates/agents/leadership/aly-cto.md.template +407 -0
  117. package/dist/templates/agents/planning/eus-decomposer.md.template +496 -0
  118. package/dist/templates/agents/planning/mon-requirements.md.template +323 -0
  119. package/dist/templates/agents/planning/ror-design.md.template +465 -0
  120. package/dist/templates/agents/planning/tra-planner.md.template +432 -0
  121. package/dist/templates/ci/cd.yml.template +175 -0
  122. package/dist/templates/ci/ci.yml.template +196 -0
  123. package/dist/templates/ci/generic-ci.yml +115 -0
  124. package/dist/templates/ci/github-actions.yml +86 -0
  125. package/dist/templates/ci/gitlab-ci.yml +103 -0
  126. package/dist/templates/claude/EMPLOYEE-DIRECTORY.md.template +545 -0
  127. package/dist/templates/documentation/ROOT-README.md.template +307 -0
  128. package/dist/templates/documentation/SUBDIRECTORY-README.md.template +261 -0
  129. package/dist/templates/investigations/bug.md.template +484 -0
  130. package/dist/templates/investigations/feature.md.template +564 -0
  131. package/dist/templates/investigations/performance.md.template +625 -0
  132. package/dist/templates/investigations/security.md.template +714 -0
  133. package/dist/templates/investigations/technical.md.template +433 -0
  134. package/dist/templates/knowledge-base/AI-DEVELOPMENT-GUIDE.md.template +957 -0
  135. package/dist/templates/knowledge-base/ARCHITECTURE.md.template +452 -0
  136. package/dist/templates/knowledge-base/CODING-PRINCIPLES.md.template +750 -0
  137. package/dist/templates/knowledge-base/DOCUMENTATION-CRITERIA.md.template +1118 -0
  138. package/dist/templates/knowledge-base/ISSUES.md.template +539 -0
  139. package/dist/templates/knowledge-base/TESTING-PRINCIPLES.md.template +894 -0
  140. package/dist/templates/knowledge-base/Technical-Debt.md.template +640 -0
  141. package/dist/templates/knowledge-base/To-do.md.template +407 -0
  142. package/dist/templates/knowledge-base/Trinity.md.template +464 -0
  143. package/dist/templates/linting/flutter/.pre-commit-config.yaml.template +27 -0
  144. package/dist/templates/linting/flutter/analysis_options.yaml.template +26 -0
  145. package/dist/templates/linting/nodejs/.eslintrc-commonjs.json.template +19 -0
  146. package/dist/templates/linting/nodejs/.eslintrc-esm.json.template +19 -0
  147. package/dist/templates/linting/nodejs/.eslintrc-typescript.json.template +22 -0
  148. package/dist/templates/linting/nodejs/.pre-commit-config.yaml.template +51 -0
  149. package/dist/templates/linting/nodejs/.prettierrc.json.template +10 -0
  150. package/dist/templates/linting/python/.flake8.template +16 -0
  151. package/dist/templates/linting/python/.pre-commit-config.yaml.template +30 -0
  152. package/dist/templates/linting/python/pyproject.toml.template +38 -0
  153. package/dist/templates/linting/rust/.pre-commit-config.yaml.template +28 -0
  154. package/dist/templates/linting/rust/clippy.toml.template +14 -0
  155. package/dist/templates/linting/rust/rustfmt.toml.template +12 -0
  156. package/dist/templates/root/CLAUDE.md.template +65 -0
  157. package/dist/templates/root/TRINITY.md.template +52 -0
  158. package/dist/templates/shared/claude-commands/trinity-agents.md.template +168 -0
  159. package/dist/templates/shared/claude-commands/trinity-audit.md.template +646 -0
  160. package/dist/templates/shared/claude-commands/trinity-changelog.md.template +624 -0
  161. package/dist/templates/shared/claude-commands/trinity-continue.md.template +549 -0
  162. package/dist/templates/shared/claude-commands/trinity-create-investigation.md.template +232 -0
  163. package/dist/templates/shared/claude-commands/trinity-decompose.md.template +181 -0
  164. package/dist/templates/shared/claude-commands/trinity-design.md.template +347 -0
  165. package/dist/templates/shared/claude-commands/trinity-docs.md.template +2093 -0
  166. package/dist/templates/shared/claude-commands/trinity-end.md.template +397 -0
  167. package/dist/templates/shared/claude-commands/trinity-init.md.template +606 -0
  168. package/dist/templates/shared/claude-commands/trinity-investigate-templates.md.template +725 -0
  169. package/dist/templates/shared/claude-commands/trinity-orchestrate.md.template +1061 -0
  170. package/dist/templates/shared/claude-commands/trinity-plan-investigation.md.template +135 -0
  171. package/dist/templates/shared/claude-commands/trinity-plan.md.template +201 -0
  172. package/dist/templates/shared/claude-commands/trinity-readme.md.template +1971 -0
  173. package/dist/templates/shared/claude-commands/trinity-requirements.md.template +148 -0
  174. package/dist/templates/shared/claude-commands/trinity-start.md.template +268 -0
  175. package/dist/templates/shared/claude-commands/trinity-verify.md.template +453 -0
  176. package/dist/templates/shared/claude-commands/trinity-workorder.md.template +249 -0
  177. package/dist/templates/source/base-CLAUDE.md.template +310 -0
  178. package/dist/templates/source/flutter-CLAUDE.md.template +593 -0
  179. package/dist/templates/source/nodejs-CLAUDE.md.template +531 -0
  180. package/dist/templates/source/python-CLAUDE.md.template +510 -0
  181. package/dist/templates/source/react-CLAUDE.md.template +513 -0
  182. package/dist/templates/source/rust-CLAUDE.md.template +653 -0
  183. package/dist/templates/source/tests-CLAUDE.md.template +432 -0
  184. package/dist/templates/trinity/CLAUDE.md.template +372 -0
  185. package/dist/templates/work-orders/ANALYSIS-TEMPLATE.md.template +276 -0
  186. package/dist/templates/work-orders/AUDIT-TEMPLATE.md.template +262 -0
  187. package/dist/templates/work-orders/IMPLEMENTATION-TEMPLATE.md.template +260 -0
  188. package/dist/templates/work-orders/INVESTIGATION-TEMPLATE.md.template +206 -0
  189. package/dist/templates/work-orders/PATTERN-TEMPLATE.md.template +320 -0
  190. package/dist/templates/work-orders/VERIFICATION-TEMPLATE.md.template +273 -0
  191. package/package.json +94 -0
@@ -0,0 +1,957 @@
1
+ # AI Development Guide
2
+
3
+ **Version**: 2.0.0
4
+ **Last Updated**: {{date}}
5
+ **Project**: {{projectName}}
6
+
7
+ ---
8
+
9
+ ## Purpose
10
+
11
+ This document establishes AI-assisted development workflows, quality gates, and agent coordination protocols for Trinity Method SDK v2.0. All AI-driven implementations must follow these guidelines.
12
+
13
+ ## 1. Scale-Based Workflows
14
+
15
+ ### 1.1 Scale Determination
16
+
17
+ **Rule**: MON (Requirement Analyzer) determines scale based on file count and complexity.
18
+
19
+ **Scale Categories**:
20
+
21
+ | Scale | File Count | Complexity | Duration | Stop Points | Documentation |
22
+ |-------|------------|------------|----------|-------------|---------------|
23
+ | **Small** | 1-2 files | Low | ~30 min | 0 | Inline comments only |
24
+ | **Medium** | 3-5 files | Medium | 2-6 hours | 2 | Design doc + Work plan |
25
+ | **Large** | 6+ files | High | 1-2 days | 4 | PRD + ADR + Design + Plan |
26
+
27
+ **Complexity Factors** (in addition to file count):
28
+ - Integration points (external APIs, databases)
29
+ - New architectural patterns
30
+ - Cross-cutting concerns
31
+ - Performance requirements
32
+ - Security implications
33
+
34
+ **Scale Examples**:
35
+
36
+ ```javascript
37
+ // SMALL: Utility function
38
+ Requirement: "Add formatCurrency utility to src/utils/currency.js"
39
+ Files: 1 (currency.js) + 1 (currency.test.js) = 2 files
40
+ Scale: SMALL
41
+ Workflow: MON → KIL → BAS (autonomous, no stops)
42
+
43
+ // MEDIUM: Feature module
44
+ Requirement: "Implement user profile edit module"
45
+ Files: 4 (profileService.js, profileController.js, profileRoutes.js, tests)
46
+ Scale: MEDIUM
47
+ Workflow: MON → ROR → (stop) → TRA → EUS → (stop) → KIL → BAS → DRA
48
+
49
+ // LARGE: System component
50
+ Requirement: "Build multi-channel notification system (email, SMS, push)"
51
+ Files: 10+ (services, controllers, models, adapters, config, tests)
52
+ Scale: LARGE
53
+ Workflow: CAP → MON → ROR → (stops at PRD, ADR, design, plan) → EUS → KIL → BAS → APO → DRA
54
+ ```
55
+
56
+ ### 1.2 Small Workflow (Autonomous)
57
+
58
+ **Trigger**: 1-2 files, simple task, no architectural decisions
59
+
60
+ **Agents**: MON → KIL → BAS
61
+
62
+ **Stop Points**: 0 (autonomous execution)
63
+
64
+ **Duration**: ≤30 minutes
65
+
66
+ **Documentation**: Inline comments only
67
+
68
+ **Workflow Diagram**:
69
+
70
+ ```
71
+ [User Request] → MON (analyze) → KIL (implement with TDD) → BAS (6-phase QA) → [Commit]
72
+
73
+ (scale: small)
74
+
75
+ No user approval needed
76
+ ```
77
+
78
+ **Use Cases**:
79
+ - Add utility function
80
+ - Fix simple bug
81
+ - Add validation
82
+ - Update configuration
83
+ - Add simple test
84
+
85
+ **Quality Gate**: BAS auto-fixes and validates, commits if all pass
86
+
87
+ ---
88
+
89
+ ### 1.3 Medium Workflow (2 Stop Points)
90
+
91
+ **Trigger**: 3-5 files, moderate complexity, some design decisions
92
+
93
+ **Agents**: MON → ROR → TRA → EUS → KIL → BAS → DRA
94
+
95
+ **Stop Points**: 2
96
+ 1. **After ROR** (Design Review): User approves technical design
97
+ 2. **After EUS** (Plan Review): User approves work plan and tasks
98
+
99
+ **Duration**: 2-6 hours
100
+
101
+ **Documentation**: Design document + Work plan
102
+
103
+ **Workflow Diagram**:
104
+
105
+ ```
106
+ [User Request] → MON (analyze scale + requirements)
107
+
108
+ ROR (technical design)
109
+
110
+ 🛑 STOP 1: Design Review
111
+ ↓ (user approves)
112
+ TRA (work plan with phases)
113
+
114
+ EUS (decompose to atomic tasks)
115
+
116
+ 🛑 STOP 2: Plan Review
117
+ ↓ (user approves)
118
+ KIL (implement with TDD)
119
+
120
+ BAS (6-phase quality gate)
121
+
122
+ DRA (code review)
123
+
124
+ [Commit]
125
+ ```
126
+
127
+ **Use Cases**:
128
+ - New feature module
129
+ - Refactor existing module
130
+ - Add API endpoints
131
+ - Implement integration
132
+ - Add complex business logic
133
+
134
+ **Stop Point 1 (Design Review)**:
135
+ - User reviews ROR's technical design
136
+ - Approves architecture decisions
137
+ - Suggests changes if needed
138
+ - ROR iterates if rejected
139
+
140
+ **Stop Point 2 (Plan Review)**:
141
+ - User reviews TRA's work plan and EUS's task breakdown
142
+ - Approves implementation approach
143
+ - Suggests changes if needed
144
+ - TRA/EUS iterate if rejected
145
+
146
+ **After Approval**: KIL executes autonomously through commit
147
+
148
+ ---
149
+
150
+ ### 1.4 Large Workflow (4 Stop Points)
151
+
152
+ **Trigger**: 6+ files, high complexity, significant architectural decisions
153
+
154
+ **Agents**: CAP → MON → ROR → TRA → EUS → KIL → BAS → APO → DRA
155
+
156
+ **Stop Points**: 4
157
+ 1. **After CAP** (PRD Review): User approves product requirements
158
+ 2. **After ROR ADR** (Architecture Review): User approves ADR
159
+ 3. **After ROR Design** (Design Review): User approves technical design
160
+ 4. **After EUS** (Plan Review): User approves work plan and tasks
161
+
162
+ **Duration**: 1-2 days
163
+
164
+ **Documentation**: PRD + ADR + Design document + Work plan + Task breakdown
165
+
166
+ **Workflow Diagram**:
167
+
168
+ ```
169
+ [Investigation] → CAP (create PRD from investigation)
170
+
171
+ 🛑 STOP 1: PRD Review
172
+ ↓ (user approves)
173
+ MON (analyze requirements from PRD)
174
+
175
+ ROR (create ADR for major decisions)
176
+
177
+ 🛑 STOP 2: ADR Review
178
+ ↓ (user approves)
179
+ ROR (detailed technical design)
180
+
181
+ 🛑 STOP 3: Design Review
182
+ ↓ (user approves)
183
+ TRA (work plan)
184
+
185
+ EUS (task decomposition)
186
+
187
+ 🛑 STOP 4: Plan Review
188
+ ↓ (user approves)
189
+ KIL (implement with TDD)
190
+
191
+ BAS (6-phase quality gate)
192
+
193
+ APO (generate E2E acceptance tests)
194
+
195
+ DRA (comprehensive code review)
196
+
197
+ [Commit]
198
+ ```
199
+
200
+ **Use Cases**:
201
+ - New system component
202
+ - Major refactoring
203
+ - Complex integration (multi-service)
204
+ - New architectural pattern
205
+ - Performance-critical feature
206
+
207
+ **Stop Point 1 (PRD Review)**:
208
+ - User reviews CAP's product requirements document
209
+ - Validates requirements completeness
210
+ - Approves scope and success criteria
211
+
212
+ **Stop Point 2 (ADR Review)**:
213
+ - User reviews ROR's architecture decision record
214
+ - Approves architectural approach
215
+ - Validates tradeoffs and alternatives considered
216
+
217
+ **Stop Point 3 (Design Review)**:
218
+ - User reviews ROR's detailed technical design
219
+ - Approves component interactions
220
+ - Validates verification levels (L1/L2/L3)
221
+
222
+ **Stop Point 4 (Plan Review)**:
223
+ - User reviews TRA's work plan and EUS's tasks
224
+ - Approves implementation strategy
225
+ - Validates task breakdown and dependencies
226
+
227
+ **After All Approvals**: KIL executes autonomously through commit
228
+
229
+ ---
230
+
231
+ ## 2. BAS 6-Phase Quality Gate
232
+
233
+ ### 2.1 Quality Gate Overview
234
+
235
+ **Purpose**: Ensure zero-error commits with 90%+ auto-fix rate
236
+
237
+ **Enforcer**: BAS (Quality Fixer)
238
+
239
+ **Execution**: Sequential phases, blocks commit if any phase fails
240
+
241
+ **Phases**:
242
+
243
+ ```
244
+ Phase 1: Linting → AUTO-FIX
245
+ Phase 2: Structure → AUTO-FIX
246
+ Phase 3: Build → VALIDATE
247
+ Phase 4: Testing → VALIDATE
248
+ Phase 5: Coverage → VALIDATE (≥80%)
249
+ Phase 6: Final Review → VALIDATE/ESCALATE
250
+ ```
251
+
252
+ ### 2.2 Phase 1: Linting
253
+
254
+ **Purpose**: Enforce code style and catch syntax errors
255
+
256
+ **Tools**: ESLint, Prettier
257
+
258
+ **Auto-Fix**: Yes (90%+ of issues)
259
+
260
+ **Execution**:
261
+
262
+ ```bash
263
+ # Run linter
264
+ eslint src/**/*.js --fix
265
+
266
+ # Run formatter
267
+ prettier src/**/*.js --write
268
+ ```
269
+
270
+ **Fixable Issues**:
271
+ - Indentation
272
+ - Semicolons
273
+ - Quotes (single vs double)
274
+ - Trailing whitespace
275
+ - Missing newlines
276
+ - Unused variables (safe removals)
277
+
278
+ **Non-Fixable Issues** (Escalate):
279
+ - Undefined variables
280
+ - Complex logic errors
281
+ - Missing imports
282
+
283
+ **Result**:
284
+ - ✅ Pass: All issues fixed or none found
285
+ - ⚠️ Escalate: Non-fixable issues require user intervention
286
+
287
+ ---
288
+
289
+ ### 2.3 Phase 2: Structure Validation
290
+
291
+ **Purpose**: Ensure proper code organization and imports
292
+
293
+ **Auto-Fix**: Yes (import ordering, file organization)
294
+
295
+ **Checks**:
296
+ - Import organization (external → internal → relative)
297
+ - Unused imports (remove)
298
+ - File placement (correct directory)
299
+ - Module exports
300
+
301
+ **Auto-Fix Actions**:
302
+
303
+ ```javascript
304
+ // BEFORE: Messy imports
305
+ const config = require('./config');
306
+ const express = require('express');
307
+ const userService = require('../services/userService');
308
+ const jwt = require('jsonwebtoken');
309
+
310
+ // AFTER: Organized imports
311
+ // External dependencies
312
+ const express = require('express');
313
+ const jwt = require('jsonwebtoken');
314
+
315
+ // Internal modules
316
+ const userService = require('../services/userService');
317
+
318
+ // Relative imports
319
+ const config = require('./config');
320
+ ```
321
+
322
+ **Result**:
323
+ - ✅ Pass: Structure validated, imports organized
324
+ - ⚠️ Warning: File in wrong directory (suggest move)
325
+
326
+ ---
327
+
328
+ ### 2.4 Phase 3: Build Validation
329
+
330
+ **Purpose**: Ensure code compiles/builds successfully
331
+
332
+ **Tools**: TypeScript (if used), Babel, Webpack
333
+
334
+ **Auto-Fix**: No (build errors require code changes)
335
+
336
+ **Execution**:
337
+
338
+ ```bash
339
+ npm run build
340
+ ```
341
+
342
+ **Success Criteria**:
343
+ - Exit code 0
344
+ - No compilation errors
345
+ - Output files generated
346
+
347
+ **Result**:
348
+ - ✅ Pass: Build successful
349
+ - ❌ Fail: Build errors, escalate to user (show errors)
350
+
351
+ ---
352
+
353
+ ### 2.5 Phase 4: Testing
354
+
355
+ **Purpose**: Ensure all tests pass
356
+
357
+ **Tools**: Jest, Mocha, or configured test runner
358
+
359
+ **Auto-Fix**: No (test failures require code/test changes)
360
+
361
+ **Execution**:
362
+
363
+ ```bash
364
+ npm test
365
+ ```
366
+
367
+ **Success Criteria**:
368
+ - All tests pass
369
+ - No test errors
370
+ - No flaky tests
371
+
372
+ **Result**:
373
+ - ✅ Pass: All tests passing
374
+ - ❌ Fail: Test failures, escalate with details
375
+
376
+ **Escalation Info**:
377
+ ```
378
+ ❌ Quality Gate Phase 4 Failed: 3 tests failing
379
+
380
+ Failed Tests:
381
+ 1. UserService › createUser › should hash password
382
+ Expected: hash(password)
383
+ Received: plaintext password
384
+
385
+ 2. UserService › deleteUser › should remove user from database
386
+ Error: Database connection timeout
387
+
388
+ 3. AuthService › login › should return JWT token
389
+ Expected: valid JWT
390
+ Received: undefined
391
+
392
+ 💡 Fix failing tests and re-run quality gate
393
+ ```
394
+
395
+ ---
396
+
397
+ ### 2.6 Phase 5: Coverage Validation
398
+
399
+ **Purpose**: Ensure adequate test coverage (≥80%)
400
+
401
+ **Tools**: Istanbul/NYC (Jest built-in coverage)
402
+
403
+ **Auto-Fix**: No (low coverage requires more tests)
404
+
405
+ **Execution**:
406
+
407
+ ```bash
408
+ npm run test:coverage
409
+ ```
410
+
411
+ **Success Criteria**:
412
+ - Line coverage ≥80%
413
+ - Branch coverage ≥80%
414
+ - Function coverage ≥80%
415
+ - Statement coverage ≥80%
416
+
417
+ **Result**:
418
+ - ✅ Pass: Coverage ≥80%
419
+ - ❌ Fail: Coverage <80%, escalate with details
420
+
421
+ **Escalation Info**:
422
+ ```
423
+ ❌ Quality Gate Phase 5 Failed: Coverage below threshold
424
+
425
+ Coverage Report:
426
+ - Lines: 72% (target: 80%)
427
+ - Branches: 68% (target: 80%)
428
+ - Functions: 75% (target: 80%)
429
+ - Statements: 73% (target: 80%)
430
+
431
+ Uncovered Files:
432
+ - src/services/userService.js (45% coverage)
433
+ - src/utils/validation.js (60% coverage)
434
+
435
+ 💡 Add tests to increase coverage
436
+ ```
437
+
438
+ ---
439
+
440
+ ### 2.7 Phase 6: Final Review (Compliance)
441
+
442
+ **Purpose**: Validate compliance with CODING-PRINCIPLES and TESTING-PRINCIPLES
443
+
444
+ **Auto-Fix**: Yes (for simple violations)
445
+
446
+ **Checks**:
447
+ - Function parameter count (≤2)
448
+ - Function length (<50 lines)
449
+ - Error handling (try-catch for async)
450
+ - Test structure (AAA pattern)
451
+ - Naming conventions
452
+
453
+ **Auto-Fix Examples**:
454
+
455
+ ```javascript
456
+ // BEFORE: 3 parameters (violation)
457
+ function createUser(email, password, name) {
458
+ // ...
459
+ }
460
+
461
+ // AFTER: Auto-refactor to config object
462
+ function createUser(config) {
463
+ const { email, password, name } = config;
464
+ // ...
465
+ }
466
+ ```
467
+
468
+ **Escalate When**:
469
+ - Ambiguous violation (unclear how to fix)
470
+ - Business logic decision needed
471
+ - Specification ambiguity
472
+ - Complex refactoring required
473
+
474
+ **Result**:
475
+ - ✅ Pass: All compliance checks pass
476
+ - ⚠️ Warning: Minor violations auto-fixed
477
+ - ❌ Escalate: Ambiguous violations require user decision
478
+
479
+ ---
480
+
481
+ ### 2.8 Quality Gate Summary
482
+
483
+ **Success Flow**:
484
+ ```
485
+ Phase 1 (Lint) → auto-fix → pass
486
+ Phase 2 (Structure) → auto-fix → pass
487
+ Phase 3 (Build) → validate → pass
488
+ Phase 4 (Test) → validate → pass
489
+ Phase 5 (Coverage) → validate → pass
490
+ Phase 6 (Compliance) → auto-fix → pass
491
+ → ✅ COMMIT APPROVED
492
+ ```
493
+
494
+ **Failure Flow**:
495
+ ```
496
+ Phase 1-6 → any failure → ❌ BLOCK COMMIT
497
+ → 🔄 ROLLBACK changes
498
+ → 📝 LOG failure details
499
+ → 💡 NOTIFY user with actionable error
500
+ ```
501
+
502
+ **Auto-Fix Rate Target**: >90%
503
+
504
+ **Zero-Error Enforcement**: 100% (no commits with errors)
505
+
506
+ ---
507
+
508
+ ## 3. Agent Communication Protocol
509
+
510
+ ### 3.1 JSON Handoff Format
511
+
512
+ **Rule**: All agents communicate via structured JSON handoff
513
+
514
+ **Standard Format**:
515
+
516
+ ```json
517
+ {
518
+ "agent": "MON",
519
+ "status": "success",
520
+ "scale": "medium",
521
+ "data": {
522
+ "requirements": [
523
+ "User can edit profile information",
524
+ "Changes save to database",
525
+ "Email notification on profile update"
526
+ ],
527
+ "fileCount": 4,
528
+ "complexity": "medium",
529
+ "integrations": ["database", "email-service"]
530
+ },
531
+ "nextAgent": "ROR",
532
+ "stopPointRequired": false,
533
+ "artifacts": {
534
+ "requirements": "docs/plans/requirements-001.md"
535
+ },
536
+ "errors": []
537
+ }
538
+ ```
539
+
540
+ **Required Fields**:
541
+ - `agent`: Current agent name
542
+ - `status`: "success" | "failed" | "escalated"
543
+ - `data`: Agent-specific output
544
+ - `nextAgent`: Next agent in workflow or null if complete
545
+ - `errors`: Array of error objects (empty if success)
546
+
547
+ **Optional Fields**:
548
+ - `scale`: "small" | "medium" | "large" (from MON)
549
+ - `stopPointRequired`: boolean (if user approval needed)
550
+ - `artifacts`: File paths to generated documents
551
+ - `metadata`: Additional context
552
+
553
+ ### 3.2 Agent Responsibilities
554
+
555
+ **MON (Requirement Analyzer)**:
556
+ - Input: User requirement (text)
557
+ - Output: Scale, requirements list, file count, next agent
558
+ - Stop Point: No
559
+
560
+ **ROR (Technical Designer)**:
561
+ - Input: Requirements from MON
562
+ - Output: Design document, ADR (if large), verification level
563
+ - Stop Point: Yes (design review)
564
+
565
+ **TRA (Work Planner)**:
566
+ - Input: Design from ROR
567
+ - Output: Work plan with phases, stop point placement
568
+ - Stop Point: No
569
+
570
+ **EUS (Task Decomposer)**:
571
+ - Input: Work plan from TRA
572
+ - Output: Atomic tasks (1-commit each), dependencies
573
+ - Stop Point: Yes (plan review)
574
+
575
+ **KIL (Task Executor)**:
576
+ - Input: Tasks from EUS
577
+ - Output: Implementation (TDD), commits
578
+ - Stop Point: No (executes autonomously post-approval)
579
+
580
+ **BAS (Quality Fixer)**:
581
+ - Input: Code changes from KIL
582
+ - Output: Quality gate results, auto-fixed code
583
+ - Stop Point: No (blocks commit on failure)
584
+
585
+ **DRA (Code Reviewer)**:
586
+ - Input: Code from BAS
587
+ - Output: Code review approval/feedback
588
+ - Stop Point: No
589
+
590
+ ### 3.3 Error Handling
591
+
592
+ **Agent Failure**:
593
+
594
+ ```json
595
+ {
596
+ "agent": "KIL",
597
+ "status": "failed",
598
+ "data": null,
599
+ "nextAgent": null,
600
+ "errors": [
601
+ {
602
+ "type": "implementation-error",
603
+ "message": "Cannot determine how to implement getUsersByRole",
604
+ "context": "Ambiguous requirement: 'by role' not defined",
605
+ "suggestion": "Clarify: Does role refer to user.role field or user.permissions?"
606
+ }
607
+ ]
608
+ }
609
+ ```
610
+
611
+ **Escalation**:
612
+
613
+ ```json
614
+ {
615
+ "agent": "BAS",
616
+ "status": "escalated",
617
+ "data": {
618
+ "phase": 6,
619
+ "issue": "compliance-violation"
620
+ },
621
+ "nextAgent": "ALY",
622
+ "errors": [
623
+ {
624
+ "type": "ambiguous-violation",
625
+ "message": "Function processOrder has 3 parameters but unclear how to refactor",
626
+ "context": "Parameters: order, user, options - all seem necessary",
627
+ "suggestion": "Should we use config object or separate into multiple functions?"
628
+ }
629
+ ]
630
+ }
631
+ ```
632
+
633
+ **Retry Logic**:
634
+ - Auto-retry on transient failures (network, timeout): max 3 attempts
635
+ - Escalate to ALY on repeated failures
636
+ - Escalate immediately on ambiguity
637
+
638
+ ---
639
+
640
+ ## 4. Escalation Protocols
641
+
642
+ ### 4.1 When to Escalate to ALY
643
+
644
+ **Escalate When**:
645
+ - Ambiguous requirements (unclear what to implement)
646
+ - Conflicting requirements
647
+ - Missing information (user input needed)
648
+ - Specification ambiguity (multiple valid interpretations)
649
+ - Technical decision outside agent expertise
650
+ - Quality gate failures after auto-fix attempts (ambiguous fixes)
651
+
652
+ **Don't Escalate When**:
653
+ - Clear error messages (user can fix)
654
+ - Auto-fixable issues (BAS handles)
655
+ - Known patterns (agent follows established approach)
656
+
657
+ ### 4.2 Escalation Format
658
+
659
+ ```json
660
+ {
661
+ "from": "KIL",
662
+ "to": "ALY",
663
+ "reason": "ambiguous-requirement",
664
+ "context": {
665
+ "requirement": "Add user filtering by 'status'",
666
+ "ambiguity": "Multiple status fields found: user.accountStatus, user.subscriptionStatus, user.verificationStatus",
667
+ "question": "Which status field should be used for filtering?"
668
+ },
669
+ "options": [
670
+ "user.accountStatus (active/inactive/suspended)",
671
+ "user.subscriptionStatus (free/premium/enterprise)",
672
+ "user.verificationStatus (verified/unverified)"
673
+ ],
674
+ "recommendation": "user.accountStatus (most commonly used in similar features)"
675
+ }
676
+ ```
677
+
678
+ ### 4.3 ALY Investigation
679
+
680
+ **ALY's Role**:
681
+ 1. Receive escalation from agent
682
+ 2. Investigate context and gather information
683
+ 3. Clarify ambiguity with user (if needed)
684
+ 4. Provide clear guidance back to agent
685
+ 5. Update requirements/design if needed
686
+
687
+ **ALY Response**:
688
+
689
+ ```json
690
+ {
691
+ "investigationId": "INV-2025-042",
692
+ "clarification": "Use user.accountStatus for filtering",
693
+ "rationale": "Matches existing user management UI patterns",
694
+ "guidance": {
695
+ "filterField": "accountStatus",
696
+ "validValues": ["active", "inactive", "suspended"],
697
+ "apiEndpoint": "/users?status=active"
698
+ },
699
+ "resumeAgent": "KIL",
700
+ "updatedRequirements": "docs/plans/requirements-001-updated.md"
701
+ }
702
+ ```
703
+
704
+ ---
705
+
706
+ ## 5. Autonomous Mode
707
+
708
+ ### 5.1 Post-Approval Execution
709
+
710
+ **Rule**: After user approves at stop points, remaining workflow executes autonomously
711
+
712
+ **Medium Workflow Example**:
713
+
714
+ ```
715
+ User Request → MON → ROR → 🛑 STOP (user approves design)
716
+
717
+ TRA → EUS → 🛑 STOP (user approves plan)
718
+
719
+ [AUTONOMOUS EXECUTION BEGINS]
720
+
721
+ KIL (implement)
722
+
723
+ BAS (quality gate)
724
+
725
+ DRA (code review)
726
+
727
+ [COMMIT]
728
+ ```
729
+
730
+ **No User Interaction Required**:
731
+ - KIL implements all tasks sequentially
732
+ - BAS auto-fixes issues
733
+ - DRA reviews and approves
734
+ - Commits created automatically
735
+
736
+ **User Notified**:
737
+ - Progress updates (optional, non-blocking)
738
+ - Completion notification
739
+ - Escalation if issues arise
740
+
741
+ ### 5.2 Rollback on Failure
742
+
743
+ **Rule**: If quality gate fails, rollback entire workflow
744
+
745
+ ```bash
746
+ # Automatic rollback
747
+ git reset --hard HEAD~N # N = commits in this workflow
748
+
749
+ # Log failure
750
+ logger.error({
751
+ workflowId: 'wf-123',
752
+ failedAt: 'BAS-Phase-4',
753
+ reason: 'Test failures',
754
+ rollbackCommits: 3
755
+ });
756
+
757
+ # Notify user
758
+ console.error('❌ Workflow failed at quality gate');
759
+ console.log('💡 Fix issues and re-run /trinity-orchestrate');
760
+ ```
761
+
762
+ ---
763
+
764
+ ## 6. Configuration
765
+
766
+ ### 6.1 Workflow Configuration
767
+
768
+ **File**: `trinity.config.js`
769
+
770
+ ```javascript
771
+ module.exports = {
772
+ // Workflow settings
773
+ workflows: {
774
+ enableStopPoints: true, // false = fully autonomous (risky)
775
+ autonomousMode: false, // true = auto-proceed at stop points (risky)
776
+ scaleOverride: null // 'small'|'medium'|'large' to override MON
777
+ },
778
+
779
+ // Quality gate settings
780
+ qualityGate: {
781
+ enabled: true,
782
+ coverage: {
783
+ threshold: 80,
784
+ enforceOnCommit: true
785
+ },
786
+ linting: {
787
+ autoFix: true,
788
+ failOnError: true
789
+ },
790
+ buildValidation: {
791
+ enabled: true
792
+ }
793
+ },
794
+
795
+ // Agent settings
796
+ agents: {
797
+ timeout: 300000, // 5 minutes per agent
798
+ maxRetries: 3,
799
+ escalateToALY: true
800
+ }
801
+ };
802
+ ```
803
+
804
+ ### 6.2 Per-Project Customization
805
+
806
+ ```javascript
807
+ // Override for specific project needs
808
+ module.exports = {
809
+ workflows: {
810
+ enableStopPoints: {
811
+ small: false, // No stops for small
812
+ medium: true, // 2 stops for medium
813
+ large: true // 4 stops for large
814
+ }
815
+ },
816
+
817
+ qualityGate: {
818
+ coverage: {
819
+ threshold: 85, // Higher than default 80%
820
+ excludePatterns: ['src/legacy/**'] // Exclude legacy code
821
+ }
822
+ }
823
+ };
824
+ ```
825
+
826
+ ---
827
+
828
+ ## 7. Monitoring & Metrics
829
+
830
+ ### 7.1 Workflow Metrics
831
+
832
+ **Track**:
833
+ - Workflow duration (by scale)
834
+ - Stop point approval time
835
+ - Auto-fix success rate
836
+ - Escalation rate
837
+ - Commit success rate
838
+
839
+ **Dashboard**:
840
+
841
+ ```
842
+ Trinity Workflow Metrics (Last 30 Days)
843
+
844
+ Small Workflows:
845
+ - Total: 142
846
+ - Avg Duration: 28 min (target: ≤30 min) ✅
847
+ - Success Rate: 98% ✅
848
+
849
+ Medium Workflows:
850
+ - Total: 67
851
+ - Avg Duration: 2.8 hours (target: ≤3 hours) ✅
852
+ - Stop Points: 2 (avg approval time: 12 min)
853
+ - Success Rate: 95% ✅
854
+
855
+ Large Workflows:
856
+ - Total: 18
857
+ - Avg Duration: 1.3 days (target: ≤1.5 days) ✅
858
+ - Stop Points: 4 (avg approval time: 45 min)
859
+ - Success Rate: 94% ✅
860
+
861
+ Quality Gate:
862
+ - Auto-Fix Rate: 92% (target: ≥90%) ✅
863
+ - Escalation Rate: 8%
864
+ - Zero-Error Commits: 100% ✅
865
+ ```
866
+
867
+ ### 7.2 Agent Performance
868
+
869
+ **Track**:
870
+ - Agent execution time
871
+ - Agent failure rate
872
+ - Agent escalation rate
873
+
874
+ **Alerts**:
875
+ - Agent timeout (>5 min)
876
+ - High failure rate (>10%)
877
+ - Escalation spike (>15%)
878
+
879
+ ---
880
+
881
+ ## 8. Best Practices
882
+
883
+ ### 8.1 Clear Requirements
884
+
885
+ **✅ Good Requirements**:
886
+ - "Add user profile edit endpoint: PATCH /users/:id/profile, accepts name/email/avatar, validates email format, returns updated user"
887
+
888
+ **❌ Vague Requirements**:
889
+ - "Make user profile editable"
890
+
891
+ ### 8.2 Trust the Process
892
+
893
+ **Do**:
894
+ - Trust MON's scale determination
895
+ - Review designs/plans at stop points
896
+ - Let BAS handle quality (don't bypass)
897
+ - Allow autonomous execution post-approval
898
+
899
+ **Don't**:
900
+ - Override scale without good reason
901
+ - Skip stop points (unless small scale)
902
+ - Bypass quality gate (emergency only)
903
+ - Micromanage agent execution
904
+
905
+ ### 8.3 Iterate on Feedback
906
+
907
+ **If design rejected**:
908
+ - ROR incorporates feedback
909
+ - Re-submits for approval
910
+ - May require multiple iterations
911
+
912
+ **If quality gate fails**:
913
+ - Fix issues flagged by BAS
914
+ - Re-run quality gate
915
+ - May require code/test changes
916
+
917
+ ---
918
+
919
+ ## References
920
+
921
+ - Trinity Method SDK v2.0 Architecture
922
+ - CODING-PRINCIPLES.md
923
+ - TESTING-PRINCIPLES.md
924
+ - DOCUMENTATION-CRITERIA.md
925
+
926
+ ---
927
+
928
+ ## 📝 WHEN TO UPDATE THIS DOCUMENT
929
+
930
+ This **workflow guide** updates when Trinity Method workflows improve.
931
+
932
+ ### When to Update ⚠️
933
+
934
+ Update **only when workflows change**:
935
+
936
+ - ✅ **Workflow Improved**: Team discovers better way to execute Trinity workflows
937
+ - ✅ **Scale Criteria Changed**: Team adjusts Small/Medium/Large definitions based on experience
938
+ - ✅ **Agent Protocol Updated**: Agent communication patterns improve
939
+ - ✅ **BAS Phase Modified**: Quality gate phases adjusted based on project needs
940
+
941
+ ### How to Update
942
+
943
+ 1. Update workflow description with improved process
944
+ 2. Add new scale example if team discovered edge case
945
+ 3. Update agent communication pattern if protocol improved
946
+ 4. Cross-reference to Trinity.md if core methodology changed
947
+ 5. Update timestamp: `Last reviewed: {{date}}`
948
+
949
+ **Cross-References**: When updating, also update [Trinity.md](./Trinity.md) if methodology itself changed.
950
+
951
+ **Update Frequency**: Occasional (monthly) - workflows improve with team experience
952
+
953
+ ---
954
+
955
+ **Document maintained by**: ZEN (Documentation Specialist)
956
+ **Used by**: All 19 agents, AJ MAESTRO orchestration
957
+ **Last reviewed**: {{date}}