@saulwade/swl-ses 1.7.2 → 1.7.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saulwade/swl-ses",
3
- "version": "1.7.2",
4
- "description": "Sistema de ingenieria de software auto-evolutivo multi-runtime polyglot con 61 agentes, 177 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.2 introduce dimension 8 del auditor CLAUDE.md (deteccion de duplicacion de reglas globales) + hook PostToolUse claudemd-duplicacion-detector + regla sin-duplicacion-reglas-globales.md + catalogo declarativo reglas-globales-conocidas.json con 6 reglas (idioma, brevedad, git-coauthor, arreglar-al-detectar, debatir, context7).",
3
+ "version": "1.7.4",
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.4 documenta knobs nativos de Claude Code (CLAUDE_CODE_SUBAGENT_MODEL, --max-budget-usd, CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS) en reglas/harness-claude-code.md + ADR-0030 Propuesto (Dreaming API para consolidacion de memoria). Hereda de v1.7.3: skill calidad-anti-patrones-universales + scripts/lib/pr-analyzer.js + 3 sub-secciones en estilo-sin-ai-isms.",
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.2",
4
- "description": "Sistema de ingenieria de software auto-evolutivo multi-runtime polyglot. 61 agentes, 177 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.2 introduce dimension 8 del auditor CLAUDE.md (deteccion de duplicacion de reglas globales), hook PostToolUse claudemd-duplicacion-detector, regla sin-duplicacion-reglas-globales y catalogo declarativo de 6 reglas globales conocidas (idioma, brevedad, git-coauthor, arreglar-al-detectar, debatir, context7).",
3
+ "version": "1.7.4",
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.4 documenta knobs nativos de Claude Code (CLAUDE_CODE_SUBAGENT_MODEL, --max-budget-usd, CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS) en reglas/harness-claude-code.md + ADR-0030 Propuesto (Dreaming API para consolidacion de memoria). Hereda de v1.7.3: skill calidad-anti-patrones-universales + scripts/lib/pr-analyzer.js + 3 sub-secciones en estilo-sin-ai-isms.",
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",
@@ -101,6 +101,45 @@ con uso constante de tools mantiene el prefijo caliente indefinidamente
101
101
  - Cambiar de modelo a media sesión invalida el cache (regla de cache
102
102
  discipline arriba). Si necesitas otro modelo, abre nueva sesión.
103
103
 
104
+ ### Knobs nativos para sub-agentes y teams (env vars del harness)
105
+
106
+ Claude Code expone variables de entorno que controlan el routing de
107
+ modelos y el costo de sesiones con múltiples agentes. Son del **harness
108
+ Anthropic**, no de swl-ses — complementan, no reemplazan, el Model-Tier
109
+ por frontmatter (`model:` en cada agente) ni el `budget-enforcer.js`.
110
+
111
+ ```bash
112
+ # Forzar el modelo de TODOS los sub-agentes/teammates a uno más barato.
113
+ # Útil en sesiones ad-hoc donde no quieres routing granular por agente.
114
+ # El líder mantiene el modelo de la sesión (Opus); los teammates bajan a Sonnet.
115
+ export CLAUDE_CODE_SUBAGENT_MODEL="claude-sonnet-4-6"
116
+
117
+ # Habilitar Agent Teams nativo (experimental): un líder coordina teammates
118
+ # que se comunican entre sí vía task list compartida. swl-ses NO lo usa por
119
+ # defecto — su patrón es orquestador-swl + Agent tool. Activar solo para
120
+ # experimentar con coordinación teammate-to-teammate.
121
+ export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
122
+ ```
123
+
124
+ ```bash
125
+ # Cap de costo nativo por sesión headless/team. Aborta la sesión completa
126
+ # al alcanzar el límite, sin importar cuántos agentes estén activos.
127
+ claude -p "build the auth system" --max-budget-usd 15.00
128
+ ```
129
+
130
+ **Relación con la infra de swl-ses:**
131
+
132
+ | Knob nativo | Equivalente swl-ses | Cuándo usar el nativo |
133
+ |-------------|---------------------|------------------------|
134
+ | `CLAUDE_CODE_SUBAGENT_MODEL` | `model:` en frontmatter de cada agente (Model-Tier) | El frontmatter es **superior** (granular por agente). El env var solo para sesiones ad-hoc sin SWL o como override global temporal |
135
+ | `--max-budget-usd` | `scripts/lib/budget-enforcer.js` (4 niveles + idempotency) + `hooks/tracking-costos.js` | El `budget-enforcer` es **superior** (warning/approval/backpressure/hard). El flag nativo es un cap duro complementario para sesiones de orquestador con muchos sub-agentes en paralelo |
136
+ | `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` | `orquestador-swl` + Agent tool | swl-ses prefiere su patrón. El nativo solo para experimentación — su modelo teammate-to-teammate no está integrado con los hooks de gobernanza SWL |
137
+
138
+ **Anti-patrón**: usar `CLAUDE_CODE_SUBAGENT_MODEL` como reemplazo del
139
+ Model-Tier por frontmatter. Pierde la granularidad (revisor-seguridad
140
+ necesita Opus aunque sea teammate). Usar solo como override de sesión,
141
+ nunca persistente en `.bashrc` si trabajas con swl-ses.
142
+
104
143
  ### `/effort` per-prompt (no per-session)
105
144
 
106
145
  ```
@@ -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
+ };