@saulwade/swl-ses 1.7.2 → 1.7.3
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/CLAUDE.md +2 -2
- package/README.md +2 -2
- package/habilidades/calidad-anti-patrones-universales/SKILL.md +368 -0
- package/habilidades/estilo-sin-ai-isms/SKILL.md +52 -1
- package/manifiestos/modulos.json +1351 -1350
- package/manifiestos/skills-lock.json +13 -6
- package/package.json +2 -2
- package/plugin.json +3 -2
- package/scripts/lib/pr-analyzer.js +399 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"lockfileVersion": 1,
|
|
3
|
-
"generatedAt": "2026-05-
|
|
4
|
-
"skillsCount":
|
|
5
|
-
"lockHash": "sha256:
|
|
3
|
+
"generatedAt": "2026-05-24T23:17:38.255Z",
|
|
4
|
+
"skillsCount": 178,
|
|
5
|
+
"lockHash": "sha256:1c37732adb57b8daf54b93978d2559419f65e73a7e85cc83af449408c9f7ec44",
|
|
6
6
|
"skills": [
|
|
7
7
|
{
|
|
8
8
|
"nombre": "accesibilidad-a11y",
|
|
@@ -242,6 +242,13 @@
|
|
|
242
242
|
"bytes": 13490,
|
|
243
243
|
"version": "\"1.0.0\""
|
|
244
244
|
},
|
|
245
|
+
{
|
|
246
|
+
"nombre": "calidad-anti-patrones-universales",
|
|
247
|
+
"path": "habilidades/calidad-anti-patrones-universales/SKILL.md",
|
|
248
|
+
"hash": "sha256:5047fc360759b8d894b3e5c20a344cae46562c8131267c5a59f9d8f8839ef178",
|
|
249
|
+
"bytes": 11840,
|
|
250
|
+
"version": "\"1.0.0\""
|
|
251
|
+
},
|
|
245
252
|
{
|
|
246
253
|
"nombre": "changelog-generator",
|
|
247
254
|
"path": "habilidades/changelog-generator/SKILL.md",
|
|
@@ -455,9 +462,9 @@
|
|
|
455
462
|
{
|
|
456
463
|
"nombre": "estilo-sin-ai-isms",
|
|
457
464
|
"path": "habilidades/estilo-sin-ai-isms/SKILL.md",
|
|
458
|
-
"hash": "sha256:
|
|
459
|
-
"bytes":
|
|
460
|
-
"version": "\"1.1.
|
|
465
|
+
"hash": "sha256:f3dc9dfafa65029fb70ebf9d6887832f71415853293c3d1e82716ce5fc447884",
|
|
466
|
+
"bytes": 39938,
|
|
467
|
+
"version": "\"1.1.1\""
|
|
461
468
|
},
|
|
462
469
|
{
|
|
463
470
|
"nombre": "estructura-proyecto-claude",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saulwade/swl-ses",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "Sistema de ingenieria de software auto-evolutivo multi-runtime polyglot con 61 agentes,
|
|
3
|
+
"version": "1.7.3",
|
|
4
|
+
"description": "Sistema de ingenieria de software auto-evolutivo multi-runtime polyglot con 61 agentes, 178 habilidades, 44 comandos, 71 reglas y 43 hooks. Soporta 11 lenguajes y 7 runtimes: Claude Code, OpenClaude, OpenCode, Gemini CLI, Cursor, Codex CLI (soporte completo); GitHub Copilot (soporte parcial). 100% en espanol (Mexico). Multi-target install (--target CSV / --all-runtimes), autoconfig MCP en Cursor/Codex con --with-mcp, agentes Codex en TOML, hooks Cursor (17 eventos) y Codex (6 eventos). Gateway bidireccional con relay Telegram y auditoria profunda Nemesis con loop evaluator-optimizer opt-in (ADR-0021) y 8 tools ejecutables. v1.7.3 agrega skill calidad-anti-patrones-universales (catalogo de 10 anti-patrones nombrados) + utility scripts/lib/pr-analyzer.js (analizador zero-deps de PRs) + 3 sub-secciones nuevas en estilo-sin-ai-isms (agencia falsa, narrador-distancia, aperturas Wh-).",
|
|
5
5
|
"bin": {
|
|
6
6
|
"swl-ses": "bin/swl-ses.js",
|
|
7
7
|
"swl-telegram-bot": "bin/swl-telegram-bot.js",
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swl-ses",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "Sistema de ingenieria de software auto-evolutivo multi-runtime polyglot. 61 agentes,
|
|
3
|
+
"version": "1.7.3",
|
|
4
|
+
"description": "Sistema de ingenieria de software auto-evolutivo multi-runtime polyglot. 61 agentes, 178 habilidades, 44 comandos, 71 reglas y 43 hooks. 62 librerias. 11 lenguajes. Soporta Claude Code, Copilot, OpenCode, Codex y Gemini CLI. Loop evaluator-optimizer en /swl:nemesis (ADR-0021). v1.7.3 agrega skill calidad-anti-patrones-universales (catalogo de 10 anti-patrones nombrados) + utility scripts/lib/pr-analyzer.js (analizador zero-deps de PRs) + 3 sub-secciones nuevas en estilo-sin-ai-isms (agencia falsa, narrador-distancia, aperturas Wh-).",
|
|
5
5
|
"author": "Saul Wade Leon",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "https://github.com/saul-wade/swl-ses",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"habilidades/build-errors-rust",
|
|
41
41
|
"habilidades/build-errors-swift",
|
|
42
42
|
"habilidades/build-errors-typescript",
|
|
43
|
+
"habilidades/calidad-anti-patrones-universales",
|
|
43
44
|
"habilidades/changelog-generator",
|
|
44
45
|
"habilidades/checklist-calidad",
|
|
45
46
|
"habilidades/checklist-seguridad",
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* pr-analyzer.js
|
|
5
|
+
*
|
|
6
|
+
* Analizador cuantitativo de PRs/diffs. Calcula complejidad (0-1), categoría
|
|
7
|
+
* de tamaño, tiempo estimado de revisión y factores de riesgo a partir de un
|
|
8
|
+
* `git diff` o un texto en formato diff unificado.
|
|
9
|
+
*
|
|
10
|
+
* Port a Node de `pr-analyzer.py` (377 LOC, MIT) del repo
|
|
11
|
+
* `anthropic-skills/code-review-skill` analizado en `temp/code-review-skill-main/`
|
|
12
|
+
* (sesión 2026-05-24). Adaptado a estilo SWL: zero-deps, módulo CommonJS
|
|
13
|
+
* exportable, API en español-MX, retorno JSON parseable.
|
|
14
|
+
*
|
|
15
|
+
* Uso programático:
|
|
16
|
+
* const { analizar } = require('./scripts/lib/pr-analyzer');
|
|
17
|
+
* const reporte = analizar(diffText);
|
|
18
|
+
*
|
|
19
|
+
* Uso CLI (pendiente de wrapper en /swl:analizar-pr o /swl:revisar):
|
|
20
|
+
* git diff main...HEAD | node -e "
|
|
21
|
+
* const { analizar, formatear } = require('./scripts/lib/pr-analyzer');
|
|
22
|
+
* let buf = ''; process.stdin.on('data', d => buf += d);
|
|
23
|
+
* process.stdin.on('end', () => console.log(formatear(analizar(buf))));
|
|
24
|
+
* "
|
|
25
|
+
*
|
|
26
|
+
* @module scripts/lib/pr-analyzer
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// ── constantes ────────────────────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
const EXT_A_LENGUAJE = {
|
|
32
|
+
'.py': 'Python',
|
|
33
|
+
'.js': 'JavaScript',
|
|
34
|
+
'.mjs': 'JavaScript',
|
|
35
|
+
'.cjs': 'JavaScript',
|
|
36
|
+
'.ts': 'TypeScript',
|
|
37
|
+
'.tsx': 'TypeScript/React',
|
|
38
|
+
'.jsx': 'JavaScript/React',
|
|
39
|
+
'.rs': 'Rust',
|
|
40
|
+
'.go': 'Go',
|
|
41
|
+
'.c': 'C',
|
|
42
|
+
'.h': 'C/C++',
|
|
43
|
+
'.cpp': 'C++',
|
|
44
|
+
'.hpp': 'C++',
|
|
45
|
+
'.cc': 'C++',
|
|
46
|
+
'.cxx': 'C++',
|
|
47
|
+
'.java': 'Java',
|
|
48
|
+
'.kt': 'Kotlin',
|
|
49
|
+
'.swift': 'Swift',
|
|
50
|
+
'.rb': 'Ruby',
|
|
51
|
+
'.php': 'PHP',
|
|
52
|
+
'.cs': 'C#',
|
|
53
|
+
'.vue': 'Vue',
|
|
54
|
+
'.svelte': 'Svelte',
|
|
55
|
+
'.sql': 'SQL',
|
|
56
|
+
'.md': 'Markdown',
|
|
57
|
+
'.json': 'JSON',
|
|
58
|
+
'.yaml': 'YAML',
|
|
59
|
+
'.yml': 'YAML',
|
|
60
|
+
'.toml': 'TOML',
|
|
61
|
+
'.css': 'CSS',
|
|
62
|
+
'.scss': 'SCSS',
|
|
63
|
+
'.less': 'Less',
|
|
64
|
+
'.html': 'HTML',
|
|
65
|
+
'.sh': 'Shell',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const PATRONES_TEST = [
|
|
69
|
+
/test_.*\.py$/,
|
|
70
|
+
/.*_test\.py$/,
|
|
71
|
+
/.*\.test\.(js|jsx|ts|tsx|mjs|cjs)$/,
|
|
72
|
+
/.*\.spec\.(js|jsx|ts|tsx|mjs|cjs)$/,
|
|
73
|
+
/tests?\//,
|
|
74
|
+
/__tests__\//,
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const PATRONES_CONFIG = [
|
|
78
|
+
/\.env(\.|$)/,
|
|
79
|
+
/(^|\/)config\./,
|
|
80
|
+
/package\.json$/,
|
|
81
|
+
/tsconfig\.json$/,
|
|
82
|
+
/Cargo\.toml$/,
|
|
83
|
+
/pyproject\.toml$/,
|
|
84
|
+
/requirements.*\.txt$/,
|
|
85
|
+
/\.ya?ml$/,
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const PATRONES_SEGURIDAD = ['.env', 'auth', 'security', 'password', 'token', 'secret', 'credential'];
|
|
89
|
+
|
|
90
|
+
const PATRONES_MIGRACION = [/migration/i, /\bmigrate\b/i, /alembic/i];
|
|
91
|
+
|
|
92
|
+
// ── detección por archivo ─────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Detecta lenguaje a partir de la extensión del archivo.
|
|
96
|
+
* @param {string} filename
|
|
97
|
+
* @returns {string}
|
|
98
|
+
*/
|
|
99
|
+
function detectarLenguaje(filename) {
|
|
100
|
+
const idx = filename.lastIndexOf('.');
|
|
101
|
+
if (idx < 0) return 'unknown';
|
|
102
|
+
const ext = filename.slice(idx).toLowerCase();
|
|
103
|
+
return EXT_A_LENGUAJE[ext] || 'unknown';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function esTest(filename) {
|
|
107
|
+
return PATRONES_TEST.some((p) => p.test(filename));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function esConfig(filename) {
|
|
111
|
+
return PATRONES_CONFIG.some((p) => p.test(filename));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ── parser de diff ────────────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Parsea un diff unificado y extrae stats por archivo.
|
|
118
|
+
* Soporta tanto `diff --git a/path b/path` como bloques sueltos `+++ b/path`.
|
|
119
|
+
* @param {string} diffText
|
|
120
|
+
* @returns {Array<{filename, additions, deletions, isTest, isConfig, language}>}
|
|
121
|
+
*/
|
|
122
|
+
function parsearDiff(diffText) {
|
|
123
|
+
const archivos = [];
|
|
124
|
+
let actual = null;
|
|
125
|
+
const lineas = String(diffText || '').split(/\r?\n/);
|
|
126
|
+
|
|
127
|
+
for (const linea of lineas) {
|
|
128
|
+
if (linea.startsWith('diff --git')) {
|
|
129
|
+
if (actual) archivos.push(actual);
|
|
130
|
+
// Regex anclado: el `(?:.+) b/` greedy hace backtrack hasta el ÚLTIMO
|
|
131
|
+
// " b/" del string, que es el separador real entre oldpath y newpath
|
|
132
|
+
// del formato `diff --git a/<oldpath> b/<newpath>`. Esto resuelve
|
|
133
|
+
// paths que contienen "b/" como subcadena interna (ej. `src/b/foo.ts`).
|
|
134
|
+
// Bug previo: el patrón `b\/(.+)$` capturaba desde el PRIMER `b/`,
|
|
135
|
+
// incluyendo el separador en el filename.
|
|
136
|
+
const m = linea.match(/^diff --git a\/(?:.+) b\/(.+)$/);
|
|
137
|
+
if (m) {
|
|
138
|
+
const filename = m[1].trim();
|
|
139
|
+
actual = {
|
|
140
|
+
filename,
|
|
141
|
+
additions: 0,
|
|
142
|
+
deletions: 0,
|
|
143
|
+
isTest: esTest(filename),
|
|
144
|
+
isConfig: esConfig(filename),
|
|
145
|
+
language: detectarLenguaje(filename),
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
actual = null;
|
|
149
|
+
}
|
|
150
|
+
} else if (actual) {
|
|
151
|
+
if (linea.startsWith('+') && !linea.startsWith('+++')) {
|
|
152
|
+
actual.additions += 1;
|
|
153
|
+
} else if (linea.startsWith('-') && !linea.startsWith('---')) {
|
|
154
|
+
actual.deletions += 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (actual) archivos.push(actual);
|
|
160
|
+
return archivos;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ── métricas ──────────────────────────────────────────────────────────────────
|
|
164
|
+
|
|
165
|
+
function calcularComplejidad(archivos) {
|
|
166
|
+
if (!archivos.length) return 0;
|
|
167
|
+
const totalCambios = archivos.reduce((s, f) => s + f.additions + f.deletions, 0);
|
|
168
|
+
// sizeFactor, fileFactor y langFactor están clamped por construcción con
|
|
169
|
+
// Math.min. noTestRatio y el score final NO lo estaban: con datos
|
|
170
|
+
// patológicos (additions negativos por corrupción de parser, archivos
|
|
171
|
+
// manipulados externamente) noTestRatio podía exceder 1.0 e inflar el
|
|
172
|
+
// score muy por encima de 1.0. Defensa en profundidad: clamp explícito.
|
|
173
|
+
const sizeFactor = Math.min(Math.max(totalCambios, 0) / 1000, 1.0);
|
|
174
|
+
const fileFactor = Math.min(archivos.length / 20, 1.0);
|
|
175
|
+
const testLineas = archivos.filter((f) => f.isTest).reduce((s, f) => s + f.additions + f.deletions, 0);
|
|
176
|
+
const noTestRatio = Math.max(0, Math.min(1, 1 - testLineas / Math.max(totalCambios, 1)));
|
|
177
|
+
const lenguajes = new Set(archivos.map((f) => f.language).filter((l) => l !== 'unknown'));
|
|
178
|
+
const langFactor = Math.min(lenguajes.size / 5, 1.0);
|
|
179
|
+
const score = sizeFactor * 0.4 + fileFactor * 0.2 + noTestRatio * 0.2 + langFactor * 0.2;
|
|
180
|
+
const scoreClamped = Math.max(0, Math.min(1, score));
|
|
181
|
+
return Math.round(scoreClamped * 100) / 100;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function categorizarTamano(totalCambios) {
|
|
185
|
+
if (totalCambios < 50) return 'XS (muy pequeño)';
|
|
186
|
+
if (totalCambios < 200) return 'S (pequeño)';
|
|
187
|
+
if (totalCambios < 400) return 'M (mediano)';
|
|
188
|
+
if (totalCambios < 800) return 'L (grande)';
|
|
189
|
+
return 'XL (muy grande) — considerar dividir';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function estimarTiempoRevision(archivos, complejidad) {
|
|
193
|
+
const totalCambios = archivos.reduce((s, f) => s + f.additions + f.deletions, 0);
|
|
194
|
+
const baseMin = totalCambios / 20; // ~1 min por 20 líneas
|
|
195
|
+
const ajustado = baseMin * (1 + complejidad);
|
|
196
|
+
return Math.max(5, Math.min(120, Math.round(ajustado)));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function identificarRiesgos(archivos) {
|
|
200
|
+
const riesgos = [];
|
|
201
|
+
const totalCambios = archivos.reduce((s, f) => s + f.additions + f.deletions, 0);
|
|
202
|
+
const testCambios = archivos.filter((f) => f.isTest).reduce((s, f) => s + f.additions + f.deletions, 0);
|
|
203
|
+
|
|
204
|
+
if (totalCambios > 400) {
|
|
205
|
+
riesgos.push({ tipo: 'PR_GRANDE', mensaje: `PR grande (${totalCambios} líneas) — más difícil de revisar a fondo` });
|
|
206
|
+
}
|
|
207
|
+
if (testCambios === 0 && totalCambios > 50) {
|
|
208
|
+
riesgos.push({ tipo: 'SIN_TESTS', mensaje: 'No hay cambios en tests — verificar cobertura' });
|
|
209
|
+
}
|
|
210
|
+
if (totalCambios > 100 && testCambios / Math.max(totalCambios, 1) < 0.2) {
|
|
211
|
+
riesgos.push({ tipo: 'BAJA_RATIO_TESTS', mensaje: 'Ratio de tests <20% — considerar agregar más' });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
for (const f of archivos) {
|
|
215
|
+
const lower = f.filename.toLowerCase();
|
|
216
|
+
if (PATRONES_SEGURIDAD.some((p) => lower.includes(p))) {
|
|
217
|
+
riesgos.push({ tipo: 'ARCHIVO_SENSIBLE', mensaje: `Archivo sensible a seguridad: ${f.filename}` });
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (const f of archivos) {
|
|
223
|
+
if (PATRONES_MIGRACION.some((p) => p.test(f.filename)) || f.language === 'SQL') {
|
|
224
|
+
riesgos.push({ tipo: 'CAMBIOS_BD', mensaje: 'Cambios en BD/migración detectados — revisar con cuidado' });
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const configs = archivos.filter((f) => f.isConfig);
|
|
230
|
+
if (configs.length) {
|
|
231
|
+
riesgos.push({ tipo: 'CONFIG', mensaje: `Cambios de configuración en ${configs.length} archivo(s)` });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return riesgos;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function generarSugerencias(archivos, complejidad, riesgos) {
|
|
238
|
+
const sugerencias = [];
|
|
239
|
+
const totalCambios = archivos.reduce((s, f) => s + f.additions + f.deletions, 0);
|
|
240
|
+
|
|
241
|
+
if (totalCambios > 800) sugerencias.push('Considerar dividir este PR en cambios más enfocados');
|
|
242
|
+
if (complejidad > 0.7) {
|
|
243
|
+
sugerencias.push('Complejidad alta — reservar tiempo extra de revisión');
|
|
244
|
+
sugerencias.push('Considerar revisión en pareja para secciones críticas');
|
|
245
|
+
}
|
|
246
|
+
if (riesgos.some((r) => r.tipo === 'SIN_TESTS')) {
|
|
247
|
+
sugerencias.push('Pedir tests antes de aprobar');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const lenguajes = new Set(archivos.map((f) => f.language));
|
|
251
|
+
if (lenguajes.has('TypeScript') || lenguajes.has('TypeScript/React')) {
|
|
252
|
+
sugerencias.push('Verificar uso de tipos (evitar `any` y aserciones inseguras)');
|
|
253
|
+
}
|
|
254
|
+
if (lenguajes.has('Rust')) {
|
|
255
|
+
sugerencias.push('Verificar `unwrap()` y `expect()` en código de producción');
|
|
256
|
+
}
|
|
257
|
+
if (lenguajes.has('C') || lenguajes.has('C++') || lenguajes.has('C/C++')) {
|
|
258
|
+
sugerencias.push('Verificar memory safety, bounds y UB');
|
|
259
|
+
}
|
|
260
|
+
if (lenguajes.has('SQL')) {
|
|
261
|
+
sugerencias.push('Revisar inyección SQL y desempeño de queries');
|
|
262
|
+
}
|
|
263
|
+
if (lenguajes.has('Python')) {
|
|
264
|
+
sugerencias.push('Verificar excepciones específicas (no `except:` desnudo) y type hints');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (!sugerencias.length) sugerencias.push('Revisión estándar suficiente');
|
|
268
|
+
return sugerencias;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Sugiere el agente revisor SWL más apropiado según el lenguaje predominante.
|
|
273
|
+
* Útil para `/swl:revisar` cuando no se especifica explícitamente el stack.
|
|
274
|
+
* @param {Array} archivos
|
|
275
|
+
* @returns {string|null}
|
|
276
|
+
*/
|
|
277
|
+
function sugerirRevisorSWL(archivos) {
|
|
278
|
+
const conteo = {};
|
|
279
|
+
for (const f of archivos) {
|
|
280
|
+
if (f.isTest || f.isConfig) continue;
|
|
281
|
+
conteo[f.language] = (conteo[f.language] || 0) + (f.additions + f.deletions);
|
|
282
|
+
}
|
|
283
|
+
const ordenados = Object.entries(conteo).sort((a, b) => b[1] - a[1]);
|
|
284
|
+
if (!ordenados.length) return null;
|
|
285
|
+
const [predominante] = ordenados[0];
|
|
286
|
+
const mapa = {
|
|
287
|
+
'TypeScript': 'revisor-typescript-swl',
|
|
288
|
+
'TypeScript/React': 'revisor-react-swl',
|
|
289
|
+
'JavaScript/React': 'revisor-react-swl',
|
|
290
|
+
'JavaScript': 'revisor-typescript-swl',
|
|
291
|
+
'Python': 'revisor-codigo-swl',
|
|
292
|
+
'Go': 'revisor-go-swl',
|
|
293
|
+
'Rust': 'revisor-rust-swl',
|
|
294
|
+
'Java': 'revisor-java-swl',
|
|
295
|
+
'Kotlin': 'revisor-kotlin-swl',
|
|
296
|
+
'Swift': 'revisor-swift-swl',
|
|
297
|
+
'C#': 'revisor-csharp-swl',
|
|
298
|
+
'PHP': 'revisor-php-swl',
|
|
299
|
+
};
|
|
300
|
+
return mapa[predominante] || 'revisor-codigo-swl';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ── API pública ───────────────────────────────────────────────────────────────
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Analiza un diff y devuelve un objeto reporte estructurado.
|
|
307
|
+
* @param {string} diffText
|
|
308
|
+
* @returns {object}
|
|
309
|
+
*/
|
|
310
|
+
function analizar(diffText) {
|
|
311
|
+
const archivos = parsearDiff(diffText);
|
|
312
|
+
const totalAdiciones = archivos.reduce((s, f) => s + f.additions, 0);
|
|
313
|
+
const totalEliminaciones = archivos.reduce((s, f) => s + f.deletions, 0);
|
|
314
|
+
const totalCambios = totalAdiciones + totalEliminaciones;
|
|
315
|
+
const complejidad = calcularComplejidad(archivos);
|
|
316
|
+
const riesgos = identificarRiesgos(archivos);
|
|
317
|
+
const sugerencias = generarSugerencias(archivos, complejidad, riesgos);
|
|
318
|
+
const revisorSugerido = sugerirRevisorSWL(archivos);
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
totalArchivos: archivos.length,
|
|
322
|
+
totalAdiciones,
|
|
323
|
+
totalEliminaciones,
|
|
324
|
+
totalCambios,
|
|
325
|
+
complejidad,
|
|
326
|
+
categoriaTamano: categorizarTamano(totalCambios),
|
|
327
|
+
tiempoRevisionEstimado: estimarTiempoRevision(archivos, complejidad),
|
|
328
|
+
riesgos,
|
|
329
|
+
sugerencias,
|
|
330
|
+
revisorSugerido,
|
|
331
|
+
archivos,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Formatea el reporte para output legible en consola.
|
|
337
|
+
* @param {object} reporte
|
|
338
|
+
* @param {{detalleArchivos?: boolean}} [opts]
|
|
339
|
+
* @returns {string}
|
|
340
|
+
*/
|
|
341
|
+
function formatear(reporte, opts = {}) {
|
|
342
|
+
const out = [];
|
|
343
|
+
out.push('═══════════════════════════════════════════════════════════');
|
|
344
|
+
out.push(' REPORTE DE ANÁLISIS DE PR');
|
|
345
|
+
out.push('═══════════════════════════════════════════════════════════');
|
|
346
|
+
out.push('');
|
|
347
|
+
out.push('Resumen:');
|
|
348
|
+
out.push(` Archivos cambiados: ${reporte.totalArchivos}`);
|
|
349
|
+
out.push(` Adiciones: +${reporte.totalAdiciones}`);
|
|
350
|
+
out.push(` Eliminaciones: -${reporte.totalEliminaciones}`);
|
|
351
|
+
out.push(` Cambios totales: ${reporte.totalCambios}`);
|
|
352
|
+
out.push('');
|
|
353
|
+
out.push(`Tamaño: ${reporte.categoriaTamano}`);
|
|
354
|
+
out.push(`Complejidad: ${reporte.complejidad}/1.0`);
|
|
355
|
+
out.push(`Tiempo estim.: ~${reporte.tiempoRevisionEstimado} min`);
|
|
356
|
+
if (reporte.revisorSugerido) {
|
|
357
|
+
out.push(`Revisor SWL sugerido: ${reporte.revisorSugerido}`);
|
|
358
|
+
}
|
|
359
|
+
if (reporte.riesgos.length) {
|
|
360
|
+
out.push('');
|
|
361
|
+
out.push('Riesgos:');
|
|
362
|
+
for (const r of reporte.riesgos) out.push(` - [${r.tipo}] ${r.mensaje}`);
|
|
363
|
+
}
|
|
364
|
+
out.push('');
|
|
365
|
+
out.push('Sugerencias:');
|
|
366
|
+
for (const s of reporte.sugerencias) out.push(` - ${s}`);
|
|
367
|
+
if (opts.detalleArchivos) {
|
|
368
|
+
out.push('');
|
|
369
|
+
out.push('Archivos por lenguaje:');
|
|
370
|
+
const porLang = {};
|
|
371
|
+
for (const f of reporte.archivos) {
|
|
372
|
+
(porLang[f.language] = porLang[f.language] || []).push(f);
|
|
373
|
+
}
|
|
374
|
+
for (const [lang, lista] of Object.entries(porLang).sort()) {
|
|
375
|
+
out.push(` [${lang}]`);
|
|
376
|
+
for (const f of lista) {
|
|
377
|
+
const tag = f.isTest ? 'test' : f.isConfig ? 'conf' : 'src';
|
|
378
|
+
out.push(` ${tag} ${f.filename} (+${f.additions}/-${f.deletions})`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
out.push('═══════════════════════════════════════════════════════════');
|
|
383
|
+
return out.join('\n');
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
module.exports = {
|
|
387
|
+
analizar,
|
|
388
|
+
formatear,
|
|
389
|
+
parsearDiff,
|
|
390
|
+
detectarLenguaje,
|
|
391
|
+
esTest,
|
|
392
|
+
esConfig,
|
|
393
|
+
calcularComplejidad,
|
|
394
|
+
categorizarTamano,
|
|
395
|
+
estimarTiempoRevision,
|
|
396
|
+
identificarRiesgos,
|
|
397
|
+
generarSugerencias,
|
|
398
|
+
sugerirRevisorSWL,
|
|
399
|
+
};
|