agentgate-runtime-control 2.13.8 → 2.13.9
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/bin/agentgate.js +31 -13
- package/package.json +1 -1
package/bin/agentgate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { evaluate } from '../src/policy-engine.js';
|
|
7
7
|
import { createAgentGate } from '../src/agentgate.js';
|
|
@@ -185,20 +185,38 @@ export { pack };
|
|
|
185
185
|
} else if (cmd === 'test' || cmd === 'check') {
|
|
186
186
|
console.log(JSON.stringify(evaluate({ action, amount: Number(amount) }), null, 2));
|
|
187
187
|
} else if (cmd === 'attack') {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
188
|
+
const configIndex = process.argv.indexOf('--config');
|
|
189
|
+
const configPath = configIndex >= 0 ? process.argv[configIndex + 1] : null;
|
|
190
|
+
const defaultTools = [
|
|
191
|
+
{ name: 'export_all', handler: async () => ({ executed: true }) },
|
|
192
|
+
{ name: 'update_production', handler: async () => ({ executed: true }) },
|
|
193
|
+
{ name: 'delete', handler: async () => ({ executed: true }) },
|
|
194
|
+
{ name: 'refund', handler: async args => ({ refunded: args.amount }) },
|
|
195
|
+
{ name: 'publish', handler: async () => ({ executed: true }) }
|
|
196
|
+
];
|
|
197
|
+
let gateway = null;
|
|
198
|
+
let label = 'built-in default policies';
|
|
199
|
+
if (configPath) {
|
|
200
|
+
const resolved = path.resolve(process.cwd(), configPath);
|
|
201
|
+
try {
|
|
202
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
203
|
+
const gate = mod.agentgate || mod.default;
|
|
204
|
+
if (!gate || typeof gate.withMCP !== 'function') {
|
|
205
|
+
console.error(`No 'agentgate' export found in ${configPath} (expected the object returned by createAgentGate()). Falling back to built-in policies.`);
|
|
206
|
+
} else {
|
|
207
|
+
gateway = gate.withMCP({ mode: 'enforce', tools: defaultTools });
|
|
208
|
+
label = `your policies (${configPath})`;
|
|
209
|
+
}
|
|
210
|
+
} catch (err) {
|
|
211
|
+
console.error(`Could not load config ${configPath}: ${err.message}. Falling back to built-in policies.`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!gateway) {
|
|
215
|
+
gateway = createMCPGateway({ mode: 'enforce', policies: { productionBlock: true }, tools: defaultTools });
|
|
216
|
+
}
|
|
199
217
|
const results = await runGatewayAttackLab(gateway);
|
|
200
218
|
const summary = summarizeAttackResults(results);
|
|
201
|
-
console.log(
|
|
219
|
+
console.log(`\nAgentGate Attack Runner — testing against ${label}`);
|
|
202
220
|
console.table(results.map(x => ({ test: x.name, decision: x.decision, risk: x.risk, passed: x.passed, runId: x.runId })));
|
|
203
221
|
console.log('Summary:', JSON.stringify(summary));
|
|
204
222
|
process.exitCode = summary.failed ? 2 : 0;
|