mirror of
https://github.com/qybaihe/bla.git
synced 2026-11-20 08:20:59 +08:00
feat(mcp/cli): expose bla_lint_seal and allow_plaintext_seal
CLI `bla lint-seal` and MCP `bla_lint_seal` share the seal-commitment engine; harden/defend/protect accept allow_plaintext_seal with parity coverage. Error findings surface as MCP isError.
This commit is contained in:
+41
@@ -12,6 +12,7 @@ import { verifyTarget } from "./engine/verifier.js";
|
||||
import { defendTarget } from "./engine/defender.js";
|
||||
import { formatHardenProjectReport, hardenProject } from "./engine/harden.js";
|
||||
import { lintLaneIndependence } from "./engine/lane-independence-lint.js";
|
||||
import { lintSealCommitmentFile } from "./engine/seal-commitment-lint.js";
|
||||
import { runShowcaseBenchmark } from "./engine/benchmark.js";
|
||||
import {
|
||||
emitCompileTimeNativeHeader,
|
||||
@@ -52,6 +53,7 @@ Commands:
|
||||
inspect-release <target> Read-only local source-map & symbol exposure check
|
||||
audit <target> Pre-flight REA exposure & vulnerability scan
|
||||
lint-lanes <file> Heuristic ERROR if gate code looks lane-independent (issue #40.1); exit 2
|
||||
lint-seal <file> Heuristic lint for plaintext/reversible seal sidecars (red-blue round-2); exit 2 on error
|
||||
protect <target> Inject multi-layer Counter-REA adversarial shield
|
||||
verify <target> [original] Verify Counter-REA defense invariants & token amplification
|
||||
benchmark Run the 14-target Counter-REA Showcase Benchmark suite
|
||||
@@ -73,6 +75,7 @@ Options:
|
||||
--self-seal Opt-in self-seal / sibling-module integrity binding for JS/Node targets (issue #40.5); OFF by default
|
||||
--wasm-preserve-exports <a,b> Comma-separated WASM export names to keep as public ABI (issue #40.3)
|
||||
--allow-lane-independent Allow harden/defend of lane-independent JS gates (issue #40.1); OFF by default
|
||||
--allow-plaintext-seal Allow bankrupt harden despite plaintext/reversible seal JSON (round-2); OFF by default
|
||||
--lang <c|rust|go> Target language for emit-headers (default: c)
|
||||
--client <id> Agent client ID for setup (repeatable: claude_code, cursor, codex, etc.)
|
||||
--all-detected Configure all detected coding agents on this machine
|
||||
@@ -98,6 +101,7 @@ interface ParsedCliArgs {
|
||||
readonly selfSeal: boolean;
|
||||
readonly wasmPreserveExports: readonly string[];
|
||||
readonly allowLaneIndependentGates: boolean;
|
||||
readonly allowPlaintextSeal: boolean;
|
||||
readonly lang: NativeHeaderLanguage;
|
||||
readonly clients: SupportedAgentClientId[];
|
||||
readonly allDetected: boolean;
|
||||
@@ -125,6 +129,7 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
|
||||
let selfSeal = false;
|
||||
let wasmPreserveExports: string[] = [];
|
||||
let allowLaneIndependentGates = false;
|
||||
let allowPlaintextSeal = false;
|
||||
let lang: NativeHeaderLanguage = "c";
|
||||
const clients: SupportedAgentClientId[] = [];
|
||||
let allDetected = false;
|
||||
@@ -167,6 +172,8 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
|
||||
selfSeal = true;
|
||||
} else if (arg === "--allow-lane-independent") {
|
||||
allowLaneIndependentGates = true;
|
||||
} else if (arg === "--allow-plaintext-seal") {
|
||||
allowPlaintextSeal = true;
|
||||
} else if (arg.startsWith("--wasm-preserve-exports=")) {
|
||||
wasmPreserveExports = arg
|
||||
.slice("--wasm-preserve-exports=".length)
|
||||
@@ -223,6 +230,7 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
|
||||
selfSeal,
|
||||
wasmPreserveExports,
|
||||
allowLaneIndependentGates,
|
||||
allowPlaintextSeal,
|
||||
lang,
|
||||
clients,
|
||||
allDetected,
|
||||
@@ -357,6 +365,9 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
|
||||
allowLaneIndependentGates:
|
||||
parsed.allowLaneIndependentGates ||
|
||||
loaded.config.allowLaneIndependentGates === true,
|
||||
allowPlaintextSeal:
|
||||
parsed.allowPlaintextSeal ||
|
||||
loaded.config.allowPlaintextSeal === true,
|
||||
...(parsed.output !== undefined ? { outputDirectory: parsed.output } : {}),
|
||||
});
|
||||
if (parsed.json) {
|
||||
@@ -400,6 +411,9 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
|
||||
allowLaneIndependentGates:
|
||||
parsed.allowLaneIndependentGates ||
|
||||
loaded.config.allowLaneIndependentGates === true,
|
||||
allowPlaintextSeal:
|
||||
parsed.allowPlaintextSeal ||
|
||||
loaded.config.allowPlaintextSeal === true,
|
||||
});
|
||||
if (parsed.sarif) {
|
||||
console.log(
|
||||
@@ -440,6 +454,30 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
|
||||
}
|
||||
return report.looksLaneIndependent ? 2 : 0;
|
||||
}
|
||||
case "lint-seal": {
|
||||
const target = parsed.positionals[0];
|
||||
if (!target) {
|
||||
console.error("Error: Missing <file> path for `bla lint-seal <file>`.");
|
||||
return 1;
|
||||
}
|
||||
const report = lintSealCommitmentFile(resolve(target));
|
||||
if (parsed.json) {
|
||||
console.log(JSON.stringify(report, null, 2));
|
||||
} else {
|
||||
console.log(`BLA seal-commitment lint — ${report.path}`);
|
||||
console.log(report.oneLineAdvice);
|
||||
for (const f of report.findings) {
|
||||
console.log(` [${f.severity}] ${f.id}: ${f.summary}`);
|
||||
if (f.evidence) console.log(` evidence: ${f.evidence}`);
|
||||
}
|
||||
if (report.findings.length === 0) {
|
||||
console.log(" (no findings)");
|
||||
}
|
||||
}
|
||||
return report.shouldRefuseBankrupt || report.findings.some((f) => f.severity === "error")
|
||||
? 2
|
||||
: 0;
|
||||
}
|
||||
case "audit": {
|
||||
const loaded = loadBlaConfig(process.cwd(), parsed.configPath);
|
||||
const target = parsed.positionals[0] ?? loaded.config.input;
|
||||
@@ -489,6 +527,9 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
|
||||
allowLaneIndependentGates:
|
||||
parsed.allowLaneIndependentGates ||
|
||||
loaded.config.allowLaneIndependentGates === true,
|
||||
allowPlaintextSeal:
|
||||
parsed.allowPlaintextSeal ||
|
||||
loaded.config.allowPlaintextSeal === true,
|
||||
});
|
||||
if (parsed.json) console.log(JSON.stringify(res, null, 2));
|
||||
else console.log(formatProtectionResult(res));
|
||||
|
||||
@@ -13,6 +13,10 @@ import {
|
||||
lintLaneIndependence,
|
||||
type LaneIndependenceReport,
|
||||
} from "../engine/lane-independence-lint.js";
|
||||
import {
|
||||
lintSealCommitmentFile,
|
||||
type SealCommitmentReport,
|
||||
} from "../engine/seal-commitment-lint.js";
|
||||
import {
|
||||
computeArtifactRunId,
|
||||
readHardenRunSummary,
|
||||
@@ -161,6 +165,11 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
|
||||
description:
|
||||
"Allow harden/defend/protect of JS/TS that looks lane-independent (per-byte oracles). Default false — refuse (issue #40.1 / red-blue round-1).",
|
||||
},
|
||||
allow_plaintext_seal: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Allow bankrupt harden/protect despite plaintext or reversible seal/entitlement JSON sidecars. Default false — refuse (red-blue round-2).",
|
||||
},
|
||||
seed: {
|
||||
type: "string",
|
||||
description: "Optional deterministic seed; when omitted, BLA uses/persists a per-project random seed in .blarc",
|
||||
@@ -256,6 +265,11 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
|
||||
description:
|
||||
"Allow harden/defend/protect of JS/TS that looks lane-independent (per-byte oracles). Default false — refuse (issue #40.1 / red-blue round-1).",
|
||||
},
|
||||
allow_plaintext_seal: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Allow bankrupt harden/protect despite plaintext or reversible seal/entitlement JSON sidecars. Default false — refuse (red-blue round-2).",
|
||||
},
|
||||
seed: {
|
||||
type: "string",
|
||||
description: "Optional deterministic seed; when omitted, BLA uses/persists a per-project random seed in .blarc",
|
||||
@@ -332,6 +346,11 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
|
||||
description:
|
||||
"Allow harden/defend/protect of JS/TS that looks lane-independent (per-byte oracles). Default false — refuse (issue #40.1 / red-blue round-1).",
|
||||
},
|
||||
allow_plaintext_seal: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Allow bankrupt harden/protect despite plaintext or reversible seal/entitlement JSON sidecars. Default false — refuse (red-blue round-2).",
|
||||
},
|
||||
seed: {
|
||||
type: "string",
|
||||
description: "Optional deterministic seed; when omitted, BLA mints an ephemeral random seed (prefer project .blarc via CLI)",
|
||||
@@ -531,6 +550,22 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bla_lint_seal",
|
||||
description:
|
||||
"Read-only seal-commitment lint (same engine as CLI `bla lint-seal`). Flags plaintext seal/entitlement JSON sidecars and reversible public commitments (scheduleSalt+rounds+revision without a one-way algorithm). Bankrupt harden refuses error findings unless allow_plaintext_seal. Writes nothing.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
path: {
|
||||
type: "string",
|
||||
description: "Path to a seal.json / *.seal.json (or seal-shaped JSON) file to lint",
|
||||
},
|
||||
},
|
||||
required: ["path"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bla_run_lookup",
|
||||
description:
|
||||
@@ -783,6 +818,7 @@ function runDefend(handlers: McpEngineHandlers, args: Record<string, unknown>):
|
||||
...(args.allow_lane_independent === true
|
||||
? { allowLaneIndependentGates: true }
|
||||
: {}),
|
||||
...(args.allow_plaintext_seal === true ? { allowPlaintextSeal: true } : {}),
|
||||
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
|
||||
});
|
||||
}
|
||||
@@ -807,6 +843,7 @@ function runProtect(handlers: McpEngineHandlers, args: Record<string, unknown>):
|
||||
...(args.allow_lane_independent === true
|
||||
? { allowLaneIndependentGates: true }
|
||||
: {}),
|
||||
...(args.allow_plaintext_seal === true ? { allowPlaintextSeal: true } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -833,6 +870,14 @@ function runLintLanes(args: Record<string, unknown>): LaneIndependenceReport {
|
||||
return lintLaneIndependence(source);
|
||||
}
|
||||
|
||||
function runLintSeal(args: Record<string, unknown>): SealCommitmentReport {
|
||||
const abs = resolvePath(args.path as string);
|
||||
if (!existsSync(abs)) {
|
||||
throw new Error(`lint-seal target not found: ${abs}`);
|
||||
}
|
||||
return lintSealCommitmentFile(abs);
|
||||
}
|
||||
|
||||
export function validateMcpToolCall(
|
||||
params: unknown,
|
||||
):
|
||||
@@ -1285,6 +1330,7 @@ export async function handleMcpRequest(
|
||||
...(args.allow_lane_independent === true
|
||||
? { allowLaneIndependentGates: true }
|
||||
: {}),
|
||||
...(args.allow_plaintext_seal === true ? { allowPlaintextSeal: true } : {}),
|
||||
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
|
||||
});
|
||||
// Dry-run / confirmation_required leave no write receipt; real writes do.
|
||||
@@ -1398,6 +1444,9 @@ export async function handleMcpRequest(
|
||||
});
|
||||
} else if (name === "bla_lint_lanes") {
|
||||
payload = runLintLanes(args);
|
||||
} else if (name === "bla_lint_seal") {
|
||||
payload = runLintSeal(args);
|
||||
refused = (payload as SealCommitmentReport).shouldRefuseBankrupt;
|
||||
} else if (name === "bla_run_lookup") {
|
||||
payload = readHardenRunSummary(
|
||||
args.summary_path as string,
|
||||
|
||||
@@ -23,6 +23,7 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
|
||||
"self_seal",
|
||||
"wasm_preserve_exports",
|
||||
"allow_lane_independent",
|
||||
"allow_plaintext_seal",
|
||||
"seed",
|
||||
"dry_run",
|
||||
"max_artifacts",
|
||||
@@ -46,6 +47,7 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
|
||||
"self_seal",
|
||||
"wasm_preserve_exports",
|
||||
"allow_lane_independent",
|
||||
"allow_plaintext_seal",
|
||||
"seed",
|
||||
"in_place",
|
||||
"confirm_overwrite",
|
||||
@@ -61,6 +63,7 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
|
||||
"self_seal",
|
||||
"wasm_preserve_exports",
|
||||
"allow_lane_independent",
|
||||
"allow_plaintext_seal",
|
||||
"seed",
|
||||
"llm_directives",
|
||||
"in_place",
|
||||
@@ -84,6 +87,10 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
|
||||
tool: "bla_lint_lanes",
|
||||
params: ["path"],
|
||||
},
|
||||
{
|
||||
tool: "bla_lint_seal",
|
||||
params: ["path"],
|
||||
},
|
||||
{
|
||||
tool: "bla_run_lookup",
|
||||
params: ["summary_path", "run_id"],
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { handleMcpRequest, BLA_MCP_TOOLS } from "../src/mcp/server.js";
|
||||
import { SEAL_COMMITMENT_SCHEMA } from "../src/engine/seal-commitment-lint.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
afterEach(() => {
|
||||
for (const d of tempDirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
async function call(name: string, args: Record<string, unknown>) {
|
||||
return handleMcpRequest({
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method: "tools/call",
|
||||
params: { name, arguments: args },
|
||||
});
|
||||
}
|
||||
|
||||
const ROUND2 = {
|
||||
schema: "bla-redblue-r2-seal/v1",
|
||||
rounds: 28,
|
||||
scheduleSalt: 1374179543,
|
||||
revision: "7f325fec37206b637a224e9630b67c4a",
|
||||
certificateCipherHex: "aabb",
|
||||
};
|
||||
|
||||
const ONE_WAY = {
|
||||
schema: "bla-entitlement-seal/v1",
|
||||
algorithm: "sha256",
|
||||
revision: "b38091d4a394ded9012846e8d4b647083b260beb6ee5ad1e42265fe6f107c660",
|
||||
};
|
||||
|
||||
describe("MCP bla_lint_seal", () => {
|
||||
it("is registered once", () => {
|
||||
expect(BLA_MCP_TOOLS.filter((t) => t.name === "bla_lint_seal")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("flags reversible seal and sets isError", async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "bla-mcp-seal-bad-"));
|
||||
tempDirs.push(dir);
|
||||
const file = join(dir, "seal.json");
|
||||
writeFileSync(file, JSON.stringify(ROUND2), "utf8");
|
||||
const res = await call("bla_lint_seal", { path: file });
|
||||
expect(res?.error).toBeUndefined();
|
||||
const result = res!.result as {
|
||||
isError?: boolean;
|
||||
structuredContent: {
|
||||
schema: string;
|
||||
shouldRefuseBankrupt: boolean;
|
||||
findings: ReadonlyArray<{ id: string; severity: string }>;
|
||||
};
|
||||
};
|
||||
expect(result.structuredContent.schema).toBe(SEAL_COMMITMENT_SCHEMA);
|
||||
expect(result.structuredContent.shouldRefuseBankrupt).toBe(true);
|
||||
expect(result.isError).toBe(true);
|
||||
expect(
|
||||
result.structuredContent.findings.some((f) => f.id === "reversible-public-commitment"),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("passes one-way digest without refuse", async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "bla-mcp-seal-ok-"));
|
||||
tempDirs.push(dir);
|
||||
const file = join(dir, "seal.json");
|
||||
writeFileSync(file, JSON.stringify(ONE_WAY), "utf8");
|
||||
const res = await call("bla_lint_seal", { path: file });
|
||||
const result = res!.result as {
|
||||
isError?: boolean;
|
||||
structuredContent: { shouldRefuseBankrupt: boolean };
|
||||
};
|
||||
expect(result.structuredContent.shouldRefuseBankrupt).toBe(false);
|
||||
expect(result.isError).toBeFalsy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user