@voidh4x0r/slopgate 0.1.11 → 0.1.13

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,30 @@ 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.13] - 2026-11-22
13
+
14
+ ### Added
15
+ - 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.
16
+ - `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.
17
+ - `--verbose` shows the resolved config path, e.g. `packages/app/.slopgate.json`, not just the filename.
18
+
19
+ ### Changed
20
+ - Git-root discovery runs once per scan and is reused for config search, baseline root and output prefix.
21
+ - **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.
22
+ - 263 tests, including a monorepo package-vs-root config test, package config `init`, and the updated subdirectory init expectations.
23
+ - 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: []`.
24
+
25
+ ## [0.1.12] - 2026-11-22
26
+
27
+ ### Fixed
28
+ - 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.
29
+ - `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.
30
+
31
+ ### Changed
32
+ - **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.
33
+ - 261 tests, including mixed root/directory/file baseline reads and subdirectory `init`.
34
+ - 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: []`.
35
+
12
36
  ## [0.1.11] - 2026-11-22
13
37
 
14
38
  ### 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.13 · 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
 
@@ -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.13 . --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.13 . --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 # 263 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 { CONFIG_FILENAMES, confidenceRank, 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";
@@ -236,6 +236,36 @@ async function findGitRoot(start) {
236
236
  dir = parent;
237
237
  }
238
238
  }
239
+ async function hasConfig(dir) {
240
+ for (const name of CONFIG_FILENAMES) {
241
+ try {
242
+ await stat(path.join(dir, name));
243
+ return true;
244
+ }
245
+ catch {
246
+ // try the next config filename
247
+ }
248
+ }
249
+ return false;
250
+ }
251
+ /**
252
+ * Nearest config wins: target → ancestors → repository root. Outside git,
253
+ * only the target directory is considered.
254
+ */
255
+ async function findConfigRoot(start, repoRoot) {
256
+ const target = path.resolve(start);
257
+ let dir = target;
258
+ for (;;) {
259
+ if (await hasConfig(dir))
260
+ return dir;
261
+ if (repoRoot === undefined || dir === repoRoot)
262
+ return repoRoot ?? target;
263
+ const parent = path.dirname(dir);
264
+ if (parent === dir)
265
+ return repoRoot;
266
+ dir = parent;
267
+ }
268
+ }
239
269
  async function runRules(options, io) {
240
270
  const rows = ALL_RULES.map((rule) => ({
241
271
  id: rule.meta.id,
@@ -285,7 +315,7 @@ const INIT_CONFIG = {
285
315
  confidence: 'high',
286
316
  failOn: 'high',
287
317
  };
288
- const INIT_WORKFLOW = (version) => `name: slopgate
318
+ const INIT_WORKFLOW = (version, target) => `name: slopgate
289
319
 
290
320
  on:
291
321
  push:
@@ -305,13 +335,20 @@ jobs:
305
335
  with:
306
336
  node-version: 22
307
337
  - name: Scan for AI slop
308
- run: npx --yes @voidh4x0r/slopgate@${version} . --fail-on high --format pretty
338
+ run: npx --yes @voidh4x0r/slopgate@${version} ${target} --fail-on high --format pretty
309
339
  `;
310
340
  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');
341
+ const requested = path.resolve(options.paths[0] ?? '.');
342
+ // Find the repo root before creating a directory, so `init newdir` does not
343
+ // leave an empty directory when the config belongs at the root.
344
+ const repoRoot = await findGitRoot(requested);
345
+ await mkdir(requested, { recursive: true });
346
+ const workflowRoot = repoRoot ?? requested;
347
+ const relativeTarget = path.relative(workflowRoot, requested).replace(/\\/g, '/');
348
+ const rawTarget = relativeTarget.length > 0 ? `./${relativeTarget}` : '.';
349
+ const workflowTarget = /\s/.test(rawTarget) ? `"${rawTarget}"` : rawTarget;
350
+ const configPath = path.join(requested, '.slopgate.json');
351
+ const workflowPath = path.join(workflowRoot, '.github', 'workflows', 'slopgate.yml');
315
352
  if (!options.force && (await exists(configPath))) {
316
353
  warn(io, options, `${path.relative(process.cwd(), configPath)} already exists (use --force to overwrite)`);
317
354
  }
@@ -324,10 +361,10 @@ async function runInit(options, io, version) {
324
361
  }
325
362
  else {
326
363
  await mkdir(path.dirname(workflowPath), { recursive: true });
327
- await writeFile(workflowPath, INIT_WORKFLOW(version), 'utf8');
364
+ await writeFile(workflowPath, INIT_WORKFLOW(version, workflowTarget), 'utf8');
328
365
  writeOut(io, `created ${path.relative(process.cwd(), workflowPath)}`);
329
366
  }
330
- writeOut(io, 'next: npx @voidh4x0r/slopgate . --write-baseline, then commit the baseline');
367
+ writeOut(io, `next: npx @voidh4x0r/slopgate ${workflowTarget} --write-baseline, then commit the baseline`);
331
368
  return 0;
332
369
  }
333
370
  async function runMcp(options) {
@@ -349,9 +386,8 @@ async function runScan(options, io) {
349
386
  throw new Error(`path not found: ${target}`);
350
387
  }
351
388
  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;
389
+ const repoRoot = await findGitRoot(projectRoot);
390
+ const configRoot = await findConfigRoot(projectRoot, repoRoot);
355
391
  const { config, file: configFile } = await loadConfig(configRoot);
356
392
  if (options.rules.length > 0) {
357
393
  const unknown = options.rules.filter((id) => !RULE_BY_ID.has(id));
@@ -382,13 +418,27 @@ async function runScan(options, io) {
382
418
  if (result.stats.files === 0) {
383
419
  throw new Error(`no files matched under ${path.relative(process.cwd(), target) || '.'} (check include/exclude patterns)`);
384
420
  }
385
- const baselinePath = path.resolve(configRoot, options.baseline ?? DEFAULT_BASELINE);
421
+ const scanBase = projectRoot;
422
+ let outputPrefix = '';
423
+ if (repoRoot) {
424
+ const relative = path.relative(repoRoot, scanBase);
425
+ if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
426
+ outputPrefix = relative.replace(/\\/g, '/');
427
+ }
428
+ }
429
+ const toRepoRelative = (items) => outputPrefix
430
+ ? items.map((finding) => ({ ...finding, file: `${outputPrefix}/${finding.file}` }))
431
+ : [...items];
432
+ const baselineRoot = repoRoot ?? projectRoot;
433
+ const baselinePath = path.resolve(baselineRoot, options.baseline ?? DEFAULT_BASELINE);
386
434
  const explicitWrite = options.writeBaseline;
387
435
  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)}`);
436
+ const writeTarget = path.resolve(baselineRoot, explicitWrite);
437
+ // Record the current findings, not the diff-filtered subset, with the same
438
+ // repo-relative keys used when reading the baseline.
439
+ const toRecord = toRepoRelative(result.findings);
440
+ await writeBaseline(writeTarget, toRecord);
441
+ writeOut(io, `wrote ${toRecord.length} findings to ${path.relative(process.cwd(), writeTarget)}`);
392
442
  return 0;
393
443
  }
394
444
  let findings = result.findings;
@@ -406,7 +456,10 @@ async function runScan(options, io) {
406
456
  if (baseline === undefined && options.baseline !== undefined) {
407
457
  throw new Error(`baseline file not found: ${baselinePath}`);
408
458
  }
409
- const { fresh, known } = partitionByBaseline(findings, baseline);
459
+ // Baseline fingerprints and report paths both use repo-relative paths, so
460
+ // one root baseline works for every scan target.
461
+ const normalizedFindings = toRepoRelative(findings);
462
+ const { fresh, known } = partitionByBaseline(normalizedFindings, baseline);
410
463
  // `--fail-on` below `--confidence` must lower the display threshold too,
411
464
  // otherwise the setting can never fail CI (the findings are filtered out).
412
465
  const displayConfidence = merged.failOn === 'none' || confidenceRank(merged.confidence) <= confidenceRank(merged.failOn)
@@ -414,23 +467,8 @@ async function runScan(options, io) {
414
467
  : merged.failOn;
415
468
  const visible = fresh.filter((finding) => meetsConfidence(finding.confidence, displayConfidence));
416
469
  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
470
  const run = {
433
- visible: outputVisible,
471
+ visible,
434
472
  stats: result.stats,
435
473
  suppressed: result.suppressedCount,
436
474
  baselined: known.length,
@@ -440,7 +478,7 @@ async function runScan(options, io) {
440
478
  const version = await readVersion();
441
479
  if (options.format === 'json') {
442
480
  writeOut(io, renderJson({
443
- findings: outputVisible,
481
+ findings: visible,
444
482
  stats: run.stats,
445
483
  version,
446
484
  suppressedByComment: run.suppressed,
@@ -449,14 +487,14 @@ async function runScan(options, io) {
449
487
  }));
450
488
  }
451
489
  else if (options.format === 'sarif') {
452
- writeOut(io, renderSarif(outputVisible, version));
490
+ writeOut(io, renderSarif(visible, version));
453
491
  }
454
492
  else if (options.format === 'github') {
455
- writeOut(io, renderGithub(outputVisible, run.stats));
493
+ writeOut(io, renderGithub(visible, run.stats));
456
494
  }
457
495
  else {
458
496
  writeOut(io, renderPretty({
459
- findings: outputVisible,
497
+ findings: visible,
460
498
  stats: run.stats,
461
499
  suppressedByComment: run.suppressed,
462
500
  baselined: run.baselined,
@@ -466,7 +504,10 @@ async function runScan(options, io) {
466
504
  quiet: options.quiet,
467
505
  }));
468
506
  if (options.verbose) {
469
- writeOut(io, ` config: ${configFile ?? '(none)'} include: ${merged.include.length} pattern(s) baseline: ${baseline ? path.relative(process.cwd(), baselinePath) : '(none)'}` +
507
+ const configLabel = configFile
508
+ ? path.relative(process.cwd(), path.join(configRoot, configFile))
509
+ : '(none)';
510
+ writeOut(io, ` config: ${configLabel} include: ${merged.include.length} pattern(s) baseline: ${baseline ? path.relative(process.cwd(), baselinePath) : '(none)'}` +
470
511
  (onlyDiff > 0 ? ` diff-only: ${onlyDiff} finding(s) outside the diff were ignored` : '') +
471
512
  '\n');
472
513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidh4x0r/slopgate",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
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",