@panguard-ai/atr 0.2.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/LICENSE +21 -0
- package/README.md +299 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +720 -0
- package/dist/cli.js.map +1 -0
- package/dist/coverage-analyzer.d.ts +43 -0
- package/dist/coverage-analyzer.d.ts.map +1 -0
- package/dist/coverage-analyzer.js +329 -0
- package/dist/coverage-analyzer.js.map +1 -0
- package/dist/engine.d.ts +127 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +636 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +21 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +124 -0
- package/dist/loader.js.map +1 -0
- package/dist/mcp-server.d.ts +13 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +220 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-tools/coverage-gaps.d.ts +13 -0
- package/dist/mcp-tools/coverage-gaps.d.ts.map +1 -0
- package/dist/mcp-tools/coverage-gaps.js +55 -0
- package/dist/mcp-tools/coverage-gaps.js.map +1 -0
- package/dist/mcp-tools/list-rules.d.ts +17 -0
- package/dist/mcp-tools/list-rules.d.ts.map +1 -0
- package/dist/mcp-tools/list-rules.js +45 -0
- package/dist/mcp-tools/list-rules.js.map +1 -0
- package/dist/mcp-tools/scan.d.ts +18 -0
- package/dist/mcp-tools/scan.d.ts.map +1 -0
- package/dist/mcp-tools/scan.js +75 -0
- package/dist/mcp-tools/scan.js.map +1 -0
- package/dist/mcp-tools/submit-proposal.d.ts +12 -0
- package/dist/mcp-tools/submit-proposal.d.ts.map +1 -0
- package/dist/mcp-tools/submit-proposal.js +95 -0
- package/dist/mcp-tools/submit-proposal.js.map +1 -0
- package/dist/mcp-tools/threat-summary.d.ts +12 -0
- package/dist/mcp-tools/threat-summary.d.ts.map +1 -0
- package/dist/mcp-tools/threat-summary.js +74 -0
- package/dist/mcp-tools/threat-summary.js.map +1 -0
- package/dist/mcp-tools/validate.d.ts +15 -0
- package/dist/mcp-tools/validate.d.ts.map +1 -0
- package/dist/mcp-tools/validate.js +45 -0
- package/dist/mcp-tools/validate.js.map +1 -0
- package/dist/modules/index.d.ts +144 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +82 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/semantic.d.ts +105 -0
- package/dist/modules/semantic.d.ts.map +1 -0
- package/dist/modules/semantic.js +283 -0
- package/dist/modules/semantic.js.map +1 -0
- package/dist/modules/session.d.ts +70 -0
- package/dist/modules/session.d.ts.map +1 -0
- package/dist/modules/session.js +128 -0
- package/dist/modules/session.js.map +1 -0
- package/dist/rule-scaffolder.d.ts +39 -0
- package/dist/rule-scaffolder.d.ts.map +1 -0
- package/dist/rule-scaffolder.js +173 -0
- package/dist/rule-scaffolder.js.map +1 -0
- package/dist/session-tracker.d.ts +56 -0
- package/dist/session-tracker.d.ts.map +1 -0
- package/dist/session-tracker.js +175 -0
- package/dist/session-tracker.js.map +1 -0
- package/dist/skill-fingerprint.d.ts +96 -0
- package/dist/skill-fingerprint.d.ts.map +1 -0
- package/dist/skill-fingerprint.js +337 -0
- package/dist/skill-fingerprint.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -0
- package/rules/agent-manipulation/ATR-2026-030-cross-agent-attack.yaml +175 -0
- package/rules/agent-manipulation/ATR-2026-032-goal-hijacking.yaml +135 -0
- package/rules/agent-manipulation/ATR-2026-074-cross-agent-privilege-escalation.yaml +115 -0
- package/rules/agent-manipulation/ATR-2026-076-inter-agent-message-spoofing.yaml +165 -0
- package/rules/agent-manipulation/ATR-2026-077-human-trust-exploitation.yaml +144 -0
- package/rules/context-exfiltration/ATR-2026-020-system-prompt-leak.yaml +175 -0
- package/rules/context-exfiltration/ATR-2026-021-api-key-exposure.yaml +176 -0
- package/rules/context-exfiltration/ATR-2026-075-agent-memory-manipulation.yaml +115 -0
- package/rules/data-poisoning/ATR-2026-070-data-poisoning.yaml +160 -0
- package/rules/excessive-autonomy/ATR-2026-050-runaway-agent-loop.yaml +134 -0
- package/rules/excessive-autonomy/ATR-2026-051-resource-exhaustion.yaml +137 -0
- package/rules/excessive-autonomy/ATR-2026-052-cascading-failure.yaml +153 -0
- package/rules/model-security/ATR-2026-072-model-behavior-extraction.yaml +115 -0
- package/rules/model-security/ATR-2026-073-malicious-finetuning-data.yaml +108 -0
- package/rules/privilege-escalation/ATR-2026-040-privilege-escalation.yaml +175 -0
- package/rules/privilege-escalation/ATR-2026-041-scope-creep.yaml +124 -0
- package/rules/prompt-injection/ATR-2026-001-direct-prompt-injection.yaml +265 -0
- package/rules/prompt-injection/ATR-2026-002-indirect-prompt-injection.yaml +214 -0
- package/rules/prompt-injection/ATR-2026-003-jailbreak-attempt.yaml +250 -0
- package/rules/prompt-injection/ATR-2026-004-system-prompt-override.yaml +204 -0
- package/rules/prompt-injection/ATR-2026-005-multi-turn-injection.yaml +181 -0
- package/rules/prompt-injection/ATR-PRED-2026-001.yaml +61 -0
- package/rules/prompt-injection/ATR-PRED-2026-002.yaml +58 -0
- package/rules/prompt-injection/ATR-PRED-2026-003.yaml +61 -0
- package/rules/prompt-injection/ATR-PRED-2026-005.yaml +55 -0
- package/rules/prompt-injection/ATR-PRED-2026-006.yaml +51 -0
- package/rules/prompt-injection/ATR-PRED-2026-007.yaml +57 -0
- package/rules/prompt-injection/ATR-PRED-2026-008.yaml +57 -0
- package/rules/prompt-injection/ATR-PRED-2026-009.yaml +51 -0
- package/rules/prompt-injection/ATR-PRED-2026-010.yaml +57 -0
- package/rules/prompt-injection/ATR-PRED-2026-011.yaml +53 -0
- package/rules/prompt-injection/ATR-PRED-2026-012.yaml +57 -0
- package/rules/prompt-injection/ATR-PRED-2026-023.yaml +56 -0
- package/rules/prompt-injection/ATR-PRED-2026-025.yaml +68 -0
- package/rules/prompt-injection/ATR-PRED-2026-026.yaml +66 -0
- package/rules/prompt-injection/ATR-PRED-2026-027.yaml +62 -0
- package/rules/skill-compromise/ATR-2026-060-skill-impersonation.yaml +153 -0
- package/rules/skill-compromise/ATR-2026-061-description-behavior-mismatch.yaml +98 -0
- package/rules/skill-compromise/ATR-2026-062-hidden-capability.yaml +96 -0
- package/rules/skill-compromise/ATR-2026-063-skill-chain-attack.yaml +96 -0
- package/rules/skill-compromise/ATR-2026-064-over-permissioned-skill.yaml +115 -0
- package/rules/skill-compromise/ATR-2026-065-skill-update-attack.yaml +93 -0
- package/rules/skill-compromise/ATR-2026-066-parameter-injection.yaml +106 -0
- package/rules/tool-poisoning/ATR-2026-010-mcp-malicious-response.yaml +237 -0
- package/rules/tool-poisoning/ATR-2026-011-tool-output-injection.yaml +185 -0
- package/rules/tool-poisoning/ATR-2026-012-unauthorized-tool-call.yaml +190 -0
- package/rules/tool-poisoning/ATR-2026-013-tool-ssrf.yaml +208 -0
- package/rules/tool-poisoning/ATR-PRED-2026-004.yaml +54 -0
- package/rules/tool-poisoning/ATR-PRED-2026-024.yaml +68 -0
- package/spec/atr-schema.yaml +375 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atr_scan MCP tool - Scan content for agent threats
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/scan
|
|
4
|
+
*/
|
|
5
|
+
const SEVERITY_ORDER = {
|
|
6
|
+
informational: 0,
|
|
7
|
+
low: 1,
|
|
8
|
+
medium: 2,
|
|
9
|
+
high: 3,
|
|
10
|
+
critical: 4,
|
|
11
|
+
};
|
|
12
|
+
const VALID_EVENT_TYPES = new Set([
|
|
13
|
+
'llm_input',
|
|
14
|
+
'llm_output',
|
|
15
|
+
'tool_call',
|
|
16
|
+
'tool_response',
|
|
17
|
+
'agent_behavior',
|
|
18
|
+
'multi_agent_message',
|
|
19
|
+
]);
|
|
20
|
+
export function handleScan(engine, args) {
|
|
21
|
+
const content = args['content'];
|
|
22
|
+
if (typeof content !== 'string' || content.trim().length === 0) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{ type: 'text', text: 'Error: "content" is required and must be a non-empty string.' }],
|
|
25
|
+
isError: true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const eventTypeRaw = args['event_type'] ?? 'llm_input';
|
|
29
|
+
if (!VALID_EVENT_TYPES.has(eventTypeRaw)) {
|
|
30
|
+
return {
|
|
31
|
+
content: [{ type: 'text', text: `Error: Invalid event_type "${eventTypeRaw}". Valid types: ${[...VALID_EVENT_TYPES].join(', ')}` }],
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const minSeverity = (args['min_severity'] ?? 'informational').toLowerCase();
|
|
36
|
+
if (!(minSeverity in SEVERITY_ORDER)) {
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: 'text', text: `Error: Invalid min_severity "${minSeverity}". Valid: informational, low, medium, high, critical` }],
|
|
39
|
+
isError: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const minIdx = SEVERITY_ORDER[minSeverity] ?? 0;
|
|
43
|
+
const event = {
|
|
44
|
+
type: eventTypeRaw,
|
|
45
|
+
timestamp: new Date().toISOString(),
|
|
46
|
+
content: content,
|
|
47
|
+
fields: {
|
|
48
|
+
user_input: content,
|
|
49
|
+
agent_output: content,
|
|
50
|
+
tool_response: content,
|
|
51
|
+
content: content,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const matches = engine.evaluate(event);
|
|
55
|
+
const filtered = matches.filter((m) => (SEVERITY_ORDER[m.rule.severity] ?? 0) >= minIdx);
|
|
56
|
+
const result = {
|
|
57
|
+
threats_found: filtered.length,
|
|
58
|
+
scan_timestamp: event.timestamp,
|
|
59
|
+
event_type: eventTypeRaw,
|
|
60
|
+
matches: filtered.map((m) => ({
|
|
61
|
+
rule_id: m.rule.id,
|
|
62
|
+
title: m.rule.title,
|
|
63
|
+
severity: m.rule.severity,
|
|
64
|
+
category: m.rule.tags.category,
|
|
65
|
+
confidence: Math.round(m.confidence * 100),
|
|
66
|
+
description: m.rule.description,
|
|
67
|
+
matched_patterns: m.matchedPatterns,
|
|
68
|
+
recommended_actions: m.rule.response.actions,
|
|
69
|
+
})),
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/mcp-tools/scan.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,MAAM,cAAc,GAA2B;IAC7C,aAAa,EAAE,CAAC;IAChB,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACrD,WAAW;IACX,YAAY;IACZ,WAAW;IACX,eAAe;IACf,gBAAgB;IAChB,qBAAqB;CACtB,CAAC,CAAC;AAEH,MAAM,UAAU,UAAU,CAAC,MAAiB,EAAE,IAA6B;IAIzE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAChC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/D,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,8DAA8D,EAAE,CAAC;YACjG,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAED,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;IAEF,MAAM,MAAM,GAAG;QACb,aAAa,EAAE,QAAQ,CAAC,MAAM;QAC9B,cAAc,EAAE,KAAK,CAAC,SAAS;QAC/B,UAAU,EAAE,YAAY;QACxB,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5B,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE;YAClB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK;YACnB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;YACzB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAC9B,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC;YAC1C,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW;YAC/B,gBAAgB,EAAE,CAAC,CAAC,eAAe;YACnC,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO;SAC7C,CAAC,CAAC;KACJ,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACnE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atr_submit_proposal MCP tool - Generate ATR rule draft from threat description
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/submit-proposal
|
|
4
|
+
*/
|
|
5
|
+
export declare function handleSubmitProposal(args: Record<string, unknown>): {
|
|
6
|
+
content: Array<{
|
|
7
|
+
type: string;
|
|
8
|
+
text: string;
|
|
9
|
+
}>;
|
|
10
|
+
isError?: boolean;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=submit-proposal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submit-proposal.d.ts","sourceRoot":"","sources":["../../src/mcp-tools/submit-proposal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyBH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACnE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CA+EA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atr_submit_proposal MCP tool - Generate ATR rule draft from threat description
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/submit-proposal
|
|
4
|
+
*/
|
|
5
|
+
import { RuleScaffolder } from '../rule-scaffolder.js';
|
|
6
|
+
const VALID_CATEGORIES = new Set([
|
|
7
|
+
'prompt-injection',
|
|
8
|
+
'tool-poisoning',
|
|
9
|
+
'context-exfiltration',
|
|
10
|
+
'agent-manipulation',
|
|
11
|
+
'privilege-escalation',
|
|
12
|
+
'excessive-autonomy',
|
|
13
|
+
'data-poisoning',
|
|
14
|
+
'model-abuse',
|
|
15
|
+
'skill-compromise',
|
|
16
|
+
]);
|
|
17
|
+
const VALID_SEVERITIES = new Set([
|
|
18
|
+
'critical',
|
|
19
|
+
'high',
|
|
20
|
+
'medium',
|
|
21
|
+
'low',
|
|
22
|
+
'informational',
|
|
23
|
+
]);
|
|
24
|
+
export function handleSubmitProposal(args) {
|
|
25
|
+
const title = args['title'];
|
|
26
|
+
const category = args['category'];
|
|
27
|
+
const attackDescription = args['attack_description'];
|
|
28
|
+
const examplePayloads = args['example_payloads'];
|
|
29
|
+
const severity = args['severity'];
|
|
30
|
+
const mitreRefs = args['mitre_refs'];
|
|
31
|
+
// Validate required fields
|
|
32
|
+
if (typeof title !== 'string' || title.trim().length === 0) {
|
|
33
|
+
return {
|
|
34
|
+
content: [{ type: 'text', text: 'Error: "title" is required and must be a non-empty string.' }],
|
|
35
|
+
isError: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (typeof category !== 'string' || !VALID_CATEGORIES.has(category)) {
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: 'text', text: `Error: "category" must be one of: ${[...VALID_CATEGORIES].join(', ')}` }],
|
|
41
|
+
isError: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (typeof attackDescription !== 'string' || attackDescription.trim().length === 0) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: 'text', text: 'Error: "attack_description" is required and must be a non-empty string.' }],
|
|
47
|
+
isError: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!Array.isArray(examplePayloads) || examplePayloads.length === 0) {
|
|
51
|
+
return {
|
|
52
|
+
content: [{ type: 'text', text: 'Error: "example_payloads" must be a non-empty array of strings.' }],
|
|
53
|
+
isError: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
for (const payload of examplePayloads) {
|
|
57
|
+
if (typeof payload !== 'string') {
|
|
58
|
+
return {
|
|
59
|
+
content: [{ type: 'text', text: 'Error: All items in "example_payloads" must be strings.' }],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (severity && !VALID_SEVERITIES.has(severity)) {
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: 'text', text: `Error: "severity" must be one of: ${[...VALID_SEVERITIES].join(', ')}` }],
|
|
67
|
+
isError: true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const scaffolder = new RuleScaffolder();
|
|
71
|
+
const result = scaffolder.scaffold({
|
|
72
|
+
title: title.trim(),
|
|
73
|
+
category: category,
|
|
74
|
+
attackDescription: attackDescription.trim(),
|
|
75
|
+
examplePayloads: examplePayloads.map((p) => p.trim()),
|
|
76
|
+
severity: severity,
|
|
77
|
+
mitreRefs: mitreRefs,
|
|
78
|
+
});
|
|
79
|
+
const response = {
|
|
80
|
+
generated_id: result.id,
|
|
81
|
+
warnings: result.warnings,
|
|
82
|
+
yaml_rule: result.yaml,
|
|
83
|
+
next_steps: [
|
|
84
|
+
'Review and refine the generated detection patterns',
|
|
85
|
+
'Add more specific regex patterns for your use case',
|
|
86
|
+
'Test with atr_scan using example payloads',
|
|
87
|
+
'Validate with atr_validate_rule before submitting',
|
|
88
|
+
'Submit as a PR to the ATR repository',
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=submit-proposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submit-proposal.js","sourceRoot":"","sources":["../../src/mcp-tools/submit-proposal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC;IACpD,kBAAkB;IAClB,gBAAgB;IAChB,sBAAsB;IACtB,oBAAoB;IACpB,sBAAsB;IACtB,oBAAoB;IACpB,gBAAgB;IAChB,aAAa;IACb,kBAAkB;CACnB,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC;IACpD,UAAU;IACV,MAAM;IACN,QAAQ;IACR,KAAK;IACL,eAAe;CAChB,CAAC,CAAC;AAEH,MAAM,UAAU,oBAAoB,CAAC,IAA6B;IAIhE,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,MAAM,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACrD,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACjD,MAA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IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atr_threat_summary MCP tool - Aggregate threat statistics
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/threat-summary
|
|
4
|
+
*/
|
|
5
|
+
import type { ATREngine } from '../engine.js';
|
|
6
|
+
export declare function handleThreatSummary(engine: ATREngine, args: Record<string, unknown>): {
|
|
7
|
+
content: Array<{
|
|
8
|
+
type: string;
|
|
9
|
+
text: string;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=threat-summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat-summary.d.ts","sourceRoot":"","sources":["../../src/mcp-tools/threat-summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACrF,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,CA8EA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atr_threat_summary MCP tool - Aggregate threat statistics
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/threat-summary
|
|
4
|
+
*/
|
|
5
|
+
export function handleThreatSummary(engine, args) {
|
|
6
|
+
const category = args['category'];
|
|
7
|
+
const rules = [...engine.getRules()];
|
|
8
|
+
const filtered = category
|
|
9
|
+
? rules.filter((r) => r.tags.category === category)
|
|
10
|
+
: rules;
|
|
11
|
+
// Aggregate by category
|
|
12
|
+
const byCategory = {};
|
|
13
|
+
for (const rule of filtered) {
|
|
14
|
+
const cat = rule.tags.category;
|
|
15
|
+
byCategory[cat] = (byCategory[cat] ?? 0) + 1;
|
|
16
|
+
}
|
|
17
|
+
// Aggregate by severity
|
|
18
|
+
const bySeverity = {};
|
|
19
|
+
for (const rule of filtered) {
|
|
20
|
+
bySeverity[rule.severity] = (bySeverity[rule.severity] ?? 0) + 1;
|
|
21
|
+
}
|
|
22
|
+
// Aggregate by status
|
|
23
|
+
const byStatus = {};
|
|
24
|
+
for (const rule of filtered) {
|
|
25
|
+
byStatus[rule.status] = (byStatus[rule.status] ?? 0) + 1;
|
|
26
|
+
}
|
|
27
|
+
// Aggregate by source type
|
|
28
|
+
const bySourceType = {};
|
|
29
|
+
for (const rule of filtered) {
|
|
30
|
+
const src = rule.agent_source.type;
|
|
31
|
+
bySourceType[src] = (bySourceType[src] ?? 0) + 1;
|
|
32
|
+
}
|
|
33
|
+
// Count test cases
|
|
34
|
+
let totalTestCases = 0;
|
|
35
|
+
let rulesWithTests = 0;
|
|
36
|
+
for (const rule of filtered) {
|
|
37
|
+
if (rule.test_cases) {
|
|
38
|
+
rulesWithTests++;
|
|
39
|
+
totalTestCases +=
|
|
40
|
+
(rule.test_cases.true_positives?.length ?? 0) +
|
|
41
|
+
(rule.test_cases.true_negatives?.length ?? 0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Top actions
|
|
45
|
+
const actionCounts = {};
|
|
46
|
+
for (const rule of filtered) {
|
|
47
|
+
for (const action of rule.response.actions) {
|
|
48
|
+
actionCounts[action] = (actionCounts[action] ?? 0) + 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const topActions = Object.entries(actionCounts)
|
|
52
|
+
.sort((a, b) => b[1] - a[1])
|
|
53
|
+
.slice(0, 5)
|
|
54
|
+
.map(([action, count]) => ({ action, count }));
|
|
55
|
+
const result = {
|
|
56
|
+
summary_timestamp: new Date().toISOString(),
|
|
57
|
+
...(category ? { filtered_category: category } : {}),
|
|
58
|
+
total_rules: filtered.length,
|
|
59
|
+
by_category: byCategory,
|
|
60
|
+
by_severity: bySeverity,
|
|
61
|
+
by_status: byStatus,
|
|
62
|
+
by_source_type: bySourceType,
|
|
63
|
+
test_coverage: {
|
|
64
|
+
rules_with_tests: rulesWithTests,
|
|
65
|
+
rules_without_tests: filtered.length - rulesWithTests,
|
|
66
|
+
total_test_cases: totalTestCases,
|
|
67
|
+
},
|
|
68
|
+
top_response_actions: topActions,
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=threat-summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat-summary.js","sourceRoot":"","sources":["../../src/mcp-tools/threat-summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,IAA6B;IAGlF,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAuB,CAAC;IACxD,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAErC,MAAM,QAAQ,GAAG,QAAQ;QACvB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC;QACnD,CAAC,CAAC,KAAK,CAAC;IAEV,wBAAwB;IACxB,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC/B,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,wBAAwB;IACxB,MAAM,UAAU,GAA2B,EAAE,CAAC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|
2
|
+
* atr_validate_rule MCP tool - Validate ATR rule YAML
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/validate
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidateInput {
|
|
6
|
+
yaml_content: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function handleValidate(args: Record<string, unknown>): {
|
|
9
|
+
content: Array<{
|
|
10
|
+
type: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}>;
|
|
13
|
+
isError?: boolean;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/mcp-tools/validate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC7D,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAwCA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* atr_validate_rule MCP tool - Validate ATR rule YAML
|
|
3
|
+
* @module agent-threat-rules/mcp-tools/validate
|
|
4
|
+
*/
|
|
5
|
+
import yaml from 'js-yaml';
|
|
6
|
+
import { validateRule } from '../loader.js';
|
|
7
|
+
export function handleValidate(args) {
|
|
8
|
+
const yamlContent = args['yaml_content'];
|
|
9
|
+
if (typeof yamlContent !== 'string' || yamlContent.trim().length === 0) {
|
|
10
|
+
return {
|
|
11
|
+
content: [{ type: 'text', text: 'Error: "yaml_content" is required and must be a non-empty string.' }],
|
|
12
|
+
isError: true,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const parsed = yaml.load(yamlContent);
|
|
17
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
18
|
+
return {
|
|
19
|
+
content: [{ type: 'text', text: JSON.stringify({ valid: false, errors: ['YAML parsed to a non-object value.'] }, null, 2) }],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const result = validateRule(parsed);
|
|
23
|
+
const response = {
|
|
24
|
+
valid: result.valid,
|
|
25
|
+
errors: result.errors,
|
|
26
|
+
parsed_fields: {
|
|
27
|
+
id: parsed['id'] ?? null,
|
|
28
|
+
title: parsed['title'] ?? null,
|
|
29
|
+
severity: parsed['severity'] ?? null,
|
|
30
|
+
category: parsed['tags']?.['category'] ?? null,
|
|
31
|
+
status: parsed['status'] ?? null,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
40
|
+
return {
|
|
41
|
+
content: [{ type: 'text', text: JSON.stringify({ valid: false, errors: [`YAML parse error: ${msg}`] }, null, 2) }],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/mcp-tools/validate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM5C,MAAM,UAAU,cAAc,CAAC,IAA6B;IAI1D,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;IACzC,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO;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M,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,qBAAqB,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SACnH,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ATR Module System
|
|
3
|
+
*
|
|
4
|
+
* Extensible detection modules beyond regex pattern matching.
|
|
5
|
+
* Inspired by YARA modules, adapted for AI agent threat detection.
|
|
6
|
+
*
|
|
7
|
+
* Built-in modules:
|
|
8
|
+
* - session: Cross-event behavioral analysis using SessionTracker
|
|
9
|
+
* - semantic: AI-driven semantic threat analysis using LLM-as-judge (v0.2)
|
|
10
|
+
*
|
|
11
|
+
* Reserved namespaces (planned):
|
|
12
|
+
* - embedding: Vector similarity detection (v0.3)
|
|
13
|
+
* - protocol: MCP/transport-level inspection (v0.3)
|
|
14
|
+
* - entropy: Information-theoretic anomaly detection (v0.4)
|
|
15
|
+
* - tokenizer: Token-level analysis for smuggling detection (v0.4)
|
|
16
|
+
*
|
|
17
|
+
* @module agent-threat-rules/modules
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentEvent } from '../types.js';
|
|
20
|
+
/**
|
|
21
|
+
* Condition defined by a module (used in rule YAML).
|
|
22
|
+
*
|
|
23
|
+
* Example in YAML:
|
|
24
|
+
* ```yaml
|
|
25
|
+
* detection:
|
|
26
|
+
* conditions:
|
|
27
|
+
* high_frequency:
|
|
28
|
+
* module: session
|
|
29
|
+
* function: call_frequency
|
|
30
|
+
* args:
|
|
31
|
+
* tool_name: "execute_code"
|
|
32
|
+
* window: "5m"
|
|
33
|
+
* operator: gt
|
|
34
|
+
* threshold: 10
|
|
35
|
+
* condition: "high_frequency"
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export interface ModuleCondition {
|
|
39
|
+
/** Module name (e.g., "session", "embedding") */
|
|
40
|
+
module: string;
|
|
41
|
+
/** Function within the module to call */
|
|
42
|
+
function: string;
|
|
43
|
+
/** Arguments passed to the module function */
|
|
44
|
+
args: Record<string, unknown>;
|
|
45
|
+
/** Comparison operator for the result */
|
|
46
|
+
operator: 'gt' | 'lt' | 'eq' | 'gte' | 'lte';
|
|
47
|
+
/** Threshold value to compare against */
|
|
48
|
+
threshold: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Result returned by a module evaluation.
|
|
52
|
+
*/
|
|
53
|
+
export interface ModuleResult {
|
|
54
|
+
/** Whether the condition was met */
|
|
55
|
+
matched: boolean;
|
|
56
|
+
/** Numeric value produced by the module (for threshold comparison) */
|
|
57
|
+
value: number;
|
|
58
|
+
/** Human-readable description of the result */
|
|
59
|
+
description: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Interface that all ATR detection modules must implement.
|
|
63
|
+
*
|
|
64
|
+
* Modules extend ATR's detection beyond regex by providing
|
|
65
|
+
* custom evaluation logic (behavioral analysis, embedding
|
|
66
|
+
* similarity, protocol inspection, etc.).
|
|
67
|
+
*/
|
|
68
|
+
export interface ATRModule {
|
|
69
|
+
/** Unique module name (used in rule YAML) */
|
|
70
|
+
readonly name: string;
|
|
71
|
+
/** Human-readable description */
|
|
72
|
+
readonly description: string;
|
|
73
|
+
/** Module version */
|
|
74
|
+
readonly version: string;
|
|
75
|
+
/**
|
|
76
|
+
* List of functions this module provides.
|
|
77
|
+
* Each function can be referenced in rule conditions.
|
|
78
|
+
*/
|
|
79
|
+
readonly functions: ReadonlyArray<{
|
|
80
|
+
name: string;
|
|
81
|
+
description: string;
|
|
82
|
+
args: ReadonlyArray<{
|
|
83
|
+
name: string;
|
|
84
|
+
type: 'string' | 'number' | 'boolean';
|
|
85
|
+
required: boolean;
|
|
86
|
+
description: string;
|
|
87
|
+
}>;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Initialize the module. Called once when the engine starts.
|
|
91
|
+
* Use for setup, connection pooling, model loading, etc.
|
|
92
|
+
*/
|
|
93
|
+
initialize(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Evaluate a module condition against an agent event.
|
|
96
|
+
*
|
|
97
|
+
* @param event - The agent event being evaluated
|
|
98
|
+
* @param condition - The module condition from the rule
|
|
99
|
+
* @returns Module evaluation result
|
|
100
|
+
*/
|
|
101
|
+
evaluate(event: AgentEvent, condition: ModuleCondition): Promise<ModuleResult>;
|
|
102
|
+
/**
|
|
103
|
+
* Clean up module resources. Called when the engine shuts down.
|
|
104
|
+
*/
|
|
105
|
+
destroy(): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Registry for ATR detection modules.
|
|
109
|
+
*/
|
|
110
|
+
export declare class ModuleRegistry {
|
|
111
|
+
private readonly modules;
|
|
112
|
+
/** Reserved module namespaces (cannot be registered by third parties) */
|
|
113
|
+
private static readonly RESERVED;
|
|
114
|
+
/**
|
|
115
|
+
* Register a detection module.
|
|
116
|
+
* @throws if module name is already registered or reserved
|
|
117
|
+
*/
|
|
118
|
+
register(module: ATRModule): void;
|
|
119
|
+
/**
|
|
120
|
+
* Check if a module name is reserved by the ATR core team.
|
|
121
|
+
*/
|
|
122
|
+
isReserved(name: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Get a registered module by name.
|
|
125
|
+
*/
|
|
126
|
+
get(name: string): ATRModule | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* List all registered modules.
|
|
129
|
+
*/
|
|
130
|
+
list(): ReadonlyArray<{
|
|
131
|
+
name: string;
|
|
132
|
+
version: string;
|
|
133
|
+
description: string;
|
|
134
|
+
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Initialize all registered modules.
|
|
137
|
+
*/
|
|
138
|
+
initializeAll(): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Destroy all registered modules.
|
|
141
|
+
*/
|
|
142
|
+
destroyAll(): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,yCAAyC;IACzC,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC;IAC7C,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,iCAAiC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,qBAAqB;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;QAChC,IAA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.
|
|
5
|
+
* Inspired by YARA modules, adapted for AI agent threat detection.
|
|
6
|
+
*
|
|
7
|
+
* Built-in modules:
|
|
8
|
+
* - session: Cross-event behavioral analysis using SessionTracker
|
|
9
|
+
* - semantic: AI-driven semantic threat analysis using LLM-as-judge (v0.2)
|
|
10
|
+
*
|
|
11
|
+
* Reserved namespaces (planned):
|
|
12
|
+
* - embedding: Vector similarity detection (v0.3)
|
|
13
|
+
* - protocol: MCP/transport-level inspection (v0.3)
|
|
14
|
+
* - entropy: Information-theoretic anomaly detection (v0.4)
|
|
15
|
+
* - tokenizer: Token-level analysis for smuggling detection (v0.4)
|
|
16
|
+
*
|
|
17
|
+
* @module agent-threat-rules/modules
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Registry for ATR detection modules.
|
|
21
|
+
*/
|
|
22
|
+
export class ModuleRegistry {
|
|
23
|
+
modules = new Map();
|
|
24
|
+
/** Reserved module namespaces (cannot be registered by third parties) */
|
|
25
|
+
static RESERVED = new Set([
|
|
26
|
+
'session',
|
|
27
|
+
'semantic',
|
|
28
|
+
'embedding',
|
|
29
|
+
'protocol',
|
|
30
|
+
'entropy',
|
|
31
|
+
'tokenizer',
|
|
32
|
+
]);
|
|
33
|
+
/**
|
|
34
|
+
* Register a detection module.
|
|
35
|
+
* @throws if module name is already registered or reserved
|
|
36
|
+
*/
|
|
37
|
+
register(module) {
|
|
38
|
+
if (this.modules.has(module.name)) {
|
|
39
|
+
throw new Error(`Module "${module.name}" is already registered`);
|
|
40
|
+
}
|
|
41
|
+
this.modules.set(module.name, module);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a module name is reserved by the ATR core team.
|
|
45
|
+
*/
|
|
46
|
+
isReserved(name) {
|
|
47
|
+
return ModuleRegistry.RESERVED.has(name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get a registered module by name.
|
|
51
|
+
*/
|
|
52
|
+
get(name) {
|
|
53
|
+
return this.modules.get(name);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* List all registered modules.
|
|
57
|
+
*/
|
|
58
|
+
list() {
|
|
59
|
+
return Array.from(this.modules.values()).map(m => ({
|
|
60
|
+
name: m.name,
|
|
61
|
+
version: m.version,
|
|
62
|
+
description: m.description,
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Initialize all registered modules.
|
|
67
|
+
*/
|
|
68
|
+
async initializeAll() {
|
|
69
|
+
for (const module of this.modules.values()) {
|
|
70
|
+
await module.initialize();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Destroy all registered modules.
|
|
75
|
+
*/
|
|
76
|
+
async destroyAll() {
|
|
77
|
+
for (const module of this.modules.values()) {
|
|
78
|
+
await module.destroy();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAoGH;;GAEG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAExD,yEAAyE;IACjE,MAAM,CAAU,QAAQ,GAAG,IAAI,GAAG,CAAC;QACzC,SAAS;QACT,UAAU;QACV,WAAW;QACX,UAAU;QACV,SAAS;QACT,WAAW;KACZ,CAAC,CAAC;IAEH;;;OAGG;IACH,QAAQ,CAAC,MAAiB;QACxB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,CAAC,IAAI,yBAAyB,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,C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