Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 14x 4x 4x 4x 4x 4x 10x 10x 10x 10x 10x 10x 14x 17x 17x 17x 17x 17x 17x 5x 5x 5x 12x 12x 12x 10x 14x 4x 4x 4x 4x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 4x 2x 2x 2x 2x 4x 4x 4x 4x 4x 4x 4x 2x 2x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 5x 5x 5x 6x 4x 4x 3x 3x 3x 3x 3x 3x 3x 3x 4x 1x 1x 1x 1x 4x 5x 5x 6x 2x 2x 2x 6x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 5x 5x 6x 2x 2x 2x 6x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 5x 5x 6x 3x 3x 3x 6x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 3x 1x 1x 1x 1x 3x 6x 1x 1x 1x 1x 6x 6x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x 1x 1x 1x 3x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 3x 1x 1x 3x 3x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 5x 5x 3x 8x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 5x 4x 4x 1x 1x 1x 1x 1x | const fs = require("fs").promises;
const path = require("path");
const standardsIngestionMethods = {
/**
* Patrones que indican intentos de sobrescribir reglas base del revisor.
*/
_getForbiddenStandardsDirectives() {
return [
/ignore\s+(all|any|previous|prior|above)\s+instructions?/i,
/ignora(?:r)?\s+(todas?|las)\s+instrucciones/i,
/do\s+not\s+review\s+(the\s+)?pr/i,
/no\s+revis(?:es|ar)\s+(el\s+)?pr/i,
/skip\s+(the\s+)?review/i,
/omitir\s+(la\s+)?revision/i,
/approve\s+(automatically|always|everything)/i,
/aprueba(?:r)?\s+(siempre|automaticamente|todo)/i,
/everything\s+is\s+ok/i,
/todo\s+esta\s+bien/i,
/respond\s+with\s+approved\s+only/i,
/responde\s+solo\s+aprobado/i,
/analy[sz]e\s+(the\s+)?entire\s+repository/i,
/revis(?:a|ar)\s+(todo\s+el\s+repositorio|todo\s+el\s+codigo)/i,
/do\s+not\s+return\s+json/i,
/no\s+responder\s+en\s+json/i,
/use\s+markdown\s+instead\s+of\s+json/i,
/usa\s+markdown\s+en\s+lugar\s+de\s+json/i,
];
},
/**
* Sanitiza contenido de estandares para evitar contradicciones con skills base.
*/
_sanitizeStandardsAgainstSkillRules(content, sourceLabel = "General") {
if (typeof content !== "string" || content.length === 0) {
return {
content: "",
removedLines: 0,
};
}
const forbiddenPatterns = this._getForbiddenStandardsDirectives();
const lines = content.split(/\r?\n/);
const keptLines = [];
let removedLines = 0;
for (const line of lines) {
const trimmed = line.trim();
const isForbidden =
trimmed.length > 0 &&
forbiddenPatterns.some((pattern) => pattern.test(trimmed));
if (isForbidden) {
removedLines += 1;
continue;
}
keptLines.push(line);
}
if (removedLines > 0) {
this.logger.warn(
` ⚠️ Se removieron ${removedLines} linea(s) potencialmente contradictorias en estandares ${sourceLabel}.`,
);
}
return {
content: keptLines.join("\n"),
removedLines,
};
},
/**
* Sanitiza un payload de estandares por tecnologia.
*/
_sanitizeStandardsPayload(standardsContent = {}) {
if (!standardsContent || typeof standardsContent !== "object") {
return {};
}
const sanitized = {};
for (const [key, value] of Object.entries(standardsContent)) {
const { content } = this._sanitizeStandardsAgainstSkillRules(
String(value || ""),
key.toUpperCase(),
);
sanitized[key] = content;
}
return sanitized;
},
/**
* Lee los archivos de estándares desde rutas locales.
*/
async _readStandardsFiles(standardsPaths, technologies) {
const normalizedTechnologies = this._normalizeTechnologies(technologies);
const standards = {};
try {
if (
standardsPaths.sql &&
normalizedTechnologies.some(
(t) => t.includes("SQL") || t.includes("Database"),
)
) {
try {
const content = await this._readPathContent(standardsPaths.sql);
const sanitized = this._sanitizeStandardsAgainstSkillRules(
content,
"SQL",
);
standards.sql = sanitized.content;
this.logger.info(
` ✓ Estándares SQL cargados (${standards.sql.length} caracteres)`,
);
} catch (err) {
this.logger.error(
` ⚠️ No se pudo leer estándares SQL: ${err.message}`,
);
}
}
if (
standardsPaths.angular &&
normalizedTechnologies.some(
(t) => t.includes("Angular") || t.includes("TypeScript"),
)
) {
try {
const content = await this._readPathContent(standardsPaths.angular);
const sanitized = this._sanitizeStandardsAgainstSkillRules(
content,
"Angular",
);
standards.angular = sanitized.content;
this.logger.info(
` ✓ Estándares Angular cargados (${standards.angular.length} caracteres)`,
);
} catch (err) {
this.logger.error(
` ⚠️ No se pudo leer estándares Angular: ${err.message}`,
);
}
}
if (
standardsPaths.dotnet &&
normalizedTechnologies.some(
(t) => t.includes(".NET") || t.includes("C#"),
)
) {
try {
const content = await this._readPathContent(standardsPaths.dotnet);
const sanitized = this._sanitizeStandardsAgainstSkillRules(
content,
".NET",
);
standards.dotnet = sanitized.content;
this.logger.info(
` ✓ Estándares .NET cargados (${standards.dotnet.length} caracteres)`,
);
} catch (err) {
this.logger.error(
` ⚠️ No se pudo leer estándares .NET: ${err.message}`,
);
}
}
if (
standardsPaths.ssis &&
normalizedTechnologies.some(
(t) => t.includes("SSIS") || t.includes("ETL"),
)
) {
try {
const content = await this._readPathContent(standardsPaths.ssis);
const sanitized = this._sanitizeStandardsAgainstSkillRules(
content,
"SSIS",
);
standards.ssis = sanitized.content;
this.logger.info(
` ✓ Estándares SSIS cargados (${standards.ssis.length} caracteres)`,
);
} catch (err) {
this.logger.error(
` ⚠️ No se pudo leer estándares SSIS: ${err.message}`,
);
}
}
} catch (error) {
this.logger.error(
`⚠️ Error leyendo archivos de estándares: ${error.message}`,
);
}
return standards;
},
/**
* Lee el contenido de una ruta (archivo o directorio).
*/
async _readPathContent(pathToRead) {
const stats = await fs.stat(pathToRead);
if (stats.isFile()) {
const content = await fs.readFile(pathToRead, "utf-8");
const extracted = this._extractTextContent(content, pathToRead);
return this._truncateContent(extracted, 2000);
}
if (stats.isDirectory()) {
const files = await fs.readdir(pathToRead);
const supportedExtensions = [
".txt",
".md",
".docx",
".doc",
".html",
".htm",
];
let combinedContent = "";
for (const file of files) {
const filePath = path.join(pathToRead, file);
const fileExt = path.extname(file).toLowerCase();
if (supportedExtensions.includes(fileExt)) {
try {
const fileStats = await fs.stat(filePath);
if (fileStats.isFile()) {
const content = await fs.readFile(filePath, "utf-8");
const extracted = this._extractTextContent(content, filePath);
combinedContent += `\n\n--- ${file} ---\n${extracted}`;
this.logger.info(` ↳ Archivo leído: ${file}`);
}
} catch (err) {
this.logger.error(` ⚠️ Error leyendo ${file}: ${err.message}`);
}
}
}
return this._truncateContent(combinedContent, 5000);
}
throw new Error("La ruta no es ni archivo ni directorio");
},
/**
* Extrae contenido de texto de archivos soportados.
*/
_extractTextContent(content, filePath) {
const ext = path.extname(filePath).toLowerCase();
if (ext === ".txt" || ext === ".md") {
return content;
}
if (ext === ".html" || ext === ".htm") {
return content
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "")
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "")
.replace(/<[^>]+>/g, " ")
.replace(/ /g, " ")
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/\s+/g, " ")
.trim();
}
return content;
},
/**
* Trunca el contenido a un tamaño máximo.
*/
_truncateContent(content, maxLength) {
if (content.length <= maxLength) {
return content;
}
return content.substring(0, maxLength) + "\n\n... (contenido truncado) ...";
},
};
module.exports = standardsIngestionMethods;
|