feat(fuzzer): add RAG knowledge base and LLM-powered strategy synthesizer
This commit is contained in:
@@ -3119,6 +3119,7 @@ var Tachyon;
|
||||
AvailableMethods2["FUZZER_STOP"] = "fuzzer_stop";
|
||||
AvailableMethods2["FUZZER_APPLY"] = "fuzzer_apply";
|
||||
AvailableMethods2["FUZZER_STRATEGIES"] = "fuzzer_strategies";
|
||||
AvailableMethods2["FUZZER_AI_SYNTHESIZE"] = "fuzzer_ai_synthesize";
|
||||
})(AvailableMethods = Tachyon2.AvailableMethods || (Tachyon2.AvailableMethods = {}));
|
||||
let AvailableClashAPIMethods;
|
||||
((AvailableClashAPIMethods2) => {
|
||||
@@ -4040,6 +4041,39 @@ var TachyonShellMethods = {
|
||||
success: false,
|
||||
error: response.stderr || _("Failed to get fuzzer strategies")
|
||||
};
|
||||
},
|
||||
fuzzerAiSynthesize: async (engine, target, customUrl, userPrompt) => {
|
||||
const args = [
|
||||
Tachyon.AvailableMethods.FUZZER_AI_SYNTHESIZE,
|
||||
engine,
|
||||
target
|
||||
];
|
||||
if (customUrl) args.push(customUrl);
|
||||
else args.push("");
|
||||
if (userPrompt) args.push(userPrompt);
|
||||
const response = await executeShellCommand({
|
||||
command: "/usr/bin/tachyon",
|
||||
args,
|
||||
timeout: 65e3
|
||||
});
|
||||
let parsed = null;
|
||||
try {
|
||||
parsed = JSON.parse(
|
||||
response.stdout?.trim() || "{}"
|
||||
);
|
||||
} catch {
|
||||
parsed = null;
|
||||
}
|
||||
if ((response.code ?? 1) === 0 && parsed && parsed.success) {
|
||||
return {
|
||||
success: true,
|
||||
data: parsed
|
||||
};
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
error: parsed?.error || response.stderr || _("Failed to synthesize AI strategies")
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11873,6 +11907,74 @@ function renderStrategyFuzzerModal(ruleNames = []) {
|
||||
]
|
||||
);
|
||||
controlsGrid.append(engineGroup, targetGroup, ruleGroup);
|
||||
const aiPromptInput = E("input", {
|
||||
type: "text",
|
||||
class: "cbi-input-text",
|
||||
placeholder: _(
|
||||
'Optional notes for AI (e.g. "Rostelecom, YouTube 4K stream is slow")...'
|
||||
),
|
||||
style: "flex: 1 1 auto; font-size: 12px;"
|
||||
});
|
||||
const aiSynthesizeBtn = renderButton({
|
||||
text: _("\u{1F9E0} Synthesize with AI"),
|
||||
classNames: ["cbi-button-action"],
|
||||
onClick: () => handleAiSynthesize()
|
||||
});
|
||||
const aiAnalysisContainer = E(
|
||||
"div",
|
||||
{
|
||||
id: "tachyon-fuzzer-ai-analysis",
|
||||
style: "display: none; padding: 10px 14px; background: rgba(0, 123, 255, 0.08); border-left: 3px solid #007bff; border-radius: 4px; font-size: 12px; line-height: 1.4;"
|
||||
},
|
||||
[
|
||||
E(
|
||||
"div",
|
||||
{
|
||||
style: "font-weight: bold; margin-bottom: 4px; display: flex; align-items: center; gap: 6px;"
|
||||
},
|
||||
[
|
||||
E("span", {}, "\u{1F9E0}"),
|
||||
E("span", {}, _("AI Diagnostics & Strategy Rationale"))
|
||||
]
|
||||
),
|
||||
E(
|
||||
"div",
|
||||
{ id: "tachyon-fuzzer-ai-analysis-text", style: "opacity: 0.85;" },
|
||||
""
|
||||
)
|
||||
]
|
||||
);
|
||||
const aiSynthesizerCard = E(
|
||||
"div",
|
||||
{
|
||||
style: "padding: 10px 14px; background: var(--background-color-secondary, rgba(0,0,0,0.15)); border: 1px dashed var(--border-color, rgba(255,255,255,0.15)); border-radius: 8px; display: flex; flex-direction: column; gap: 8px;"
|
||||
},
|
||||
[
|
||||
E(
|
||||
"div",
|
||||
{
|
||||
style: "font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: space-between;"
|
||||
},
|
||||
[
|
||||
E(
|
||||
"span",
|
||||
{},
|
||||
"\u{1F9E0} " + _("AI DPI Engineer & Strategy Synthesizer (RAG-Powered)")
|
||||
),
|
||||
E(
|
||||
"span",
|
||||
{ style: "font-size: 10px; opacity: 0.6; font-weight: normal;" },
|
||||
_("Knowledge Base + Live Probe Context")
|
||||
)
|
||||
]
|
||||
),
|
||||
E("div", { style: "display: flex; gap: 8px; align-items: center;" }, [
|
||||
aiPromptInput,
|
||||
aiSynthesizeBtn
|
||||
]),
|
||||
aiAnalysisContainer
|
||||
]
|
||||
);
|
||||
const progressContainer = E(
|
||||
"div",
|
||||
{
|
||||
@@ -11962,7 +12064,7 @@ function renderStrategyFuzzerModal(ruleNames = []) {
|
||||
style: "padding: 24px; text-align: center; opacity: 0.6;"
|
||||
},
|
||||
_(
|
||||
'No benchmark results yet. Select engine and click "Start Benchmark".'
|
||||
'No benchmark results yet. Select engine and click "Start Benchmark" or "Synthesize with AI".'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -12164,6 +12266,55 @@ function renderStrategyFuzzerModal(ruleNames = []) {
|
||||
startBtn.innerText = _("\u{1F680} Start Benchmark");
|
||||
}
|
||||
};
|
||||
const handleAiSynthesize = async () => {
|
||||
const userPrompt = aiPromptInput.value.trim();
|
||||
aiSynthesizeBtn.disabled = true;
|
||||
aiSynthesizeBtn.innerText = _("\u{1F9E0} Synthesizing...");
|
||||
const analysisBox = document.getElementById("tachyon-fuzzer-ai-analysis");
|
||||
const analysisText = document.getElementById(
|
||||
"tachyon-fuzzer-ai-analysis-text"
|
||||
);
|
||||
if (analysisBox) analysisBox.style.display = "none";
|
||||
try {
|
||||
showToast(_("Consulting DPI Knowledge Base & AI..."), "success");
|
||||
const res = await TachyonShellMethods.fuzzerAiSynthesize(
|
||||
selectedEngine,
|
||||
selectedTarget,
|
||||
customUrl,
|
||||
userPrompt
|
||||
);
|
||||
if (res.success && res.data) {
|
||||
showToast(
|
||||
_("AI successfully synthesized custom strategies!"),
|
||||
"success"
|
||||
);
|
||||
if (analysisBox && analysisText && res.data.analysis) {
|
||||
analysisText.innerText = res.data.analysis;
|
||||
analysisBox.style.display = "block";
|
||||
}
|
||||
startBtn.disabled = true;
|
||||
startBtn.innerText = _("\u{1F6D1} Stop Benchmark");
|
||||
const startRes = await TachyonShellMethods.startFuzzer(
|
||||
selectedEngine,
|
||||
selectedTarget,
|
||||
customUrl,
|
||||
selectedRuleSection
|
||||
);
|
||||
if (startRes.success) {
|
||||
isRunning = true;
|
||||
startPolling();
|
||||
}
|
||||
} else {
|
||||
const errMsg = !res.success ? res.error : _("AI synthesis failed");
|
||||
showToast(`${_("AI Synthesis Error")}: ${errMsg}`, "error");
|
||||
}
|
||||
} catch {
|
||||
showToast(_("Failed to communicate with AI provider"), "error");
|
||||
} finally {
|
||||
aiSynthesizeBtn.disabled = false;
|
||||
aiSynthesizeBtn.innerText = _("\u{1F9E0} Synthesize with AI");
|
||||
}
|
||||
};
|
||||
const handleApplySingle = async (item) => {
|
||||
const res = await TachyonShellMethods.applyFuzzerStrategy(
|
||||
item.engine,
|
||||
@@ -12186,6 +12337,7 @@ function renderStrategyFuzzerModal(ruleNames = []) {
|
||||
modalContainer.append(
|
||||
headerEl,
|
||||
controlsGrid,
|
||||
aiSynthesizerCard,
|
||||
progressContainer,
|
||||
resultsContainer,
|
||||
footerActions
|
||||
|
||||
Reference in New Issue
Block a user