@emilia-protocol/fire-drill 0.1.0 → 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/cli.mjs +7 -1
- package/index.js +66 -0
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @license Apache-2.0
|
|
13
13
|
*/
|
|
14
14
|
import fs from 'node:fs';
|
|
15
|
-
import { scan, TAGLINE } from './index.js';
|
|
15
|
+
import { scan, TAGLINE, generatePullRequest } from './index.js';
|
|
16
16
|
|
|
17
17
|
const argv = process.argv.slice(2);
|
|
18
18
|
const flags = new Set(argv.filter((a) => a.startsWith('--')));
|
|
@@ -43,6 +43,12 @@ if (flags.has('--json')) {
|
|
|
43
43
|
process.exit(report.eg1 === 'pass' ? 0 : 1);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
if (flags.has('--pr')) {
|
|
47
|
+
const pr = generatePullRequest(report);
|
|
48
|
+
console.log(`# ${pr.title}\n\n${pr.body}`);
|
|
49
|
+
process.exit(report.eg1 === 'pass' ? 0 : 1);
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
const G = (s) => `\x1b[32m${s}\x1b[0m`;
|
|
47
53
|
const R = (s) => `\x1b[31m${s}\x1b[0m`;
|
|
48
54
|
const Y = (s) => `\x1b[33m${s}\x1b[0m`;
|
package/index.js
CHANGED
|
@@ -188,8 +188,74 @@ export function buildReport(operations, targetType = 'unknown') {
|
|
|
188
188
|
|
|
189
189
|
export const TAGLINE = 'If your agent can take an irreversible action without a receipt, you do not have control. You have hope.';
|
|
190
190
|
|
|
191
|
+
// ── Shareable badge ──────────────────────────────────────────────────────────
|
|
192
|
+
|
|
193
|
+
/** Approximate pixel width of a label segment (flat-badge sizing, no font metrics). */
|
|
194
|
+
function segWidth(text) {
|
|
195
|
+
return Math.max(40, Math.round(String(text).length * 6.6) + 20);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A shields-style flat SVG badge: "agent action firewall | EG-1 Enforced".
|
|
200
|
+
* Green when EG-1 passes / score 100, amber for partial, red for fail.
|
|
201
|
+
* @param {object} o
|
|
202
|
+
* @param {'pass'|'fail'} [o.eg1]
|
|
203
|
+
* @param {number} [o.score] 0..100 — overrides the message with "N/100" when given
|
|
204
|
+
* @param {string} [o.label='agent action firewall']
|
|
205
|
+
*/
|
|
206
|
+
export function badgeSvg({ eg1, score, label = 'agent action firewall' } = {}) {
|
|
207
|
+
const hasScore = typeof score === 'number' && Number.isFinite(score);
|
|
208
|
+
const pass = eg1 === 'pass' || score === 100;
|
|
209
|
+
const message = hasScore ? `${score}/100` : (pass ? 'EG-1 Enforced' : 'EG-1 not earned');
|
|
210
|
+
const color = pass ? '#16A34A' : (hasScore && score >= 50 ? '#D97706' : '#DC2626');
|
|
211
|
+
const lw = segWidth(label);
|
|
212
|
+
const mw = segWidth(message);
|
|
213
|
+
const w = lw + mw;
|
|
214
|
+
const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
215
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="20" role="img" aria-label="${esc(label)}: ${esc(message)}">`
|
|
216
|
+
+ `<linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient>`
|
|
217
|
+
+ `<rect rx="3" width="${w}" height="20" fill="#555"/>`
|
|
218
|
+
+ `<rect rx="3" x="${lw}" width="${mw}" height="20" fill="${color}"/>`
|
|
219
|
+
+ `<rect rx="3" width="${w}" height="20" fill="url(#s)"/>`
|
|
220
|
+
+ `<g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11">`
|
|
221
|
+
+ `<text x="${lw / 2}" y="14">${esc(label)}</text>`
|
|
222
|
+
+ `<text x="${lw + mw / 2}" y="14">${esc(message)}</text>`
|
|
223
|
+
+ `</g></svg>`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ── Generate-PR ──────────────────────────────────────────────────────────────
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Turn a report into a ready-to-open pull request (title + Markdown body) that
|
|
230
|
+
* tells a maintainer exactly which dangerous tools to gate and how to earn EG-1.
|
|
231
|
+
* @param {object} report a buildReport() result
|
|
232
|
+
* @param {object} [o]
|
|
233
|
+
* @param {string} [o.project] project/repo name for the title
|
|
234
|
+
*/
|
|
235
|
+
export function generatePullRequest(report, { project } = {}) {
|
|
236
|
+
const name = project ? ` for ${project}` : '';
|
|
237
|
+
const failing = report.findings || [];
|
|
238
|
+
const title = failing.length
|
|
239
|
+
? `Require an EMILIA receipt for ${failing.length} high-risk action${failing.length > 1 ? 's' : ''}${name} (earn EG-1)`
|
|
240
|
+
: `Confirm EG-1 Enforced${name}`;
|
|
241
|
+
const lines = [];
|
|
242
|
+
lines.push(`## Agent Action Firewall: ${report.score}/100 (EG-1 ${report.eg1.toUpperCase()})`, '');
|
|
243
|
+
if (!failing.length) {
|
|
244
|
+
lines.push('No dangerous action can run without a receipt. This integration is **EG-1 Enforced**.', '');
|
|
245
|
+
} else {
|
|
246
|
+
lines.push('These tool calls can mutate money, data, permissions, or production **without an accountable human receipt**:', '');
|
|
247
|
+
for (const f of failing) lines.push(`- \`${f.operation}\` — ${f.family} — ${f.fix}`);
|
|
248
|
+
lines.push('', '### Fix', '', '```js', `import { createGate } from '@emilia-protocol/gate';`, `import { gateMcpTool } from '@emilia-protocol/gate/mcp';`, '', `const gate = createGate({ manifest, trustedKeys: [process.env.EMILIA_ISSUER] });`);
|
|
249
|
+
for (const f of failing) lines.push(`server.tool('${f.operation}', gateMcpTool(gate, { tool: '${f.operation}' }, handler));`);
|
|
250
|
+
lines.push('```', '', `Then \`npx @emilia-protocol/fire-drill <manifest>\` should report **EG-1 Enforced**.`);
|
|
251
|
+
}
|
|
252
|
+
lines.push('', '---', `_Generated by [@emilia-protocol/fire-drill](https://www.npmjs.com/package/@emilia-protocol/fire-drill) — the Agent Action Firewall Test._`);
|
|
253
|
+
return { title, body: lines.join('\n') };
|
|
254
|
+
}
|
|
255
|
+
|
|
191
256
|
export default {
|
|
192
257
|
FIRE_DRILL_VERSION, TAGLINE,
|
|
193
258
|
classifyOperation, detectReceiptGate, buildReport,
|
|
194
259
|
scan, scanMcpManifest, scanOpenApi, scanToolList,
|
|
260
|
+
badgeSvg, generatePullRequest,
|
|
195
261
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emilia-protocol/fire-drill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The Agent Action Firewall Test. Scan any MCP server manifest, OpenAPI spec, or tool list for dangerous actions an AI agent can take without an accountable human receipt — money movement, data destruction, production deploy, permission change, bulk export, regulated override. Reports an Agent Action Firewall score, the failing operations, the fix (EMILIA Gate), and EG-1 pass/fail. Static, zero-dependency, CI-friendly.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|