mneme-ai 2.129.0 → 2.130.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `mneme firewall` (v2.130.0) — Structural Context Firewall against Indirect
3
+ * Prompt Injection (OWASP LLM01). Scan content an agent is about to read; detect
4
+ * + neutralize known injection patterns hidden in comments/strings, and wrap it
5
+ * in an untrusted-data boundary so the model treats it as DATA, never commands.
6
+ *
7
+ * cat suspect.ts | mneme firewall scan # verdict + findings
8
+ * cat external-dep.ts | mneme firewall fortify # → safe-to-read content (neutralized + wrapped)
9
+ */
10
+ import type { Command } from "commander";
11
+ export declare function registerFirewallCommands(program: Command): void;
12
+ //# sourceMappingURL=firewall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firewall.d.ts","sourceRoot":"","sources":["../../src/commands/firewall.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBzC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA+B/D"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * `mneme firewall` (v2.130.0) — Structural Context Firewall against Indirect
3
+ * Prompt Injection (OWASP LLM01). Scan content an agent is about to read; detect
4
+ * + neutralize known injection patterns hidden in comments/strings, and wrap it
5
+ * in an untrusted-data boundary so the model treats it as DATA, never commands.
6
+ *
7
+ * cat suspect.ts | mneme firewall scan # verdict + findings
8
+ * cat external-dep.ts | mneme firewall fortify # → safe-to-read content (neutralized + wrapped)
9
+ */
10
+ import { existsSync, readFileSync } from "node:fs";
11
+ import { firewall } from "@mneme-ai/core";
12
+ function out(s) { process.stdout.write(s + "\n"); }
13
+ function readStdin() {
14
+ return new Promise((resolve) => {
15
+ if (process.stdin.isTTY)
16
+ return resolve("");
17
+ let d = "";
18
+ let done = false;
19
+ const fin = () => { if (!done) {
20
+ done = true;
21
+ resolve(d);
22
+ } };
23
+ process.stdin.setEncoding("utf8");
24
+ process.stdin.on("data", (c) => { d += c; if (d.length > 8_000_000)
25
+ fin(); });
26
+ process.stdin.on("end", fin);
27
+ process.stdin.on("error", fin);
28
+ setTimeout(fin, 4000);
29
+ });
30
+ }
31
+ async function getPayload(opts) {
32
+ if (typeof opts.text === "string")
33
+ return opts.text;
34
+ if (opts.file && existsSync(opts.file)) {
35
+ try {
36
+ return readFileSync(opts.file, "utf8");
37
+ }
38
+ catch { /* */ }
39
+ }
40
+ return readStdin();
41
+ }
42
+ export function registerFirewallCommands(program) {
43
+ const fw = program.command("firewall").description("🧱 STRUCTURAL CONTEXT FIREWALL — defend against Indirect Prompt Injection (OWASP LLM01): scan content for injection hidden in comments/strings + neutralize it, and wrap it as untrusted DATA so the model never obeys instructions buried in a file. Defense-in-depth, not a 100% guarantee against unknown attacks.");
44
+ fw.command("scan")
45
+ .description("Scan content (stdin/--file/--text). Verdict clean | flagged | blocked + findings (line, category). Exit 2 on blocked.")
46
+ .option("--text <t>", "inline content.")
47
+ .option("--file <p>", "read from a file.")
48
+ .option("--json", "JSON output.")
49
+ .action(async (opts) => {
50
+ const r = firewall.scanInjection(await getPayload(opts));
51
+ if (opts.json) {
52
+ process.stdout.write(JSON.stringify(r, null, 2) + "\n");
53
+ }
54
+ else {
55
+ const icon = r.verdict === "blocked" ? "🛑" : r.verdict === "flagged" ? "⚠️" : "✓";
56
+ out(`${icon} FIREWALL ${r.verdict.toUpperCase()} — ${r.findings.length} finding(s), ${r.neutralizedCount} neutralized`);
57
+ for (const f of r.findings.slice(0, 12))
58
+ out(` • L${f.line} [${f.severity}] ${f.category}: ${f.snippet}`);
59
+ if (r.verdict !== "clean")
60
+ out(` → read the FORTIFIED form (mneme firewall fortify) instead of the raw file.`);
61
+ }
62
+ if (r.verdict === "blocked")
63
+ process.exitCode = 2;
64
+ });
65
+ fw.command("fortify")
66
+ .description("Emit the safe-to-read form: known injections neutralized + content wrapped in an untrusted-data boundary (the always-on, attack-agnostic separation). Read THIS instead of the raw file.")
67
+ .option("--text <t>", "inline content.")
68
+ .option("--file <p>", "read from a file.")
69
+ .option("--json", "JSON output (fortified + findings).")
70
+ .action(async (opts) => {
71
+ const r = firewall.fortify(await getPayload(opts), opts.file ? { path: opts.file } : undefined);
72
+ if (opts.json) {
73
+ process.stdout.write(JSON.stringify(r, null, 2) + "\n");
74
+ return;
75
+ }
76
+ process.stdout.write(r.fortified + "\n");
77
+ process.stderr.write(`🧱 firewall: ${r.verdict} · ${r.neutralizedCount} injection(s) neutralized · wrapped as untrusted data\n`);
78
+ });
79
+ }
80
+ //# sourceMappingURL=firewall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firewall.js","sourceRoot":"","sources":["../../src/commands/firewall.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,SAAS,GAAG,CAAC,CAAS,IAAU,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACjE,SAAS,SAAS;IAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,GAAG,EAAE,CAAC;QAAC,IAAI,IAAI,GAAG,KAAK,CAAC;QAAC,MAAM,GAAG,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAAC,IAAI,GAAG,IAAI,CAAC;YAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAAC,CAAC,CAAC,CAAC,CAAC;QAC5F,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAAC,OAA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,CAAC;SACvD,MAAM,CAAC,KAAK,EAAE,IAAsD,EAAE,EAAE;QACvE,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QACnF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,gBAAgB,yDAAyD,CAAC,CAAC;IACnI,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA0JA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA4gNvD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2JA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA6gNvD"}
package/dist/index.js CHANGED
@@ -87,6 +87,7 @@ import { registerScaffoldCommands } from "./commands/scaffold.js";
87
87
  import { registerBlindCommands } from "./commands/blind.js";
88
88
  import { registerChannelCommands } from "./commands/channel.js";
89
89
  import { registerSettlementCommands } from "./commands/settlement.js";
90
+ import { registerFirewallCommands } from "./commands/firewall.js";
90
91
  import { registerTrustCommands } from "./commands/trust.js";
91
92
  import { registerNuclearCommands } from "./commands/nuclear-cli.js";
92
93
  import { registerOvernightCommand } from "./commands/overnight.js";
@@ -4719,6 +4720,7 @@ export async function run(argv) {
4719
4720
  registerBlindCommands(program);
4720
4721
  registerChannelCommands(program);
4721
4722
  registerSettlementCommands(program);
4723
+ registerFirewallCommands(program);
4722
4724
  // ─── Trust calibrator (v1.31.0) -- per-subsystem precision/recall/band
4723
4725
  registerTrustCommands(program);
4724
4726
  // ─── Wisdom reactor (v1.33.0) -- five nuclear-physics formulas as Mneme metrics