@eduardbar/drift 1.3.0 → 1.4.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 (168) hide show
  1. package/.gga +50 -0
  2. package/.github/actions/drift-review/README.md +60 -0
  3. package/.github/actions/drift-review/action.yml +131 -0
  4. package/.github/actions/drift-scan/README.md +28 -32
  5. package/.github/actions/drift-scan/action.yml +78 -14
  6. package/.github/workflows/review-pr.yml +34 -41
  7. package/AGENTS.md +75 -251
  8. package/CHANGELOG.md +28 -0
  9. package/README.md +148 -41
  10. package/dist/benchmark.d.ts +1 -1
  11. package/dist/benchmark.js +71 -52
  12. package/dist/cli.js +243 -8
  13. package/dist/config.js +16 -2
  14. package/dist/diff.js +42 -50
  15. package/dist/doctor.d.ts +5 -0
  16. package/dist/doctor.js +133 -0
  17. package/dist/format.d.ts +17 -0
  18. package/dist/format.js +45 -0
  19. package/dist/guard-types.d.ts +57 -0
  20. package/dist/guard-types.js +2 -0
  21. package/dist/guard.d.ts +14 -0
  22. package/dist/guard.js +239 -0
  23. package/dist/index.d.ts +10 -3
  24. package/dist/index.js +4 -1
  25. package/dist/init.d.ts +15 -0
  26. package/dist/init.js +273 -0
  27. package/dist/map-cycles.d.ts +2 -0
  28. package/dist/map-cycles.js +34 -0
  29. package/dist/map-svg.d.ts +19 -0
  30. package/dist/map-svg.js +97 -0
  31. package/dist/map.js +78 -138
  32. package/dist/metrics.js +70 -55
  33. package/dist/output-metadata.d.ts +13 -0
  34. package/dist/output-metadata.js +17 -0
  35. package/dist/plugins-capabilities.d.ts +4 -0
  36. package/dist/plugins-capabilities.js +21 -0
  37. package/dist/plugins-messages.d.ts +10 -0
  38. package/dist/plugins-messages.js +16 -0
  39. package/dist/plugins-rules.d.ts +9 -0
  40. package/dist/plugins-rules.js +137 -0
  41. package/dist/plugins.d.ts +1 -1
  42. package/dist/plugins.js +45 -142
  43. package/dist/reporter-constants.d.ts +16 -0
  44. package/dist/reporter-constants.js +39 -0
  45. package/dist/reporter.d.ts +3 -3
  46. package/dist/reporter.js +35 -55
  47. package/dist/review.d.ts +2 -1
  48. package/dist/review.js +2 -1
  49. package/dist/rules/phase3-configurable.js +23 -15
  50. package/dist/saas/constants.d.ts +15 -0
  51. package/dist/saas/constants.js +48 -0
  52. package/dist/saas/dashboard.d.ts +8 -0
  53. package/dist/saas/dashboard.js +132 -0
  54. package/dist/saas/errors.d.ts +19 -0
  55. package/dist/saas/errors.js +37 -0
  56. package/dist/saas/helpers.d.ts +21 -0
  57. package/dist/saas/helpers.js +110 -0
  58. package/dist/saas/ingest.d.ts +3 -0
  59. package/dist/saas/ingest.js +249 -0
  60. package/dist/saas/organization.d.ts +5 -0
  61. package/dist/saas/organization.js +82 -0
  62. package/dist/saas/plan-change.d.ts +10 -0
  63. package/dist/saas/plan-change.js +15 -0
  64. package/dist/saas/store.d.ts +21 -0
  65. package/dist/saas/store.js +159 -0
  66. package/dist/saas/types.d.ts +191 -0
  67. package/dist/saas/types.js +2 -0
  68. package/dist/saas.d.ts +8 -218
  69. package/dist/saas.js +7 -761
  70. package/dist/sarif.d.ts +74 -0
  71. package/dist/sarif.js +122 -0
  72. package/dist/trust-advanced.d.ts +14 -0
  73. package/dist/trust-advanced.js +65 -0
  74. package/dist/trust-kpi-fs.d.ts +3 -0
  75. package/dist/trust-kpi-fs.js +141 -0
  76. package/dist/trust-kpi-parse.d.ts +7 -0
  77. package/dist/trust-kpi-parse.js +186 -0
  78. package/dist/trust-kpi-types.d.ts +16 -0
  79. package/dist/trust-kpi-types.js +2 -0
  80. package/dist/trust-kpi.d.ts +1 -3
  81. package/dist/trust-kpi.js +6 -266
  82. package/dist/trust-policy.d.ts +32 -0
  83. package/dist/trust-policy.js +160 -0
  84. package/dist/trust-render.d.ts +9 -0
  85. package/dist/trust-render.js +54 -0
  86. package/dist/trust-scoring.d.ts +9 -0
  87. package/dist/trust-scoring.js +208 -0
  88. package/dist/trust.d.ts +4 -32
  89. package/dist/trust.js +29 -432
  90. package/dist/types/app.d.ts +30 -0
  91. package/dist/types/app.js +2 -0
  92. package/dist/types/config.d.ts +25 -0
  93. package/dist/types/config.js +2 -0
  94. package/dist/types/core.d.ts +100 -0
  95. package/dist/types/core.js +2 -0
  96. package/dist/types/diff.d.ts +55 -0
  97. package/dist/types/diff.js +2 -0
  98. package/dist/types/plugin.d.ts +41 -0
  99. package/dist/types/plugin.js +2 -0
  100. package/dist/types/trust.d.ts +120 -0
  101. package/dist/types/trust.js +2 -0
  102. package/dist/types.d.ts +8 -365
  103. package/docs/release-notes-draft.md +40 -0
  104. package/docs/rules-catalog.md +49 -0
  105. package/docs/trust-core-release-checklist.md +37 -5
  106. package/package.json +3 -2
  107. package/packages/vscode-drift/src/code-actions.ts +1 -1
  108. package/schemas/drift-ai-output.v1.json +162 -0
  109. package/schemas/drift-report.v1.json +151 -0
  110. package/schemas/drift-trust.v1.json +131 -0
  111. package/scripts/smoke-repo.mjs +394 -0
  112. package/src/benchmark.ts +75 -53
  113. package/src/cli.ts +285 -13
  114. package/src/config.ts +19 -2
  115. package/src/diff.ts +57 -48
  116. package/src/doctor.ts +173 -0
  117. package/src/format.ts +81 -0
  118. package/src/guard-types.ts +64 -0
  119. package/src/guard.ts +324 -0
  120. package/src/index.ts +35 -0
  121. package/src/init.ts +298 -0
  122. package/src/map-cycles.ts +38 -0
  123. package/src/map-svg.ts +124 -0
  124. package/src/map.ts +111 -142
  125. package/src/metrics.ts +78 -59
  126. package/src/output-metadata.ts +30 -0
  127. package/src/plugins-capabilities.ts +36 -0
  128. package/src/plugins-messages.ts +35 -0
  129. package/src/plugins-rules.ts +296 -0
  130. package/src/plugins.ts +76 -283
  131. package/src/reporter-constants.ts +46 -0
  132. package/src/reporter.ts +64 -65
  133. package/src/review.ts +4 -2
  134. package/src/rules/phase3-configurable.ts +39 -26
  135. package/src/saas/constants.ts +56 -0
  136. package/src/saas/dashboard.ts +172 -0
  137. package/src/saas/errors.ts +45 -0
  138. package/src/saas/helpers.ts +140 -0
  139. package/src/saas/ingest.ts +278 -0
  140. package/src/saas/organization.ts +99 -0
  141. package/src/saas/plan-change.ts +19 -0
  142. package/src/saas/store.ts +172 -0
  143. package/src/saas/types.ts +216 -0
  144. package/src/saas.ts +49 -1031
  145. package/src/sarif.ts +232 -0
  146. package/src/trust-advanced.ts +99 -0
  147. package/src/trust-kpi-fs.ts +169 -0
  148. package/src/trust-kpi-parse.ts +219 -0
  149. package/src/trust-kpi-types.ts +19 -0
  150. package/src/trust-kpi.ts +8 -316
  151. package/src/trust-policy.ts +246 -0
  152. package/src/trust-render.ts +61 -0
  153. package/src/trust-scoring.ts +231 -0
  154. package/src/trust.ts +62 -576
  155. package/src/types/app.ts +30 -0
  156. package/src/types/config.ts +27 -0
  157. package/src/types/core.ts +105 -0
  158. package/src/types/diff.ts +61 -0
  159. package/src/types/plugin.ts +46 -0
  160. package/src/types/trust.ts +134 -0
  161. package/src/types.ts +78 -409
  162. package/tests/cli-sarif.test.ts +92 -0
  163. package/tests/format.test.ts +157 -0
  164. package/tests/new-features.test.ts +10 -2
  165. package/tests/phase1-init-doctor-guard.test.ts +199 -0
  166. package/tests/sarif.test.ts +160 -0
  167. package/tests/trust-kpi.test.ts +31 -4
  168. package/tests/trust.test.ts +18 -0
@@ -0,0 +1,30 @@
1
+ import type { DriftPerformanceConfig, LayerDefinition, ModuleBoundary } from './config.js'
2
+ import type { TrustGatePolicyConfig } from './trust.js'
3
+
4
+ export interface DriftConfig {
5
+ layers?: LayerDefinition[]
6
+ modules?: ModuleBoundary[]
7
+ moduleBoundaries?: ModuleBoundary[]
8
+ boundaries?: ModuleBoundary[]
9
+ plugins?: string[]
10
+ performance?: DriftPerformanceConfig
11
+ architectureRules?: {
12
+ controllerNoDb?: boolean
13
+ serviceNoHttp?: boolean
14
+ maxFunctionLines?: number
15
+ }
16
+ saas?: {
17
+ freeUserThreshold?: number
18
+ maxRunsPerWorkspacePerMonth?: number
19
+ maxReposPerWorkspace?: number
20
+ retentionDays?: number
21
+ strictActorEnforcement?: boolean
22
+ maxWorkspacesPerOrganizationByPlan?: {
23
+ free?: number
24
+ sponsor?: number
25
+ team?: number
26
+ business?: number
27
+ }
28
+ }
29
+ trustGate?: TrustGatePolicyConfig
30
+ }
@@ -0,0 +1,27 @@
1
+ export interface LayerDefinition {
2
+ name: string
3
+ patterns: string[]
4
+ canImportFrom: string[]
5
+ }
6
+
7
+ export interface ModuleBoundary {
8
+ name: string
9
+ root: string
10
+ allowedExternalImports?: string[]
11
+ }
12
+
13
+ export interface DriftPerformanceConfig {
14
+ lowMemory?: boolean
15
+ chunkSize?: number
16
+ maxFiles?: number
17
+ maxFileSizeKb?: number
18
+ includeSemanticDuplication?: boolean
19
+ }
20
+
21
+ export interface DriftAnalysisOptions {
22
+ lowMemory?: boolean
23
+ chunkSize?: number
24
+ maxFiles?: number
25
+ maxFileSizeKb?: number
26
+ includeSemanticDuplication?: boolean
27
+ }
@@ -0,0 +1,105 @@
1
+ export interface DriftIssue {
2
+ rule: string
3
+ severity: 'error' | 'warning' | 'info'
4
+ message: string
5
+ line: number
6
+ column: number
7
+ snippet: string
8
+ }
9
+
10
+ export interface FileReport {
11
+ path: string
12
+ issues: DriftIssue[]
13
+ score: number
14
+ }
15
+
16
+ export interface RepoQualityScore {
17
+ overall: number
18
+ dimensions: {
19
+ architecture: number
20
+ complexity: number
21
+ 'ai-patterns': number
22
+ testing: number
23
+ }
24
+ }
25
+
26
+ export interface RiskHotspot {
27
+ file: string
28
+ driftScore: number
29
+ complexityIssues: number
30
+ hasNearbyTests: boolean
31
+ changeFrequency: number
32
+ risk: number
33
+ reasons: string[]
34
+ }
35
+
36
+ export interface MaintenanceRiskMetrics {
37
+ score: number
38
+ level: 'low' | 'medium' | 'high' | 'critical'
39
+ hotspots: RiskHotspot[]
40
+ signals: {
41
+ highComplexityFiles: number
42
+ filesWithoutNearbyTests: number
43
+ frequentChangeFiles: number
44
+ }
45
+ }
46
+
47
+ export interface DriftReport {
48
+ scannedAt: string
49
+ targetPath: string
50
+ files: FileReport[]
51
+ totalIssues: number
52
+ totalScore: number
53
+ totalFiles: number
54
+ summary: {
55
+ errors: number
56
+ warnings: number
57
+ infos: number
58
+ byRule: Record<string, number>
59
+ }
60
+ quality: RepoQualityScore
61
+ maintenanceRisk: MaintenanceRiskMetrics
62
+ }
63
+
64
+ export interface AIIssue {
65
+ rank: number
66
+ file: string
67
+ line: number
68
+ rule: string
69
+ severity: string
70
+ message: string
71
+ snippet: string
72
+ fix_suggestion: string
73
+ effort: 'low' | 'medium' | 'high'
74
+ }
75
+
76
+ export interface AIOutput {
77
+ summary: {
78
+ score: number
79
+ grade: string
80
+ total_issues: number
81
+ files_affected: number
82
+ files_clean: number
83
+ ai_likelihood: number
84
+ ai_code_smell_score: number
85
+ }
86
+ files_suspected: Array<{ path: string; ai_likelihood: number; triggers: string[] }>
87
+ priority_order: AIIssue[]
88
+ maintenance_risk: MaintenanceRiskMetrics
89
+ quality: RepoQualityScore
90
+ context_for_ai: {
91
+ project_type: string
92
+ scan_path: string
93
+ rules_detected: string[]
94
+ recommended_action: string
95
+ }
96
+ }
97
+
98
+ export interface DriftOutputMetadata {
99
+ $schema: string
100
+ toolVersion: string
101
+ }
102
+
103
+ export type DriftReportJson = DriftReport & DriftOutputMetadata
104
+
105
+ export type AIOutputJson = AIOutput & DriftOutputMetadata
@@ -0,0 +1,61 @@
1
+ import type { DriftIssue, DriftReport, FileReport } from './core.js'
2
+
3
+ export interface FileDiff {
4
+ path: string
5
+ scoreBefore: number
6
+ scoreAfter: number
7
+ scoreDelta: number
8
+ newIssues: DriftIssue[]
9
+ resolvedIssues: DriftIssue[]
10
+ }
11
+
12
+ export interface DriftDiff {
13
+ baseRef: string
14
+ projectPath: string
15
+ scannedAt: string
16
+ files: FileDiff[]
17
+ totalScoreBefore: number
18
+ totalScoreAfter: number
19
+ totalDelta: number
20
+ newIssuesCount: number
21
+ resolvedIssuesCount: number
22
+ }
23
+
24
+ export interface HistoricalAnalysis {
25
+ commitHash: string
26
+ commitDate: Date
27
+ author: string
28
+ message: string
29
+ files: FileReport[]
30
+ totalScore: number
31
+ averageScore: number
32
+ }
33
+
34
+ export interface TrendDataPoint {
35
+ date: Date
36
+ score: number
37
+ fileCount: number
38
+ avgIssuesPerFile: number
39
+ }
40
+
41
+ export interface BlameAttribution {
42
+ author: string
43
+ email: string
44
+ commits: number
45
+ linesChanged: number
46
+ issuesIntroduced: number
47
+ avgScoreImpact: number
48
+ }
49
+
50
+ export interface DriftTrendReport extends DriftReport {
51
+ trend: TrendDataPoint[]
52
+ regression: {
53
+ slope: number
54
+ intercept: number
55
+ r2: number
56
+ }
57
+ }
58
+
59
+ export interface DriftBlameReport extends DriftReport {
60
+ blame: BlameAttribution[]
61
+ }
@@ -0,0 +1,46 @@
1
+ import type { SourceFile } from 'ts-morph'
2
+ import type { DriftConfig } from './app.js'
3
+ import type { DriftIssue } from './core.js'
4
+
5
+ export interface PluginRuleContext {
6
+ projectRoot: string
7
+ filePath: string
8
+ config?: DriftConfig
9
+ }
10
+
11
+ export interface DriftPluginRule {
12
+ id?: string
13
+ name: string
14
+ severity?: DriftIssue['severity']
15
+ weight?: number
16
+ detect: (file: SourceFile, context: PluginRuleContext) => DriftIssue[]
17
+ fix?: (issue: DriftIssue, file: SourceFile, context: PluginRuleContext) => DriftIssue | void
18
+ }
19
+
20
+ export interface DriftPlugin {
21
+ name: string
22
+ apiVersion?: number
23
+ capabilities?: Record<string, string | number | boolean>
24
+ rules: DriftPluginRule[]
25
+ }
26
+
27
+ export interface LoadedPlugin {
28
+ id: string
29
+ plugin: DriftPlugin
30
+ }
31
+
32
+ export interface PluginLoadError {
33
+ pluginId: string
34
+ pluginName?: string
35
+ ruleId?: string
36
+ code?: string
37
+ message: string
38
+ }
39
+
40
+ export interface PluginLoadWarning {
41
+ pluginId: string
42
+ pluginName?: string
43
+ ruleId?: string
44
+ code?: string
45
+ message: string
46
+ }
@@ -0,0 +1,134 @@
1
+ import type { DriftIssue, DriftOutputMetadata } from './core.js'
2
+
3
+ export type MergeRiskLevel = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
4
+
5
+ export interface TrustGatePolicyPreset {
6
+ branch: string
7
+ enabled?: boolean
8
+ minTrust?: number
9
+ maxRisk?: MergeRiskLevel
10
+ }
11
+
12
+ export interface TrustGatePolicyPack {
13
+ enabled?: boolean
14
+ minTrust?: number
15
+ maxRisk?: MergeRiskLevel
16
+ }
17
+
18
+ export interface TrustGatePolicyConfig {
19
+ enabled?: boolean
20
+ minTrust?: number
21
+ maxRisk?: MergeRiskLevel
22
+ presets?: TrustGatePolicyPreset[]
23
+ policyPacks?: Record<string, TrustGatePolicyPack>
24
+ }
25
+
26
+ export interface TrustReason {
27
+ label: string
28
+ detail: string
29
+ impact: number
30
+ }
31
+
32
+ export interface TrustFixPriority {
33
+ rank: number
34
+ rule: string
35
+ severity: DriftIssue['severity']
36
+ occurrences: number
37
+ estimated_trust_gain: number
38
+ effort: 'low' | 'medium' | 'high'
39
+ suggestion: string
40
+ confidence?: 'low' | 'medium' | 'high'
41
+ explanation?: string
42
+ systemic?: boolean
43
+ }
44
+
45
+ export interface TrustAdvancedComparison {
46
+ source: 'previous-trust-json' | 'snapshot-history'
47
+ trend: 'improving' | 'regressing' | 'stable'
48
+ summary: string
49
+ trust_delta?: number
50
+ previous_trust_score?: number
51
+ previous_merge_risk?: MergeRiskLevel
52
+ snapshot_score_delta?: number
53
+ snapshot_label?: string
54
+ snapshot_timestamp?: string
55
+ }
56
+
57
+ export interface TrustAdvancedContext {
58
+ comparison?: TrustAdvancedComparison
59
+ team_guidance: string[]
60
+ }
61
+
62
+ export interface TrustDiffContext {
63
+ baseRef: string
64
+ status: 'improved' | 'regressed' | 'neutral'
65
+ scoreDelta: number
66
+ newIssues: number
67
+ resolvedIssues: number
68
+ filesChanged: number
69
+ penalty: number
70
+ bonus: number
71
+ netImpact: number
72
+ }
73
+
74
+ export interface DriftTrustReport {
75
+ scannedAt: string
76
+ targetPath: string
77
+ trust_score: number
78
+ merge_risk: MergeRiskLevel
79
+ top_reasons: TrustReason[]
80
+ fix_priorities: TrustFixPriority[]
81
+ diff_context?: TrustDiffContext
82
+ advanced_context?: TrustAdvancedContext
83
+ }
84
+
85
+ export type DriftTrustReportJson = DriftTrustReport & DriftOutputMetadata
86
+
87
+ export interface TrustKpiDiagnostic {
88
+ level: 'warning' | 'error'
89
+ code: 'path-not-found' | 'path-not-supported' | 'read-failed' | 'parse-failed' | 'invalid-shape' | 'invalid-diff-context'
90
+ message: string
91
+ file?: string
92
+ }
93
+
94
+ export interface TrustScoreStats {
95
+ average: number | null
96
+ median: number | null
97
+ min: number | null
98
+ max: number | null
99
+ }
100
+
101
+ export interface TrustDiffTrendSummary {
102
+ available: boolean
103
+ samples: number
104
+ statusDistribution: {
105
+ improved: number
106
+ regressed: number
107
+ neutral: number
108
+ }
109
+ scoreDelta: {
110
+ average: number | null
111
+ median: number | null
112
+ }
113
+ issues: {
114
+ newTotal: number
115
+ resolvedTotal: number
116
+ netNew: number
117
+ }
118
+ }
119
+
120
+ export interface TrustKpiReport {
121
+ generatedAt: string
122
+ input: string
123
+ files: {
124
+ matched: number
125
+ parsed: number
126
+ malformed: number
127
+ }
128
+ prsEvaluated: number
129
+ mergeRiskDistribution: Record<MergeRiskLevel, number>
130
+ trustScore: TrustScoreStats
131
+ highRiskRatio: number | null
132
+ diffTrend: TrustDiffTrendSummary
133
+ diagnostics: TrustKpiDiagnostic[]
134
+ }