@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.
- package/.gga +50 -0
- package/.github/actions/drift-review/README.md +62 -0
- package/.github/actions/drift-review/action.yml +148 -0
- package/.github/actions/drift-scan/README.md +28 -32
- package/.github/actions/drift-scan/action.yml +78 -14
- package/.github/workflows/publish-vscode.yml +1 -3
- package/.github/workflows/publish.yml +8 -0
- package/.github/workflows/quality.yml +15 -0
- package/.github/workflows/reusable-quality-checks.yml +95 -0
- package/.github/workflows/review-pr.yml +33 -41
- package/AGENTS.md +75 -251
- package/CHANGELOG.md +41 -0
- package/README.md +177 -43
- package/benchmarks/fixtures/critical/drift.config.ts +21 -0
- package/benchmarks/fixtures/critical/src/app/user-service.ts +30 -0
- package/benchmarks/fixtures/critical/src/domain/entities.ts +19 -0
- package/benchmarks/fixtures/critical/src/domain/policies.ts +22 -0
- package/benchmarks/fixtures/critical/src/index.ts +10 -0
- package/benchmarks/fixtures/critical/src/infra/memory-user-repo.ts +14 -0
- package/benchmarks/perf-budget.v1.json +27 -0
- package/dist/benchmark.d.ts +1 -1
- package/dist/benchmark.js +83 -52
- package/dist/cli.js +243 -8
- package/dist/config.js +16 -2
- package/dist/diff.js +42 -50
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +140 -0
- package/dist/format.d.ts +17 -0
- package/dist/format.js +45 -0
- package/dist/guard-baseline.d.ts +12 -0
- package/dist/guard-baseline.js +57 -0
- package/dist/guard-metrics.d.ts +6 -0
- package/dist/guard-metrics.js +39 -0
- package/dist/guard-types.d.ts +58 -0
- package/dist/guard-types.js +2 -0
- package/dist/guard.d.ts +16 -0
- package/dist/guard.js +178 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +4 -1
- package/dist/init.d.ts +15 -0
- package/dist/init.js +273 -0
- package/dist/map-cycles.d.ts +2 -0
- package/dist/map-cycles.js +34 -0
- package/dist/map-svg.d.ts +19 -0
- package/dist/map-svg.js +97 -0
- package/dist/map.js +78 -138
- package/dist/metrics.js +70 -55
- package/dist/output-metadata.d.ts +15 -0
- package/dist/output-metadata.js +19 -0
- package/dist/plugins-capabilities.d.ts +4 -0
- package/dist/plugins-capabilities.js +21 -0
- package/dist/plugins-messages.d.ts +10 -0
- package/dist/plugins-messages.js +16 -0
- package/dist/plugins-rules.d.ts +9 -0
- package/dist/plugins-rules.js +137 -0
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +45 -142
- package/dist/reporter-constants.d.ts +16 -0
- package/dist/reporter-constants.js +39 -0
- package/dist/reporter.d.ts +3 -3
- package/dist/reporter.js +35 -55
- package/dist/review.d.ts +2 -1
- package/dist/review.js +2 -1
- package/dist/rules/phase3-configurable.js +23 -15
- package/dist/saas/constants.d.ts +15 -0
- package/dist/saas/constants.js +48 -0
- package/dist/saas/dashboard.d.ts +8 -0
- package/dist/saas/dashboard.js +132 -0
- package/dist/saas/errors.d.ts +19 -0
- package/dist/saas/errors.js +37 -0
- package/dist/saas/helpers.d.ts +21 -0
- package/dist/saas/helpers.js +110 -0
- package/dist/saas/ingest.d.ts +3 -0
- package/dist/saas/ingest.js +249 -0
- package/dist/saas/organization.d.ts +5 -0
- package/dist/saas/organization.js +82 -0
- package/dist/saas/plan-change.d.ts +10 -0
- package/dist/saas/plan-change.js +15 -0
- package/dist/saas/store.d.ts +21 -0
- package/dist/saas/store.js +159 -0
- package/dist/saas/types.d.ts +191 -0
- package/dist/saas/types.js +2 -0
- package/dist/saas.d.ts +8 -218
- package/dist/saas.js +7 -761
- package/dist/sarif.d.ts +74 -0
- package/dist/sarif.js +122 -0
- package/dist/trust-advanced.d.ts +14 -0
- package/dist/trust-advanced.js +65 -0
- package/dist/trust-kpi-fs.d.ts +3 -0
- package/dist/trust-kpi-fs.js +141 -0
- package/dist/trust-kpi-parse.d.ts +7 -0
- package/dist/trust-kpi-parse.js +186 -0
- package/dist/trust-kpi-types.d.ts +16 -0
- package/dist/trust-kpi-types.js +2 -0
- package/dist/trust-kpi.d.ts +1 -3
- package/dist/trust-kpi.js +6 -266
- package/dist/trust-policy.d.ts +32 -0
- package/dist/trust-policy.js +160 -0
- package/dist/trust-render.d.ts +9 -0
- package/dist/trust-render.js +54 -0
- package/dist/trust-scoring.d.ts +9 -0
- package/dist/trust-scoring.js +208 -0
- package/dist/trust.d.ts +5 -32
- package/dist/trust.js +29 -432
- package/dist/types/app.d.ts +30 -0
- package/dist/types/app.js +2 -0
- package/dist/types/config.d.ts +25 -0
- package/dist/types/config.js +2 -0
- package/dist/types/core.d.ts +100 -0
- package/dist/types/core.js +2 -0
- package/dist/types/diff.d.ts +55 -0
- package/dist/types/diff.js +2 -0
- package/dist/types/plugin.d.ts +41 -0
- package/dist/types/plugin.js +2 -0
- package/dist/types/trust.d.ts +120 -0
- package/dist/types/trust.js +2 -0
- package/dist/types.d.ts +8 -365
- package/docs/AGENTS.md +1 -1
- package/docs/release-notes-draft.md +40 -0
- package/docs/rules-catalog.md +49 -0
- package/docs/trust-core-release-checklist.md +37 -5
- package/package.json +11 -4
- package/packages/vscode-drift/src/code-actions.ts +1 -1
- package/schemas/drift-ai-output.v1.json +162 -0
- package/schemas/drift-doctor.v1.json +57 -0
- package/schemas/drift-guard.v1.json +298 -0
- package/schemas/drift-report.v1.json +151 -0
- package/schemas/drift-trust.v1.json +131 -0
- package/scripts/check-docs-drift.mjs +154 -0
- package/scripts/check-performance-budget.mjs +360 -0
- package/scripts/check-runtime-policy.mjs +66 -0
- package/scripts/smoke-repo.mjs +394 -0
- package/src/benchmark.ts +92 -53
- package/src/cli.ts +285 -13
- package/src/config.ts +19 -2
- package/src/diff.ts +57 -48
- package/src/doctor.ts +185 -0
- package/src/format.ts +81 -0
- package/src/guard-baseline.ts +74 -0
- package/src/guard-metrics.ts +52 -0
- package/src/guard-types.ts +66 -0
- package/src/guard.ts +248 -0
- package/src/index.ts +36 -0
- package/src/init.ts +298 -0
- package/src/map-cycles.ts +38 -0
- package/src/map-svg.ts +124 -0
- package/src/map.ts +111 -142
- package/src/metrics.ts +78 -59
- package/src/output-metadata.ts +32 -0
- package/src/plugins-capabilities.ts +36 -0
- package/src/plugins-messages.ts +35 -0
- package/src/plugins-rules.ts +296 -0
- package/src/plugins.ts +76 -283
- package/src/reporter-constants.ts +46 -0
- package/src/reporter.ts +64 -65
- package/src/review.ts +4 -2
- package/src/rules/phase3-configurable.ts +39 -26
- package/src/saas/constants.ts +56 -0
- package/src/saas/dashboard.ts +172 -0
- package/src/saas/errors.ts +45 -0
- package/src/saas/helpers.ts +140 -0
- package/src/saas/ingest.ts +278 -0
- package/src/saas/organization.ts +99 -0
- package/src/saas/plan-change.ts +19 -0
- package/src/saas/store.ts +172 -0
- package/src/saas/types.ts +216 -0
- package/src/saas.ts +49 -1031
- package/src/sarif.ts +232 -0
- package/src/trust-advanced.ts +99 -0
- package/src/trust-kpi-fs.ts +169 -0
- package/src/trust-kpi-parse.ts +219 -0
- package/src/trust-kpi-types.ts +19 -0
- package/src/trust-kpi.ts +8 -316
- package/src/trust-policy.ts +246 -0
- package/src/trust-render.ts +61 -0
- package/src/trust-scoring.ts +231 -0
- package/src/trust.ts +62 -576
- package/src/types/app.ts +30 -0
- package/src/types/config.ts +27 -0
- package/src/types/core.ts +105 -0
- package/src/types/diff.ts +61 -0
- package/src/types/plugin.ts +46 -0
- package/src/types/trust.ts +134 -0
- package/src/types.ts +79 -409
- package/tests/ci-quality-matrix.test.ts +37 -0
- package/tests/ci-smoke-gate.test.ts +26 -0
- package/tests/ci-version-alignment.test.ts +93 -0
- package/tests/cli-sarif.test.ts +92 -0
- package/tests/docs-drift-check.test.ts +115 -0
- package/tests/format.test.ts +157 -0
- package/tests/new-features.test.ts +11 -3
- package/tests/perf-budget-check.test.ts +146 -0
- package/tests/phase1-init-doctor-guard.test.ts +301 -0
- package/tests/runtime-policy-alignment.test.ts +46 -0
- package/tests/sarif.test.ts +160 -0
- package/tests/trust-kpi.test.ts +31 -4
- package/tests/trust.test.ts +18 -0
- 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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
34
|
-
run: npx --no-install tsx ./src/cli.ts
|
|
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.
|
|
61
|
-
echo "- Merge risk: **${{ steps.
|
|
62
|
-
echo "- New issues vs base: **${{ steps.
|
|
63
|
-
echo "- Resolved issues vs base: **${{ steps.
|
|
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
|
|
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
|
-
|
|
111
|
-
|
|
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
|
|
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
|
|
121
|
+
COMMENT_BODY+="$(cat "${{ steps.drift_review.outputs.review-markdown }}")"
|
|
130
122
|
COMMENT_BODY+=$'\n\n'
|
|
131
|
-
COMMENT_BODY+="<!-- drift-trust-kpi score=${{ steps.
|
|
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
|
|
139
|
+
cat "${{ steps.drift_review.outputs.trust-markdown }}"
|
|
148
140
|
echo
|
|
149
141
|
echo "## drift review"
|
|
150
142
|
echo
|
|
151
|
-
cat
|
|
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
|
|
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
|
-
-
|
|
8
|
-
-
|
|
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
|
|
13
|
+
## Stack y runtime
|
|
15
14
|
|
|
16
15
|
| Dep | Rol |
|
|
17
16
|
|-----|-----|
|
|
18
|
-
| `ts-morph ^27` |
|
|
19
|
-
| `commander ^14` | CLI
|
|
20
|
-
| `kleur ^4` |
|
|
21
|
-
| `typescript ^5.9` |
|
|
22
|
-
|
|
|
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
|
-
|
|
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
|
-
##
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
##
|
|
53
|
+
## Reglas y scoring (estado real)
|
|
164
54
|
|
|
165
|
-
|
|
166
|
-
-
|
|
167
|
-
-
|
|
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
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
86
|
+
`scan`, `diff`, `guard`, `trust`, `report`, `badge`, `ci`, `snapshot` comparten:
|
|
254
87
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
##
|
|
96
|
+
## Comandos incorporados recientes (operativos)
|
|
268
97
|
|
|
269
|
-
-
|
|
270
|
-
-
|
|
271
|
-
-
|
|
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
|
|
104
|
+
## Convenciones de contribución (rápidas)
|
|
278
105
|
|
|
279
|
-
-
|
|
280
|
-
-
|
|
281
|
-
- Conventional Commits
|
|
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
|
-
##
|
|
112
|
+
## Archivos clave
|
|
289
113
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|