decision-guardian 1.1.0
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/LICENSE +21 -0
- package/README.md +792 -0
- package/dist/adapters/github/actions-logger.js +88 -0
- package/dist/adapters/github/comment.js +601 -0
- package/dist/adapters/github/github-provider.js +260 -0
- package/dist/adapters/github/health.js +56 -0
- package/dist/adapters/local/console-logger.js +46 -0
- package/dist/adapters/local/local-git-provider.js +247 -0
- package/dist/cli/commands/check.js +134 -0
- package/dist/cli/commands/init.js +58 -0
- package/dist/cli/commands/template.js +70 -0
- package/dist/cli/formatter.js +68 -0
- package/dist/cli/index.js +12458 -0
- package/dist/cli/licenses.txt +143 -0
- package/dist/cli/paths.js +40 -0
- package/dist/core/content-matchers.js +333 -0
- package/dist/core/health.js +52 -0
- package/dist/core/interfaces/index.js +2 -0
- package/dist/core/interfaces/logger.js +2 -0
- package/dist/core/interfaces/scm-provider.js +5 -0
- package/dist/core/logger.js +20 -0
- package/dist/core/matcher.js +184 -0
- package/dist/core/metrics.js +87 -0
- package/dist/core/parser.js +338 -0
- package/dist/core/rule-evaluator.js +186 -0
- package/dist/core/rule-parser.js +211 -0
- package/dist/core/rule-types.js +22 -0
- package/dist/core/trie.js +83 -0
- package/dist/core/types.js +2 -0
- package/dist/index.js +61142 -0
- package/dist/licenses.txt +758 -0
- package/dist/main.js +290 -0
- package/dist/telemetry/payload.js +25 -0
- package/dist/telemetry/privacy.js +37 -0
- package/dist/telemetry/sender.js +40 -0
- package/dist/version.js +7 -0
- package/package.json +60 -0
- package/templates/advanced-rules.md +94 -0
- package/templates/api.md +70 -0
- package/templates/basic.md +38 -0
- package/templates/database.md +81 -0
- package/templates/security.md +89 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
balanced-match
|
|
2
|
+
MIT
|
|
3
|
+
(MIT)
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
8
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
9
|
+
the Software without restriction, including without limitation the rights to
|
|
10
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
11
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
12
|
+
so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
brace-expansion
|
|
27
|
+
MIT
|
|
28
|
+
MIT License
|
|
29
|
+
|
|
30
|
+
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
in the Software without restriction, including without limitation the rights
|
|
35
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
furnished to do so, subject to the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be included in all
|
|
40
|
+
copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
SOFTWARE.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
minimatch
|
|
52
|
+
ISC
|
|
53
|
+
The ISC License
|
|
54
|
+
|
|
55
|
+
Copyright (c) 2011-2023 Isaac Z. Schlueter and Contributors
|
|
56
|
+
|
|
57
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
58
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
59
|
+
copyright notice and this permission notice appear in all copies.
|
|
60
|
+
|
|
61
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
62
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
63
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
64
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
65
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
66
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
67
|
+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
parse-diff
|
|
71
|
+
MIT
|
|
72
|
+
The MIT License (MIT)
|
|
73
|
+
|
|
74
|
+
Copyright (c) 2014 Sergey Todyshev
|
|
75
|
+
|
|
76
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
77
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
78
|
+
the Software without restriction, including without limitation the rights to
|
|
79
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
80
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
81
|
+
subject to the following conditions:
|
|
82
|
+
|
|
83
|
+
The above copyright notice and this permission notice shall be included in all
|
|
84
|
+
copies or substantial portions of the Software.
|
|
85
|
+
|
|
86
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
87
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
88
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
89
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
90
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
91
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
regexp-tree
|
|
95
|
+
MIT
|
|
96
|
+
MIT License
|
|
97
|
+
|
|
98
|
+
Copyright (c) 2017 Dmitry Soshnikov
|
|
99
|
+
|
|
100
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
101
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
102
|
+
in the Software without restriction, including without limitation the rights
|
|
103
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
104
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
105
|
+
furnished to do so, subject to the following conditions:
|
|
106
|
+
|
|
107
|
+
The above copyright notice and this permission notice shall be included in all
|
|
108
|
+
copies or substantial portions of the Software.
|
|
109
|
+
|
|
110
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
111
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
112
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
113
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
114
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
115
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
116
|
+
SOFTWARE.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
safe-regex
|
|
120
|
+
MIT
|
|
121
|
+
Copyright 2019-present is held by the authors of the safe-regex module.
|
|
122
|
+
|
|
123
|
+
This software is released under the MIT license:
|
|
124
|
+
|
|
125
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
126
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
127
|
+
the Software without restriction, including without limitation the rights to
|
|
128
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
129
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
130
|
+
subject to the following conditions:
|
|
131
|
+
|
|
132
|
+
The above copyright notice and this permission notice shall be included in all
|
|
133
|
+
copies or substantial portions of the Software.
|
|
134
|
+
|
|
135
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
136
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
137
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
138
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
139
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
140
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
141
|
+
|
|
142
|
+
Original author: James Halliday @substack
|
|
143
|
+
Maintainer: James C. (Jamie) Davis @davisjam
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getTemplatesDir = getTemplatesDir;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
function getTemplatesDir() {
|
|
39
|
+
return path.join(__dirname, '..', '..', 'templates');
|
|
40
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ContentMatchers = void 0;
|
|
40
|
+
/**
|
|
41
|
+
* Content Matchers - Match content patterns within file diffs
|
|
42
|
+
*/
|
|
43
|
+
const parse_diff_1 = __importDefault(require("parse-diff"));
|
|
44
|
+
const safe_regex_1 = __importDefault(require("safe-regex"));
|
|
45
|
+
const vm_1 = __importDefault(require("vm"));
|
|
46
|
+
const logger_1 = require("./logger");
|
|
47
|
+
const crypto = __importStar(require("crypto"));
|
|
48
|
+
class ContentMatchers {
|
|
49
|
+
resultCache = new Map();
|
|
50
|
+
MAX_CACHE_SIZE = 500;
|
|
51
|
+
logger;
|
|
52
|
+
constructor(logger) {
|
|
53
|
+
this.logger = logger;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Match string patterns in changed lines
|
|
57
|
+
*/
|
|
58
|
+
matchString(rule, fileDiff) {
|
|
59
|
+
const changedLines = this.getChangedLines(fileDiff.patch);
|
|
60
|
+
const matchedPatterns = [];
|
|
61
|
+
for (const pattern of rule.patterns || []) {
|
|
62
|
+
if (changedLines.some((line) => line.includes(pattern))) {
|
|
63
|
+
matchedPatterns.push(pattern);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
matched: matchedPatterns.length > 0,
|
|
68
|
+
matchedPatterns,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Match regex pattern in changed content
|
|
73
|
+
*/
|
|
74
|
+
async matchRegex(rule, fileDiff) {
|
|
75
|
+
if (rule.pattern && !(0, safe_regex_1.default)(rule.pattern)) {
|
|
76
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Security] Unsafe regex pattern rejected`, {
|
|
77
|
+
pattern: rule.pattern,
|
|
78
|
+
});
|
|
79
|
+
return { matched: false, matchedPatterns: [] };
|
|
80
|
+
}
|
|
81
|
+
const ALLOWED_FLAGS = /^[gimsuy]*$/;
|
|
82
|
+
if (rule.flags && !ALLOWED_FLAGS.test(rule.flags)) {
|
|
83
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Security] Invalid regex flags rejected`, {
|
|
84
|
+
flags: rule.flags,
|
|
85
|
+
});
|
|
86
|
+
return { matched: false, matchedPatterns: [] };
|
|
87
|
+
}
|
|
88
|
+
const changedContent = this.getChangedLines(fileDiff.patch).join('\n');
|
|
89
|
+
const MAX_CONTENT_SIZE = 1024 * 1024;
|
|
90
|
+
if (changedContent.length > MAX_CONTENT_SIZE) {
|
|
91
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Security] Content exceeds size limit`, {
|
|
92
|
+
size: changedContent.length,
|
|
93
|
+
limit: MAX_CONTENT_SIZE,
|
|
94
|
+
});
|
|
95
|
+
return { matched: false, matchedPatterns: [] };
|
|
96
|
+
}
|
|
97
|
+
if (rule.pattern && rule.pattern.length > 1000) {
|
|
98
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Security] Regex pattern too complex`, {
|
|
99
|
+
length: rule.pattern.length,
|
|
100
|
+
});
|
|
101
|
+
return { matched: false, matchedPatterns: [] };
|
|
102
|
+
}
|
|
103
|
+
const cacheKey = this.createCacheKey(rule.pattern, rule.flags || '', changedContent);
|
|
104
|
+
const cached = this.resultCache.get(cacheKey);
|
|
105
|
+
if (cached !== undefined) {
|
|
106
|
+
return {
|
|
107
|
+
matched: cached,
|
|
108
|
+
matchedPatterns: cached ? [rule.pattern] : [],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const matched = this.runRegexWithTimeout(rule.pattern, rule.flags, changedContent, 5000);
|
|
113
|
+
this.updateCache(cacheKey, matched);
|
|
114
|
+
return {
|
|
115
|
+
matched,
|
|
116
|
+
matchedPatterns: matched ? [rule.pattern] : [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const errorMessage = String(error);
|
|
121
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `Regex check failed for pattern`, {
|
|
122
|
+
pattern: rule.pattern,
|
|
123
|
+
error: errorMessage,
|
|
124
|
+
});
|
|
125
|
+
// Fail closed: treat error/timeout as a match (security risk)
|
|
126
|
+
return {
|
|
127
|
+
matched: false,
|
|
128
|
+
matchedPatterns: [`Regex check failed: ${errorMessage}`],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Run Regex in a VM sandbox with timeout
|
|
134
|
+
*/
|
|
135
|
+
runRegexWithTimeout(pattern, flags, text, timeoutMs) {
|
|
136
|
+
const sandbox = Object.create(null);
|
|
137
|
+
sandbox.result = false;
|
|
138
|
+
sandbox.text = String(text);
|
|
139
|
+
sandbox.pattern = String(pattern);
|
|
140
|
+
sandbox.flags = String(flags || '');
|
|
141
|
+
const context = vm_1.default.createContext(sandbox, {
|
|
142
|
+
name: 'RegexSandbox',
|
|
143
|
+
codeGeneration: {
|
|
144
|
+
strings: false,
|
|
145
|
+
wasm: false,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const code = `
|
|
149
|
+
'use strict';
|
|
150
|
+
try {
|
|
151
|
+
const regex = new RegExp(pattern, flags);
|
|
152
|
+
result = regex.test(text);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
result = false;
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
vm_1.default.runInContext(code, context, {
|
|
158
|
+
timeout: timeoutMs,
|
|
159
|
+
displayErrors: false,
|
|
160
|
+
});
|
|
161
|
+
return Boolean(sandbox.result);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Match if changes occur within specified line range
|
|
165
|
+
*/
|
|
166
|
+
matchLineRange(rule, fileDiff) {
|
|
167
|
+
const changedLineNumbers = this.extractChangedLineNumbers(fileDiff.patch);
|
|
168
|
+
const matched = changedLineNumbers.some((lineNum) => lineNum >= rule.start && lineNum <= rule.end);
|
|
169
|
+
return {
|
|
170
|
+
matched,
|
|
171
|
+
matchedPatterns: matched ? [`lines ${rule.start}-${rule.end}`] : [],
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Full file mode - any change to the file matches
|
|
176
|
+
*/
|
|
177
|
+
matchFullFile(_fileDiff) {
|
|
178
|
+
return {
|
|
179
|
+
matched: true,
|
|
180
|
+
matchedPatterns: ['full_file'],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* JSON path mode - check if specific JSON keys changed
|
|
185
|
+
*
|
|
186
|
+
* Improved heuristic: all keys in the dotted path must appear as
|
|
187
|
+
* `"key"\s*:` in the changed lines, and each subsequent key must
|
|
188
|
+
* appear at a line number >= the previous key's line number.
|
|
189
|
+
* This enforces hierarchical ordering without needing the full file.
|
|
190
|
+
*/
|
|
191
|
+
matchJsonPath(rule, fileDiff) {
|
|
192
|
+
const changedLines = this.getChangedLinesWithNumbers(fileDiff.patch);
|
|
193
|
+
const matchedPatterns = [];
|
|
194
|
+
for (const jsonPath of rule.paths || []) {
|
|
195
|
+
const keys = jsonPath.split('.');
|
|
196
|
+
let minLine = -1;
|
|
197
|
+
let allKeysFound = true;
|
|
198
|
+
for (const key of keys) {
|
|
199
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
200
|
+
const keyRegex = new RegExp(`"${escapedKey}"\\s*:`);
|
|
201
|
+
// Find the first matching line at or after minLine
|
|
202
|
+
const match = changedLines.find((line) => line.lineNumber >= minLine && keyRegex.test(line.content));
|
|
203
|
+
if (match) {
|
|
204
|
+
minLine = match.lineNumber;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
allKeysFound = false;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (allKeysFound) {
|
|
212
|
+
matchedPatterns.push(jsonPath);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
matched: matchedPatterns.length > 0,
|
|
217
|
+
matchedPatterns,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
createCacheKey(pattern, flags, content) {
|
|
221
|
+
const contentHash = crypto.createHash('sha256').update(content).digest('hex').substring(0, 16);
|
|
222
|
+
return `${pattern}:${flags}:${contentHash}`;
|
|
223
|
+
}
|
|
224
|
+
updateCache(key, value) {
|
|
225
|
+
if (this.resultCache.size >= this.MAX_CACHE_SIZE) {
|
|
226
|
+
const toEvict = Math.floor(this.MAX_CACHE_SIZE * 0.1);
|
|
227
|
+
const iterator = this.resultCache.keys();
|
|
228
|
+
for (let i = 0; i < toEvict; i++) {
|
|
229
|
+
const firstKey = iterator.next().value;
|
|
230
|
+
if (firstKey)
|
|
231
|
+
this.resultCache.delete(firstKey);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
this.resultCache.set(key, value);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Extract changed (added) lines from diff using parse-diff
|
|
238
|
+
*/
|
|
239
|
+
getChangedLines(patch) {
|
|
240
|
+
if (!patch)
|
|
241
|
+
return [];
|
|
242
|
+
try {
|
|
243
|
+
const fullDiff = `diff --git a/file b/file
|
|
244
|
+
--- a/file
|
|
245
|
+
+++ b/file
|
|
246
|
+
${patch}`;
|
|
247
|
+
const parsed = (0, parse_diff_1.default)(fullDiff);
|
|
248
|
+
const lines = [];
|
|
249
|
+
for (const file of parsed) {
|
|
250
|
+
for (const chunk of file.chunks) {
|
|
251
|
+
for (const change of chunk.changes) {
|
|
252
|
+
if (change.type === 'add') {
|
|
253
|
+
lines.push(change.content.substring(1));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return lines;
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Parsing] Failed to parse diff content`, {
|
|
262
|
+
error: String(error),
|
|
263
|
+
});
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Extract line numbers of changed lines using parse-diff
|
|
269
|
+
*/
|
|
270
|
+
extractChangedLineNumbers(patch) {
|
|
271
|
+
if (!patch)
|
|
272
|
+
return [];
|
|
273
|
+
try {
|
|
274
|
+
const fullDiff = `diff --git a/file b/file
|
|
275
|
+
--- a/file
|
|
276
|
+
+++ b/file
|
|
277
|
+
${patch}`;
|
|
278
|
+
const parsed = (0, parse_diff_1.default)(fullDiff);
|
|
279
|
+
const lineNumbers = [];
|
|
280
|
+
for (const file of parsed) {
|
|
281
|
+
for (const chunk of file.chunks) {
|
|
282
|
+
for (const change of chunk.changes) {
|
|
283
|
+
if (change.type === 'add' && change.ln) {
|
|
284
|
+
lineNumbers.push(change.ln);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return lineNumbers;
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Parsing] Failed to parse diff line numbers`, {
|
|
293
|
+
error: String(error),
|
|
294
|
+
});
|
|
295
|
+
return [];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Extract changed lines with their line numbers using parse-diff
|
|
300
|
+
*/
|
|
301
|
+
getChangedLinesWithNumbers(patch) {
|
|
302
|
+
if (!patch)
|
|
303
|
+
return [];
|
|
304
|
+
try {
|
|
305
|
+
const fullDiff = `diff --git a/file b/file
|
|
306
|
+
--- a/file
|
|
307
|
+
+++ b/file
|
|
308
|
+
${patch}`;
|
|
309
|
+
const parsed = (0, parse_diff_1.default)(fullDiff);
|
|
310
|
+
const lines = [];
|
|
311
|
+
for (const file of parsed) {
|
|
312
|
+
for (const chunk of file.chunks) {
|
|
313
|
+
for (const change of chunk.changes) {
|
|
314
|
+
if (change.type === 'add' && change.ln) {
|
|
315
|
+
lines.push({
|
|
316
|
+
content: change.content.substring(1),
|
|
317
|
+
lineNumber: change.ln,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return lines;
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
(0, logger_1.logStructured)(this.logger, 'warning', `[Parsing] Failed to parse diff content with line numbers`, {
|
|
327
|
+
error: String(error),
|
|
328
|
+
});
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
exports.ContentMatchers = ContentMatchers;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.checkDecisionFileExists = checkDecisionFileExists;
|
|
37
|
+
/**
|
|
38
|
+
* Core health checks — platform-agnostic portion.
|
|
39
|
+
*/
|
|
40
|
+
const fs = __importStar(require("fs/promises"));
|
|
41
|
+
/**
|
|
42
|
+
* Check if a decision file or directory exists and is accessible.
|
|
43
|
+
*/
|
|
44
|
+
async function checkDecisionFileExists(filePath) {
|
|
45
|
+
try {
|
|
46
|
+
await fs.access(filePath);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logStructured = logStructured;
|
|
4
|
+
/**
|
|
5
|
+
* Log structured data using the provided logger instance.
|
|
6
|
+
*/
|
|
7
|
+
function logStructured(logger, level, message, context) {
|
|
8
|
+
const logMessage = context ? `${message} | ${JSON.stringify(context)}` : message;
|
|
9
|
+
switch (level) {
|
|
10
|
+
case 'info':
|
|
11
|
+
logger.info(logMessage);
|
|
12
|
+
break;
|
|
13
|
+
case 'warning':
|
|
14
|
+
logger.warning(logMessage);
|
|
15
|
+
break;
|
|
16
|
+
case 'error':
|
|
17
|
+
logger.error(logMessage);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|