@vee-stack/delta-cli 2.0.4 → 2.0.6

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 (135) hide show
  1. package/dist/analyzer/commands/analyze.js +260 -0
  2. package/dist/analyzer/commands/config.js +83 -0
  3. package/dist/analyzer/commands/report.js +38 -0
  4. package/dist/analyzer/generators/report.generator.js +123 -0
  5. package/dist/analyzer/index.js +44 -0
  6. package/dist/analyzer/scanners/project.scanner.js +92 -0
  7. package/dist/analyzer/validators/contracts.validator.js +42 -0
  8. package/dist/analyzer/validators/maintainability.validator.js +40 -0
  9. package/dist/analyzer/validators/observability.validator.js +39 -0
  10. package/dist/analyzer/validators/performance.validator.js +42 -0
  11. package/dist/analyzer/validators/security.validator.js +66 -0
  12. package/dist/analyzer/validators/soc.validator.js +75 -0
  13. package/dist/apps/cli/src/analyzer/commands/analyze.js +256 -0
  14. package/dist/apps/cli/src/analyzer/commands/config.js +83 -0
  15. package/dist/apps/cli/src/analyzer/commands/report.js +38 -0
  16. package/dist/apps/cli/src/analyzer/generators/report.generator.js +123 -0
  17. package/dist/apps/cli/src/analyzer/index.js +44 -0
  18. package/dist/apps/cli/src/analyzer/scanners/project.scanner.js +92 -0
  19. package/dist/apps/cli/src/analyzer/validators/contracts.validator.js +42 -0
  20. package/dist/apps/cli/src/analyzer/validators/maintainability.validator.js +40 -0
  21. package/dist/apps/cli/src/analyzer/validators/observability.validator.js +39 -0
  22. package/dist/apps/cli/src/analyzer/validators/performance.validator.js +42 -0
  23. package/dist/apps/cli/src/analyzer/validators/security.validator.js +66 -0
  24. package/dist/apps/cli/src/analyzer/validators/soc.validator.js +75 -0
  25. package/dist/apps/cli/src/auth/secure-auth.js +312 -0
  26. package/dist/apps/cli/src/commands/analyze.js +286 -0
  27. package/dist/apps/cli/src/commands/auth-new.js +37 -0
  28. package/dist/apps/cli/src/commands/auth.js +122 -0
  29. package/dist/apps/cli/src/commands/config.js +49 -0
  30. package/dist/apps/cli/src/commands/deploy.js +6 -0
  31. package/dist/apps/cli/src/commands/init.js +47 -0
  32. package/dist/apps/cli/src/commands/logout.js +23 -0
  33. package/dist/apps/cli/src/commands/plugins.js +21 -0
  34. package/dist/apps/cli/src/commands/status.js +80 -0
  35. package/dist/apps/cli/src/commands/sync.js +6 -0
  36. package/dist/apps/cli/src/commands/whoami.js +115 -0
  37. package/dist/apps/cli/src/components/Dashboard.js +168 -0
  38. package/dist/apps/cli/src/components/DeltaApp.js +56 -0
  39. package/dist/apps/cli/src/components/UnifiedManager.js +324 -0
  40. package/dist/apps/cli/src/core/audit.js +184 -0
  41. package/dist/apps/cli/src/core/completion.js +294 -0
  42. package/dist/apps/cli/src/core/contracts.js +6 -0
  43. package/dist/apps/cli/src/core/engine.js +124 -0
  44. package/dist/apps/cli/src/core/exit-codes.js +71 -0
  45. package/dist/apps/cli/src/core/hooks.js +181 -0
  46. package/dist/apps/cli/src/core/index.js +7 -0
  47. package/dist/apps/cli/src/core/policy.js +115 -0
  48. package/dist/apps/cli/src/core/profiles.js +161 -0
  49. package/dist/apps/cli/src/core/wizard.js +203 -0
  50. package/dist/apps/cli/src/index.js +636 -0
  51. package/dist/apps/cli/src/interactive/index.js +11 -0
  52. package/dist/apps/cli/src/plugins/GitStatusPlugin.js +99 -0
  53. package/dist/apps/cli/src/providers/ai-provider.js +74 -0
  54. package/dist/apps/cli/src/providers/local-provider.js +302 -0
  55. package/dist/apps/cli/src/providers/remote-provider.js +100 -0
  56. package/dist/apps/cli/src/types/api.js +3 -0
  57. package/dist/apps/cli/src/ui.js +219 -0
  58. package/dist/apps/cli/src/welcome.js +81 -0
  59. package/dist/auth/secure-auth.js +418 -0
  60. package/dist/bundle.js +45 -45
  61. package/dist/commands/analyze.js +384 -0
  62. package/dist/commands/auth-new.js +37 -0
  63. package/dist/commands/auth.js +134 -0
  64. package/dist/commands/config.js +51 -0
  65. package/dist/commands/deploy.js +6 -0
  66. package/dist/commands/init.js +47 -0
  67. package/dist/commands/logout.js +31 -0
  68. package/dist/commands/plugins.js +21 -0
  69. package/dist/commands/status.js +82 -0
  70. package/dist/commands/sync.js +6 -0
  71. package/dist/commands/whoami.js +72 -0
  72. package/dist/components/Dashboard.js +169 -0
  73. package/dist/components/DeltaApp.js +57 -0
  74. package/dist/components/UnifiedManager.js +344 -0
  75. package/dist/core/audit.js +184 -0
  76. package/dist/core/completion.js +294 -0
  77. package/dist/core/contracts.js +6 -0
  78. package/dist/core/engine.js +124 -0
  79. package/dist/core/exit-codes.js +71 -0
  80. package/dist/core/hooks.js +181 -0
  81. package/dist/core/index.js +7 -0
  82. package/dist/core/policy.js +115 -0
  83. package/dist/core/profiles.js +161 -0
  84. package/dist/core/wizard.js +203 -0
  85. package/dist/index.js +387 -0
  86. package/dist/interactive/index.js +11 -0
  87. package/dist/packages/domain/src/constitution/contracts/index.js +43 -0
  88. package/dist/packages/domain/src/constitution/contracts/ts.rules.js +268 -0
  89. package/dist/packages/domain/src/constitution/index.js +139 -0
  90. package/dist/packages/domain/src/constitution/maintainability/index.js +43 -0
  91. package/dist/packages/domain/src/constitution/maintainability/ts.rules.js +344 -0
  92. package/dist/packages/domain/src/constitution/observability/index.js +43 -0
  93. package/dist/packages/domain/src/constitution/observability/ts.rules.js +307 -0
  94. package/dist/packages/domain/src/constitution/performance/index.js +43 -0
  95. package/dist/packages/domain/src/constitution/performance/ts.rules.js +325 -0
  96. package/dist/packages/domain/src/constitution/security/index.js +50 -0
  97. package/dist/packages/domain/src/constitution/security/ts.rules.js +267 -0
  98. package/dist/packages/domain/src/constitution/soc/index.js +43 -0
  99. package/dist/packages/domain/src/constitution/soc/ts.rules.js +360 -0
  100. package/dist/packages/domain/src/contracts/analysis.contract.js +18 -0
  101. package/dist/packages/domain/src/contracts/index.js +7 -0
  102. package/dist/packages/domain/src/contracts/projects.contract.js +18 -0
  103. package/dist/packages/domain/src/control/registry/rules.registry.js +29 -0
  104. package/dist/packages/domain/src/control/schemas/policies.js +6 -0
  105. package/dist/packages/domain/src/core/analysis/discovery.js +163 -0
  106. package/dist/packages/domain/src/core/analysis/engine.contract.js +298 -0
  107. package/dist/packages/domain/src/core/analysis/engine.js +77 -0
  108. package/dist/packages/domain/src/core/analysis/index.js +14 -0
  109. package/dist/packages/domain/src/core/analysis/orchestrator.js +242 -0
  110. package/dist/packages/domain/src/core/comparison/engine.js +29 -0
  111. package/dist/packages/domain/src/core/comparison/index.js +5 -0
  112. package/dist/packages/domain/src/core/documentation/index.js +5 -0
  113. package/dist/packages/domain/src/core/documentation/pipeline.js +41 -0
  114. package/dist/packages/domain/src/core/fs/adapter.js +111 -0
  115. package/dist/packages/domain/src/core/fs/index.js +5 -0
  116. package/dist/packages/domain/src/core/parser/unified-parser.js +166 -0
  117. package/dist/packages/domain/src/index.js +33 -0
  118. package/dist/packages/domain/src/plugin/registry.js +195 -0
  119. package/dist/packages/domain/src/plugin/types.js +6 -0
  120. package/dist/packages/domain/src/ports/analysis.engine.js +7 -0
  121. package/dist/packages/domain/src/ports/audit.logger.js +7 -0
  122. package/dist/packages/domain/src/ports/project.repository.js +7 -0
  123. package/dist/packages/domain/src/rules/index.js +134 -0
  124. package/dist/packages/domain/src/types/analysis.js +6 -0
  125. package/dist/packages/domain/src/types/errors.js +53 -0
  126. package/dist/packages/domain/src/types/fs.js +6 -0
  127. package/dist/packages/domain/src/types/index.js +7 -0
  128. package/dist/plugins/GitStatusPlugin.js +93 -0
  129. package/dist/providers/ai-provider.js +74 -0
  130. package/dist/providers/local-provider.js +304 -0
  131. package/dist/providers/remote-provider.js +100 -0
  132. package/dist/types/api.js +3 -0
  133. package/dist/ui.js +219 -0
  134. package/dist/welcome.js +81 -0
  135. package/package.json +18 -18
@@ -0,0 +1,344 @@
1
+ /**
2
+ * Delta Constitution - Maintainability Rules
3
+ * @description Code quality, testing, and documentation standards
4
+ * @version 1.0.0
5
+ * @see docs/architecture/CONSTITUTION.md
6
+ */
7
+ // =============================================================================
8
+ // MAINTAINABILITY RULE DEFINITIONS
9
+ // =============================================================================
10
+ export const MaintainabilityRules = {
11
+ version: '1.0.0',
12
+ lastUpdated: '2026-02-10',
13
+ // ============================================================================
14
+ // 1. LOCALITY OF BEHAVIOR
15
+ // ============================================================================
16
+ localityOfBehavior: {
17
+ enabled: true,
18
+ required: true,
19
+ description: 'All related code in one place',
20
+ principle: 'Co-location reduces cognitive load',
21
+ requirements: {
22
+ features: {
23
+ location: 'src/features/[name]/',
24
+ contains: ['UI', 'hooks', 'services', 'tests'],
25
+ maxDepth: 3,
26
+ },
27
+ modules: {
28
+ location: 'src/modules/[name]/',
29
+ contains: ['business logic', 'policies', 'types'],
30
+ maxDepth: 2,
31
+ },
32
+ core: {
33
+ location: 'src/core/[name]/',
34
+ contains: ['pure functions', 'domain logic'],
35
+ maxDepth: 2,
36
+ },
37
+ },
38
+ rules: [
39
+ {
40
+ id: 'MAINT-LOB-001',
41
+ name: 'No Deep Nesting',
42
+ description: 'Maximum 3 levels of directory nesting',
43
+ severity: 'warning',
44
+ },
45
+ {
46
+ id: 'MAINT-LOB-002',
47
+ name: 'Related Files Together',
48
+ description: 'Tests, types, and implementation in same directory',
49
+ severity: 'error',
50
+ },
51
+ ],
52
+ },
53
+ // ============================================================================
54
+ // 2. TESTING REQUIREMENTS
55
+ // ============================================================================
56
+ testing: {
57
+ enabled: true,
58
+ required: true,
59
+ description: 'Comprehensive test coverage',
60
+ coverage: {
61
+ unit: {
62
+ target: 80,
63
+ minimum: 70,
64
+ scope: 'functions, hooks, utilities',
65
+ },
66
+ integration: {
67
+ target: 60,
68
+ minimum: 50,
69
+ scope: 'modules, services',
70
+ },
71
+ e2e: {
72
+ target: 30,
73
+ minimum: 20,
74
+ scope: 'critical user flows',
75
+ },
76
+ },
77
+ types: {
78
+ unit: {
79
+ description: 'Test individual functions in isolation',
80
+ location: '__tests__/ or *.test.ts',
81
+ tools: ['vitest', 'jest'],
82
+ },
83
+ integration: {
84
+ description: 'Test module interactions',
85
+ location: '__tests__/integration/',
86
+ tools: ['vitest', 'supertest'],
87
+ },
88
+ constitution: {
89
+ description: 'Test architecture compliance',
90
+ location: 'tests/constitution/',
91
+ checks: ['import boundaries', 'pure functions', 'policy usage'],
92
+ },
93
+ },
94
+ rules: [
95
+ {
96
+ id: 'MAINT-TEST-001',
97
+ name: 'Test Pure Functions',
98
+ description: 'All pure functions must have unit tests',
99
+ severity: 'error',
100
+ },
101
+ {
102
+ id: 'MAINT-TEST-002',
103
+ name: 'Test Business Logic',
104
+ description: 'All business logic in modules must have tests',
105
+ severity: 'error',
106
+ },
107
+ {
108
+ id: 'MAINT-TEST-003',
109
+ name: 'Mock External Dependencies',
110
+ description: 'External services must be mocked in tests',
111
+ severity: 'warning',
112
+ },
113
+ ],
114
+ },
115
+ // ============================================================================
116
+ // 3. DOCUMENTATION
117
+ // ============================================================================
118
+ documentation: {
119
+ enabled: true,
120
+ required: true,
121
+ description: 'Documentation for every layer',
122
+ requirements: {
123
+ code: {
124
+ jsdoc: true,
125
+ description: 'Every exported function must have JSDoc',
126
+ required: ['description', 'param', 'returns'],
127
+ },
128
+ features: {
129
+ readme: 'README.md',
130
+ blueprint: 'docs/blueprints/[feature].md',
131
+ content: ['purpose', 'usage', 'api', 'examples'],
132
+ },
133
+ modules: {
134
+ readme: 'README.md',
135
+ content: ['purpose', 'public api', 'policies', 'examples'],
136
+ },
137
+ architecture: {
138
+ location: 'docs/architecture/',
139
+ files: [
140
+ 'CONSTITUTION.md',
141
+ 'OVERVIEW.md',
142
+ 'ENTERPRISE_ARCHITECTURE.md',
143
+ 'FEATURE_ASSESSMENT_TEMPLATE.md',
144
+ ],
145
+ },
146
+ },
147
+ rules: [
148
+ {
149
+ id: 'MAINT-DOC-001',
150
+ name: 'JSDoc Required',
151
+ description: 'All public exports must have JSDoc comments',
152
+ severity: 'error',
153
+ },
154
+ {
155
+ id: 'MAINT-DOC-002',
156
+ name: 'Feature Blueprint',
157
+ description: 'Each feature must have a blueprint document',
158
+ severity: 'warning',
159
+ },
160
+ ],
161
+ },
162
+ // ============================================================================
163
+ // 4. PURE FUNCTIONS
164
+ // ============================================================================
165
+ pureFunctions: {
166
+ enabled: true,
167
+ required: true,
168
+ description: 'Core must use pure functions only',
169
+ definition: {
170
+ deterministic: 'Same input always produces same output',
171
+ noSideEffects: 'No mutation of external state',
172
+ noDependencies: 'No reliance on external state',
173
+ },
174
+ rules: [
175
+ {
176
+ id: 'MAINT-PURE-001',
177
+ name: 'Core Functions Pure',
178
+ description: 'All functions in src/core/ must be pure',
179
+ severity: 'error',
180
+ check: 'AST analysis for side effects',
181
+ },
182
+ {
183
+ id: 'MAINT-PURE-002',
184
+ name: 'No Global State',
185
+ description: 'No global variables or singletons in Core',
186
+ severity: 'error',
187
+ forbidden: ['let global', 'var global', 'static state'],
188
+ },
189
+ ],
190
+ benefits: {
191
+ testing: 'Easy to test without mocks',
192
+ caching: 'Results can be safely cached',
193
+ concurrency: 'Safe to run in parallel',
194
+ debugging: 'Predictable behavior',
195
+ },
196
+ },
197
+ // ============================================================================
198
+ // 5. CODE QUALITY
199
+ // ============================================================================
200
+ codeQuality: {
201
+ enabled: true,
202
+ required: true,
203
+ description: 'Code quality standards',
204
+ metrics: {
205
+ complexity: {
206
+ cyclomatic: { max: 10, target: 5 },
207
+ cognitive: { max: 15, target: 10 },
208
+ },
209
+ lines: {
210
+ function: { max: 50, target: 30 },
211
+ file: { max: 300, target: 200 },
212
+ },
213
+ duplication: {
214
+ threshold: '5%',
215
+ target: '0%',
216
+ },
217
+ },
218
+ linting: {
219
+ eslint: {
220
+ config: '.eslintrc.cjs',
221
+ extends: ['next', 'typescript', 'prettier'],
222
+ customRules: 'constitution rules',
223
+ },
224
+ prettier: {
225
+ config: '.prettierrc',
226
+ enabled: true,
227
+ },
228
+ },
229
+ rules: [
230
+ {
231
+ id: 'MAINT-QUAL-001',
232
+ name: 'Max Complexity',
233
+ description: 'Cyclomatic complexity <= 10',
234
+ severity: 'warning',
235
+ },
236
+ {
237
+ id: 'MAINT-QUAL-002',
238
+ name: 'Max Function Length',
239
+ description: 'Functions should be <= 50 lines',
240
+ severity: 'warning',
241
+ },
242
+ {
243
+ id: 'MAINT-QUAL-003',
244
+ name: 'No Code Duplication',
245
+ description: 'Duplication <= 5%',
246
+ severity: 'error',
247
+ },
248
+ ],
249
+ },
250
+ // ============================================================================
251
+ // 6. NAMING CONVENTIONS
252
+ // ============================================================================
253
+ namingConventions: {
254
+ enabled: true,
255
+ required: true,
256
+ description: 'Consistent naming across the codebase',
257
+ conventions: {
258
+ files: {
259
+ components: 'PascalCase.tsx',
260
+ hooks: 'camelCase.ts (use*.ts)',
261
+ services: 'camelCase.service.ts',
262
+ utilities: 'camelCase.ts',
263
+ types: 'PascalCase.ts',
264
+ constants: 'UPPER_SNAKE_CASE.ts',
265
+ },
266
+ directories: {
267
+ features: 'kebab-case/',
268
+ modules: 'kebab-case/',
269
+ components: 'kebab-case/',
270
+ },
271
+ exports: {
272
+ functions: 'camelCase',
273
+ components: 'PascalCase',
274
+ types: 'PascalCase',
275
+ constants: 'UPPER_SNAKE_CASE',
276
+ },
277
+ },
278
+ rules: [
279
+ {
280
+ id: 'MAINT-NAME-001',
281
+ name: 'Descriptive Names',
282
+ description: 'Names should clearly describe purpose',
283
+ examples: {
284
+ bad: ['x', 'data', 'process'],
285
+ good: ['fileUploadProgress', 'analysisResult', 'validateUserInput'],
286
+ },
287
+ },
288
+ ],
289
+ },
290
+ };
291
+ export function validateTestCoverage(coverage) {
292
+ const violations = [];
293
+ let score = 100;
294
+ const { testing } = MaintainabilityRules;
295
+ if (coverage.unit < testing.coverage.unit.minimum) {
296
+ violations.push(`MAINT-TEST-COV: Unit coverage ${coverage.unit}% below minimum ${testing.coverage.unit.minimum}%`);
297
+ score -= 25;
298
+ }
299
+ if (coverage.integration < testing.coverage.integration.minimum) {
300
+ violations.push(`MAINT-TEST-COV: Integration coverage ${coverage.integration}% below minimum ${testing.coverage.integration.minimum}%`);
301
+ score -= 20;
302
+ }
303
+ if (coverage.e2e < testing.coverage.e2e.minimum) {
304
+ violations.push(`MAINT-TEST-COV: E2E coverage ${coverage.e2e}% below minimum ${testing.coverage.e2e.minimum}%`);
305
+ score -= 15;
306
+ }
307
+ return {
308
+ valid: violations.length === 0,
309
+ violations,
310
+ score: Math.max(0, score),
311
+ };
312
+ }
313
+ export function calculateMaintainabilityScore(checks) {
314
+ const maxScore = 100;
315
+ let score = 0;
316
+ // Testing (40 points)
317
+ if (checks.hasUnitTests)
318
+ score += 15;
319
+ if (checks.hasIntegrationTests)
320
+ score += 15;
321
+ if (checks.hasConstitutionTests)
322
+ score += 10;
323
+ // Documentation (25 points)
324
+ if (checks.hasJSDoc)
325
+ score += 10;
326
+ if (checks.hasReadme)
327
+ score += 10;
328
+ if (checks.hasBlueprints)
329
+ score += 5;
330
+ // Pure functions (20 points)
331
+ if (checks.coreUsesPureFunctions)
332
+ score += 20;
333
+ // Code quality (15 points)
334
+ if (checks.hasLinting)
335
+ score += 5;
336
+ if (checks.hasFormatting)
337
+ score += 5;
338
+ if (typeof checks.complexity === 'number' && checks.complexity < 10)
339
+ score += 5;
340
+ const grade = score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : score >= 60 ? 'D' : 'F';
341
+ return { score, maxScore, grade };
342
+ }
343
+ export default MaintainabilityRules;
344
+ //# sourceMappingURL=ts.rules.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Delta Constitution - Observability Rules Index
3
+ * @description Observability rules for all supported languages
4
+ * @version 1.0.0
5
+ */
6
+ // TypeScript / Node.js Rules
7
+ export { default as ts, ObservabilityRules as TSObservabilityRules } from './ts.rules';
8
+ // Language-agnostic exports
9
+ export const ObservabilityAxis = {
10
+ name: 'Observability',
11
+ description: 'Health Checks, Logging, Metrics, Error Tracking, Alerting',
12
+ weight: 5,
13
+ languages: ['typescript', 'javascript', 'node'],
14
+ principles: [
15
+ {
16
+ id: 'OBS-001',
17
+ name: 'Health Checks',
18
+ description: 'Every service exposes /api/health, /api/ready, /api/live',
19
+ },
20
+ {
21
+ id: 'OBS-002',
22
+ name: 'Structured Logging',
23
+ description: 'JSON structured logs across all layers',
24
+ },
25
+ {
26
+ id: 'OBS-003',
27
+ name: 'Error Tracking',
28
+ description: 'Centralized error tracking with context',
29
+ },
30
+ {
31
+ id: 'OBS-004',
32
+ name: 'Performance Metrics',
33
+ description: 'Track latency, throughput, errors, business metrics',
34
+ },
35
+ {
36
+ id: 'OBS-005',
37
+ name: 'Alerting',
38
+ description: 'Proactive alerts for critical issues',
39
+ },
40
+ ],
41
+ };
42
+ export default ObservabilityAxis;
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,307 @@
1
+ /**
2
+ * Delta Constitution - Observability Rules
3
+ * @description Monitoring, logging, and health check standards
4
+ * @version 1.0.0
5
+ * @see docs/architecture/CONSTITUTION.md
6
+ */
7
+ // =============================================================================
8
+ // OBSERVABILITY RULE DEFINITIONS
9
+ // =============================================================================
10
+ export const ObservabilityRules = {
11
+ version: '1.0.0',
12
+ lastUpdated: '2026-02-10',
13
+ // ============================================================================
14
+ // 1. HEALTH CHECKS
15
+ // ============================================================================
16
+ healthChecks: {
17
+ enabled: true,
18
+ required: true,
19
+ description: 'Health checks for every endpoint and service',
20
+ endpoints: {
21
+ main: {
22
+ path: '/api/health',
23
+ method: 'GET',
24
+ checks: ['database', 'cache', 'storage'],
25
+ response: {
26
+ status: 'healthy | degraded | unhealthy',
27
+ timestamp: 'ISO 8601',
28
+ version: 'app version',
29
+ checks: 'Record<string, boolean> - Health check results',
30
+ },
31
+ },
32
+ ready: {
33
+ path: '/api/ready',
34
+ method: 'GET',
35
+ purpose: 'Kubernetes readiness probe',
36
+ checks: ['dependencies ready'],
37
+ },
38
+ live: {
39
+ path: '/api/live',
40
+ method: 'GET',
41
+ purpose: 'Kubernetes liveness probe',
42
+ checks: ['process running'],
43
+ },
44
+ },
45
+ requirements: {
46
+ allServices: true,
47
+ responseTime: '< 500ms',
48
+ frequency: 'configurable',
49
+ alerting: true,
50
+ },
51
+ rules: [
52
+ {
53
+ id: 'OBS-HEALTH-001',
54
+ name: 'Health Endpoint Required',
55
+ description: 'Every service must expose /api/health',
56
+ severity: 'error',
57
+ },
58
+ {
59
+ id: 'OBS-HEALTH-002',
60
+ name: 'Dependency Checks',
61
+ description: 'Health check must verify all dependencies',
62
+ severity: 'error',
63
+ },
64
+ ],
65
+ },
66
+ // ============================================================================
67
+ // 2. STRUCTURED LOGGING
68
+ // ============================================================================
69
+ structuredLogging: {
70
+ enabled: true,
71
+ required: true,
72
+ description: 'JSON structured logging across all layers',
73
+ format: {
74
+ type: 'JSON',
75
+ required: ['timestamp', 'level', 'message', 'service'],
76
+ optional: ['traceId', 'userId', 'duration', 'metadata'],
77
+ },
78
+ levels: {
79
+ fatal: { level: 60, use: 'Application crash' },
80
+ error: { level: 50, use: 'Errors requiring immediate attention' },
81
+ warn: { level: 40, use: 'Warnings, recoverable issues' },
82
+ info: { level: 30, use: 'General information' },
83
+ debug: { level: 20, use: 'Debugging information' },
84
+ trace: { level: 10, use: 'Detailed tracing' },
85
+ },
86
+ layers: {
87
+ features: { level: 'info', purpose: 'User actions, UI events' },
88
+ modules: { level: 'info', purpose: 'Business logic operations' },
89
+ core: { level: 'debug', purpose: 'Domain logic details' },
90
+ security: { level: 'info', purpose: 'Audit events, violations' },
91
+ infrastructure: { level: 'warn', purpose: 'External service issues' },
92
+ },
93
+ tools: {
94
+ development: 'pino-pretty',
95
+ production: 'pino',
96
+ transport: 'stdout (containerized)',
97
+ },
98
+ },
99
+ // ============================================================================
100
+ // 3. ERROR TRACKING
101
+ // ============================================================================
102
+ errorTracking: {
103
+ enabled: true,
104
+ required: true,
105
+ description: 'Centralized error tracking and alerting',
106
+ tools: {
107
+ primary: 'Sentry',
108
+ fallback: 'Custom error aggregation',
109
+ },
110
+ requirements: {
111
+ capture: ['exceptions', 'unhandled rejections', 'crashes'],
112
+ context: ['user', 'request', 'tags', 'breadcrumbs'],
113
+ alerting: {
114
+ channels: ['email', 'slack', 'pagerduty'],
115
+ rules: [
116
+ { condition: 'error rate > 1%', level: 'warning' },
117
+ { condition: 'error rate > 5%', level: 'critical' },
118
+ { condition: 'fatal error', level: 'critical' },
119
+ ],
120
+ },
121
+ },
122
+ rules: [
123
+ {
124
+ id: 'OBS-ERR-001',
125
+ name: 'Error Context',
126
+ description: 'All errors must include user and request context',
127
+ severity: 'error',
128
+ },
129
+ {
130
+ id: 'OBS-ERR-002',
131
+ name: 'Alert Threshold',
132
+ description: 'Alert when error rate exceeds 1%',
133
+ severity: 'warning',
134
+ },
135
+ ],
136
+ },
137
+ // ============================================================================
138
+ // 4. PERFORMANCE METRICS
139
+ // ============================================================================
140
+ performanceMetrics: {
141
+ enabled: true,
142
+ required: true,
143
+ description: 'Performance tracking and dashboards',
144
+ metrics: {
145
+ api: {
146
+ latency: { p50: '100ms', p95: '300ms', p99: '500ms' },
147
+ throughput: 'requests per second',
148
+ errors: 'error rate percentage',
149
+ },
150
+ frontend: {
151
+ ttfb: 'Time to first byte',
152
+ fcp: 'First contentful paint',
153
+ lcp: 'Largest contentful paint',
154
+ tti: 'Time to interactive',
155
+ cls: 'Cumulative layout shift',
156
+ },
157
+ business: {
158
+ activeUsers: 'Concurrent users',
159
+ featureUsage: 'Feature adoption rates',
160
+ conversion: 'User conversion rates',
161
+ },
162
+ },
163
+ targets: {
164
+ lighthouse: {
165
+ performance: 90,
166
+ accessibility: 90,
167
+ 'best-practices': 90,
168
+ seo: 90,
169
+ },
170
+ api: {
171
+ p95: '300ms',
172
+ p99: '500ms',
173
+ errorRate: '0.1%',
174
+ },
175
+ },
176
+ dashboards: {
177
+ grafana: 'Primary dashboard',
178
+ vercel: 'Built-in analytics',
179
+ custom: 'Custom business metrics',
180
+ },
181
+ },
182
+ // ============================================================================
183
+ // 5. DISTRIBUTED TRACING
184
+ // ============================================================================
185
+ distributedTracing: {
186
+ enabled: true,
187
+ required: false,
188
+ description: 'Trace requests across services',
189
+ implementation: {
190
+ tool: 'OpenTelemetry',
191
+ propagation: 'W3C Trace Context',
192
+ sampling: '1% in production, 100% in development',
193
+ },
194
+ spans: {
195
+ required: ['request', 'database', 'cache', 'external-api'],
196
+ optional: ['render', 'compute', 'validation'],
197
+ },
198
+ },
199
+ // ============================================================================
200
+ // 6. ALERTING
201
+ // ============================================================================
202
+ alerting: {
203
+ enabled: true,
204
+ required: true,
205
+ description: 'Proactive alerting for issues',
206
+ channels: {
207
+ slack: { type: 'notification', use: 'team alerts' },
208
+ email: { type: 'notification', use: 'summary reports' },
209
+ pagerduty: { type: 'pager', use: 'critical issues' },
210
+ },
211
+ rules: [
212
+ {
213
+ id: 'OBS-ALERT-001',
214
+ condition: 'Health check fails',
215
+ severity: 'critical',
216
+ channel: 'pagerduty',
217
+ response: 'immediate',
218
+ },
219
+ {
220
+ id: 'OBS-ALERT-002',
221
+ condition: 'Error rate > 1%',
222
+ severity: 'warning',
223
+ channel: 'slack',
224
+ response: 'within 15 min',
225
+ },
226
+ {
227
+ id: 'OBS-ALERT-003',
228
+ condition: 'API latency p95 > 500ms',
229
+ severity: 'warning',
230
+ channel: 'slack',
231
+ response: 'within 30 min',
232
+ },
233
+ {
234
+ id: 'OBS-ALERT-004',
235
+ condition: 'Security policy violation',
236
+ severity: 'critical',
237
+ channel: 'pagerduty + slack',
238
+ response: 'immediate',
239
+ },
240
+ ],
241
+ },
242
+ };
243
+ // =============================================================================
244
+ // VALIDATION HELPERS
245
+ // =============================================================================
246
+ export function validateObservabilityCompliance(checks) {
247
+ const violations = [];
248
+ let score = 100;
249
+ if (!checks.hasHealthEndpoint) {
250
+ violations.push('OBS-HEALTH-001: Missing health endpoint');
251
+ score -= 20;
252
+ }
253
+ if (!checks.hasStructuredLogging) {
254
+ violations.push('OBS-LOG-001: Missing structured logging');
255
+ score -= 20;
256
+ }
257
+ if (!checks.hasErrorTracking) {
258
+ violations.push('OBS-ERR-001: Missing error tracking');
259
+ score -= 20;
260
+ }
261
+ if (!checks.hasMetrics) {
262
+ violations.push('OBS-MET-001: Missing performance metrics');
263
+ score -= 15;
264
+ }
265
+ if (!checks.hasAlerting) {
266
+ violations.push('OBS-ALERT-001: Missing alerting configuration');
267
+ score -= 15;
268
+ }
269
+ return {
270
+ compliant: violations.length === 0,
271
+ violations,
272
+ score: Math.max(0, score),
273
+ };
274
+ }
275
+ export function calculateObservabilityScore(checks) {
276
+ const maxScore = 100;
277
+ let score = 0;
278
+ // Health checks (25 points)
279
+ if (checks.hasHealthEndpoint)
280
+ score += 15;
281
+ if (checks.hasReadinessProbe)
282
+ score += 5;
283
+ if (checks.hasLivenessProbe)
284
+ score += 5;
285
+ // Logging (25 points)
286
+ if (checks.hasStructuredLogging)
287
+ score += 15;
288
+ if (checks.hasLogAggregation)
289
+ score += 10;
290
+ // Error tracking (20 points)
291
+ if (checks.hasErrorTracking)
292
+ score += 15;
293
+ if (checks.hasErrorAlerting)
294
+ score += 5;
295
+ // Metrics (20 points)
296
+ if (checks.hasMetrics)
297
+ score += 15;
298
+ if (checks.hasDashboards)
299
+ score += 5;
300
+ // Alerting (10 points)
301
+ if (checks.hasAlerting)
302
+ score += 10;
303
+ const grade = score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : score >= 60 ? 'D' : 'F';
304
+ return { score, maxScore, grade };
305
+ }
306
+ export default ObservabilityRules;
307
+ //# sourceMappingURL=ts.rules.js.map