fix(watch): run the orchestrator with the watched project as cwd

PLAN § v8.1.3 punkt 5. watch-cron.mjs started the orchestrator with
cwd = pluginRoot, so every watched project was outside cwd, i.e. not the
caller's own working tree, and its .llm-security-ignore / policy.json
were dropped: the user saw findings they had already suppressed. The
orchestrator now runs with cwd = the target dir (its parent for a file);
a relative target.path still resolves against pluginRoot as before.

The scope test's entropy blob is now fixed instead of random: one run
with a random blob reported zero findings for both projects, probably a
blob starting with `/` (skipped as a path, 1 in 64). Red on 002c0ba with
the fixed blob, verified.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-09-23 11:34:55 +02:00
commit 62e3cade60
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 25 additions and 4 deletions

View file

@ -8,7 +8,7 @@
// Exit: 0 = all ALLOW, 1 = any WARNING, 2 = any BLOCK
import { resolve, join, dirname, basename } from 'node:path';
import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync } from 'node:fs';
import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync, statSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { spawnSync } from 'node:child_process';
import { tmpdir } from 'node:os';
@ -66,18 +66,32 @@ function loadConfig(configPath) {
// --- Scan Execution ---
// The orchestrator runs with the watched project as cwd, so the project is
// its own working tree and its .llm-security-ignore / policy.json are honored
// (scanners/lib/own-working-tree.mjs). Until v8.1.3 it ran with cwd =
// pluginRoot, which made every watched project foreign. A relative
// target.path still resolves against pluginRoot, as it did then.
function scanCwd(targetPath) {
try {
return statSync(targetPath).isDirectory() ? targetPath : dirname(targetPath);
} catch {
return dirname(targetPath);
}
}
function runScan(target, options, pluginRoot) {
const label = target.label || basename(target.path);
const tmpFile = join(tmpdir(), `llm-security-watch-${Date.now()}-${label}.json`);
const targetPath = resolve(pluginRoot, target.path);
const args = [ORCHESTRATOR, target.path, '--output-file', tmpFile];
const args = [ORCHESTRATOR, targetPath, '--output-file', tmpFile];
if (options.baseline !== false) args.push('--baseline');
if (options.saveBaseline !== false) args.push('--save-baseline');
const result = spawnSync(process.execPath, args, {
encoding: 'utf8',
timeout: SCAN_TIMEOUT,
cwd: pluginRoot
cwd: scanCwd(targetPath)
});
const entry = {