@voidh4x0r/slopgate 0.1.11 → 0.1.14

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/CHANGELOG.md CHANGED
@@ -9,6 +9,42 @@ All notable changes to this project are documented here. The format follows [Kee
9
9
  - Go and Rust grammars.
10
10
  - VS Code diagnostics.
11
11
 
12
+ ## [0.1.14] - 2026-11-22
13
+
14
+ ### Fixed
15
+ - MCP `scan_path` resolves config for the requested target with the same nearest-config search as the CLI (package config wins, root config falls back). Configs are cached per resolved config root.
16
+ - MCP findings are reported relative to the MCP server root (`packages/app/app.py`), not relative to the scan target (`app.py`).
17
+ - MCP uses the target config’s `confidence` as the default when a call omits `confidence`.
18
+ - `findGitRoot` / `hasConfig` / `findConfigRoot` moved from `cli.ts` to `config.ts`, shared by CLI and MCP.
19
+
20
+ ### Changed
21
+ - 266 tests, including MCP package-vs-root config parity, root-relative paths, and target-confidence behavior.
22
+ - Benchmark unchanged at **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects, 0 high findings on 601 JavaScript files**; `staleLabels: []`, `unlabeledHigh: []`.
23
+
24
+ ## [0.1.13] - 2026-11-22
25
+
26
+ ### Added
27
+ - Per-package config discovery: `.slopgate.json` / `slopgate.config.json` is searched from the scan target upward to the git repository root, and the nearest config wins. `packages/app` uses its own package config; `src` without one falls back to the root config. Baselines remain shared at the repository root.
28
+ - `slopgate init <dir>` writes the config in `<dir>` and the workflow at the repository root, with the workflow command targeting `./<dir>`. Root `init` output is unchanged.
29
+ - `--verbose` shows the resolved config path, e.g. `packages/app/.slopgate.json`, not just the filename.
30
+
31
+ ### Changed
32
+ - Git-root discovery runs once per scan and is reused for config search, baseline root and output prefix.
33
+ - **Behavior change:** `init <subdir>` now writes the config in that subdirectory (0.1.12 wrote it at the repo root); this makes generated package configs actually apply. The workflow still lives at the root.
34
+ - 263 tests, including a monorepo package-vs-root config test, package config `init`, and the updated subdirectory init expectations.
35
+ - Benchmark unchanged at **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects, 0 high findings on 601 JavaScript files**; `staleLabels: []`, `unlabeledHigh: []`.
36
+
37
+ ## [0.1.12] - 2026-11-22
38
+
39
+ ### Fixed
40
+ - Baseline fingerprints are normalized to repository-relative paths, so one baseline written with `slopgate .`, `slopgate src` or `slopgate src/a.py` suppresses the same findings from any target.
41
+ - `slopgate init <subdirectory>` writes `.slopgate.json` and `.github/workflows/slopgate.yml` at the repository root, matching scan/config semantics; non-git targets keep the requested directory.
42
+
43
+ ### Changed
44
+ - **Migration:** baselines written by 0.1.11 while scanning a subdirectory contain target-relative keys and are no longer matched; recreate them from the root or with the current version. Baselines written from the repository root remain compatible.
45
+ - 261 tests, including mixed root/directory/file baseline reads and subdirectory `init`.
46
+ - Benchmark unchanged at **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects, 0 high findings on 601 JavaScript files**; `staleLabels: []`, `unlabeledHigh: []`.
47
+
12
48
  ## [0.1.11] - 2026-11-22
13
49
 
14
50
  ### Fixed
package/README.md CHANGED
@@ -14,7 +14,7 @@ AI writes code that *looks* right. `slopgate` finds the parts that only look rig
14
14
  ```console
15
15
  $ npx @voidh4x0r/slopgate .
16
16
 
17
- slopgate 0.1.11 · 4 files · 39ms
17
+ slopgate 0.1.14 · 4 files · 39ms
18
18
 
19
19
  app.py
20
20
  4:1 error high py/phantom-import `helper` is imported but not declared in any manifest and not present in this repository
@@ -128,7 +128,7 @@ slopgate [path] [options]
128
128
 
129
129
  ### Configuration
130
130
 
131
- `slopgate` reads `.slopgate.json` (or `slopgate.config.json`) from the **nearest git repository root** (falling back to the scan target’s directory outside git). Every key is optional:
131
+ `slopgate` reads `.slopgate.json` (or `slopgate.config.json`) by walking up from the scan target to the git repository root and using the **nearest** config. A package config such as `packages/app/.slopgate.json` overrides the root config; `src` with no config falls back to the root. Every key is optional:
132
132
 
133
133
  ```json
134
134
  {
@@ -151,11 +151,11 @@ slopgate [path] [options]
151
151
 
152
152
  For example, `{"include": ["src/**"]}` scans only files under `src/`; it does **not** keep the default Python/TS/JS coverage. Add the patterns you need, or use the CLI flag to append one pattern to the defaults.
153
153
 
154
- The default `.slopgate-baseline.json` also lives at the repository root. `--baseline` and `--write-baseline` paths resolve there, so scanning `src` and then the repository root share one baseline.
154
+ The default `.slopgate-baseline.json` also lives at the repository root. `--baseline` and `--write-baseline` paths resolve there, so scanning `src` and then the repository root share one baseline. Baseline fingerprints use the same repository-relative paths as reports, so one root baseline works for `slopgate .`, `slopgate src`, and `slopgate path/to/file.py`.
155
155
 
156
156
  Reported paths (including SARIF and GitHub annotations) are relative to the nearest git repository root. If the target is outside a git repository, paths stay relative to the scan target.
157
157
 
158
- `slopgate init` writes a minimal config plus a GitHub Actions workflow.
158
+ `slopgate init` writes a minimal config at the requested directory and a GitHub Actions workflow at the repository root; the workflow targets that directory. Run it at the repository root for a repo-wide config.
159
159
 
160
160
  ### Adopting it on an existing repository
161
161
 
@@ -190,7 +190,7 @@ npx @voidh4x0r/slopgate . --diff origin/main --fail-on high
190
190
  | `scan_path` | findings in a file or directory |
191
191
  | `list_rules` | the rule table, so the agent knows what is checked |
192
192
 
193
- Reports are compact text: `file:line:col severity confidence rule-id message`, evidence included, capped at 50 findings per call. The server reads `.slopgate.json` and `.slopgate-baseline.json` like the CLI does, so an agent never re-reports debt you already accepted. It runs locally, makes no network calls, and writes nothing to disk.
193
+ Reports are compact text: `file:line:col severity confidence rule-id message`, evidence included, capped at 50 findings per call. Paths are relative to the MCP server root, and config is resolved per requested path with the same nearest-config rule as the CLI. The server reads `.slopgate.json` and `.slopgate-baseline.json` like the CLI does, so an agent never re-reports debt you already accepted. It runs locally, makes no network calls, and writes nothing to disk.
194
194
 
195
195
  Full details: [docs/mcp.md](https://github.com/VoidH4x0r/slopgate/blob/main/docs/mcp.md).
196
196
 
@@ -210,7 +210,7 @@ jobs:
210
210
  - uses: actions/checkout@v4
211
211
  - uses: actions/setup-node@v4
212
212
  with: { node-version: 22 }
213
- - run: npx --yes @voidh4x0r/slopgate@0.1.11 . --fail-on high
213
+ - run: npx --yes @voidh4x0r/slopgate@0.1.14 . --fail-on high
214
214
  ```
215
215
 
216
216
  For GitHub code scanning, use `--format sarif` and upload with `github/codeql-action/upload-sarif`.
@@ -218,7 +218,7 @@ For GitHub code scanning, use `--format sarif` and upload with `github/codeql-ac
218
218
  For inline pull-request annotations **without** code scanning, use `--format github`, which emits [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions):
219
219
 
220
220
  ```yaml
221
- - run: npx --yes @voidh4x0r/slopgate@0.1.11 . --format github --fail-on high
221
+ - run: npx --yes @voidh4x0r/slopgate@0.1.14 . --format github --fail-on high
222
222
  ```
223
223
 
224
224
  Each finding becomes an `error` / `warning` / `notice` annotation on the exact line, followed by a summary notice.
@@ -303,7 +303,7 @@ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://githu
303
303
  git clone https://github.com/VoidH4x0r/slopgate
304
304
  cd slopgate
305
305
  npm install
306
- npm test # 259 tests; the tests themselves make no network or child-process calls
306
+ npm test # 266 tests; the tests themselves make no network or child-process calls
307
307
  npm run typecheck
308
308
  npm run verify # all release gates in one command
309
309
  ```
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import * as path from 'node:path';
4
4
  import process from 'node:process';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { loadBaseline, partitionByBaseline, writeBaseline } from "./baseline.js";
7
- import { confidenceRank, loadConfig, meetsConfidence } from "./config.js";
7
+ import { confidenceRank, findConfigRoot, findGitRoot, loadConfig, meetsConfidence, } from "./config.js";
8
8
  import { assertSafeRef, diffSince, findRepoRoot, isInDiffWithPrefix } from "./diff.js";
9
9
  import { scanProject } from "./engine.js";
10
10
  import { serveMcp } from "./mcp.js";
@@ -216,26 +216,6 @@ function warn(io, options, message) {
216
216
  if (!options.quiet)
217
217
  io.err(`slopgate: ${message}\n`);
218
218
  }
219
- /**
220
- * Nearest ancestor containing `.git`, without spawning git. A `.git` file
221
- * (worktree/submodule) counts as a repository marker too.
222
- */
223
- async function findGitRoot(start) {
224
- let dir = path.resolve(start);
225
- for (;;) {
226
- try {
227
- await stat(path.join(dir, '.git'));
228
- return dir;
229
- }
230
- catch {
231
- // keep walking towards the filesystem root
232
- }
233
- const parent = path.dirname(dir);
234
- if (parent === dir)
235
- return undefined;
236
- dir = parent;
237
- }
238
- }
239
219
  async function runRules(options, io) {
240
220
  const rows = ALL_RULES.map((rule) => ({
241
221
  id: rule.meta.id,
@@ -285,7 +265,7 @@ const INIT_CONFIG = {
285
265
  confidence: 'high',
286
266
  failOn: 'high',
287
267
  };
288
- const INIT_WORKFLOW = (version) => `name: slopgate
268
+ const INIT_WORKFLOW = (version, target) => `name: slopgate
289
269
 
290
270
  on:
291
271
  push:
@@ -305,13 +285,20 @@ jobs:
305
285
  with:
306
286
  node-version: 22
307
287
  - name: Scan for AI slop
308
- run: npx --yes @voidh4x0r/slopgate@${version} . --fail-on high --format pretty
288
+ run: npx --yes @voidh4x0r/slopgate@${version} ${target} --fail-on high --format pretty
309
289
  `;
310
290
  async function runInit(options, io, version) {
311
- const root = path.resolve(options.paths[0] ?? '.');
312
- await mkdir(root, { recursive: true });
313
- const configPath = path.join(root, '.slopgate.json');
314
- const workflowPath = path.join(root, '.github', 'workflows', 'slopgate.yml');
291
+ const requested = path.resolve(options.paths[0] ?? '.');
292
+ // Find the repo root before creating a directory, so `init newdir` does not
293
+ // leave an empty directory when the config belongs at the root.
294
+ const repoRoot = await findGitRoot(requested);
295
+ await mkdir(requested, { recursive: true });
296
+ const workflowRoot = repoRoot ?? requested;
297
+ const relativeTarget = path.relative(workflowRoot, requested).replace(/\\/g, '/');
298
+ const rawTarget = relativeTarget.length > 0 ? `./${relativeTarget}` : '.';
299
+ const workflowTarget = /\s/.test(rawTarget) ? `"${rawTarget}"` : rawTarget;
300
+ const configPath = path.join(requested, '.slopgate.json');
301
+ const workflowPath = path.join(workflowRoot, '.github', 'workflows', 'slopgate.yml');
315
302
  if (!options.force && (await exists(configPath))) {
316
303
  warn(io, options, `${path.relative(process.cwd(), configPath)} already exists (use --force to overwrite)`);
317
304
  }
@@ -324,10 +311,10 @@ async function runInit(options, io, version) {
324
311
  }
325
312
  else {
326
313
  await mkdir(path.dirname(workflowPath), { recursive: true });
327
- await writeFile(workflowPath, INIT_WORKFLOW(version), 'utf8');
314
+ await writeFile(workflowPath, INIT_WORKFLOW(version, workflowTarget), 'utf8');
328
315
  writeOut(io, `created ${path.relative(process.cwd(), workflowPath)}`);
329
316
  }
330
- writeOut(io, 'next: npx @voidh4x0r/slopgate . --write-baseline, then commit the baseline');
317
+ writeOut(io, `next: npx @voidh4x0r/slopgate ${workflowTarget} --write-baseline, then commit the baseline`);
331
318
  return 0;
332
319
  }
333
320
  async function runMcp(options) {
@@ -349,9 +336,8 @@ async function runScan(options, io) {
349
336
  throw new Error(`path not found: ${target}`);
350
337
  }
351
338
  const projectRoot = targetInfo.isFile() ? path.dirname(target) : target;
352
- // Config and the default baseline belong to the repository, not to the
353
- // directory being scanned. Manifests stay target-scoped inside scanProject.
354
- const configRoot = (await findGitRoot(projectRoot)) ?? projectRoot;
339
+ const repoRoot = await findGitRoot(projectRoot);
340
+ const configRoot = await findConfigRoot(projectRoot, repoRoot);
355
341
  const { config, file: configFile } = await loadConfig(configRoot);
356
342
  if (options.rules.length > 0) {
357
343
  const unknown = options.rules.filter((id) => !RULE_BY_ID.has(id));
@@ -382,13 +368,27 @@ async function runScan(options, io) {
382
368
  if (result.stats.files === 0) {
383
369
  throw new Error(`no files matched under ${path.relative(process.cwd(), target) || '.'} (check include/exclude patterns)`);
384
370
  }
385
- const baselinePath = path.resolve(configRoot, options.baseline ?? DEFAULT_BASELINE);
371
+ const scanBase = projectRoot;
372
+ let outputPrefix = '';
373
+ if (repoRoot) {
374
+ const relative = path.relative(repoRoot, scanBase);
375
+ if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
376
+ outputPrefix = relative.replace(/\\/g, '/');
377
+ }
378
+ }
379
+ const toRepoRelative = (items) => outputPrefix
380
+ ? items.map((finding) => ({ ...finding, file: `${outputPrefix}/${finding.file}` }))
381
+ : [...items];
382
+ const baselineRoot = repoRoot ?? projectRoot;
383
+ const baselinePath = path.resolve(baselineRoot, options.baseline ?? DEFAULT_BASELINE);
386
384
  const explicitWrite = options.writeBaseline;
387
385
  if (explicitWrite) {
388
- const writeTarget = path.resolve(configRoot, explicitWrite);
389
- // Record the current findings, not the diff-filtered subset.
390
- await writeBaseline(writeTarget, result.findings);
391
- writeOut(io, `wrote ${result.findings.length} findings to ${path.relative(process.cwd(), writeTarget)}`);
386
+ const writeTarget = path.resolve(baselineRoot, explicitWrite);
387
+ // Record the current findings, not the diff-filtered subset, with the same
388
+ // repo-relative keys used when reading the baseline.
389
+ const toRecord = toRepoRelative(result.findings);
390
+ await writeBaseline(writeTarget, toRecord);
391
+ writeOut(io, `wrote ${toRecord.length} findings to ${path.relative(process.cwd(), writeTarget)}`);
392
392
  return 0;
393
393
  }
394
394
  let findings = result.findings;
@@ -406,7 +406,10 @@ async function runScan(options, io) {
406
406
  if (baseline === undefined && options.baseline !== undefined) {
407
407
  throw new Error(`baseline file not found: ${baselinePath}`);
408
408
  }
409
- const { fresh, known } = partitionByBaseline(findings, baseline);
409
+ // Baseline fingerprints and report paths both use repo-relative paths, so
410
+ // one root baseline works for every scan target.
411
+ const normalizedFindings = toRepoRelative(findings);
412
+ const { fresh, known } = partitionByBaseline(normalizedFindings, baseline);
410
413
  // `--fail-on` below `--confidence` must lower the display threshold too,
411
414
  // otherwise the setting can never fail CI (the findings are filtered out).
412
415
  const displayConfidence = merged.failOn === 'none' || confidenceRank(merged.confidence) <= confidenceRank(merged.failOn)
@@ -414,23 +417,8 @@ async function runScan(options, io) {
414
417
  : merged.failOn;
415
418
  const visible = fresh.filter((finding) => meetsConfidence(finding.confidence, displayConfidence));
416
419
  const hidden = fresh.length - visible.length;
417
- // Reporters (SARIF, GitHub workflow commands) resolve paths from the repo
418
- // root, not from the scan target. Prefix output findings only: baseline
419
- // fingerprints and diff filtering keep using the raw target-relative paths.
420
- const scanBase = targetInfo.isFile() ? path.dirname(target) : target;
421
- const outputRoot = await findGitRoot(scanBase);
422
- let outputPrefix = '';
423
- if (outputRoot) {
424
- const relative = path.relative(outputRoot, scanBase);
425
- if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
426
- outputPrefix = relative.replace(/\\/g, '/');
427
- }
428
- }
429
- const outputVisible = outputPrefix
430
- ? visible.map((finding) => ({ ...finding, file: `${outputPrefix}/${finding.file}` }))
431
- : visible;
432
420
  const run = {
433
- visible: outputVisible,
421
+ visible,
434
422
  stats: result.stats,
435
423
  suppressed: result.suppressedCount,
436
424
  baselined: known.length,
@@ -440,7 +428,7 @@ async function runScan(options, io) {
440
428
  const version = await readVersion();
441
429
  if (options.format === 'json') {
442
430
  writeOut(io, renderJson({
443
- findings: outputVisible,
431
+ findings: visible,
444
432
  stats: run.stats,
445
433
  version,
446
434
  suppressedByComment: run.suppressed,
@@ -449,14 +437,14 @@ async function runScan(options, io) {
449
437
  }));
450
438
  }
451
439
  else if (options.format === 'sarif') {
452
- writeOut(io, renderSarif(outputVisible, version));
440
+ writeOut(io, renderSarif(visible, version));
453
441
  }
454
442
  else if (options.format === 'github') {
455
- writeOut(io, renderGithub(outputVisible, run.stats));
443
+ writeOut(io, renderGithub(visible, run.stats));
456
444
  }
457
445
  else {
458
446
  writeOut(io, renderPretty({
459
- findings: outputVisible,
447
+ findings: visible,
460
448
  stats: run.stats,
461
449
  suppressedByComment: run.suppressed,
462
450
  baselined: run.baselined,
@@ -466,7 +454,10 @@ async function runScan(options, io) {
466
454
  quiet: options.quiet,
467
455
  }));
468
456
  if (options.verbose) {
469
- writeOut(io, ` config: ${configFile ?? '(none)'} include: ${merged.include.length} pattern(s) baseline: ${baseline ? path.relative(process.cwd(), baselinePath) : '(none)'}` +
457
+ const configLabel = configFile
458
+ ? path.relative(process.cwd(), path.join(configRoot, configFile))
459
+ : '(none)';
460
+ writeOut(io, ` config: ${configLabel} include: ${merged.include.length} pattern(s) baseline: ${baseline ? path.relative(process.cwd(), baselinePath) : '(none)'}` +
470
461
  (onlyDiff > 0 ? ` diff-only: ${onlyDiff} finding(s) outside the diff were ignored` : '') +
471
462
  '\n');
472
463
  }
package/dist/config.d.ts CHANGED
@@ -17,6 +17,14 @@ export interface LoadedConfig {
17
17
  file: string | undefined;
18
18
  }
19
19
  export declare const CONFIG_FILENAMES: readonly [".slopgate.json", "slopgate.config.json"];
20
+ /** Nearest ancestor containing `.git`, without spawning git. */
21
+ export declare function findGitRoot(start: string): Promise<string | undefined>;
22
+ export declare function hasConfig(dir: string): Promise<boolean>;
23
+ /**
24
+ * Nearest config wins: target → ancestors → repository root. Outside git,
25
+ * only the target directory is considered.
26
+ */
27
+ export declare function findConfigRoot(start: string, repoRoot: string | undefined): Promise<string>;
20
28
  export declare const DEFAULT_CONFIG: Config;
21
29
  export declare function confidenceRank(c: Confidence): number;
22
30
  export declare function meetsConfidence(value: Confidence, minimum: Confidence): boolean;
package/dist/config.js CHANGED
@@ -1,7 +1,54 @@
1
- import { readFile } from 'node:fs/promises';
1
+ import { readFile, stat } from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
3
  import { DEFAULT_INCLUDE } from "./files.js";
4
4
  export const CONFIG_FILENAMES = ['.slopgate.json', 'slopgate.config.json'];
5
+ /** Nearest ancestor containing `.git`, without spawning git. */
6
+ export async function findGitRoot(start) {
7
+ let dir = path.resolve(start);
8
+ for (;;) {
9
+ try {
10
+ await stat(path.join(dir, '.git'));
11
+ return dir;
12
+ }
13
+ catch {
14
+ // keep walking towards the filesystem root
15
+ }
16
+ const parent = path.dirname(dir);
17
+ if (parent === dir)
18
+ return undefined;
19
+ dir = parent;
20
+ }
21
+ }
22
+ export async function hasConfig(dir) {
23
+ for (const name of CONFIG_FILENAMES) {
24
+ try {
25
+ await stat(path.join(dir, name));
26
+ return true;
27
+ }
28
+ catch {
29
+ // try the next config filename
30
+ }
31
+ }
32
+ return false;
33
+ }
34
+ /**
35
+ * Nearest config wins: target → ancestors → repository root. Outside git,
36
+ * only the target directory is considered.
37
+ */
38
+ export async function findConfigRoot(start, repoRoot) {
39
+ const target = path.resolve(start);
40
+ let dir = target;
41
+ for (;;) {
42
+ if (await hasConfig(dir))
43
+ return dir;
44
+ if (repoRoot === undefined || dir === repoRoot)
45
+ return repoRoot ?? target;
46
+ const parent = path.dirname(dir);
47
+ if (parent === dir)
48
+ return repoRoot;
49
+ dir = parent;
50
+ }
51
+ }
5
52
  export const DEFAULT_CONFIG = {
6
53
  include: [...DEFAULT_INCLUDE],
7
54
  exclude: [],
package/dist/mcp.d.ts CHANGED
@@ -28,6 +28,8 @@ export interface McpDeps {
28
28
  root: string;
29
29
  version: string;
30
30
  config: Config;
31
+ /** Resolve the nearest config for a scan target; falls back to `config`. */
32
+ configFor?: (root: string) => Promise<Config>;
31
33
  scan: (root: string) => Promise<ScanResult>;
32
34
  diff: (root: string, base: string) => Promise<DiffSet>;
33
35
  }
package/dist/mcp.js CHANGED
@@ -1,9 +1,9 @@
1
- import { realpath } from 'node:fs/promises';
1
+ import { realpath, stat } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import process from 'node:process';
4
4
  import { createInterface } from 'node:readline';
5
5
  import { loadBaseline, partitionByBaseline } from "./baseline.js";
6
- import { loadConfig, meetsConfidence } from "./config.js";
6
+ import { findConfigRoot, findGitRoot, loadConfig, meetsConfidence, } from "./config.js";
7
7
  import { diffSince, isInDiff } from "./diff.js";
8
8
  import { scanProject } from "./engine.js";
9
9
  import { ALL_RULES } from "./rules/index.js";
@@ -97,6 +97,12 @@ function formatFindings(findings, result, version, max, preamble) {
97
97
  }
98
98
  return lines.join('\n');
99
99
  }
100
+ function prefixForRoot(root, base) {
101
+ const relative = path.relative(root, base);
102
+ if (!relative || relative.startsWith('..') || path.isAbsolute(relative))
103
+ return '';
104
+ return relative.replace(/\\/g, '/');
105
+ }
100
106
  export function createMcpServer(deps) {
101
107
  async function callTool(name, params) {
102
108
  if (name === 'list_rules') {
@@ -106,8 +112,8 @@ export function createMcpServer(deps) {
106
112
  }
107
113
  return textResult(lines.join('\n'));
108
114
  }
109
- const confidence = coerceConfidence(params.confidence, deps.config.confidence);
110
115
  const max = coerceNumber(params.maxFindings, MAX_FINDINGS);
116
+ const configFor = deps.configFor ?? (async () => deps.config);
111
117
  if (name === 'scan_path') {
112
118
  const target = path.resolve(deps.root, typeof params.path === 'string' ? params.path : '.');
113
119
  if (!isInsideRoot(deps.root, target)) {
@@ -120,15 +126,25 @@ export function createMcpServer(deps) {
120
126
  if (!isInsideRoot(realRoot, realTarget)) {
121
127
  return textResult(`Refusing to scan outside the repository root: ${target}`, true);
122
128
  }
129
+ const targetConfig = await configFor(target);
130
+ const confidence = coerceConfidence(params.confidence, targetConfig.confidence);
123
131
  const result = await deps.scan(target);
124
132
  if (result.stats.files === 0) {
125
133
  return textResult(`No files matched under ${target} (check include/exclude patterns)`, true);
126
134
  }
127
135
  const visible = result.findings.filter((finding) => meetsConfidence(finding.confidence, confidence));
128
- return textResult(formatFindings(visible, result, deps.version, max));
136
+ const targetInfo = await stat(target).catch(() => undefined);
137
+ const base = targetInfo?.isFile() ? path.dirname(target) : target;
138
+ const prefix = prefixForRoot(deps.root, base);
139
+ const output = prefix
140
+ ? visible.map((finding) => ({ ...finding, file: `${prefix}/${finding.file}` }))
141
+ : visible;
142
+ return textResult(formatFindings(output, result, deps.version, max));
129
143
  }
130
144
  if (name === 'scan_diff') {
131
145
  const base = typeof params.base === 'string' && params.base.length > 0 ? params.base : 'HEAD';
146
+ const rootConfig = await configFor(deps.root);
147
+ const confidence = coerceConfidence(params.confidence, rootConfig.confidence);
132
148
  const result = await deps.scan(deps.root);
133
149
  if (result.stats.files === 0) {
134
150
  return textResult('No files matched in the repository (check include/exclude patterns)', true);
@@ -195,16 +211,24 @@ export function createMcpServer(deps) {
195
211
  };
196
212
  }
197
213
  export function defaultMcpDeps(root, version) {
198
- let configPromise;
199
- const getConfig = async () => {
200
- configPromise ??= loadConfig(root).then((loaded) => loaded.config);
201
- return configPromise;
214
+ const configCache = new Map();
215
+ const configFor = async (start) => {
216
+ const target = path.resolve(start);
217
+ const repoRoot = (await findGitRoot(target)) ?? root;
218
+ const configRoot = await findConfigRoot(target, repoRoot);
219
+ let pending = configCache.get(configRoot);
220
+ if (!pending) {
221
+ pending = loadConfig(configRoot).then((loaded) => loaded.config);
222
+ configCache.set(configRoot, pending);
223
+ }
224
+ return pending;
202
225
  };
203
226
  return {
204
227
  root,
205
228
  version,
229
+ configFor,
206
230
  async scan(scanRoot) {
207
- const config = await getConfig();
231
+ const config = await configFor(scanRoot);
208
232
  const result = await scanProject({ root: scanRoot, config });
209
233
  // Respect a baseline if one exists, so agents do not re-report known debt.
210
234
  const baseline = await loadBaseline(path.join(root, '.slopgate-baseline.json'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidh4x0r/slopgate",
3
- "version": "0.1.11",
3
+ "version": "0.1.14",
4
4
  "description": "The slop gate for AI-written code. Precision-first structural linting for Python and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "MIT",