Skip to content

Commit 701eab6

Browse files
alpslaclaude
andcommitted
Session 92: Add P0/P1/P2 security tools to Java orchestrator
- Add gitleaks, checkov, trivy, grype, spectral, graphql-cop to JAVA_TOOL_CATEGORIES mapping - Update shouldJavaToolRun() to check P0/P1/P2 categories (secrets, iacSecurity, containerSecurity, apiDesign, graphqlSecurity) - Add P0/P1/P2 tools to getToolsToRun() based on analysis mode: - P0 (secrets): gitleaks - fast/standard/thorough/complete - P0 (iac): checkov - standard/thorough/complete - P0 (container): trivy, grype - standard/thorough/complete - P1 (api): spectral - thorough/complete - P1 (graphql): graphql-cop - thorough/complete - Update getAgentToolCategories() to include P0/P1/P2 tools - Add executeUniversalTool() handlers for all new tools: - SecretScanner.runGitleaks() for secret detection - IaCScanner.runCheckov() for IaC security - ContainerScanner.scanDockerfiles() for Trivy - ContainerScanner.scanFilesystemWithGrype() for Grype - runSpectral() for API schema validation - runGraphQLScanner() for GraphQL security This enables the full P0/P1/P2 tool suite for Java PR analysis, matching the tool configurations in analysis-modes.ts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d03b886 commit 701eab6

2 files changed

Lines changed: 240 additions & 6 deletions

File tree

packages/agents/src/two-branch/tools/base-tool-orchestrator.ts

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,169 @@ export abstract class BaseToolOrchestrator {
528528
break;
529529
}
530530

531+
// ============================================================
532+
// SESSION 92: P0/P1/P2 Universal Security Tools
533+
// ============================================================
534+
535+
case 'gitleaks': {
536+
// P0: Secret detection
537+
logger.info('🔐 Running Gitleaks secret detection...');
538+
const { SecretScanner } = await import('./universal');
539+
const scanner = new SecretScanner();
540+
const secretResult = await scanner.runGitleaks(repoPath);
541+
issues = secretResult.issues.map(issue => ({
542+
id: `gitleaks-${issue.file}-${issue.line}`,
543+
tool: 'gitleaks',
544+
file: issue.file,
545+
line: issue.line,
546+
severity: issue.severity,
547+
title: issue.ruleId,
548+
description: issue.description,
549+
category: 'Security',
550+
rule: issue.ruleId,
551+
// Required V9 Issue fields
552+
status: 'new' as const,
553+
agent: 'Security',
554+
impact: 'Exposed secrets can lead to unauthorized access',
555+
businessImpact: 'High risk of credential theft and data breach'
556+
}));
557+
logger.info(`🔐 Gitleaks completed: ${issues.length} secrets found`);
558+
break;
559+
}
560+
561+
case 'checkov': {
562+
// P0: IaC security scanning
563+
logger.info('🏗️ Running Checkov IaC security scan...');
564+
const { IaCScanner } = await import('./universal');
565+
const iacScannerInstance = new IaCScanner();
566+
const iacResult = await iacScannerInstance.runCheckov(repoPath);
567+
issues = iacResult.issues.map(issue => ({
568+
id: `checkov-${issue.file}-${issue.line}`,
569+
tool: 'checkov',
570+
file: issue.file,
571+
line: issue.line,
572+
severity: issue.severity,
573+
title: issue.checkId,
574+
description: issue.description,
575+
category: 'Security',
576+
rule: issue.checkId,
577+
cwe: issue.guideline,
578+
// Required V9 Issue fields
579+
status: 'new' as const,
580+
agent: 'Security',
581+
impact: 'Infrastructure misconfiguration',
582+
businessImpact: 'May expose cloud resources to attacks'
583+
}));
584+
logger.info(`🏗️ Checkov completed: ${issues.length} IaC issues found`);
585+
break;
586+
}
587+
588+
case 'trivy': {
589+
// P0: Container security scanning (scans Dockerfiles)
590+
logger.info('🐳 Running Trivy container security scan...');
591+
const { ContainerScanner } = await import('./universal');
592+
const containerScannerInstance = new ContainerScanner();
593+
const trivyResult = await containerScannerInstance.scanDockerfiles(repoPath);
594+
// Convert Dockerfile issues to Issue format
595+
issues = (trivyResult.dockerfileIssues || []).map(issue => ({
596+
id: `trivy-dockerfile-${issue.file}-${issue.line}`,
597+
tool: 'trivy',
598+
file: issue.file,
599+
line: issue.line,
600+
severity: issue.severity === 'negligible' ? 'low' as const : issue.severity,
601+
title: issue.rule,
602+
description: issue.message,
603+
category: 'Security',
604+
rule: issue.rule,
605+
// Required V9 Issue fields
606+
status: 'new' as const,
607+
agent: 'Security',
608+
impact: 'Container security misconfiguration',
609+
businessImpact: 'May allow container escape or privilege escalation'
610+
}));
611+
logger.info(`🐳 Trivy completed: ${issues.length} container issues found`);
612+
break;
613+
}
614+
615+
case 'grype': {
616+
// P0: SBOM-based vulnerability scanning
617+
logger.info('📦 Running Grype SBOM vulnerability scan...');
618+
const { ContainerScanner: GrypeScanner } = await import('./universal');
619+
const grypeInstance = new GrypeScanner();
620+
const grypeResult = await grypeInstance.scanFilesystemWithGrype(repoPath);
621+
issues = grypeResult.vulnerabilities.map(vuln => ({
622+
id: `grype-${vuln.pkgName}-${vuln.vulnerabilityId}`,
623+
tool: 'grype',
624+
file: 'package dependencies',
625+
line: 1,
626+
severity: vuln.severity === 'negligible' ? 'low' as const : vuln.severity,
627+
title: vuln.vulnerabilityId,
628+
description: `${vuln.pkgName}@${vuln.installedVersion}: ${vuln.title}`,
629+
category: 'Dependency',
630+
rule: vuln.vulnerabilityId,
631+
cwe: vuln.cvss?.toString(),
632+
// Required V9 Issue fields
633+
status: 'new' as const,
634+
agent: 'Dependency',
635+
impact: 'Known vulnerability in dependency',
636+
businessImpact: 'May be exploited by attackers'
637+
}));
638+
logger.info(`📦 Grype completed: ${issues.length} vulnerabilities found`);
639+
break;
640+
}
641+
642+
case 'spectral': {
643+
// P1: API schema validation
644+
logger.info('📋 Running Spectral API schema validation...');
645+
const { runSpectral } = await import('./universal');
646+
const spectralResult = await runSpectral(repoPath);
647+
issues = spectralResult.issues.map(issue => ({
648+
id: `spectral-${issue.file}-${issue.line}-${issue.ruleId}`,
649+
tool: 'spectral',
650+
file: issue.file,
651+
line: issue.line,
652+
severity: issue.severity,
653+
title: issue.ruleId,
654+
description: issue.message,
655+
category: 'Architecture',
656+
rule: issue.ruleId,
657+
// Required V9 Issue fields
658+
status: 'new' as const,
659+
agent: 'Architecture',
660+
impact: 'API schema design issue',
661+
businessImpact: 'May cause API compatibility or security issues'
662+
}));
663+
logger.info(`📋 Spectral completed: ${issues.length} API schema issues found`);
664+
break;
665+
}
666+
667+
case 'graphql-cop':
668+
case 'graphql-scanner': {
669+
// P1: GraphQL security scanning
670+
logger.info('🔮 Running GraphQL security scan...');
671+
const { runGraphQLScanner } = await import('./universal');
672+
const gqlResult = await runGraphQLScanner(repoPath);
673+
issues = gqlResult.issues.map(issue => ({
674+
id: `graphql-${issue.file || 'unknown'}-${issue.line || 0}-${issue.ruleId}`,
675+
tool: 'graphql-cop',
676+
file: issue.file || 'graphql-schema',
677+
line: issue.line || 1,
678+
severity: issue.severity,
679+
title: issue.ruleId,
680+
description: issue.message,
681+
category: 'Security',
682+
rule: issue.ruleId,
683+
cwe: issue.impact,
684+
// Required V9 Issue fields
685+
status: 'new' as const,
686+
agent: 'Security',
687+
impact: 'GraphQL API security issue',
688+
businessImpact: 'May allow unauthorized data access or DoS'
689+
}));
690+
logger.info(`🔮 GraphQL scan completed: ${issues.length} security issues found`);
691+
break;
692+
}
693+
531694
default:
532695
throw new Error(`Unknown universal tool: ${toolName}`);
533696
}

packages/agents/src/two-branch/tools/java/java-tool-orchestrator.ts

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export const DEFAULT_JAVA_CONFIG: JavaToolConfig = {
163163
* Java tool category mapping
164164
* SESSION 57 Part 5: Added jdepend for architecture analysis
165165
* SESSION 58: Added performance static analysis
166+
* SESSION 92: Added P0/P1/P2 universal tools
166167
*/
167168
const JAVA_TOOL_CATEGORIES = {
168169
pmd: ToolCategory.CODE_QUALITY,
@@ -171,19 +172,32 @@ const JAVA_TOOL_CATEGORIES = {
171172
checkstyle: ToolCategory.STYLE_LINT,
172173
spotbugs: ToolCategory.ADVANCED,
173174
jdepend: ToolCategory.ADVANCED, // Architecture analysis
174-
performance: ToolCategory.ADVANCED // Static performance analysis
175+
performance: ToolCategory.ADVANCED, // Static performance analysis
176+
// P0: Secret detection (Session 92)
177+
gitleaks: ToolCategory.SECRETS,
178+
// P0: IaC security (Session 92)
179+
checkov: ToolCategory.IAC_SECURITY,
180+
// P0: Container security (Session 92)
181+
trivy: ToolCategory.CONTAINER_SECURITY,
182+
grype: ToolCategory.CONTAINER_SECURITY,
183+
// P1: API schema validation (Session 92)
184+
spectral: ToolCategory.API_DESIGN,
185+
// P1: GraphQL security (Session 92)
186+
'graphql-cop': ToolCategory.GRAPHQL_SECURITY
175187
};
176188

177189
/**
178190
* Check if a Java tool should run based on analysis mode
191+
* SESSION 92: Added P0/P1/P2 tool category checks
179192
*/
180193
function shouldJavaToolRun(toolName: string, mode: AnalysisMode): boolean {
181194
const category = JAVA_TOOL_CATEGORIES[toolName as keyof typeof JAVA_TOOL_CATEGORIES];
182195
if (!category) return false;
183-
196+
184197
const modeConfig = UNIVERSAL_ANALYSIS_MODES[mode];
185-
198+
186199
switch (category) {
200+
// Core categories
187201
case ToolCategory.CODE_QUALITY:
188202
return modeConfig.toolCategories.codeQuality;
189203
case ToolCategory.SECURITY:
@@ -194,6 +208,21 @@ function shouldJavaToolRun(toolName: string, mode: AnalysisMode): boolean {
194208
return modeConfig.toolCategories.styleLint;
195209
case ToolCategory.ADVANCED:
196210
return modeConfig.toolCategories.advanced;
211+
// P0 categories (Session 92)
212+
case ToolCategory.SECRETS:
213+
return modeConfig.toolCategories.secrets;
214+
case ToolCategory.IAC_SECURITY:
215+
return modeConfig.toolCategories.iacSecurity;
216+
case ToolCategory.CONTAINER_SECURITY:
217+
return modeConfig.toolCategories.containerSecurity;
218+
// P1 categories (Session 92)
219+
case ToolCategory.API_DESIGN:
220+
return modeConfig.toolCategories.apiDesign;
221+
case ToolCategory.GRAPHQL_SECURITY:
222+
return modeConfig.toolCategories.graphqlSecurity;
223+
// P2 categories
224+
case ToolCategory.ARCHITECTURE:
225+
return modeConfig.toolCategories.architecture;
197226
default:
198227
return false;
199228
}
@@ -308,6 +337,39 @@ export class JavaToolOrchestrator extends BaseToolOrchestrator {
308337
tools.push('performance');
309338
}
310339

340+
// ============================================================
341+
// SESSION 92: P0/P1/P2 Universal Security Tools
342+
// These are language-agnostic tools handled by base orchestrator
343+
// ============================================================
344+
345+
// P0: Secret detection (gitleaks) - enabled in fast/standard/thorough/complete
346+
if (shouldJavaToolRun('gitleaks', mode)) {
347+
tools.push('gitleaks');
348+
}
349+
350+
// P0: IaC security (checkov) - enabled in standard/thorough/complete
351+
if (shouldJavaToolRun('checkov', mode)) {
352+
tools.push('checkov');
353+
}
354+
355+
// P0: Container security (trivy, grype) - enabled in standard/thorough/complete
356+
if (shouldJavaToolRun('trivy', mode)) {
357+
tools.push('trivy');
358+
}
359+
if (shouldJavaToolRun('grype', mode)) {
360+
tools.push('grype');
361+
}
362+
363+
// P1: API schema validation (spectral) - enabled in thorough/complete
364+
if (shouldJavaToolRun('spectral', mode)) {
365+
tools.push('spectral');
366+
}
367+
368+
// P1: GraphQL security (graphql-cop) - enabled in thorough/complete
369+
if (shouldJavaToolRun('graphql-cop', mode)) {
370+
tools.push('graphql-cop');
371+
}
372+
311373
return tools;
312374
}
313375

@@ -357,15 +419,24 @@ export class JavaToolOrchestrator extends BaseToolOrchestrator {
357419

358420
/**
359421
* SESSION 57 Part 5: Override to include JDepend under Architecture
422+
* SESSION 92: Added P0/P1/P2 tools
360423
*/
361424
protected getAgentToolCategories(): Record<string, string[]> {
362425
return {
363-
'Security': ['semgrep', 'dependency-check', 'spotbugs'], // SpotBugs can find security issues
426+
// Core tools
427+
'Security': [
428+
'semgrep', 'dependency-check', 'spotbugs',
429+
// P0 security tools (Session 92)
430+
'gitleaks', 'checkov', 'trivy', 'grype',
431+
// P1 security tools (Session 92)
432+
'graphql-cop'
433+
],
364434
'Code Quality': ['pmd', 'checkstyle', 'spotbugs'],
365435
// SESSION 58: Added static performance analysis
366436
'Performance': ['performance'], // PMD perf rules, memory patterns, complexity
367-
'Architecture': ['jdepend'], // SESSION 57 Part 5: JDepend for architecture analysis
368-
'Dependencies': ['dependency-check']
437+
// SESSION 57 Part 5 + Session 92: Architecture analysis
438+
'Architecture': ['jdepend', 'spectral'], // JDepend + API schema validation
439+
'Dependencies': ['dependency-check', 'trivy', 'grype'] // Session 92: Added container scanners
369440
};
370441
}
371442

0 commit comments

Comments
 (0)