@saulwade/swl-ses 1.3.8 → 1.4.1

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 (148) hide show
  1. package/CLAUDE.md +15 -6
  2. package/README.md +15 -14
  3. package/agentes/nemesis-auditor-swl.md +161 -0
  4. package/bin/swl-mcp-server.js +187 -187
  5. package/bin/swl-webhook-server.js +198 -0
  6. package/comandos/swl/.evolved.json +22 -22
  7. package/comandos/swl/adoptar-proyecto.md +21 -1
  8. package/comandos/swl/claudemd.md +14 -1
  9. package/comandos/swl/contribuir.md +233 -233
  10. package/comandos/swl/exportar-vault.md +108 -0
  11. package/comandos/swl/nemesis.md +122 -0
  12. package/comandos/swl/nuevo-proyecto.md +24 -2
  13. package/comandos/swl/salud.md +34 -0
  14. package/comandos/swl/verificar.md +45 -0
  15. package/gateway/adapters/base.js +109 -0
  16. package/gateway/adapters/discord.js +167 -0
  17. package/gateway/adapters/email.js +221 -0
  18. package/gateway/adapters/slack.js +192 -0
  19. package/gateway/adapters/telegram.js +183 -0
  20. package/gateway/adapters/webhook.js +113 -0
  21. package/gateway/adapters/whatsapp.js +214 -0
  22. package/gateway/agent-executor.js +322 -0
  23. package/gateway/command-relay.js +271 -0
  24. package/gateway/cron/jobs.js +263 -0
  25. package/gateway/cron/scheduler.js +322 -0
  26. package/gateway/cron/store.js +335 -0
  27. package/gateway/index.js +320 -0
  28. package/gateway/lib/event-channel.js +191 -0
  29. package/gateway/session.js +131 -0
  30. package/gateway/webhook-server.js +324 -0
  31. package/habilidades/backend-production-resilience/SKILL.md +288 -288
  32. package/habilidades/benchmark-memoria/SKILL.md +186 -186
  33. package/habilidades/build-errors-nextjs/SKILL.md +55 -1
  34. package/habilidades/diagrama-arquitectura/assets/template.html +276 -276
  35. package/habilidades/doubt-driven-review/SKILL.md +171 -171
  36. package/habilidades/doubt-driven-review/recursos/EXAMPLES.md +130 -130
  37. package/habilidades/eval-framework/SKILL.md +212 -212
  38. package/habilidades/extractor-de-aprendizajes/SKILL.md +20 -10
  39. package/habilidades/feynman-auditor-swl/SKILL.md +123 -0
  40. package/habilidades/feynman-auditor-swl/recursos/preguntas-language-agnostic.md +108 -0
  41. package/habilidades/harness-claude-code/SKILL.md +299 -299
  42. package/habilidades/infra-github-actions/SKILL.md +166 -166
  43. package/habilidades/legacy-code-rescue/SKILL.md +267 -267
  44. package/habilidades/manejo-errores/.evolved.json +8 -8
  45. package/habilidades/meta-skills-estandar/recursos/convencion-examples.md +93 -93
  46. package/habilidades/meta-skills-estandar/recursos/skills-as-agents.md +163 -163
  47. package/habilidades/nextjs-testing/SKILL.md +89 -5
  48. package/habilidades/node-experto/SKILL.md +37 -1
  49. package/habilidades/patrones-python/SKILL.md +229 -229
  50. package/habilidades/patrones-python/recursos/patrones-avanzados.md +469 -469
  51. package/habilidades/planear-fase/SKILL.md +319 -319
  52. package/habilidades/react-experto/SKILL.md +45 -4
  53. package/habilidades/release-semver/.evolved.json +8 -8
  54. package/habilidades/state-inconsistency-auditor-swl/SKILL.md +166 -0
  55. package/habilidades/state-inconsistency-auditor-swl/recursos/coupled-state-patterns.md +147 -0
  56. package/habilidades/tdd-workflow/SKILL.md +36 -4
  57. package/habilidades/testing-python/SKILL.md +340 -340
  58. package/habilidades/web-fetcher-routing/SKILL.md +75 -0
  59. package/hooks/claudemd-bloat-detector.js +161 -161
  60. package/hooks/inyeccion-contexto.js +8 -3
  61. package/hooks/lib/agent-routing.js +107 -107
  62. package/hooks/lib/auto-consolidator.js +335 -335
  63. package/hooks/lib/error-classifier.js +308 -308
  64. package/hooks/lib/merkle-audit.js +96 -96
  65. package/hooks/lib/provenance-tracker.js +191 -191
  66. package/hooks/lib/rate-limit-ip.js +177 -0
  67. package/hooks/lib/rate-limit-tracker.js +253 -253
  68. package/hooks/lib/resource-quota.js +122 -122
  69. package/hooks/lib/retry-jitter.js +165 -165
  70. package/hooks/lib/security-net.js +201 -0
  71. package/hooks/lib/skill-auditor.js +588 -588
  72. package/hooks/lib/sync-status.js +228 -228
  73. package/hooks/lib/taint-tracker.js +107 -107
  74. package/hooks/lib/text-similarity.js +241 -241
  75. package/hooks/lib/toon-compressor.js +245 -245
  76. package/hooks/lib/webhook-dedup.js +184 -0
  77. package/hooks/lib/webhook-verify.js +123 -0
  78. package/hooks/proteccion-rutas.js +120 -15
  79. package/hooks/registro-turnos.js +209 -209
  80. package/hooks/sugerir-regenerar-inventario.js +170 -170
  81. package/hooks/validar-formato-post-subagente.js +140 -140
  82. package/hooks/validar-memoria-hook.js +218 -218
  83. package/instintos/prompt-appendices.yaml +57 -57
  84. package/manifiestos/agent-output-schemas.json +57 -57
  85. package/manifiestos/modulos.json +31 -0
  86. package/manifiestos/skills-lock.json +1114 -1093
  87. package/package.json +6 -4
  88. package/plantillas/auditor-veto-template.md +105 -105
  89. package/plantillas/github-workflows/README.md +47 -47
  90. package/plantillas/github-workflows/release-please.yml +44 -44
  91. package/plantillas/github-workflows/swl-ci.yml +107 -107
  92. package/plantillas/github-workflows/swl-security.yml +51 -51
  93. package/plugin.json +2 -2
  94. package/reglas/analisis-previo-tareas-grandes.md +172 -172
  95. package/reglas/arreglar-al-detectar.md +147 -147
  96. package/reglas/fragmentos-compartidos.md +152 -152
  97. package/reglas/harness-claude-code.md +213 -213
  98. package/reglas/usar-context7.md +226 -226
  99. package/reglas/usar-sistema-swl.md +251 -0
  100. package/schemas/diary-entry.schema.json +80 -80
  101. package/scripts/audit-tools/audit-history.js +330 -0
  102. package/scripts/audit-tools/bundle-tracker.js +290 -0
  103. package/scripts/audit-tools/canary-monitor.js +352 -0
  104. package/scripts/audit-tools/code-profiler.js +605 -0
  105. package/scripts/audit-tools/dep-doctor.js +320 -0
  106. package/scripts/audit-tools/env-validator.js +206 -0
  107. package/scripts/audit-tools/lib/fs-walk.js +48 -0
  108. package/scripts/audit-tools/lib/output.js +23 -0
  109. package/scripts/audit-tools/migration-checker.js +392 -0
  110. package/scripts/audit-tools/pentest-scanner.js +1436 -0
  111. package/scripts/benchmark-memoria.js +167 -167
  112. package/scripts/comandos/skills.js +251 -2
  113. package/scripts/configurar-branch-protection.js +418 -418
  114. package/scripts/detectar-aprendizajes-duplicados.js +151 -151
  115. package/scripts/field-report.js +199 -199
  116. package/scripts/generar-checklists-consolidados.js +273 -273
  117. package/scripts/generar-inventario.js +420 -420
  118. package/scripts/generar-matriz-lenguajes.js +271 -271
  119. package/scripts/lib/artefactos-python.js +43 -43
  120. package/scripts/lib/benchmark-metrics.js +160 -160
  121. package/scripts/lib/budget-enforcer.js +252 -252
  122. package/scripts/lib/configurar-ci.js +380 -380
  123. package/scripts/lib/contadores-inventario.js +217 -217
  124. package/scripts/lib/detectar-stack-detallado.js +307 -307
  125. package/scripts/lib/diary-entry.js +234 -234
  126. package/scripts/lib/eval-metrics-store.js +218 -218
  127. package/scripts/lib/eval-quality.js +171 -171
  128. package/scripts/lib/eval-schemas.js +144 -144
  129. package/scripts/lib/eval-self-correct.js +106 -106
  130. package/scripts/lib/eval-validator.js +185 -185
  131. package/scripts/lib/jaccard-similarity.js +98 -98
  132. package/scripts/lib/longmemeval-runner.js +125 -125
  133. package/scripts/lib/npm-version.js +261 -261
  134. package/scripts/lib/paquetes-conocidos.js +50 -50
  135. package/scripts/lib/prompt-builder.js +264 -264
  136. package/scripts/lib/rrf-fusion.js +175 -175
  137. package/scripts/lib/scoring-instintos.js +277 -277
  138. package/scripts/lib/semantic-search.js +252 -252
  139. package/scripts/limpiar-artefactos-python.js +131 -131
  140. package/scripts/mcp-server/README.md +128 -128
  141. package/scripts/mcp-server/handlers.js +206 -206
  142. package/scripts/migrar-csv-a-array.js +168 -168
  143. package/scripts/migrar-fase-dominio.js +201 -201
  144. package/scripts/publicar.js +511 -511
  145. package/scripts/run-eval.js +141 -141
  146. package/scripts/validar-manifest.js +195 -195
  147. package/scripts/validar-userland-vacio.js +110 -110
  148. package/scripts/verificar-release.js +110 -0
@@ -0,0 +1,320 @@
1
+ // Adaptado de temp/ultraship-main/tools/dep-doctor.mjs bajo MIT License
2
+ // Fuente: Houseofmvps/ultraship (https://github.com/Houseofmvps/ultraship)
3
+ 'use strict';
4
+
5
+ const { readFileSync, existsSync, readdirSync, statSync } = require('fs');
6
+ const { join, relative, extname } = require('path');
7
+ const { outputJSON, outputError } = require('./lib/output');
8
+
9
+ const SKIP_DIRS = new Set([
10
+ 'node_modules', '.git', 'dist', 'build', '.next', 'coverage',
11
+ '__pycache__', '.cache', 'venv', '.venv', 'target', 'vendor',
12
+ '.tox', 'eggs', '.eggs', 'htmlcov', '.mypy_cache', '.pytest_cache',
13
+ ]);
14
+
15
+ const CODE_EXTS = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.json', '.vue', '.svelte']);
16
+
17
+ /**
18
+ * Recorre un directorio buscando archivos de código.
19
+ * @param {string} dir
20
+ * @returns {string[]}
21
+ */
22
+ function findCodeFiles(dir) {
23
+ const files = [];
24
+ function walk(d) {
25
+ try {
26
+ for (const entry of readdirSync(d)) {
27
+ if (entry.startsWith('.') || SKIP_DIRS.has(entry)) continue;
28
+ const p = join(d, entry);
29
+ try {
30
+ const s = statSync(p);
31
+ if (s.isDirectory()) walk(p);
32
+ else if (CODE_EXTS.has(extname(entry).toLowerCase())) files.push(p);
33
+ } catch { /* skip */ }
34
+ }
35
+ } catch { /* skip */ }
36
+ }
37
+ walk(dir);
38
+ return files;
39
+ }
40
+
41
+ // Dependencias usadas implícitamente (herramientas de build, definiciones de tipos)
42
+ const IMPLICIT_DEPS = new Set([
43
+ 'typescript', '@types/node', '@types/react', '@types/react-dom',
44
+ 'eslint', 'prettier', 'vitest', 'jest', 'mocha',
45
+ 'tailwindcss', 'autoprefixer', 'postcss',
46
+ 'drizzle-kit', 'prisma',
47
+ '@vitejs/plugin-react', 'vite',
48
+ 'tsx', 'ts-node', 'nodemon',
49
+ 'husky', 'lint-staged', 'commitlint',
50
+ 'dotenv', 'cross-env',
51
+ ]);
52
+
53
+ // Paquetes cuyo nombre de import difiere del nombre en package.json
54
+ const IMPORT_ALIASES = {
55
+ 'next': ['next', 'next/'],
56
+ '@hono/node-server': ['@hono/node-server'],
57
+ 'drizzle-orm': ['drizzle-orm'],
58
+ '@neondatabase/serverless': ['@neondatabase/serverless'],
59
+ 'better-auth': ['better-auth'],
60
+ '@anthropic-ai/sdk': ['@anthropic-ai/sdk', 'anthropic'],
61
+ '@clerk/nextjs': ['@clerk/nextjs'],
62
+ };
63
+
64
+ /**
65
+ * Detecta dependencias no utilizadas en el directorio dado.
66
+ * @param {string} dir
67
+ * @returns {{ unused: object[], total_deps: number, total_dev_deps: number, error?: string }}
68
+ */
69
+ function detectUnusedDeps(dir) {
70
+ const pkgPath = join(dir, 'package.json');
71
+ if (!existsSync(pkgPath)) return { unused: [], error: 'No se encontró package.json', total_deps: 0, total_dev_deps: 0 };
72
+
73
+ let pkg;
74
+ try {
75
+ pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
76
+ } catch (e) {
77
+ return { unused: [], error: `package.json inválido: ${e.message}`, total_deps: 0, total_dev_deps: 0 };
78
+ }
79
+
80
+ const prodDeps = Object.keys(pkg.dependencies || {});
81
+ const devDeps = Object.keys(pkg.devDependencies || {});
82
+
83
+ const codeFiles = findCodeFiles(dir);
84
+ const fileContents = new Map();
85
+ let allCode = '';
86
+
87
+ for (const file of codeFiles) {
88
+ try {
89
+ const code = readFileSync(file, 'utf8');
90
+ fileContents.set(file, code);
91
+ allCode += code + '\n';
92
+ } catch { /* skip */ }
93
+ }
94
+
95
+ // Incluir archivos de configuración en la raíz
96
+ const configFiles = [
97
+ 'vite.config.ts', 'vite.config.js', 'next.config.js', 'next.config.mjs',
98
+ 'tailwind.config.js', 'tailwind.config.ts', 'postcss.config.js', 'postcss.config.cjs',
99
+ 'drizzle.config.ts', 'drizzle.config.js', '.eslintrc.js', '.eslintrc.json',
100
+ 'tsconfig.json', 'jest.config.js', 'vitest.config.ts',
101
+ ];
102
+ for (const cf of configFiles) {
103
+ const p = join(dir, cf);
104
+ if (existsSync(p)) {
105
+ try {
106
+ const code = readFileSync(p, 'utf8');
107
+ fileContents.set(p, code);
108
+ allCode += code + '\n';
109
+ } catch { /* skip */ }
110
+ }
111
+ }
112
+
113
+ // Construir grafo de imports: objetivos de import locales normalizados
114
+ const allImportTargets = new Set();
115
+ for (const [, code] of fileContents) {
116
+ const importRegex = /(?:from\s+|require\s*\(\s*)['"]([^'"]+)['"]/g;
117
+ let m;
118
+ while ((m = importRegex.exec(code)) !== null) {
119
+ const target = m[1];
120
+ if (target.startsWith('.') || target.startsWith('@/') || target.startsWith('~/')) {
121
+ const clean = target.replace(/^(?:\.\/|@\/|~\/)/, '').replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/, '');
122
+ allImportTargets.add(clean);
123
+ allImportTargets.add(clean.replace(/\/index$/, ''));
124
+ }
125
+ }
126
+ }
127
+
128
+ function isFileReachable(filePath) {
129
+ const rel = relative(dir, filePath).replace(/\\/g, '/');
130
+ const noExt = rel.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/, '');
131
+ const noIndex = noExt.replace(/\/index$/, '');
132
+ const basename = filePath.split(/[/\\]/).pop();
133
+ if (['page.tsx', 'page.ts', 'page.jsx', 'layout.tsx', 'layout.ts',
134
+ 'main.tsx', 'main.ts', 'App.tsx', 'App.ts', 'index.tsx', 'index.ts',
135
+ 'index.js', 'main.js'].includes(basename)) return true;
136
+ if (rel.includes('/routes/') || rel.includes('/api/') || rel.includes('/pages/')) return true;
137
+ if (rel.includes('config')) return true;
138
+ for (const target of allImportTargets) {
139
+ if (target === noExt || target === noIndex ||
140
+ target === `src/${noExt}` || target === `src/${noIndex}` ||
141
+ noExt.endsWith(`/${target}`) || noIndex.endsWith(`/${target}`)) return true;
142
+ }
143
+ return false;
144
+ }
145
+
146
+ function findDepImportFiles(dep) {
147
+ const aliases = IMPORT_ALIASES[dep] || [dep];
148
+ const files = [];
149
+ for (const [filePath, code] of fileContents) {
150
+ for (const alias of aliases) {
151
+ if (code.includes(`'${alias}'`) || code.includes(`"${alias}"`) ||
152
+ code.includes(`'${alias}/`) || code.includes(`"${alias}/`)) {
153
+ files.push(filePath);
154
+ break;
155
+ }
156
+ }
157
+ if (dep.startsWith('@') && !files.includes(filePath)) {
158
+ if (code.includes(`'${dep}'`) || code.includes(`"${dep}"`) ||
159
+ code.includes(`'${dep}/`) || code.includes(`"${dep}/`)) {
160
+ files.push(filePath);
161
+ }
162
+ }
163
+ }
164
+ return files;
165
+ }
166
+
167
+ const unused = [];
168
+
169
+ function isUsed(dep) {
170
+ if (IMPLICIT_DEPS.has(dep)) return true;
171
+ if (dep.startsWith('@types/')) return true;
172
+ const aliases = IMPORT_ALIASES[dep] || [dep];
173
+ for (const alias of aliases) {
174
+ if (allCode.includes(`'${alias}'`) || allCode.includes(`"${alias}"`)) return true;
175
+ if (allCode.includes(`'${alias}/`) || allCode.includes(`"${alias}/`)) return true;
176
+ if (allCode.includes(`require('${alias}')`) || allCode.includes(`require("${alias}")`)) return true;
177
+ }
178
+ if (dep.startsWith('@')) {
179
+ if (allCode.includes(`'${dep}'`) || allCode.includes(`"${dep}"`)) return true;
180
+ if (allCode.includes(`'${dep}/`) || allCode.includes(`"${dep}/`)) return true;
181
+ }
182
+ return false;
183
+ }
184
+
185
+ function isDeadCode(dep) {
186
+ const importFiles = findDepImportFiles(dep);
187
+ if (importFiles.length === 0) return true;
188
+ return importFiles.every(f => !isFileReachable(f));
189
+ }
190
+
191
+ for (const dep of prodDeps) {
192
+ if (!isUsed(dep)) {
193
+ unused.push({ name: dep, type: 'production', severity: 'high', message: `"${dep}" está en dependencies pero no se importa en ningún lugar — eliminar para reducir el tamaño de instalación` });
194
+ } else if (isDeadCode(dep)) {
195
+ unused.push({ name: dep, type: 'production', severity: 'medium', message: `"${dep}" solo se importa en archivos no alcanzables — eliminar si esos componentes no se necesitan` });
196
+ }
197
+ }
198
+
199
+ for (const dep of devDeps) {
200
+ if (!isUsed(dep)) {
201
+ unused.push({ name: dep, type: 'devDependency', severity: 'low', message: `"${dep}" está en devDependencies pero no se referencia — puede eliminarse` });
202
+ }
203
+ }
204
+
205
+ return { unused, total_deps: prodDeps.length, total_dev_deps: devDeps.length };
206
+ }
207
+
208
+ /**
209
+ * Detecta dependencias posiblemente desactualizadas.
210
+ * @param {string} dir
211
+ * @returns {{ outdated: object[] }}
212
+ */
213
+ function detectOutdated(dir) {
214
+ const pkgPath = join(dir, 'package.json');
215
+ if (!existsSync(pkgPath)) return { outdated: [] };
216
+
217
+ let pkg;
218
+ try {
219
+ pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
220
+ } catch {
221
+ return { outdated: [] };
222
+ }
223
+
224
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
225
+ const findings = [];
226
+
227
+ for (const [name, version] of Object.entries(allDeps)) {
228
+ if (typeof version !== 'string') continue;
229
+ const v = version.trim();
230
+ if (v.startsWith('file:') || v.startsWith('link:') || v.startsWith('workspace:') || v === '*' || v === 'latest') continue;
231
+
232
+ // Versión anclada exacta (sin ^ ni ~)
233
+ if (/^\d/.test(v)) {
234
+ findings.push({
235
+ name,
236
+ version: v,
237
+ severity: 'low',
238
+ issue: 'anclada',
239
+ message: `"${name}@${v}" está anclado a versión exacta — usar ^${v} para recibir actualizaciones de parches`,
240
+ });
241
+ }
242
+
243
+ // Versiones mayores muy antiguas de paquetes conocidos
244
+ const majorMatch = v.match(/\d+/);
245
+ if (majorMatch) {
246
+ const major = parseInt(majorMatch[0], 10);
247
+ const knownOld = {
248
+ 'react': 18, 'next': 14, 'vue': 3, 'express': 4, 'hono': 4,
249
+ 'typescript': 5, 'vite': 5, 'tailwindcss': 3, 'eslint': 9,
250
+ 'drizzle-orm': 0, 'prisma': 5, 'zod': 3,
251
+ };
252
+ if (knownOld[name] !== undefined && major < knownOld[name] - 1) {
253
+ findings.push({
254
+ name,
255
+ version: v,
256
+ severity: 'medium',
257
+ issue: 'mayor_desactualizado',
258
+ message: `"${name}@${v}" tiene ${knownOld[name] - major}+ versiones mayores de retraso — considerar actualización`,
259
+ });
260
+ }
261
+ }
262
+ }
263
+
264
+ return { outdated: findings };
265
+ }
266
+
267
+ function main() {
268
+ const dir = process.argv[2];
269
+ if (!dir) {
270
+ outputError('Uso: node dep-doctor.js <directorio-proyecto>');
271
+ process.exit(0);
272
+ }
273
+
274
+ if (!existsSync(dir)) {
275
+ outputError(`Ruta no encontrada: ${dir}`);
276
+ process.exit(0);
277
+ }
278
+
279
+ const unusedResult = detectUnusedDeps(dir);
280
+ const outdatedResult = detectOutdated(dir);
281
+
282
+ outputJSON({
283
+ success: true,
284
+ packages_scanned: 1,
285
+ total_production_deps: unusedResult.total_deps || 0,
286
+ total_dev_deps: unusedResult.total_dev_deps || 0,
287
+ unused_count: unusedResult.unused.length,
288
+ outdated_count: outdatedResult.outdated.length,
289
+ total_findings: unusedResult.unused.length + outdatedResult.outdated.length,
290
+ unused: unusedResult.unused,
291
+ outdated: outdatedResult.outdated,
292
+ });
293
+ }
294
+
295
+ main();
296
+
297
+ module.exports = { detectUnusedDeps, detectOutdated, findCodeFiles, IMPLICIT_DEPS };
298
+
299
+ /**
300
+ * @complemento Skill("dependencias-auditoria")
301
+ *
302
+ * dep-doctor.js realiza **análisis estático** de dependencias:
303
+ * - Detecta dependencias declaradas pero nunca importadas en el código fuente.
304
+ * - Detecta versiones ancladas sin `^`/`~` y versiones mayores muy desactualizadas.
305
+ * - Sin ejecución de shell, sin red. Seguro para usar en cualquier entorno.
306
+ * - Rápido (solo lectura de archivos locales).
307
+ *
308
+ * Skill("dependencias-auditoria") realiza **auditoría de seguridad profunda**:
309
+ * - Consulta bases de datos CVE reales (pip-audit, npm audit, trivy, grype).
310
+ * - Detecta licencias incompatibles (pip-licenses, license-checker).
311
+ * - Identifica dependencias abandonadas con fecha de último commit.
312
+ * - Requiere: red (acceso a advisories), shell (pip-audit, npm, trivy instalados).
313
+ * - Más lento pero definitivo en vulnerabilidades conocidas.
314
+ *
315
+ * Flujo recomendado:
316
+ * 1. Ejecutar `dep-doctor.js` primero (rápido, sin dependencias externas).
317
+ * → Eliminar dependencias no usadas reduce la superficie de ataque.
318
+ * 2. Luego invocar `Skill("dependencias-auditoria")` para CVEs y licencias.
319
+ * → Asegura que las dependencias restantes no tienen vulnerabilidades conocidas.
320
+ */
@@ -0,0 +1,206 @@
1
+ // Adaptado de temp/ultraship-main/tools/env-validator.mjs bajo MIT License
2
+ // Fuente: Houseofmvps/ultraship (https://github.com/Houseofmvps/ultraship)
3
+ 'use strict';
4
+
5
+ const { readFileSync, existsSync } = require('fs');
6
+ const { join, basename, resolve } = require('path');
7
+ const { outputJSON, outputError } = require('./lib/output');
8
+
9
+ /**
10
+ * Parsea un archivo .env y devuelve un mapa clave→valor.
11
+ * Maneja comillas simples/dobles y comentarios con #.
12
+ * @param {string} filePath
13
+ * @returns {Record<string, string>}
14
+ */
15
+ function parseEnvFile(filePath) {
16
+ let content;
17
+ try {
18
+ content = readFileSync(filePath, 'utf8');
19
+ } catch {
20
+ return {};
21
+ }
22
+
23
+ const vars = {};
24
+ for (const line of content.split('\n')) {
25
+ const trimmed = line.trim();
26
+ if (!trimmed || trimmed.startsWith('#')) continue;
27
+ const match = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)(\s*=\s*)(.*)/);
28
+ if (!match) continue;
29
+ const key = match[1];
30
+ let value = match[3].trim();
31
+ // Eliminar comillas envolventes
32
+ if (
33
+ (value.startsWith('"') && value.endsWith('"')) ||
34
+ (value.startsWith("'") && value.endsWith("'"))
35
+ ) {
36
+ value = value.slice(1, -1);
37
+ }
38
+ vars[key] = value;
39
+ }
40
+ return vars;
41
+ }
42
+
43
+ /**
44
+ * Detecta si un valor es claramente un placeholder.
45
+ * @param {string} value
46
+ * @returns {boolean}
47
+ */
48
+ function isPlaceholder(value) {
49
+ if (!value) return false;
50
+ const v = value.toLowerCase();
51
+ return (
52
+ v.includes('your_') ||
53
+ v.includes('xxx') ||
54
+ v.includes('placeholder') ||
55
+ v.includes('change_me') ||
56
+ v.includes('todo') ||
57
+ v.includes('replace') ||
58
+ v.includes('your-') ||
59
+ v === 'sk-...' ||
60
+ v === 'pk_...' ||
61
+ /^[a-z_]+_here$/i.test(v)
62
+ );
63
+ }
64
+
65
+ function main() {
66
+ const args = process.argv.slice(2);
67
+ const rawDir = args.find(a => !a.startsWith('--'));
68
+ const dir = resolve(rawDir || process.cwd());
69
+
70
+ if (!existsSync(dir)) {
71
+ outputError(`Directorio no encontrado: ${dir}`);
72
+ process.exit(0);
73
+ }
74
+
75
+ // Buscar archivo de variables de entorno de ejemplo
76
+ const exampleNames = ['.env.example', '.env.sample', '.env.template', '.env.defaults'];
77
+ let exampleFile = null;
78
+ for (const name of exampleNames) {
79
+ const p = join(dir, name);
80
+ if (existsSync(p)) {
81
+ exampleFile = p;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if (!exampleFile) {
87
+ outputJSON({
88
+ success: true,
89
+ warning: 'No se encontró archivo .env.example. No es posible validar las variables de entorno requeridas.',
90
+ suggestion: 'Crea un archivo .env.example con todas las variables requeridas y valores de ejemplo.',
91
+ findings: [],
92
+ });
93
+ process.exit(0);
94
+ }
95
+
96
+ const requiredVars = parseEnvFile(exampleFile);
97
+ const requiredKeys = Object.keys(requiredVars);
98
+
99
+ if (requiredKeys.length === 0) {
100
+ outputJSON({
101
+ success: true,
102
+ message: 'No se encontraron variables en el archivo de ejemplo.',
103
+ findings: [],
104
+ });
105
+ process.exit(0);
106
+ }
107
+
108
+ // Leer variables reales: .env.local, luego .env, luego process.env
109
+ let actualVars = {};
110
+
111
+ const envLocalFile = join(dir, '.env.local');
112
+ if (existsSync(envLocalFile)) {
113
+ Object.assign(actualVars, parseEnvFile(envLocalFile));
114
+ }
115
+
116
+ const envFile = join(dir, '.env');
117
+ if (existsSync(envFile)) {
118
+ Object.assign(actualVars, parseEnvFile(envFile));
119
+ }
120
+
121
+ // Las variables de entorno en tiempo de ejecución tienen mayor precedencia
122
+ for (const key of requiredKeys) {
123
+ if (process.env[key] !== undefined) {
124
+ actualVars[key] = process.env[key];
125
+ }
126
+ }
127
+
128
+ const findings = [];
129
+ const missing = [];
130
+ const empty = [];
131
+ const placeholder = [];
132
+ const set = [];
133
+
134
+ for (const key of requiredKeys) {
135
+ const exampleValue = requiredVars[key];
136
+ const actualValue = actualVars[key];
137
+
138
+ if (actualValue === undefined) {
139
+ missing.push(key);
140
+ findings.push({
141
+ variable: key,
142
+ status: 'faltante',
143
+ severity: 'critical',
144
+ message: `${key} es requerida pero no está definida en .env ni en el entorno`,
145
+ example_value: exampleValue || '(sin valor de ejemplo)',
146
+ });
147
+ } else if (actualValue === '') {
148
+ empty.push(key);
149
+ findings.push({
150
+ variable: key,
151
+ status: 'vacía',
152
+ severity: 'high',
153
+ message: `${key} está definida pero su valor es vacío`,
154
+ });
155
+ } else if (actualValue === exampleValue && isPlaceholder(exampleValue)) {
156
+ placeholder.push(key);
157
+ findings.push({
158
+ variable: key,
159
+ status: 'placeholder',
160
+ severity: 'high',
161
+ message: `${key} aún tiene su valor de ejemplo — reemplázalo con el valor real`,
162
+ });
163
+ } else {
164
+ set.push(key);
165
+ }
166
+ }
167
+
168
+ // Verificar que .env está en .gitignore
169
+ const gitignorePath = join(dir, '.gitignore');
170
+ let envInGitignore = false;
171
+ if (existsSync(gitignorePath)) {
172
+ const gitignore = readFileSync(gitignorePath, 'utf8');
173
+ envInGitignore = gitignore.split('\n').some(line => {
174
+ const t = line.trim();
175
+ return t === '.env' || t === '.env*' || t === '.env.local';
176
+ });
177
+ }
178
+
179
+ if (!envInGitignore) {
180
+ findings.push({
181
+ variable: '.env',
182
+ status: 'gitignore_ausente',
183
+ severity: 'critical',
184
+ message: '.env no está en .gitignore — los secretos podrían commitearse accidentalmente',
185
+ });
186
+ }
187
+
188
+ outputJSON({
189
+ success: true,
190
+ example_file: basename(exampleFile),
191
+ total_required: requiredKeys.length,
192
+ set: set.length,
193
+ missing: missing.length,
194
+ empty: empty.length,
195
+ placeholder: placeholder.length,
196
+ env_in_gitignore: envInGitignore,
197
+ deploy_ready: missing.length === 0 && empty.length === 0 && placeholder.length === 0,
198
+ findings,
199
+ });
200
+ }
201
+
202
+ if (require.main === module) {
203
+ main();
204
+ }
205
+
206
+ module.exports = { parseEnvFile, isPlaceholder };
@@ -0,0 +1,48 @@
1
+ // Adaptado de temp/ultraship-main/tools/*.mjs bajo MIT License
2
+ // Fuente: Houseofmvps/ultraship (https://github.com/Houseofmvps/ultraship)
3
+ 'use strict';
4
+
5
+ const { readdirSync, statSync } = require('fs');
6
+ const { join, extname } = require('path');
7
+
8
+ const SKIP_DIRS = new Set([
9
+ 'node_modules', '.git', 'dist', 'build', '.next', 'coverage',
10
+ '__pycache__', '.cache', 'venv', '.venv', 'target', 'vendor',
11
+ '.tox', 'eggs', '.eggs', 'htmlcov', '.mypy_cache', '.pytest_cache',
12
+ ]);
13
+
14
+ /**
15
+ * Recorre recursivamente un directorio y retorna archivos de código.
16
+ * Omite directorios en SKIP_DIRS y entradas que empiecen con '.'.
17
+ *
18
+ * @param {string} dir - Directorio raíz a recorrer
19
+ * @param {object} [opciones]
20
+ * @param {string[]} [opciones.extensions] - Extensiones a incluir
21
+ * @returns {string[]} Lista de rutas absolutas de archivos encontrados
22
+ */
23
+ function walkCode(dir, opciones = {}) {
24
+ const extensions = opciones.extensions || [
25
+ '.js', '.ts', '.tsx', '.jsx', '.py', '.mjs', '.cjs',
26
+ ];
27
+ const extSet = new Set(extensions.map(e => e.toLowerCase()));
28
+ const files = [];
29
+
30
+ function walk(d) {
31
+ try {
32
+ for (const entry of readdirSync(d)) {
33
+ if (entry.startsWith('.') || SKIP_DIRS.has(entry)) continue;
34
+ const p = join(d, entry);
35
+ try {
36
+ const s = statSync(p);
37
+ if (s.isDirectory()) walk(p);
38
+ else if (extSet.has(extname(entry).toLowerCase())) files.push(p);
39
+ } catch { /* skip archivos no accesibles */ }
40
+ }
41
+ } catch { /* skip directorios no accesibles */ }
42
+ }
43
+
44
+ walk(dir);
45
+ return files;
46
+ }
47
+
48
+ module.exports = { walkCode, SKIP_DIRS };
@@ -0,0 +1,23 @@
1
+ // Adaptado de temp/ultraship-main/tools/*.mjs bajo MIT License
2
+ // Fuente: Houseofmvps/ultraship (https://github.com/Houseofmvps/ultraship)
3
+ 'use strict';
4
+
5
+ /**
6
+ * Escribe datos como JSON formateado a stdout.
7
+ * @param {object} data
8
+ */
9
+ function outputJSON(data) {
10
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
11
+ }
12
+
13
+ /**
14
+ * Escribe un error a stderr. Nunca lanza excepción.
15
+ * @param {string} msg
16
+ * @param {object|null} contextData
17
+ */
18
+ function outputError(msg, contextData = null) {
19
+ const err = contextData ? { error: msg, context: contextData } : { error: msg };
20
+ process.stderr.write(JSON.stringify(err, null, 2) + '\n');
21
+ }
22
+
23
+ module.exports = { outputJSON, outputError };