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,646 @@
1
+ ---
2
+ description: Launch comprehensive, deterministic codebase audit with JUNO
3
+ ---
4
+
5
+ # Trinity Audit
6
+
7
+ **Purpose:** Launch JUNO to perform systematic, framework-agnostic codebase audit.
8
+
9
+ **Primary Use Case:** Comprehensive quality assessment of any codebase (JavaScript, Python, Rust, Go, etc.)
10
+
11
+ **IMPORTANT:** When the user invokes `/trinity-audit`, proceed immediately with systematic analysis. The audit is deterministic and reproducible.
12
+
13
+ ---
14
+
15
+ ## Overview
16
+
17
+ `/trinity-audit` invokes **JUNO (Quality Auditor)** to perform systematic analysis using:
18
+ - **Automated tool execution** (linters, coverage, security scanners)
19
+ - **Universal code patterns** (works on any language)
20
+ - **Baseline tracking** (compare against previous audits)
21
+ - **Objective metrics** (not subjective observations)
22
+
23
+ **What Makes This Audit Different:**
24
+ - ✅ **Deterministic:** Same code = same results every time
25
+ - ✅ **Framework-agnostic:** Works on Node.js, Python, Rust, Go, etc.
26
+ - ✅ **Baseline tracking:** Second audit shows only NEW or PERSISTENT issues
27
+ - ✅ **Completeness guarantee:** Explicit coverage metrics (100% of files analyzed)
28
+ - ✅ **Tool-based:** Uses actual linters/scanners, not just file reading
29
+
30
+ **Deliverable:**
31
+ - `trinity/reports/CODEBASE-AUDIT-{date}.md` (human-readable report)
32
+ - `trinity/reports/AUDIT-BASELINE-{date}.json` (machine-readable baseline for future comparisons)
33
+
34
+ ---
35
+
36
+ ## When to Use
37
+
38
+ ### ✅ Use /trinity-audit When:
39
+
40
+ 1. **First time auditing a codebase**
41
+ - Creates baseline for future comparisons
42
+ - Identifies ALL current issues systematically
43
+
44
+ 2. **After fixing audit issues**
45
+ - Verify fixes resolved the problems
46
+ - Ensure no new issues were introduced
47
+ - See progress: "X issues fixed, 0 new issues"
48
+
49
+ 3. **Before major refactoring**
50
+ - Establish quality baseline
51
+ - Track improvements over time
52
+
53
+ 4. **Periodic quality checks**
54
+ - Monthly/quarterly codebase health review
55
+ - Track technical debt accumulation
56
+
57
+ ### ⚠️ Second Audit Behavior:
58
+
59
+ When a baseline exists (`trinity/reports/AUDIT-BASELINE-*.json`):
60
+ - **FIXED issues:** ✅ Marked as resolved (celebrate!)
61
+ - **NEW issues:** ⚠️ Flagged as introduced since last audit
62
+ - **PERSISTENT issues:** 🔴 Still present from previous audit
63
+
64
+ **Goal:** Second audit should show "0 new issues, 0 persistent issues" if you fixed everything.
65
+
66
+ ---
67
+
68
+ ## JUNO's Deterministic Audit Protocol
69
+
70
+ JUNO follows a **strict, repeatable process** to ensure consistent results:
71
+
72
+ ### Phase 0: Baseline Check & Comparison
73
+
74
+ **CRITICAL:** Load previous audit baseline if it exists.
75
+
76
+ ```bash
77
+ # Check for existing baseline
78
+ IF trinity/reports/AUDIT-BASELINE-*.json exists:
79
+ - Load previous findings
80
+ - Track what's been fixed ✅
81
+ - Track what's new ⚠️
82
+ - Track what's persistent 🔴
83
+ - Report: "Comparing against baseline from {date}"
84
+ ELSE:
85
+ - This is first audit
86
+ - Create new baseline
87
+ - Report: "Creating new audit baseline"
88
+ ```
89
+
90
+ **Output:**
91
+ - State whether baseline exists
92
+ - If comparing: Show baseline date
93
+ - Set audit mode: BASELINE or COMPARISON
94
+
95
+ ---
96
+
97
+ ### Phase 1: Stack Detection (Framework-Agnostic)
98
+
99
+ **Systematic discovery** of project type, language, and available tools.
100
+
101
+ **Steps (execute ALL, skip none):**
102
+
103
+ 1. **Detect Language & Framework:**
104
+ ```bash
105
+ Check for package.json → Node.js/JavaScript/TypeScript
106
+ Check for Cargo.toml → Rust
107
+ Check for go.mod → Go
108
+ Check for requirements.txt, setup.py, pyproject.toml → Python
109
+ Check for Gemfile → Ruby
110
+ Check for pom.xml, build.gradle → Java
111
+ Check for pubspec.yaml → Flutter/Dart
112
+ Check for *.csproj → C#
113
+ ```
114
+
115
+ 2. **Identify ALL Source Directories:**
116
+ ```bash
117
+ Scan for: src/, lib/, app/, pkg/, internal/
118
+ Ignore: node_modules/, dist/, build/, target/, vendor/
119
+ ```
120
+
121
+ 3. **Count Files by Extension:**
122
+ ```bash
123
+ .js, .ts, .jsx, .tsx → JavaScript/TypeScript count
124
+ .py → Python count
125
+ .rs → Rust count
126
+ .go → Go count
127
+ .rb → Ruby count
128
+ .java → Java count
129
+ .cs → C# count
130
+ ```
131
+
132
+ 4. **Calculate Total LOC:**
133
+ ```bash
134
+ Use Bash tool: find . -name "*.{ext}" -exec wc -l {} + | tail -1
135
+ ```
136
+
137
+ 5. **Identify Available Tools:**
138
+ ```bash
139
+ Check if eslint exists: which eslint || npm list eslint
140
+ Check if pytest exists: which pytest
141
+ Check if cargo exists: which cargo
142
+ Check if go exists: which go
143
+ Document which tools are available vs unavailable
144
+ ```
145
+
146
+ **Output:**
147
+ ```json
148
+ {
149
+ "language": "JavaScript/TypeScript",
150
+ "framework": "Node.js",
151
+ "source_dirs": ["src/", "tests/"],
152
+ "file_counts": {"ts": 49, "json": 12},
153
+ "total_loc": 4632,
154
+ "tools_available": ["eslint", "jest", "npm"],
155
+ "tools_unavailable": ["cargo", "go", "pytest"]
156
+ }
157
+ ```
158
+
159
+ ---
160
+
161
+ ### Phase 2: Automated Tool Execution (Opportunistic)
162
+
163
+ **RUN ACTUAL TOOLS** to get objective metrics. Do NOT skip this phase.
164
+
165
+ **For Each Available Tool:**
166
+
167
+ #### If `npm run lint` or `eslint` exists:
168
+ ```bash
169
+ npm run lint 2>&1 | tee audit-lint-output.txt
170
+ # OR
171
+ eslint . --format json > audit-eslint.json
172
+
173
+ Parse output:
174
+ - Count total warnings/errors
175
+ - Extract ALL specific issues (file:line:rule)
176
+ - Group by severity (error vs warning)
177
+ - Save to findings array
178
+ ```
179
+
180
+ #### If `npm test` or test framework exists:
181
+ ```bash
182
+ npm run test:coverage 2>&1 | tee audit-coverage-output.txt
183
+ # OR pytest --cov
184
+ # OR cargo test
185
+ # OR go test -cover
186
+
187
+ Parse output:
188
+ - Extract coverage percentage
189
+ - Identify uncovered files
190
+ - Count total tests passing/failing
191
+ ```
192
+
193
+ #### If `npm audit` or dependency checker exists:
194
+ ```bash
195
+ npm audit --json > audit-dependencies.json
196
+ # OR pip-audit
197
+ # OR cargo audit
198
+
199
+ Parse output:
200
+ - List vulnerabilities with CVE IDs
201
+ - Group by severity (critical/high/medium/low)
202
+ - Note outdated packages
203
+ ```
204
+
205
+ #### If TypeScript compiler exists:
206
+ ```bash
207
+ tsc --noEmit 2>&1 | tee audit-tsc-output.txt
208
+
209
+ Parse output:
210
+ - Count type errors
211
+ - Extract specific errors (file:line)
212
+ ```
213
+
214
+ **Output:**
215
+ ```json
216
+ {
217
+ "tools_executed": {
218
+ "lint": {"run": true, "errors": 13, "warnings": 44},
219
+ "coverage": {"run": true, "percentage": 67},
220
+ "audit": {"run": true, "vulnerabilities": 0},
221
+ "typecheck": {"run": true, "errors": 0}
222
+ }
223
+ }
224
+ ```
225
+
226
+ **IMPORTANT:** Document which tools ran and which couldn't run. This is critical for reproducibility.
227
+
228
+ ---
229
+
230
+ ### Phase 3: Universal Code Analysis (Language-Agnostic)
231
+
232
+ **These checks work on ANY codebase**, regardless of language or tooling.
233
+
234
+ **Execute ALL checks systematically:**
235
+
236
+ 1. **TODO/FIXME/HACK Comments:**
237
+ ```bash
238
+ grep -rn "TODO\|FIXME\|HACK" src/ --exclude-dir=node_modules
239
+
240
+ For each match:
241
+ - Record file:line
242
+ - Extract comment text
243
+ - Flag as technical debt
244
+ ```
245
+
246
+ 2. **Hardcoded Secrets Detection:**
247
+ ```bash
248
+ grep -rniE "(api_key|apikey|secret|password|token|auth.*=).*['\"][a-zA-Z0-9]{20,}" src/ --exclude-dir=node_modules
249
+
250
+ Patterns to check:
251
+ - API_KEY = "..."
252
+ - password = "..."
253
+ - secret = "..."
254
+ - Bearer tokens
255
+ ```
256
+
257
+ 3. **Large File Detection:**
258
+ ```bash
259
+ find src/ -name "*.{js,ts,py,rs,go}" -exec wc -l {} + | awk '$1 > 500 {print}'
260
+
261
+ Flag files >500 LOC for review
262
+ ```
263
+
264
+ 4. **Directory Structure Depth:**
265
+ ```bash
266
+ find src/ -type d | awk -F/ 'NF > 5 {print}'
267
+
268
+ Flag deeply nested directories (>5 levels)
269
+ ```
270
+
271
+ 5. **Missing Documentation:**
272
+ ```bash
273
+ Check for README.md in root
274
+ Check for CONTRIBUTING.md
275
+ Check for API documentation (docs/ or similar)
276
+ ```
277
+
278
+ 6. **Environment File Exposure:**
279
+ ```bash
280
+ Check if .env exists AND .env.example does NOT exist
281
+ Check if .env is in .gitignore
282
+ ```
283
+
284
+ **Output:**
285
+ ```json
286
+ {
287
+ "universal_checks": {
288
+ "todo_comments": 12,
289
+ "hardcoded_secrets": 0,
290
+ "large_files": 2,
291
+ "deep_nesting": 0,
292
+ "missing_docs": false,
293
+ "env_exposure_risk": false
294
+ }
295
+ }
296
+ ```
297
+
298
+ ---
299
+
300
+ ### Phase 4: Language-Specific Pattern Detection
301
+
302
+ **Based on detected language**, check for common anti-patterns:
303
+
304
+ #### JavaScript/TypeScript:
305
+ ```bash
306
+ grep -rn "eval(" src/
307
+ grep -rn "innerHTML.*=" src/
308
+ grep -rn " == " src/ # Suggest === instead
309
+ ```
310
+
311
+ #### Python:
312
+ ```bash
313
+ grep -rn "exec(" src/
314
+ grep -rn "input()" src/ # Check for validation
315
+ ```
316
+
317
+ #### Rust:
318
+ ```bash
319
+ grep -rn "unsafe" src/
320
+ ```
321
+
322
+ #### Go:
323
+ ```bash
324
+ grep -rn "go func" src/ # Check for goroutine leaks
325
+ ```
326
+
327
+ **Output:** List of pattern matches with file:line
328
+
329
+ ---
330
+
331
+ ### Phase 5: Baseline Comparison (If Baseline Exists)
332
+
333
+ **CRITICAL PHASE:** Compare current findings against previous audit.
334
+
335
+ ```json
336
+ IF baseline exists:
337
+ FOR EACH issue in previous_baseline:
338
+ IF issue NOT in current_findings:
339
+ status = "FIXED" ✅
340
+ ELSE:
341
+ status = "PERSISTENT" 🔴
342
+
343
+ FOR EACH issue in current_findings:
344
+ IF issue NOT in previous_baseline:
345
+ status = "NEW" ⚠️
346
+ ELSE:
347
+ status = "PERSISTENT" 🔴
348
+
349
+ Report summary:
350
+ - Fixed: X issues ✅
351
+ - Persistent: Y issues 🔴
352
+ - New: Z issues ⚠️
353
+ ```
354
+
355
+ **This is what prevents infinite audit cycles.**
356
+
357
+ ---
358
+
359
+ ### Phase 6: Completeness Verification
360
+
361
+ **Explicitly state what was analyzed** to guarantee thoroughness.
362
+
363
+ **Required Metrics:**
364
+
365
+ ```json
366
+ {
367
+ "completeness": {
368
+ "files_analyzed": "49/49 (100%)",
369
+ "tools_executed": "3/5 available tools",
370
+ "universal_checks": "6/6 checks completed",
371
+ "language_patterns": "4/4 patterns checked",
372
+ "baseline_comparison": "yes" or "no (first audit)",
373
+ "confidence_level": "HIGH" or "MEDIUM" or "LOW"
374
+ }
375
+ }
376
+ ```
377
+
378
+ **Confidence Levels:**
379
+ - **HIGH:** All available tools ran successfully, 100% file coverage
380
+ - **MEDIUM:** Some tools unavailable, but all files analyzed
381
+ - **LOW:** Many tools unavailable, manual analysis only
382
+
383
+ ---
384
+
385
+ ### Phase 7: Generate Findings Report
386
+
387
+ **Structure findings by priority** (based on objective criteria):
388
+
389
+ #### CRITICAL (P0):
390
+ - Security vulnerabilities (CVE with CVSS > 7.0)
391
+ - Hardcoded secrets found
392
+ - Authentication/authorization bypasses
393
+ - SQL injection, XSS, RCE vulnerabilities
394
+
395
+ #### HIGH (P1):
396
+ - Lint errors (not warnings)
397
+ - Failed tests
398
+ - Coverage below 50%
399
+ - Outdated dependencies with known vulnerabilities
400
+ - Type errors (if TypeScript)
401
+
402
+ #### MEDIUM (P2):
403
+ - Lint warnings
404
+ - Coverage 50-80%
405
+ - TODO/FIXME comments
406
+ - Large files (>500 LOC)
407
+ - Cyclomatic complexity >15
408
+
409
+ #### LOW (P3):
410
+ - Documentation gaps
411
+ - Deep directory nesting
412
+ - Minor code style issues
413
+
414
+ **Each finding must include:**
415
+ - File path
416
+ - Line number (if applicable)
417
+ - Issue description
418
+ - Tool that detected it (or "manual analysis")
419
+ - Recommendation for fix
420
+ - Estimated effort
421
+
422
+ ---
423
+
424
+ ### Phase 8: Save Outputs
425
+
426
+ **Two files created:**
427
+
428
+ #### 1. Human-Readable Report: `trinity/reports/CODEBASE-AUDIT-{date}.md`
429
+
430
+ ```markdown
431
+ # Codebase Audit Report
432
+
433
+ **Audit Date:** {timestamp}
434
+ **Audit Mode:** {BASELINE | COMPARISON}
435
+ **Baseline Date:** {previous-audit-date} (if comparison)
436
+
437
+ ## Executive Summary
438
+
439
+ **Project Type:** {type}
440
+ **Language:** {language}
441
+ **Framework:** {framework}
442
+ **Total LOC:** {loc}
443
+ **Files Analyzed:** {count}
444
+
445
+ ### Audit Results
446
+
447
+ - **Fixed Issues:** {count} ✅ (if comparison mode)
448
+ - **Persistent Issues:** {count} 🔴 (if comparison mode)
449
+ - **New Issues:** {count} ⚠️ (if comparison mode)
450
+ - **Total Issues:** {count}
451
+
452
+ ### Completeness Metrics
453
+
454
+ - Files analyzed: 100% (49/49)
455
+ - Tools executed: 3/5 available
456
+ - Confidence: HIGH
457
+
458
+ ## Findings by Priority
459
+
460
+ ### 🔴 CRITICAL (Fix Immediately)
461
+ [List with file:line references]
462
+
463
+ ### 🟡 HIGH (Fix This Week)
464
+ [List with file:line references]
465
+
466
+ ### 🟢 MEDIUM (Improvements)
467
+ [List with file:line references]
468
+
469
+ ### 💡 QUICK WINS
470
+ [Easy fixes, <30min each]
471
+
472
+ ## Tool Execution Details
473
+
474
+ ### ESLint Results
475
+ - Errors: {count}
476
+ - Warnings: {count}
477
+ [Specific issues...]
478
+
479
+ ### Test Coverage
480
+ - Percentage: {percent}%
481
+ - Uncovered files: [list]
482
+
483
+ ### Dependency Audit
484
+ - Vulnerabilities: {count}
485
+ [Specific CVEs if any...]
486
+
487
+ ## Universal Analysis
488
+
489
+ - TODO comments: {count}
490
+ - Large files: {count}
491
+ - Hardcoded secrets: {count}
492
+
493
+ ## Recommendations
494
+
495
+ [Prioritized list of actionable next steps]
496
+
497
+ ## Next Audit
498
+
499
+ Run `/trinity-audit` again after fixing issues.
500
+ Expected result: "0 new issues, 0 persistent issues, X fixed issues"
501
+
502
+ ---
503
+
504
+ **Audit Complete:** {timestamp}
505
+ **Confidence:** {HIGH|MEDIUM|LOW}
506
+ **Baseline Saved:** trinity/reports/AUDIT-BASELINE-{date}.json
507
+ ```
508
+
509
+ #### 2. Machine-Readable Baseline: `trinity/reports/AUDIT-BASELINE-{date}.json`
510
+
511
+ ```json
512
+ {
513
+ "audit_id": "2025-12-21-001",
514
+ "timestamp": "2025-12-21T12:00:00Z",
515
+ "project": {
516
+ "language": "JavaScript/TypeScript",
517
+ "framework": "Node.js",
518
+ "total_loc": 4632,
519
+ "files_analyzed": 49
520
+ },
521
+ "tools": {
522
+ "lint": {"run": true, "errors": 13, "warnings": 44},
523
+ "coverage": {"run": true, "percentage": 67},
524
+ "audit": {"run": true, "vulnerabilities": 0}
525
+ },
526
+ "findings": [
527
+ {
528
+ "id": "lint-001",
529
+ "file": "src/cli/commands/deploy/configuration.ts",
530
+ "line": 31,
531
+ "severity": "HIGH",
532
+ "category": "complexity",
533
+ "description": "Cyclomatic complexity 21 exceeds limit of 15",
534
+ "tool": "eslint"
535
+ }
536
+ // ... all findings
537
+ ],
538
+ "completeness": {
539
+ "file_coverage": "100%",
540
+ "tools_available": 3,
541
+ "tools_unavailable": 2,
542
+ "confidence": "HIGH"
543
+ }
544
+ }
545
+ ```
546
+
547
+ ---
548
+
549
+ ## Work Order Creation
550
+
551
+ **After audit completes**, create work order files for CRITICAL and HIGH issues.
552
+
553
+ **Naming:** `WO-AUDIT-{XXX}-{short-desc}-{date}.md`
554
+
555
+ **Create ONE work order per issue type:**
556
+ - WO-AUDIT-001-fix-cyclomatic-complexity-2025-12-21.md
557
+ - WO-AUDIT-002-increase-test-coverage-2025-12-21.md
558
+ - WO-AUDIT-003-remove-unused-code-2025-12-21.md
559
+
560
+ **Each work order includes:**
561
+ - Specific files/lines affected
562
+ - Objective acceptance criteria
563
+ - Estimated effort
564
+ - Testing requirements
565
+
566
+ ---
567
+
568
+ ## Example: Second Audit (Comparison Mode)
569
+
570
+ ```bash
571
+ User: /trinity-audit
572
+
573
+ JUNO: Loading previous audit baseline...
574
+
575
+ ✅ Baseline found: AUDIT-BASELINE-2025-12-20.json
576
+ 📊 Comparing current state against previous audit
577
+
578
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
579
+
580
+ **Audit Results:**
581
+
582
+ ✅ FIXED: 3 issues
583
+ - Cyclomatic complexity in configuration.ts (FIXED)
584
+ - Unused variables in deploy.ts (FIXED)
585
+ - Missing return type in metrics.ts (FIXED)
586
+
587
+ 🔴 PERSISTENT: 0 issues
588
+ (All previously identified issues have been resolved!)
589
+
590
+ ⚠️ NEW: 0 issues
591
+ (No new problems introduced since last audit!)
592
+
593
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
594
+
595
+ **Summary:**
596
+ ✨ Codebase quality improved since last audit!
597
+ ✨ All identified issues resolved
598
+ ✨ No regressions detected
599
+
600
+ **Recommendation:** You're done! The codebase is in excellent shape.
601
+
602
+ **Audit saved:** trinity/reports/CODEBASE-AUDIT-2025-12-21.md
603
+ **Baseline updated:** trinity/reports/AUDIT-BASELINE-2025-12-21.json
604
+ ```
605
+
606
+ **This is how the cycle ends.**
607
+
608
+ ---
609
+
610
+ ## Summary
611
+
612
+ ### Key Principles
613
+
614
+ 1. **Deterministic:** Same code = same findings (tool-based, not subjective)
615
+ 2. **Framework-Agnostic:** Works on any language
616
+ 3. **Baseline Tracking:** Second audit shows only changes
617
+ 4. **Completeness Guarantee:** Explicit metrics (100% coverage stated)
618
+ 5. **Objective Criteria:** Linting errors, not "feels complex"
619
+
620
+ ### Typical Workflow
621
+
622
+ ```bash
623
+ # First audit (creates baseline)
624
+ /trinity-audit
625
+ # → Finds 10 issues, creates baseline
626
+
627
+ # Fix all issues
628
+ /trinity-orchestrate @WO-AUDIT-001.md
629
+ /trinity-orchestrate @WO-AUDIT-002.md
630
+
631
+ # Second audit (comparison mode)
632
+ /trinity-audit
633
+ # → Result: "10 fixed, 0 persistent, 0 new" ✅ DONE
634
+ ```
635
+
636
+ ### When Are You Done?
637
+
638
+ You're done when the second audit shows:
639
+ - **0 persistent issues** (everything from first audit fixed)
640
+ - **0 new issues** (fixes didn't introduce problems)
641
+
642
+ **No infinite loop. Clear completion criteria.**
643
+
644
+ ---
645
+
646
+ **Next:** After audit, execute work orders with `/trinity-orchestrate @WO-AUDIT-XXX.md`