Spaces:
Paused
Paused
File size: 7,750 Bytes
440cddf | 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 | "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.configLoader = exports.PrixConfigLoader = exports.DEFAULT_PRIX_CONFIG = void 0;
exports.getConfig = getConfig;
exports.meetsConfidenceThreshold = meetsConfidenceThreshold;
exports.meetsMinimumSeverity = meetsMinimumSeverity;
exports.lintSuggestion = lintSuggestion;
const fs_1 = require("fs");
const path_1 = require("path");
const context_1 = require("./context");
const utils_1 = require("./utils");
exports.DEFAULT_PRIX_CONFIG = {
version: '1.0',
severity: {
minimumLevel: 'minor',
showConfidenceThreshold: 50
},
filters: {
excludePatterns: [],
includePatterns: ['**/*'],
disableTypes: []
},
linting: {
enabled: true,
eslint: true,
prettier: true,
failOnError: false
},
review: {
maxFilesPerPR: 50,
maxCommentsPerFile: 10,
denseMode: false,
showImpactAnalysis: true
},
remedies: {
enabled: false,
autoCreatePR: false,
requireApproval: true
},
confidence: {
minCritical: 0,
minMajor: 60,
minMinor: 70,
minInfo: 80
}
};
class PrixConfigLoader {
config = null;
load(workingDir) {
if (this.config) {
return this.config;
}
const possiblePaths = [
(0, path_1.join)(workingDir, '.prix.yml'),
(0, path_1.join)(workingDir, 'prix.yml'),
(0, path_1.join)(workingDir, '.prix.yaml'),
(0, path_1.join)(workingDir, 'prix.yaml')
];
for (const configPath of possiblePaths) {
if ((0, fs_1.existsSync)(configPath)) {
try {
const content = (0, fs_1.readFileSync)(configPath, 'utf8');
this.config = this.mergeWithDefaults(this.parseYAML(content));
return this.config;
}
catch (e) {
console.warn(`Failed to load prix config from ${configPath}: ${e}`);
}
}
}
this.config = exports.DEFAULT_PRIX_CONFIG;
return this.config;
}
parseYAML(content) {
const result = {};
const lines = content.split('\n');
let currentSection = null;
let currentSectionObj = {};
let sectionKey = '';
for (const line of lines) {
const sectionMatch = line.match(/^(\w+):\s*$/);
if (sectionMatch) {
if (currentSection && sectionKey) {
;
result[sectionKey] = currentSectionObj;
}
currentSection = sectionMatch[1];
sectionKey = currentSection;
currentSectionObj = {};
continue;
}
const keyValueMatch = line.match(/^\s*(\w+):\s*(.+)$/);
if (keyValueMatch && currentSection) {
const key = keyValueMatch[1];
let value = keyValueMatch[2].trim();
if (value === 'true')
value = true;
else if (value === 'false')
value = false;
else if (!isNaN(Number(value)))
value = Number(value);
currentSectionObj[key] = value;
}
}
if (currentSection && sectionKey) {
;
result[sectionKey] = currentSectionObj;
}
return result;
}
mergeWithDefaults(config) {
return {
version: config.version || exports.DEFAULT_PRIX_CONFIG.version,
severity: {
...exports.DEFAULT_PRIX_CONFIG.severity,
...config.severity
},
filters: {
...exports.DEFAULT_PRIX_CONFIG.filters,
...config.filters
},
linting: {
...exports.DEFAULT_PRIX_CONFIG.linting,
...config.linting
},
review: {
...exports.DEFAULT_PRIX_CONFIG.review,
...config.review
},
remedies: {
...exports.DEFAULT_PRIX_CONFIG.remedies,
...config.remedies
},
confidence: {
...exports.DEFAULT_PRIX_CONFIG.confidence,
...config.confidence
}
};
}
shouldIncludeFile(config, filename) {
const { excludePatterns, includePatterns } = config.filters;
for (const pattern of excludePatterns) {
if (this.matchesPattern(filename, pattern)) {
return false;
}
}
if (includePatterns.length === 0) {
return true;
}
for (const pattern of includePatterns) {
if (this.matchesPattern(filename, pattern)) {
return true;
}
}
return false;
}
matchesPattern(filename, pattern) {
const regexPattern = pattern
.replace(/\./g, '\\.')
.replace(/\*/g, '.*')
.replace(/\?/g, '.')
.replace(/\*\*/g, '.*');
return new RegExp(`^${regexPattern}$`).test(filename);
}
}
exports.PrixConfigLoader = PrixConfigLoader;
exports.configLoader = new PrixConfigLoader();
function getConfig() {
const ctx = context_1.als.getStore();
const workingDir = ctx?.workingDir || process.cwd();
return exports.configLoader.load(workingDir);
}
function meetsConfidenceThreshold(severity, confidence) {
const config = getConfig();
const thresholds = config.confidence;
switch (severity) {
case 'critical':
return confidence >= thresholds.minCritical;
case 'major':
return confidence >= thresholds.minMajor;
case 'minor':
return confidence >= thresholds.minMinor;
case 'info':
return confidence >= thresholds.minInfo;
default:
return true;
}
}
function meetsMinimumSeverity(severity) {
const config = getConfig();
const levels = ['critical', 'major', 'minor', 'info'];
const minimumLevel = config.severity.minimumLevel;
const minimumIndex = levels.indexOf(minimumLevel);
const severityIndex = levels.indexOf(severity.toLowerCase());
return severityIndex >= minimumIndex;
}
async function lintSuggestion(suggestion, filename, language) {
const config = getConfig();
if (!config.linting.enabled) {
return { valid: true, errors: [] };
}
const errors = [];
const workingDir = context_1.als.getStore()?.workingDir || process.cwd();
if (config.linting.prettier) {
try {
(0, utils_1.prixExec)(`echo "${suggestion.replace(/"/g, '\\"')}" | prettier --stdin-filepath ${filename}`, {
cwd: workingDir,
stdio: 'pipe'
});
}
catch {
errors.push('Prettier formatting check failed');
}
}
if (config.linting.eslint &&
(language === 'javascript' || language === 'typescript')) {
try {
const ext = filename.endsWith('.ts') ? 'ts' : 'js';
const tempFile = `.prix_temp_suggestion.${ext}`;
(0, utils_1.prixExec)(`echo "${suggestion.replace(/"/g, '\\"')}" > ${tempFile} && npx eslint ${tempFile} --format json 2>&1 || true`, {
cwd: workingDir,
stdio: 'pipe'
});
}
catch {
errors.push('ESLint check failed');
}
}
return {
valid: config.linting.failOnError ? errors.length === 0 : true,
errors
};
}
//# sourceMappingURL=config.js.map |