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.

feat(doctor): verify installed skill bundle files exist and match bundled hashes

qybaihe46a1a6763a6c
diff --git a/src/setup/doctor.ts b/src/setup/doctor.ts
index eff782a..96a02e0 100644
--- a/src/setup/doctor.ts
+++ b/src/setup/doctor.ts
@@ -18,7 +18,11 @@ import {
type ClientConfigFormat,
type SupportedAgentClientId,
} from "./clients.js";
-import { readInstallManifest, resolveBundledSkillContent } from "./setup.js";
+import {
+ readInstallManifest,
+ resolveBundledSkillBundle,
+ resolveBundledSkillContent,
+} from "./setup.js";
export type EngineHealthStatus = "ready" | "degraded" | "unavailable";
export type DoctorClientCheckState = "pass" | "warn" | "fail" | "not_checked";
@@ -51,6 +55,10 @@ export interface DoctorClientDiagnostic {
readonly mcpRegistered: boolean;
readonly skillInstalled: boolean;
readonly skillStatus: DoctorSkillStatus;
+ /** Supporting bundle files (references/appendices) absent next to SKILL.md. */
+ readonly skillMissingFiles: readonly string[];
+ /** Supporting bundle files whose sha256 differs from the bundled/recorded copy. */
+ readonly skillModifiedFiles: readonly string[];
readonly status: DoctorClientCheckState;
readonly issues: readonly string[];
}
@@ -315,6 +323,9 @@ export function runDoctor(homeDirOrOptions?: string | DoctorOptions): DoctorDiag
const clients = resolveSupportedAgentClients(home, platform, options.env);
const manifest = readInstallManifest(home);
const bundledSkillSha256 = sha256Hex(resolveBundledSkillContent());
+ const bundledSupportFiles = resolveBundledSkillBundle().filter(
+ (f) => f.relativePath !== "SKILL.md",
+ );
const engines = checkEngines(options.sqliteAvailableOverride);
const globalIssues: string[] = [];
@@ -382,6 +393,34 @@ export function runDoctor(homeDirOrOptions?: string | DoctorOptions): DoctorDiag
clientIssues.push(`MCP server is configured for ${c.displayName}, but SKILL.md is missing at '${skillPath}'`);
}
+ // Full-bundle integrity: SKILL.md links into references/ etc., so a
+ // half-installed bundle silently breaks the agent guide.
+ const skillMissingFiles: string[] = [];
+ const skillModifiedFiles: string[] = [];
+ if (skillInstalled) {
+ const recorded = manifest.clients[c.id]?.writtenSkillFiles;
+ for (const file of bundledSupportFiles) {
+ const full = join(c.skillDirectory, ...file.relativePath.split("/"));
+ if (!existsSync(full)) {
+ skillMissingFiles.push(file.relativePath);
+ continue;
+ }
+ try {
+ const sha = sha256Hex(readFileSync(full, "utf8"));
+ if (sha !== file.sha256 && sha !== recorded?.[file.relativePath]) {
+ skillModifiedFiles.push(file.relativePath);
+ }
+ } catch {
+ skillMissingFiles.push(file.relativePath);
+ }
+ }
+ if (skillMissingFiles.length > 0) {
+ clientIssues.push(
+ `Skill bundle for ${c.displayName} is incomplete (missing: ${skillMissingFiles.join(", ")}); re-run \`bla setup --yes\``,
+ );
+ }
+ }
+
let handshakeStatus: DoctorHandshakeStatus = "not_checked";
let handshakeVerified = false;
if (options.verifyHandshake && configured && commandResolvable && command !== null) {
@@ -399,9 +438,14 @@ export function runDoctor(homeDirOrOptions?: string | DoctorOptions): DoctorDiag
if (configStatus === "malformed" || configStatus === "invalid_entry") {
status = "fail";
} else if (configured) {
- if (!commandResolvable || !skillInstalled || handshakeStatus === "failed") {
+ if (
+ !commandResolvable ||
+ !skillInstalled ||
+ skillMissingFiles.length > 0 ||
+ handshakeStatus === "failed"
+ ) {
status = "fail";
- } else if (skillStatus === "modified") {
+ } else if (skillStatus === "modified" || skillModifiedFiles.length > 0) {
status = "warn";
} else {
status = "pass";
@@ -434,6 +478,8 @@ export function runDoctor(homeDirOrOptions?: string | DoctorOptions): DoctorDiag
mcpRegistered,
skillInstalled,
skillStatus,
+ skillMissingFiles,
+ skillModifiedFiles,
status,
issues: clientIssues,
};
diff --git a/tests/skill-bundle-install.test.ts b/tests/skill-bundle-install.test.ts
new file mode 100644
index 0000000..bf04914
--- /dev/null
+++ b/tests/skill-bundle-install.test.ts
@@ -0,0 +1,92 @@
+import { existsSync, mkdtempSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+import { runDoctor } from "../src/setup/doctor.js";
+import {
+ readInstallManifest,
+ resolveBundledSkillBundle,
+ runSetup,
+ runUninstall,
+} from "../src/setup/setup.js";
+
+const tempDirs: string[] = [];
+function makeHome(): string {
+ const dir = mkdtempSync(join(tmpdir(), "bla-skill-bundle-"));
+ tempDirs.push(dir);
+ return dir;
+}
+afterEach(() => {
+ for (const d of tempDirs.splice(0)) rmSync(d, { recursive: true, force: true });
+});
+
+const MATRIX = "references/counter-rea-matrix.md";
+
+function setupCursor(home: string): string {
+ runSetup({
+ homeDir: home,
+ clientIds: ["cursor"],
+ mcpCommand: process.execPath,
+ mcpArgs: [resolve(process.cwd(), "dist/cli.js"), "mcp"],
+ yes: true,
+ });
+ return join(home, ".cursor", "skills", "blind-llm-agents");
+}
+
+describe("skill bundle install integrity", () => {
+ it("bundles SKILL.md first plus every reference file", () => {
+ const bundle = resolveBundledSkillBundle();
+ expect(bundle[0]!.relativePath).toBe("SKILL.md");
+ expect(bundle.map((f) => f.relativePath)).toContain(MATRIX);
+ });
+
+ it("fresh setup installs references so SKILL.md relative links resolve", () => {
+ const home = makeHome();
+ const skillDir = setupCursor(home);
+ const skill = readFileSync(join(skillDir, "SKILL.md"), "utf8");
+ const links = [...skill.matchAll(/\]\((references\/[^)]+)\)/g)].map((m) => m[1]!);
+ expect(links.length).toBeGreaterThan(0);
+ for (const rel of links) expect(existsSync(join(skillDir, rel))).toBe(true);
+ const rec = readInstallManifest(home).clients.cursor!;
+ expect(Object.keys(rec.writtenSkillFiles ?? {})).toContain(MATRIX);
+ });
+
+ it("doctor fails on a missing reference and warns on a modified one", () => {
+ const home = makeHome();
+ const skillDir = setupCursor(home);
+ const ok = runDoctor({ homeDir: home, sqliteAvailableOverride: true });
+ const cursorOk = ok.agentClients.find((c) => c.id === "cursor")!;
+ expect(cursorOk.skillMissingFiles).toEqual([]);
+ expect(cursorOk.status).toBe("pass");
+
+ writeFileSync(join(skillDir, MATRIX), "tampered\n", "utf8");
+ const warn = runDoctor({ homeDir: home, sqliteAvailableOverride: true });
+ const cursorWarn = warn.agentClients.find((c) => c.id === "cursor")!;
+ expect(cursorWarn.skillModifiedFiles).toEqual([MATRIX]);
+ expect(cursorWarn.status).toBe("warn");
+
+ unlinkSync(join(skillDir, MATRIX));
+ const bad = runDoctor({ homeDir: home, sqliteAvailableOverride: true });
+ const cursorBad = bad.agentClients.find((c) => c.id === "cursor")!;
+ expect(cursorBad.skillMissingFiles).toEqual([MATRIX]);
+ expect(cursorBad.status).toBe("fail");
+ expect(bad.healthy).toBe(false);
+ expect(cursorBad.issues.join("\n")).toContain(MATRIX);
+ });
+
+ it("uninstall removes the whole owned bundle and the empty skill dir", () => {
+ const home = makeHome();
+ const skillDir = setupCursor(home);
+ runUninstall({ homeDir: home, clientIds: ["cursor"] });
+ expect(existsSync(join(skillDir, MATRIX))).toBe(false);
+ expect(existsSync(skillDir)).toBe(false);
+ });
+
+ it("uninstall preserves a user-modified reference", () => {
+ const home = makeHome();
+ const skillDir = setupCursor(home);
+ writeFileSync(join(skillDir, MATRIX), "my notes\n", "utf8");
+ runUninstall({ homeDir: home, clientIds: ["cursor"] });
+ expect(readFileSync(join(skillDir, MATRIX), "utf8")).toBe("my notes\n");
+ });
+});