@harness-engineering/core 0.26.3 → 0.27.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.
@@ -0,0 +1,125 @@
1
+ // src/architecture/types.ts
2
+ import { z } from "zod";
3
+ var ArchMetricCategorySchema = z.enum([
4
+ "circular-deps",
5
+ "layer-violations",
6
+ "complexity",
7
+ "coupling",
8
+ "forbidden-imports",
9
+ "module-size",
10
+ "dependency-depth"
11
+ ]);
12
+ var ViolationSchema = z.object({
13
+ id: z.string(),
14
+ // stable hash: sha256(relativePath + ':' + category + ':' + normalizedDetail)
15
+ file: z.string(),
16
+ // relative to project root
17
+ category: ArchMetricCategorySchema.optional(),
18
+ // context for baseline reporting
19
+ detail: z.string(),
20
+ // human-readable description
21
+ severity: z.enum(["error", "warning"])
22
+ });
23
+ var MetricResultSchema = z.object({
24
+ category: ArchMetricCategorySchema,
25
+ scope: z.string(),
26
+ // e.g., 'project', 'src/services', 'src/api/routes.ts'
27
+ value: z.number(),
28
+ // numeric metric (violation count, complexity score, etc.)
29
+ violations: z.array(ViolationSchema),
30
+ metadata: z.record(z.unknown()).optional()
31
+ });
32
+ var CategoryBaselineSchema = z.object({
33
+ value: z.number(),
34
+ // aggregate metric value at baseline time
35
+ violationIds: z.array(z.string())
36
+ // stable IDs of known violations (the allowlist)
37
+ });
38
+ var ArchBaselineSchema = z.object({
39
+ version: z.literal(1),
40
+ updatedAt: z.string().datetime(),
41
+ // ISO 8601
42
+ updatedFrom: z.string(),
43
+ // commit hash
44
+ metrics: z.record(ArchMetricCategorySchema, CategoryBaselineSchema)
45
+ });
46
+ var CategoryRegressionSchema = z.object({
47
+ category: ArchMetricCategorySchema,
48
+ baselineValue: z.number(),
49
+ currentValue: z.number(),
50
+ delta: z.number()
51
+ });
52
+ var ArchDiffResultSchema = z.object({
53
+ passed: z.boolean(),
54
+ newViolations: z.array(ViolationSchema),
55
+ // in current but not in baseline -> FAIL
56
+ resolvedViolations: z.array(z.string()),
57
+ // in baseline but not in current -> celebrate
58
+ preExisting: z.array(z.string()),
59
+ // in both -> allowed, tracked
60
+ regressions: z.array(CategoryRegressionSchema)
61
+ // aggregate value exceeded baseline
62
+ });
63
+ var ThresholdConfigSchema = z.record(
64
+ ArchMetricCategorySchema,
65
+ z.union([z.number(), z.record(z.string(), z.number())])
66
+ );
67
+ var ArchConfigSchema = z.object({
68
+ enabled: z.boolean().default(true),
69
+ baselinePath: z.string().default(".harness/arch/baselines.json"),
70
+ thresholds: ThresholdConfigSchema.default({}),
71
+ modules: z.record(z.string(), ThresholdConfigSchema).default({})
72
+ });
73
+ var ConstraintRuleSchema = z.object({
74
+ id: z.string(),
75
+ // stable hash: sha256(category + ':' + scope + ':' + description)
76
+ category: ArchMetricCategorySchema,
77
+ description: z.string(),
78
+ // e.g., "Layer 'services' must not import from 'ui'"
79
+ scope: z.string(),
80
+ // e.g., 'src/services/', 'project'
81
+ targets: z.array(z.string()).optional()
82
+ // forward-compat for governs edges
83
+ });
84
+ var ViolationSnapshotSchema = z.object({
85
+ timestamp: z.string().datetime(),
86
+ violations: z.array(ViolationSchema)
87
+ });
88
+ var ViolationHistorySchema = z.object({
89
+ version: z.literal(1),
90
+ snapshots: z.array(ViolationSnapshotSchema)
91
+ });
92
+ var EmergenceConfidenceSchema = z.enum(["low", "medium", "high"]);
93
+ var EmergentConstraintSuggestionSchema = z.object({
94
+ suggestedRule: ConstraintRuleSchema,
95
+ confidence: EmergenceConfidenceSchema,
96
+ occurrences: z.number(),
97
+ uniqueFiles: z.number(),
98
+ pattern: z.string(),
99
+ sampleViolations: z.array(ViolationSchema),
100
+ rationale: z.string()
101
+ });
102
+ var EmergenceResultSchema = z.object({
103
+ suggestions: z.array(EmergentConstraintSuggestionSchema),
104
+ totalViolationsAnalyzed: z.number(),
105
+ windowWeeks: z.number(),
106
+ minOccurrences: z.number()
107
+ });
108
+
109
+ export {
110
+ ArchMetricCategorySchema,
111
+ ViolationSchema,
112
+ MetricResultSchema,
113
+ CategoryBaselineSchema,
114
+ ArchBaselineSchema,
115
+ CategoryRegressionSchema,
116
+ ArchDiffResultSchema,
117
+ ThresholdConfigSchema,
118
+ ArchConfigSchema,
119
+ ConstraintRuleSchema,
120
+ ViolationSnapshotSchema,
121
+ ViolationHistorySchema,
122
+ EmergenceConfidenceSchema,
123
+ EmergentConstraintSuggestionSchema,
124
+ EmergenceResultSchema
125
+ };