Lines 1-36javascript
3 * candor-ts-watch — keep a candor report FRESH as an agent edits, so candor-ts-mcp serves live ground
4 * truth (roadmap #1, the freshness half). It tracks the project's TS sources by content hash and
5 * re-scans only when a tracked source ACTUALLY changed — a no-op save, a touched node_modules file, or
6 * an unrelated write never triggers work. The MCP server reads the same `--out` prefix, so the loop is:
7 * agent edits → watcher refreshes the report → agent asks candor_impact and gets the post-edit answer.
9 * v1 re-runs a FULL scan on a real change — sound (the report always equals a clean scan), and fast
10 * enough for the edit loop on small/mid projects. The deeper optimisation — re-analysing only the
11 * changed file's subgraph and re-propagating incrementally (the part that needs candor-ts's scanner
12 * factored for per-file extraction) — is the staged next step; the content-hash gate here is the first
13 * increment of it (don't redo work when nothing relevant changed).
15 * candor-ts-watch <dir> [--out <prefix>] [--interval <ms>]
17import { spawnSync } from "node:child_process";
18import crypto from "node:crypto";
LowWeak Crypto
Package source references weak cryptographic algorithms.
watch.mjsView on unpkg · L16 19import fs from "node:fs";
20import path from "node:path";
21import { fileURLToPath } from "node:url";
22import * as Q from "./query-core.mjs";
24const HERE = path.dirname(fileURLToPath(import.meta.url));
25const SRC = /\.[mc]?[jt]sx?$/; // .ts/.tsx/.mts/.cts/.js/.jsx — what candor-ts analyses
26const SKIP = new Set(["node_modules", ".git", "dist", "build", ".candor"]);
28// The tracked source set: every analysable file under `target` (a dir), or the single file itself.
29export function trackedFiles(target) {
30 const st = fs.statSync(target);
31 if (st.isFile()) return SRC.test(target) ? [path.resolve(target)] : [];
34 for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
35 if (ent.name.startsWith(".") && ent.name !== ".") continue;
36 if (SKIP.has(ent.name)) continue;