trinity-method-sdk 2.0.9 → 2.2.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 (147) hide show
  1. package/CHANGELOG.md +702 -267
  2. package/README.md +550 -540
  3. package/dist/cli/commands/deploy/agents.js +1 -1
  4. package/dist/cli/commands/deploy/ci-cd.d.ts +4 -3
  5. package/dist/cli/commands/deploy/ci-cd.js +10 -9
  6. package/dist/cli/commands/deploy/claude-setup.js +28 -35
  7. package/dist/cli/commands/deploy/configuration.js +10 -11
  8. package/dist/cli/commands/deploy/directories.js +13 -14
  9. package/dist/cli/commands/deploy/gitignore.js +3 -5
  10. package/dist/cli/commands/deploy/index.d.ts +1 -1
  11. package/dist/cli/commands/deploy/index.js +7 -3
  12. package/dist/cli/commands/deploy/knowledge-base.js +3 -3
  13. package/dist/cli/commands/deploy/pre-flight.js +1 -1
  14. package/dist/cli/commands/deploy/root-files.js +3 -18
  15. package/dist/cli/commands/deploy/sdk-install.js +1 -1
  16. package/dist/cli/commands/deploy/summary.js +3 -3
  17. package/dist/cli/commands/deploy/templates.js +33 -20
  18. package/dist/cli/commands/update/agents.js +1 -1
  19. package/dist/cli/commands/update/backup.js +6 -12
  20. package/dist/cli/commands/update/commands.d.ts +1 -0
  21. package/dist/cli/commands/update/commands.js +18 -45
  22. package/dist/cli/commands/update/knowledge-base.js +2 -2
  23. package/dist/cli/commands/update/pre-flight.js +11 -11
  24. package/dist/cli/commands/update/summary.js +5 -5
  25. package/dist/cli/commands/update/templates.js +35 -13
  26. package/dist/cli/commands/update/verification.js +5 -5
  27. package/dist/cli/commands/update/version.js +1 -1
  28. package/dist/cli/utils/deploy-ci.d.ts +3 -2
  29. package/dist/cli/utils/deploy-ci.js +24 -24
  30. package/dist/cli/utils/deploy-linting.js +101 -6
  31. package/dist/cli/utils/error-classes.d.ts +2 -2
  32. package/dist/cli/utils/linting-tools.js +14 -6
  33. package/dist/cli/utils/template-processor.js +2 -4
  34. package/dist/templates/{claude → .claude}/EMPLOYEE-DIRECTORY.md.template +16 -22
  35. package/dist/templates/{agents → .claude/agents}/aj-team/apo-documentation-specialist.md.template +10 -10
  36. package/dist/templates/{agents → .claude/agents}/aj-team/bas-quality-gate.md.template +13 -15
  37. package/dist/templates/{agents → .claude/agents}/aj-team/bon-dependency-manager.md.template +4 -4
  38. package/dist/templates/{agents → .claude/agents}/aj-team/cap-configuration-specialist.md.template +3 -3
  39. package/dist/templates/{agents → .claude/agents}/aj-team/dra-code-reviewer.md.template +8 -10
  40. package/dist/templates/{agents → .claude/agents}/aj-team/kil-task-executor.md.template +11 -13
  41. package/dist/templates/{agents → .claude/agents}/aj-team/uro-refactoring-specialist.md.template +3 -3
  42. package/dist/templates/{agents → .claude/agents}/audit/juno-auditor.md.template +46 -42
  43. package/dist/templates/{agents → .claude/agents}/deployment/ein-cicd.md.template +59 -164
  44. package/dist/templates/{agents → .claude/agents}/deployment/ino-context.md.template +25 -22
  45. package/dist/templates/{agents → .claude/agents}/deployment/tan-structure.md.template +32 -30
  46. package/dist/templates/{agents → .claude/agents}/deployment/zen-knowledge.md.template +28 -23
  47. package/dist/templates/{agents → .claude/agents}/leadership/aj-maestro.md.template +10 -6
  48. package/dist/templates/{agents → .claude/agents}/leadership/aly-cto.md.template +22 -19
  49. package/dist/templates/{agents → .claude/agents}/planning/eus-decomposer.md.template +8 -4
  50. package/dist/templates/{agents → .claude/agents}/planning/mon-requirements.md.template +8 -4
  51. package/dist/templates/{agents → .claude/agents}/planning/ror-design.md.template +8 -4
  52. package/dist/templates/{agents → .claude/agents}/planning/tra-planner.md.template +10 -4
  53. package/dist/templates/{shared/claude-commands → .claude/commands/execution}/trinity-audit.md.template +15 -15
  54. package/dist/templates/.claude/commands/execution/trinity-breakdown.md.template +535 -0
  55. package/dist/templates/{shared/claude-commands → .claude/commands/execution}/trinity-orchestrate.md.template +48 -48
  56. package/dist/templates/{shared/claude-commands → .claude/commands/infrastructure}/trinity-init.md.template +32 -54
  57. package/dist/templates/{shared/claude-commands → .claude/commands/investigation}/trinity-create-investigation.md.template +13 -7
  58. package/dist/templates/{shared/claude-commands → .claude/commands/investigation}/trinity-investigate-templates.md.template +19 -15
  59. package/dist/templates/{shared/claude-commands → .claude/commands/investigation}/trinity-plan-investigation.md.template +12 -6
  60. package/dist/templates/{shared/claude-commands → .claude/commands/maintenance}/trinity-changelog.md.template +9 -8
  61. package/dist/templates/.claude/commands/maintenance/trinity-docs-update.md.template +279 -0
  62. package/dist/templates/.claude/commands/maintenance/trinity-docs.md.template +2828 -0
  63. package/dist/templates/{shared/claude-commands → .claude/commands/maintenance}/trinity-readme.md.template +21 -20
  64. package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-decompose.md.template +6 -4
  65. package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-design.md.template +6 -4
  66. package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-plan.md.template +7 -5
  67. package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-requirements.md.template +6 -4
  68. package/dist/templates/{shared/claude-commands → .claude/commands/session}/trinity-continue.md.template +30 -24
  69. package/dist/templates/{shared/claude-commands → .claude/commands/session}/trinity-end.md.template +403 -397
  70. package/dist/templates/{shared/claude-commands → .claude/commands/session}/trinity-start.md.template +9 -4
  71. package/dist/templates/{shared/claude-commands → .claude/commands/utility}/trinity-agents.md.template +11 -8
  72. package/dist/templates/{shared/claude-commands → .claude/commands/utility}/trinity-verify.md.template +56 -57
  73. package/dist/templates/{shared/claude-commands → .claude/commands/utility}/trinity-workorder.md.template +13 -9
  74. package/dist/templates/ci/ci.yml.template +2 -2
  75. package/dist/templates/root/CLAUDE.md.template +9 -9
  76. package/dist/templates/root/linting/nodejs/.husky-pre-commit.template +5 -0
  77. package/dist/templates/source/base-CLAUDE.md.template +310 -310
  78. package/dist/templates/source/flutter-CLAUDE.md.template +593 -593
  79. package/dist/templates/source/nodejs-CLAUDE.md.template +531 -531
  80. package/dist/templates/source/python-CLAUDE.md.template +510 -510
  81. package/dist/templates/source/react-CLAUDE.md.template +513 -513
  82. package/dist/templates/source/rust-CLAUDE.md.template +653 -653
  83. package/dist/templates/trinity/CLAUDE.md.template +14 -14
  84. package/dist/templates/{knowledge-base → trinity/knowledge-base}/AI-DEVELOPMENT-GUIDE.md.template +1 -1
  85. package/dist/templates/{knowledge-base → trinity/knowledge-base}/ARCHITECTURE.md.template +5 -5
  86. package/dist/templates/{knowledge-base → trinity/knowledge-base}/CODING-PRINCIPLES.md.template +1 -1
  87. package/dist/templates/{knowledge-base → trinity/knowledge-base}/DOCUMENTATION-CRITERIA.md.template +1 -1
  88. package/dist/templates/{knowledge-base → trinity/knowledge-base}/ISSUES.md.template +9 -9
  89. package/dist/templates/{knowledge-base → trinity/knowledge-base}/TESTING-PRINCIPLES.md.template +1 -1
  90. package/dist/templates/{knowledge-base → trinity/knowledge-base}/Technical-Debt.md.template +2 -4
  91. package/dist/templates/{knowledge-base → trinity/knowledge-base}/To-do.md.template +2 -2
  92. package/dist/templates/{knowledge-base → trinity/knowledge-base}/Trinity.md.template +6 -6
  93. package/dist/templates/trinity/templates/documentation/api-docs/README.md.template +218 -0
  94. package/dist/templates/trinity/templates/documentation/configuration/documentation-structure.md.template +71 -0
  95. package/dist/templates/trinity/templates/documentation/configuration/env-example-generator.md.template +387 -0
  96. package/dist/templates/trinity/templates/documentation/discovery/api-endpoint-scanner.md.template +343 -0
  97. package/dist/templates/trinity/templates/documentation/discovery/component-discovery.md.template +254 -0
  98. package/dist/templates/trinity/templates/documentation/discovery/env-variable-extraction.md.template +316 -0
  99. package/dist/templates/trinity/templates/documentation/discovery/framework-detection.md.template +205 -0
  100. package/dist/templates/trinity/templates/documentation/guides/api-development.md.template +375 -0
  101. package/dist/templates/trinity/templates/documentation/guides/contributing.md.template +488 -0
  102. package/dist/templates/trinity/templates/documentation/guides/deployment.md.template +565 -0
  103. package/dist/templates/trinity/templates/documentation/guides/getting-started.md.template +118 -0
  104. package/dist/templates/trinity/templates/documentation/mermaid-diagrams/api-endpoint-map.md.template +56 -0
  105. package/dist/templates/trinity/templates/documentation/mermaid-diagrams/component-hierarchy.md.template +60 -0
  106. package/dist/templates/trinity/templates/documentation/mermaid-diagrams/database-er.md.template +49 -0
  107. package/dist/templates/trinity/templates/documentation/mermaid-diagrams/mvc-flow.md.template +41 -0
  108. package/dist/templates/trinity/templates/documentation/processes/error-handling-protocol.md.template +166 -0
  109. package/dist/templates/trinity/templates/documentation/processes/fallback-mechanism.md.template +88 -0
  110. package/dist/templates/trinity/templates/documentation/reports/apo-docs-update-checklist.md.template +343 -0
  111. package/dist/templates/trinity/templates/documentation/reports/juno-docs-update-checklist.md.template +1337 -0
  112. package/dist/templates/trinity/templates/documentation/reports/juno-final-report.md.template +237 -0
  113. package/dist/templates/trinity/templates/documentation/reports/juno-internal-report.md.template +461 -0
  114. package/dist/templates/trinity/templates/documentation/validation/documentation-verification-rules.md.template +379 -0
  115. package/dist/templates/trinity/templates/documentation/validation/juno-quality-gates.md.template +282 -0
  116. package/dist/templates/{investigations → trinity/templates/investigations}/bug.md.template +14 -14
  117. package/dist/templates/{investigations → trinity/templates/investigations}/feature.md.template +14 -14
  118. package/dist/templates/{investigations → trinity/templates/investigations}/performance.md.template +14 -14
  119. package/dist/templates/{investigations → trinity/templates/investigations}/security.md.template +14 -14
  120. package/dist/templates/{investigations → trinity/templates/investigations}/technical.md.template +14 -14
  121. package/dist/templates/{work-orders → trinity/templates/work-orders}/ANALYSIS-TEMPLATE.md.template +10 -13
  122. package/dist/templates/{work-orders → trinity/templates/work-orders}/AUDIT-TEMPLATE.md.template +10 -26
  123. package/dist/templates/{work-orders → trinity/templates/work-orders}/IMPLEMENTATION-TEMPLATE.md.template +10 -26
  124. package/dist/templates/{work-orders → trinity/templates/work-orders}/INVESTIGATION-TEMPLATE.md.template +10 -25
  125. package/dist/templates/{work-orders → trinity/templates/work-orders}/PATTERN-TEMPLATE.md.template +10 -26
  126. package/dist/templates/{work-orders → trinity/templates/work-orders}/VERIFICATION-TEMPLATE.md.template +10 -26
  127. package/package.json +99 -94
  128. package/dist/templates/agents/leadership/aj-cc.md.template +0 -462
  129. package/dist/templates/ci/cd.yml.template +0 -175
  130. package/dist/templates/ci/github-actions.yml +0 -86
  131. package/dist/templates/root/TRINITY.md.template +0 -52
  132. package/dist/templates/shared/claude-commands/trinity-docs.md.template +0 -2577
  133. /package/dist/templates/{linting → root/linting}/flutter/.pre-commit-config.yaml.template +0 -0
  134. /package/dist/templates/{linting → root/linting}/flutter/analysis_options.yaml.template +0 -0
  135. /package/dist/templates/{linting → root/linting}/nodejs/.eslintrc-commonjs.json.template +0 -0
  136. /package/dist/templates/{linting → root/linting}/nodejs/.eslintrc-esm.json.template +0 -0
  137. /package/dist/templates/{linting → root/linting}/nodejs/.eslintrc-typescript.json.template +0 -0
  138. /package/dist/templates/{linting → root/linting}/nodejs/.pre-commit-config.yaml.template +0 -0
  139. /package/dist/templates/{linting → root/linting}/nodejs/.prettierrc.json.template +0 -0
  140. /package/dist/templates/{linting → root/linting}/python/.flake8.template +0 -0
  141. /package/dist/templates/{linting → root/linting}/python/.pre-commit-config.yaml.template +0 -0
  142. /package/dist/templates/{linting → root/linting}/python/pyproject.toml.template +0 -0
  143. /package/dist/templates/{linting → root/linting}/rust/.pre-commit-config.yaml.template +0 -0
  144. /package/dist/templates/{linting → root/linting}/rust/clippy.toml.template +0 -0
  145. /package/dist/templates/{linting → root/linting}/rust/rustfmt.toml.template +0 -0
  146. /package/dist/templates/{documentation → trinity/templates/documentation}/ROOT-README.md.template +0 -0
  147. /package/dist/templates/{documentation → trinity/templates/documentation}/SUBDIRECTORY-README.md.template +0 -0
@@ -0,0 +1,254 @@
1
+ # Component Discovery Patterns
2
+ **Category:** Discovery
3
+ **Purpose:** Discover React, Vue, Angular, and Svelte components with glob patterns
4
+ **Used By:** JUNO (Phase 1), APO-1 (Diagrams), APO-2 (Guides)
5
+
6
+ ---
7
+
8
+ ## Overview
9
+
10
+ This template provides glob patterns and filtering logic to discover UI components across different frontend frameworks.
11
+
12
+ ---
13
+
14
+ ## Critical Rule: Zero Tolerance for Fake Components
15
+
16
+ **RULE:** Every component name MUST exist in the codebase (verified with Glob).
17
+ - No placeholder component names
18
+ - No example/demo component names unless they actually exist
19
+ - All components must be verifiable via file path
20
+
21
+ ---
22
+
23
+ ## Component Discovery Patterns
24
+
25
+ ### React Components (.tsx, .jsx)
26
+
27
+ ```javascript
28
+ const react_patterns = [
29
+ "client/**/*.{tsx,jsx}",
30
+ "src/**/*.{tsx,jsx}",
31
+ "components/**/*.{tsx,jsx}",
32
+ "app/**/*.{tsx,jsx}",
33
+ "pages/**/*.{tsx,jsx}"
34
+ ];
35
+ ```
36
+
37
+ ### Vue Components (.vue)
38
+
39
+ ```javascript
40
+ const vue_patterns = [
41
+ "src/**/*.vue",
42
+ "components/**/*.vue",
43
+ "views/**/*.vue",
44
+ "pages/**/*.vue"
45
+ ];
46
+ ```
47
+
48
+ ### Angular Components (.ts with @Component)
49
+
50
+ ```javascript
51
+ const angular_patterns = [
52
+ "src/**/*.component.ts",
53
+ "app/**/*.component.ts"
54
+ ];
55
+ ```
56
+
57
+ ### Svelte Components (.svelte)
58
+
59
+ ```javascript
60
+ const svelte_patterns = [
61
+ "src/**/*.svelte",
62
+ "components/**/*.svelte",
63
+ "routes/**/*.svelte"
64
+ ];
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Filtering Logic
70
+
71
+ ### Exclusion Patterns
72
+
73
+ **Always exclude:**
74
+ - Test files: `*.test.{tsx,jsx,ts,vue,svelte}`, `*.spec.{tsx,jsx,ts,vue,svelte}`
75
+ - Config files: `*.config.{ts,js}`
76
+ - Entry points: `main.{ts,tsx,js,jsx}`, `index.{ts,tsx,js,jsx}` (unless clearly a component)
77
+ - Build artifacts: `dist/`, `build/`, `.next/`, `node_modules/`
78
+
79
+ **Example filter:**
80
+ ```javascript
81
+ const actual_components = all_component_files.filter(f =>
82
+ !f.includes('.test.') &&
83
+ !f.includes('.spec.') &&
84
+ !f.includes('.config.') &&
85
+ !f.includes('node_modules') &&
86
+ !f.includes('dist/') &&
87
+ !f.includes('build/')
88
+ );
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Component Name Extraction
94
+
95
+ ### From File Path
96
+
97
+ ```javascript
98
+ // Input: "src/components/UserProfile.tsx"
99
+ // Output: "UserProfile"
100
+
101
+ const extractComponentName = (filepath) => {
102
+ const filename = filepath.split('/').pop(); // "UserProfile.tsx"
103
+ return filename.split('.')[0]; // "UserProfile"
104
+ };
105
+ ```
106
+
107
+ ### Handling Index Files
108
+
109
+ ```javascript
110
+ // Input: "src/components/UserProfile/index.tsx"
111
+ // Output: "UserProfile" (use parent directory name)
112
+
113
+ if (filename === 'index.tsx' || filename === 'index.jsx') {
114
+ const parts = filepath.split('/');
115
+ return parts[parts.length - 2]; // Parent directory name
116
+ }
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Component Categorization
122
+
123
+ ### By Type (React Example)
124
+
125
+ ```javascript
126
+ // Detect component type from imports or patterns
127
+ if (content.includes('useState') || content.includes('useEffect')) {
128
+ type = 'Functional Component (Hooks)';
129
+ } else if (content.includes('class') && content.includes('extends React.Component')) {
130
+ type = 'Class Component';
131
+ }
132
+ ```
133
+
134
+ ### By Location
135
+
136
+ ```javascript
137
+ // Group by directory structure
138
+ if (filepath.includes('pages/')) category = 'Page Component';
139
+ else if (filepath.includes('components/')) category = 'Reusable Component';
140
+ else if (filepath.includes('layouts/')) category = 'Layout Component';
141
+ ```
142
+
143
+ ---
144
+
145
+ ## Template Variable Mapping
146
+
147
+ **Variables to populate:**
148
+ - `{{COMPONENT_COUNT}}` → Total number of components found
149
+ - `{{COMPONENT_LIST}}` → Comma-separated list of component names
150
+ - `{{COMPONENT_PATHS}}` → Full paths for verification (APO-1 uses this)
151
+ - `{{COMPONENT_FRAMEWORK}}` → React/Vue/Angular/Svelte
152
+
153
+ ---
154
+
155
+ ## Verification Requirements
156
+
157
+ ### For APO-1 (Diagrams)
158
+
159
+ **Must provide:**
160
+ 1. Component name
161
+ 2. Full file path (for Glob verification)
162
+ 3. Component type (if detectable)
163
+
164
+ **Example output for JUNO report:**
165
+ ```
166
+ Components (15 total):
167
+ - UserProfile (src/components/UserProfile.tsx)
168
+ - LoginForm (src/components/auth/LoginForm.tsx)
169
+ - Dashboard (src/pages/Dashboard.tsx)
170
+ ...
171
+ ```
172
+
173
+ ### For APO-2 (Guides)
174
+
175
+ **Must provide:**
176
+ 1. Component count
177
+ 2. Example component names (2-3 most important)
178
+ 3. Component directory structure
179
+
180
+ ---
181
+
182
+ ## Fallback Detection
183
+
184
+ If no components found with primary patterns:
185
+
186
+ 1. **Broaden search:** Try `**/*.{tsx,jsx,vue,svelte}` (all directories)
187
+ 2. **Check alternative locations:** `lib/`, `views/`, `containers/`
188
+ 3. **Search for JSX/TSX syntax:** Grep for `return (<` or `<div>` in TypeScript/JavaScript files
189
+ 4. **Log warning:** "⚠️ No components found with standard patterns - using broad search"
190
+
191
+ ---
192
+
193
+ ## Examples
194
+
195
+ ### Example 1: React App
196
+
197
+ ```javascript
198
+ // Glob patterns:
199
+ ["src/**/*.{tsx,jsx}"]
200
+
201
+ // Found files:
202
+ [
203
+ "src/components/UserProfile.tsx",
204
+ "src/components/LoginForm.tsx",
205
+ "src/components/UserProfile.test.tsx", // EXCLUDE (test file)
206
+ "src/pages/Dashboard.tsx",
207
+ "src/App.tsx"
208
+ ]
209
+
210
+ // Filtered components:
211
+ [
212
+ "UserProfile (src/components/UserProfile.tsx)",
213
+ "LoginForm (src/components/LoginForm.tsx)",
214
+ "Dashboard (src/pages/Dashboard.tsx)",
215
+ "App (src/App.tsx)"
216
+ ]
217
+
218
+ // Template variables:
219
+ COMPONENT_COUNT = 4
220
+ COMPONENT_LIST = "UserProfile, LoginForm, Dashboard, App"
221
+ ```
222
+
223
+ ### Example 2: Vue App
224
+
225
+ ```javascript
226
+ // Glob patterns:
227
+ ["src/**/*.vue"]
228
+
229
+ // Found files:
230
+ [
231
+ "src/components/HelloWorld.vue",
232
+ "src/views/Home.vue",
233
+ "src/views/About.vue"
234
+ ]
235
+
236
+ // Template variables:
237
+ COMPONENT_COUNT = 3
238
+ COMPONENT_FRAMEWORK = "Vue.js"
239
+ ```
240
+
241
+ ---
242
+
243
+ ## Error Handling
244
+
245
+ **No components found:**
246
+ - Log: "⚠️ WARNING: No components discovered - may be backend-only project"
247
+ - Set `COMPONENT_COUNT = 0`
248
+ - Continue processing (not a critical error)
249
+
250
+ **Too many components (>100):**
251
+ - Log: "ℹ️ Large component count detected: [count] - listing top 20 in report"
252
+ - Provide full list to APO-1 but summarize in JUNO report
253
+
254
+ ---
@@ -0,0 +1,316 @@
1
+ # Environment Variable Extraction Patterns
2
+ **Category:** Discovery
3
+ **Purpose:** Extract environment variables from .env files and process.env usage
4
+ **Used By:** JUNO (Phase 1), APO-3 (Config Files)
5
+
6
+ ---
7
+
8
+ ## Overview
9
+
10
+ This template provides patterns for discovering environment variables used in a codebase through .env file analysis and process.env usage scanning.
11
+
12
+ ---
13
+
14
+ ## Environment Variable Sources
15
+
16
+ ### 1. .env Files
17
+
18
+ **Common .env file locations:**
19
+ ```javascript
20
+ const env_files = [
21
+ ".env",
22
+ ".env.example",
23
+ ".env.template",
24
+ ".env.local",
25
+ ".env.development",
26
+ ".env.production",
27
+ ".env.test"
28
+ ];
29
+ ```
30
+
31
+ **Priority order:**
32
+ 1. `.env.example` or `.env.template` (recommended source - no secrets)
33
+ 2. `.env` (actual config - may contain secrets, use carefully)
34
+ 3. `.env.development`, `.env.production` (environment-specific)
35
+
36
+ ---
37
+
38
+ ### 2. Code Usage (process.env)
39
+
40
+ **Grep pattern for environment variable usage:**
41
+ ```javascript
42
+ // Search for: process.env.VARIABLE_NAME
43
+ const env_usage_pattern = /process\.env\.([A-Z_][A-Z0-9_]*)/g;
44
+ ```
45
+
46
+ **Example extraction:**
47
+ ```javascript
48
+ // From code:
49
+ const dbUrl = process.env.DATABASE_URL;
50
+ const port = process.env.PORT || 3000;
51
+
52
+ // Extract:
53
+ ["DATABASE_URL", "PORT"]
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Extraction Logic
59
+
60
+ ### Step 1: Read .env.example (Preferred)
61
+
62
+ ```javascript
63
+ // Priority: Use .env.example to avoid exposing secrets
64
+ const env_content = Read(".env.example");
65
+
66
+ // Parse format: KEY=value
67
+ const lines = env_content.split('\n');
68
+ const variables = lines
69
+ .filter(line => line && !line.startsWith('#')) // Skip comments
70
+ .map(line => line.split('=')[0].trim());
71
+ ```
72
+
73
+ ### Step 2: Fallback to Code Scanning
74
+
75
+ ```javascript
76
+ // If .env.example doesn't exist, grep codebase
77
+ const env_usage = Grep({
78
+ pattern: "process\\.env\\.",
79
+ output_mode: "content"
80
+ });
81
+
82
+ // Extract variable names from matches
83
+ const variable_names = [...new Set(
84
+ env_usage.match(/process\.env\.([A-Z_][A-Z0-9_]*)/g)
85
+ .map(match => match.replace('process.env.', ''))
86
+ )];
87
+ ```
88
+
89
+ ### Step 3: Combine and Deduplicate
90
+
91
+ ```javascript
92
+ // Merge variables from both sources
93
+ const all_variables = [...new Set([
94
+ ...env_file_variables,
95
+ ...code_usage_variables
96
+ ])];
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Variable Categorization
102
+
103
+ ### By Purpose (Common Conventions)
104
+
105
+ ```javascript
106
+ const categories = {
107
+ database: ['DATABASE_URL', 'DB_HOST', 'DB_PORT', 'DB_NAME', 'DB_USER', 'DB_PASSWORD'],
108
+ api_keys: ['API_KEY', 'SECRET_KEY', 'JWT_SECRET', 'STRIPE_KEY'],
109
+ server: ['PORT', 'HOST', 'NODE_ENV'],
110
+ external_services: ['SMTP_HOST', 'REDIS_URL', 'S3_BUCKET'],
111
+ features: ['ENABLE_ANALYTICS', 'DEBUG_MODE']
112
+ };
113
+ ```
114
+
115
+ **Auto-categorization by prefix:**
116
+ ```javascript
117
+ if (var_name.startsWith('DB_')) category = 'database';
118
+ else if (var_name.includes('API_KEY')) category = 'api_keys';
119
+ else if (var_name.includes('SECRET')) category = 'api_keys';
120
+ else if (var_name === 'PORT' || var_name === 'HOST') category = 'server';
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Template Variable Mapping
126
+
127
+ **Variables to populate:**
128
+ - `{{ENV_VAR_COUNT}}` → Total number of environment variables
129
+ - `{{ENV_VAR_LIST}}` → List of variable names
130
+ - `{{ENV_VAR_CATEGORIES}}` → Categorized variable groups
131
+ - `{{HAS_ENV_FILE}}` → Boolean (true if .env.example exists)
132
+
133
+ ---
134
+
135
+ ## .env.example Generation (APO-3)
136
+
137
+ ### Format for .env.example
138
+
139
+ ```bash
140
+ # Database Configuration
141
+ DATABASE_URL=postgresql://user:password@localhost:5432/dbname
142
+ DB_HOST=localhost
143
+ DB_PORT=5432
144
+
145
+ # Server Configuration
146
+ PORT=3000
147
+ NODE_ENV=development
148
+
149
+ # API Keys (DO NOT commit actual keys)
150
+ API_KEY=your_api_key_here
151
+ JWT_SECRET=your_jwt_secret_here
152
+
153
+ # External Services
154
+ REDIS_URL=redis://localhost:6379
155
+ SMTP_HOST=smtp.example.com
156
+ ```
157
+
158
+ ### Value Placeholders
159
+
160
+ **For sensitive values:**
161
+ ```bash
162
+ JWT_SECRET=your_secret_here_change_in_production
163
+ API_KEY=get_from_service_provider
164
+ STRIPE_SECRET_KEY=sk_test_...
165
+ ```
166
+
167
+ **For standard values:**
168
+ ```bash
169
+ PORT=3000
170
+ NODE_ENV=development
171
+ LOG_LEVEL=info
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Verification Requirements
177
+
178
+ ### For JUNO Report
179
+
180
+ **Must provide:**
181
+ 1. Environment variable count
182
+ 2. List of all variable names (without values)
183
+ 3. Source (from .env.example vs code scanning)
184
+
185
+ **Example output:**
186
+ ```
187
+ Environment Variables (12 total):
188
+
189
+ Database:
190
+ - DATABASE_URL
191
+ - DB_HOST
192
+ - DB_PORT
193
+
194
+ Server:
195
+ - PORT
196
+ - NODE_ENV
197
+ - HOST
198
+
199
+ API Keys:
200
+ - JWT_SECRET
201
+ - API_KEY
202
+ ```
203
+
204
+ ### For APO-3 (.env.example Generation)
205
+
206
+ **Must provide:**
207
+ 1. All variable names discovered
208
+ 2. Categorized grouping (with comments)
209
+ 3. Appropriate placeholder values
210
+ 4. Documentation comments for each category
211
+
212
+ ---
213
+
214
+ ## Security Considerations
215
+
216
+ ### NEVER Include in Reports
217
+
218
+ **DO NOT extract or display:**
219
+ - Actual secret values from .env
220
+ - API keys
221
+ - Passwords
222
+ - JWT secrets
223
+ - Database credentials
224
+
225
+ **ONLY extract:**
226
+ - Variable names (keys)
227
+ - Variable structure
228
+ - Expected format (from .env.example)
229
+
230
+ ### Safe Sources
231
+
232
+ **Preferred (Safe):**
233
+ - `.env.example` (no secrets, safe to read)
234
+ - `.env.template` (no secrets, safe to read)
235
+ - Code scanning for `process.env.VAR_NAME` (no values, just keys)
236
+
237
+ **Avoid (May contain secrets):**
238
+ - `.env` (may contain real secrets)
239
+ - `.env.local` (may contain real secrets)
240
+ - `.env.production` (likely contains real secrets)
241
+
242
+ ---
243
+
244
+ ## Fallback Detection
245
+
246
+ If no .env file found and no process.env usage detected:
247
+
248
+ 1. **Check package.json scripts:**
249
+ - Look for environment variables in npm scripts: `"start": "PORT=3000 node server.js"`
250
+ 2. **Check common config files:**
251
+ - `config/default.js`, `config/development.js`
252
+ - May reference environment variables
253
+ 3. **Log warning:** "ℹ️ No environment variables detected - project may use hardcoded config"
254
+
255
+ ---
256
+
257
+ ## Examples
258
+
259
+ ### Example 1: Express + PostgreSQL App
260
+
261
+ ```bash
262
+ # .env.example content:
263
+ DATABASE_URL=postgresql://localhost:5432/myapp
264
+ PORT=3000
265
+ NODE_ENV=development
266
+ JWT_SECRET=change_me_in_production
267
+
268
+ # Extracted variables:
269
+ ENV_VAR_COUNT = 4
270
+ ENV_VAR_LIST = ["DATABASE_URL", "PORT", "NODE_ENV", "JWT_SECRET"]
271
+ HAS_ENV_FILE = true
272
+ ```
273
+
274
+ ### Example 2: Code Scanning Fallback
275
+
276
+ ```javascript
277
+ // No .env.example, but code contains:
278
+ const dbUrl = process.env.DATABASE_URL;
279
+ const apiKey = process.env.API_KEY;
280
+ const port = process.env.PORT || 3000;
281
+
282
+ // Extracted from code:
283
+ ENV_VAR_COUNT = 3
284
+ ENV_VAR_LIST = ["DATABASE_URL", "API_KEY", "PORT"]
285
+ HAS_ENV_FILE = false
286
+ ENV_VAR_SOURCE = "code_scanning"
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Error Handling
292
+
293
+ **No .env file and no process.env usage:**
294
+ - Log: "ℹ️ No environment variables detected - may use hardcoded configuration"
295
+ - Set `ENV_VAR_COUNT = 0`
296
+ - Continue processing (not critical)
297
+
298
+ **.env file malformed:**
299
+ - Log: "⚠️ .env file exists but could not be parsed - using code scanning fallback"
300
+ - Fall back to code scanning method
301
+
302
+ **Too many variables (>30):**
303
+ - Log: "ℹ️ Large number of environment variables detected: [count]"
304
+ - Provide categorized summary in report
305
+
306
+ ---
307
+
308
+ ## Best Practices
309
+
310
+ 1. **Always prefer .env.example over .env** - Avoid exposing secrets
311
+ 2. **Validate variable names** - Should follow UPPER_SNAKE_CASE convention
312
+ 3. **Group by purpose** - Makes .env.example more maintainable
313
+ 4. **Document each variable** - Add comments explaining purpose
314
+ 5. **Provide safe placeholder values** - Help developers understand expected format
315
+
316
+ ---