@opena2a/oasb 0.2.0 → 0.3.1

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.
Files changed (52) hide show
  1. package/README.md +61 -18
  2. package/dist/harness/adapter.d.ts +205 -0
  3. package/dist/harness/adapter.js +18 -0
  4. package/dist/harness/arp-wrapper.d.ts +25 -20
  5. package/dist/harness/arp-wrapper.js +137 -28
  6. package/dist/harness/capabilities.d.ts +26 -0
  7. package/dist/harness/capabilities.js +76 -0
  8. package/dist/harness/create-adapter.d.ts +16 -0
  9. package/dist/harness/create-adapter.js +40 -0
  10. package/dist/harness/event-collector.d.ts +1 -1
  11. package/dist/harness/llm-guard-wrapper.d.ts +32 -0
  12. package/dist/harness/llm-guard-wrapper.js +325 -0
  13. package/dist/harness/mock-llm-adapter.d.ts +2 -2
  14. package/dist/harness/mock-llm-adapter.js +6 -5
  15. package/dist/harness/rebuff-wrapper.d.ts +32 -0
  16. package/dist/harness/rebuff-wrapper.js +325 -0
  17. package/dist/harness/types.d.ts +4 -38
  18. package/package.json +15 -7
  19. package/src/atomic/ai-layer/AT-AI-001.prompt-input-scan.test.ts +18 -42
  20. package/src/atomic/ai-layer/AT-AI-002.prompt-output-scan.test.ts +13 -32
  21. package/src/atomic/ai-layer/AT-AI-003.mcp-tool-scan.test.ts +18 -42
  22. package/src/atomic/ai-layer/AT-AI-004.a2a-message-scan.test.ts +14 -36
  23. package/src/atomic/ai-layer/AT-AI-005.pattern-coverage.test.ts +11 -5
  24. package/src/atomic/enforcement/AT-ENF-001.log-action.test.ts +4 -4
  25. package/src/atomic/enforcement/AT-ENF-002.alert-callback.test.ts +5 -5
  26. package/src/atomic/enforcement/AT-ENF-003.pause-sigstop.test.ts +4 -4
  27. package/src/atomic/enforcement/AT-ENF-004.kill-sigterm.test.ts +5 -5
  28. package/src/atomic/enforcement/AT-ENF-005.resume-sigcont.test.ts +4 -4
  29. package/src/atomic/intelligence/AT-INT-001.l0-rule-match.test.ts +1 -1
  30. package/src/atomic/intelligence/AT-INT-002.l1-anomaly-score.test.ts +10 -8
  31. package/src/atomic/intelligence/AT-INT-003.l2-escalation.test.ts +1 -1
  32. package/src/atomic/intelligence/AT-INT-004.budget-exhaustion.test.ts +8 -6
  33. package/src/atomic/intelligence/AT-INT-005.baseline-learning.test.ts +9 -9
  34. package/src/baseline/BL-002.anomaly-injection.test.ts +6 -6
  35. package/src/baseline/BL-003.baseline-persistence.test.ts +9 -9
  36. package/src/harness/adapter.ts +261 -0
  37. package/src/harness/arp-wrapper.ts +175 -42
  38. package/src/harness/capabilities.ts +79 -0
  39. package/src/harness/create-adapter.ts +53 -0
  40. package/src/harness/event-collector.ts +1 -1
  41. package/src/harness/llm-guard-wrapper.ts +345 -0
  42. package/src/harness/mock-llm-adapter.ts +7 -6
  43. package/src/harness/rebuff-wrapper.ts +343 -0
  44. package/src/harness/types.ts +33 -39
  45. package/src/integration/INT-001.data-exfil-detection.test.ts +1 -1
  46. package/src/integration/INT-002.mcp-tool-abuse.test.ts +1 -1
  47. package/src/integration/INT-003.prompt-injection-response.test.ts +1 -1
  48. package/src/integration/INT-004.a2a-trust-exploitation.test.ts +1 -1
  49. package/src/integration/INT-005.baseline-then-attack.test.ts +1 -1
  50. package/src/integration/INT-006.multi-monitor-correlation.test.ts +1 -1
  51. package/src/integration/INT-007.budget-exhaustion-attack.test.ts +8 -8
  52. package/src/integration/INT-008.kill-switch-recovery.test.ts +6 -6
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.describeWithCapability = void 0;
4
+ exports.hasCapability = hasCapability;
5
+ exports.requireCapability = requireCapability;
6
+ exports.getCapabilityMatrix = getCapabilityMatrix;
7
+ /**
8
+ * Capability-aware test helpers.
9
+ *
10
+ * Tests call requireCapability() to skip gracefully when the
11
+ * adapter under test doesn't support a given feature. This produces
12
+ * an honest scorecard: N/A instead of FAIL.
13
+ *
14
+ * @example
15
+ * import { requireCapability } from '../harness/capabilities';
16
+ *
17
+ * describe('MCP Tool Scanning', () => {
18
+ * requireCapability('mcp-scanning');
19
+ * // tests only run if adapter has mcp-scanning
20
+ * });
21
+ */
22
+ const vitest_1 = require("vitest");
23
+ const create_adapter_1 = require("./create-adapter");
24
+ let _matrix = null;
25
+ function getMatrix() {
26
+ if (!_matrix) {
27
+ const adapter = (0, create_adapter_1.createAdapter)();
28
+ _matrix = adapter.getCapabilities();
29
+ }
30
+ return _matrix;
31
+ }
32
+ /**
33
+ * Check if the current adapter has a capability.
34
+ */
35
+ function hasCapability(cap) {
36
+ return getMatrix().capabilities.has(cap);
37
+ }
38
+ /**
39
+ * Call at the top of a describe() block to skip the entire suite
40
+ * if the adapter lacks the required capability.
41
+ *
42
+ * Uses describe.skipIf() so the tests show as skipped, not failed.
43
+ */
44
+ function requireCapability(cap) {
45
+ const has = hasCapability(cap);
46
+ if (!has) {
47
+ // Can't use describe.skipIf at this point, but we can use
48
+ // a beforeAll that throws a skip. The caller should use
49
+ // describeWithCapability instead for cleaner skip behavior.
50
+ }
51
+ }
52
+ /**
53
+ * A describe() wrapper that skips the entire suite if the adapter
54
+ * lacks the required capability. Produces N/A in the scorecard.
55
+ *
56
+ * @example
57
+ * describeWithCapability('mcp-scanning', 'MCP Tool Scanning', () => {
58
+ * it('should detect path traversal', () => { ... });
59
+ * });
60
+ */
61
+ const describeWithCapability = (cap, name, fn) => {
62
+ const has = hasCapability(cap);
63
+ if (has) {
64
+ (0, vitest_1.describe)(name, fn);
65
+ }
66
+ else {
67
+ vitest_1.describe.skip(`${name} [requires: ${cap}]`, fn);
68
+ }
69
+ };
70
+ exports.describeWithCapability = describeWithCapability;
71
+ /**
72
+ * Get the full capability matrix for reporting.
73
+ */
74
+ function getCapabilityMatrix() {
75
+ return getMatrix();
76
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Adapter factory — selects which security product adapter to use.
3
+ *
4
+ * Set OASB_ADAPTER env var to choose:
5
+ * - "arp" (default) — uses arp-guard (must be installed)
6
+ * - "llm-guard" — uses theRizwan/llm-guard
7
+ * - path to a JS/TS module that exports a class implementing SecurityProductAdapter
8
+ *
9
+ * All test files import from here instead of instantiating adapters directly.
10
+ */
11
+ import type { SecurityProductAdapter, LabConfig } from './adapter';
12
+ /**
13
+ * Create a configured adapter instance.
14
+ * Uses OASB_ADAPTER env var to select the product under test.
15
+ */
16
+ export declare function createAdapter(config?: LabConfig): SecurityProductAdapter;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAdapter = createAdapter;
4
+ // Eagerly resolve the adapter class at import time.
5
+ // This file is only imported by tests that need the adapter,
6
+ // so the cost is acceptable. Each wrapper handles lazy loading internally.
7
+ const arp_wrapper_1 = require("./arp-wrapper");
8
+ const llm_guard_wrapper_1 = require("./llm-guard-wrapper");
9
+ const rebuff_wrapper_1 = require("./rebuff-wrapper");
10
+ let AdapterClass;
11
+ const adapterName = process.env.OASB_ADAPTER || 'arp';
12
+ switch (adapterName) {
13
+ case 'arp':
14
+ AdapterClass = arp_wrapper_1.ArpWrapper;
15
+ break;
16
+ case 'llm-guard':
17
+ AdapterClass = llm_guard_wrapper_1.LLMGuardWrapper;
18
+ break;
19
+ case 'rebuff':
20
+ AdapterClass = rebuff_wrapper_1.RebuffWrapper;
21
+ break;
22
+ default: {
23
+ // Custom adapter — loaded at module level
24
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
25
+ const mod = require(adapterName);
26
+ const Cls = mod.default || mod.Adapter || mod[Object.keys(mod)[0]];
27
+ if (!Cls || typeof Cls !== 'function') {
28
+ throw new Error(`Module "${adapterName}" does not export an adapter class`);
29
+ }
30
+ AdapterClass = Cls;
31
+ break;
32
+ }
33
+ }
34
+ /**
35
+ * Create a configured adapter instance.
36
+ * Uses OASB_ADAPTER env var to select the product under test.
37
+ */
38
+ function createAdapter(config) {
39
+ return new AdapterClass(config);
40
+ }
@@ -1,4 +1,4 @@
1
- import type { ARPEvent, EnforcementResult } from '@opena2a/arp';
1
+ import type { SecurityEvent as ARPEvent, EnforcementResult } from './adapter';
2
2
  /**
3
3
  * Collects ARP events and enforcement results for test assertions.
4
4
  * Supports async waiting for specific events with timeout.
@@ -0,0 +1,32 @@
1
+ import { EventCollector } from './event-collector';
2
+ import type { SecurityProductAdapter, SecurityEvent, EnforcementResult, LabConfig, PromptScanner, MCPScanner, A2AScanner, PatternScanner, BudgetManager, AnomalyScorer, EventEngine, EnforcementEngine, CapabilityMatrix } from './adapter';
3
+ export declare class LLMGuardWrapper implements SecurityProductAdapter {
4
+ private _dataDir;
5
+ private engine;
6
+ private enforcement;
7
+ private rules;
8
+ readonly collector: EventCollector;
9
+ constructor(labConfig?: LabConfig);
10
+ getCapabilities(): CapabilityMatrix;
11
+ start(): Promise<void>;
12
+ stop(): Promise<void>;
13
+ injectEvent(event: Omit<SecurityEvent, 'id' | 'timestamp' | 'classifiedBy'>): Promise<SecurityEvent>;
14
+ waitForEvent(predicate: (event: SecurityEvent) => boolean, timeoutMs?: number): Promise<SecurityEvent>;
15
+ getEvents(): SecurityEvent[];
16
+ getEventsByCategory(category: string): SecurityEvent[];
17
+ getEnforcements(): EnforcementResult[];
18
+ getEnforcementsByAction(action: string): EnforcementResult[];
19
+ resetCollector(): void;
20
+ getEventEngine(): EventEngine;
21
+ getEnforcementEngine(): EnforcementEngine;
22
+ get dataDir(): string;
23
+ createPromptScanner(): PromptScanner;
24
+ createMCPScanner(_allowedTools?: string[]): MCPScanner;
25
+ createA2AScanner(_trustedAgents?: string[]): A2AScanner;
26
+ createPatternScanner(): PatternScanner;
27
+ createBudgetManager(dataDir: string, config?: {
28
+ budgetUsd?: number;
29
+ maxCallsPerHour?: number;
30
+ }): BudgetManager;
31
+ createAnomalyScorer(): AnomalyScorer;
32
+ }
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.LLMGuardWrapper = void 0;
37
+ /**
38
+ * llm-guard Adapter — Third-party benchmark comparison
39
+ *
40
+ * Wraps theRizwan/llm-guard (npm: llm-guard) for OASB evaluation.
41
+ * This is a prompt-level scanner only — it does NOT provide:
42
+ * - Process/network/filesystem monitoring
43
+ * - MCP tool call validation
44
+ * - A2A message scanning
45
+ * - Anomaly detection / intelligence layers
46
+ * - Enforcement actions (pause/kill/resume)
47
+ *
48
+ * Tests that require these capabilities will get no-op implementations
49
+ * that return empty/negative results, documenting the coverage gap.
50
+ */
51
+ const fs = __importStar(require("fs"));
52
+ const os = __importStar(require("os"));
53
+ const path = __importStar(require("path"));
54
+ const event_collector_1 = require("./event-collector");
55
+ // Lazy-loaded llm-guard
56
+ let _LLMGuard;
57
+ function getLLMGuard() {
58
+ if (!_LLMGuard) {
59
+ _LLMGuard = require('llm-guard').LLMGuard;
60
+ }
61
+ return _LLMGuard;
62
+ }
63
+ /** Convert llm-guard result to OASB ScanResult */
64
+ function toScanResult(guardResult) {
65
+ const matches = [];
66
+ if (guardResult.results) {
67
+ for (const r of guardResult.results) {
68
+ if (!r.valid && r.details) {
69
+ for (const d of r.details) {
70
+ matches.push({
71
+ pattern: {
72
+ id: d.rule || 'LLM-GUARD',
73
+ category: d.rule?.includes('jailbreak') ? 'jailbreak'
74
+ : d.rule?.includes('pii') ? 'data-exfiltration'
75
+ : d.rule?.includes('injection') ? 'prompt-injection'
76
+ : 'unknown',
77
+ description: d.message || '',
78
+ pattern: /./,
79
+ severity: guardResult.score <= 0.3 ? 'high' : 'medium',
80
+ },
81
+ matchedText: d.matched || '',
82
+ });
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return {
88
+ detected: !guardResult.isValid,
89
+ matches,
90
+ };
91
+ }
92
+ /** Simple event engine that stores and emits events */
93
+ class SimpleEventEngine {
94
+ constructor() {
95
+ this.handlers = [];
96
+ this.idCounter = 0;
97
+ }
98
+ emit(event) {
99
+ const full = {
100
+ ...event,
101
+ id: `llmg-${++this.idCounter}`,
102
+ timestamp: new Date().toISOString(),
103
+ classifiedBy: 'llm-guard',
104
+ };
105
+ for (const h of this.handlers) {
106
+ h(full);
107
+ }
108
+ return full;
109
+ }
110
+ onEvent(handler) {
111
+ this.handlers.push(handler);
112
+ }
113
+ }
114
+ /** Simple enforcement engine — llm-guard doesn't have enforcement */
115
+ class SimpleEnforcementEngine {
116
+ constructor() {
117
+ this.pausedPids = new Set();
118
+ }
119
+ async execute(action, event) {
120
+ return { action, success: true, reason: 'llm-guard-enforcement', event };
121
+ }
122
+ pause(pid) {
123
+ this.pausedPids.add(pid);
124
+ return true;
125
+ }
126
+ resume(pid) {
127
+ return this.pausedPids.delete(pid);
128
+ }
129
+ kill(pid) {
130
+ this.pausedPids.delete(pid);
131
+ return true;
132
+ }
133
+ getPausedPids() {
134
+ return [...this.pausedPids];
135
+ }
136
+ setAlertCallback(callback) {
137
+ this.alertCallback = callback;
138
+ }
139
+ }
140
+ class LLMGuardWrapper {
141
+ constructor(labConfig) {
142
+ this._dataDir = labConfig?.dataDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'llmg-lab-'));
143
+ this.engine = new SimpleEventEngine();
144
+ this.enforcement = new SimpleEnforcementEngine();
145
+ this.rules = labConfig?.rules ?? [];
146
+ this.collector = new event_collector_1.EventCollector();
147
+ this.engine.onEvent(async (event) => {
148
+ this.collector.eventHandler(event);
149
+ // Check rules for enforcement
150
+ for (const rule of this.rules) {
151
+ const cond = rule.condition;
152
+ if (cond.category && cond.category !== event.category)
153
+ continue;
154
+ if (cond.source && cond.source !== event.source)
155
+ continue;
156
+ if (cond.minSeverity) {
157
+ const sevOrder = ['info', 'low', 'medium', 'high', 'critical'];
158
+ if (sevOrder.indexOf(event.severity) < sevOrder.indexOf(cond.minSeverity))
159
+ continue;
160
+ }
161
+ const result = await this.enforcement.execute(rule.action, event);
162
+ result.reason = rule.name;
163
+ this.collector.enforcementHandler(result);
164
+ }
165
+ });
166
+ }
167
+ getCapabilities() {
168
+ return {
169
+ product: 'llm-guard',
170
+ version: '0.1.8',
171
+ capabilities: new Set([
172
+ 'prompt-input-scanning',
173
+ 'pattern-scanning',
174
+ ]),
175
+ };
176
+ }
177
+ async start() { }
178
+ async stop() {
179
+ this.collector.reset();
180
+ try {
181
+ fs.rmSync(this._dataDir, { recursive: true, force: true });
182
+ }
183
+ catch { }
184
+ }
185
+ async injectEvent(event) {
186
+ return this.engine.emit(event);
187
+ }
188
+ waitForEvent(predicate, timeoutMs = 10000) {
189
+ return this.collector.waitForEvent(predicate, timeoutMs);
190
+ }
191
+ getEvents() { return this.collector.getEvents(); }
192
+ getEventsByCategory(category) { return this.collector.eventsByCategory(category); }
193
+ getEnforcements() { return this.collector.getEnforcements(); }
194
+ getEnforcementsByAction(action) { return this.collector.enforcementsByAction(action); }
195
+ resetCollector() { this.collector.reset(); }
196
+ getEventEngine() { return this.engine; }
197
+ getEnforcementEngine() { return this.enforcement; }
198
+ get dataDir() { return this._dataDir; }
199
+ // ─── Factory Methods ────────────────────────────────────────────
200
+ createPromptScanner() {
201
+ const LLMGuard = getLLMGuard();
202
+ const guard = new LLMGuard({
203
+ promptInjection: { enabled: true },
204
+ jailbreak: { enabled: true },
205
+ pii: { enabled: true },
206
+ });
207
+ return {
208
+ start: async () => { },
209
+ stop: async () => { },
210
+ scanInput: (text) => {
211
+ // llm-guard is async, but OASB scanner interface is sync.
212
+ // We run synchronously by checking patterns manually.
213
+ // This is a limitation — real usage would be async.
214
+ const result = scanWithPatterns(text, 'input');
215
+ return result;
216
+ },
217
+ scanOutput: (text) => {
218
+ return scanWithPatterns(text, 'output');
219
+ },
220
+ };
221
+ }
222
+ createMCPScanner(_allowedTools) {
223
+ // llm-guard has no MCP scanning capability
224
+ return {
225
+ start: async () => { },
226
+ stop: async () => { },
227
+ scanToolCall: () => ({ detected: false, matches: [] }),
228
+ };
229
+ }
230
+ createA2AScanner(_trustedAgents) {
231
+ // llm-guard has no A2A scanning capability
232
+ return {
233
+ start: async () => { },
234
+ stop: async () => { },
235
+ scanMessage: () => ({ detected: false, matches: [] }),
236
+ };
237
+ }
238
+ createPatternScanner() {
239
+ // llm-guard uses its own internal patterns, not the OASB ThreatPattern format.
240
+ // We expose what we can via regex approximation.
241
+ const patterns = getLLMGuardPatterns();
242
+ return {
243
+ scanText: (text, pats) => scanWithPatterns(text, 'input'),
244
+ getAllPatterns: () => patterns,
245
+ getPatternSets: () => ({
246
+ inputPatterns: patterns.filter(p => p.category !== 'output-leak'),
247
+ outputPatterns: patterns.filter(p => p.category === 'output-leak'),
248
+ mcpPatterns: [],
249
+ a2aPatterns: [],
250
+ }),
251
+ };
252
+ }
253
+ createBudgetManager(dataDir, config) {
254
+ // llm-guard has no budget management — implement a simple one
255
+ let spent = 0;
256
+ let totalCalls = 0;
257
+ let callsThisHour = 0;
258
+ const budgetUsd = config?.budgetUsd ?? 5;
259
+ const maxCallsPerHour = config?.maxCallsPerHour ?? 20;
260
+ return {
261
+ canAfford: (cost) => spent + cost <= budgetUsd && callsThisHour < maxCallsPerHour,
262
+ record: (cost, _tokens) => { spent += cost; totalCalls++; callsThisHour++; },
263
+ getStatus: () => ({
264
+ spent,
265
+ budget: budgetUsd,
266
+ remaining: budgetUsd - spent,
267
+ percentUsed: Math.round((spent / budgetUsd) * 100),
268
+ callsThisHour,
269
+ maxCallsPerHour,
270
+ totalCalls,
271
+ }),
272
+ reset: () => { spent = 0; totalCalls = 0; callsThisHour = 0; },
273
+ };
274
+ }
275
+ createAnomalyScorer() {
276
+ // llm-guard has no anomaly detection — implement a stub
277
+ const baselines = new Map();
278
+ const observations = new Map();
279
+ return {
280
+ score: () => 0,
281
+ record: (event) => {
282
+ const key = event.source;
283
+ if (!observations.has(key))
284
+ observations.set(key, []);
285
+ observations.get(key).push(1);
286
+ const vals = observations.get(key);
287
+ const mean = vals.length;
288
+ baselines.set(key, { mean, stddev: 0, count: 1 });
289
+ },
290
+ getBaseline: (source) => baselines.get(source) ?? null,
291
+ reset: () => { baselines.clear(); observations.clear(); },
292
+ };
293
+ }
294
+ }
295
+ exports.LLMGuardWrapper = LLMGuardWrapper;
296
+ // ─── Internal pattern-based scanning (sync approximation of llm-guard) ───
297
+ function getLLMGuardPatterns() {
298
+ return [
299
+ { id: 'LLMG-PI-001', category: 'prompt-injection', description: 'Instruction override', pattern: /(?:ignore|disregard|forget)\s+(?:all\s+)?(?:previous\s+)?(?:instructions?|prompts?|rules?)/i, severity: 'high' },
300
+ { id: 'LLMG-PI-002', category: 'prompt-injection', description: 'System prompt extraction', pattern: /(?:system\s+prompt|repeat\s+(?:your|the)\s+(?:instructions?|prompt))/i, severity: 'high' },
301
+ { id: 'LLMG-PI-003', category: 'prompt-injection', description: 'Persona override', pattern: /(?:you\s+are\s+now|pretend\s+you\s+are|act\s+as\s+if)/i, severity: 'medium' },
302
+ { id: 'LLMG-JB-001', category: 'jailbreak', description: 'DAN jailbreak', pattern: /(?:DAN|do\s+anything\s+now)/i, severity: 'high' },
303
+ { id: 'LLMG-JB-002', category: 'jailbreak', description: 'Roleplay bypass', pattern: /(?:pretend|imagine|roleplay)\s+(?:you\s+are|as)\s+(?:an?\s+)?(?:evil|unrestricted|unfiltered)/i, severity: 'high' },
304
+ { id: 'LLMG-PII-001', category: 'data-exfiltration', description: 'SSN detection', pattern: /\b\d{3}-\d{2}-\d{4}\b/, severity: 'high' },
305
+ { id: 'LLMG-PII-002', category: 'data-exfiltration', description: 'Credit card detection', pattern: /\b(?:\d{4}[- ]?){3}\d{4}\b/, severity: 'high' },
306
+ { id: 'LLMG-PII-003', category: 'data-exfiltration', description: 'API key detection', pattern: /(?:sk-[a-zA-Z0-9]{20,}|AKIA[A-Z0-9]{12,})/i, severity: 'critical' },
307
+ ];
308
+ }
309
+ function scanWithPatterns(text, _direction) {
310
+ const patterns = getLLMGuardPatterns();
311
+ const matches = [];
312
+ for (const pattern of patterns) {
313
+ const match = pattern.pattern.exec(text);
314
+ if (match) {
315
+ matches.push({
316
+ pattern,
317
+ matchedText: match[0].slice(0, 200),
318
+ });
319
+ }
320
+ }
321
+ return {
322
+ detected: matches.length > 0,
323
+ matches,
324
+ };
325
+ }
@@ -1,4 +1,4 @@
1
- import type { LLMAdapter, LLMResponse } from '@opena2a/arp';
1
+ import type { LLMAdapter, LLMResponse } from './adapter';
2
2
  interface MockCall {
3
3
  prompt: string;
4
4
  maxTokens: number;
@@ -17,7 +17,7 @@ export declare class MockLLMAdapter implements LLMAdapter {
17
17
  latencyMs?: number;
18
18
  costPerCall?: number;
19
19
  });
20
- assess(prompt: string, maxTokens: number): Promise<LLMResponse>;
20
+ assess(prompt: string): Promise<LLMResponse>;
21
21
  estimateCost(inputTokens: number, outputTokens: number): number;
22
22
  healthCheck(): Promise<boolean>;
23
23
  /** Get number of calls made */
@@ -12,17 +12,18 @@ class MockLLMAdapter {
12
12
  this.latencyMs = options?.latencyMs ?? 10;
13
13
  this.costPerCall = options?.costPerCall ?? 0.001;
14
14
  }
15
- async assess(prompt, maxTokens) {
16
- this.calls.push({ prompt, maxTokens, timestamp: Date.now() });
15
+ async assess(prompt) {
16
+ this.calls.push({ prompt, maxTokens: 300, timestamp: Date.now() });
17
17
  if (this.latencyMs > 0) {
18
18
  await new Promise((r) => setTimeout(r, this.latencyMs));
19
19
  }
20
20
  const response = this.generateResponse(prompt);
21
21
  return {
22
22
  content: response,
23
- inputTokens: Math.ceil(prompt.length / 4),
24
- outputTokens: Math.ceil(response.length / 4),
25
- model: 'mock-llm',
23
+ usage: {
24
+ inputTokens: Math.ceil(prompt.length / 4),
25
+ outputTokens: Math.ceil(response.length / 4),
26
+ },
26
27
  };
27
28
  }
28
29
  estimateCost(inputTokens, outputTokens) {
@@ -0,0 +1,32 @@
1
+ import { EventCollector } from './event-collector';
2
+ import type { SecurityProductAdapter, SecurityEvent, EnforcementResult, LabConfig, PromptScanner, MCPScanner, A2AScanner, PatternScanner, BudgetManager, AnomalyScorer, EventEngine, EnforcementEngine, CapabilityMatrix } from './adapter';
3
+ export declare class RebuffWrapper implements SecurityProductAdapter {
4
+ private _dataDir;
5
+ private engine;
6
+ private enforcement;
7
+ private rules;
8
+ readonly collector: EventCollector;
9
+ constructor(labConfig?: LabConfig);
10
+ getCapabilities(): CapabilityMatrix;
11
+ start(): Promise<void>;
12
+ stop(): Promise<void>;
13
+ injectEvent(event: Omit<SecurityEvent, 'id' | 'timestamp' | 'classifiedBy'>): Promise<SecurityEvent>;
14
+ waitForEvent(predicate: (event: SecurityEvent) => boolean, timeoutMs?: number): Promise<SecurityEvent>;
15
+ getEvents(): SecurityEvent[];
16
+ getEventsByCategory(category: string): SecurityEvent[];
17
+ getEnforcements(): EnforcementResult[];
18
+ getEnforcementsByAction(action: string): EnforcementResult[];
19
+ resetCollector(): void;
20
+ getEventEngine(): EventEngine;
21
+ getEnforcementEngine(): EnforcementEngine;
22
+ get dataDir(): string;
23
+ createPromptScanner(): PromptScanner;
24
+ createMCPScanner(_allowedTools?: string[]): MCPScanner;
25
+ createA2AScanner(_trustedAgents?: string[]): A2AScanner;
26
+ createPatternScanner(): PatternScanner;
27
+ createBudgetManager(dataDir: string, config?: {
28
+ budgetUsd?: number;
29
+ maxCallsPerHour?: number;
30
+ }): BudgetManager;
31
+ createAnomalyScorer(): AnomalyScorer;
32
+ }