88 lines
2.7 KiB
Python
88 lines
2.7 KiB
Python
import re
|
||
|
||
with open('src/components/SandboxSimulation.tsx', 'r') as f:
|
||
content = f.read()
|
||
|
||
old_handle = """ // Perform rule matching
|
||
let currentAlerts = [...prev.alerts];
|
||
let silentCount = prev.interceptCount;
|
||
const activeRules = rules.filter(r => r.enabled);
|
||
|
||
activeRules.forEach(rule => {
|
||
// Check if any keyword matches
|
||
const matchedKeyword = rule.keywords.find(kw =>
|
||
text.toLowerCase().includes(kw.toLowerCase())
|
||
);
|
||
|
||
if (matchedKeyword) {
|
||
// Check if this rule was already triggered in the current session
|
||
const alreadyTriggered = currentAlerts.some(a => a.ruleId === rule.id);
|
||
|
||
if (alreadyTriggered) {
|
||
// Duplicate hit: silent interception
|
||
silentCount += 1;
|
||
// Silent notify
|
||
addToast(`规则「${rule.name}」在 seq: ${nextSeq} 中再次触发,已被系统去重静默拦截!`, 'info');
|
||
} else {
|
||
// Fresh alert!
|
||
const alertId = `alert-${rule.id}-${Date.now()}`;
|
||
const newAlert: Alert = {
|
||
id: alertId,
|
||
ruleId: rule.id,
|
||
ruleName: rule.name,
|
||
keyword: matchedKeyword,
|
||
text: text.trim(),
|
||
seq: nextSeq,
|
||
timestamp,
|
||
};
|
||
currentAlerts = [...currentAlerts, newAlert];
|
||
addToast(`⚠️ 触发预警: 「${rule.name}」(命中词: ${matchedKeyword})`, 'warning');
|
||
}
|
||
}
|
||
});
|
||
|
||
return {
|
||
...prev,
|
||
lines: updatedLines,
|
||
alerts: currentAlerts,
|
||
interceptCount: silentCount
|
||
};"""
|
||
|
||
new_handle = """ // Perform rule matching
|
||
let currentAlerts = [...prev.alerts];
|
||
const activeRules = rules.filter(r => r.enabled);
|
||
|
||
activeRules.forEach(rule => {
|
||
// Check if any keyword matches
|
||
const matchedKeyword = rule.keywords.find(kw =>
|
||
text.toLowerCase().includes(kw.toLowerCase())
|
||
);
|
||
|
||
if (matchedKeyword) {
|
||
// Fresh alert!
|
||
const alertId = `alert-${rule.id}-${Date.now()}`;
|
||
const newAlert: Alert = {
|
||
id: alertId,
|
||
ruleId: rule.id,
|
||
ruleName: rule.name,
|
||
keyword: matchedKeyword,
|
||
text: text.trim(),
|
||
seq: nextSeq,
|
||
timestamp,
|
||
};
|
||
currentAlerts = [...currentAlerts, newAlert];
|
||
addToast(`⚠️ 触发预警: 「${rule.name}」(命中词: ${matchedKeyword})`, 'warning');
|
||
}
|
||
});
|
||
|
||
return {
|
||
...prev,
|
||
lines: updatedLines,
|
||
alerts: currentAlerts
|
||
};"""
|
||
|
||
content = content.replace(old_handle, new_handle)
|
||
|
||
with open('src/components/SandboxSimulation.tsx', 'w') as f:
|
||
f.write(content)
|