@interlace/eslint-devkit 1.9.0 → 1.11.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.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/src/aria-definitions.js +1 -990
  4. package/src/ast/ast-utils.js +1 -133
  5. package/src/ast/index.js +1 -17
  6. package/src/ast-node-types.js +1 -174
  7. package/src/index.js +1 -43
  8. package/src/messaging/config.js +1 -98
  9. package/src/messaging/constants.js +1 -678
  10. package/src/messaging/formatters-ai.js +2 -176
  11. package/src/messaging/formatters-v2.js +10 -212
  12. package/src/messaging/formatters.js +3 -186
  13. package/src/messaging/index.js +1 -21
  14. package/src/messaging/types-v2.js +1 -2
  15. package/src/messaging/types.js +1 -2
  16. package/src/node/fs.js +1 -104
  17. package/src/node/index.js +1 -19
  18. package/src/node/os.js +1 -52
  19. package/src/node/path.js +1 -143
  20. package/src/resolver/dependency-analysis.js +1 -740
  21. package/src/resolver/index.js +1 -20
  22. package/src/resolver/resolver-adapter.js +1 -92
  23. package/src/resolver/resolver-detection.js +1 -189
  24. package/src/resolver/resolver.js +1 -206
  25. package/src/resolver.js +1 -17
  26. package/src/rule-creation/browser-escape-hatch-rule.js +1 -100
  27. package/src/rule-creation/hardcoded-credentials-rule.js +1 -143
  28. package/src/rule-creation/index.d.ts +2 -0
  29. package/src/rule-creation/index.js +1 -26
  30. package/src/rule-creation/mass-assignment-rule.js +1 -121
  31. package/src/rule-creation/message-source.d.ts +95 -0
  32. package/src/rule-creation/message-source.js +1 -0
  33. package/src/rule-creation/mock-context.js +1 -39
  34. package/src/rule-creation/raw-identifier-rule.js +1 -140
  35. package/src/rule-creation/require-tls-rule.js +1 -190
  36. package/src/rule-creation/rule-creator.js +1 -70
  37. package/src/rule-creation/sdk-api-key-rule.js +1 -121
  38. package/src/rule-creation/sql-injection-rule.js +1 -207
  39. package/src/rule-creation/system-prompt-injection-rule.d.ts +78 -0
  40. package/src/rule-creation/system-prompt-injection-rule.js +1 -0
  41. package/src/rule-creation/unscoped-mutation-rule.js +1 -234
  42. package/src/security/index.js +1 -17
  43. package/src/security/security-utils.js +1 -461
  44. package/src/types/index.js +1 -18
  45. package/src/types/meta-augmentation.js +1 -2
  46. package/src/types/type-utils.js +1 -222
@@ -1,176 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildASTSelector = buildASTSelector;
4
- exports.formatAgentMessage = formatAgentMessage;
5
- exports.formatMessageNextGen = formatMessageNextGen;
6
- exports.formatLLMMessageNextGen = formatLLMMessageNextGen;
7
- const constants_1 = require("./constants");
8
- const config_1 = require("./config");
9
- function buildASTSelector(node, maxDepth = 3) {
10
- const parts = [];
11
- let current = node;
12
- let depth = 0;
13
- while (current && depth < maxDepth) {
14
- const selector = buildNodeSelector(current);
15
- if (selector) {
16
- parts.unshift(selector);
17
- }
18
- if (isAnchorNode(current.type)) {
19
- break;
20
- }
21
- current = current.parent;
22
- depth++;
23
- }
24
- return parts.join(' ');
25
- }
26
- function buildNodeSelector(node) {
27
- switch (node.type) {
28
- case 'CallExpression':
29
- if (node.callee?.name) {
30
- return `CallExpression[callee.name='${node.callee.name}']`;
31
- }
32
- if (node.callee?.property?.name) {
33
- return `CallExpression[callee.property.name='${node.callee.property.name}']`;
34
- }
35
- return 'CallExpression';
36
- case 'MethodDefinition':
37
- if (node.key?.name) {
38
- return `MethodDefinition[key.name='${node.key.name}']`;
39
- }
40
- return 'MethodDefinition';
41
- case 'FunctionDeclaration':
42
- if (node.id?.name) {
43
- return `FunctionDeclaration[id.name='${node.id.name}']`;
44
- }
45
- return 'FunctionDeclaration';
46
- case 'ClassDeclaration':
47
- if (node.id?.name) {
48
- return `ClassDeclaration[id.name='${node.id.name}']`;
49
- }
50
- return 'ClassDeclaration';
51
- case 'VariableDeclarator':
52
- if (node.id?.name) {
53
- return `VariableDeclarator[id.name='${node.id.name}']`;
54
- }
55
- return 'VariableDeclarator';
56
- case 'MemberExpression':
57
- return 'MemberExpression';
58
- case 'Identifier':
59
- if (node.name) {
60
- return `Identifier[name='${node.name}']`;
61
- }
62
- return 'Identifier';
63
- default:
64
- return node.type;
65
- }
66
- }
67
- function isAnchorNode(type) {
68
- return [
69
- 'FunctionDeclaration',
70
- 'FunctionExpression',
71
- 'ArrowFunctionExpression',
72
- 'MethodDefinition',
73
- 'ClassDeclaration',
74
- 'ClassExpression',
75
- 'Program',
76
- ].includes(type);
77
- }
78
- function enrichFromCWE(options) {
79
- if (!options.cwe)
80
- return options;
81
- const cweData = constants_1.CWE_MAPPING[options.cwe];
82
- if (!cweData)
83
- return options;
84
- return {
85
- ...options,
86
- owasp: options.owasp ?? cweData.owasp,
87
- cvss: options.cvss ?? cweData.cvss,
88
- compliance: options.compliance ?? constants_1.CWE_COMPLIANCE_MAPPING[options.cwe],
89
- };
90
- }
91
- function formatAgentMessage(options, compress = false) {
92
- const enriched = enrichFromCWE(options);
93
- if (compress) {
94
- return JSON.stringify({
95
- id: enriched.cwe ?? enriched.ruleId,
96
- s: (0, constants_1.severityToCVSS)(enriched.severity),
97
- desc: enriched.description,
98
- fix: enriched.fix,
99
- ast: options.astSelector,
100
- refs: [enriched.documentationLink],
101
- });
102
- }
103
- return JSON.stringify({
104
- ruleId: enriched.ruleId ?? enriched.cwe,
105
- severity: enriched.severity,
106
- description: enriched.description,
107
- fixInstruction: enriched.fix,
108
- astTarget: options.astSelector,
109
- hints: options.aiHints,
110
- benchmarks: {
111
- cwe: enriched.cwe,
112
- owasp: enriched.owasp,
113
- cvss: enriched.cvss,
114
- },
115
- documentation: enriched.documentationLink,
116
- });
117
- }
118
- function formatHumanMessage(options, includeHints = false) {
119
- const enriched = enrichFromCWE(options);
120
- const { icon, cwe, description, severity, fix, documentationLink } = enriched;
121
- const owasp = enriched.owasp;
122
- const cvss = enriched.cvss;
123
- const compliance = enriched.compliance;
124
- const standards = [];
125
- if (cwe)
126
- standards.push(cwe);
127
- if (owasp) {
128
- const owaspCode = owasp.split(':')[0];
129
- const owaspDetails = constants_1.OWASP_DETAILS[owasp];
130
- const owaspName = owaspDetails?.name?.split(' ')[0] || '';
131
- standards.push(`OWASP:${owaspCode}-${owaspName}`);
132
- }
133
- if (cvss !== undefined)
134
- standards.push(`CVSS:${cvss}`);
135
- const standardsPart = standards.length > 0 ? `${standards.join(' ')} | ` : '';
136
- const compliancePart = compliance && compliance.length > 0
137
- ? ` [${compliance.slice(0, 4).join(',')}]`
138
- : '';
139
- const firstLine = `${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;
140
- let secondLine = ` Fix: ${fix} | ${documentationLink}`;
141
- if (includeHints) {
142
- const agentOptions = options;
143
- if (agentOptions.astSelector || agentOptions.aiHints) {
144
- const hints = [
145
- agentOptions.astSelector ? `Target: ${agentOptions.astSelector}` : '',
146
- ...(agentOptions.aiHints ?? []),
147
- ]
148
- .filter(Boolean)
149
- .join('; ');
150
- secondLine += ` <!-- AI_HINT: ${hints} -->`;
151
- }
152
- }
153
- return `${firstLine}\n${secondLine}`;
154
- }
155
- function formatMessageNextGen(options, context) {
156
- const mode = (0, config_1.resolveAIMode)(context);
157
- const compress = (0, config_1.resolveCompression)(context);
158
- switch (mode) {
159
- case 'AGENT_JSON':
160
- return formatAgentMessage(options, compress);
161
- case 'IDE_CURSOR':
162
- return formatHumanMessage(options, true);
163
- case 'CI':
164
- case 'CLI':
165
- default:
166
- return formatHumanMessage(options, false);
167
- }
168
- }
169
- function formatLLMMessageNextGen(options) {
170
- const mode = (0, config_1.getAIMessagingMode)();
171
- const compress = (0, config_1.isTokenCompressionEnabled)();
172
- if (mode === 'AGENT_JSON') {
173
- return formatAgentMessage(options, compress);
174
- }
175
- return formatHumanMessage(options, mode === 'IDE_CURSOR');
176
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.buildASTSelector=buildASTSelector;exports.formatAgentMessage=formatAgentMessage;exports.formatMessageNextGen=formatMessageNextGen;exports.formatLLMMessageNextGen=formatLLMMessageNextGen;const constants_1=require("./constants");const config_1=require("./config");function buildASTSelector(node,maxDepth=3){const parts=[];let current=node;let depth=0;while(current&&depth<maxDepth){const selector=buildNodeSelector(current);if(selector){parts.unshift(selector)}if(isAnchorNode(current.type)){break}current=current.parent;depth++}return parts.join(" ")}function buildNodeSelector(node){switch(node.type){case"CallExpression":if(node.callee?.name){return`CallExpression[callee.name='${node.callee.name}']`}if(node.callee?.property?.name){return`CallExpression[callee.property.name='${node.callee.property.name}']`}return"CallExpression";case"MethodDefinition":if(node.key?.name){return`MethodDefinition[key.name='${node.key.name}']`}return"MethodDefinition";case"FunctionDeclaration":if(node.id?.name){return`FunctionDeclaration[id.name='${node.id.name}']`}return"FunctionDeclaration";case"ClassDeclaration":if(node.id?.name){return`ClassDeclaration[id.name='${node.id.name}']`}return"ClassDeclaration";case"VariableDeclarator":if(node.id?.name){return`VariableDeclarator[id.name='${node.id.name}']`}return"VariableDeclarator";case"MemberExpression":return"MemberExpression";case"Identifier":if(node.name){return`Identifier[name='${node.name}']`}return"Identifier";default:return node.type}}function isAnchorNode(type){return["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","MethodDefinition","ClassDeclaration","ClassExpression","Program"].includes(type)}function enrichFromCWE(options){if(!options.cwe)return options;const cweData=constants_1.CWE_MAPPING[options.cwe];if(!cweData)return options;return{...options,owasp:options.owasp??cweData.owasp,cvss:options.cvss??cweData.cvss,compliance:options.compliance??constants_1.CWE_COMPLIANCE_MAPPING[options.cwe]}}function formatAgentMessage(options,compress=false){const enriched=enrichFromCWE(options);if(compress){return JSON.stringify({id:enriched.cwe??enriched.ruleId,s:(0,constants_1.severityToCVSS)(enriched.severity),desc:enriched.description,fix:enriched.fix,ast:options.astSelector,refs:[enriched.documentationLink]})}return JSON.stringify({ruleId:enriched.ruleId??enriched.cwe,severity:enriched.severity,description:enriched.description,fixInstruction:enriched.fix,astTarget:options.astSelector,hints:options.aiHints,benchmarks:{cwe:enriched.cwe,owasp:enriched.owasp,cvss:enriched.cvss},documentation:enriched.documentationLink})}function formatHumanMessage(options,includeHints=false){const enriched=enrichFromCWE(options);const{icon,cwe,description,severity,fix,documentationLink}=enriched;const owasp=enriched.owasp;const cvss=enriched.cvss;const compliance=enriched.compliance;const standards=[];if(cwe)standards.push(cwe);if(owasp){const owaspCode=owasp.split(":")[0];const owaspDetails=constants_1.OWASP_DETAILS[owasp];const owaspName=owaspDetails?.name?.split(" ")[0]||"";standards.push(`OWASP:${owaspCode}-${owaspName}`)}if(cvss!==void 0)standards.push(`CVSS:${cvss}`);const standardsPart=standards.length>0?`${standards.join(" ")} | `:"";const compliancePart=compliance&&compliance.length>0?` [${compliance.slice(0,4).join(",")}]`:"";const firstLine=`${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;let secondLine=` Fix: ${fix} | ${documentationLink}`;if(includeHints){const agentOptions=options;if(agentOptions.astSelector||agentOptions.aiHints){const hints=[agentOptions.astSelector?`Target: ${agentOptions.astSelector}`:"",...agentOptions.aiHints??[]].filter(Boolean).join("; ");secondLine+=` <!-- AI_HINT: ${hints} -->`}}return`${firstLine}
2
+ ${secondLine}`}function formatMessageNextGen(options,context){const mode=(0,config_1.resolveAIMode)(context);const compress=(0,config_1.resolveCompression)(context);switch(mode){case"AGENT_JSON":return formatAgentMessage(options,compress);case"IDE_CURSOR":return formatHumanMessage(options,true);case"CI":case"CLI":default:return formatHumanMessage(options,false)}}function formatLLMMessageNextGen(options){const mode=(0,config_1.getAIMessagingMode)();const compress=(0,config_1.isTokenCompressionEnabled)();if(mode==="AGENT_JSON"){return formatAgentMessage(options,compress)}return formatHumanMessage(options,mode==="IDE_CURSOR")}
@@ -1,212 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatSecurityMessage = formatSecurityMessage;
4
- exports.formatCodeQualityMessage = formatCodeQualityMessage;
5
- exports.formatPerformanceMessage = formatPerformanceMessage;
6
- const constants_1 = require("./constants");
7
- const CATEGORY_ICONS = {
8
- security: '🔒',
9
- 'circular-dependency': '🔄',
10
- 'unused-import': '🧹',
11
- 'barrel-file': '📦',
12
- 'dependency-boundary': '🚧',
13
- 'import-order': '📋',
14
- 'naming-convention': '✏️',
15
- 'dead-code': '💀',
16
- performance: '⚡',
17
- };
18
- const SEVERITY_SHORT = {
19
- CRITICAL: 'CRIT',
20
- HIGH: 'HIGH',
21
- MEDIUM: 'MED',
22
- LOW: 'LOW',
23
- INFO: 'INFO',
24
- };
25
- function renderWhy(why) {
26
- return why ? `\n Why: ${why}` : '';
27
- }
28
- function renderExamples(vulnerable, safe) {
29
- const parts = [];
30
- if (vulnerable)
31
- parts.push(` ✗ ${vulnerable}`);
32
- if (safe)
33
- parts.push(` ✓ ${safe}`);
34
- return parts.length > 0 ? '\n' + parts.join('\n') : '';
35
- }
36
- function renderInlineExamples(vulnerable, safe) {
37
- const parts = [];
38
- if (vulnerable)
39
- parts.push(`✗ ${vulnerable}`);
40
- if (safe)
41
- parts.push(`✓ ${safe}`);
42
- return parts.length > 0 ? ' | ' + parts.join(' ') : '';
43
- }
44
- function renderDocs(docs) {
45
- return docs ? ` | ${docs}` : '';
46
- }
47
- function enrichSecurity(options) {
48
- if (!options.cwe)
49
- return options;
50
- const cweData = constants_1.CWE_MAPPING[options.cwe];
51
- if (!cweData)
52
- return options;
53
- return {
54
- ...options,
55
- owasp: options.owasp ?? cweData.owasp,
56
- cvss: options.cvss ?? cweData.cvss,
57
- compliance: options.compliance ?? constants_1.CWE_COMPLIANCE_MAPPING[options.cwe],
58
- };
59
- }
60
- function buildStandards(cwe, owasp, cvss) {
61
- const parts = [];
62
- if (cwe)
63
- parts.push(cwe);
64
- if (owasp) {
65
- const owaspCode = owasp.split(':')[0];
66
- const owaspDetails = constants_1.OWASP_DETAILS[owasp];
67
- const owaspName = owaspDetails?.name?.split(' ')[0] || '';
68
- parts.push(`OWASP:${owaspCode}-${owaspName}`);
69
- }
70
- if (cvss !== undefined)
71
- parts.push(`CVSS:${cvss}`);
72
- return parts.length > 0 ? `${parts.join(' ')} | ` : '';
73
- }
74
- function buildCompactStandards(cwe, cvss) {
75
- const parts = [];
76
- if (cwe)
77
- parts.push(cwe);
78
- if (cvss !== undefined)
79
- parts.push(`${cvss}`);
80
- return parts.length > 0 ? `${parts.join(' ')} ` : '';
81
- }
82
- function buildCompliance(compliance) {
83
- return compliance && compliance.length > 0
84
- ? ` [${compliance.slice(0, 4).join(',')}]`
85
- : '';
86
- }
87
- function formatSecurityMessage(options, mode = 'human') {
88
- const enriched = enrichSecurity(options);
89
- if (mode === 'agent') {
90
- return securityToAgentJSON(enriched);
91
- }
92
- if (mode === 'compact') {
93
- return securityToCompact(enriched);
94
- }
95
- return securityToHuman(enriched);
96
- }
97
- function securityToHuman(enriched) {
98
- const { cwe, owasp, cvss, compliance, description, severity, fix, docs, why, vulnerable, safe } = enriched;
99
- const icon = CATEGORY_ICONS['security'];
100
- const standardsPart = buildStandards(cwe, owasp, cvss);
101
- const compliancePart = buildCompliance(compliance);
102
- const line1 = `${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;
103
- const whyLine = renderWhy(why);
104
- const fixLine = `\n Fix: ${fix}${renderDocs(docs)}`;
105
- const examples = renderExamples(vulnerable, safe);
106
- return `${line1}${whyLine}${fixLine}${examples}`;
107
- }
108
- function securityToCompact(enriched) {
109
- const { cwe, cvss, description, severity, fix, vulnerable, safe } = enriched;
110
- const sev = SEVERITY_SHORT[severity] || severity;
111
- const std = buildCompactStandards(cwe, cvss);
112
- const examples = renderInlineExamples(vulnerable, safe);
113
- return `${std}${description} | ${sev}\n Fix: ${fix}${examples}`;
114
- }
115
- function securityToAgentJSON(enriched) {
116
- const obj = {
117
- id: enriched.cwe,
118
- cvss: enriched.cvss ?? (0, constants_1.severityToCVSS)(enriched.severity),
119
- description: enriched.description,
120
- fix: enriched.fix,
121
- };
122
- if (enriched.vulnerable)
123
- obj['bad'] = enriched.vulnerable;
124
- if (enriched.safe)
125
- obj['good'] = enriched.safe;
126
- return JSON.stringify(obj);
127
- }
128
- function formatCodeQualityMessage(options, mode = 'human') {
129
- if (mode === 'agent') {
130
- return codeQualityToAgentJSON(options);
131
- }
132
- if (mode === 'compact') {
133
- return codeQualityToCompact(options);
134
- }
135
- return codeQualityToHuman(options);
136
- }
137
- function codeQualityToHuman(options) {
138
- const { category, description, severity, fix, docs, why, cycle, vulnerable, safe } = options;
139
- const icon = CATEGORY_ICONS[category] || '📐';
140
- const line1 = `${icon} ${description} | ${severity}`;
141
- const whyLine = renderWhy(why);
142
- const fixLine = `\n Fix: ${fix}${renderDocs(docs)}`;
143
- const examples = renderExamples(vulnerable, safe);
144
- const cycleLine = cycle && cycle.length > 0
145
- ? `\n Cycle: ${cycle.join(' → ')}`
146
- : '';
147
- return `${line1}${whyLine}${fixLine}${examples}${cycleLine}`;
148
- }
149
- function codeQualityToCompact(options) {
150
- const { description, severity, fix, vulnerable, safe, cycle } = options;
151
- const sev = SEVERITY_SHORT[severity] || severity;
152
- const examples = renderInlineExamples(vulnerable, safe);
153
- const cycleSuffix = cycle && cycle.length > 0
154
- ? ` [${cycle.map(f => f.split('/').pop()).join('→')}]`
155
- : '';
156
- return `${description} | ${sev}\n Fix: ${fix}${examples}${cycleSuffix}`;
157
- }
158
- function codeQualityToAgentJSON(options) {
159
- const obj = {
160
- category: options.category,
161
- description: options.description,
162
- fix: options.fix,
163
- };
164
- if (options.cycle)
165
- obj['cycle'] = options.cycle;
166
- if (options.vulnerable)
167
- obj['bad'] = options.vulnerable;
168
- if (options.safe)
169
- obj['good'] = options.safe;
170
- return JSON.stringify(obj);
171
- }
172
- function formatPerformanceMessage(options, mode = 'human') {
173
- if (mode === 'agent') {
174
- return performanceToAgentJSON(options);
175
- }
176
- if (mode === 'compact') {
177
- return performanceToCompact(options);
178
- }
179
- return performanceToHuman(options);
180
- }
181
- function performanceToHuman(options) {
182
- const { description, severity, fix, docs, why, vulnerable, safe, impact } = options;
183
- const icon = CATEGORY_ICONS['performance'];
184
- const line1 = `${icon} ${description} | ${severity}`;
185
- const whyLine = renderWhy(why);
186
- const fixLine = `\n Fix: ${fix}${renderDocs(docs)}`;
187
- const impactLine = impact
188
- ? `\n Impact: ${impact.current} → ${impact.optimized}`
189
- : '';
190
- const examples = renderExamples(vulnerable, safe);
191
- return `${line1}${whyLine}${fixLine}${impactLine}${examples}`;
192
- }
193
- function performanceToCompact(options) {
194
- const { description, severity, fix, vulnerable, safe, impact } = options;
195
- const sev = SEVERITY_SHORT[severity] || severity;
196
- const impactSuffix = impact ? ` (${impact.current}→${impact.optimized})` : '';
197
- const examples = renderInlineExamples(vulnerable, safe);
198
- return `${description} | ${sev}${impactSuffix}\n Fix: ${fix}${examples}`;
199
- }
200
- function performanceToAgentJSON(options) {
201
- const obj = {
202
- description: options.description,
203
- fix: options.fix,
204
- };
205
- if (options.impact)
206
- obj['impact'] = { current: options.impact.current, optimized: options.impact.optimized };
207
- if (options.vulnerable)
208
- obj['bad'] = options.vulnerable;
209
- if (options.safe)
210
- obj['good'] = options.safe;
211
- return JSON.stringify(obj);
212
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatSecurityMessage=formatSecurityMessage;exports.formatCodeQualityMessage=formatCodeQualityMessage;exports.formatPerformanceMessage=formatPerformanceMessage;const constants_1=require("./constants");const CATEGORY_ICONS={security:"\u{1F512}","circular-dependency":"\u{1F504}","unused-import":"\u{1F9F9}","barrel-file":"\u{1F4E6}","dependency-boundary":"\u{1F6A7}","import-order":"\u{1F4CB}","naming-convention":"\u270F\uFE0F","dead-code":"\u{1F480}",performance:"\u26A1"};const SEVERITY_SHORT={CRITICAL:"CRIT",HIGH:"HIGH",MEDIUM:"MED",LOW:"LOW",INFO:"INFO"};function renderWhy(why){return why?`
2
+ Why: ${why}`:""}function renderExamples(vulnerable,safe){const parts=[];if(vulnerable)parts.push(` \u2717 ${vulnerable}`);if(safe)parts.push(` \u2713 ${safe}`);return parts.length>0?"\n"+parts.join("\n"):""}function renderInlineExamples(vulnerable,safe){const parts=[];if(vulnerable)parts.push(`\u2717 ${vulnerable}`);if(safe)parts.push(`\u2713 ${safe}`);return parts.length>0?" | "+parts.join(" "):""}function renderDocs(docs){return docs?` | ${docs}`:""}function enrichSecurity(options){if(!options.cwe)return options;const cweData=constants_1.CWE_MAPPING[options.cwe];if(!cweData)return options;return{...options,owasp:options.owasp??cweData.owasp,cvss:options.cvss??cweData.cvss,compliance:options.compliance??constants_1.CWE_COMPLIANCE_MAPPING[options.cwe]}}function buildStandards(cwe,owasp,cvss){const parts=[];if(cwe)parts.push(cwe);if(owasp){const owaspCode=owasp.split(":")[0];const owaspDetails=constants_1.OWASP_DETAILS[owasp];const owaspName=owaspDetails?.name?.split(" ")[0]||"";parts.push(`OWASP:${owaspCode}-${owaspName}`)}if(cvss!==void 0)parts.push(`CVSS:${cvss}`);return parts.length>0?`${parts.join(" ")} | `:""}function buildCompactStandards(cwe,cvss){const parts=[];if(cwe)parts.push(cwe);if(cvss!==void 0)parts.push(`${cvss}`);return parts.length>0?`${parts.join(" ")} `:""}function buildCompliance(compliance){return compliance&&compliance.length>0?` [${compliance.slice(0,4).join(",")}]`:""}function formatSecurityMessage(options,mode="human"){const enriched=enrichSecurity(options);if(mode==="agent"){return securityToAgentJSON(enriched)}if(mode==="compact"){return securityToCompact(enriched)}return securityToHuman(enriched)}function securityToHuman(enriched){const{cwe,owasp,cvss,compliance,description,severity,fix,docs,why,vulnerable,safe}=enriched;const icon=CATEGORY_ICONS["security"];const standardsPart=buildStandards(cwe,owasp,cvss);const compliancePart=buildCompliance(compliance);const line1=`${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;const whyLine=renderWhy(why);const fixLine=`
3
+ Fix: ${fix}${renderDocs(docs)}`;const examples=renderExamples(vulnerable,safe);return`${line1}${whyLine}${fixLine}${examples}`}function securityToCompact(enriched){const{cwe,cvss,description,severity,fix,vulnerable,safe}=enriched;const sev=SEVERITY_SHORT[severity]||severity;const std=buildCompactStandards(cwe,cvss);const examples=renderInlineExamples(vulnerable,safe);return`${std}${description} | ${sev}
4
+ Fix: ${fix}${examples}`}function securityToAgentJSON(enriched){const obj={id:enriched.cwe,cvss:enriched.cvss??(0,constants_1.severityToCVSS)(enriched.severity),description:enriched.description,fix:enriched.fix};if(enriched.vulnerable)obj["bad"]=enriched.vulnerable;if(enriched.safe)obj["good"]=enriched.safe;return JSON.stringify(obj)}function formatCodeQualityMessage(options,mode="human"){if(mode==="agent"){return codeQualityToAgentJSON(options)}if(mode==="compact"){return codeQualityToCompact(options)}return codeQualityToHuman(options)}function codeQualityToHuman(options){const{category,description,severity,fix,docs,why,cycle,vulnerable,safe}=options;const icon=CATEGORY_ICONS[category]||"\u{1F4D0}";const line1=`${icon} ${description} | ${severity}`;const whyLine=renderWhy(why);const fixLine=`
5
+ Fix: ${fix}${renderDocs(docs)}`;const examples=renderExamples(vulnerable,safe);const cycleLine=cycle&&cycle.length>0?`
6
+ Cycle: ${cycle.join(" \u2192 ")}`:"";return`${line1}${whyLine}${fixLine}${examples}${cycleLine}`}function codeQualityToCompact(options){const{description,severity,fix,vulnerable,safe,cycle}=options;const sev=SEVERITY_SHORT[severity]||severity;const examples=renderInlineExamples(vulnerable,safe);const cycleSuffix=cycle&&cycle.length>0?` [${cycle.map(f=>f.split("/").pop()).join("\u2192")}]`:"";return`${description} | ${sev}
7
+ Fix: ${fix}${examples}${cycleSuffix}`}function codeQualityToAgentJSON(options){const obj={category:options.category,description:options.description,fix:options.fix};if(options.cycle)obj["cycle"]=options.cycle;if(options.vulnerable)obj["bad"]=options.vulnerable;if(options.safe)obj["good"]=options.safe;return JSON.stringify(obj)}function formatPerformanceMessage(options,mode="human"){if(mode==="agent"){return performanceToAgentJSON(options)}if(mode==="compact"){return performanceToCompact(options)}return performanceToHuman(options)}function performanceToHuman(options){const{description,severity,fix,docs,why,vulnerable,safe,impact}=options;const icon=CATEGORY_ICONS["performance"];const line1=`${icon} ${description} | ${severity}`;const whyLine=renderWhy(why);const fixLine=`
8
+ Fix: ${fix}${renderDocs(docs)}`;const impactLine=impact?`
9
+ Impact: ${impact.current} \u2192 ${impact.optimized}`:"";const examples=renderExamples(vulnerable,safe);return`${line1}${whyLine}${fixLine}${impactLine}${examples}`}function performanceToCompact(options){const{description,severity,fix,vulnerable,safe,impact}=options;const sev=SEVERITY_SHORT[severity]||severity;const impactSuffix=impact?` (${impact.current}\u2192${impact.optimized})`:"";const examples=renderInlineExamples(vulnerable,safe);return`${description} | ${sev}${impactSuffix}
10
+ Fix: ${fix}${examples}`}function performanceToAgentJSON(options){const obj={description:options.description,fix:options.fix};if(options.impact)obj["impact"]={current:options.impact.current,optimized:options.impact.optimized};if(options.vulnerable)obj["bad"]=options.vulnerable;if(options.safe)obj["good"]=options.safe;return JSON.stringify(obj)}
@@ -1,186 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatLLMMessage = formatLLMMessage;
4
- exports.formatLLMMessageTemplate = formatLLMMessageTemplate;
5
- exports.getSecurityBenchmarks = getSecurityBenchmarks;
6
- exports.registerMessageTemplate = registerMessageTemplate;
7
- exports.getMessageTemplate = getMessageTemplate;
8
- exports.listMessageTemplates = listMessageTemplates;
9
- exports.clearMessageTemplates = clearMessageTemplates;
10
- exports.formatWithTemplate = formatWithTemplate;
11
- exports.toSARIF = toSARIF;
12
- const constants_1 = require("./constants");
13
- function enrichFromCWE(options) {
14
- if (!options.cwe)
15
- return options;
16
- const cweData = constants_1.CWE_MAPPING[options.cwe];
17
- if (!cweData)
18
- return options;
19
- return {
20
- ...options,
21
- owasp: options.owasp ?? cweData.owasp,
22
- cvss: options.cvss ?? cweData.cvss,
23
- compliance: options.compliance ?? constants_1.CWE_COMPLIANCE_MAPPING[options.cwe],
24
- };
25
- }
26
- function formatLLMMessage(options) {
27
- const enriched = enrichFromCWE(options);
28
- const { icon, cwe, description, severity, fix, documentationLink } = enriched;
29
- const owasp = enriched.owasp;
30
- const cvss = enriched.cvss;
31
- const compliance = enriched.compliance;
32
- const standards = [];
33
- if (cwe)
34
- standards.push(cwe);
35
- if (owasp) {
36
- const owaspCode = owasp.split(':')[0];
37
- const owaspDetails = constants_1.OWASP_DETAILS[owasp];
38
- const owaspName = owaspDetails?.name?.split(' ')[0] || '';
39
- standards.push(`OWASP:${owaspCode}-${owaspName}`);
40
- }
41
- if (cvss !== undefined)
42
- standards.push(`CVSS:${cvss}`);
43
- const standardsPart = standards.length > 0 ? `${standards.join(' ')} | ` : '';
44
- const compliancePart = compliance && compliance.length > 0
45
- ? ` [${compliance.slice(0, 4).join(',')}]`
46
- : '';
47
- const firstLine = `${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;
48
- const secondLine = ` Fix: ${fix} | ${documentationLink}`;
49
- return `${firstLine}\n${secondLine}`;
50
- }
51
- function formatLLMMessageTemplate(options) {
52
- return formatLLMMessage(options);
53
- }
54
- function getSecurityBenchmarks(cwe) {
55
- const cweData = constants_1.CWE_MAPPING[cwe];
56
- if (!cweData)
57
- return undefined;
58
- const owaspDetails = constants_1.OWASP_DETAILS[cweData.owasp];
59
- return {
60
- owasp: cweData.owasp,
61
- owaspName: owaspDetails.name,
62
- owaspLink: owaspDetails.link,
63
- cvss: cweData.cvss,
64
- severity: cweData.severity,
65
- name: cweData.name,
66
- compliance: constants_1.CWE_COMPLIANCE_MAPPING[cwe] ?? [],
67
- };
68
- }
69
- const templateRegistry = new Map();
70
- function registerMessageTemplate(name, config) {
71
- templateRegistry.set(name, config);
72
- }
73
- function getMessageTemplate(name) {
74
- return templateRegistry.get(name);
75
- }
76
- function listMessageTemplates() {
77
- return Array.from(templateRegistry.keys());
78
- }
79
- function clearMessageTemplates() {
80
- templateRegistry.clear();
81
- }
82
- function replacePlaceholders(template, values) {
83
- return template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
84
- return values[key] ?? match;
85
- });
86
- }
87
- function formatWithTemplate(options) {
88
- const templateConfig = options.templateConfig ??
89
- (options.templateName
90
- ? getMessageTemplate(options.templateName)
91
- : undefined);
92
- if (!templateConfig) {
93
- return formatLLMMessage(options);
94
- }
95
- const enriched = enrichFromCWE(options);
96
- const owasp = enriched.owasp;
97
- const cvss = enriched.cvss ??
98
- (0, constants_1.severityToCVSS)(enriched.severity);
99
- const compliance = enriched.compliance ?? [];
100
- let jiraUrl = '';
101
- if (templateConfig.jiraTemplate && options.jiraData) {
102
- jiraUrl = replacePlaceholders(templateConfig.jiraTemplate, {
103
- summary: encodeURIComponent(options.jiraData.summary ?? options.description),
104
- priority: options.jiraData.priority ?? 'Medium',
105
- labels: options.jiraData.labels?.join(',') ?? '',
106
- project: options.jiraData.project ?? 'SEC',
107
- description: encodeURIComponent(options.description),
108
- });
109
- }
110
- let confluenceUrl = '';
111
- if (templateConfig.confluenceTemplate) {
112
- confluenceUrl = replacePlaceholders(templateConfig.confluenceTemplate, {
113
- cwe: options.cwe ?? '',
114
- owasp: owasp ?? '',
115
- });
116
- }
117
- const owaspDisplay = owasp ? `OWASP:${owasp.split(':')[0]}` : '';
118
- const allCompliance = [
119
- ...compliance,
120
- ...(templateConfig.customCompliance ?? []),
121
- ];
122
- const complianceDisplay = allCompliance.length > 0 ? `[${allCompliance.slice(0, 4).join(',')}]` : '';
123
- const placeholderValues = {
124
- icon: enriched.icon,
125
- cwe: enriched.cwe,
126
- owasp: owaspDisplay,
127
- cvss: `CVSS:${cvss}`,
128
- severity: enriched.severity,
129
- description: enriched.description,
130
- compliance: complianceDisplay,
131
- fix: enriched.fix,
132
- documentation: enriched.documentationLink,
133
- jira: jiraUrl,
134
- confluence: confluenceUrl,
135
- organization: templateConfig.organizationName ?? '',
136
- ...templateConfig.customMetadata,
137
- ...options.customPlaceholders,
138
- };
139
- const line1Template = templateConfig.line1Format ??
140
- '{{icon}} {{cwe}} {{owasp}} {{cvss}} | {{description}} | {{severity}} {{compliance}}';
141
- const line2Template = templateConfig.line2Format ?? ' Fix: {{fix}} | {{documentation}}';
142
- const line1 = replacePlaceholders(line1Template, placeholderValues)
143
- .replace(/\s+\|/g, ' |')
144
- .replace(/\|\s+\|/g, '|')
145
- .replace(/\s{2,}/g, ' ')
146
- .trim();
147
- const line2 = replacePlaceholders(line2Template, placeholderValues)
148
- .replace(/\s+\|/g, ' |')
149
- .replace(/\|\s+\|/g, '|')
150
- .replace(/\s{2,}/g, ' ')
151
- .trim();
152
- return `${line1}\n${line2}`;
153
- }
154
- function toSARIF(options) {
155
- const enriched = enrichFromCWE(options);
156
- return {
157
- ruleId: options.ruleId ||
158
- options.cwe ||
159
- options.issueName.replace(/\s+/g, '-').toLowerCase(),
160
- level: severityToSARIFLevel(enriched.severity),
161
- message: { text: enriched.description },
162
- properties: {
163
- 'security-severity': enriched.cvss?.toString() ??
164
- (0, constants_1.severityToCVSS)(enriched.severity).toString(),
165
- cwe: enriched.cwe,
166
- owasp: enriched.owasp,
167
- cvss: enriched.cvss ?? (0, constants_1.severityToCVSS)(enriched.severity),
168
- compliance: enriched.compliance,
169
- fix: enriched.fix,
170
- },
171
- };
172
- }
173
- function severityToSARIFLevel(severity) {
174
- switch (severity) {
175
- case 'CRITICAL':
176
- case 'HIGH':
177
- return 'error';
178
- case 'MEDIUM':
179
- return 'warning';
180
- case 'LOW':
181
- case 'INFO':
182
- return 'note';
183
- default:
184
- return 'none';
185
- }
186
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.formatLLMMessage=formatLLMMessage;exports.formatLLMMessageTemplate=formatLLMMessageTemplate;exports.getSecurityBenchmarks=getSecurityBenchmarks;exports.registerMessageTemplate=registerMessageTemplate;exports.getMessageTemplate=getMessageTemplate;exports.listMessageTemplates=listMessageTemplates;exports.clearMessageTemplates=clearMessageTemplates;exports.formatWithTemplate=formatWithTemplate;exports.toSARIF=toSARIF;const constants_1=require("./constants");function enrichFromCWE(options){if(!options.cwe)return options;const cweData=constants_1.CWE_MAPPING[options.cwe];if(!cweData)return options;return{...options,owasp:options.owasp??cweData.owasp,cvss:options.cvss??cweData.cvss,compliance:options.compliance??constants_1.CWE_COMPLIANCE_MAPPING[options.cwe]}}function formatLLMMessage(options){const enriched=enrichFromCWE(options);const{icon,cwe,description,severity,fix,documentationLink}=enriched;const owasp=enriched.owasp;const cvss=enriched.cvss;const compliance=enriched.compliance;const standards=[];if(cwe)standards.push(cwe);if(owasp){const owaspCode=owasp.split(":")[0];const owaspDetails=constants_1.OWASP_DETAILS[owasp];const owaspName=owaspDetails?.name?.split(" ")[0]||"";standards.push(`OWASP:${owaspCode}-${owaspName}`)}if(cvss!==void 0)standards.push(`CVSS:${cvss}`);const standardsPart=standards.length>0?`${standards.join(" ")} | `:"";const compliancePart=compliance&&compliance.length>0?` [${compliance.slice(0,4).join(",")}]`:"";const firstLine=`${icon} ${standardsPart}${description} | ${severity}${compliancePart}`;const secondLine=` Fix: ${fix} | ${documentationLink}`;return`${firstLine}
2
+ ${secondLine}`}function formatLLMMessageTemplate(options){return formatLLMMessage(options)}function getSecurityBenchmarks(cwe){const cweData=constants_1.CWE_MAPPING[cwe];if(!cweData)return void 0;const owaspDetails=constants_1.OWASP_DETAILS[cweData.owasp];return{owasp:cweData.owasp,owaspName:owaspDetails.name,owaspLink:owaspDetails.link,cvss:cweData.cvss,severity:cweData.severity,name:cweData.name,compliance:constants_1.CWE_COMPLIANCE_MAPPING[cwe]??[]}}const templateRegistry=new Map;function registerMessageTemplate(name,config){templateRegistry.set(name,config)}function getMessageTemplate(name){return templateRegistry.get(name)}function listMessageTemplates(){return Array.from(templateRegistry.keys())}function clearMessageTemplates(){templateRegistry.clear()}function replacePlaceholders(template,values){return template.replace(/\{\{(\w+)\}\}/g,(match,key)=>{return values[key]??match})}function formatWithTemplate(options){const templateConfig=options.templateConfig??(options.templateName?getMessageTemplate(options.templateName):void 0);if(!templateConfig){return formatLLMMessage(options)}const enriched=enrichFromCWE(options);const owasp=enriched.owasp;const cvss=enriched.cvss??(0,constants_1.severityToCVSS)(enriched.severity);const compliance=enriched.compliance??[];let jiraUrl="";if(templateConfig.jiraTemplate&&options.jiraData){jiraUrl=replacePlaceholders(templateConfig.jiraTemplate,{summary:encodeURIComponent(options.jiraData.summary??options.description),priority:options.jiraData.priority??"Medium",labels:options.jiraData.labels?.join(",")??"",project:options.jiraData.project??"SEC",description:encodeURIComponent(options.description)})}let confluenceUrl="";if(templateConfig.confluenceTemplate){confluenceUrl=replacePlaceholders(templateConfig.confluenceTemplate,{cwe:options.cwe??"",owasp:owasp??""})}const owaspDisplay=owasp?`OWASP:${owasp.split(":")[0]}`:"";const allCompliance=[...compliance,...templateConfig.customCompliance??[]];const complianceDisplay=allCompliance.length>0?`[${allCompliance.slice(0,4).join(",")}]`:"";const placeholderValues={icon:enriched.icon,cwe:enriched.cwe,owasp:owaspDisplay,cvss:`CVSS:${cvss}`,severity:enriched.severity,description:enriched.description,compliance:complianceDisplay,fix:enriched.fix,documentation:enriched.documentationLink,jira:jiraUrl,confluence:confluenceUrl,organization:templateConfig.organizationName??"",...templateConfig.customMetadata,...options.customPlaceholders};const line1Template=templateConfig.line1Format??"{{icon}} {{cwe}} {{owasp}} {{cvss}} | {{description}} | {{severity}} {{compliance}}";const line2Template=templateConfig.line2Format??" Fix: {{fix}} | {{documentation}}";const line1=replacePlaceholders(line1Template,placeholderValues).replace(/\s+\|/g," |").replace(/\|\s+\|/g,"|").replace(/\s{2,}/g," ").trim();const line2=replacePlaceholders(line2Template,placeholderValues).replace(/\s+\|/g," |").replace(/\|\s+\|/g,"|").replace(/\s{2,}/g," ").trim();return`${line1}
3
+ ${line2}`}function toSARIF(options){const enriched=enrichFromCWE(options);return{ruleId:options.ruleId||options.cwe||options.issueName.replace(/\s+/g,"-").toLowerCase(),level:severityToSARIFLevel(enriched.severity),message:{text:enriched.description},properties:{"security-severity":enriched.cvss?.toString()??(0,constants_1.severityToCVSS)(enriched.severity).toString(),cwe:enriched.cwe,owasp:enriched.owasp,cvss:enriched.cvss??(0,constants_1.severityToCVSS)(enriched.severity),compliance:enriched.compliance,fix:enriched.fix}}}function severityToSARIFLevel(severity){switch(severity){case"CRITICAL":case"HIGH":return"error";case"MEDIUM":return"warning";case"LOW":case"INFO":return"note";default:return"none"}}
@@ -1,21 +1 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./constants"), exports);
19
- __exportStar(require("./formatters"), exports);
20
- __exportStar(require("./config"), exports);
21
- __exportStar(require("./formatters-ai"), exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});__exportStar(require("./types"),exports);__exportStar(require("./constants"),exports);__exportStar(require("./formatters"),exports);__exportStar(require("./config"),exports);__exportStar(require("./formatters-ai"),exports);
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});