Skip to content

armgit / bla

Public Imported from GitHub
0

🛡️ BLA (Blind LLM Agents) — Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.

fix(mcp): attach writeReceipt on successful bla_harden

qybaihe408f7dea42a2
diff --git a/src/mcp/server.ts b/src/mcp/server.ts
index 561cd21..7f5fcb9 100644
--- a/src/mcp/server.ts
+++ b/src/mcp/server.ts
@@ -555,7 +555,7 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
{
name: "bla_redteam_report",
description:
- "Read (or optionally re-run) the empirical REA red-team report at docs/redteam/empirical-rea-validation.json. Missing report and unready REA → status unverified. Pass execute:true only when sibling REA dist is built.",
+ "Read (or optionally re-run) the empirical REA red-team report at docs/redteam/empirical-rea-validation.json. On-disk read without execute → status available (not a live REA verdict). execute:true → pass/fail from the harness. Missing report and unready REA → status unverified. Pass execute:true only when sibling REA dist is built.",
inputSchema: {
type: "object",
properties: {
@@ -1247,7 +1247,7 @@ export async function handleMcpRequest(
payload = confirmationRequiredPayload(name, preOverwrite);
} else {
const wasmPreserveExports = stringListArg(args.wasm_preserve_exports);
- payload = handlers.hardenProject({
+ const report = handlers.hardenProject({
directory: hardenDir,
dryRun,
...(maxArtifacts !== undefined ? { maxArtifacts } : {}),
@@ -1263,6 +1263,21 @@ export async function handleMcpRequest(
...(wasmPreserveExports !== undefined ? { wasmPreserveExports } : {}),
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
});
+ // Dry-run / confirmation_required leave no write receipt; real writes do.
+ if (!dryRun) {
+ const wrote = report.artifacts
+ .filter((a) => a.success)
+ .map((a) => a.outputPath);
+ if (report.summaryPath !== undefined) {
+ wrote.push(report.summaryPath);
+ }
+ payload = {
+ ...report,
+ writeReceipt: writeReceipt(wrote, preOverwrite, confirmed),
+ };
+ } else {
+ payload = report;
+ }
}
} else if (name === "bla_defend" || name === "bla_protect") {
const inPlace = args.in_place === true;
diff --git a/tests/agent-write-safety.test.ts b/tests/agent-write-safety.test.ts
index 031f654..b88cab8 100644
--- a/tests/agent-write-safety.test.ts
+++ b/tests/agent-write-safety.test.ts
@@ -69,9 +69,10 @@ async function call(name: string, args: Record<string, unknown>) {
artifacts?: ReadonlyArray<{ relativePath?: string; outputPath?: string }>;
truncated?: boolean;
dryRun?: boolean;
+ overallSuccess?: boolean;
+ hardenedCount?: number;
discoveredCount?: number;
wouldOverwrite?: readonly string[];
- hardenedCount?: number;
status?: string;
writeReceipt?: Readonly<Record<string, unknown>>;
};
@@ -110,13 +111,35 @@ describe("read-only discover + zero-write dry-run", () => {
expect(r.isError).toBe(false);
const rep = r.structuredContent;
expect(rep.dryRun).toBe(true);
+ // Preview must not claim a successful harden.
+ expect(rep.overallSuccess).toBe(false);
+ expect(rep.hardenedCount).toBe(0);
expect(rep.discoveredCount).toBe(2);
expect(rep.artifacts?.[0]?.outputPath).toContain(".bla-hardened");
expect(rep.wouldOverwrite).toEqual([]);
+ expect(rep.writeReceipt).toBeUndefined();
expect(existsSync(join(root, ".bla-hardened"))).toBe(false);
expect(snapshot(root)).toEqual(before);
});
+ it("dry_run never demands confirm_overwrite even when planned outputs already exist", async () => {
+ const root = project(1);
+ const first = await call("bla_harden", { directory: root, seed: "pre" });
+ expect(first.isError).toBe(false);
+ const out = join(root, ".bla-hardened", "dist", "m0.js");
+ const hardened = readFileSync(out, "utf8");
+ const before = snapshot(root);
+
+ const preview = await call("bla_harden", { directory: root, dry_run: true, seed: "pre2" });
+ expect(preview.isError).toBe(false);
+ expect(preview.structuredContent.status).not.toBe("confirmation_required");
+ expect(preview.structuredContent.dryRun).toBe(true);
+ expect(preview.structuredContent.overallSuccess).toBe(false);
+ expect(preview.structuredContent.wouldOverwrite).toEqual([out]);
+ expect(readFileSync(out, "utf8")).toBe(hardened);
+ expect(snapshot(root)).toEqual(before);
+ });
+
it("CLI `harden --dry-run` writes nothing (no .bla-hardened, no .blarc)", async () => {
const root = project(1);
const before = snapshot(root);
@@ -133,6 +156,12 @@ describe("overwrite confirmation boundary", () => {
expect(first.isError).toBe(false);
expect(first.structuredContent.hardenedCount).toBe(1);
const out = join(root, ".bla-hardened", "dist", "m0.js");
+ expect(first.structuredContent.writeReceipt).toMatchObject({
+ status: "written",
+ wrote: expect.arrayContaining([out]),
+ overwrote: [],
+ confirmed: false,
+ });
const hardened = readFileSync(out, "utf8");
const refused = await call("bla_harden", { directory: root, seed: "s2" });
@@ -145,6 +174,11 @@ describe("overwrite confirmation boundary", () => {
expect(ok.isError).toBe(false);
expect(ok.structuredContent.hardenedCount).toBe(1);
expect(ok.structuredContent.wouldOverwrite).toEqual([out]);
+ expect(ok.structuredContent.writeReceipt).toMatchObject({
+ status: "written",
+ overwrote: [out],
+ confirmed: true,
+ });
});
it("bla_protect refuses an existing output_path without confirmation and succeeds with it", async () => {