@viberaven/mcp 1.7.0 → 1.7.1

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 VibeRaven
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VibeRaven
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -41,13 +41,14 @@ Reconnect, confirm tools appear, then pass the app root:
41
41
  }
42
42
  ```
43
43
 
44
- Use `C:/projects/your-app` on Windows. Omitted `cwd` means the server startup directory; npm validation accepts no `cwd`. This server invokes matching `@viberaven/cli@1.6.12` through npx. Scans need no VibeRaven login/API key; downloads and npm validation need network.
44
+ Use `C:/projects/your-app` on Windows. Omitted `cwd` means the server startup directory; npm validation accepts no `cwd`. This server prefers a matching CLI installed alongside the MCP and otherwise invokes the exact matching version through npx. Scans need no VibeRaven login/API key; downloads and npm validation need network.
45
45
 
46
- ## The 14 Tools
46
+ ## Repository tools
47
47
 
48
48
  | Tool | CLI operation |
49
49
  | --- | --- |
50
50
  | `viberaven_check_readiness` | `check --json`: fresh check, summary and artifact paths |
51
+ | `viberaven_rls_test` | Experimental `rls-test --json --matrix <path>`; optional `migrations` directory |
51
52
  | `viberaven_verify` | `check --json`: recheck after a batch of fixes |
52
53
  | `viberaven_audit` | `audit --vercel-supabase`; optional `json: true` |
53
54
  | `viberaven_init_rules` | `init`: native instructions; preview with `dryRun: true` |
@@ -64,6 +65,22 @@ Use `C:/projects/your-app` on Windows. Omitted `cwd` means the server startup di
64
65
 
65
66
  Responses contain `exit N`, CLI output and parseable JSON objects as structured content. Blocker exit 1 can be normal tool content.
66
67
 
68
+ ### Optional local behavioral RLS test (local candidate)
69
+
70
+ After reviewing the intended access in a permissions matrix, a local candidate host that lists `viberaven_rls_test` can run:
71
+
72
+ ```json
73
+ {"name":"viberaven_rls_test","arguments":{"cwd":"/absolute/path/to/app","matrix":"reviewed.permissions.json"}}
74
+ ```
75
+
76
+ This reuses the CLI's experimental PGlite imitation for owner, other_user and anon. Prefer `defaultGrants: none` with actual GRANT SQL for new schemas; disclose legacy defaults otherwise. Review expected access before running, and keep it unchanged while fixing a failure. Read Pass/Fail/Unknown and coverage: valid findings (exit 1) and inconclusive results (exit 2) retain their structured evidence. Unknown is inconclusive. Invalid/missing matrices, missing engine, failed migrations/role checks and malformed or inconsistent receipts are tool errors. Local observations do not prove live Supabase behavior or security.
77
+
78
+ Completed RLS results keep the complete receipt in both compact JSON text and `structuredContent`; only JSON formatting whitespace is removed. All evidence fields and stderr diagnostics remain available. Error diagnostics keep their original text.
79
+
80
+ RLS calls stop after 300 seconds or 8 MiB of combined child output. A stopped run terminates the CLI and returns a tool error without a partial passing receipt.
81
+
82
+ Use an already installed matching candidate CLI with optional `@electric-sql/pglite@0.5.8` next to it, configured for this local MCP host as described below. Installing PGlite only in the target project may not make it visible to the host CLI. The RLS route requires this installed CLI and never falls back to npx. Missing host setup returns setup guidance without spawning; missing PGlite returns the existing CLI guidance. The tool does not install dependencies, accept SQL/credentials or access a provider. Obtain normal user authorization before installing dependencies. The installed CLI fallback is `viberaven rls-test --matrix PATH --json`; this candidate tool is not assumed to exist in the published MCP version shown above.
83
+
67
84
  ## Work The Result
68
85
 
69
86
  Readiness refreshes `.viberaven/agent-tasklist.md`, `gate-result.json` and `context-map.json` without patching source. Read tasks/source, review `viberaven_heal_plan` before apply, and recheck each batch with `viberaven_verify`. Provider steps require provider evidence.
@@ -94,4 +111,4 @@ The [RLS comparison](https://ohad6k.github.io/VibeRaven/examples/proof/rls-compa
94
111
 
95
112
  For `viberaven_work_report`, standalone MCP resolves an already installed `@viberaven/cli/package.json` from the MCP installation, and requires its name and exact version to match the MCP candidate. Alternatively, set the host process environment `VIBERAVEN_CLI_PATH` to an absolute matching `dist/cli.js` path. This is an operator-controlled local-candidate setting, not a tool argument. Keep the CLI installation outside the task repository. A regular canonical CLI entry and adjacent manifest are validated before execution.
96
113
 
97
- Report runs Node directly with `shell: false`, strips Node/npm environment steering and never invokes npm, npx, package installation or registry fallback. Install/configure the matching candidate separately; reporting fails until it is available. Missing/mismatched installations, process failures, malformed results, output over the bounded transport budget and the 30-second read timeout return a generic error without raw child diagnostics or local paths. Other standalone MCP tools retain their existing pinned npx execution path. The source-level embedded MCP compatibility handler uses its own CLI entry with the same shared bounded report runner. It has parity/regression tests but is not exposed as a second installed CLI server entrypoint; the executable MCP route is `@viberaven/mcp`.
114
+ Report runs Node directly with `shell: false`, strips Node/npm environment steering and never invokes npm, npx, package installation or registry fallback. Install/configure the matching candidate separately; reporting fails until it is available. Missing/mismatched installations, process failures, malformed results, output over the bounded transport budget and the 30-second read timeout return a generic error without raw child diagnostics or local paths. Standalone MCP tools other than RLS tests and reports use the same installation validation and direct Node execution when a matching host CLI is available; otherwise they retain exact-version pinned npx fallback. An explicitly invalid `VIBERAVEN_CLI_PATH` fails without fallback. Task-local packages and symlinked entries are not trusted. Transport failures and missing/malformed JSON on JSON routes set MCP `isError`; completed checks with findings remain normal structured content. The source-level embedded MCP compatibility handler uses its own CLI entry with the same shared bounded report runner. It has parity/regression tests but is not exposed as a second installed CLI server entrypoint; the executable MCP route is `@viberaven/mcp`.
@@ -323,6 +323,30 @@ function buildWorkToolArgs(name, raw) {
323
323
  return [...out, "--json"];
324
324
  }
325
325
 
326
+ // ../../shared/rlsTool.ts
327
+ var RLS_TOOL_NAME = "viberaven_rls_test";
328
+ var RLS_RUN_TIMEOUT_MS = 3e5;
329
+ var RLS_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
330
+ var MAX_PATH_LENGTH = 4096;
331
+ function record(value) {
332
+ return value !== null && typeof value === "object" && !Array.isArray(value);
333
+ }
334
+ function nonempty(value) {
335
+ return typeof value === "string" && Boolean(value.trim());
336
+ }
337
+ function pathArg(value, name, commandLine = true) {
338
+ if (!nonempty(value) || value.length > MAX_PATH_LENGTH || /[\x00-\x1f\x7f]/.test(value)) throw Error(`Invalid RLS ${name}: expected a non-empty local path up to ${MAX_PATH_LENGTH} characters`);
339
+ if (commandLine && (value.trimStart().startsWith("-") || /[&|<>^%!"'`$();]/.test(value))) throw Error(`Unsafe RLS ${name} path`);
340
+ return value;
341
+ }
342
+ function buildRlsToolArgs(input) {
343
+ if (!record(input) || Object.keys(input).some((key) => !["matrix", "migrations", "cwd"].includes(key))) throw Error("Invalid RLS tool arguments: only matrix, migrations and cwd are accepted");
344
+ const args = ["rls-test", "--json", "--matrix", pathArg(input.matrix, "matrix")];
345
+ if ("migrations" in input) args.push("--migrations", pathArg(input.migrations, "migrations"));
346
+ if ("cwd" in input) pathArg(input.cwd, "cwd", false);
347
+ return args;
348
+ }
349
+
326
350
  // src/lib/cli-runner.ts
327
351
  var import_node_child_process = require("node:child_process");
328
352
  var import_node_fs3 = require("node:fs");
@@ -424,7 +448,7 @@ function runWorkReportProcess(entry, args, cwd3, spawnFn2) {
424
448
  } catch {
425
449
  return Promise.resolve(workReportFailure());
426
450
  }
427
- return new Promise((resolve) => {
451
+ return new Promise((resolve2) => {
428
452
  let settled = false, stdoutBytes = 0, stderrBytes = 0;
429
453
  const chunks = [];
430
454
  let child;
@@ -432,7 +456,7 @@ function runWorkReportProcess(entry, args, cwd3, spawnFn2) {
432
456
  if (!settled) {
433
457
  settled = true;
434
458
  clearTimeout(timer);
435
- resolve(result);
459
+ resolve2(result);
436
460
  }
437
461
  };
438
462
  const fail = () => {
@@ -481,27 +505,34 @@ var within = (root, target) => {
481
505
  const rel = (0, import_node_path.relative)(root, target);
482
506
  return !rel || !(0, import_node_path.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(`..${import_node_path.sep}`);
483
507
  };
484
- function installedReportCli(version, cwd3) {
508
+ function resolveInstalledCli(version, cwd3) {
485
509
  const override = process.env.VIBERAVEN_CLI_PATH;
486
- if (override !== void 0 && !(0, import_node_path.isAbsolute)(override)) throw new Error("Unavailable installed CLI");
487
- const selected = override ?? (0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_module.createRequire)(__filename).resolve("@viberaven/cli/package.json")), "dist", "cli.js");
488
- const info = (0, import_node_fs2.lstatSync)(selected);
489
- if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unavailable installed CLI");
490
- const entry = (0, import_node_fs2.realpathSync)(selected);
491
- const root = (0, import_node_fs2.realpathSync)((0, import_node_path.join)((0, import_node_path.dirname)(entry), ".."));
492
- if (entry !== (0, import_node_path.join)(root, "dist", "cli.js") || within(cwd3, entry)) throw new Error("Unavailable installed CLI");
493
- const manifestPath = (0, import_node_path.join)(root, "package.json"), manifestInfo = (0, import_node_fs2.lstatSync)(manifestPath);
494
- if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink() || manifestInfo.size > 65536 || (0, import_node_fs2.realpathSync)(manifestPath) !== manifestPath) throw new Error("Unavailable installed CLI");
495
- const manifest = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
496
- if (manifest.name !== "@viberaven/cli" || manifest.version !== version) throw new Error("Unavailable installed CLI");
497
- return entry;
510
+ try {
511
+ if (override !== void 0 && !(0, import_node_path.isAbsolute)(override)) throw new Error("Unavailable installed CLI");
512
+ const selected = override ?? (0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_module.createRequire)(__filename).resolve("@viberaven/cli/package.json")), "dist", "cli.js");
513
+ const info = (0, import_node_fs2.lstatSync)(selected);
514
+ if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unavailable installed CLI");
515
+ const entry = (0, import_node_fs2.realpathSync)(selected);
516
+ const root = (0, import_node_fs2.realpathSync)((0, import_node_path.join)((0, import_node_path.dirname)(entry), ".."));
517
+ if (entry !== (0, import_node_path.resolve)(selected) || entry !== (0, import_node_path.join)(root, "dist", "cli.js") || within((0, import_node_fs2.realpathSync)(cwd3), entry)) throw new Error("Unavailable installed CLI");
518
+ const manifestPath = (0, import_node_path.join)(root, "package.json"), manifestInfo = (0, import_node_fs2.lstatSync)(manifestPath);
519
+ if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink() || manifestInfo.size > 65536 || (0, import_node_fs2.realpathSync)(manifestPath) !== manifestPath) throw new Error("Unavailable installed CLI");
520
+ const manifest = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
521
+ if (manifest.name !== "@viberaven/cli" || manifest.version !== version) throw new Error("Unavailable installed CLI");
522
+ return entry;
523
+ } catch {
524
+ if (override !== void 0) throw new Error("Matching installed CLI unavailable. Check VIBERAVEN_CLI_PATH, its exact version and installation outside the task repository.");
525
+ return void 0;
526
+ }
498
527
  }
499
528
  function runInstalledWorkReport(args, cwd3, version, spawnFn2) {
500
529
  let entry, canonicalCwd;
501
530
  try {
502
531
  if (cwd3 !== void 0 && (typeof cwd3 !== "string" || !cwd3.trim())) return Promise.resolve(workReportFailure());
503
532
  canonicalCwd = (0, import_node_fs2.realpathSync)(cwd3 === void 0 ? process.cwd() : cwd3);
504
- entry = installedReportCli(version, canonicalCwd);
533
+ const installed = resolveInstalledCli(version, canonicalCwd);
534
+ if (!installed) return Promise.resolve(workReportFailure());
535
+ entry = installed;
505
536
  } catch {
506
537
  return Promise.resolve(workReportFailure());
507
538
  }
@@ -523,7 +554,7 @@ function mcpVersion() {
523
554
  } catch {
524
555
  }
525
556
  }
526
- found ??= true ? "1.7.0" : void 0;
557
+ found ??= true ? "1.7.1" : void 0;
527
558
  if (!found || !PLAIN_VERSION.test(found)) {
528
559
  throw new Error(`Could not read a valid ${MCP_PACKAGE} version (got ${JSON.stringify(found)}), so the matching ${CLI_PACKAGE} cannot be pinned.`);
529
560
  }
@@ -580,6 +611,7 @@ function buildHealArgs(prefix, args) {
580
611
  return cliArgs;
581
612
  }
582
613
  function buildToolArgs(name, args) {
614
+ if (name === RLS_TOOL_NAME) return buildRlsToolArgs(args);
583
615
  if (isLiveTool(name)) return buildLiveToolArgs(name, args);
584
616
  if (isWorkTool(name)) return buildWorkToolArgs(name, args);
585
617
  switch (name) {
@@ -629,6 +661,9 @@ function buildToolArgs(name, args) {
629
661
  throw new Error(`Unknown VibeRaven tool: ${name}`);
630
662
  }
631
663
  }
664
+ function transportFailure(error, stderr = "") {
665
+ return { stdout: "", stderr, exitCode: 1, transportError: true, text: `ERROR: ${error instanceof Error ? error.message : String(error)}` };
666
+ }
632
667
  async function runVibeRaven(args, cwd3) {
633
668
  return (await runVibeRavenDetailed(args, cwd3)).text;
634
669
  }
@@ -640,32 +675,87 @@ function runVibeRavenDetailed(args, cwd3) {
640
675
  return Promise.resolve(workReportFailure());
641
676
  }
642
677
  }
643
- let npxArgs;
678
+ let built;
679
+ let childCwd, env;
644
680
  try {
645
- npxArgs = cliNpxArgs(args);
681
+ childCwd = resolveCwd(cwd3);
682
+ const installed = resolveInstalledCli(mcpVersion(), childCwd);
683
+ if (args[0] === "rls-test" && !installed) return Promise.resolve(transportFailure(new Error("RLS testing requires a matching installed CLI outside the task repository, with optional PGlite installed next to it. Configure the local MCP host installation or VIBERAVEN_CLI_PATH; this tool does not download or install dependencies.")));
684
+ built = installed ? { command: process.execPath, args: [installed, ...args], shell: false } : buildNpxCommand(cliNpxArgs(args));
685
+ env = installed ? Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(?:node_|npm_)/i.test(key) && key.toLowerCase() !== "viberaven_cli_path")) : cliChildEnv();
646
686
  } catch (error) {
647
- return Promise.resolve({ stdout: "", stderr: "", exitCode: 1, text: `ERROR: ${error instanceof Error ? error.message : String(error)}` });
687
+ return Promise.resolve(transportFailure(error));
648
688
  }
649
- return new Promise((resolve) => {
650
- const built = buildNpxCommand(npxArgs);
651
- const child = spawnFn(built.command, built.args, {
652
- cwd: resolveCwd(cwd3),
653
- env: cliChildEnv(),
654
- shell: built.shell,
655
- stdio: ["ignore", "pipe", "pipe"]
656
- });
689
+ return new Promise((resolve2) => {
690
+ let child;
691
+ try {
692
+ child = spawnFn(built.command, built.args, {
693
+ cwd: childCwd,
694
+ env,
695
+ shell: built.shell,
696
+ windowsHide: true,
697
+ stdio: ["ignore", "pipe", "pipe"]
698
+ });
699
+ } catch (error) {
700
+ resolve2(transportFailure(error));
701
+ return;
702
+ }
657
703
  let stdout = "";
658
704
  let stderr = "";
659
- child.stdout?.on("data", (chunk) => {
660
- stdout += chunk.toString();
661
- });
662
- child.stderr?.on("data", (chunk) => {
663
- stderr += chunk.toString();
664
- });
665
- child.on("error", (error) => resolve({ stdout: "", stderr, exitCode: 1, text: `ERROR: ${error.message}` }));
705
+ const boundedRls = args[0] === "rls-test";
706
+ const rlsChunks = { stdout: [], stderr: [] };
707
+ let outputBytes = 0;
708
+ let settled = false;
709
+ let timer;
710
+ const finish = (result) => {
711
+ if (settled) return;
712
+ settled = true;
713
+ if (timer) clearTimeout(timer);
714
+ resolve2(result);
715
+ };
716
+ const stopRls = (reason) => {
717
+ finish(transportFailure(new Error(reason)));
718
+ try {
719
+ child.kill("SIGKILL");
720
+ } catch {
721
+ }
722
+ };
723
+ if (boundedRls) timer = setTimeout(() => stopRls("RLS test exceeded its 300-second aggregate time limit and was stopped; no partial result is reported as passed."), RLS_RUN_TIMEOUT_MS);
724
+ const collect = (chunk, stream) => {
725
+ if (settled) return;
726
+ outputBytes += Buffer.byteLength(chunk);
727
+ if (boundedRls && outputBytes > RLS_MAX_OUTPUT_BYTES) {
728
+ stopRls("RLS test exceeded its combined output limit and was stopped; no partial result is reported as passed.");
729
+ return;
730
+ }
731
+ if (boundedRls) {
732
+ rlsChunks[stream].push(Buffer.from(chunk));
733
+ return;
734
+ }
735
+ if (stream === "stdout") stdout += chunk.toString();
736
+ else stderr += chunk.toString();
737
+ };
738
+ child.stdout?.on("data", (chunk) => collect(chunk, "stdout"));
739
+ child.stderr?.on("data", (chunk) => collect(chunk, "stderr"));
740
+ child.on("error", (error) => finish(transportFailure(error, boundedRls ? "" : stderr)));
666
741
  child.on("close", (code) => {
742
+ if (settled) return;
743
+ if (code === null) {
744
+ finish(transportFailure(new Error("CLI process ended without an exit code"), boundedRls ? "" : stderr));
745
+ return;
746
+ }
747
+ if (boundedRls) {
748
+ try {
749
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
750
+ stdout = decoder.decode(Buffer.concat(rlsChunks.stdout));
751
+ stderr = decoder.decode(Buffer.concat(rlsChunks.stderr));
752
+ } catch {
753
+ finish(transportFailure(new Error("RLS test returned invalid UTF-8; no partial result is reported as passed.")));
754
+ return;
755
+ }
756
+ }
667
757
  const combined = `${stdout}${stderr}`.trim();
668
- resolve({ stdout, stderr, exitCode: code ?? 1, text: `exit ${code ?? 1}${combined ? `
758
+ finish({ stdout, stderr, exitCode: code ?? 1, text: `exit ${code ?? 1}${combined ? `
669
759
  ${combined}` : ""}` });
670
760
  });
671
761
  });
package/dist/server.js CHANGED
@@ -30,6 +30,122 @@ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
30
30
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
31
31
  var import_types = require("@modelcontextprotocol/sdk/types.js");
32
32
 
33
+ // ../../shared/rlsTool.ts
34
+ var RLS_TOOL_NAME = "viberaven_rls_test";
35
+ var RLS_RUN_TIMEOUT_MS = 3e5;
36
+ var RLS_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
37
+ var NON_AUTHORITATIVE_LABEL = "PGlite imitation of Supabase, non-authoritative. Scenario passed locally does not prove production.";
38
+ var MAX_PATH_LENGTH = 4096;
39
+ var RLS_TOOL = {
40
+ name: RLS_TOOL_NAME,
41
+ description: "After reviewing a Supabase migration or ownership policy, optionally execute already reviewed local permissions scenarios for owner, other_user and anon. Returns Pass, Fail or Unknown per cell with the original scoped evidence. This is an experimental PGlite imitation, not live Supabase proof. The optional PGlite dependency must already be installed next to the matching CLI used by this local MCP host; missing setup returns the CLI setup guidance as a tool error. No SQL, credentials, provider calls or dependency installation are accepted.",
42
+ inputSchema: {
43
+ type: "object",
44
+ properties: {
45
+ matrix: { type: "string", minLength: 1, maxLength: MAX_PATH_LENGTH, description: "Path to an already reviewed permissions JSON file, relative to cwd or absolute. Expectations must describe intended access." },
46
+ migrations: { type: "string", minLength: 1, maxLength: MAX_PATH_LENGTH, description: "Local migrations directory. Defaults to supabase/migrations under cwd." },
47
+ cwd: { type: "string", minLength: 1, maxLength: MAX_PATH_LENGTH, description: "Project root. Defaults to the MCP server working directory." }
48
+ },
49
+ required: ["matrix"],
50
+ additionalProperties: false
51
+ }
52
+ };
53
+ function record(value) {
54
+ return value !== null && typeof value === "object" && !Array.isArray(value);
55
+ }
56
+ function nonempty(value) {
57
+ return typeof value === "string" && Boolean(value.trim());
58
+ }
59
+ function pathArg(value, name, commandLine = true) {
60
+ if (!nonempty(value) || value.length > MAX_PATH_LENGTH || /[\x00-\x1f\x7f]/.test(value)) throw Error(`Invalid RLS ${name}: expected a non-empty local path up to ${MAX_PATH_LENGTH} characters`);
61
+ if (commandLine && (value.trimStart().startsWith("-") || /[&|<>^%!"'`$();]/.test(value))) throw Error(`Unsafe RLS ${name} path`);
62
+ return value;
63
+ }
64
+ function buildRlsToolArgs(input) {
65
+ if (!record(input) || Object.keys(input).some((key) => !["matrix", "migrations", "cwd"].includes(key))) throw Error("Invalid RLS tool arguments: only matrix, migrations and cwd are accepted");
66
+ const args = ["rls-test", "--json", "--matrix", pathArg(input.matrix, "matrix")];
67
+ if ("migrations" in input) args.push("--migrations", pathArg(input.migrations, "migrations"));
68
+ if ("cwd" in input) pathArg(input.cwd, "cwd", false);
69
+ return args;
70
+ }
71
+ var hash = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
72
+ var strings = (value) => Array.isArray(value) && value.every(nonempty);
73
+ var actions = ["select", "insert", "update", "delete"];
74
+ var actors = ["owner", "other_user", "anon"];
75
+ function completedReceipt(receipt, processExit) {
76
+ if ("error" in receipt || receipt.tool !== "viberaven rls-test" || receipt.experimental !== true || receipt.label !== NON_AUTHORITATIVE_LABEL || !nonempty(receipt.project)) return false;
77
+ if (![0, 1, 2].includes(processExit) || receipt.exitCode !== processExit) return false;
78
+ const { engine, migrations, matrix, summary, tables, roleChecks } = receipt;
79
+ if (!record(engine) || engine.name !== "PGlite" || engine.available !== true || "error" in engine) return false;
80
+ if (!record(migrations) || migrations.applied !== true || "failure" in migrations || !nonempty(migrations.dir) || !hash(migrations.hash) || !Array.isArray(migrations.files) || migrations.files.length === 0 || !migrations.files.every((file) => record(file) && nonempty(file.name) && hash(file.sha256))) return false;
81
+ if (!record(matrix) || !nonempty(matrix.path) || !hash(matrix.hash) || !["none", "supabase-legacy"].includes(matrix.defaultGrants)) return false;
82
+ if (receipt.commit !== null && (!record(receipt.commit) || typeof receipt.commit.sha !== "string" || !/^[a-f0-9]{40}$/.test(receipt.commit.sha) || ![true, false, null].includes(receipt.commit.dirty))) return false;
83
+ if (!strings(receipt.filesRead) || !strings(receipt.assumptions) || !strings(receipt.exclusions)) return false;
84
+ if (!Array.isArray(roleChecks) || !roleChecks.every((check) => record(check) && nonempty(check.role) && check.ok === true && nonempty(check.detail))) return false;
85
+ const checkedRoles = new Set(roleChecks.map((check) => check.role));
86
+ if (checkedRoles.size !== roleChecks.length || !checkedRoles.has("anon") || !checkedRoles.has("authenticated")) return false;
87
+ if (!record(summary) || !Array.isArray(tables) || tables.length === 0) return false;
88
+ const counts = { pass: 0, fail: 0, unknown: 0, notApplicable: 0, tested: 0, total: 0 };
89
+ const tableNames = /* @__PURE__ */ new Set();
90
+ for (const table of tables) {
91
+ if (!record(table) || !nonempty(table.name) || tableNames.has(table.name) || !Array.isArray(table.cells) || table.cells.length === 0) return false;
92
+ tableNames.add(table.name);
93
+ const cells = /* @__PURE__ */ new Set();
94
+ let observed = false;
95
+ for (const cell of table.cells) {
96
+ if (!record(cell) || cell.table !== table.name || ![...actors, "service_role"].includes(cell.actor) || ![...actions, "reassign"].includes(cell.action)) return false;
97
+ const key = `${cell.actor}:${cell.action}`;
98
+ if (cells.has(key) || !record(cell.observed) || !nonempty(cell.observed.summary) || !nonempty(cell.reason)) return false;
99
+ cells.add(key);
100
+ if (cell.actor === "service_role") {
101
+ if (!actions.includes(cell.action) || cell.expected !== "excluded" || cell.outcome !== "N/A") return false;
102
+ } else if (cell.expected === "skip") {
103
+ if (cell.outcome !== "N/A") return false;
104
+ } else if (!["allow", "deny"].includes(cell.expected) || !["Pass", "Fail", "Unknown"].includes(cell.outcome)) return false;
105
+ if (cell.outcome === "Pass") {
106
+ counts.pass += 1;
107
+ observed = true;
108
+ } else if (cell.outcome === "Fail") {
109
+ counts.fail += 1;
110
+ observed = true;
111
+ } else if (cell.outcome === "Unknown") counts.unknown += 1;
112
+ else if (cell.outcome === "N/A") counts.notApplicable += 1;
113
+ else return false;
114
+ counts.total += 1;
115
+ }
116
+ if (actors.some((actor) => actions.some((action) => !cells.has(`${actor}:${action}`)))) return false;
117
+ if (actions.some((action) => cells.has(`service_role:${action}`)) && actions.some((action) => !cells.has(`service_role:${action}`))) return false;
118
+ if (observed || table.rls !== void 0) {
119
+ if (!record(table.rls) || typeof table.rls.enabled !== "boolean" || typeof table.rls.forced !== "boolean" || !nonempty(table.rls.owner)) return false;
120
+ if (!checkedRoles.has(`anon on ${table.name}`) || !checkedRoles.has(`authenticated on ${table.name}`)) return false;
121
+ }
122
+ }
123
+ counts.tested = counts.total - counts.notApplicable;
124
+ if (Object.entries(counts).some(([key, value]) => !Number.isSafeInteger(summary[key]) || summary[key] !== value)) return false;
125
+ const exitCode = counts.fail > 0 ? 1 : counts.pass === 0 || counts.unknown > 0 ? 2 : 0;
126
+ if (processExit !== exitCode) return false;
127
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
128
+ const verdict = counts.fail > 0 ? `Not ready within tested scope: ${plural(counts.fail, "cell does", "cells do")} not match the matrix; ${plural(counts.unknown, "unknown")}.` : counts.pass === 0 ? `Nothing was observed: ${plural(counts.unknown, "unknown")}, ${counts.notApplicable} N/A.` : counts.unknown > 0 ? `No blockers found within tested scope; ${plural(counts.unknown, "unknown")}.` : "No blockers found within tested scope; 0 unknowns. Scenario passed locally.";
129
+ return receipt.verdict === verdict;
130
+ }
131
+ function classifyRlsToolResult(stdout, exitCode, transportError = false) {
132
+ let receipt;
133
+ try {
134
+ receipt = JSON.parse(stdout);
135
+ } catch {
136
+ return { isError: true };
137
+ }
138
+ if (!record(receipt)) return { isError: true };
139
+ return { isError: transportError || !completedReceipt(receipt, exitCode), structuredContent: receipt };
140
+ }
141
+ function buildRlsToolResponse(run) {
142
+ const classified = classifyRlsToolResult(run.stdout, run.exitCode, run.transportError);
143
+ const text = !classified.isError && classified.structuredContent ? `exit ${run.exitCode}
144
+ ${JSON.stringify(classified.structuredContent)}${run.stderr ? `
145
+ ${run.stderr}` : ""}`.trim() : run.text;
146
+ return { content: [{ type: "text", text }], ...classified };
147
+ }
148
+
33
149
  // ../../shared/liveTools.ts
34
150
  var cwd = { type: "string", description: "Local project directory. Defaults to the MCP working directory." };
35
151
  var stepId = { type: "string", format: "uuid", description: "The stepId returned by live_start; preserve it through sign-in, payment and retries." };
@@ -963,7 +1079,7 @@ function runWorkReportProcess(entry, args, cwd3, spawnFn2) {
963
1079
  } catch {
964
1080
  return Promise.resolve(workReportFailure());
965
1081
  }
966
- return new Promise((resolve) => {
1082
+ return new Promise((resolve2) => {
967
1083
  let settled = false, stdoutBytes = 0, stderrBytes = 0;
968
1084
  const chunks = [];
969
1085
  let child;
@@ -971,7 +1087,7 @@ function runWorkReportProcess(entry, args, cwd3, spawnFn2) {
971
1087
  if (!settled) {
972
1088
  settled = true;
973
1089
  clearTimeout(timer);
974
- resolve(result);
1090
+ resolve2(result);
975
1091
  }
976
1092
  };
977
1093
  const fail = () => {
@@ -1020,27 +1136,34 @@ var within = (root, target) => {
1020
1136
  const rel = (0, import_node_path.relative)(root, target);
1021
1137
  return !rel || !(0, import_node_path.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(`..${import_node_path.sep}`);
1022
1138
  };
1023
- function installedReportCli(version, cwd3) {
1139
+ function resolveInstalledCli(version, cwd3) {
1024
1140
  const override = process.env.VIBERAVEN_CLI_PATH;
1025
- if (override !== void 0 && !(0, import_node_path.isAbsolute)(override)) throw new Error("Unavailable installed CLI");
1026
- const selected = override ?? (0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_module.createRequire)(__filename).resolve("@viberaven/cli/package.json")), "dist", "cli.js");
1027
- const info = (0, import_node_fs2.lstatSync)(selected);
1028
- if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unavailable installed CLI");
1029
- const entry = (0, import_node_fs2.realpathSync)(selected);
1030
- const root = (0, import_node_fs2.realpathSync)((0, import_node_path.join)((0, import_node_path.dirname)(entry), ".."));
1031
- if (entry !== (0, import_node_path.join)(root, "dist", "cli.js") || within(cwd3, entry)) throw new Error("Unavailable installed CLI");
1032
- const manifestPath = (0, import_node_path.join)(root, "package.json"), manifestInfo = (0, import_node_fs2.lstatSync)(manifestPath);
1033
- if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink() || manifestInfo.size > 65536 || (0, import_node_fs2.realpathSync)(manifestPath) !== manifestPath) throw new Error("Unavailable installed CLI");
1034
- const manifest = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
1035
- if (manifest.name !== "@viberaven/cli" || manifest.version !== version) throw new Error("Unavailable installed CLI");
1036
- return entry;
1141
+ try {
1142
+ if (override !== void 0 && !(0, import_node_path.isAbsolute)(override)) throw new Error("Unavailable installed CLI");
1143
+ const selected = override ?? (0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_module.createRequire)(__filename).resolve("@viberaven/cli/package.json")), "dist", "cli.js");
1144
+ const info = (0, import_node_fs2.lstatSync)(selected);
1145
+ if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unavailable installed CLI");
1146
+ const entry = (0, import_node_fs2.realpathSync)(selected);
1147
+ const root = (0, import_node_fs2.realpathSync)((0, import_node_path.join)((0, import_node_path.dirname)(entry), ".."));
1148
+ if (entry !== (0, import_node_path.resolve)(selected) || entry !== (0, import_node_path.join)(root, "dist", "cli.js") || within((0, import_node_fs2.realpathSync)(cwd3), entry)) throw new Error("Unavailable installed CLI");
1149
+ const manifestPath = (0, import_node_path.join)(root, "package.json"), manifestInfo = (0, import_node_fs2.lstatSync)(manifestPath);
1150
+ if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink() || manifestInfo.size > 65536 || (0, import_node_fs2.realpathSync)(manifestPath) !== manifestPath) throw new Error("Unavailable installed CLI");
1151
+ const manifest = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
1152
+ if (manifest.name !== "@viberaven/cli" || manifest.version !== version) throw new Error("Unavailable installed CLI");
1153
+ return entry;
1154
+ } catch {
1155
+ if (override !== void 0) throw new Error("Matching installed CLI unavailable. Check VIBERAVEN_CLI_PATH, its exact version and installation outside the task repository.");
1156
+ return void 0;
1157
+ }
1037
1158
  }
1038
1159
  function runInstalledWorkReport(args, cwd3, version, spawnFn2) {
1039
1160
  let entry, canonicalCwd;
1040
1161
  try {
1041
1162
  if (cwd3 !== void 0 && (typeof cwd3 !== "string" || !cwd3.trim())) return Promise.resolve(workReportFailure());
1042
1163
  canonicalCwd = (0, import_node_fs2.realpathSync)(cwd3 === void 0 ? process.cwd() : cwd3);
1043
- entry = installedReportCli(version, canonicalCwd);
1164
+ const installed = resolveInstalledCli(version, canonicalCwd);
1165
+ if (!installed) return Promise.resolve(workReportFailure());
1166
+ entry = installed;
1044
1167
  } catch {
1045
1168
  return Promise.resolve(workReportFailure());
1046
1169
  }
@@ -1062,7 +1185,7 @@ function mcpVersion() {
1062
1185
  } catch {
1063
1186
  }
1064
1187
  }
1065
- found ??= true ? "1.7.0" : void 0;
1188
+ found ??= true ? "1.7.1" : void 0;
1066
1189
  if (!found || !PLAIN_VERSION.test(found)) {
1067
1190
  throw new Error(`Could not read a valid ${MCP_PACKAGE} version (got ${JSON.stringify(found)}), so the matching ${CLI_PACKAGE} cannot be pinned.`);
1068
1191
  }
@@ -1113,6 +1236,7 @@ function buildHealArgs(prefix, args) {
1113
1236
  return cliArgs;
1114
1237
  }
1115
1238
  function buildToolArgs(name, args) {
1239
+ if (name === RLS_TOOL_NAME) return buildRlsToolArgs(args);
1116
1240
  if (isLiveTool(name)) return buildLiveToolArgs(name, args);
1117
1241
  if (isWorkTool(name)) return buildWorkToolArgs(name, args);
1118
1242
  switch (name) {
@@ -1162,6 +1286,9 @@ function buildToolArgs(name, args) {
1162
1286
  throw new Error(`Unknown VibeRaven tool: ${name}`);
1163
1287
  }
1164
1288
  }
1289
+ function transportFailure(error, stderr = "") {
1290
+ return { stdout: "", stderr, exitCode: 1, transportError: true, text: `ERROR: ${error instanceof Error ? error.message : String(error)}` };
1291
+ }
1165
1292
  function runVibeRavenDetailed(args, cwd3) {
1166
1293
  if (args[0] === "work" && args[1] === "report") {
1167
1294
  try {
@@ -1170,32 +1297,87 @@ function runVibeRavenDetailed(args, cwd3) {
1170
1297
  return Promise.resolve(workReportFailure());
1171
1298
  }
1172
1299
  }
1173
- let npxArgs;
1300
+ let built;
1301
+ let childCwd, env;
1174
1302
  try {
1175
- npxArgs = cliNpxArgs(args);
1303
+ childCwd = resolveCwd(cwd3);
1304
+ const installed = resolveInstalledCli(mcpVersion(), childCwd);
1305
+ if (args[0] === "rls-test" && !installed) return Promise.resolve(transportFailure(new Error("RLS testing requires a matching installed CLI outside the task repository, with optional PGlite installed next to it. Configure the local MCP host installation or VIBERAVEN_CLI_PATH; this tool does not download or install dependencies.")));
1306
+ built = installed ? { command: process.execPath, args: [installed, ...args], shell: false } : buildNpxCommand(cliNpxArgs(args));
1307
+ env = installed ? Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(?:node_|npm_)/i.test(key) && key.toLowerCase() !== "viberaven_cli_path")) : cliChildEnv();
1176
1308
  } catch (error) {
1177
- return Promise.resolve({ stdout: "", stderr: "", exitCode: 1, text: `ERROR: ${error instanceof Error ? error.message : String(error)}` });
1309
+ return Promise.resolve(transportFailure(error));
1178
1310
  }
1179
- return new Promise((resolve) => {
1180
- const built = buildNpxCommand(npxArgs);
1181
- const child = spawnFn(built.command, built.args, {
1182
- cwd: resolveCwd(cwd3),
1183
- env: cliChildEnv(),
1184
- shell: built.shell,
1185
- stdio: ["ignore", "pipe", "pipe"]
1186
- });
1311
+ return new Promise((resolve2) => {
1312
+ let child;
1313
+ try {
1314
+ child = spawnFn(built.command, built.args, {
1315
+ cwd: childCwd,
1316
+ env,
1317
+ shell: built.shell,
1318
+ windowsHide: true,
1319
+ stdio: ["ignore", "pipe", "pipe"]
1320
+ });
1321
+ } catch (error) {
1322
+ resolve2(transportFailure(error));
1323
+ return;
1324
+ }
1187
1325
  let stdout = "";
1188
1326
  let stderr = "";
1189
- child.stdout?.on("data", (chunk) => {
1190
- stdout += chunk.toString();
1191
- });
1192
- child.stderr?.on("data", (chunk) => {
1193
- stderr += chunk.toString();
1194
- });
1195
- child.on("error", (error) => resolve({ stdout: "", stderr, exitCode: 1, text: `ERROR: ${error.message}` }));
1327
+ const boundedRls = args[0] === "rls-test";
1328
+ const rlsChunks = { stdout: [], stderr: [] };
1329
+ let outputBytes = 0;
1330
+ let settled = false;
1331
+ let timer;
1332
+ const finish = (result) => {
1333
+ if (settled) return;
1334
+ settled = true;
1335
+ if (timer) clearTimeout(timer);
1336
+ resolve2(result);
1337
+ };
1338
+ const stopRls = (reason) => {
1339
+ finish(transportFailure(new Error(reason)));
1340
+ try {
1341
+ child.kill("SIGKILL");
1342
+ } catch {
1343
+ }
1344
+ };
1345
+ if (boundedRls) timer = setTimeout(() => stopRls("RLS test exceeded its 300-second aggregate time limit and was stopped; no partial result is reported as passed."), RLS_RUN_TIMEOUT_MS);
1346
+ const collect = (chunk, stream) => {
1347
+ if (settled) return;
1348
+ outputBytes += Buffer.byteLength(chunk);
1349
+ if (boundedRls && outputBytes > RLS_MAX_OUTPUT_BYTES) {
1350
+ stopRls("RLS test exceeded its combined output limit and was stopped; no partial result is reported as passed.");
1351
+ return;
1352
+ }
1353
+ if (boundedRls) {
1354
+ rlsChunks[stream].push(Buffer.from(chunk));
1355
+ return;
1356
+ }
1357
+ if (stream === "stdout") stdout += chunk.toString();
1358
+ else stderr += chunk.toString();
1359
+ };
1360
+ child.stdout?.on("data", (chunk) => collect(chunk, "stdout"));
1361
+ child.stderr?.on("data", (chunk) => collect(chunk, "stderr"));
1362
+ child.on("error", (error) => finish(transportFailure(error, boundedRls ? "" : stderr)));
1196
1363
  child.on("close", (code) => {
1364
+ if (settled) return;
1365
+ if (code === null) {
1366
+ finish(transportFailure(new Error("CLI process ended without an exit code"), boundedRls ? "" : stderr));
1367
+ return;
1368
+ }
1369
+ if (boundedRls) {
1370
+ try {
1371
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
1372
+ stdout = decoder.decode(Buffer.concat(rlsChunks.stdout));
1373
+ stderr = decoder.decode(Buffer.concat(rlsChunks.stderr));
1374
+ } catch {
1375
+ finish(transportFailure(new Error("RLS test returned invalid UTF-8; no partial result is reported as passed.")));
1376
+ return;
1377
+ }
1378
+ }
1197
1379
  const combined = `${stdout}${stderr}`.trim();
1198
- resolve({ stdout, stderr, exitCode: code ?? 1, text: `exit ${code ?? 1}${combined ? `
1380
+ finish({ stdout, stderr, exitCode: code ?? 1, text: `exit ${code ?? 1}${combined ? `
1199
1381
  ${combined}` : ""}` });
1200
1382
  });
1201
1383
  });
@@ -1203,8 +1385,10 @@ ${combined}` : ""}` });
1203
1385
 
1204
1386
  // src/tools/index.ts
1205
1387
  var [checkReadiness, verify, strictGate, gateResult, contextMap] = readinessTools;
1388
+ var SEMANTIC_FINDING_TOOLS = /* @__PURE__ */ new Set(["viberaven_check_readiness", "viberaven_verify", "viberaven_audit", "viberaven_strict_gate", "viberaven_gate_result"]);
1206
1389
  var ALL_TOOLS = [
1207
1390
  checkReadiness,
1391
+ RLS_TOOL,
1208
1392
  verify,
1209
1393
  ...auditTools,
1210
1394
  ...rulesTools,
@@ -1227,16 +1411,37 @@ function parseJsonObjectFromToolText(text) {
1227
1411
  return void 0;
1228
1412
  }
1229
1413
  }
1414
+ function isCompletedNegativeNpmVerdict(receipt) {
1415
+ if (!receipt || "error" in receipt) return false;
1416
+ const results = "results" in receipt ? receipt.results : [receipt];
1417
+ try {
1418
+ return Array.isArray(results) && results.length > 0 && results.every((item) => {
1419
+ if (!item || typeof item !== "object" || Array.isArray(item) || "error" in item) return false;
1420
+ return typeof item.name === "string" && Boolean(item.name.trim()) && ["ok", "not_found", "suspicious"].includes(item.verdict) && Array.isArray(item.reasons) && item.reasons.length > 0 && item.reasons.every((reason) => typeof reason === "string" && Boolean(reason.trim())) && item.registryUrl === `https://registry.npmjs.org/${encodeURIComponent(item.name)}` && typeof item.followUpCommand === "string" && Boolean(item.followUpCommand.trim());
1421
+ }) && results.some((item) => item.verdict !== "ok");
1422
+ } catch {
1423
+ return false;
1424
+ }
1425
+ }
1230
1426
  async function handleRequest(method, params) {
1231
1427
  if (method === "tools/list") return { tools: ALL_TOOLS };
1232
1428
  if (method === "tools/call") {
1233
1429
  if (params.name === "provider_playbook") return providerPlaybook(params.arguments);
1234
1430
  const args = params.arguments || {};
1235
- const { text, stdout, exitCode } = await runVibeRavenDetailed(buildToolArgs(params.name, args), args.cwd);
1431
+ const cliArgs = buildToolArgs(params.name, args);
1432
+ const run = await runVibeRavenDetailed(cliArgs, args.cwd);
1433
+ if (params.name === RLS_TOOL_NAME) return buildRlsToolResponse(run);
1434
+ const { text, stdout, exitCode, transportError } = run;
1236
1435
  const parsed = parseJsonObjectFromToolText(stdout);
1436
+ const receipt = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
1437
+ const approvalRefusal = params.name === "viberaven_heal_apply" && receipt?.status === "refused_dangerous";
1438
+ const textAuditFinding = params.name === "viberaven_audit" && !cliArgs.includes("--json") && !transportError && /^VibeRaven Vercel\/Supabase audit\r?\nStatus: needs_work\r?\n/.test(stdout) && /^NEEDS_WORK [a-z][a-z0-9-]*\r?$/m.test(stdout);
1439
+ const semanticFinding = exitCode === 1 && (textAuditFinding || receipt && !receipt.error && (SEMANTIC_FINDING_TOOLS.has(params.name) || approvalRefusal));
1440
+ const npmFinding = params.name === "viberaven_validate_npm_package" && exitCode === 2 && !transportError && isCompletedNegativeNpmVerdict(receipt);
1441
+ const isError = transportError || cliArgs.includes("--json") && !receipt || Boolean(receipt?.error) || exitCode !== 0 && !semanticFinding && !npmFinding || isLiveTool(params.name) && isLiveToolFailure(exitCode, parsed);
1237
1442
  return {
1238
1443
  content: [{ type: "text", text }],
1239
- ...params.name.startsWith("viberaven_work_") && exitCode !== 0 || isLiveTool(params.name) && isLiveToolFailure(exitCode, parsed) ? { isError: true } : {},
1444
+ ...isError ? { isError: true } : {},
1240
1445
  ...parsed ? { structuredContent: parsed } : {}
1241
1446
  };
1242
1447
  }
@@ -1244,7 +1449,7 @@ async function handleRequest(method, params) {
1244
1449
  }
1245
1450
 
1246
1451
  // src/server.ts
1247
- var SERVER_INFO = { name: "viberaven-mcp", version: "1.7.0" };
1452
+ var SERVER_INFO = { name: "viberaven-mcp", version: "1.7.1" };
1248
1453
  var INSTRUCTIONS = [
1249
1454
  "VibeRaven reads a repository and lists launch gaps for AI-built apps that deploy on Vercel and use Supabase.",
1250
1455
  "Suggest one viberaven_check_readiness run before such an app launches or is handed off, after a Supabase migration or policy change,",
@@ -1253,6 +1458,7 @@ var INSTRUCTIONS = [
1253
1458
  "It is a repository check, not a live database test. It cannot show which RLS policies are live in production, and a clear result is not a security audit.",
1254
1459
  "The existing repository checks are scoped to Vercel and Supabase; they do not cover every provider.",
1255
1460
  "For feature planning, provider_playbook returns versioned provider knowledge independently of hosting. Read the supported pack and its limits; retrieval does not execute checks or connect to providers.",
1461
+ "For optional behavioral checks after reviewing a Supabase migration or ownership policy, viberaven_rls_test runs an already reviewed local permissions matrix for owner, other_user and anon. Read Pass, Fail and Unknown per cell; Unknown is inconclusive. This experimental PGlite imitation is not live Supabase proof. PGlite must already be installed next to the matching CLI used by the local MCP host; missing setup is a tool error with CLI guidance, not a passing result.",
1256
1462
  "After fixes, call viberaven_verify once per batch, not after every edit."
1257
1463
  ].join(" ");
1258
1464
  var server = new import_server.Server(SERVER_INFO, { capabilities: { tools: {} }, instructions: INSTRUCTIONS });
@@ -30,6 +30,122 @@ __export(tools_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(tools_exports);
32
32
 
33
+ // ../../shared/rlsTool.ts
34
+ var RLS_TOOL_NAME = "viberaven_rls_test";
35
+ var RLS_RUN_TIMEOUT_MS = 3e5;
36
+ var RLS_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
37
+ var NON_AUTHORITATIVE_LABEL = "PGlite imitation of Supabase, non-authoritative. Scenario passed locally does not prove production.";
38
+ var MAX_PATH_LENGTH = 4096;
39
+ var RLS_TOOL = {
40
+ name: RLS_TOOL_NAME,
41
+ description: "After reviewing a Supabase migration or ownership policy, optionally execute already reviewed local permissions scenarios for owner, other_user and anon. Returns Pass, Fail or Unknown per cell with the original scoped evidence. This is an experimental PGlite imitation, not live Supabase proof. The optional PGlite dependency must already be installed next to the matching CLI used by this local MCP host; missing setup returns the CLI setup guidance as a tool error. No SQL, credentials, provider calls or dependency installation are accepted.",
42
+ inputSchema: {
43
+ type: "object",
44
+ properties: {
45
+ matrix: { type: "string", minLength: 1, maxLength: MAX_PATH_LENGTH, description: "Path to an already reviewed permissions JSON file, relative to cwd or absolute. Expectations must describe intended access." },
46
+ migrations: { type: "string", minLength: 1, maxLength: MAX_PATH_LENGTH, description: "Local migrations directory. Defaults to supabase/migrations under cwd." },
47
+ cwd: { type: "string", minLength: 1, maxLength: MAX_PATH_LENGTH, description: "Project root. Defaults to the MCP server working directory." }
48
+ },
49
+ required: ["matrix"],
50
+ additionalProperties: false
51
+ }
52
+ };
53
+ function record(value) {
54
+ return value !== null && typeof value === "object" && !Array.isArray(value);
55
+ }
56
+ function nonempty(value) {
57
+ return typeof value === "string" && Boolean(value.trim());
58
+ }
59
+ function pathArg(value, name, commandLine = true) {
60
+ if (!nonempty(value) || value.length > MAX_PATH_LENGTH || /[\x00-\x1f\x7f]/.test(value)) throw Error(`Invalid RLS ${name}: expected a non-empty local path up to ${MAX_PATH_LENGTH} characters`);
61
+ if (commandLine && (value.trimStart().startsWith("-") || /[&|<>^%!"'`$();]/.test(value))) throw Error(`Unsafe RLS ${name} path`);
62
+ return value;
63
+ }
64
+ function buildRlsToolArgs(input) {
65
+ if (!record(input) || Object.keys(input).some((key) => !["matrix", "migrations", "cwd"].includes(key))) throw Error("Invalid RLS tool arguments: only matrix, migrations and cwd are accepted");
66
+ const args = ["rls-test", "--json", "--matrix", pathArg(input.matrix, "matrix")];
67
+ if ("migrations" in input) args.push("--migrations", pathArg(input.migrations, "migrations"));
68
+ if ("cwd" in input) pathArg(input.cwd, "cwd", false);
69
+ return args;
70
+ }
71
+ var hash = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
72
+ var strings = (value) => Array.isArray(value) && value.every(nonempty);
73
+ var actions = ["select", "insert", "update", "delete"];
74
+ var actors = ["owner", "other_user", "anon"];
75
+ function completedReceipt(receipt, processExit) {
76
+ if ("error" in receipt || receipt.tool !== "viberaven rls-test" || receipt.experimental !== true || receipt.label !== NON_AUTHORITATIVE_LABEL || !nonempty(receipt.project)) return false;
77
+ if (![0, 1, 2].includes(processExit) || receipt.exitCode !== processExit) return false;
78
+ const { engine, migrations, matrix, summary, tables, roleChecks } = receipt;
79
+ if (!record(engine) || engine.name !== "PGlite" || engine.available !== true || "error" in engine) return false;
80
+ if (!record(migrations) || migrations.applied !== true || "failure" in migrations || !nonempty(migrations.dir) || !hash(migrations.hash) || !Array.isArray(migrations.files) || migrations.files.length === 0 || !migrations.files.every((file) => record(file) && nonempty(file.name) && hash(file.sha256))) return false;
81
+ if (!record(matrix) || !nonempty(matrix.path) || !hash(matrix.hash) || !["none", "supabase-legacy"].includes(matrix.defaultGrants)) return false;
82
+ if (receipt.commit !== null && (!record(receipt.commit) || typeof receipt.commit.sha !== "string" || !/^[a-f0-9]{40}$/.test(receipt.commit.sha) || ![true, false, null].includes(receipt.commit.dirty))) return false;
83
+ if (!strings(receipt.filesRead) || !strings(receipt.assumptions) || !strings(receipt.exclusions)) return false;
84
+ if (!Array.isArray(roleChecks) || !roleChecks.every((check) => record(check) && nonempty(check.role) && check.ok === true && nonempty(check.detail))) return false;
85
+ const checkedRoles = new Set(roleChecks.map((check) => check.role));
86
+ if (checkedRoles.size !== roleChecks.length || !checkedRoles.has("anon") || !checkedRoles.has("authenticated")) return false;
87
+ if (!record(summary) || !Array.isArray(tables) || tables.length === 0) return false;
88
+ const counts = { pass: 0, fail: 0, unknown: 0, notApplicable: 0, tested: 0, total: 0 };
89
+ const tableNames = /* @__PURE__ */ new Set();
90
+ for (const table of tables) {
91
+ if (!record(table) || !nonempty(table.name) || tableNames.has(table.name) || !Array.isArray(table.cells) || table.cells.length === 0) return false;
92
+ tableNames.add(table.name);
93
+ const cells = /* @__PURE__ */ new Set();
94
+ let observed = false;
95
+ for (const cell of table.cells) {
96
+ if (!record(cell) || cell.table !== table.name || ![...actors, "service_role"].includes(cell.actor) || ![...actions, "reassign"].includes(cell.action)) return false;
97
+ const key = `${cell.actor}:${cell.action}`;
98
+ if (cells.has(key) || !record(cell.observed) || !nonempty(cell.observed.summary) || !nonempty(cell.reason)) return false;
99
+ cells.add(key);
100
+ if (cell.actor === "service_role") {
101
+ if (!actions.includes(cell.action) || cell.expected !== "excluded" || cell.outcome !== "N/A") return false;
102
+ } else if (cell.expected === "skip") {
103
+ if (cell.outcome !== "N/A") return false;
104
+ } else if (!["allow", "deny"].includes(cell.expected) || !["Pass", "Fail", "Unknown"].includes(cell.outcome)) return false;
105
+ if (cell.outcome === "Pass") {
106
+ counts.pass += 1;
107
+ observed = true;
108
+ } else if (cell.outcome === "Fail") {
109
+ counts.fail += 1;
110
+ observed = true;
111
+ } else if (cell.outcome === "Unknown") counts.unknown += 1;
112
+ else if (cell.outcome === "N/A") counts.notApplicable += 1;
113
+ else return false;
114
+ counts.total += 1;
115
+ }
116
+ if (actors.some((actor) => actions.some((action) => !cells.has(`${actor}:${action}`)))) return false;
117
+ if (actions.some((action) => cells.has(`service_role:${action}`)) && actions.some((action) => !cells.has(`service_role:${action}`))) return false;
118
+ if (observed || table.rls !== void 0) {
119
+ if (!record(table.rls) || typeof table.rls.enabled !== "boolean" || typeof table.rls.forced !== "boolean" || !nonempty(table.rls.owner)) return false;
120
+ if (!checkedRoles.has(`anon on ${table.name}`) || !checkedRoles.has(`authenticated on ${table.name}`)) return false;
121
+ }
122
+ }
123
+ counts.tested = counts.total - counts.notApplicable;
124
+ if (Object.entries(counts).some(([key, value]) => !Number.isSafeInteger(summary[key]) || summary[key] !== value)) return false;
125
+ const exitCode = counts.fail > 0 ? 1 : counts.pass === 0 || counts.unknown > 0 ? 2 : 0;
126
+ if (processExit !== exitCode) return false;
127
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
128
+ const verdict = counts.fail > 0 ? `Not ready within tested scope: ${plural(counts.fail, "cell does", "cells do")} not match the matrix; ${plural(counts.unknown, "unknown")}.` : counts.pass === 0 ? `Nothing was observed: ${plural(counts.unknown, "unknown")}, ${counts.notApplicable} N/A.` : counts.unknown > 0 ? `No blockers found within tested scope; ${plural(counts.unknown, "unknown")}.` : "No blockers found within tested scope; 0 unknowns. Scenario passed locally.";
129
+ return receipt.verdict === verdict;
130
+ }
131
+ function classifyRlsToolResult(stdout, exitCode, transportError = false) {
132
+ let receipt;
133
+ try {
134
+ receipt = JSON.parse(stdout);
135
+ } catch {
136
+ return { isError: true };
137
+ }
138
+ if (!record(receipt)) return { isError: true };
139
+ return { isError: transportError || !completedReceipt(receipt, exitCode), structuredContent: receipt };
140
+ }
141
+ function buildRlsToolResponse(run) {
142
+ const classified = classifyRlsToolResult(run.stdout, run.exitCode, run.transportError);
143
+ const text = !classified.isError && classified.structuredContent ? `exit ${run.exitCode}
144
+ ${JSON.stringify(classified.structuredContent)}${run.stderr ? `
145
+ ${run.stderr}` : ""}`.trim() : run.text;
146
+ return { content: [{ type: "text", text }], ...classified };
147
+ }
148
+
33
149
  // ../../shared/liveTools.ts
34
150
  var cwd = { type: "string", description: "Local project directory. Defaults to the MCP working directory." };
35
151
  var stepId = { type: "string", format: "uuid", description: "The stepId returned by live_start; preserve it through sign-in, payment and retries." };
@@ -963,7 +1079,7 @@ function runWorkReportProcess(entry, args, cwd3, spawnFn2) {
963
1079
  } catch {
964
1080
  return Promise.resolve(workReportFailure());
965
1081
  }
966
- return new Promise((resolve) => {
1082
+ return new Promise((resolve2) => {
967
1083
  let settled = false, stdoutBytes = 0, stderrBytes = 0;
968
1084
  const chunks = [];
969
1085
  let child;
@@ -971,7 +1087,7 @@ function runWorkReportProcess(entry, args, cwd3, spawnFn2) {
971
1087
  if (!settled) {
972
1088
  settled = true;
973
1089
  clearTimeout(timer);
974
- resolve(result);
1090
+ resolve2(result);
975
1091
  }
976
1092
  };
977
1093
  const fail = () => {
@@ -1020,27 +1136,34 @@ var within = (root, target) => {
1020
1136
  const rel = (0, import_node_path.relative)(root, target);
1021
1137
  return !rel || !(0, import_node_path.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(`..${import_node_path.sep}`);
1022
1138
  };
1023
- function installedReportCli(version, cwd3) {
1139
+ function resolveInstalledCli(version, cwd3) {
1024
1140
  const override = process.env.VIBERAVEN_CLI_PATH;
1025
- if (override !== void 0 && !(0, import_node_path.isAbsolute)(override)) throw new Error("Unavailable installed CLI");
1026
- const selected = override ?? (0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_module.createRequire)(__filename).resolve("@viberaven/cli/package.json")), "dist", "cli.js");
1027
- const info = (0, import_node_fs2.lstatSync)(selected);
1028
- if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unavailable installed CLI");
1029
- const entry = (0, import_node_fs2.realpathSync)(selected);
1030
- const root = (0, import_node_fs2.realpathSync)((0, import_node_path.join)((0, import_node_path.dirname)(entry), ".."));
1031
- if (entry !== (0, import_node_path.join)(root, "dist", "cli.js") || within(cwd3, entry)) throw new Error("Unavailable installed CLI");
1032
- const manifestPath = (0, import_node_path.join)(root, "package.json"), manifestInfo = (0, import_node_fs2.lstatSync)(manifestPath);
1033
- if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink() || manifestInfo.size > 65536 || (0, import_node_fs2.realpathSync)(manifestPath) !== manifestPath) throw new Error("Unavailable installed CLI");
1034
- const manifest = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
1035
- if (manifest.name !== "@viberaven/cli" || manifest.version !== version) throw new Error("Unavailable installed CLI");
1036
- return entry;
1141
+ try {
1142
+ if (override !== void 0 && !(0, import_node_path.isAbsolute)(override)) throw new Error("Unavailable installed CLI");
1143
+ const selected = override ?? (0, import_node_path.join)((0, import_node_path.dirname)((0, import_node_module.createRequire)(__filename).resolve("@viberaven/cli/package.json")), "dist", "cli.js");
1144
+ const info = (0, import_node_fs2.lstatSync)(selected);
1145
+ if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unavailable installed CLI");
1146
+ const entry = (0, import_node_fs2.realpathSync)(selected);
1147
+ const root = (0, import_node_fs2.realpathSync)((0, import_node_path.join)((0, import_node_path.dirname)(entry), ".."));
1148
+ if (entry !== (0, import_node_path.resolve)(selected) || entry !== (0, import_node_path.join)(root, "dist", "cli.js") || within((0, import_node_fs2.realpathSync)(cwd3), entry)) throw new Error("Unavailable installed CLI");
1149
+ const manifestPath = (0, import_node_path.join)(root, "package.json"), manifestInfo = (0, import_node_fs2.lstatSync)(manifestPath);
1150
+ if (!manifestInfo.isFile() || manifestInfo.isSymbolicLink() || manifestInfo.size > 65536 || (0, import_node_fs2.realpathSync)(manifestPath) !== manifestPath) throw new Error("Unavailable installed CLI");
1151
+ const manifest = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
1152
+ if (manifest.name !== "@viberaven/cli" || manifest.version !== version) throw new Error("Unavailable installed CLI");
1153
+ return entry;
1154
+ } catch {
1155
+ if (override !== void 0) throw new Error("Matching installed CLI unavailable. Check VIBERAVEN_CLI_PATH, its exact version and installation outside the task repository.");
1156
+ return void 0;
1157
+ }
1037
1158
  }
1038
1159
  function runInstalledWorkReport(args, cwd3, version, spawnFn2) {
1039
1160
  let entry, canonicalCwd;
1040
1161
  try {
1041
1162
  if (cwd3 !== void 0 && (typeof cwd3 !== "string" || !cwd3.trim())) return Promise.resolve(workReportFailure());
1042
1163
  canonicalCwd = (0, import_node_fs2.realpathSync)(cwd3 === void 0 ? process.cwd() : cwd3);
1043
- entry = installedReportCli(version, canonicalCwd);
1164
+ const installed = resolveInstalledCli(version, canonicalCwd);
1165
+ if (!installed) return Promise.resolve(workReportFailure());
1166
+ entry = installed;
1044
1167
  } catch {
1045
1168
  return Promise.resolve(workReportFailure());
1046
1169
  }
@@ -1062,7 +1185,7 @@ function mcpVersion() {
1062
1185
  } catch {
1063
1186
  }
1064
1187
  }
1065
- found ??= true ? "1.7.0" : void 0;
1188
+ found ??= true ? "1.7.1" : void 0;
1066
1189
  if (!found || !PLAIN_VERSION.test(found)) {
1067
1190
  throw new Error(`Could not read a valid ${MCP_PACKAGE} version (got ${JSON.stringify(found)}), so the matching ${CLI_PACKAGE} cannot be pinned.`);
1068
1191
  }
@@ -1119,6 +1242,7 @@ function buildHealArgs(prefix, args) {
1119
1242
  return cliArgs;
1120
1243
  }
1121
1244
  function buildToolArgs(name, args) {
1245
+ if (name === RLS_TOOL_NAME) return buildRlsToolArgs(args);
1122
1246
  if (isLiveTool(name)) return buildLiveToolArgs(name, args);
1123
1247
  if (isWorkTool(name)) return buildWorkToolArgs(name, args);
1124
1248
  switch (name) {
@@ -1168,6 +1292,9 @@ function buildToolArgs(name, args) {
1168
1292
  throw new Error(`Unknown VibeRaven tool: ${name}`);
1169
1293
  }
1170
1294
  }
1295
+ function transportFailure(error, stderr = "") {
1296
+ return { stdout: "", stderr, exitCode: 1, transportError: true, text: `ERROR: ${error instanceof Error ? error.message : String(error)}` };
1297
+ }
1171
1298
  async function runVibeRaven(args, cwd3) {
1172
1299
  return (await runVibeRavenDetailed(args, cwd3)).text;
1173
1300
  }
@@ -1179,32 +1306,87 @@ function runVibeRavenDetailed(args, cwd3) {
1179
1306
  return Promise.resolve(workReportFailure());
1180
1307
  }
1181
1308
  }
1182
- let npxArgs;
1309
+ let built;
1310
+ let childCwd, env;
1183
1311
  try {
1184
- npxArgs = cliNpxArgs(args);
1312
+ childCwd = resolveCwd(cwd3);
1313
+ const installed = resolveInstalledCli(mcpVersion(), childCwd);
1314
+ if (args[0] === "rls-test" && !installed) return Promise.resolve(transportFailure(new Error("RLS testing requires a matching installed CLI outside the task repository, with optional PGlite installed next to it. Configure the local MCP host installation or VIBERAVEN_CLI_PATH; this tool does not download or install dependencies.")));
1315
+ built = installed ? { command: process.execPath, args: [installed, ...args], shell: false } : buildNpxCommand(cliNpxArgs(args));
1316
+ env = installed ? Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^(?:node_|npm_)/i.test(key) && key.toLowerCase() !== "viberaven_cli_path")) : cliChildEnv();
1185
1317
  } catch (error) {
1186
- return Promise.resolve({ stdout: "", stderr: "", exitCode: 1, text: `ERROR: ${error instanceof Error ? error.message : String(error)}` });
1318
+ return Promise.resolve(transportFailure(error));
1187
1319
  }
1188
- return new Promise((resolve) => {
1189
- const built = buildNpxCommand(npxArgs);
1190
- const child = spawnFn(built.command, built.args, {
1191
- cwd: resolveCwd(cwd3),
1192
- env: cliChildEnv(),
1193
- shell: built.shell,
1194
- stdio: ["ignore", "pipe", "pipe"]
1195
- });
1320
+ return new Promise((resolve2) => {
1321
+ let child;
1322
+ try {
1323
+ child = spawnFn(built.command, built.args, {
1324
+ cwd: childCwd,
1325
+ env,
1326
+ shell: built.shell,
1327
+ windowsHide: true,
1328
+ stdio: ["ignore", "pipe", "pipe"]
1329
+ });
1330
+ } catch (error) {
1331
+ resolve2(transportFailure(error));
1332
+ return;
1333
+ }
1196
1334
  let stdout = "";
1197
1335
  let stderr = "";
1198
- child.stdout?.on("data", (chunk) => {
1199
- stdout += chunk.toString();
1200
- });
1201
- child.stderr?.on("data", (chunk) => {
1202
- stderr += chunk.toString();
1203
- });
1204
- child.on("error", (error) => resolve({ stdout: "", stderr, exitCode: 1, text: `ERROR: ${error.message}` }));
1336
+ const boundedRls = args[0] === "rls-test";
1337
+ const rlsChunks = { stdout: [], stderr: [] };
1338
+ let outputBytes = 0;
1339
+ let settled = false;
1340
+ let timer;
1341
+ const finish = (result) => {
1342
+ if (settled) return;
1343
+ settled = true;
1344
+ if (timer) clearTimeout(timer);
1345
+ resolve2(result);
1346
+ };
1347
+ const stopRls = (reason) => {
1348
+ finish(transportFailure(new Error(reason)));
1349
+ try {
1350
+ child.kill("SIGKILL");
1351
+ } catch {
1352
+ }
1353
+ };
1354
+ if (boundedRls) timer = setTimeout(() => stopRls("RLS test exceeded its 300-second aggregate time limit and was stopped; no partial result is reported as passed."), RLS_RUN_TIMEOUT_MS);
1355
+ const collect = (chunk, stream) => {
1356
+ if (settled) return;
1357
+ outputBytes += Buffer.byteLength(chunk);
1358
+ if (boundedRls && outputBytes > RLS_MAX_OUTPUT_BYTES) {
1359
+ stopRls("RLS test exceeded its combined output limit and was stopped; no partial result is reported as passed.");
1360
+ return;
1361
+ }
1362
+ if (boundedRls) {
1363
+ rlsChunks[stream].push(Buffer.from(chunk));
1364
+ return;
1365
+ }
1366
+ if (stream === "stdout") stdout += chunk.toString();
1367
+ else stderr += chunk.toString();
1368
+ };
1369
+ child.stdout?.on("data", (chunk) => collect(chunk, "stdout"));
1370
+ child.stderr?.on("data", (chunk) => collect(chunk, "stderr"));
1371
+ child.on("error", (error) => finish(transportFailure(error, boundedRls ? "" : stderr)));
1205
1372
  child.on("close", (code) => {
1373
+ if (settled) return;
1374
+ if (code === null) {
1375
+ finish(transportFailure(new Error("CLI process ended without an exit code"), boundedRls ? "" : stderr));
1376
+ return;
1377
+ }
1378
+ if (boundedRls) {
1379
+ try {
1380
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
1381
+ stdout = decoder.decode(Buffer.concat(rlsChunks.stdout));
1382
+ stderr = decoder.decode(Buffer.concat(rlsChunks.stderr));
1383
+ } catch {
1384
+ finish(transportFailure(new Error("RLS test returned invalid UTF-8; no partial result is reported as passed.")));
1385
+ return;
1386
+ }
1387
+ }
1206
1388
  const combined = `${stdout}${stderr}`.trim();
1207
- resolve({ stdout, stderr, exitCode: code ?? 1, text: `exit ${code ?? 1}${combined ? `
1389
+ finish({ stdout, stderr, exitCode: code ?? 1, text: `exit ${code ?? 1}${combined ? `
1208
1390
  ${combined}` : ""}` });
1209
1391
  });
1210
1392
  });
@@ -1212,8 +1394,10 @@ ${combined}` : ""}` });
1212
1394
 
1213
1395
  // src/tools/index.ts
1214
1396
  var [checkReadiness, verify, strictGate, gateResult, contextMap] = readinessTools;
1397
+ var SEMANTIC_FINDING_TOOLS = /* @__PURE__ */ new Set(["viberaven_check_readiness", "viberaven_verify", "viberaven_audit", "viberaven_strict_gate", "viberaven_gate_result"]);
1215
1398
  var ALL_TOOLS = [
1216
1399
  checkReadiness,
1400
+ RLS_TOOL,
1217
1401
  verify,
1218
1402
  ...auditTools,
1219
1403
  ...rulesTools,
@@ -1236,6 +1420,18 @@ function parseJsonObjectFromToolText(text) {
1236
1420
  return void 0;
1237
1421
  }
1238
1422
  }
1423
+ function isCompletedNegativeNpmVerdict(receipt) {
1424
+ if (!receipt || "error" in receipt) return false;
1425
+ const results = "results" in receipt ? receipt.results : [receipt];
1426
+ try {
1427
+ return Array.isArray(results) && results.length > 0 && results.every((item) => {
1428
+ if (!item || typeof item !== "object" || Array.isArray(item) || "error" in item) return false;
1429
+ return typeof item.name === "string" && Boolean(item.name.trim()) && ["ok", "not_found", "suspicious"].includes(item.verdict) && Array.isArray(item.reasons) && item.reasons.length > 0 && item.reasons.every((reason) => typeof reason === "string" && Boolean(reason.trim())) && item.registryUrl === `https://registry.npmjs.org/${encodeURIComponent(item.name)}` && typeof item.followUpCommand === "string" && Boolean(item.followUpCommand.trim());
1430
+ }) && results.some((item) => item.verdict !== "ok");
1431
+ } catch {
1432
+ return false;
1433
+ }
1434
+ }
1239
1435
  async function callTool(name, args) {
1240
1436
  if (name === "provider_playbook") return providerPlaybook(args).content[0].text;
1241
1437
  return runVibeRaven(buildToolArgs(name, args || {}), args?.cwd);
@@ -1245,11 +1441,20 @@ async function handleRequest(method, params) {
1245
1441
  if (method === "tools/call") {
1246
1442
  if (params.name === "provider_playbook") return providerPlaybook(params.arguments);
1247
1443
  const args = params.arguments || {};
1248
- const { text, stdout, exitCode } = await runVibeRavenDetailed(buildToolArgs(params.name, args), args.cwd);
1444
+ const cliArgs = buildToolArgs(params.name, args);
1445
+ const run = await runVibeRavenDetailed(cliArgs, args.cwd);
1446
+ if (params.name === RLS_TOOL_NAME) return buildRlsToolResponse(run);
1447
+ const { text, stdout, exitCode, transportError } = run;
1249
1448
  const parsed = parseJsonObjectFromToolText(stdout);
1449
+ const receipt = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
1450
+ const approvalRefusal = params.name === "viberaven_heal_apply" && receipt?.status === "refused_dangerous";
1451
+ const textAuditFinding = params.name === "viberaven_audit" && !cliArgs.includes("--json") && !transportError && /^VibeRaven Vercel\/Supabase audit\r?\nStatus: needs_work\r?\n/.test(stdout) && /^NEEDS_WORK [a-z][a-z0-9-]*\r?$/m.test(stdout);
1452
+ const semanticFinding = exitCode === 1 && (textAuditFinding || receipt && !receipt.error && (SEMANTIC_FINDING_TOOLS.has(params.name) || approvalRefusal));
1453
+ const npmFinding = params.name === "viberaven_validate_npm_package" && exitCode === 2 && !transportError && isCompletedNegativeNpmVerdict(receipt);
1454
+ const isError = transportError || cliArgs.includes("--json") && !receipt || Boolean(receipt?.error) || exitCode !== 0 && !semanticFinding && !npmFinding || isLiveTool(params.name) && isLiveToolFailure(exitCode, parsed);
1250
1455
  return {
1251
1456
  content: [{ type: "text", text }],
1252
- ...params.name.startsWith("viberaven_work_") && exitCode !== 0 || isLiveTool(params.name) && isLiveToolFailure(exitCode, parsed) ? { isError: true } : {},
1457
+ ...isError ? { isError: true } : {},
1253
1458
  ...parsed ? { structuredContent: parsed } : {}
1254
1459
  };
1255
1460
  }
package/package.json CHANGED
@@ -1,70 +1,70 @@
1
- {
2
- "name": "@viberaven/mcp",
3
- "version": "1.7.0",
4
- "description": "MCP server for VibeRaven: lets Claude Code, Cursor and Codex run the Supabase RLS and security check on an AI-built Vercel + Supabase app and read the findings.",
5
- "license": "MIT",
6
- "author": "VibeRaven",
7
- "mcpName": "io.github.ohad6k/viberaven",
8
- "homepage": "https://viberaven.dev/mcp.md",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/ohad6k/VibeRaven.git",
12
- "directory": "packages/mcp"
13
- },
14
- "bugs": {
15
- "url": "https://github.com/ohad6k/VibeRaven/issues"
16
- },
17
- "keywords": [
18
- "viberaven",
19
- "mcp",
20
- "claude-code",
21
- "codex",
22
- "cursor",
23
- "launch-readiness",
24
- "production",
25
- "supabase-rls",
26
- "row-level-security",
27
- "rls",
28
- "supabase-security",
29
- "security-scanner",
30
- "security",
31
- "lovable",
32
- "bolt",
33
- "secrets",
34
- "service-role-key",
35
- "stripe-webhook",
36
- "postgres",
37
- "migrations"
38
- ],
39
- "publishConfig": {
40
- "access": "public",
41
- "tag": "next"
42
- },
43
- "bin": {
44
- "viberaven-mcp": "dist/server.js"
45
- },
46
- "files": [
47
- "dist",
48
- "README.md"
49
- ],
50
- "engines": {
51
- "node": ">=20"
52
- },
53
- "scripts": {
54
- "build": "node scripts/build.mjs",
55
- "typecheck": "tsc -p tsconfig.json --noEmit",
56
- "presmoke": "npm run build",
57
- "smoke": "node scripts/smoke.mjs",
58
- "prepublishOnly": "npm run build && npm test",
59
- "pretest": "npm run build",
60
- "test": "vitest run"
61
- },
62
- "dependencies": {
63
- "@modelcontextprotocol/sdk": "^1.0.0"
64
- },
65
- "devDependencies": {
66
- "esbuild": "^0.25.0",
67
- "typescript": "^5.8.0",
68
- "vitest": "^3.2.0"
69
- }
70
- }
1
+ {
2
+ "name": "@viberaven/mcp",
3
+ "version": "1.7.1",
4
+ "description": "MCP server for VibeRaven: lets Claude Code, Cursor and Codex run the Supabase RLS and security check on an AI-built Vercel + Supabase app and read the findings.",
5
+ "license": "MIT",
6
+ "author": "VibeRaven",
7
+ "mcpName": "io.github.ohad6k/viberaven",
8
+ "homepage": "https://viberaven.dev/mcp.md",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/ohad6k/VibeRaven.git",
12
+ "directory": "packages/mcp"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/ohad6k/VibeRaven/issues"
16
+ },
17
+ "keywords": [
18
+ "viberaven",
19
+ "mcp",
20
+ "claude-code",
21
+ "codex",
22
+ "cursor",
23
+ "launch-readiness",
24
+ "production",
25
+ "supabase-rls",
26
+ "row-level-security",
27
+ "rls",
28
+ "supabase-security",
29
+ "security-scanner",
30
+ "security",
31
+ "lovable",
32
+ "bolt",
33
+ "secrets",
34
+ "service-role-key",
35
+ "stripe-webhook",
36
+ "postgres",
37
+ "migrations"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "tag": "next"
42
+ },
43
+ "bin": {
44
+ "viberaven-mcp": "dist/server.js"
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "README.md"
49
+ ],
50
+ "engines": {
51
+ "node": ">=20"
52
+ },
53
+ "scripts": {
54
+ "build": "node scripts/build.mjs",
55
+ "typecheck": "tsc -p tsconfig.json --noEmit",
56
+ "presmoke": "npm run build",
57
+ "smoke": "node scripts/smoke.mjs",
58
+ "prepublishOnly": "npm run build && npm test",
59
+ "pretest": "npm run build",
60
+ "test": "vitest run"
61
+ },
62
+ "dependencies": {
63
+ "@modelcontextprotocol/sdk": "^1.0.0"
64
+ },
65
+ "devDependencies": {
66
+ "esbuild": "^0.25.0",
67
+ "typescript": "^5.8.0",
68
+ "vitest": "^3.2.0"
69
+ }
70
+ }