@eduardbar/drift 1.3.0 → 1.5.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 (198) hide show
  1. package/.gga +50 -0
  2. package/.github/actions/drift-review/README.md +62 -0
  3. package/.github/actions/drift-review/action.yml +148 -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/publish-vscode.yml +1 -3
  7. package/.github/workflows/publish.yml +8 -0
  8. package/.github/workflows/quality.yml +15 -0
  9. package/.github/workflows/reusable-quality-checks.yml +95 -0
  10. package/.github/workflows/review-pr.yml +33 -41
  11. package/AGENTS.md +75 -251
  12. package/CHANGELOG.md +41 -0
  13. package/README.md +177 -43
  14. package/benchmarks/fixtures/critical/drift.config.ts +21 -0
  15. package/benchmarks/fixtures/critical/src/app/user-service.ts +30 -0
  16. package/benchmarks/fixtures/critical/src/domain/entities.ts +19 -0
  17. package/benchmarks/fixtures/critical/src/domain/policies.ts +22 -0
  18. package/benchmarks/fixtures/critical/src/index.ts +10 -0
  19. package/benchmarks/fixtures/critical/src/infra/memory-user-repo.ts +14 -0
  20. package/benchmarks/perf-budget.v1.json +27 -0
  21. package/dist/benchmark.d.ts +1 -1
  22. package/dist/benchmark.js +83 -52
  23. package/dist/cli.js +243 -8
  24. package/dist/config.js +16 -2
  25. package/dist/diff.js +42 -50
  26. package/dist/doctor.d.ts +26 -0
  27. package/dist/doctor.js +140 -0
  28. package/dist/format.d.ts +17 -0
  29. package/dist/format.js +45 -0
  30. package/dist/guard-baseline.d.ts +12 -0
  31. package/dist/guard-baseline.js +57 -0
  32. package/dist/guard-metrics.d.ts +6 -0
  33. package/dist/guard-metrics.js +39 -0
  34. package/dist/guard-types.d.ts +58 -0
  35. package/dist/guard-types.js +2 -0
  36. package/dist/guard.d.ts +16 -0
  37. package/dist/guard.js +178 -0
  38. package/dist/index.d.ts +10 -3
  39. package/dist/index.js +4 -1
  40. package/dist/init.d.ts +15 -0
  41. package/dist/init.js +273 -0
  42. package/dist/map-cycles.d.ts +2 -0
  43. package/dist/map-cycles.js +34 -0
  44. package/dist/map-svg.d.ts +19 -0
  45. package/dist/map-svg.js +97 -0
  46. package/dist/map.js +78 -138
  47. package/dist/metrics.js +70 -55
  48. package/dist/output-metadata.d.ts +15 -0
  49. package/dist/output-metadata.js +19 -0
  50. package/dist/plugins-capabilities.d.ts +4 -0
  51. package/dist/plugins-capabilities.js +21 -0
  52. package/dist/plugins-messages.d.ts +10 -0
  53. package/dist/plugins-messages.js +16 -0
  54. package/dist/plugins-rules.d.ts +9 -0
  55. package/dist/plugins-rules.js +137 -0
  56. package/dist/plugins.d.ts +1 -1
  57. package/dist/plugins.js +45 -142
  58. package/dist/reporter-constants.d.ts +16 -0
  59. package/dist/reporter-constants.js +39 -0
  60. package/dist/reporter.d.ts +3 -3
  61. package/dist/reporter.js +35 -55
  62. package/dist/review.d.ts +2 -1
  63. package/dist/review.js +2 -1
  64. package/dist/rules/phase3-configurable.js +23 -15
  65. package/dist/saas/constants.d.ts +15 -0
  66. package/dist/saas/constants.js +48 -0
  67. package/dist/saas/dashboard.d.ts +8 -0
  68. package/dist/saas/dashboard.js +132 -0
  69. package/dist/saas/errors.d.ts +19 -0
  70. package/dist/saas/errors.js +37 -0
  71. package/dist/saas/helpers.d.ts +21 -0
  72. package/dist/saas/helpers.js +110 -0
  73. package/dist/saas/ingest.d.ts +3 -0
  74. package/dist/saas/ingest.js +249 -0
  75. package/dist/saas/organization.d.ts +5 -0
  76. package/dist/saas/organization.js +82 -0
  77. package/dist/saas/plan-change.d.ts +10 -0
  78. package/dist/saas/plan-change.js +15 -0
  79. package/dist/saas/store.d.ts +21 -0
  80. package/dist/saas/store.js +159 -0
  81. package/dist/saas/types.d.ts +191 -0
  82. package/dist/saas/types.js +2 -0
  83. package/dist/saas.d.ts +8 -218
  84. package/dist/saas.js +7 -761
  85. package/dist/sarif.d.ts +74 -0
  86. package/dist/sarif.js +122 -0
  87. package/dist/trust-advanced.d.ts +14 -0
  88. package/dist/trust-advanced.js +65 -0
  89. package/dist/trust-kpi-fs.d.ts +3 -0
  90. package/dist/trust-kpi-fs.js +141 -0
  91. package/dist/trust-kpi-parse.d.ts +7 -0
  92. package/dist/trust-kpi-parse.js +186 -0
  93. package/dist/trust-kpi-types.d.ts +16 -0
  94. package/dist/trust-kpi-types.js +2 -0
  95. package/dist/trust-kpi.d.ts +1 -3
  96. package/dist/trust-kpi.js +6 -266
  97. package/dist/trust-policy.d.ts +32 -0
  98. package/dist/trust-policy.js +160 -0
  99. package/dist/trust-render.d.ts +9 -0
  100. package/dist/trust-render.js +54 -0
  101. package/dist/trust-scoring.d.ts +9 -0
  102. package/dist/trust-scoring.js +208 -0
  103. package/dist/trust.d.ts +5 -32
  104. package/dist/trust.js +29 -432
  105. package/dist/types/app.d.ts +30 -0
  106. package/dist/types/app.js +2 -0
  107. package/dist/types/config.d.ts +25 -0
  108. package/dist/types/config.js +2 -0
  109. package/dist/types/core.d.ts +100 -0
  110. package/dist/types/core.js +2 -0
  111. package/dist/types/diff.d.ts +55 -0
  112. package/dist/types/diff.js +2 -0
  113. package/dist/types/plugin.d.ts +41 -0
  114. package/dist/types/plugin.js +2 -0
  115. package/dist/types/trust.d.ts +120 -0
  116. package/dist/types/trust.js +2 -0
  117. package/dist/types.d.ts +8 -365
  118. package/docs/AGENTS.md +1 -1
  119. package/docs/release-notes-draft.md +40 -0
  120. package/docs/rules-catalog.md +49 -0
  121. package/docs/trust-core-release-checklist.md +37 -5
  122. package/package.json +11 -4
  123. package/packages/vscode-drift/src/code-actions.ts +1 -1
  124. package/schemas/drift-ai-output.v1.json +162 -0
  125. package/schemas/drift-doctor.v1.json +57 -0
  126. package/schemas/drift-guard.v1.json +298 -0
  127. package/schemas/drift-report.v1.json +151 -0
  128. package/schemas/drift-trust.v1.json +131 -0
  129. package/scripts/check-docs-drift.mjs +154 -0
  130. package/scripts/check-performance-budget.mjs +360 -0
  131. package/scripts/check-runtime-policy.mjs +66 -0
  132. package/scripts/smoke-repo.mjs +394 -0
  133. package/src/benchmark.ts +92 -53
  134. package/src/cli.ts +285 -13
  135. package/src/config.ts +19 -2
  136. package/src/diff.ts +57 -48
  137. package/src/doctor.ts +185 -0
  138. package/src/format.ts +81 -0
  139. package/src/guard-baseline.ts +74 -0
  140. package/src/guard-metrics.ts +52 -0
  141. package/src/guard-types.ts +66 -0
  142. package/src/guard.ts +248 -0
  143. package/src/index.ts +36 -0
  144. package/src/init.ts +298 -0
  145. package/src/map-cycles.ts +38 -0
  146. package/src/map-svg.ts +124 -0
  147. package/src/map.ts +111 -142
  148. package/src/metrics.ts +78 -59
  149. package/src/output-metadata.ts +32 -0
  150. package/src/plugins-capabilities.ts +36 -0
  151. package/src/plugins-messages.ts +35 -0
  152. package/src/plugins-rules.ts +296 -0
  153. package/src/plugins.ts +76 -283
  154. package/src/reporter-constants.ts +46 -0
  155. package/src/reporter.ts +64 -65
  156. package/src/review.ts +4 -2
  157. package/src/rules/phase3-configurable.ts +39 -26
  158. package/src/saas/constants.ts +56 -0
  159. package/src/saas/dashboard.ts +172 -0
  160. package/src/saas/errors.ts +45 -0
  161. package/src/saas/helpers.ts +140 -0
  162. package/src/saas/ingest.ts +278 -0
  163. package/src/saas/organization.ts +99 -0
  164. package/src/saas/plan-change.ts +19 -0
  165. package/src/saas/store.ts +172 -0
  166. package/src/saas/types.ts +216 -0
  167. package/src/saas.ts +49 -1031
  168. package/src/sarif.ts +232 -0
  169. package/src/trust-advanced.ts +99 -0
  170. package/src/trust-kpi-fs.ts +169 -0
  171. package/src/trust-kpi-parse.ts +219 -0
  172. package/src/trust-kpi-types.ts +19 -0
  173. package/src/trust-kpi.ts +8 -316
  174. package/src/trust-policy.ts +246 -0
  175. package/src/trust-render.ts +61 -0
  176. package/src/trust-scoring.ts +231 -0
  177. package/src/trust.ts +62 -576
  178. package/src/types/app.ts +30 -0
  179. package/src/types/config.ts +27 -0
  180. package/src/types/core.ts +105 -0
  181. package/src/types/diff.ts +61 -0
  182. package/src/types/plugin.ts +46 -0
  183. package/src/types/trust.ts +134 -0
  184. package/src/types.ts +79 -409
  185. package/tests/ci-quality-matrix.test.ts +37 -0
  186. package/tests/ci-smoke-gate.test.ts +26 -0
  187. package/tests/ci-version-alignment.test.ts +93 -0
  188. package/tests/cli-sarif.test.ts +92 -0
  189. package/tests/docs-drift-check.test.ts +115 -0
  190. package/tests/format.test.ts +157 -0
  191. package/tests/new-features.test.ts +11 -3
  192. package/tests/perf-budget-check.test.ts +146 -0
  193. package/tests/phase1-init-doctor-guard.test.ts +301 -0
  194. package/tests/runtime-policy-alignment.test.ts +46 -0
  195. package/tests/sarif.test.ts +160 -0
  196. package/tests/trust-kpi.test.ts +31 -4
  197. package/tests/trust.test.ts +18 -0
  198. package/vitest.config.ts +2 -0
@@ -7,6 +7,7 @@ on:
7
7
  permissions:
8
8
  contents: read
9
9
  pull-requests: write
10
+ security-events: write
10
11
 
11
12
  jobs:
12
13
  drift-review:
@@ -26,50 +27,33 @@ jobs:
26
27
  - name: Install dependencies
27
28
  run: npm ci
28
29
 
29
- # Run directly from TypeScript source in this PR to avoid stale dist artifacts.
30
- - name: Generate drift review markdown
31
- run: npx --no-install tsx ./src/cli.ts review --base "origin/${{ github.base_ref }}" --comment > drift-review.md
30
+ - name: Generate drift trust/review artifacts and gate
31
+ id: drift_review
32
+ uses: ./.github/actions/drift-review
33
+ with:
34
+ path: .
35
+ base-ref: origin/${{ github.base_ref }}
36
+ min-trust: 45
37
+ max-risk: HIGH
38
+ fail-on-gate: true
39
+ include-review: true
32
40
 
33
- - name: Generate drift trust markdown
34
- run: npx --no-install tsx ./src/cli.ts trust . --base "origin/${{ github.base_ref }}" --markdown --json-output drift-trust.json > drift-trust.md
35
-
36
- - name: Extract trust KPI values
37
- id: trust_kpi
38
- run: |
39
- node --input-type=module -e "
40
- import fs from 'node:fs'
41
- const payload = JSON.parse(fs.readFileSync('drift-trust.json', 'utf8'))
42
- const score = payload.trust_score ?? 'n/a'
43
- const risk = payload.merge_risk ?? 'n/a'
44
- const diff = payload.diff_context ?? {}
45
- const newIssues = diff.newIssues ?? 'n/a'
46
- const resolvedIssues = diff.resolvedIssues ?? 'n/a'
47
- fs.appendFileSync(process.env.GITHUB_OUTPUT, [
48
- 'trust_score=' + score,
49
- 'merge_risk=' + risk,
50
- 'new_issues=' + newIssues,
51
- 'resolved_issues=' + resolvedIssues,
52
- ].join('\\n') + '\\n')
53
- "
41
+ - name: Generate drift SARIF
42
+ run: npx --no-install tsx ./src/cli.ts scan . --format sarif > drift.sarif
54
43
 
55
44
  - name: Publish trust KPI step summary
56
45
  run: |
57
46
  {
58
47
  echo "## drift trust KPI"
59
48
  echo
60
- echo "- Trust score: **${{ steps.trust_kpi.outputs.trust_score }}**"
61
- echo "- Merge risk: **${{ steps.trust_kpi.outputs.merge_risk }}**"
62
- echo "- New issues vs base: **${{ steps.trust_kpi.outputs.new_issues }}**"
63
- echo "- Resolved issues vs base: **${{ steps.trust_kpi.outputs.resolved_issues }}**"
49
+ echo "- Trust score: **${{ steps.drift_review.outputs.trust-score }}**"
50
+ echo "- Merge risk: **${{ steps.drift_review.outputs.merge-risk }}**"
51
+ echo "- New issues vs base: **${{ steps.drift_review.outputs.new-issues }}**"
52
+ echo "- Resolved issues vs base: **${{ steps.drift_review.outputs.resolved-issues }}**"
64
53
  } >> "$GITHUB_STEP_SUMMARY"
65
54
 
66
- - name: Validate trust gate from generated JSON
67
- run: |
68
- set -euo pipefail
69
- npx --no-install tsx ./src/cli.ts trust-gate drift-trust.json --min-trust 40 --max-risk HIGH | tee drift-trust-gate.txt
70
-
71
55
  - name: Aggregate trust KPI from trust JSON artifact
72
- run: npx --no-install tsx ./src/cli.ts kpi drift-trust.json --no-summary > drift-trust-kpi.json
56
+ run: npx --no-install tsx ./src/cli.ts kpi "${{ steps.drift_review.outputs.trust-json }}" --no-summary > drift-trust-kpi.json
73
57
 
74
58
  - name: Extract aggregated KPI values
75
59
  id: trust_kpi_aggregate
@@ -107,12 +91,20 @@ jobs:
107
91
  with:
108
92
  name: drift-trust-json-pr-${{ github.event.pull_request.number }}-run-${{ github.run_attempt }}
109
93
  path: |
110
- drift-trust.json
111
- drift-trust-gate.txt
94
+ ${{ steps.drift_review.outputs.trust-json }}
95
+ ${{ steps.drift_review.outputs.trust-markdown }}
96
+ ${{ steps.drift_review.outputs.review-markdown }}
112
97
  drift-trust-kpi.json
98
+ drift.sarif
113
99
  if-no-files-found: error
114
100
  retention-days: 14
115
101
 
102
+ - name: Upload SARIF to GitHub Code Scanning (non-fork only)
103
+ if: github.event.pull_request.head.repo.fork == false
104
+ uses: github/codeql-action/upload-sarif@v3
105
+ with:
106
+ sarif_file: drift.sarif
107
+
116
108
  - name: Post or update PR comment (non-fork only)
117
109
  if: github.event.pull_request.head.repo.fork == false
118
110
  env:
@@ -123,12 +115,12 @@ jobs:
123
115
  COMMENT_BODY="<!-- drift-review -->"
124
116
  COMMENT_BODY+=$'\n'
125
117
  COMMENT_BODY+="## drift trust"$'\n\n'
126
- COMMENT_BODY+="$(cat drift-trust.md)"
118
+ COMMENT_BODY+="$(cat "${{ steps.drift_review.outputs.trust-markdown }}")"
127
119
  COMMENT_BODY+=$'\n\n'
128
120
  COMMENT_BODY+="## drift review"$'\n\n'
129
- COMMENT_BODY+="$(cat drift-review.md)"
121
+ COMMENT_BODY+="$(cat "${{ steps.drift_review.outputs.review-markdown }}")"
130
122
  COMMENT_BODY+=$'\n\n'
131
- COMMENT_BODY+="<!-- drift-trust-kpi score=${{ steps.trust_kpi.outputs.trust_score }} risk=${{ steps.trust_kpi.outputs.merge_risk }} new=${{ steps.trust_kpi.outputs.new_issues }} resolved=${{ steps.trust_kpi.outputs.resolved_issues }} -->"
123
+ COMMENT_BODY+="<!-- drift-trust-kpi score=${{ steps.drift_review.outputs.trust-score }} risk=${{ steps.drift_review.outputs.merge-risk }} new=${{ steps.drift_review.outputs.new-issues }} resolved=${{ steps.drift_review.outputs.resolved-issues }} -->"
132
124
 
133
125
  EXISTING_ID=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" --jq '.[] | select(.user.login == "github-actions[bot]") | select(.body | contains("<!-- drift-review -->")) | .id' | sed -n '1p')
134
126
 
@@ -144,10 +136,10 @@ jobs:
144
136
  {
145
137
  echo "## drift trust"
146
138
  echo
147
- cat drift-trust.md
139
+ cat "${{ steps.drift_review.outputs.trust-markdown }}"
148
140
  echo
149
141
  echo "## drift review"
150
142
  echo
151
- cat drift-review.md
143
+ cat "${{ steps.drift_review.outputs.review-markdown }}"
152
144
  } >> "$GITHUB_STEP_SUMMARY"
153
145
 
package/AGENTS.md CHANGED
@@ -2,294 +2,118 @@
2
2
 
3
3
  ## Qué es drift
4
4
 
5
- `@eduardbar/drift` es un CLI TypeScript que escanea proyectos TypeScript con análisis AST (ts-morph) y asigna un score de 0 a 100 a cada archivo según la cantidad de deuda técnica AI-generada que contiene.
5
+ `@eduardbar/drift` es un CLI de auditoría estática para repos TypeScript/JavaScript orientado a deuda estructural y confianza de merge en PRs asistidas por AI.
6
6
 
7
- - **0** = código limpio
8
- - **100** = reescribí esto antes de que alguien lo vea
9
-
10
- Publicado en npm como `@eduardbar/drift`. MIT.
7
+ - Publicado en npm como `@eduardbar/drift`
8
+ - Licencia MIT
9
+ - Versión del paquete: `1.5.0` (`package.json`)
11
10
 
12
11
  ---
13
12
 
14
- ## Stack técnico
13
+ ## Stack y runtime
15
14
 
16
15
  | Dep | Rol |
17
16
  |-----|-----|
18
- | `ts-morph ^27` | Motor AST — traversal de nodos TypeScript |
19
- | `commander ^14` | CLI flags y subcomandos |
20
- | `kleur ^4` | Colores en consola (sin dependencias) |
21
- | `typescript ^5.9` | Dev — compilación |
22
- | `@types/node ^25` | Dev — tipos Node.js |
23
- | `vitest ^4` | Testing |
24
-
25
- **Runtime:** Node.js 18+, ES Modules (`"type": "module"`).
26
-
27
- ---
28
-
29
- ## Estructura del proyecto
30
-
31
- ```
32
- drift/
33
- ├── bin/
34
- │ └── drift.js ← wrapper cross-platform (Windows npx fix)
35
- ├── src/
36
- │ ├── analyzer.ts ← motor AST + 26 reglas + drift-ignore
37
- │ ├── types.ts ← interfaces: DriftIssue, FileReport, DriftReport, AIOutput
38
- │ ├── reporter.ts ← buildReport(), formatMarkdown(), formatAIOutput()
39
- │ ├── printer.ts ← salida consola con colores y score bar ASCII
40
- │ ├── utils.ts ← scoreToGrade, severityIcon, scoreBar
41
- │ ├── index.ts ← re-exports públicos (librería)
42
- │ ├── cli.ts ← entry point Commander.js
43
- │ ├── config.ts ← drift.config.ts support
44
- │ ├── fix.ts ← drift fix command
45
- │ ├── ci.ts ← drift ci command
46
- │ ├── diff.ts ← drift diff command
47
- │ ├── report.ts ← drift report command
48
- │ ├── badge.ts ← drift badge command
49
- │ ├── snapshot.ts ← drift snapshot command
50
- │ ├── git.ts ← re-exports git analyzers
51
- │ ├── git/
52
- │ │ ├── trend.ts ← drift trend (historial de scores)
53
- │ │ ├── blame.ts ← drift blame (atribución de deuda)
54
- │ │ └── helpers.ts
55
- │ └── rules/ ← reglas modularizadas por fase
56
- │ ├── phase0-basic.ts
57
- │ ├── phase1-complexity.ts
58
- │ ├── phase2-crossfile.ts ← dead-file, unused-export, unused-dependency
59
- │ ├── phase3-arch.ts ← circular-dependency, layer-violation
60
- │ ├── phase5-ai.ts
61
- │ ├── phase8-semantic.ts ← semantic-duplication
62
- │ ├── complexity.ts
63
- │ ├── coupling.ts
64
- │ ├── nesting.ts
65
- │ ├── promise.ts
66
- │ ├── magic.ts
67
- │ ├── comments.ts
68
- │ └── shared.ts
69
- ├── packages/
70
- │ ├── eslint-plugin-drift/ ← ESLint plugin oficial
71
- │ └── vscode-drift/ ← VS Code extension
72
- ├── dist/ ← output tsc (no editar a mano)
73
- ├── assets/
74
- │ ├── og.svg / og.png
75
- │ ├── og-v030-linkedin.svg/png
76
- │ └── og-v030-x.svg/png
77
- ├── .github/workflows/publish.yml
78
- ├── package.json
79
- ├── tsconfig.json
80
- └── AGENTS.md ← este archivo
81
- ```
82
-
83
- ---
84
-
85
- ## Comandos de desarrollo
86
-
87
- ```bash
88
- npm run build # tsc — compila src/ → dist/
89
- npm run dev # tsc --watch
90
- npm start # node dist/cli.js (desarrollo local)
91
- npm test # vitest run
92
- npm run test:watch # vitest (watch mode)
93
- ```
94
-
95
- **Pre-publicación:** `prepublishOnly` corre `build` automáticamente.
96
-
97
- ---
17
+ | `ts-morph ^27` | análisis AST |
18
+ | `commander ^14` | CLI y flags |
19
+ | `kleur ^4` | salida con color |
20
+ | `typescript ^5.9` | compilación |
21
+ | `vitest ^4` | testing |
98
22
 
99
- ## CLI flags disponibles
100
-
101
- | Flag | Tipo | Descripción |
102
- |------|------|-------------|
103
- | `scan <path>` | positional | Ruta a escanear (requerido) |
104
- | `--output <file>` / `-o` | string | Escribe reporte Markdown a archivo |
105
- | `--json` | boolean | Imprime `DriftReport` crudo como JSON |
106
- | `--ai` | boolean | JSON optimizado para LLMs (`AIOutput`) |
107
- | `--fix` | boolean | Muestra sugerencias de fix en consola |
108
- | `--min-score <n>` | number | Exit code 1 si score supera umbral (CI) |
109
- | `--low-memory` | boolean | Activa análisis por chunks para bajar el pico de RAM |
110
- | `--chunk-size <n>` | number | Cantidad de archivos por chunk en low-memory mode |
111
- | `--max-files <n>` | number | Límite blando de archivos analizados (el resto se reporta como skip) |
112
- | `--max-file-size-kb <n>` | number | Saltea archivos grandes y agrega diagnóstico de skip |
113
- | `--with-semantic-duplication` | boolean | Rehabilita semantic-duplication en low-memory mode |
114
-
115
- **Uso básico:**
116
- ```bash
117
- npx @eduardbar/drift scan .
118
- npx @eduardbar/drift scan ./src --min-score 60
119
- npx @eduardbar/drift scan ./src --ai | pbcopy # pegar en Claude/GPT
120
- npx @eduardbar/drift scan ./src --fix # ver sugerencias inline
121
- npx @eduardbar/drift scan ./src -o report.md # exportar Markdown
122
- npx @eduardbar/drift scan ./src --low-memory --max-file-size-kb 1024
123
- ```
23
+ Runtime: Node.js 20.x and 22.x (LTS), ES Modules (`"type": "module"`).
124
24
 
125
25
  ---
126
26
 
127
- ## Reglas del analyzer
128
-
129
- | Regla | Severidad | Peso |
130
- |-------|-----------|------|
131
- | `large-file` | error | 20 |
132
- | `large-function` | error | 15 |
133
- | `duplicate-function-name` | error | 18 |
134
- | `high-complexity` | error | 15 |
135
- | `circular-dependency` | error | 14 |
136
- | `layer-violation` | error | 16 |
137
- | `comment-contradiction` | warning | 12 |
138
- | `deep-nesting` | warning | 12 |
139
- | `semantic-duplication` | warning | 12 |
140
- | `debug-leftover` | warning | 10 |
141
- | `catch-swallow` | warning | 10 |
142
- | `high-coupling` | warning | 10 |
143
- | `dead-file` | warning | 10 |
144
- | `hardcoded-config` | warning | 10 |
145
- | `cross-boundary-import` | warning | 10 |
146
- | `dead-code` | warning | 8 |
147
- | `any-abuse` | warning | 8 |
148
- | `too-many-params` | warning | 8 |
149
- | `unused-export` | warning | 8 |
150
- | `inconsistent-error-handling` | warning | 8 |
151
- | `promise-style-mix` | warning | 7 |
152
- | `unnecessary-abstraction` | warning | 7 |
153
- | `naming-inconsistency` | warning | 6 |
154
- | `unused-dependency` | warning | 6 |
155
- | `no-return-type` | info | 5 |
156
- | `over-commented` | info | 4 |
157
- | `magic-number` | info | 3 |
158
-
159
- **Score = suma de pesos capped a 100. Score del proyecto = promedio de archivos.**
27
+ ## Comandos CLI actuales
28
+
29
+ Comandos top-level definidos en `src/cli.ts`:
30
+
31
+ - `scan [path]`
32
+ - `init`
33
+ - `diff [ref]`
34
+ - `guard [path]`
35
+ - `benchmark`
36
+ - `review`
37
+ - `trust [path]`
38
+ - `trust-gate <trustJsonFile>`
39
+ - `doctor`
40
+ - `kpi <path>`
41
+ - `map [path]`
42
+ - `report [path]`
43
+ - `badge [path]`
44
+ - `ci [path]`
45
+ - `trend [period]`
46
+ - `blame [target]`
47
+ - `fix [path]`
48
+ - `snapshot [path]`
49
+ - `cloud` (con subcomandos: `ingest`, `summary`, `plan-set`, `plan-changes`, `usage`, `dashboard`)
160
50
 
161
51
  ---
162
52
 
163
- ## drift-ignore
53
+ ## Reglas y scoring (estado real)
164
54
 
165
- **Por línea** (`// drift-ignore`):
166
- - Suprime el issue en la línea actual o en la línea inmediatamente superior al problema.
167
- - Funciona para cualquier regla.
55
+ - La fuente de verdad de reglas/pesos/severidad es `RULE_WEIGHTS` en `src/analyzer.ts`.
56
+ - Estado actual: **35 rule IDs** (incluye reglas de detección, reglas configurables, meta-reglas y diagnósticos de plugins/guardrails de análisis).
57
+ - Score por archivo: suma de pesos cap a 100.
58
+ - Score de proyecto: promedio de scores por archivo.
168
59
 
169
- **Por archivo** (`// drift-ignore-file`):
170
- - Se coloca en las primeras 10 líneas del archivo.
171
- - `analyzeFile()` devuelve reporte vacío (score 0, cero issues) para ese archivo.
172
- - Usar en archivos con `console.log` intencional (ej: `printer.ts`).
60
+ Catálogo completo actualizado en `docs/rules-catalog.md`.
173
61
 
174
62
  ---
175
63
 
176
- ## Formato `--ai` (`AIOutput`)
177
-
178
- ```typescript
179
- interface AIOutput {
180
- summary: {
181
- score: number
182
- grade: string // "CLEAN" | "LOW" | "MEDIUM" | "HIGH" | "CRITICAL"
183
- total_issues: number
184
- files_affected: number
185
- files_clean: number
186
- }
187
- priority_order: Array<{
188
- rank: number
189
- file: string
190
- line: number
191
- rule: string
192
- severity: "error" | "warning" | "info"
193
- message: string
194
- snippet: string
195
- fix_suggestion: string
196
- effort: "low" | "medium" | "high"
197
- }>
198
- context_for_ai: {
199
- project_type: "typescript"
200
- scan_path: string
201
- rules_detected: string[]
202
- recommended_action: string
203
- }
204
- }
205
- ```
206
-
207
- Los issues se ordenan: error > warning > info, luego low effort primero (quick wins).
64
+ ## Configuración soportada (`drift.config.*`)
208
65
 
209
- ---
66
+ `DriftConfig` actual (ver `src/types/app.ts`):
210
67
 
211
- ## Formato `--fix` en consola
68
+ - `layers`: capas para `layer-violation`
69
+ - `modules`: boundaries para `cross-boundary-import`
70
+ - `moduleBoundaries` / `boundaries`: alias legacy normalizados a `modules`
71
+ - `plugins`: plugins drift
72
+ - `performance`: `lowMemory`, `chunkSize`, `maxFiles`, `maxFileSizeKb`, `includeSemanticDuplication`
73
+ - `architectureRules`: `controllerNoDb`, `serviceNoHttp`, `maxFunctionLines`
74
+ - `saas`: límites/política local multi-tenant (`strictActorEnforcement` incluido)
75
+ - `trustGate`: políticas de gating para `trust` / `trust-gate`
212
76
 
213
- ```
214
- ┌──────────────────────────────────────────────────────┐
215
- │ - console.log(userData)
216
- │ + Remove this console.log statement
217
- │ + Or replace with a proper logging library
218
- └──────────────────────────────────────────────────────┘
219
- ```
77
+ Notas:
220
78
 
221
- Las sugerencias por regla están hardcodeadas en `src/printer.ts`.
79
+ - Sin config, reglas puramente configurables/arquitectónicas se omiten.
80
+ - `exclude` y overrides tipo `rules: { ... }` **no** forman parte del contrato tipado actual de `DriftConfig`.
222
81
 
223
82
  ---
224
83
 
225
- ## CI/CD GitHub Actions
226
-
227
- Workflow en `.github/workflows/publish.yml`:
228
- - **Trigger único:** `release: published` (evita doble publish)
229
- - **Fallback manual:** `workflow_dispatch` con input `tag`
230
- - **Guard:** verifica `npm view @eduardbar/drift@$VERSION` antes de publicar
231
-
232
- **Integración CI en proyectos externos:**
233
- ```yaml
234
- - name: Check drift score
235
- run: npx @eduardbar/drift scan ./src --min-score 60
236
- ```
237
-
238
- ---
239
-
240
- ## Compatibilidad Windows
241
-
242
- `bin/drift.js` es el wrapper cross-platform:
243
- ```javascript
244
- #!/usr/bin/env node
245
- import('../dist/cli.js')
246
- ```
247
-
248
- `package.json` apunta `bin.drift` a `bin/drift.js`, **no** a `dist/cli.js`.
249
- Sin esto, Windows no ejecuta el shebang correctamente con ES modules.
250
-
251
- ---
84
+ ## Flags transversales de recursos
252
85
 
253
- ## Versiones
86
+ `scan`, `diff`, `guard`, `trust`, `report`, `badge`, `ci`, `snapshot` comparten:
254
87
 
255
- | Versión | Cambios principales |
256
- |---------|---------------------|
257
- | **1.0.0** | 26 reglas, 131 tests, modular rules, JS/JSX, drift fix/report/diff/ci/badge/trend/blame, VS Code extension |
258
- | **0.3.0** | `--ai` (LLM-optimized JSON output) + `--fix` (inline suggestions) |
259
- | **0.2.3** | Fix: bin wrapper para compatibilidad Windows npx |
260
- | **0.2.2** | Refactor: `formatMarkdown` dividido en helpers + fix CI doble publish |
261
- | **0.2.1** | `drift-ignore` por línea y por archivo + fix console output propio |
262
- | **0.2.0** | Score bar ASCII + header hierarchy + DRY utils + file count en CLI |
263
- | **0.1.x** | Bootstrap: tipos, analyzer (10 reglas), reporter, printer, CLI, CI/CD |
88
+ - `--low-memory`
89
+ - `--chunk-size <n>`
90
+ - `--max-files <n>`
91
+ - `--max-file-size-kb <n>`
92
+ - `--with-semantic-duplication`
264
93
 
265
94
  ---
266
95
 
267
- ## Estado actual (feb 2026)
96
+ ## Comandos incorporados recientes (operativos)
268
97
 
269
- - **Versión publicada:** `1.0.0`
270
- - **Branch:** `master`, sincronizado con `origin`
271
- - **Self-scan score:** 5/100 (LOW)
272
- - **Top issues:** 51× magic-number, 2× deep-nesting, 2× catch-swallow
273
- - **26 reglas activas** organizadas en fases
98
+ - `init`: scaffolding de `drift.config.ts`, workflow CI y baseline (`drift-baseline.json`)
99
+ - `doctor`: diagnóstico de entorno/proyecto (`--json` opcional)
100
+ - `guard`: evaluación de regresión por diff (`--base`) o baseline (`--baseline`) con `--budget` y `--by-severity`
274
101
 
275
102
  ---
276
103
 
277
- ## Convenciones de código
104
+ ## Convenciones de contribución (rápidas)
278
105
 
279
- - Todo en TypeScript sin `any` explícito (drift se corre sobre sí mismo)
280
- - ES Modules `import/export`, sin CommonJS
281
- - Conventional Commits obligatorios (ver AGENTS.md global)
282
- - `// drift-ignore-file` en `printer.ts` — sus `console.log` son output intencional
283
- - `scoreToGrade`, `severityIcon`, `scoreBar` viven en `utils.ts` — no duplicar
284
- - Nuevas reglas: agregar entrada en `RULE_WEIGHTS` en `analyzer.ts` + lógica de detección AST
106
+ - Evitar drift real en el propio repo (drift se corre sobre sí mismo).
107
+ - Mantener README + AGENTS + catálogo de reglas sincronizados cuando cambian reglas/CLI.
108
+ - Usar Conventional Commits.
285
109
 
286
110
  ---
287
111
 
288
- ## Agregar una nueva regla — checklist
112
+ ## Archivos clave
289
113
 
290
- 1. Agregar `"rule-name": <peso>` a `RULE_WEIGHTS` en `src/analyzer.ts`
291
- 2. Implementar la lógica de detección AST usando ts-morph en `analyzeFile()`
292
- 3. Agregar `fix_suggestion` para la regla en `src/printer.ts` (objeto de sugerencias por regla)
293
- 4. Actualizar `README.md` — tabla de reglas
294
- 5. Actualizar este `AGENTS.md` — tabla de reglas
295
- 6. Commit: `feat(analyzer): add <rule-name> rule`
114
+ - `src/cli.ts` — contrato de comandos y flags
115
+ - `src/analyzer.ts` orquestación de análisis + `RULE_WEIGHTS`
116
+ - `src/rules/*.ts` detecciones por fase
117
+ - `src/config.ts` y `src/types/*.ts` — contrato de configuración
118
+ - `README.md` — documentación de uso pública
119
+ - `docs/rules-catalog.md` inventario completo de reglas
package/CHANGELOG.md CHANGED
@@ -20,6 +20,47 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
20
20
 
21
21
  ---
22
22
 
23
+ ## [1.5.0] - 2026-03-26
24
+
25
+ ### Changed
26
+
27
+ - CI drift version policy now uses `package.json` as source of truth, aligns action defaults/docs to `1.5.0`, and adds a test guard that fails if action/workflow references drift semver values that diverge.
28
+ - Reusable quality checks now include a required CLI smoke E2E gate (`npm run smoke:repo`) for merge/release verification and upload smoke artifacts (`.drift-smoke/...`) for CI failure triage.
29
+ - Runtime support policy is now enforced as Node.js `20.x` and `22.x` (LTS): `package.json` now declares `engines.node`, CI matrix moved to `20/22`, and docs/doctor output were aligned to avoid advertising unsupported Node versions.
30
+ - Added runtime policy gate (`npm run check:runtime-policy`) in required CI checks to fail fast when `engines.node`, workflow matrix, README runtime line, or lockfile dependency constraints diverge.
31
+ - Tradeoff: dropped Node 18 from required support because `commander@14` (runtime dependency) requires Node `>=20`; preserving `18/20/22` would create false support claims and non-deterministic install/runtime behavior.
32
+ - `drift doctor --json` and `drift guard --json` now emit schema metadata (`$schema`, `toolVersion`) and are covered by v1 schema contract tests (`schemas/drift-doctor.v1.json`, `schemas/drift-guard.v1.json`).
33
+ - Added performance regression gate (`npm run check:perf-budget`) with versioned budgets in `benchmarks/perf-budget.v1.json`, benchmark memory/runtime contract checks, and CI artifact upload under `.drift-perf/` (gated on Node 20 to reduce matrix flakiness).
34
+ - Stabilized local/CI test reliability by setting global Vitest default timeouts (15s) and tuning the scan runtime perf budget threshold for lower false-positive noise.
35
+
36
+ ---
37
+
38
+ ## [1.4.0] - 2026-03-18
39
+
40
+ ### Added
41
+
42
+ - `drift init`: project scaffolding command for `drift.config.ts`, optional CI workflow, and baseline generation.
43
+ - `drift doctor`: environment and project diagnostics command with optional JSON output.
44
+ - `drift guard [path]`: non-regression gate command for diff-aware (`--base`) or baseline-aware (`--baseline`) quality checks.
45
+ - Output schema contracts and metadata for machine-consumable outputs (v1 JSON schemas).
46
+ - SARIF mapper/public API and SARIF output support for `scan`, `ci`, `diff`, `review`, and `trust`.
47
+ - CI integration update for SARIF publishing in pull request workflows and action v2 contract alignment.
48
+
49
+ ### Changed
50
+
51
+ - Unified CLI output format handling around `--format` with legacy alias compatibility (`--json`, `--ai`, `--comment`, `--markdown`).
52
+ - `docs/rules-catalog.md` and command format matrix updated to reflect current SARIF-capable commands and 35-rule catalog.
53
+
54
+ ### Tests
55
+
56
+ - Added and expanded coverage for init/doctor/guard flows and SARIF paths (`tests/phase1-init-doctor-guard.test.ts`, `tests/cli-sarif.test.ts`, `tests/sarif.test.ts`, `tests/format.test.ts`).
57
+
58
+ ### Docs
59
+
60
+ - Updated trust-core and release-oriented docs to match current CLI behavior, trust artifacts, and SARIF workflow expectations.
61
+
62
+ ---
63
+
23
64
  ## [0.9.0] - 2026-02-24
24
65
 
25
66
  ### Added