progress
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// src/utils/aiPipeline.ts - REDESIGNED with micro-task architecture
|
||||
// src/utils/aiPipeline.ts - ENHANCED with improved forensics prompts
|
||||
import { getCompressedToolsDataForAI } from './dataService.js';
|
||||
import { embeddingsService, type EmbeddingData } from './embeddings.js';
|
||||
|
||||
@@ -72,8 +72,6 @@ class MicroTaskAIPipeline {
|
||||
this.maxSelectedItems = parseInt(process.env.AI_MAX_SELECTED_ITEMS || '15', 10);
|
||||
this.embeddingCandidates = parseInt(process.env.AI_EMBEDDING_CANDIDATES || '30', 10);
|
||||
this.similarityThreshold = parseFloat(process.env.AI_SIMILARITY_THRESHOLD || '0.3');
|
||||
|
||||
// New: Micro-task delay to respect rate limits
|
||||
this.microTaskDelay = parseInt(process.env.AI_MICRO_TASK_DELAY_MS || '500', 10);
|
||||
}
|
||||
|
||||
@@ -103,7 +101,11 @@ class MicroTaskAIPipeline {
|
||||
model: this.analyzerConfig.model,
|
||||
messages: [{ role: 'user', content: prompt }],
|
||||
max_tokens: maxTokens,
|
||||
temperature: 0.2 // Lower temperature for consistency
|
||||
temperature: 0.2,
|
||||
// Enhanced: Better parameters for consistent forensics output
|
||||
top_p: 0.9,
|
||||
frequency_penalty: 0.1,
|
||||
presence_penalty: 0.1
|
||||
})
|
||||
});
|
||||
|
||||
@@ -137,23 +139,29 @@ class MicroTaskAIPipeline {
|
||||
}
|
||||
}
|
||||
|
||||
// MICRO-TASK 1: Scenario/Problem Analysis
|
||||
// ENHANCED MICRO-TASK 1: Scenario/Problem Analysis with improved forensics methodology
|
||||
private async analyzeScenario(context: AnalysisContext): Promise<MicroTaskResult> {
|
||||
const isWorkflow = context.mode === 'workflow';
|
||||
|
||||
const prompt = `Du bist ein DFIR-Experte. Analysiere das folgende ${isWorkflow ? 'forensische Szenario' : 'spezifische Problem'} detailliert.
|
||||
const prompt = `Sie sind ein erfahrener DFIR-Experte mit Spezialisierung auf Objektivität und wissenschaftliche Methoden. Analysieren Sie das folgende ${isWorkflow ? 'forensische Szenario' : 'technische Problem'}.
|
||||
|
||||
${isWorkflow ? 'FORENSISCHES SZENARIO' : 'SPEZIFISCHES PROBLEM'}: "${context.userQuery}"
|
||||
${isWorkflow ? 'FORENSISCHES SZENARIO' : 'TECHNISCHES PROBLEM'}: "${context.userQuery}"
|
||||
|
||||
Führen Sie eine systematische ${isWorkflow ? 'Szenario-Analyse' : 'Problem-Analyse'} durch und berücksichtigen Sie dabei:
|
||||
|
||||
Führe eine ${isWorkflow ? 'Szenario-Analyse' : 'Problem-Analyse'} durch:
|
||||
${isWorkflow ?
|
||||
'- Identifiziere die Art des Vorfalls\n- Erkenne betroffene Systeme und Technologien\n- Bestimme potentielle Bedrohungen\n- Analysiere forensische Herausforderungen' :
|
||||
'- Identifiziere technische Anforderungen\n- Erkenne spezifische Herausforderungen\n- Bestimme benötigte Fähigkeiten\n- Analysiere Erfolgsfaktoren'
|
||||
`- Angriffsvektoren und Bedrohungsmodellierung nach MITRE ATT&CK
|
||||
- Betroffene Systeme und kritische Infrastrukturen (ICS/SCADA, AD, Endpoints)
|
||||
- Zeitkritische Faktoren und Beweiserhaltung (Chain of Custody)
|
||||
- Forensische Artefakte und Datenquellen (Logs, Memory, Disk, Network)` :
|
||||
`- Spezifische forensische Herausforderungen
|
||||
- Verfügbare Datenquellen und deren Integrität
|
||||
- Methodische Anforderungen für rechtssichere Analyse`
|
||||
}
|
||||
|
||||
Antworte nur mit der Analyse als Fließtext (keine Listen), maximal 150 Wörter.`;
|
||||
WICHTIG: Antworten Sie NUR in fließendem deutschen Text ohne Listen, Aufzählungen oder Markdown-Formatierung. Verwenden Sie Fachterminologie und fundierte Methodik. Maximum 150 Wörter.`;
|
||||
|
||||
const result = await this.callMicroTaskAI(prompt, 200);
|
||||
const result = await this.callMicroTaskAI(prompt, 220);
|
||||
|
||||
if (result.success) {
|
||||
if (isWorkflow) {
|
||||
@@ -166,25 +174,31 @@ Antworte nur mit der Analyse als Fließtext (keine Listen), maximal 150 Wörter.
|
||||
return result;
|
||||
}
|
||||
|
||||
// MICRO-TASK 2: Investigation/Solution Approach
|
||||
// ENHANCED MICRO-TASK 2: Investigation/Solution Approach with forensics methodology
|
||||
private async generateApproach(context: AnalysisContext): Promise<MicroTaskResult> {
|
||||
const isWorkflow = context.mode === 'workflow';
|
||||
const analysis = isWorkflow ? context.scenarioAnalysis : context.problemAnalysis;
|
||||
|
||||
const prompt = `Basierend auf der vorherigen Analyse entwickle einen strategischen ${isWorkflow ? 'Untersuchungsansatz' : 'Lösungsansatz'}.
|
||||
const prompt = `Basierend auf der Analyse entwickeln Sie einen fundierten ${isWorkflow ? 'Untersuchungsansatz' : 'Lösungsansatz'} nach NIST SP 800-86 Methodik.
|
||||
|
||||
VORHERIGE ANALYSE: "${analysis}"
|
||||
FORENSISCHE ANALYSE: "${analysis}"
|
||||
${isWorkflow ? 'SZENARIO' : 'PROBLEM'}: "${context.userQuery}"
|
||||
|
||||
Entwickle einen ${isWorkflow ? 'Untersuchungsansatz' : 'Lösungsansatz'}:
|
||||
Entwickeln Sie einen systematischen ${isWorkflow ? 'Untersuchungsansatz' : 'Lösungsansatz'} unter Berücksichtigung von:
|
||||
|
||||
${isWorkflow ?
|
||||
'- Prioritäten für die Untersuchung\n- Reihenfolge der Phasen\n- Besondere Überlegungen für diesen Fall' :
|
||||
'- Optimale Herangehensweise\n- Prioritäten bei der Umsetzung\n- Anwendungsreihenfolge'
|
||||
`- Triage-Prioritäten nach forensischer Dringlichkeit (volatile vs. persistent evidence)
|
||||
- Phasenabfolge nach NIST-Methodik (Collection → Examination → Analysis → Reporting)
|
||||
- Kontaminationsvermeidung und forensische Isolierung` :
|
||||
`- Methodik-Auswahl nach wissenschaftlichen Kriterien
|
||||
- Validierung und Verifizierung der gewählten Ansätze
|
||||
- Qualitätssicherung und Reproduzierbarkeit
|
||||
- Integration in bestehende forensische Workflows`
|
||||
}
|
||||
|
||||
Antworte nur mit dem Ansatz als Fließtext, maximal 150 Wörter.`;
|
||||
WICHTIG: Antworten Sie NUR in fließendem deutschen Text ohne Listen oder Markdown. Verwenden Sie forensische Fachterminologie. Maximum 150 Wörter.`;
|
||||
|
||||
const result = await this.callMicroTaskAI(prompt, 200);
|
||||
const result = await this.callMicroTaskAI(prompt, 220);
|
||||
|
||||
if (result.success) {
|
||||
context.investigationApproach = result.content;
|
||||
@@ -193,22 +207,31 @@ Antworte nur mit dem Ansatz als Fließtext, maximal 150 Wörter.`;
|
||||
return result;
|
||||
}
|
||||
|
||||
// MICRO-TASK 3: Critical Considerations
|
||||
// ENHANCED MICRO-TASK 3: Critical Considerations with forensics focus
|
||||
private async generateCriticalConsiderations(context: AnalysisContext): Promise<MicroTaskResult> {
|
||||
const isWorkflow = context.mode === 'workflow';
|
||||
|
||||
const prompt = `Identifiziere ${isWorkflow ? 'kritische Überlegungen' : 'wichtige Voraussetzungen'} für diesen Fall.
|
||||
const prompt = `Identifizieren Sie ${isWorkflow ? 'kritische forensische Überlegungen' : 'wichtige methodische Voraussetzungen'} für diesen Fall basierend auf bewährten DFIR-Praktiken.
|
||||
|
||||
${isWorkflow ? 'SZENARIO' : 'PROBLEM'}: "${context.userQuery}"
|
||||
ANSATZ: "${context.investigationApproach}"
|
||||
|
||||
Identifiziere:
|
||||
Berücksichtigen Sie folgende forensische Aspekte:
|
||||
|
||||
${isWorkflow ?
|
||||
'- Zeitkritische Faktoren\n- Wichtige Sicherheitsaspekte\n- Besondere Vorsichtsmaßnahmen\n- Rechtliche Überlegungen' :
|
||||
'- Wichtige Voraussetzungen\n- Potentielle Fallstricke\n- Warnungen bei der Anwendung\n- Erforderliche Vorkenntnisse'
|
||||
`- Time-sensitive evidence preservation (RAM, log rotation, network captures)
|
||||
- Chain of custody requirements und rechtliche Verwertbarkeit
|
||||
- Incident containment vs. evidence preservation Dilemma
|
||||
- Cross-contamination risks zwischen verschiedenen Systemen
|
||||
- Privacy- und Compliance-Anforderungen (DSGVO, sector-specific regulations)` :
|
||||
`- Tool-Validierung und Nachvollziehbarkeit
|
||||
- False positive/negative Risiken bei der gewählten Methodik
|
||||
- Methodische Limitationen und deren Auswirkungen
|
||||
- Qualifikationsanforderungen für die Durchführung
|
||||
- Dokumentations- und Reporting-Standards`
|
||||
}
|
||||
|
||||
Antworte nur mit den Überlegungen als Fließtext, maximal 120 Wörter.`;
|
||||
WICHTIG: Antworten Sie NUR in fließendem deutschen Text ohne Listen oder Markdown. Maximum 120 Wörter.`;
|
||||
|
||||
const result = await this.callMicroTaskAI(prompt, 180);
|
||||
|
||||
@@ -219,7 +242,7 @@ Antworte nur mit den Überlegungen als Fließtext, maximal 120 Wörter.`;
|
||||
return result;
|
||||
}
|
||||
|
||||
// MICRO-TASK 4: Tool Selection (for workflow mode)
|
||||
// ENHANCED MICRO-TASK 4: Tool Selection with forensics validation
|
||||
private async selectToolsForPhase(context: AnalysisContext, phase: any): Promise<MicroTaskResult> {
|
||||
const phaseTools = context.filteredData.tools.filter((tool: any) =>
|
||||
tool.phases && tool.phases.includes(phase.id)
|
||||
@@ -234,32 +257,37 @@ Antworte nur mit den Überlegungen als Fließtext, maximal 120 Wörter.`;
|
||||
};
|
||||
}
|
||||
|
||||
const prompt = `Wähle 2-3 passende Tools für die Phase "${phase.name}" basierend auf dem Szenario.
|
||||
const prompt = `Wählen Sie 2-3 Methoden/Tools für die Phase "${phase.name}" basierend auf objektiven, fallbezogenen Kriterien.
|
||||
|
||||
SZENARIO: "${context.userQuery}"
|
||||
SZENARIO-ANALYSE: "${context.scenarioAnalysis}"
|
||||
FORENSISCHE ANALYSE: "${context.scenarioAnalysis}"
|
||||
|
||||
VERFÜGBARE TOOLS FÜR ${phase.name.toUpperCase()}:
|
||||
${phaseTools.map((tool: any) => `- ${tool.name}: ${tool.description.slice(0, 100)}...`).join('\n')}
|
||||
|
||||
Wähle 2-3 Tools aus und begründe knapp die Auswahl für dieses spezifische Szenario.
|
||||
Wählen Sie Methoden/Tools nach folgenden forensischen Kriterien aus:
|
||||
- Court admissibility und Chain of Custody Kompatibilität
|
||||
- False positive/negative Raten bei ähnlichen Szenarien
|
||||
- Integration in forensische Standard-Workflows
|
||||
- Reproduzierbarkeit und Dokumentationsqualität
|
||||
- Transparenter Untersuchungsprozess
|
||||
- Objektivität
|
||||
|
||||
Antworte nur mit JSON:
|
||||
Antworten Sie AUSSCHLIESSLICH mit diesem JSON-Format (kein zusätzlicher Text):
|
||||
[
|
||||
{
|
||||
"toolName": "Exakter Tool-Name",
|
||||
"priority": "high|medium|low",
|
||||
"justification": "Kurze Begründung warum für dieses Szenario geeignet"
|
||||
"toolName": "Exakter Methoden/Tool-Name",
|
||||
"priority": "high|medium|low",
|
||||
"justification": "Objektive Begründung warum diese Methode/Tool für das spezifische Szenario besser geeignet ist als vergleichbare Methoden/Tools"
|
||||
}
|
||||
]`;
|
||||
|
||||
const result = await this.callMicroTaskAI(prompt, 400);
|
||||
const result = await this.callMicroTaskAI(prompt, 450);
|
||||
|
||||
if (result.success) {
|
||||
try {
|
||||
const selections = JSON.parse(result.content.replace(/^```json\s*/i, '').replace(/\s*```\s*$/g, '').trim());
|
||||
|
||||
// Validate and store selections
|
||||
const validSelections = selections.filter((sel: any) =>
|
||||
phaseTools.some((tool: any) => tool.name === sel.toolName)
|
||||
);
|
||||
@@ -291,9 +319,9 @@ Antworte nur mit JSON:
|
||||
return result;
|
||||
}
|
||||
|
||||
// MICRO-TASK 5: Tool Evaluation (for tool mode)
|
||||
// ENHANCED MICRO-TASK 5: Tool Evaluation with scientific methodology
|
||||
private async evaluateSpecificTool(context: AnalysisContext, tool: any, rank: number): Promise<MicroTaskResult> {
|
||||
const prompt = `Bewerte dieses Tool detailliert für das spezifische Problem.
|
||||
const prompt = `Bewerten Sie diese Methode/Tool fallbezogen für das spezifische Problem nach forensischen Qualitätskriterien.
|
||||
|
||||
PROBLEM: "${context.userQuery}"
|
||||
PROBLEM-ANALYSE: "${context.problemAnalysis}"
|
||||
@@ -304,23 +332,22 @@ BESCHREIBUNG: ${tool.description}
|
||||
PLATTFORMEN: ${tool.platforms?.join(', ') || 'N/A'}
|
||||
SKILL LEVEL: ${tool.skillLevel}
|
||||
|
||||
Bewerte das Tool und antworte nur mit JSON:
|
||||
Bewerten Sie nach forensischen Standards und antworten Sie AUSSCHLIESSLICH mit diesem JSON-Format:
|
||||
{
|
||||
"suitability_score": "high|medium|low",
|
||||
"detailed_explanation": "Detaillierte Erklärung warum dieses Tool das Problem löst",
|
||||
"implementation_approach": "Konkrete Schritte zur Anwendung für dieses Problem",
|
||||
"pros": ["Vorteil 1", "Vorteil 2"],
|
||||
"cons": ["Nachteil 1", "Nachteil 2"],
|
||||
"alternatives": "Alternative Ansätze wenn relevant"
|
||||
"detailed_explanation": "Detaillierte forensische Begründung warum diese Methode/Tool das Problem löst, basierend auf objektiven, pragmatischen Kriterien",
|
||||
"implementation_approach": "Konkrete methodische Schritte zur korrekten Anwendung für dieses spezifische Problem",
|
||||
"pros": ["Forensischer Vorteil 1", "Validierter Vorteil 2"],
|
||||
"cons": ["Methodische Limitation 1", "Potenzielle Schwäche 2"],
|
||||
"alternatives": "Alternative Ansätze falls diese Methode/Tool nicht optimal ist"
|
||||
}`;
|
||||
|
||||
const result = await this.callMicroTaskAI(prompt, 600);
|
||||
const result = await this.callMicroTaskAI(prompt, 650);
|
||||
|
||||
if (result.success) {
|
||||
try {
|
||||
const evaluation = JSON.parse(result.content.replace(/^```json\s*/i, '').replace(/\s*```\s*$/g, '').trim());
|
||||
|
||||
// Store the evaluation with the tool
|
||||
if (!context.selectedTools) context.selectedTools = [];
|
||||
context.selectedTools.push({
|
||||
tool: {
|
||||
@@ -347,7 +374,7 @@ Bewerte das Tool und antworte nur mit JSON:
|
||||
return result;
|
||||
}
|
||||
|
||||
// MICRO-TASK 6: Background Knowledge Selection
|
||||
// ENHANCED MICRO-TASK 6: Background Knowledge with forensics context
|
||||
private async selectBackgroundKnowledge(context: AnalysisContext): Promise<MicroTaskResult> {
|
||||
const availableConcepts = context.filteredData.concepts;
|
||||
|
||||
@@ -362,7 +389,7 @@ Bewerte das Tool und antworte nur mit JSON:
|
||||
|
||||
const selectedToolNames = context.selectedTools?.map(st => st.tool.name) || [];
|
||||
|
||||
const prompt = `Wähle relevante Hintergrundwissen-Konzepte für diesen Fall.
|
||||
const prompt = `Wählen Sie relevante forensische Konzepte für das Verständnis der empfohlenen Methodik.
|
||||
|
||||
${context.mode === 'workflow' ? 'SZENARIO' : 'PROBLEM'}: "${context.userQuery}"
|
||||
EMPFOHLENE TOOLS: ${selectedToolNames.join(', ')}
|
||||
@@ -370,13 +397,13 @@ EMPFOHLENE TOOLS: ${selectedToolNames.join(', ')}
|
||||
VERFÜGBARE KONZEPTE:
|
||||
${availableConcepts.slice(0, 15).map((concept: any) => `- ${concept.name}: ${concept.description.slice(0, 80)}...`).join('\n')}
|
||||
|
||||
Wähle 2-4 Konzepte aus, die für das Verständnis der empfohlenen Tools oder des Problems wichtig sind.
|
||||
Wählen Sie 2-4 Konzepte aus, die für das Verständnis der forensischen Methodik und der empfohlenen Tools essentiell sind.
|
||||
|
||||
Antworte nur mit JSON:
|
||||
Antworten Sie AUSSCHLIESSLICH mit diesem JSON-Format:
|
||||
[
|
||||
{
|
||||
"conceptName": "Exakter Konzept-Name",
|
||||
"relevance": "Warum dieses Konzept für die Tools/das Problem relevant ist"
|
||||
"relevance": "Forensische Relevanz: Warum dieses Konzept für das Verständnis der Methodik/Tools kritisch ist"
|
||||
}
|
||||
]`;
|
||||
|
||||
@@ -406,32 +433,34 @@ Antworte nur mit JSON:
|
||||
return result;
|
||||
}
|
||||
|
||||
// MICRO-TASK 7: Final Workflow/Additional Considerations
|
||||
// ENHANCED MICRO-TASK 7: Final Recommendations with forensics methodology
|
||||
private async generateFinalRecommendations(context: AnalysisContext): Promise<MicroTaskResult> {
|
||||
const isWorkflow = context.mode === 'workflow';
|
||||
|
||||
const prompt = isWorkflow ?
|
||||
`Erstelle eine finale Workflow-Empfehlung basierend auf der Analyse.
|
||||
`Erstellen Sie eine forensisch fundierte Workflow-Empfehlung basierend auf DFIR-Prinzipien un pragmatischen Aspekten.
|
||||
|
||||
SZENARIO: "${context.userQuery}"
|
||||
AUSGEWÄHLTE TOOLS: ${context.selectedTools?.map(st => st.tool.name).join(', ') || 'Keine Tools ausgewählt'}
|
||||
|
||||
Erstelle eine konkrete Workflow-Empfehlung mit Schritten für dieses spezifische Szenario.
|
||||
Maximal 120 Wörter, als Fließtext.` :
|
||||
Erstellen Sie konkrete methodische Workflow-Schritte für dieses spezifische Szenario unter Berücksichtigung forensischer Best Practices, Objektivität und rechtlicher Verwertbarkeit.
|
||||
|
||||
WICHTIG: Antworten Sie NUR in fließendem deutschen Text ohne Listen oder Markdown. Maximum 120 Wörter.` :
|
||||
|
||||
`Erstelle zusätzliche Überlegungen für die Tool-Anwendung.
|
||||
`Erstellen Sie wichtige methodische Überlegungen für die korrekte Methoden-/Tool-Anwendung.
|
||||
|
||||
PROBLEM: "${context.userQuery}"
|
||||
EMPFOHLENE TOOLS: ${context.selectedTools?.map(st => st.tool.name).join(', ') || 'Keine Tools ausgewählt'}
|
||||
EMPFOHLENE TOOLS: ${context.selectedTools?.map(st => st.tool.name).join(', ') || 'Keine Methoden/Tools ausgewählt'}
|
||||
|
||||
Gib wichtige zusätzliche Überlegungen, Voraussetzungen oder Warnungen.
|
||||
Maximal 100 Wörter, als Fließtext.`;
|
||||
Geben Sie kritische methodische Überlegungen, Validierungsanforderungen und Qualitätssicherungsmaßnahmen für die korrekte Anwendung der empfohlenen Methoden/Tools.
|
||||
|
||||
WICHTIG: Antworten Sie NUR in fließendem deutschen Text ohne Listen oder Markdown. Maximum 100 Wörter.`;
|
||||
|
||||
const result = await this.callMicroTaskAI(prompt, 180);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Main processing pipeline with micro-tasks
|
||||
// Main processing pipeline with micro-tasks (unchanged structure)
|
||||
async processQuery(userQuery: string, mode: string): Promise<AnalysisResult> {
|
||||
const startTime = Date.now();
|
||||
let completedTasks = 0;
|
||||
@@ -517,7 +546,7 @@ Maximal 100 Wörter, als Fließtext.`;
|
||||
const finalResult = await this.generateFinalRecommendations(context);
|
||||
if (finalResult.success) completedTasks++; else failedTasks++;
|
||||
|
||||
// Build final recommendation object
|
||||
// Build final recommendation object (ENHANCED: Remove generic additional_notes)
|
||||
const recommendation = this.buildRecommendation(context, mode, finalResult.content);
|
||||
|
||||
processingStats.microTasksCompleted = completedTasks;
|
||||
@@ -539,6 +568,7 @@ Maximal 100 Wörter, als Fließtext.`;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXED: Remove generic additional_notes message
|
||||
private buildRecommendation(context: AnalysisContext, mode: string, finalContent: string): any {
|
||||
const isWorkflow = mode === 'workflow';
|
||||
|
||||
@@ -562,8 +592,8 @@ Maximal 100 Wörter, als Fließtext.`;
|
||||
priority: st.priority,
|
||||
justification: st.justification || `Empfohlen für ${st.phase}`
|
||||
})) || [],
|
||||
workflow_suggestion: finalContent,
|
||||
additional_notes: "Workflow basierend auf Micro-Task-Analyse generiert."
|
||||
workflow_suggestion: finalContent
|
||||
// REMOVED: additional_notes: "Workflow basierend auf Micro-Task-Analyse generiert."
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user