@saulwade/swl-ses 2.4.3 → 2.5.2
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 +194 -241
- package/README.md +600 -597
- package/agentes/_intent-spec.md +73 -73
- package/agentes/_propose-step.md +90 -90
- package/agentes/abogado-diablo-swl.md +145 -0
- package/agentes/accesibilidad-wcag-swl.md +690 -690
- package/agentes/arquitecto-swl.md +267 -267
- package/agentes/auto-evolucion-swl.md +908 -908
- package/agentes/backend-api-swl.md +1 -1
- package/agentes/backend-csharp-swl.md +420 -420
- package/agentes/backend-go-swl.md +390 -390
- package/agentes/backend-java-swl.md +281 -281
- package/agentes/backend-node-swl.md +1 -1
- package/agentes/backend-python-swl.md +1 -1
- package/agentes/backend-rust-swl.md +364 -364
- package/agentes/backend-workers-swl.md +482 -482
- package/agentes/cloud-infra-swl.md +509 -509
- package/agentes/consolidador-swl.md +541 -541
- package/agentes/datos-swl.md +1 -1
- package/agentes/depurador-swl.md +352 -352
- package/agentes/devops-ci-swl.md +400 -400
- package/agentes/disenador-ui-swl.md +569 -569
- package/agentes/documentador-swl.md +345 -345
- package/agentes/frontend-angular-swl.md +621 -621
- package/agentes/frontend-css-swl.md +716 -716
- package/agentes/frontend-react-swl.md +692 -692
- package/agentes/frontend-swl.md +496 -496
- package/agentes/frontend-tailwind-swl.md +826 -826
- package/agentes/gh-fix-ci-swl.md +6 -1
- package/agentes/implementador-swl.md +1 -1
- package/agentes/investigador-swl.md +432 -432
- package/agentes/investigador-ux-swl.md +505 -505
- package/agentes/llm-apps-swl.md +1 -1
- package/agentes/migrador-swl.md +442 -442
- package/agentes/mobile-android-swl.md +511 -511
- package/agentes/mobile-cross-swl.md +541 -541
- package/agentes/mobile-ios-swl.md +502 -502
- package/agentes/mobile-testing-swl.md +302 -302
- package/agentes/nemesis-auditor-swl.md +285 -285
- package/agentes/notificador-swl.md +1 -1
- package/agentes/observabilidad-swl.md +438 -438
- package/agentes/pagos-swl.md +310 -310
- package/agentes/perfilador-usuario-swl.md +321 -321
- package/agentes/planificador-swl.md +399 -399
- package/agentes/producto-prd-swl.md +589 -589
- package/agentes/red-team-swl.md +218 -218
- package/agentes/release-manager-swl.md +590 -590
- package/agentes/rendimiento-swl.md +713 -713
- package/agentes/resolutor-build-swl.md +10 -1
- package/agentes/revisor-angular-swl.md +278 -278
- package/agentes/revisor-codigo-swl.md +1 -1
- package/agentes/revisor-csharp-swl.md +264 -264
- package/agentes/revisor-go-swl.md +259 -259
- package/agentes/revisor-java-swl.md +257 -257
- package/agentes/revisor-kotlin-swl.md +273 -273
- package/agentes/revisor-nextjs-swl.md +281 -281
- package/agentes/revisor-php-swl.md +271 -271
- package/agentes/revisor-react-swl.md +278 -278
- package/agentes/revisor-rust-swl.md +346 -346
- package/agentes/revisor-seguridad-swl.md +399 -399
- package/agentes/revisor-swift-swl.md +268 -268
- package/agentes/revisor-typescript-swl.md +346 -346
- package/agentes/sre-swl.md +1 -1
- package/agentes/tdd-qa-swl.md +393 -393
- package/bin/lib/bot-comandos.js +1 -1
- package/bin/swl-ses.js +6 -0
- package/comandos/swl/adoptar-proyecto.md +14 -2
- package/comandos/swl/configurar-ci.md +8 -1
- package/comandos/swl/deuda-codigo.md +97 -97
- package/comandos/swl/discutir-fase.md +22 -118
- package/comandos/swl/fix.md +118 -0
- package/comandos/swl/nuevo-proyecto.md +54 -3
- package/comandos/swl/predecir.md +32 -2
- package/comandos/swl/seguridad.md +189 -0
- package/comandos/swl/status.md +5 -3
- package/habilidades/aprendizaje-continuo/SKILL.md +3 -1
- package/habilidades/discutir-fase/SKILL.md +84 -81
- package/habilidades/discutir-fase/recursos/plantilla-contexto.md +136 -0
- package/habilidades/doc-sync/SKILL.md +3 -1
- package/habilidades/doubt-driven-review/SKILL.md +15 -1
- package/habilidades/ejecutar-task-iterativo/SKILL.md +278 -278
- package/habilidades/estructura-proyecto-claude/SKILL.md +11 -2
- package/habilidades/harness-claude-code/SKILL.md +3 -1
- package/habilidades/instalar-sistema/SKILL.md +3 -1
- package/habilidades/meta-reglas-extendido/SKILL.md +92 -0
- package/habilidades/meta-reglas-extendido/recursos/analisis-previo-tareas-grandes.md +186 -0
- package/habilidades/meta-reglas-extendido/recursos/analizar-directorios-antes-de-escribir.md +235 -0
- package/habilidades/meta-reglas-extendido/recursos/api-diseno.md +413 -0
- package/habilidades/meta-reglas-extendido/recursos/arquitectura.md +491 -0
- package/habilidades/meta-reglas-extendido/recursos/arreglar-al-detectar.md +264 -0
- package/habilidades/meta-reglas-extendido/recursos/debatir-antes-de-aceptar.md +152 -0
- package/habilidades/meta-reglas-extendido/recursos/git-workflow.md +259 -0
- package/habilidades/meta-reglas-extendido/recursos/gobernanza.md +291 -0
- package/habilidades/meta-reglas-extendido/recursos/memoria-consolidada.md +263 -0
- package/habilidades/meta-reglas-extendido/recursos/seguridad-agentes.md +443 -0
- package/habilidades/meta-reglas-extendido/recursos/sesiones-paralelas.md +190 -0
- package/habilidades/meta-reglas-extendido/recursos/sin-duplicacion-reglas-globales.md +179 -0
- package/habilidades/meta-reglas-extendido/recursos/skills-estandar.md +394 -0
- package/habilidades/meta-reglas-extendido/recursos/usar-code-review-graph.md +156 -0
- package/habilidades/meta-reglas-extendido/recursos/usar-context7.md +236 -0
- package/habilidades/meta-reglas-extendido/recursos/usar-sistema-swl.md +253 -0
- package/habilidades/meta-reglas-extendido/recursos/verificar-citas-normativas.md +527 -0
- package/habilidades/meta-skills-estandar/SKILL.md +3 -1
- package/habilidades/nuevo-proyecto/SKILL.md +20 -3
- package/habilidades/php-experto/SKILL.md +10 -3
- package/habilidades/{filament-admin/SKILL.md → php-experto/recursos/filament-admin.md} +23 -39
- package/habilidades/prevencion-sobreingenieria/recursos/soluciones-nativas.md +166 -166
- package/habilidades/prevencion-sobreingenieria/recursos/variables-residuales-post-refactor.md +85 -85
- package/habilidades/proceso-debate-adversarial/recursos/personas.md +5 -4
- package/habilidades/proceso-ingenieria-requerimientos/SKILL.md +147 -0
- package/hooks/check-update.js +19 -10
- package/hooks/contexto-subagente.js +68 -68
- package/hooks/degradacion-instintos.js +1 -1
- package/hooks/extraccion-aprendizajes.js +2 -2
- package/hooks/lib/briefing.js +3 -3
- package/hooks/lib/nudge-tracker.js +1 -1
- package/hooks/lib/otlp-exporter.js +1 -1
- package/hooks/lib/webhook-dedup.js +1 -1
- package/hooks/session-briefing.js +1 -1
- package/llms.txt +6 -6
- package/manifiestos/canonical-hashes.json +1043 -52
- package/manifiestos/hooks-config.json +469 -469
- package/manifiestos/invariantes-criticos.json +30 -30
- package/manifiestos/modulos.json +168 -135
- package/manifiestos/perfiles.json +0 -2
- package/manifiestos/skills-lock.json +49 -56
- package/package.json +7 -5
- package/plantillas/github-workflows/README.md +15 -1
- package/plantillas/github-workflows/swl-devsecops.yml +70 -0
- package/plugin.json +5 -5
- package/reglas/analisis-previo-tareas-grandes.md +30 -156
- package/reglas/analizar-directorios-antes-de-escribir.md +30 -211
- package/reglas/api-diseno.md +28 -398
- package/reglas/arquitectura.md +35 -456
- package/reglas/arreglar-al-detectar.md +30 -230
- package/reglas/debatir-antes-de-aceptar.md +30 -143
- package/reglas/docs.md +7 -0
- package/reglas/estilo-codigo.md +9 -0
- package/reglas/fragmentos-compartidos.md +6 -0
- package/reglas/git-workflow.md +44 -240
- package/reglas/gobernanza.md +23 -262
- package/reglas/memoria-consolidada.md +34 -228
- package/reglas/performance.md +8 -0
- package/reglas/pruebas.md +12 -0
- package/reglas/seguridad-agentes.md +37 -418
- package/reglas/seguridad.md +12 -0
- package/reglas/sesiones-paralelas.md +29 -162
- package/reglas/sin-duplicacion-reglas-globales.md +25 -166
- package/reglas/skills-estandar.md +23 -373
- package/reglas/usar-code-review-graph.md +31 -140
- package/reglas/usar-context7.md +30 -208
- package/reglas/usar-sistema-swl.md +47 -242
- package/reglas/verificar-citas-normativas.md +47 -537
- package/scripts/actualizar.js +253 -253
- package/scripts/audit-tools/auditar-relleno-inventario.js +145 -0
- package/scripts/auditar-clases-conocidas.js +106 -0
- package/scripts/bootstrap-instintos.js +2 -2
- package/scripts/canario-hooks.js +166 -0
- package/scripts/cli/configurar-ci.js +2 -1
- package/scripts/evidencia-valor.js +101 -0
- package/scripts/field-report.js +18 -2
- package/scripts/generar-comandos.js +143 -0
- package/scripts/generar-inventario.js +236 -23
- package/scripts/generar-matriz-lenguajes.js +1 -1
- package/scripts/instalador.js +15 -1
- package/scripts/instalar-git-hook.js +8 -1
- package/scripts/lib/configurar-ci.js +10 -3
- package/scripts/lib/diary-entry.js +3 -1
- package/scripts/lib/drift-detector.js +1 -1
- package/scripts/lib/evidencia-valor.js +228 -0
- package/scripts/lib/expandir-targets.js +71 -71
- package/scripts/lib/frontmatter-md.js +63 -0
- package/scripts/lib/parsear-opciones.js +2 -0
- package/scripts/lib/prune-componentes.js +180 -0
- package/scripts/lib/reglas-globales-conocidas.json +16 -2
- package/scripts/lib/scoring-instintos.js +2 -2
- package/scripts/lib/toml-merge.js +204 -204
- package/scripts/lib/transformadores/claude.js +1 -1
- package/scripts/lib/transformadores/codex.js +1 -1
- package/scripts/lib/transformadores/copilot.js +1 -1
- package/scripts/lib/transformadores/cursor.js +1 -1
- package/scripts/lib/transformadores/gemini.js +22 -2
- package/scripts/lib/transformadores/opencode.js +1 -1
- package/scripts/mcp-server/auth.js +105 -105
- package/scripts/mcp-server/cache.js +106 -106
- package/scripts/prune.js +102 -0
- package/scripts/publicar.js +18 -2
- package/scripts/tui/index.js +10 -1
- package/scripts/tui/pantallas/inspect.js +175 -175
- package/scripts/tui/pantallas/install-wizard.js +21 -8
- package/scripts/tui/pantallas/uninstall-wizard.js +210 -210
- package/scripts/tui/pantallas/update-wizard.js +234 -234
- package/scripts/tui/pantallas/welcome.js +188 -189
- package/habilidades/paid-media-tracking/SKILL.md +0 -269
- package/habilidades/paid-media-tracking/recursos/auditoria-tracking.md +0 -220
- package/habilidades/paid-media-tracking/recursos/google-ads-api.md +0 -215
- package/habilidades/tracking-measurement/SKILL.md +0 -239
- package/habilidades/tracking-measurement/recursos/consent-mode.md +0 -231
- package/habilidades/tracking-measurement/recursos/gtm-datalayer.md +0 -216
- package/habilidades/tracking-measurement/recursos/meta-capi.md +0 -262
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Merge mínimo de secciones TOML — zero-deps.
|
|
5
|
-
*
|
|
6
|
-
* Opera sobre el formato concreto de `~/.codex/config.toml` (OpenAI Codex CLI):
|
|
7
|
-
* [mcp_servers.<name>]
|
|
8
|
-
* command = "node"
|
|
9
|
-
* args = ["...", "..."]
|
|
10
|
-
* [mcp_servers.<name>.env]
|
|
11
|
-
* KEY = "value"
|
|
12
|
-
*
|
|
13
|
-
* Reglas:
|
|
14
|
-
* - NUNCA reescribe el archivo entero. Solo agrega o reemplaza la sección
|
|
15
|
-
* `[mcp_servers.<name>]` indicada (incluyendo sub-tabla `.env`).
|
|
16
|
-
* - Si el archivo no existe lo crea con permisos 0600.
|
|
17
|
-
* - Si el archivo tiene comentarios o secciones desconocidas, las preserva.
|
|
18
|
-
* - Bloque "owned" delimitado por marcadores `# SWL-MCP-BEGIN <name>` /
|
|
19
|
-
* `# SWL-MCP-END <name>` para permitir actualizaciones idempotentes.
|
|
20
|
-
*
|
|
21
|
-
* NO soporta:
|
|
22
|
-
* - TOML completo (arrays multilínea complejos, inline tables, etc.)
|
|
23
|
-
* - Multi-section nested tables fuera de `mcp_servers.*`
|
|
24
|
-
*
|
|
25
|
-
* Si en el futuro Codex publica un comando idempotente `codex mcp add --idempotent`
|
|
26
|
-
* podemos delegarle el trabajo y deprecar este helper.
|
|
27
|
-
*
|
|
28
|
-
* @module scripts/lib/toml-merge
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
const fs = require('fs');
|
|
32
|
-
const path = require('path');
|
|
33
|
-
|
|
34
|
-
const { atomicWriteSync } = require('../../hooks/lib/atomic-write');
|
|
35
|
-
|
|
36
|
-
const BEGIN_PREFIX = '# SWL-MCP-BEGIN';
|
|
37
|
-
const END_PREFIX = '# SWL-MCP-END';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Serializa un servidor MCP en bloque TOML.
|
|
41
|
-
*
|
|
42
|
-
* @param {string} name - Nombre del server (identificador en config.toml).
|
|
43
|
-
* @param {{ command: string, args?: string[], env?: Record<string,string> }} cfg
|
|
44
|
-
* @returns {string} Bloque TOML con marcadores.
|
|
45
|
-
*/
|
|
46
|
-
function serializarServidor(name, cfg) {
|
|
47
|
-
if (!name || typeof name !== 'string' || !/^[a-zA-Z0-9_-]+$/.test(name)) {
|
|
48
|
-
throw new Error(`Nombre de MCP server inválido: "${name}". Solo [a-zA-Z0-9_-].`);
|
|
49
|
-
}
|
|
50
|
-
if (!cfg || typeof cfg.command !== 'string' || cfg.command.length === 0) {
|
|
51
|
-
throw new Error(`MCP server "${name}" requiere "command" string no vacío.`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const lineas = [];
|
|
55
|
-
lineas.push(`${BEGIN_PREFIX} ${name}`);
|
|
56
|
-
lineas.push(`[mcp_servers.${name}]`);
|
|
57
|
-
lineas.push(`command = ${tomlString(cfg.command)}`);
|
|
58
|
-
|
|
59
|
-
if (Array.isArray(cfg.args) && cfg.args.length > 0) {
|
|
60
|
-
const items = cfg.args.map(tomlString).join(', ');
|
|
61
|
-
lineas.push(`args = [${items}]`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (cfg.env && typeof cfg.env === 'object' && Object.keys(cfg.env).length > 0) {
|
|
65
|
-
lineas.push('');
|
|
66
|
-
lineas.push(`[mcp_servers.${name}.env]`);
|
|
67
|
-
for (const [k, v] of Object.entries(cfg.env)) {
|
|
68
|
-
if (typeof v !== 'string') {
|
|
69
|
-
throw new Error(`MCP server "${name}" env.${k} debe ser string (recibido: ${typeof v}).`);
|
|
70
|
-
}
|
|
71
|
-
// Solo claves alfanuméricas/_ en env names — TOML restricción razonable
|
|
72
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) {
|
|
73
|
-
throw new Error(`MCP server "${name}" env key inválido: "${k}".`);
|
|
74
|
-
}
|
|
75
|
-
lineas.push(`${k} = ${tomlString(v)}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
lineas.push(`${END_PREFIX} ${name}`);
|
|
80
|
-
return lineas.join('\n');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Escapa un string para TOML usando comillas dobles.
|
|
85
|
-
* No usa basic-string raw para evitar pitfalls con backslashes.
|
|
86
|
-
*/
|
|
87
|
-
function tomlString(s) {
|
|
88
|
-
// TOML basic string: escape backslash, doblequote, control chars.
|
|
89
|
-
const escapado = String(s)
|
|
90
|
-
.replace(/\\/g, '\\\\')
|
|
91
|
-
.replace(/"/g, '\\"')
|
|
92
|
-
.replace(/\n/g, '\\n')
|
|
93
|
-
.replace(/\r/g, '\\r')
|
|
94
|
-
.replace(/\t/g, '\\t');
|
|
95
|
-
return `"${escapado}"`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Inserta o actualiza un servidor MCP en `config.toml`.
|
|
100
|
-
*
|
|
101
|
-
* Idempotente: si el bloque ya existe con el mismo contenido, no escribe.
|
|
102
|
-
* Si existe con contenido distinto, lo reemplaza dentro de los marcadores.
|
|
103
|
-
* Si no existe, lo agrega al final del archivo precedido de línea en blanco.
|
|
104
|
-
*
|
|
105
|
-
* @param {string} rutaConfig - Path absoluto a config.toml (típicamente ~/.codex/config.toml).
|
|
106
|
-
* @param {string} name - Nombre del MCP server (clave de [mcp_servers.<name>]).
|
|
107
|
-
* @param {{ command: string, args?: string[], env?: Record<string,string> }} cfg
|
|
108
|
-
* @returns {{ accion: 'creado' | 'agregado' | 'actualizado' | 'sin-cambios', ruta: string }}
|
|
109
|
-
*/
|
|
110
|
-
function upsertMcpServer(rutaConfig, name, cfg) {
|
|
111
|
-
const bloqueNuevo = serializarServidor(name, cfg);
|
|
112
|
-
|
|
113
|
-
let existente = '';
|
|
114
|
-
let existia = false;
|
|
115
|
-
try {
|
|
116
|
-
existente = fs.readFileSync(rutaConfig, 'utf-8');
|
|
117
|
-
existia = true;
|
|
118
|
-
} catch (err) {
|
|
119
|
-
if (err.code !== 'ENOENT') throw err;
|
|
120
|
-
// Archivo no existe — se crea
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const beginTag = `${BEGIN_PREFIX} ${name}`;
|
|
124
|
-
const endTag = `${END_PREFIX} ${name}`;
|
|
125
|
-
|
|
126
|
-
if (!existia) {
|
|
127
|
-
const dir = path.dirname(rutaConfig);
|
|
128
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
129
|
-
const contenido = `# config.toml de Codex CLI — gestionado parcialmente por swl-ses\n# Bloques delimitados por SWL-MCP-BEGIN/END son regenerables.\n\n${bloqueNuevo}\n`;
|
|
130
|
-
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
131
|
-
return { accion: 'creado', ruta: rutaConfig };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const idxBegin = existente.indexOf(beginTag);
|
|
135
|
-
const idxEnd = existente.indexOf(endTag);
|
|
136
|
-
|
|
137
|
-
// Caso 1: no existe el bloque → append al final
|
|
138
|
-
if (idxBegin === -1 || idxEnd === -1) {
|
|
139
|
-
const separador = existente.endsWith('\n') ? '\n' : '\n\n';
|
|
140
|
-
const contenido = existente + separador + bloqueNuevo + '\n';
|
|
141
|
-
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
142
|
-
return { accion: 'agregado', ruta: rutaConfig };
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Caso 2: existe — comparar contenido
|
|
146
|
-
// Calculamos fin REAL incluyendo el endTag completo.
|
|
147
|
-
const finBloqueExistente = idxEnd + endTag.length;
|
|
148
|
-
const bloqueExistente = existente.slice(idxBegin, finBloqueExistente);
|
|
149
|
-
|
|
150
|
-
if (bloqueExistente === bloqueNuevo) {
|
|
151
|
-
return { accion: 'sin-cambios', ruta: rutaConfig };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const contenido = existente.slice(0, idxBegin) + bloqueNuevo + existente.slice(finBloqueExistente);
|
|
155
|
-
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
156
|
-
return { accion: 'actualizado', ruta: rutaConfig };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Elimina un bloque MCP server por nombre. Idempotente: si no existe, no hace nada.
|
|
161
|
-
*
|
|
162
|
-
* @param {string} rutaConfig
|
|
163
|
-
* @param {string} name
|
|
164
|
-
* @returns {{ accion: 'eliminado' | 'sin-cambios', ruta: string }}
|
|
165
|
-
*/
|
|
166
|
-
function removeMcpServer(rutaConfig, name) {
|
|
167
|
-
let existente = '';
|
|
168
|
-
try {
|
|
169
|
-
existente = fs.readFileSync(rutaConfig, 'utf-8');
|
|
170
|
-
} catch (err) {
|
|
171
|
-
if (err.code === 'ENOENT') return { accion: 'sin-cambios', ruta: rutaConfig };
|
|
172
|
-
throw err;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const beginTag = `${BEGIN_PREFIX} ${name}`;
|
|
176
|
-
const endTag = `${END_PREFIX} ${name}`;
|
|
177
|
-
const idxBegin = existente.indexOf(beginTag);
|
|
178
|
-
const idxEnd = existente.indexOf(endTag);
|
|
179
|
-
|
|
180
|
-
if (idxBegin === -1 || idxEnd === -1) {
|
|
181
|
-
return { accion: 'sin-cambios', ruta: rutaConfig };
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Quitar bloque + posible newline previo y posterior (cosmético)
|
|
185
|
-
let inicio = idxBegin;
|
|
186
|
-
let fin = idxEnd + endTag.length;
|
|
187
|
-
// Comer un \n previo si existe (no comer doble \n para preservar separadores entre secciones)
|
|
188
|
-
if (inicio > 0 && existente[inicio - 1] === '\n') inicio--;
|
|
189
|
-
if (fin < existente.length && existente[fin] === '\n') fin++;
|
|
190
|
-
|
|
191
|
-
const contenido = existente.slice(0, inicio) + existente.slice(fin);
|
|
192
|
-
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
193
|
-
return { accion: 'eliminado', ruta: rutaConfig };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports = {
|
|
197
|
-
upsertMcpServer,
|
|
198
|
-
removeMcpServer,
|
|
199
|
-
serializarServidor,
|
|
200
|
-
// Para tests
|
|
201
|
-
_tomlString: tomlString,
|
|
202
|
-
BEGIN_PREFIX,
|
|
203
|
-
END_PREFIX,
|
|
204
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merge mínimo de secciones TOML — zero-deps.
|
|
5
|
+
*
|
|
6
|
+
* Opera sobre el formato concreto de `~/.codex/config.toml` (OpenAI Codex CLI):
|
|
7
|
+
* [mcp_servers.<name>]
|
|
8
|
+
* command = "node"
|
|
9
|
+
* args = ["...", "..."]
|
|
10
|
+
* [mcp_servers.<name>.env]
|
|
11
|
+
* KEY = "value"
|
|
12
|
+
*
|
|
13
|
+
* Reglas:
|
|
14
|
+
* - NUNCA reescribe el archivo entero. Solo agrega o reemplaza la sección
|
|
15
|
+
* `[mcp_servers.<name>]` indicada (incluyendo sub-tabla `.env`).
|
|
16
|
+
* - Si el archivo no existe lo crea con permisos 0600.
|
|
17
|
+
* - Si el archivo tiene comentarios o secciones desconocidas, las preserva.
|
|
18
|
+
* - Bloque "owned" delimitado por marcadores `# SWL-MCP-BEGIN <name>` /
|
|
19
|
+
* `# SWL-MCP-END <name>` para permitir actualizaciones idempotentes.
|
|
20
|
+
*
|
|
21
|
+
* NO soporta:
|
|
22
|
+
* - TOML completo (arrays multilínea complejos, inline tables, etc.)
|
|
23
|
+
* - Multi-section nested tables fuera de `mcp_servers.*`
|
|
24
|
+
*
|
|
25
|
+
* Si en el futuro Codex publica un comando idempotente `codex mcp add --idempotent`
|
|
26
|
+
* podemos delegarle el trabajo y deprecar este helper.
|
|
27
|
+
*
|
|
28
|
+
* @module scripts/lib/toml-merge
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
const path = require('path');
|
|
33
|
+
|
|
34
|
+
const { atomicWriteSync } = require('../../hooks/lib/atomic-write');
|
|
35
|
+
|
|
36
|
+
const BEGIN_PREFIX = '# SWL-MCP-BEGIN';
|
|
37
|
+
const END_PREFIX = '# SWL-MCP-END';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Serializa un servidor MCP en bloque TOML.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} name - Nombre del server (identificador en config.toml).
|
|
43
|
+
* @param {{ command: string, args?: string[], env?: Record<string,string> }} cfg
|
|
44
|
+
* @returns {string} Bloque TOML con marcadores.
|
|
45
|
+
*/
|
|
46
|
+
function serializarServidor(name, cfg) {
|
|
47
|
+
if (!name || typeof name !== 'string' || !/^[a-zA-Z0-9_-]+$/.test(name)) {
|
|
48
|
+
throw new Error(`Nombre de MCP server inválido: "${name}". Solo [a-zA-Z0-9_-].`);
|
|
49
|
+
}
|
|
50
|
+
if (!cfg || typeof cfg.command !== 'string' || cfg.command.length === 0) {
|
|
51
|
+
throw new Error(`MCP server "${name}" requiere "command" string no vacío.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const lineas = [];
|
|
55
|
+
lineas.push(`${BEGIN_PREFIX} ${name}`);
|
|
56
|
+
lineas.push(`[mcp_servers.${name}]`);
|
|
57
|
+
lineas.push(`command = ${tomlString(cfg.command)}`);
|
|
58
|
+
|
|
59
|
+
if (Array.isArray(cfg.args) && cfg.args.length > 0) {
|
|
60
|
+
const items = cfg.args.map(tomlString).join(', ');
|
|
61
|
+
lineas.push(`args = [${items}]`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (cfg.env && typeof cfg.env === 'object' && Object.keys(cfg.env).length > 0) {
|
|
65
|
+
lineas.push('');
|
|
66
|
+
lineas.push(`[mcp_servers.${name}.env]`);
|
|
67
|
+
for (const [k, v] of Object.entries(cfg.env)) {
|
|
68
|
+
if (typeof v !== 'string') {
|
|
69
|
+
throw new Error(`MCP server "${name}" env.${k} debe ser string (recibido: ${typeof v}).`);
|
|
70
|
+
}
|
|
71
|
+
// Solo claves alfanuméricas/_ en env names — TOML restricción razonable
|
|
72
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) {
|
|
73
|
+
throw new Error(`MCP server "${name}" env key inválido: "${k}".`);
|
|
74
|
+
}
|
|
75
|
+
lineas.push(`${k} = ${tomlString(v)}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
lineas.push(`${END_PREFIX} ${name}`);
|
|
80
|
+
return lineas.join('\n');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Escapa un string para TOML usando comillas dobles.
|
|
85
|
+
* No usa basic-string raw para evitar pitfalls con backslashes.
|
|
86
|
+
*/
|
|
87
|
+
function tomlString(s) {
|
|
88
|
+
// TOML basic string: escape backslash, doblequote, control chars.
|
|
89
|
+
const escapado = String(s)
|
|
90
|
+
.replace(/\\/g, '\\\\')
|
|
91
|
+
.replace(/"/g, '\\"')
|
|
92
|
+
.replace(/\n/g, '\\n')
|
|
93
|
+
.replace(/\r/g, '\\r')
|
|
94
|
+
.replace(/\t/g, '\\t');
|
|
95
|
+
return `"${escapado}"`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Inserta o actualiza un servidor MCP en `config.toml`.
|
|
100
|
+
*
|
|
101
|
+
* Idempotente: si el bloque ya existe con el mismo contenido, no escribe.
|
|
102
|
+
* Si existe con contenido distinto, lo reemplaza dentro de los marcadores.
|
|
103
|
+
* Si no existe, lo agrega al final del archivo precedido de línea en blanco.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} rutaConfig - Path absoluto a config.toml (típicamente ~/.codex/config.toml).
|
|
106
|
+
* @param {string} name - Nombre del MCP server (clave de [mcp_servers.<name>]).
|
|
107
|
+
* @param {{ command: string, args?: string[], env?: Record<string,string> }} cfg
|
|
108
|
+
* @returns {{ accion: 'creado' | 'agregado' | 'actualizado' | 'sin-cambios', ruta: string }}
|
|
109
|
+
*/
|
|
110
|
+
function upsertMcpServer(rutaConfig, name, cfg) {
|
|
111
|
+
const bloqueNuevo = serializarServidor(name, cfg);
|
|
112
|
+
|
|
113
|
+
let existente = '';
|
|
114
|
+
let existia = false;
|
|
115
|
+
try {
|
|
116
|
+
existente = fs.readFileSync(rutaConfig, 'utf-8');
|
|
117
|
+
existia = true;
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err.code !== 'ENOENT') throw err;
|
|
120
|
+
// Archivo no existe — se crea
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const beginTag = `${BEGIN_PREFIX} ${name}`;
|
|
124
|
+
const endTag = `${END_PREFIX} ${name}`;
|
|
125
|
+
|
|
126
|
+
if (!existia) {
|
|
127
|
+
const dir = path.dirname(rutaConfig);
|
|
128
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
129
|
+
const contenido = `# config.toml de Codex CLI — gestionado parcialmente por swl-ses\n# Bloques delimitados por SWL-MCP-BEGIN/END son regenerables.\n\n${bloqueNuevo}\n`;
|
|
130
|
+
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
131
|
+
return { accion: 'creado', ruta: rutaConfig };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const idxBegin = existente.indexOf(beginTag);
|
|
135
|
+
const idxEnd = existente.indexOf(endTag);
|
|
136
|
+
|
|
137
|
+
// Caso 1: no existe el bloque → append al final
|
|
138
|
+
if (idxBegin === -1 || idxEnd === -1) {
|
|
139
|
+
const separador = existente.endsWith('\n') ? '\n' : '\n\n';
|
|
140
|
+
const contenido = existente + separador + bloqueNuevo + '\n';
|
|
141
|
+
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
142
|
+
return { accion: 'agregado', ruta: rutaConfig };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Caso 2: existe — comparar contenido
|
|
146
|
+
// Calculamos fin REAL incluyendo el endTag completo.
|
|
147
|
+
const finBloqueExistente = idxEnd + endTag.length;
|
|
148
|
+
const bloqueExistente = existente.slice(idxBegin, finBloqueExistente);
|
|
149
|
+
|
|
150
|
+
if (bloqueExistente === bloqueNuevo) {
|
|
151
|
+
return { accion: 'sin-cambios', ruta: rutaConfig };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const contenido = existente.slice(0, idxBegin) + bloqueNuevo + existente.slice(finBloqueExistente);
|
|
155
|
+
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
156
|
+
return { accion: 'actualizado', ruta: rutaConfig };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Elimina un bloque MCP server por nombre. Idempotente: si no existe, no hace nada.
|
|
161
|
+
*
|
|
162
|
+
* @param {string} rutaConfig
|
|
163
|
+
* @param {string} name
|
|
164
|
+
* @returns {{ accion: 'eliminado' | 'sin-cambios', ruta: string }}
|
|
165
|
+
*/
|
|
166
|
+
function removeMcpServer(rutaConfig, name) {
|
|
167
|
+
let existente = '';
|
|
168
|
+
try {
|
|
169
|
+
existente = fs.readFileSync(rutaConfig, 'utf-8');
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (err.code === 'ENOENT') return { accion: 'sin-cambios', ruta: rutaConfig };
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const beginTag = `${BEGIN_PREFIX} ${name}`;
|
|
176
|
+
const endTag = `${END_PREFIX} ${name}`;
|
|
177
|
+
const idxBegin = existente.indexOf(beginTag);
|
|
178
|
+
const idxEnd = existente.indexOf(endTag);
|
|
179
|
+
|
|
180
|
+
if (idxBegin === -1 || idxEnd === -1) {
|
|
181
|
+
return { accion: 'sin-cambios', ruta: rutaConfig };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Quitar bloque + posible newline previo y posterior (cosmético)
|
|
185
|
+
let inicio = idxBegin;
|
|
186
|
+
let fin = idxEnd + endTag.length;
|
|
187
|
+
// Comer un \n previo si existe (no comer doble \n para preservar separadores entre secciones)
|
|
188
|
+
if (inicio > 0 && existente[inicio - 1] === '\n') inicio--;
|
|
189
|
+
if (fin < existente.length && existente[fin] === '\n') fin++;
|
|
190
|
+
|
|
191
|
+
const contenido = existente.slice(0, inicio) + existente.slice(fin);
|
|
192
|
+
atomicWriteSync(rutaConfig, contenido, 'utf8', { mode: 0o600 });
|
|
193
|
+
return { accion: 'eliminado', ruta: rutaConfig };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = {
|
|
197
|
+
upsertMcpServer,
|
|
198
|
+
removeMcpServer,
|
|
199
|
+
serializarServidor,
|
|
200
|
+
// Para tests
|
|
201
|
+
_tomlString: tomlString,
|
|
202
|
+
BEGIN_PREFIX,
|
|
203
|
+
END_PREFIX,
|
|
204
|
+
};
|
|
@@ -57,7 +57,7 @@ class TransformadorClaude extends TransformadorBase {
|
|
|
57
57
|
* - Documenta patrón "ask Claude to save to memory" del video oficial
|
|
58
58
|
*/
|
|
59
59
|
generarArchivoInstrucciones(contexto) {
|
|
60
|
-
const fecha = new Date().
|
|
60
|
+
const fecha = new Date().toLocaleDateString('sv');
|
|
61
61
|
const stack = contexto.dirProyecto
|
|
62
62
|
? this._detectarStackSeguro(contexto.dirProyecto)
|
|
63
63
|
: null;
|
|
@@ -223,7 +223,7 @@ class TransformadorCodex extends TransformadorBase {
|
|
|
223
223
|
*/
|
|
224
224
|
generarArchivoInstrucciones(contexto) {
|
|
225
225
|
const lineas = [];
|
|
226
|
-
const fecha = new Date().
|
|
226
|
+
const fecha = new Date().toLocaleDateString('sv');
|
|
227
227
|
|
|
228
228
|
lineas.push('## Sistema SWL — uso obligatorio (gestionado por swl-ses)');
|
|
229
229
|
lineas.push('');
|
|
@@ -46,7 +46,7 @@ class TransformadorCopilot extends TransformadorBase {
|
|
|
46
46
|
const lineas = [];
|
|
47
47
|
lineas.push('# Instrucciones del proyecto — SWL');
|
|
48
48
|
lineas.push('');
|
|
49
|
-
lineas.push(`> Generado por swl-ses v${contexto.version} — ${new Date().
|
|
49
|
+
lineas.push(`> Generado por swl-ses v${contexto.version} — ${new Date().toLocaleDateString('sv')}`);
|
|
50
50
|
lineas.push('> NO editar manualmente. Regenerar con: npx @saulwade/swl-ses@latest install --target copilot');
|
|
51
51
|
lineas.push('');
|
|
52
52
|
|
|
@@ -126,7 +126,7 @@ class TransformadorCursor extends TransformadorBase {
|
|
|
126
126
|
*/
|
|
127
127
|
generarArchivoInstrucciones(contexto) {
|
|
128
128
|
const lineas = [];
|
|
129
|
-
const fecha = new Date().
|
|
129
|
+
const fecha = new Date().toLocaleDateString('sv');
|
|
130
130
|
|
|
131
131
|
lineas.push('# Sistema SWL — agentes y referencia operativa (Cursor)');
|
|
132
132
|
lineas.push('');
|
|
@@ -45,7 +45,7 @@ class TransformadorGemini extends TransformadorBase {
|
|
|
45
45
|
const lineas = [];
|
|
46
46
|
lineas.push('# GEMINI.md — Sistema SWL');
|
|
47
47
|
lineas.push('');
|
|
48
|
-
lineas.push(`> Generado por swl-ses v${contexto.version} — ${new Date().
|
|
48
|
+
lineas.push(`> Generado por swl-ses v${contexto.version} — ${new Date().toLocaleDateString('sv')}`);
|
|
49
49
|
lineas.push('> NO editar manualmente. Regenerar con: npx @saulwade/swl-ses@latest install --target gemini');
|
|
50
50
|
lineas.push('');
|
|
51
51
|
lineas.push(`Este proyecto usa el sistema SWL con perfil "${contexto.perfil}".`);
|
|
@@ -55,7 +55,27 @@ class TransformadorGemini extends TransformadorBase {
|
|
|
55
55
|
lineas.push(`- Reglas: ${contexto.conteos.reglas}`);
|
|
56
56
|
lineas.push(`- Comandos: ${contexto.conteos.comandos}`);
|
|
57
57
|
lineas.push('');
|
|
58
|
-
lineas.push('Los agentes están en `.gemini/agents/`, los skills en `.gemini/skills
|
|
58
|
+
lineas.push('Los agentes están en `.gemini/agents/`, los skills en `.gemini/skills/`,');
|
|
59
|
+
lineas.push('las reglas en `.gemini/rules/` y los comandos en `.gemini/commands/swl/`.');
|
|
60
|
+
lineas.push('');
|
|
61
|
+
lineas.push('## Reglas de decisión del harness (resumen)');
|
|
62
|
+
lineas.push('');
|
|
63
|
+
lineas.push('1. **Idioma**: todo output en español de México (`rules/brevedad-output.md`).');
|
|
64
|
+
lineas.push('2. **Usar el sistema, no rodearlo**: si existe un agente, skill o comando SWL');
|
|
65
|
+
lineas.push(' aplicable a la tarea, usarlo es obligatorio — el trabajo directo con');
|
|
66
|
+
lineas.push(' herramientas básicas solo procede en las excepciones de `rules/usar-sistema-swl.md`');
|
|
67
|
+
lineas.push(' (tarea trivial de 1-2 archivos, lectura pura, override explícito del usuario).');
|
|
68
|
+
lineas.push('3. **Ciclo GSD con gates**: `discutir-fase` → `planear-fase` → `aprobar-plan`');
|
|
69
|
+
lineas.push(' (gate G1: lock SHA256) → `ejecutar-fase` → `verificar` (gate G4: trazabilidad');
|
|
70
|
+
lineas.push(' REQ→tarea→commit→test). Nunca ejecutar una fase sin plan aprobado ni');
|
|
71
|
+
lineas.push(' reportarla completa sin verificar.');
|
|
72
|
+
lineas.push('4. **Escalación**: acciones irreversibles (push, borrados fuera del working');
|
|
73
|
+
lineas.push(' tree, cambios de CI/infra) requieren aprobación humana; ante fallas, reportar');
|
|
74
|
+
lineas.push(' — nunca degradar en silencio (`rules/seguridad-agentes.md`).');
|
|
75
|
+
lineas.push('5. **Commits**: imperativo en español, atómicos, sin co-autores de IA.');
|
|
76
|
+
lineas.push('');
|
|
77
|
+
lineas.push('Si el proyecto tiene `AGENTS.md`, léelo — contiene la guía completa del');
|
|
78
|
+
lineas.push('harness (equipos de agentes, model-tier, catálogo de comandos).');
|
|
59
79
|
lineas.push('');
|
|
60
80
|
|
|
61
81
|
return {
|
|
@@ -46,7 +46,7 @@ class TransformadorOpenCode extends TransformadorBase {
|
|
|
46
46
|
const lineas = [];
|
|
47
47
|
lineas.push('# AGENTS.md — Sistema SWL');
|
|
48
48
|
lineas.push('');
|
|
49
|
-
lineas.push(`> Generado por swl-ses v${contexto.version} — ${new Date().
|
|
49
|
+
lineas.push(`> Generado por swl-ses v${contexto.version} — ${new Date().toLocaleDateString('sv')}`);
|
|
50
50
|
lineas.push('> NO editar manualmente. Regenerar con: npx @saulwade/swl-ses@latest install --target opencode');
|
|
51
51
|
lineas.push('');
|
|
52
52
|
lineas.push(`Este proyecto usa el sistema SWL con perfil "${contexto.perfil}".`);
|