swarm-engine 1.3.0 → 1.41.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.
- package/README.md +45 -7
- package/dist/cli/commands/memory.js +117 -0
- package/dist/cli/commands/memory.js.map +1 -1
- package/dist/core/patterns.d.ts +7 -1
- package/dist/core/patterns.d.ts.map +1 -1
- package/dist/core/patterns.js +23 -0
- package/dist/core/patterns.js.map +1 -1
- package/dist/core/types.d.ts +39 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +37 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +91 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/runtime/adaptive.d.ts +1 -0
- package/dist/runtime/adaptive.d.ts.map +1 -1
- package/dist/runtime/adaptive.js +18 -4
- package/dist/runtime/adaptive.js.map +1 -1
- package/dist/runtime/agent-runner.d.ts +18 -0
- package/dist/runtime/agent-runner.d.ts.map +1 -1
- package/dist/runtime/agent-runner.js +147 -4
- package/dist/runtime/agent-runner.js.map +1 -1
- package/dist/runtime/backends/claude-session.d.ts +49 -0
- package/dist/runtime/backends/claude-session.d.ts.map +1 -0
- package/dist/runtime/backends/claude-session.js +237 -0
- package/dist/runtime/backends/claude-session.js.map +1 -0
- package/dist/runtime/backends/claude.d.ts.map +1 -1
- package/dist/runtime/backends/claude.js +90 -4
- package/dist/runtime/backends/claude.js.map +1 -1
- package/dist/runtime/backends/types.d.ts +31 -1
- package/dist/runtime/backends/types.d.ts.map +1 -1
- package/dist/runtime/compaction.d.ts +7 -1
- package/dist/runtime/compaction.d.ts.map +1 -1
- package/dist/runtime/compaction.js +12 -2
- package/dist/runtime/compaction.js.map +1 -1
- package/dist/runtime/distiller.d.ts +1 -0
- package/dist/runtime/distiller.d.ts.map +1 -1
- package/dist/runtime/distiller.js +8 -2
- package/dist/runtime/distiller.js.map +1 -1
- package/dist/runtime/engine.d.ts +48 -2
- package/dist/runtime/engine.d.ts.map +1 -1
- package/dist/runtime/engine.js +600 -8
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/execution-graph.d.ts +86 -0
- package/dist/runtime/execution-graph.d.ts.map +1 -0
- package/dist/runtime/execution-graph.js +441 -0
- package/dist/runtime/execution-graph.js.map +1 -0
- package/dist/runtime/executor.d.ts +7 -1
- package/dist/runtime/executor.d.ts.map +1 -1
- package/dist/runtime/executor.js +20 -0
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/graph-adversarial.d.ts +88 -0
- package/dist/runtime/graph-adversarial.d.ts.map +1 -0
- package/dist/runtime/graph-adversarial.js +378 -0
- package/dist/runtime/graph-adversarial.js.map +1 -0
- package/dist/runtime/graph-analyzer.d.ts +106 -0
- package/dist/runtime/graph-analyzer.d.ts.map +1 -0
- package/dist/runtime/graph-analyzer.js +321 -0
- package/dist/runtime/graph-analyzer.js.map +1 -0
- package/dist/runtime/graph-causal.d.ts +91 -0
- package/dist/runtime/graph-causal.d.ts.map +1 -0
- package/dist/runtime/graph-causal.js +292 -0
- package/dist/runtime/graph-causal.js.map +1 -0
- package/dist/runtime/graph-context-router.d.ts +73 -0
- package/dist/runtime/graph-context-router.d.ts.map +1 -0
- package/dist/runtime/graph-context-router.js +162 -0
- package/dist/runtime/graph-context-router.js.map +1 -0
- package/dist/runtime/graph-discovery.d.ts +71 -0
- package/dist/runtime/graph-discovery.d.ts.map +1 -0
- package/dist/runtime/graph-discovery.js +364 -0
- package/dist/runtime/graph-discovery.js.map +1 -0
- package/dist/runtime/graph-dropout.d.ts +59 -0
- package/dist/runtime/graph-dropout.d.ts.map +1 -0
- package/dist/runtime/graph-dropout.js +204 -0
- package/dist/runtime/graph-dropout.js.map +1 -0
- package/dist/runtime/graph-embeddings.d.ts +58 -0
- package/dist/runtime/graph-embeddings.d.ts.map +1 -0
- package/dist/runtime/graph-embeddings.js +299 -0
- package/dist/runtime/graph-embeddings.js.map +1 -0
- package/dist/runtime/graph-feedback.d.ts +30 -0
- package/dist/runtime/graph-feedback.d.ts.map +1 -0
- package/dist/runtime/graph-feedback.js +80 -0
- package/dist/runtime/graph-feedback.js.map +1 -0
- package/dist/runtime/graph-gnn.d.ts +120 -0
- package/dist/runtime/graph-gnn.d.ts.map +1 -0
- package/dist/runtime/graph-gnn.js +524 -0
- package/dist/runtime/graph-gnn.js.map +1 -0
- package/dist/runtime/graph-learner.d.ts +70 -0
- package/dist/runtime/graph-learner.d.ts.map +1 -0
- package/dist/runtime/graph-learner.js +265 -0
- package/dist/runtime/graph-learner.js.map +1 -0
- package/dist/runtime/graph-meta-adversarial.d.ts +113 -0
- package/dist/runtime/graph-meta-adversarial.d.ts.map +1 -0
- package/dist/runtime/graph-meta-adversarial.js +366 -0
- package/dist/runtime/graph-meta-adversarial.js.map +1 -0
- package/dist/runtime/graph-meta.d.ts +115 -0
- package/dist/runtime/graph-meta.d.ts.map +1 -0
- package/dist/runtime/graph-meta.js +465 -0
- package/dist/runtime/graph-meta.js.map +1 -0
- package/dist/runtime/graph-self-evolve.d.ts +92 -0
- package/dist/runtime/graph-self-evolve.d.ts.map +1 -0
- package/dist/runtime/graph-self-evolve.js +422 -0
- package/dist/runtime/graph-self-evolve.js.map +1 -0
- package/dist/runtime/graph-synthesis.d.ts +47 -0
- package/dist/runtime/graph-synthesis.d.ts.map +1 -0
- package/dist/runtime/graph-synthesis.js +232 -0
- package/dist/runtime/graph-synthesis.js.map +1 -0
- package/dist/runtime/graph-trajectory.d.ts +88 -0
- package/dist/runtime/graph-trajectory.d.ts.map +1 -0
- package/dist/runtime/graph-trajectory.js +334 -0
- package/dist/runtime/graph-trajectory.js.map +1 -0
- package/dist/runtime/learning-engine.d.ts +12 -0
- package/dist/runtime/learning-engine.d.ts.map +1 -1
- package/dist/runtime/learning-engine.js +70 -0
- package/dist/runtime/learning-engine.js.map +1 -1
- package/dist/runtime/prompt-compressor.d.ts +16 -0
- package/dist/runtime/prompt-compressor.d.ts.map +1 -0
- package/dist/runtime/prompt-compressor.js +68 -0
- package/dist/runtime/prompt-compressor.js.map +1 -0
- package/dist/runtime/repo-map.d.ts +40 -0
- package/dist/runtime/repo-map.d.ts.map +1 -0
- package/dist/runtime/repo-map.js +358 -0
- package/dist/runtime/repo-map.js.map +1 -0
- package/dist/runtime/sdk-mcp-server.d.ts +44 -0
- package/dist/runtime/sdk-mcp-server.d.ts.map +1 -0
- package/dist/runtime/sdk-mcp-server.js +133 -0
- package/dist/runtime/sdk-mcp-server.js.map +1 -0
- package/dist/runtime/structured-handoff.d.ts +41 -0
- package/dist/runtime/structured-handoff.d.ts.map +1 -0
- package/dist/runtime/structured-handoff.js +279 -0
- package/dist/runtime/structured-handoff.js.map +1 -0
- package/dist/runtime/token-analytics.d.ts +38 -0
- package/dist/runtime/token-analytics.d.ts.map +1 -0
- package/dist/runtime/token-analytics.js +59 -0
- package/dist/runtime/token-analytics.js.map +1 -0
- package/dist/runtime/verifier.d.ts +10 -0
- package/dist/runtime/verifier.d.ts.map +1 -1
- package/dist/runtime/verifier.js +97 -1
- package/dist/runtime/verifier.js.map +1 -1
- package/package.json +2 -2
- package/skills/swarm-output-style/SKILL.md +71 -33
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ExecutionGraph } from './execution-graph.js';
|
|
2
|
+
export type AttackCategory = 'injection' | 'auth_bypass' | 'data_exposure' | 'race_condition' | 'resource_exhaustion' | 'input_validation' | 'error_handling' | 'crypto_weakness';
|
|
3
|
+
export declare const ALL_ATTACK_CATEGORIES: AttackCategory[];
|
|
4
|
+
export interface CategoryArm {
|
|
5
|
+
category: AttackCategory;
|
|
6
|
+
alpha: number;
|
|
7
|
+
beta_: number;
|
|
8
|
+
roundsApplied: number;
|
|
9
|
+
recentlyPatched: number;
|
|
10
|
+
lastPatchedRound: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AttackStrategy {
|
|
13
|
+
categories: AttackCategory[];
|
|
14
|
+
reasoning: string;
|
|
15
|
+
regressionTargets: AttackCategory[];
|
|
16
|
+
}
|
|
17
|
+
export interface DefenseStrategy {
|
|
18
|
+
priorities: Array<{
|
|
19
|
+
file: string;
|
|
20
|
+
riskScore: number;
|
|
21
|
+
topCategory: AttackCategory;
|
|
22
|
+
}>;
|
|
23
|
+
proactiveChecks: AttackCategory[];
|
|
24
|
+
}
|
|
25
|
+
export interface VulnerabilityHeat {
|
|
26
|
+
file: string;
|
|
27
|
+
riskScore: number;
|
|
28
|
+
topCategory: AttackCategory;
|
|
29
|
+
unresolvedCount: number;
|
|
30
|
+
totalAttacks: number;
|
|
31
|
+
}
|
|
32
|
+
export interface RoundResult {
|
|
33
|
+
category: AttackCategory;
|
|
34
|
+
vulnerabilitiesFound: number;
|
|
35
|
+
vulnerabilitiesPatched: number;
|
|
36
|
+
files: string[];
|
|
37
|
+
roundNumber: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Co-evolutionary adversarial learning using Thompson Sampling over attack
|
|
41
|
+
* categories. Maintains Beta-distributed arms per category and persists
|
|
42
|
+
* state to the execution knowledge graph for cross-run learning.
|
|
43
|
+
*/
|
|
44
|
+
export declare class AdversarialEvolver {
|
|
45
|
+
private graph;
|
|
46
|
+
private arms;
|
|
47
|
+
private history;
|
|
48
|
+
constructor(graph: ExecutionGraph);
|
|
49
|
+
/**
|
|
50
|
+
* Thompson Sampling to select next attack categories.
|
|
51
|
+
* Unvisited categories are always prioritized. Recently-patched categories
|
|
52
|
+
* get a +0.2 regression bonus within 5 rounds of patching.
|
|
53
|
+
*/
|
|
54
|
+
evolveAttackStrategy(targetFiles: string[], previousRounds: RoundResult[]): AttackStrategy;
|
|
55
|
+
/**
|
|
56
|
+
* Generate defense priorities from historical attack data. Files are scored
|
|
57
|
+
* using a blend of overall success rate and recency-weighted rate (λ=0.14,
|
|
58
|
+
* half-life ~5 rounds). Categories with >50% historical attack success
|
|
59
|
+
* are flagged for proactive checking.
|
|
60
|
+
*/
|
|
61
|
+
evolveDefenseStrategy(previousAttacks: RoundResult[]): DefenseStrategy;
|
|
62
|
+
/**
|
|
63
|
+
* Record a round's results. Updates the Beta distribution parameters for
|
|
64
|
+
* the attacked category and persists state to the graph.
|
|
65
|
+
*/
|
|
66
|
+
recordRound(result: RoundResult): void;
|
|
67
|
+
/**
|
|
68
|
+
* Compute a vulnerability heatmap across all files in history.
|
|
69
|
+
* Files with more unresolved vulnerabilities and recent attack success
|
|
70
|
+
* rank higher.
|
|
71
|
+
*/
|
|
72
|
+
getVulnerabilityHeatmap(): VulnerabilityHeat[];
|
|
73
|
+
private saveToGraph;
|
|
74
|
+
private loadFromGraph;
|
|
75
|
+
/**
|
|
76
|
+
* Sample from Beta(α, β) distribution using the ratio of two Gamma samples.
|
|
77
|
+
*/
|
|
78
|
+
static sampleBeta(alpha: number, beta_: number, rng?: () => number): number;
|
|
79
|
+
/**
|
|
80
|
+
* Sample from Gamma(shape) distribution via Marsaglia-Tsang method.
|
|
81
|
+
*/
|
|
82
|
+
static sampleGamma(shape: number, rng?: () => number): number;
|
|
83
|
+
/**
|
|
84
|
+
* Sample from standard Normal distribution via Box-Muller transform.
|
|
85
|
+
*/
|
|
86
|
+
static sampleNormal(rng?: () => number): number;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=graph-adversarial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-adversarial.d.ts","sourceRoot":"","sources":["../../src/runtime/graph-adversarial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,MAAM,MAAM,cAAc,GACtB,WAAW,GACX,aAAa,GACb,eAAe,GACf,gBAAgB,GAChB,qBAAqB,GACrB,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB,eAAO,MAAM,qBAAqB,EAAE,cAAc,EASjD,CAA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EAAE,WAAW,EAAE,GAAG,eAAe;IA8FtE;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAsDtC;;;;OAIG;IACH,uBAAuB,IAAI,iBAAiB,EAAE;IAkE9C,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,aAAa;IAsCrB;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,MAAoB,GAAG,MAAM;IAOxF;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,MAAoB,GAAG,MAAM;IAyB1E;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,GAAE,MAAM,MAAoB,GAAG,MAAM;CAQ7D"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
export const ALL_ATTACK_CATEGORIES = [
|
|
2
|
+
'injection',
|
|
3
|
+
'auth_bypass',
|
|
4
|
+
'data_exposure',
|
|
5
|
+
'race_condition',
|
|
6
|
+
'resource_exhaustion',
|
|
7
|
+
'input_validation',
|
|
8
|
+
'error_handling',
|
|
9
|
+
'crypto_weakness',
|
|
10
|
+
];
|
|
11
|
+
// ─── AdversarialEvolver ───────────────────────────────────────────
|
|
12
|
+
/**
|
|
13
|
+
* Co-evolutionary adversarial learning using Thompson Sampling over attack
|
|
14
|
+
* categories. Maintains Beta-distributed arms per category and persists
|
|
15
|
+
* state to the execution knowledge graph for cross-run learning.
|
|
16
|
+
*/
|
|
17
|
+
export class AdversarialEvolver {
|
|
18
|
+
graph;
|
|
19
|
+
arms;
|
|
20
|
+
history;
|
|
21
|
+
constructor(graph) {
|
|
22
|
+
this.graph = graph;
|
|
23
|
+
this.arms = new Map();
|
|
24
|
+
for (const cat of ALL_ATTACK_CATEGORIES) {
|
|
25
|
+
this.arms.set(cat, {
|
|
26
|
+
category: cat,
|
|
27
|
+
alpha: 1,
|
|
28
|
+
beta_: 1,
|
|
29
|
+
roundsApplied: 0,
|
|
30
|
+
recentlyPatched: 0,
|
|
31
|
+
lastPatchedRound: 0,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
this.history = [];
|
|
35
|
+
this.loadFromGraph();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thompson Sampling to select next attack categories.
|
|
39
|
+
* Unvisited categories are always prioritized. Recently-patched categories
|
|
40
|
+
* get a +0.2 regression bonus within 5 rounds of patching.
|
|
41
|
+
*/
|
|
42
|
+
evolveAttackStrategy(targetFiles, previousRounds) {
|
|
43
|
+
const currentRound = this.history.length > 0 ? Math.max(...this.history.map((r) => r.roundNumber)) + 1 : 1;
|
|
44
|
+
const scored = [];
|
|
45
|
+
for (const [cat, arm] of this.arms) {
|
|
46
|
+
let score;
|
|
47
|
+
if (arm.roundsApplied === 0) {
|
|
48
|
+
// Unvisited arms always selected first
|
|
49
|
+
score = Infinity;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
score = AdversarialEvolver.sampleBeta(arm.alpha, arm.beta_);
|
|
53
|
+
}
|
|
54
|
+
// Regression bonus for recently-patched categories
|
|
55
|
+
if (arm.recentlyPatched > 0 && currentRound - arm.lastPatchedRound <= 5) {
|
|
56
|
+
score += 0.2;
|
|
57
|
+
}
|
|
58
|
+
scored.push({ category: cat, score });
|
|
59
|
+
}
|
|
60
|
+
scored.sort((a, b) => b.score - a.score);
|
|
61
|
+
const top3 = scored.slice(0, 3).map((s) => s.category);
|
|
62
|
+
// Regression targets: recently-patched categories within 5 rounds
|
|
63
|
+
const regressionTargets = [];
|
|
64
|
+
for (const [cat, arm] of this.arms) {
|
|
65
|
+
if (arm.recentlyPatched > 0 && currentRound - arm.lastPatchedRound <= 5) {
|
|
66
|
+
regressionTargets.push(cat);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const reasoning = scored
|
|
70
|
+
.slice(0, 3)
|
|
71
|
+
.map((s) => `${s.category}: score=${s.score === Infinity ? '∞ (unvisited)' : s.score.toFixed(3)}`)
|
|
72
|
+
.join(', ');
|
|
73
|
+
return {
|
|
74
|
+
categories: top3,
|
|
75
|
+
reasoning: `Thompson Sampling selected: ${reasoning}. Target files: ${targetFiles.length}`,
|
|
76
|
+
regressionTargets,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generate defense priorities from historical attack data. Files are scored
|
|
81
|
+
* using a blend of overall success rate and recency-weighted rate (λ=0.14,
|
|
82
|
+
* half-life ~5 rounds). Categories with >50% historical attack success
|
|
83
|
+
* are flagged for proactive checking.
|
|
84
|
+
*/
|
|
85
|
+
evolveDefenseStrategy(previousAttacks) {
|
|
86
|
+
// Merge history with any additional rounds, deduplicating
|
|
87
|
+
const seen = new Set();
|
|
88
|
+
const allRounds = [];
|
|
89
|
+
for (const r of this.history) {
|
|
90
|
+
const key = `${r.roundNumber}:${r.category}`;
|
|
91
|
+
if (!seen.has(key)) {
|
|
92
|
+
seen.add(key);
|
|
93
|
+
allRounds.push(r);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const r of previousAttacks) {
|
|
97
|
+
const key = `${r.roundNumber}:${r.category}`;
|
|
98
|
+
if (!seen.has(key)) {
|
|
99
|
+
seen.add(key);
|
|
100
|
+
allRounds.push(r);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (allRounds.length === 0) {
|
|
104
|
+
return { priorities: [], proactiveChecks: [] };
|
|
105
|
+
}
|
|
106
|
+
const maxRound = Math.max(...allRounds.map((r) => r.roundNumber));
|
|
107
|
+
// Group attacks by file
|
|
108
|
+
const fileMap = new Map();
|
|
109
|
+
for (const round of allRounds) {
|
|
110
|
+
for (const file of round.files) {
|
|
111
|
+
if (!fileMap.has(file))
|
|
112
|
+
fileMap.set(file, []);
|
|
113
|
+
fileMap.get(file).push({
|
|
114
|
+
found: round.vulnerabilitiesFound,
|
|
115
|
+
roundNumber: round.roundNumber,
|
|
116
|
+
category: round.category,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const priorities = [];
|
|
121
|
+
for (const [file, attacks] of fileMap) {
|
|
122
|
+
const totalAttacks = attacks.length;
|
|
123
|
+
const successCount = attacks.filter((a) => a.found > 0).length;
|
|
124
|
+
const successRate = totalAttacks > 0 ? successCount / totalAttacks : 0;
|
|
125
|
+
// Recency-weighted rate (λ=0.14)
|
|
126
|
+
let weightedSum = 0;
|
|
127
|
+
let totalWeight = 0;
|
|
128
|
+
for (const a of attacks) {
|
|
129
|
+
const weight = Math.exp(-0.14 * (maxRound - a.roundNumber));
|
|
130
|
+
weightedSum += weight * (a.found > 0 ? 1 : 0);
|
|
131
|
+
totalWeight += weight;
|
|
132
|
+
}
|
|
133
|
+
const recencyWeightedRate = totalWeight > 0 ? weightedSum / totalWeight : 0;
|
|
134
|
+
const riskScore = Math.min(1, 0.6 * successRate + 0.4 * recencyWeightedRate);
|
|
135
|
+
// Top category: most vulns found for this file
|
|
136
|
+
const catCounts = new Map();
|
|
137
|
+
for (const a of attacks) {
|
|
138
|
+
catCounts.set(a.category, (catCounts.get(a.category) ?? 0) + a.found);
|
|
139
|
+
}
|
|
140
|
+
let topCategory = attacks[0].category;
|
|
141
|
+
let maxCount = 0;
|
|
142
|
+
for (const [cat, count] of catCounts) {
|
|
143
|
+
if (count > maxCount) {
|
|
144
|
+
maxCount = count;
|
|
145
|
+
topCategory = cat;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
priorities.push({ file, riskScore, topCategory });
|
|
149
|
+
}
|
|
150
|
+
priorities.sort((a, b) => b.riskScore - a.riskScore);
|
|
151
|
+
// Proactive checks: categories with >50% historical attack success
|
|
152
|
+
const catStats = new Map();
|
|
153
|
+
for (const round of allRounds) {
|
|
154
|
+
const stats = catStats.get(round.category) ?? { total: 0, successful: 0 };
|
|
155
|
+
stats.total++;
|
|
156
|
+
if (round.vulnerabilitiesFound > 0)
|
|
157
|
+
stats.successful++;
|
|
158
|
+
catStats.set(round.category, stats);
|
|
159
|
+
}
|
|
160
|
+
const proactiveChecks = [];
|
|
161
|
+
for (const [cat, stats] of catStats) {
|
|
162
|
+
if (stats.total > 0 && stats.successful / stats.total > 0.5) {
|
|
163
|
+
proactiveChecks.push(cat);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { priorities, proactiveChecks };
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Record a round's results. Updates the Beta distribution parameters for
|
|
170
|
+
* the attacked category and persists state to the graph.
|
|
171
|
+
*/
|
|
172
|
+
recordRound(result) {
|
|
173
|
+
const arm = this.arms.get(result.category);
|
|
174
|
+
if (!arm)
|
|
175
|
+
return;
|
|
176
|
+
// Update Beta params: success → α++, failure → β++
|
|
177
|
+
if (result.vulnerabilitiesFound > 0) {
|
|
178
|
+
arm.alpha++;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
arm.beta_++;
|
|
182
|
+
}
|
|
183
|
+
arm.roundsApplied++;
|
|
184
|
+
if (result.vulnerabilitiesPatched > 0) {
|
|
185
|
+
arm.recentlyPatched = result.vulnerabilitiesPatched;
|
|
186
|
+
arm.lastPatchedRound = result.roundNumber;
|
|
187
|
+
}
|
|
188
|
+
this.history.push(result);
|
|
189
|
+
// Persist arm state
|
|
190
|
+
this.saveToGraph();
|
|
191
|
+
// Persist round as graph node + edges
|
|
192
|
+
const roundId = `adversarial:round:${result.roundNumber}:${result.category}`;
|
|
193
|
+
this.graph.addNode({
|
|
194
|
+
id: roundId,
|
|
195
|
+
type: 'heuristic',
|
|
196
|
+
label: `Attack round ${result.roundNumber}: ${result.category}`,
|
|
197
|
+
properties: {
|
|
198
|
+
category: result.category,
|
|
199
|
+
vulnerabilitiesFound: result.vulnerabilitiesFound,
|
|
200
|
+
vulnerabilitiesPatched: result.vulnerabilitiesPatched,
|
|
201
|
+
files: result.files,
|
|
202
|
+
roundNumber: result.roundNumber,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
this.graph.addEdge({
|
|
206
|
+
source: roundId,
|
|
207
|
+
target: `adversarial:arm:${result.category}`,
|
|
208
|
+
type: 'learned_from',
|
|
209
|
+
confidence: 'EXTRACTED',
|
|
210
|
+
});
|
|
211
|
+
for (const file of result.files) {
|
|
212
|
+
const fileId = `file:${file}`;
|
|
213
|
+
this.graph.addNode({ id: fileId, type: 'file', label: file });
|
|
214
|
+
this.graph.addEdge({
|
|
215
|
+
source: roundId,
|
|
216
|
+
target: fileId,
|
|
217
|
+
type: 'touched_file',
|
|
218
|
+
confidence: 'EXTRACTED',
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Compute a vulnerability heatmap across all files in history.
|
|
224
|
+
* Files with more unresolved vulnerabilities and recent attack success
|
|
225
|
+
* rank higher.
|
|
226
|
+
*/
|
|
227
|
+
getVulnerabilityHeatmap() {
|
|
228
|
+
if (this.history.length === 0)
|
|
229
|
+
return [];
|
|
230
|
+
const maxRound = Math.max(...this.history.map((r) => r.roundNumber));
|
|
231
|
+
// Group by file
|
|
232
|
+
const fileMap = new Map();
|
|
233
|
+
for (const round of this.history) {
|
|
234
|
+
for (const file of round.files) {
|
|
235
|
+
if (!fileMap.has(file))
|
|
236
|
+
fileMap.set(file, []);
|
|
237
|
+
fileMap.get(file).push({
|
|
238
|
+
found: round.vulnerabilitiesFound,
|
|
239
|
+
patched: round.vulnerabilitiesPatched,
|
|
240
|
+
roundNumber: round.roundNumber,
|
|
241
|
+
category: round.category,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const heatmap = [];
|
|
246
|
+
for (const [file, attacks] of fileMap) {
|
|
247
|
+
const totalAttacks = attacks.length;
|
|
248
|
+
const totalFound = attacks.reduce((sum, a) => sum + a.found, 0);
|
|
249
|
+
const totalPatched = attacks.reduce((sum, a) => sum + a.patched, 0);
|
|
250
|
+
const unresolvedCount = totalFound - totalPatched;
|
|
251
|
+
const successCount = attacks.filter((a) => a.found > 0).length;
|
|
252
|
+
const successRate = totalAttacks > 0 ? successCount / totalAttacks : 0;
|
|
253
|
+
let weightedSum = 0;
|
|
254
|
+
let totalWeight = 0;
|
|
255
|
+
for (const a of attacks) {
|
|
256
|
+
const weight = Math.exp(-0.14 * (maxRound - a.roundNumber));
|
|
257
|
+
weightedSum += weight * (a.found > 0 ? 1 : 0);
|
|
258
|
+
totalWeight += weight;
|
|
259
|
+
}
|
|
260
|
+
const recencyWeightedRate = totalWeight > 0 ? weightedSum / totalWeight : 0;
|
|
261
|
+
const riskScore = Math.min(1, 0.6 * successRate + 0.4 * recencyWeightedRate);
|
|
262
|
+
// Top category by most vulnerabilities found
|
|
263
|
+
const catCounts = new Map();
|
|
264
|
+
for (const a of attacks) {
|
|
265
|
+
catCounts.set(a.category, (catCounts.get(a.category) ?? 0) + a.found);
|
|
266
|
+
}
|
|
267
|
+
let topCategory = attacks[0].category;
|
|
268
|
+
let maxCount = 0;
|
|
269
|
+
for (const [cat, count] of catCounts) {
|
|
270
|
+
if (count > maxCount) {
|
|
271
|
+
maxCount = count;
|
|
272
|
+
topCategory = cat;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
heatmap.push({ file, riskScore, topCategory, unresolvedCount, totalAttacks });
|
|
276
|
+
}
|
|
277
|
+
heatmap.sort((a, b) => b.riskScore - a.riskScore);
|
|
278
|
+
return heatmap;
|
|
279
|
+
}
|
|
280
|
+
// ─── Graph Persistence ──────────────────────────────────────────
|
|
281
|
+
saveToGraph() {
|
|
282
|
+
for (const [, arm] of this.arms) {
|
|
283
|
+
this.graph.addNode({
|
|
284
|
+
id: `adversarial:arm:${arm.category}`,
|
|
285
|
+
type: 'heuristic',
|
|
286
|
+
label: `Adversarial arm: ${arm.category}`,
|
|
287
|
+
properties: {
|
|
288
|
+
alpha: arm.alpha,
|
|
289
|
+
beta_: arm.beta_,
|
|
290
|
+
roundsApplied: arm.roundsApplied,
|
|
291
|
+
recentlyPatched: arm.recentlyPatched,
|
|
292
|
+
lastPatchedRound: arm.lastPatchedRound,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
loadFromGraph() {
|
|
298
|
+
// Restore arm state from persisted nodes
|
|
299
|
+
for (const cat of ALL_ATTACK_CATEGORIES) {
|
|
300
|
+
const node = this.graph.getNode(`adversarial:arm:${cat}`);
|
|
301
|
+
if (node) {
|
|
302
|
+
const p = node.properties;
|
|
303
|
+
this.arms.set(cat, {
|
|
304
|
+
category: cat,
|
|
305
|
+
alpha: p.alpha ?? 1,
|
|
306
|
+
beta_: p.beta_ ?? 1,
|
|
307
|
+
roundsApplied: p.roundsApplied ?? 0,
|
|
308
|
+
recentlyPatched: p.recentlyPatched ?? 0,
|
|
309
|
+
lastPatchedRound: p.lastPatchedRound ?? 0,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// Restore round history from persisted nodes
|
|
314
|
+
const heuristicNodes = this.graph.getNodesByType('heuristic');
|
|
315
|
+
for (const node of heuristicNodes) {
|
|
316
|
+
if (node.id.startsWith('adversarial:round:')) {
|
|
317
|
+
const p = node.properties;
|
|
318
|
+
if (p.category && p.roundNumber !== undefined) {
|
|
319
|
+
this.history.push({
|
|
320
|
+
category: p.category,
|
|
321
|
+
vulnerabilitiesFound: p.vulnerabilitiesFound ?? 0,
|
|
322
|
+
vulnerabilitiesPatched: p.vulnerabilitiesPatched ?? 0,
|
|
323
|
+
files: p.files ?? [],
|
|
324
|
+
roundNumber: p.roundNumber,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
this.history.sort((a, b) => a.roundNumber - b.roundNumber);
|
|
330
|
+
}
|
|
331
|
+
// ─── Statistical Sampling (pure TypeScript, no deps) ────────────
|
|
332
|
+
/**
|
|
333
|
+
* Sample from Beta(α, β) distribution using the ratio of two Gamma samples.
|
|
334
|
+
*/
|
|
335
|
+
static sampleBeta(alpha, beta_, rng = Math.random) {
|
|
336
|
+
const x = AdversarialEvolver.sampleGamma(alpha, rng);
|
|
337
|
+
const y = AdversarialEvolver.sampleGamma(beta_, rng);
|
|
338
|
+
if (x + y === 0)
|
|
339
|
+
return 0.5;
|
|
340
|
+
return x / (x + y);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Sample from Gamma(shape) distribution via Marsaglia-Tsang method.
|
|
344
|
+
*/
|
|
345
|
+
static sampleGamma(shape, rng = Math.random) {
|
|
346
|
+
if (shape < 1) {
|
|
347
|
+
return AdversarialEvolver.sampleGamma(shape + 1, rng) * Math.pow(rng(), 1 / shape);
|
|
348
|
+
}
|
|
349
|
+
const d = shape - 1 / 3;
|
|
350
|
+
const c = 1 / Math.sqrt(9 * d);
|
|
351
|
+
for (;;) {
|
|
352
|
+
let x;
|
|
353
|
+
let v;
|
|
354
|
+
do {
|
|
355
|
+
x = AdversarialEvolver.sampleNormal(rng);
|
|
356
|
+
v = Math.pow(1 + c * x, 3);
|
|
357
|
+
} while (v <= 0);
|
|
358
|
+
if (rng() < 1 - 0.0331 * Math.pow(x, 4)) {
|
|
359
|
+
return d * v;
|
|
360
|
+
}
|
|
361
|
+
if (Math.log(rng()) < 0.5 * x * x + d * (1 - v + Math.log(v))) {
|
|
362
|
+
return d * v;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Sample from standard Normal distribution via Box-Muller transform.
|
|
368
|
+
*/
|
|
369
|
+
static sampleNormal(rng = Math.random) {
|
|
370
|
+
let u1;
|
|
371
|
+
do {
|
|
372
|
+
u1 = rng();
|
|
373
|
+
} while (u1 === 0);
|
|
374
|
+
const u2 = rng();
|
|
375
|
+
return Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
//# sourceMappingURL=graph-adversarial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-adversarial.js","sourceRoot":"","sources":["../../src/runtime/graph-adversarial.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,qBAAqB,GAAqB;IACrD,WAAW;IACX,aAAa;IACb,eAAe;IACf,gBAAgB;IAChB,qBAAqB;IACrB,kBAAkB;IAClB,gBAAgB;IAChB,iBAAiB;CAClB,CAAC;AAsCF,qEAAqE;AAErE;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAIT;IAHZ,IAAI,CAAmC;IACvC,OAAO,CAAgB;IAE/B,YAAoB,KAAqB;QAArB,UAAK,GAAL,KAAK,CAAgB;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,KAAK,MAAM,GAAG,IAAI,qBAAqB,EAAE,CAAC;YACxC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;gBACjB,QAAQ,EAAE,GAAG;gBACb,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,CAAC;gBACR,aAAa,EAAE,CAAC;gBAChB,eAAe,EAAE,CAAC;gBAClB,gBAAgB,EAAE,CAAC;aACpB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,oBAAoB,CAAC,WAAqB,EAAE,cAA6B;QACvE,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE3G,MAAM,MAAM,GAAuD,EAAE,CAAC;QAEtE,KAAK,MAAM,CAA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F"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { GraphNode, GraphEdge, GraphNodeType, GraphEdgeType, PhaseGateResult, PhaseGateConfig } from '../core/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read-only interface for ExecutionGraph methods used by the analyzer.
|
|
4
|
+
* Decouples from the concrete SQLite-backed implementation for testability,
|
|
5
|
+
* following the same pattern as GraphContextRouter's ExecutionGraphReader.
|
|
6
|
+
*/
|
|
7
|
+
export interface GraphAnalyzable {
|
|
8
|
+
getNode(id: string): GraphNode | null;
|
|
9
|
+
getNodesByType(type: GraphNodeType): GraphNode[];
|
|
10
|
+
getEdgesByType(type: GraphEdgeType): GraphEdge[];
|
|
11
|
+
getEdges(nodeId: string, direction?: 'outgoing' | 'incoming' | 'both'): GraphEdge[];
|
|
12
|
+
getNeighbors(nodeId: string, edgeType?: GraphEdgeType): GraphNode[];
|
|
13
|
+
bfs(startId: string, maxDepth?: number): {
|
|
14
|
+
nodes: GraphNode[];
|
|
15
|
+
edges: GraphEdge[];
|
|
16
|
+
};
|
|
17
|
+
shortestPath(fromId: string, toId: string, maxHops?: number): {
|
|
18
|
+
nodes: GraphNode[];
|
|
19
|
+
edges: GraphEdge[];
|
|
20
|
+
} | null;
|
|
21
|
+
}
|
|
22
|
+
export interface GodNode {
|
|
23
|
+
node: GraphNode;
|
|
24
|
+
degree: number;
|
|
25
|
+
inDegree: number;
|
|
26
|
+
outDegree: number;
|
|
27
|
+
fanOut: number;
|
|
28
|
+
}
|
|
29
|
+
export interface FailurePrediction {
|
|
30
|
+
nodeId: string;
|
|
31
|
+
label: string;
|
|
32
|
+
riskScore: number;
|
|
33
|
+
reasons: string[];
|
|
34
|
+
historicalFailRate: number;
|
|
35
|
+
}
|
|
36
|
+
export interface TopologySuggestion {
|
|
37
|
+
type: 'isolated_output' | 'bottleneck' | 'thin_cluster' | 'ambiguous_dependency' | 'high_centrality';
|
|
38
|
+
message: string;
|
|
39
|
+
nodeIds: string[];
|
|
40
|
+
severity: 'info' | 'warning' | 'critical';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Pre-execution analysis (centrality, failure prediction) and post-execution
|
|
44
|
+
* insights (topology-driven suggestions) over the execution knowledge graph.
|
|
45
|
+
*
|
|
46
|
+
* All analysis is purely structural — no LLM calls, just graph topology.
|
|
47
|
+
*/
|
|
48
|
+
export declare class GraphAnalyzer {
|
|
49
|
+
private graph;
|
|
50
|
+
constructor(graph: GraphAnalyzable);
|
|
51
|
+
/**
|
|
52
|
+
* Find "god nodes" — nodes with highest degree, excluding orchestration
|
|
53
|
+
* hubs (which are structurally central by definition, not interesting).
|
|
54
|
+
*/
|
|
55
|
+
findGodNodes(options?: {
|
|
56
|
+
type?: GraphNodeType;
|
|
57
|
+
limit?: number;
|
|
58
|
+
}): GodNode[];
|
|
59
|
+
/**
|
|
60
|
+
* Sampling-based betweenness centrality approximation.
|
|
61
|
+
*
|
|
62
|
+
* Samples random node pairs, finds shortest paths between them, and counts
|
|
63
|
+
* how often each intermediate node appears on those paths. Nodes that
|
|
64
|
+
* frequently appear as bridges score highest.
|
|
65
|
+
*
|
|
66
|
+
* O(samples × avgPathLength) vs O(V×E) for exact Brandes algorithm.
|
|
67
|
+
* Normalizes by valid paths found (not total samples) for meaningful scores.
|
|
68
|
+
*/
|
|
69
|
+
computeCentrality(sampleSize?: number): Map<string, number>;
|
|
70
|
+
/**
|
|
71
|
+
* Predict which agents are most likely to fail based on graph signals:
|
|
72
|
+
*
|
|
73
|
+
* - Historical fail rate for the agent type (min 3 samples)
|
|
74
|
+
* - Files with prior error associations (caused_by edges)
|
|
75
|
+
* - Ambiguous inbound dependencies
|
|
76
|
+
* - High fan-in (more dependencies = more that can go wrong)
|
|
77
|
+
*/
|
|
78
|
+
predictFailures(orchestrationId?: string, files?: string[]): FailurePrediction[];
|
|
79
|
+
/**
|
|
80
|
+
* Post-execution topology-driven suggestions.
|
|
81
|
+
*
|
|
82
|
+
* Detects structural issues without any LLM:
|
|
83
|
+
* 1. Isolated outputs — agents whose work was never consumed
|
|
84
|
+
* 2. High-centrality bottlenecks — single points of failure
|
|
85
|
+
* 3. Ambiguous dependencies — edges that need verification
|
|
86
|
+
*/
|
|
87
|
+
suggestImprovements(orchestrationId?: string): TopologySuggestion[];
|
|
88
|
+
/**
|
|
89
|
+
* Evaluate whether a phase should proceed, warn, or halt based on
|
|
90
|
+
* reflection confidence and historical pattern success rates.
|
|
91
|
+
*/
|
|
92
|
+
evaluatePhaseConfidence(phase: {
|
|
93
|
+
kind: string;
|
|
94
|
+
agentCount: number;
|
|
95
|
+
outputs: string[];
|
|
96
|
+
usage?: {
|
|
97
|
+
totalTokens: number;
|
|
98
|
+
};
|
|
99
|
+
}, reflection: {
|
|
100
|
+
confidence: 'high' | 'medium' | 'low';
|
|
101
|
+
}, patternStats?: {
|
|
102
|
+
successRate: number;
|
|
103
|
+
avgDurationMs: number;
|
|
104
|
+
}, config?: PhaseGateConfig): PhaseGateResult;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=graph-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-analyzer.d.ts","sourceRoot":"","sources":["../../src/runtime/graph-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,aAAa,EACb,aAAa,EAEb,eAAe,EACf,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAI1B;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACtC,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,CAAC;IACjD,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,EAAE,CAAC;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,EAAE,CAA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