mneme-ai 3.5.1 → 3.7.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/dist/commands/agentcert.d.ts +10 -0
- package/dist/commands/agentcert.d.ts.map +1 -0
- package/dist/commands/agentcert.js +100 -0
- package/dist/commands/agentcert.js.map +1 -0
- package/dist/commands/mcpgate.d.ts +10 -0
- package/dist/commands/mcpgate.d.ts.map +1 -0
- package/dist/commands/mcpgate.js +77 -0
- package/dist/commands/mcpgate.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mneme agentcert` (v3.7.0) — the Agent Run Certificate.
|
|
3
|
+
* agentcert build [--run <id>] [--task "…"] [--agent "…"] --out cert.json → a signed, self-contained certificate
|
|
4
|
+
* agentcert verify <cert.json> → verify OFFLINE (no Mneme, no vendor)
|
|
5
|
+
* The build embeds the run's evidence (MCP-gateway audit chain + human approvals) and NOTARY-signs
|
|
6
|
+
* the whole thing, so an insurer / auditor / customer verifies the entire governed run from ONE file.
|
|
7
|
+
*/
|
|
8
|
+
import type { Command } from "commander";
|
|
9
|
+
export declare function registerAgentcertCommands(program: Command): void;
|
|
10
|
+
//# sourceMappingURL=agentcert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentcert.d.ts","sourceRoot":"","sources":["../../src/commands/agentcert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBzC,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA8ChE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { agentcert, notary } from "@mneme-ai/core";
|
|
4
|
+
function out(s) { process.stdout.write(s + "\n"); }
|
|
5
|
+
function loadFrames(cwd, run) {
|
|
6
|
+
const p = join(cwd, ".mneme", "mcpgate", "audit.jsonl");
|
|
7
|
+
if (!existsSync(p))
|
|
8
|
+
return [];
|
|
9
|
+
const all = readFileSync(p, "utf8").trim().split("\n").filter(Boolean).map((l) => { try {
|
|
10
|
+
return JSON.parse(l);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
} }).filter(Boolean);
|
|
15
|
+
return run ? all.filter((f) => f.run === run) : all;
|
|
16
|
+
}
|
|
17
|
+
function loadApprovals(cwd) {
|
|
18
|
+
try {
|
|
19
|
+
const st = JSON.parse(readFileSync(join(cwd, ".mneme", "pager", "state.json"), "utf8"));
|
|
20
|
+
return (st.receipts ?? []).filter((r) => r.decidedBy === "human").map((r) => ({ id: String(r.req?.id ?? ""), decision: (r.decision === "deny" ? "deny" : "allow"), by: "human", on: String(r.channel ?? "pager"), at: Number(r.at) || 0 }));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function registerAgentcertCommands(program) {
|
|
27
|
+
const k = program.command("agentcert").description("🎖 AGENT RUN CERTIFICATE — one portable, offline-verifiable certificate per governed agent run (the audit chain + human approvals, NOTARY-signed). The piece a giant adopts + an insurer underwrites: no vendor can issue it for itself.");
|
|
28
|
+
k.command("build").description("Build + sign a certificate for a run (or the whole audit ledger).")
|
|
29
|
+
.option("--run <id>", "only this run's audit frames (default: all)").option("--task <t>", "the run's task").option("--agent <a>", "agent/vendor name").option("--model <m>", "model id")
|
|
30
|
+
.option("--out <file>", "write the signed certificate").option("--json", "print the signed certificate JSON")
|
|
31
|
+
.action((o) => {
|
|
32
|
+
const cwd = process.cwd();
|
|
33
|
+
const auditFrames = loadFrames(cwd, o.run);
|
|
34
|
+
if (!auditFrames.length) {
|
|
35
|
+
out(`✗ no audit frames${o.run ? ` for run ${o.run}` : ""} — run some gated tool-calls first (mneme mcpgate / gephyra serve / matrix).`);
|
|
36
|
+
process.exitCode = 2;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const approvals = loadApprovals(cwd);
|
|
40
|
+
const ev = {
|
|
41
|
+
runId: o.run || auditFrames[0].run || "all", agent: o.agent || auditFrames[0].agent || "agent", model: o.model, task: o.task,
|
|
42
|
+
startedAt: auditFrames[0].ts, endedAt: auditFrames[auditFrames.length - 1].ts, auditFrames, approvals,
|
|
43
|
+
};
|
|
44
|
+
const cert = agentcert.buildCertificate(ev);
|
|
45
|
+
// self-contained, portable: embed the evidence + sign the whole thing for offline verify
|
|
46
|
+
const payload = { cert, evidence: ev };
|
|
47
|
+
let signed = payload;
|
|
48
|
+
try {
|
|
49
|
+
signed = notary.issueReceipt(cwd, { kind: "reasoning-trace", subject: `agent-run-cert:${cert.runId}`, payload, includePayload: true, issuedAt: Date.now() });
|
|
50
|
+
}
|
|
51
|
+
catch { /* */ }
|
|
52
|
+
if (o.out)
|
|
53
|
+
writeFileSync(o.out, JSON.stringify(signed, null, 2), "utf8");
|
|
54
|
+
if (o.json) {
|
|
55
|
+
out(JSON.stringify(signed, null, 2));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const s = cert.summary;
|
|
59
|
+
const ico = s.insurability === "insurable" ? "🟢" : s.insurability === "review" ? "🟡" : "🔴";
|
|
60
|
+
out(`🎖 AGENT RUN CERTIFICATE — ${cert.agent}${cert.task ? ` · "${cert.task}"` : ""} · ${ico} ${s.insurability.toUpperCase()}`);
|
|
61
|
+
out(` ${s.calls} gated call(s): ${s.allowed} allowed · ${s.blocked} blocked · ${s.needsApproval} escalated · ${s.humanApprovals + s.humanDenials} human decision(s)`);
|
|
62
|
+
out(` policy-compliant: ${s.policyCompliant ? "yes" : "NO"} · audit chain: ${s.auditChainOk ? "intact" : "BROKEN"} · max risk ${s.riskMax}`);
|
|
63
|
+
out(` evidence sha256 ${cert.evidenceHash.slice(0, 16)}…${o.out ? ` · 🎖 signed → ${o.out}` : ""} (verify offline: mneme agentcert verify)`);
|
|
64
|
+
});
|
|
65
|
+
k.command("verify <file>").description("Verify a certificate OFFLINE — the signature, the embedded audit chain, and that the summary RE-DERIVES from the evidence (the cert cannot lie about its run).")
|
|
66
|
+
.action((file) => {
|
|
67
|
+
if (!existsSync(file)) {
|
|
68
|
+
out("certificate not found");
|
|
69
|
+
process.exitCode = 2;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let signed;
|
|
73
|
+
try {
|
|
74
|
+
signed = JSON.parse(readFileSync(file, "utf8"));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
out("✗ invalid certificate JSON");
|
|
78
|
+
process.exitCode = 2;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const sig = notary.verifyReceipt(signed);
|
|
82
|
+
out(sig.valid ? "✓ signature VALID (Ed25519, offline — proves who issued it)" : `✗ signature INVALID: ${sig.reason}`);
|
|
83
|
+
const cert = signed.payload?.cert, evidence = signed.payload?.evidence;
|
|
84
|
+
if (!cert || !evidence) {
|
|
85
|
+
out("✗ certificate has no embedded cert/evidence");
|
|
86
|
+
process.exitCode = 2;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const v = agentcert.verifyCertificate(cert, evidence);
|
|
90
|
+
out(v.valid ? "✓ run VERIFIED — " + v.reasons[0] : "✗ run NOT verified:");
|
|
91
|
+
if (!v.valid)
|
|
92
|
+
for (const r of v.reasons)
|
|
93
|
+
out(" • " + r);
|
|
94
|
+
const s = cert.summary;
|
|
95
|
+
out(` → ${cert.agent}${cert.task ? ` · "${cert.task}"` : ""}: ${s.calls} gated calls · ${s.blocked} blocked · insurability ${s.insurability}`);
|
|
96
|
+
if (!sig.valid || !v.valid)
|
|
97
|
+
process.exitCode = 2;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
//# sourceMapp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AAI,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;YAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QAC7G,MAAM,CAAC,GAAG,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtD,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC;QAC1E,IAAI,CAAC,CAAC,CAAC,KAAK;YAAE,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO;gBAAE,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QACvB,GAAG,CAAC,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,kBAAkB,CAAC,CAAC,OAAO,2BAA2B,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;QACjJ,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK;YAAE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mneme mcpgate` (v3.6.0) — the local-first MCP gateway surface.
|
|
3
|
+
* mcpgate decide --tool <t> [--args '<json>'] [--agent a] → ALLOW / NEEDS-APPROVAL / BLOCK
|
|
4
|
+
* mcpgate audit [--verify] → the signed, offline-verifiable call ledger
|
|
5
|
+
* Every call through `gephyra serve` (HTTP MCP-proxy) and the matrix gRPC rail is gated + audited
|
|
6
|
+
* automatically; this CLI is for manual decisions + verifying the audit chain.
|
|
7
|
+
*/
|
|
8
|
+
import type { Command } from "commander";
|
|
9
|
+
export declare function registerMcpgateCommands(program: Command): void;
|
|
10
|
+
//# sourceMappingURL=mcpgate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpgate.d.ts","sourceRoot":"","sources":["../../src/commands/mcpgate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOzC,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAmC9D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { mcpgate, notary } from "@mneme-ai/core";
|
|
4
|
+
function out(s) { process.stdout.write(s + "\n"); }
|
|
5
|
+
export function registerMcpgateCommands(program) {
|
|
6
|
+
const k = program.command("mcpgate").description("🛂 MCP GATEWAY — gate every agent tool-call (policy + behavioral risk + skill provenance → allow / needs-approval / block) and keep a SIGNED, offline-verifiable audit ledger. Local-first; the runtime perimeter a cloud gateway can't be.");
|
|
7
|
+
k.command("decide").description("Gate one tool-call.")
|
|
8
|
+
.requiredOption("--tool <t>", "tool name").option("--args <json>", "args JSON", "{}").option("--agent <a>", "agent id", "agent").option("--json", "emit JSON")
|
|
9
|
+
.action((o) => {
|
|
10
|
+
let args = {};
|
|
11
|
+
try {
|
|
12
|
+
args = JSON.parse(o.args ?? "{}");
|
|
13
|
+
}
|
|
14
|
+
catch { /* */ }
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
let policy = {};
|
|
17
|
+
try {
|
|
18
|
+
const pp = join(cwd, ".mneme", "mcpgate", "policy.json");
|
|
19
|
+
if (existsSync(pp))
|
|
20
|
+
policy = JSON.parse(readFileSync(pp, "utf8"));
|
|
21
|
+
}
|
|
22
|
+
catch { /* */ }
|
|
23
|
+
const v = mcpgate.gateCall({ tool: o.tool, agent: o.agent, args }, policy);
|
|
24
|
+
if (o.json) {
|
|
25
|
+
out(JSON.stringify(v, null, 2));
|
|
26
|
+
if (v.decision === "block")
|
|
27
|
+
process.exitCode = 2;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const icon = v.decision === "block" ? "🔴" : v.decision === "needs-approval" ? "🟡" : "🟢";
|
|
31
|
+
out(`🛂 ${icon} ${v.decision.toUpperCase()} · ${o.tool} · risk ${v.risk} · args ${v.argsHash.slice(0, 12)}…`);
|
|
32
|
+
for (const r of v.reasons)
|
|
33
|
+
out(` • ${r}`);
|
|
34
|
+
if (v.decision === "needs-approval")
|
|
35
|
+
out(" → route to the human: mneme pager request");
|
|
36
|
+
if (v.decision === "block")
|
|
37
|
+
process.exitCode = 2;
|
|
38
|
+
});
|
|
39
|
+
k.command("audit").description("Show + verify the call audit ledger (.mneme/mcpgate/audit.jsonl).")
|
|
40
|
+
.option("--verify", "verify the hash-chain + the NOTARY-signed head OFFLINE").option("--tail <n>", "show the last N frames", "10")
|
|
41
|
+
.action((o) => {
|
|
42
|
+
const dir = join(process.cwd(), ".mneme", "mcpgate");
|
|
43
|
+
const ledger = join(dir, "audit.jsonl");
|
|
44
|
+
if (!existsSync(ledger)) {
|
|
45
|
+
out("no audit ledger yet (no gated calls)");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const frames = readFileSync(ledger, "utf8").trim().split("\n").filter(Boolean).map((l) => { try {
|
|
49
|
+
return JSON.parse(l);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
} }).filter(Boolean);
|
|
54
|
+
const tail = Math.max(1, parseInt(o.tail ?? "10", 10));
|
|
55
|
+
out(`🛂 MCP gateway audit — ${frames.length} call(s)`);
|
|
56
|
+
for (const f of frames.slice(-tail))
|
|
57
|
+
out(` #${f.seq} ${f.decision === "block" ? "🔴" : f.decision === "needs-approval" ? "🟡" : "🟢"} ${f.tool} · ${f.agent} · risk ${f.risk} · args ${f.argsHash.slice(0, 10)}…`);
|
|
58
|
+
if (o.verify) {
|
|
59
|
+
const chain = mcpgate.verifyAuditChain(frames);
|
|
60
|
+
out(chain.ok ? ` ✓ chain VERIFIED — ${chain.frames} frames intact (offline, tamper-evident)` : ` ✗ chain BROKEN at #${chain.brokenAt}: ${chain.reason}`);
|
|
61
|
+
const headPath = join(dir, "audit.head.json");
|
|
62
|
+
if (existsSync(headPath)) {
|
|
63
|
+
try {
|
|
64
|
+
const rec = JSON.parse(readFileSync(headPath, "utf8"));
|
|
65
|
+
const v = notary.verifyReceipt(rec);
|
|
66
|
+
const head = rec.payload?.frameId;
|
|
67
|
+
const last = frames[frames.length - 1]?.frameId;
|
|
68
|
+
out(v.valid ? ` ✓ signed head VALID (Ed25519, offline)${head === last ? " · points at the current tip" : " · ⚠ tip moved"}` : ` ✗ signed head INVALID: ${v.reason}`);
|
|
69
|
+
}
|
|
70
|
+
catch { /* */ }
|
|
71
|
+
}
|
|
72
|
+
if (!chain.ok)
|
|
73
|
+
process.exitCode = 2;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=mcpgate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpgate.js","sourceRoot":"","sources":["../../src/commands/mcpgate.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEjD,SAAS,GAAG,CAAC,CAAS,IAAU,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAEjE,MAAM,UAAU,uBAAuB,CAAC,OAAgB;IACtD,MA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AC/C,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,yBAAyB,KAAK,CAAC,MAAM,0CAA0C,CAAC,CAAC,CAAC,yBAAyB,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC7J,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;YAC9C,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAAC,IAAI,CAAC;oBAAC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;oBAAC,MAAM,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;oBAAC,MAAM,IAAI,GAAI,GAAG,CAAC,OAAgC,EAAE,OAAO,CAAC;oBAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC;oBAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,4CAA4C,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;gBAAC,CAAC;gBAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;YAAC,CAAC;YAC1a,IAAI,CAAC,KAAK,CAAC,EAAE;gBAAE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+LA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA+lNvD"}
|
package/dist/index.js
CHANGED
|
@@ -107,6 +107,8 @@ import { registerPagerCommands } from "./commands/pager.js";
|
|
|
107
107
|
import { registerKeryxCommands } from "./commands/keryx.js";
|
|
108
108
|
import { registerCompileCommands } from "./commands/compile.js";
|
|
109
109
|
import { registerSkillscanCommands } from "./commands/skillscan.js";
|
|
110
|
+
import { registerMcpgateCommands } from "./commands/mcpgate.js";
|
|
111
|
+
import { registerAgentcertCommands } from "./commands/agentcert.js";
|
|
110
112
|
import { registerAdamasCommands } from "./commands/adamas.js";
|
|
111
113
|
import { registerPrismCommands } from "./commands/prism.js";
|
|
112
114
|
import { registerGoldilocksCommands } from "./commands/goldilocks.js";
|
|
@@ -4781,6 +4783,8 @@ export async function run(argv) {
|
|
|
4781
4783
|
registerKeryxCommands(program);
|
|
4782
4784
|
registerCompileCommands(program);
|
|
4783
4785
|
registerSkillscanCommands(program);
|
|
4786
|
+
registerMcpgateCommands(program);
|
|
4787
|
+
registerAgentcertCommands(program);
|
|
4784
4788
|
registerAdamasCommands(program);
|
|
4785
4789
|
registerPrismCommands(program);
|
|
4786
4790
|
registerGoldilocksCommands(program);
|