codebase-snapshot 0.22.0 → 0.22.2

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/dist/cli.js CHANGED
@@ -1,64 +1,80 @@
1
1
  import './chunk-WMEZFLUT.js';
2
- import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, startHttpTransport, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, readConfinedText, auditSnapshot, describeManifestShapeProblem, loadManifest, buildLiveIndex, resolveImpactChanges, computeImpact, DEFAULT_MAX_PROGRAM_FILES, findMultipleSymbolReferences, planTestRun, renderImpactText, runTestPlan, briefFromPaths, resolveDiffBase, filterAndRedactDiff, matchesExclude, defaultIgnoreReason, isSensitivePath, findSection, parsePartSections, buildBrief, explainPath, compareManifests, renderDiffText, generateSnapshot, getGitInfo, loadSigningKey, SIGNATURE_FILE, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, resolveLatest, isNewer, updateCommand, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, escapeControls, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, runWithStdoutCapture, inlineCode, findSecretInPath, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-NPCDJBE4.js';
3
- export { buildAgentContract } from './chunk-NPCDJBE4.js';
2
+ import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, startHttpTransport, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, assertServerSafeConfig, resolveConfig, validateSnapshot, readConfinedText, auditSnapshot, describeManifestShapeProblem, loadManifest, buildLiveIndex, resolveImpactChanges, computeImpact, DEFAULT_MAX_PROGRAM_FILES, findMultipleSymbolReferences, planTestRun, renderImpactText, runTestPlan, briefFromPaths, resolveDiffBase, filterAndRedactDiff, matchesExclude, defaultIgnoreReason, isSensitivePath, findSection, parsePartSections, buildBrief, explainPath, compareManifests, renderDiffText, generateSnapshot, getGitInfo, loadSigningKey, SIGNATURE_FILE, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, resolveLatest, isNewer, updateCommand, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, escapeControls, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, runWithStdoutCapture, inlineCode, findSecretInPath, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-OVH6B3GV.js';
3
+ export { buildAgentContract } from './chunk-OVH6B3GV.js';
4
4
  import { spawnSync } from 'child_process';
5
- import * as fs2 from 'fs';
6
- import * as path3 from 'path';
5
+ import * as fs4 from 'fs';
6
+ import * as path4 from 'path';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { parseArgs } from 'util';
9
9
 
10
10
  var MAX_CONSUMERS = 10;
11
11
  var MAX_TESTS = 5;
12
12
  var MAX_ROUTES = 5;
13
+ var MAX_DOCUMENTATION = 5;
13
14
  var MAX_HOOK_CHARS = 1200;
14
15
  function take(values, limit) {
15
16
  return { taken: values.slice(0, limit), omitted: Math.max(0, values.length - limit) };
16
17
  }
18
+ function safePath(value) {
19
+ return escapeControls(findSecretInPath(value)?.masked ?? value);
20
+ }
17
21
  function toGap(entry) {
18
22
  return {
19
23
  kind: "consumer",
20
- path: entry.path,
24
+ path: safePath(entry.path),
21
25
  distance: entry.distance,
22
- via: entry.via,
26
+ via: safePath(entry.via),
23
27
  ...entry.confidence === void 0 ? {} : { confidence: entry.confidence }
24
28
  };
25
29
  }
26
30
  function testGap(entry) {
27
- return { kind: "test", path: entry.path, covers: [...entry.covers] };
31
+ return { kind: "test", path: safePath(entry.path), covers: entry.covers.map(safePath) };
28
32
  }
29
33
  function routeGap(entry) {
30
- return { kind: "route", path: entry.path, methods: [...entry.methods] };
34
+ return { kind: "route", path: safePath(entry.path), methods: [...entry.methods] };
31
35
  }
32
- function buildGuardReport(impact) {
33
- const changed = impact.changed.filter((entry) => entry.deleted !== true).map((entry) => entry.path);
34
- const changedSet = new Set(changed);
36
+ function buildGuardReport(impact, documentation = []) {
37
+ const changedSet = new Set(impact.changed.map((entry) => entry.path));
38
+ const changed = impact.changed.map((entry) => safePath(entry.path));
35
39
  const consumers = impact.affected.filter((entry) => !changedSet.has(entry.path));
36
40
  const tests = impact.tests.filter((entry) => !changedSet.has(entry.path));
37
41
  const routes = (impact.routesAffected ?? []).filter((entry) => !changedSet.has(entry.path));
38
42
  const consumerPart = take(consumers, MAX_CONSUMERS);
39
43
  const testPart = take(tests, MAX_TESTS);
40
44
  const routePart = take(routes, MAX_ROUTES);
45
+ const documentationPart = take(documentation, MAX_DOCUMENTATION);
41
46
  const gaps = [
42
47
  ...consumerPart.taken.map(toGap),
43
48
  ...testPart.taken.map(testGap),
44
- ...routePart.taken.map(routeGap)
49
+ ...routePart.taken.map(routeGap),
50
+ ...documentationPart.taken.map((gap) => ({
51
+ kind: "documentation",
52
+ path: safePath(gap.path),
53
+ symbols: gap.symbols.map((symbol) => escapeControls(symbol))
54
+ }))
45
55
  ];
56
+ const symbolPruned = impact.affected.some(
57
+ (entry) => entry.impactKind === "direct-symbol" || entry.impactKind === "reexport" || entry.impactKind === "namespace-or-cjs"
58
+ );
46
59
  return {
47
60
  schemaVersion: 1,
48
61
  changed,
49
62
  gaps,
50
63
  trust: impact.trust,
51
- truncated: impact.truncated || consumerPart.omitted > 0 || testPart.omitted > 0 || routePart.omitted > 0,
64
+ confidence: symbolPruned ? "symbol-pruned" : "file-import",
65
+ truncated: impact.truncated || consumerPart.omitted > 0 || testPart.omitted > 0 || routePart.omitted > 0 || documentationPart.omitted > 0,
52
66
  omitted: {
53
67
  consumers: consumerPart.omitted,
54
68
  tests: testPart.omitted,
55
- routes: routePart.omitted
69
+ routes: routePart.omitted,
70
+ documentation: documentationPart.omitted
56
71
  }
57
72
  };
58
73
  }
59
74
  function label(gap) {
60
75
  if (gap.kind === "test") return "test";
61
76
  if (gap.kind === "route") return "route";
77
+ if (gap.kind === "documentation") return "docs";
62
78
  return "consumer";
63
79
  }
64
80
  function renderGuardText(report) {
@@ -77,6 +93,8 @@ function renderGuardText(report) {
77
93
  if (meta.length > 0) parts.push("(" + meta.join(", ") + ")");
78
94
  } else if (gap.kind === "test") {
79
95
  parts.push("(test" + (gap.covers && gap.covers.length > 0 ? ": " + gap.covers.join(", ") : "") + ")");
96
+ } else if (gap.kind === "documentation") {
97
+ parts.push("(documentation" + (gap.symbols && gap.symbols.length > 0 ? ": " + gap.symbols.join(", ") : "") + ")");
80
98
  } else {
81
99
  parts.push("(route" + (gap.methods && gap.methods.length > 0 ? ": " + gap.methods.join(", ") : "") + ")");
82
100
  }
@@ -85,10 +103,10 @@ function renderGuardText(report) {
85
103
  if (report.truncated) {
86
104
  const omitted = report.omitted;
87
105
  lines.push(
88
- " \u2026 truncated: " + omitted.consumers + " consumer(s), " + omitted.tests + " test(s), " + omitted.routes + " route(s) omitted"
106
+ " \u2026 truncated: " + omitted.consumers + " consumer(s), " + omitted.tests + " test(s), " + omitted.routes + " route(s), " + omitted.documentation + " documentation gap(s) omitted"
89
107
  );
90
108
  }
91
- lines.push(" coverage: " + report.trust.coverage + " \xB7 confidence: symbol-pruned");
109
+ lines.push(" coverage: " + report.trust.coverage + " \xB7 confidence: " + report.confidence);
92
110
  return lines.join("\n");
93
111
  }
94
112
  function truncateGuardText(text, maxChars) {
@@ -107,11 +125,13 @@ function renderGuardHookText(report, maxChars = MAX_HOOK_CHARS) {
107
125
  );
108
126
  } else if (gap.kind === "test") {
109
127
  lines.push(" test " + gap.path);
128
+ } else if (gap.kind === "documentation") {
129
+ lines.push(" docs " + gap.path + (gap.symbols && gap.symbols.length > 0 ? " (" + gap.symbols.join(", ") + ")" : ""));
110
130
  } else {
111
131
  lines.push(" route " + gap.path + (gap.methods && gap.methods.length > 0 ? " (" + gap.methods.join(", ") + ")" : ""));
112
132
  }
113
133
  }
114
- lines.push("coverage: " + report.trust.coverage + " \xB7 confidence: symbol-pruned");
134
+ lines.push("coverage: " + report.trust.coverage + " \xB7 confidence: " + report.confidence);
115
135
  lines.push("run: npx codebase-snapshot brief --diff HEAD");
116
136
  return truncateGuardText(lines.join("\n"), maxChars);
117
137
  }
@@ -128,15 +148,26 @@ function renderGuardHook(report, client, event, maxChars = MAX_HOOK_CHARS) {
128
148
  }
129
149
  return JSON.stringify({ additionalContext: text });
130
150
  }
151
+ function canonicalForRelative(target) {
152
+ try {
153
+ return fs4.realpathSync.native(target);
154
+ } catch {
155
+ try {
156
+ return path4.join(fs4.realpathSync.native(path4.dirname(target)), path4.basename(target));
157
+ } catch {
158
+ return path4.resolve(target);
159
+ }
160
+ }
161
+ }
131
162
  function normalizePath(cwd, raw) {
132
163
  const value = raw.trim();
133
164
  if (value.length === 0 || value.includes("\0")) return null;
134
- const absolute = path3.isAbsolute(value) ? value : path3.resolve(cwd, value);
135
- const relative4 = path3.relative(cwd, absolute).split(path3.sep).join("/");
136
- if (relative4 === "" || relative4 === ".." || relative4.startsWith("../") || path3.isAbsolute(relative4)) {
165
+ const absolute = path4.isAbsolute(value) ? value : path4.resolve(cwd, value);
166
+ const relative5 = path4.relative(canonicalForRelative(cwd), canonicalForRelative(absolute)).split(path4.sep).join("/");
167
+ if (relative5 === "" || relative5 === ".." || relative5.startsWith("../") || path4.isAbsolute(relative5)) {
137
168
  return null;
138
169
  }
139
- return relative4;
170
+ return relative5;
140
171
  }
141
172
  function collectPaths(value, out, depth = 0) {
142
173
  if (depth > 6 || value === null || typeof value !== "object") return;
@@ -209,25 +240,75 @@ function parseGuardHookInput(client, raw, cwd) {
209
240
  event
210
241
  };
211
242
  }
243
+ var DOC_PATH = /\.(?:md|mdx|rst|adoc)$/i;
244
+ var MAX_DOC_BYTES = 512 * 1024;
245
+ var MAX_DOC_FILES = 200;
246
+ var MAX_SYMBOLS = 5;
247
+ function publicSymbols(entry) {
248
+ const summary = entry.summary;
249
+ if (summary === null || typeof summary !== "object") return [];
250
+ const record = summary;
251
+ const values = [
252
+ ...Array.isArray(record.exports) ? record.exports : [],
253
+ ...Array.isArray(record.reactComponents) ? record.reactComponents : [],
254
+ ...Array.isArray(record.routeHandlers) ? record.routeHandlers : []
255
+ ];
256
+ return [...new Set(values.filter((value) => typeof value === "string" && value.length >= 3))];
257
+ }
258
+ function inside(root, relative5) {
259
+ const absolute = path4.resolve(root, relative5);
260
+ const rel = path4.relative(root, absolute);
261
+ if (rel === "" || rel === ".." || rel.startsWith(".." + path4.sep) || path4.isAbsolute(rel)) return null;
262
+ return absolute;
263
+ }
264
+ function findDocumentationGaps(manifest, cwd, changedPaths) {
265
+ const docs = manifest.files.filter((entry) => DOC_PATH.test(entry.relativePath) && !changedPaths.has(entry.relativePath)).slice(0, MAX_DOC_FILES);
266
+ if (docs.length === 0) return [];
267
+ const texts = [];
268
+ for (const doc of docs) {
269
+ const absolute = inside(cwd, doc.relativePath);
270
+ if (absolute === null) continue;
271
+ try {
272
+ const stat = fs4.statSync(absolute);
273
+ if (!stat.isFile() || stat.size > MAX_DOC_BYTES) continue;
274
+ texts.push(fs4.readFileSync(absolute, "utf8").toLowerCase());
275
+ } catch {
276
+ }
277
+ }
278
+ if (texts.length === 0) return [];
279
+ const gaps = [];
280
+ for (const entry of manifest.files) {
281
+ if (!changedPaths.has(entry.relativePath)) continue;
282
+ if (DOC_PATH.test(entry.relativePath)) continue;
283
+ const symbols = publicSymbols(entry);
284
+ if (symbols.length === 0) continue;
285
+ const mentioned = texts.some(
286
+ (text) => symbols.some((symbol) => text.includes(symbol.toLowerCase()))
287
+ );
288
+ if (!mentioned) gaps.push({ path: entry.relativePath, symbols: symbols.slice(0, MAX_SYMBOLS) });
289
+ if (gaps.length >= 5) break;
290
+ }
291
+ return gaps;
292
+ }
212
293
  var SKILL_TARGETS = ["agents", "claude", "cursor", "all"];
213
294
  var REFUSED = "Refusing to install the agent skill";
214
295
  var LEGACY_AGENTS_MARKER = "<!-- codebase-snapshot:skill:start -->";
215
296
  function targetPath(cwd, target) {
216
297
  switch (target) {
217
298
  case "agents":
218
- return path3.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
299
+ return path4.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
219
300
  case "claude":
220
- return path3.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
301
+ return path4.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
221
302
  case "cursor":
222
- return path3.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
303
+ return path4.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
223
304
  }
224
305
  }
225
306
  function assertWritableInsideRepository(cwd, filePath) {
226
- const root = fs2.realpathSync(cwd);
227
- const shown = path3.relative(root, filePath) || filePath;
307
+ const root = fs4.realpathSync(cwd);
308
+ const shown = path4.relative(root, filePath) || filePath;
228
309
  let stat = null;
229
310
  try {
230
- stat = fs2.lstatSync(filePath);
311
+ stat = fs4.lstatSync(filePath);
231
312
  } catch {
232
313
  stat = null;
233
314
  }
@@ -243,32 +324,32 @@ function assertWritableInsideRepository(cwd, filePath) {
243
324
  }
244
325
  let existing = filePath;
245
326
  const missing = [];
246
- while (!fs2.existsSync(existing)) {
247
- missing.unshift(path3.basename(existing));
248
- const parent = path3.dirname(existing);
327
+ while (!fs4.existsSync(existing)) {
328
+ missing.unshift(path4.basename(existing));
329
+ const parent = path4.dirname(existing);
249
330
  if (parent === existing) break;
250
331
  existing = parent;
251
332
  }
252
- const realAncestor = fs2.realpathSync(existing);
253
- const resolved = missing.length === 0 ? realAncestor : path3.join(realAncestor, ...missing);
254
- if (resolved !== root && !resolved.startsWith(`${root}${path3.sep}`)) {
333
+ const realAncestor = fs4.realpathSync(existing);
334
+ const resolved = missing.length === 0 ? realAncestor : path4.join(realAncestor, ...missing);
335
+ if (resolved !== root && !resolved.startsWith(`${root}${path4.sep}`)) {
255
336
  throw new Error(
256
337
  `${REFUSED}: ${shown} resolves outside the repository (${resolved}). Move it back inside ${root}, or remove the link, and run again.`
257
338
  );
258
339
  }
259
340
  }
260
341
  function writeIfChanged(target, filePath, content) {
261
- const existing = fs2.existsSync(filePath) ? fs2.readFileSync(filePath, "utf8") : null;
342
+ const existing = fs4.existsSync(filePath) ? fs4.readFileSync(filePath, "utf8") : null;
262
343
  if (existing === content) return { target, path: filePath, action: "unchanged" };
263
- fs2.mkdirSync(path3.dirname(filePath), { recursive: true });
264
- fs2.writeFileSync(filePath, content, "utf8");
344
+ fs4.mkdirSync(path4.dirname(filePath), { recursive: true });
345
+ fs4.writeFileSync(filePath, content, "utf8");
265
346
  return { target, path: filePath, action: existing === null ? "created" : "updated" };
266
347
  }
267
348
  function legacyAgentsNote(cwd) {
268
- const filePath = path3.join(cwd, "AGENTS.md");
349
+ const filePath = path4.join(cwd, "AGENTS.md");
269
350
  try {
270
- if (!fs2.existsSync(filePath)) return null;
271
- if (!fs2.readFileSync(filePath, "utf8").includes(LEGACY_AGENTS_MARKER)) return null;
351
+ if (!fs4.existsSync(filePath)) return null;
352
+ if (!fs4.readFileSync(filePath, "utf8").includes(LEGACY_AGENTS_MARKER)) return null;
272
353
  } catch {
273
354
  return null;
274
355
  }
@@ -280,9 +361,9 @@ function installSkill(cwd, target = "all", options = {}) {
280
361
  const notes = [];
281
362
  const wanted = target === "all" ? ["agents", "claude", "cursor"] : [target];
282
363
  for (const item of wanted) assertWritableInsideRepository(cwd, targetPath(cwd, item));
283
- const createsSomething = wanted.some((item) => !fs2.existsSync(targetPath(cwd, item)));
364
+ const createsSomething = wanted.some((item) => !fs4.existsSync(targetPath(cwd, item)));
284
365
  if (createsSomething) {
285
- assertWritableInsideRepository(cwd, path3.join(cwd, ".gitignore"));
366
+ assertWritableInsideRepository(cwd, path4.join(cwd, ".gitignore"));
286
367
  }
287
368
  const pendingMcp = options.withMcp === true ? prepareMcpConfig(cwd) : null;
288
369
  for (const item of wanted) {
@@ -297,20 +378,20 @@ function installSkill(cwd, target = "all", options = {}) {
297
378
  if (pendingMcp !== null) {
298
379
  if (pendingMcp.note !== null) notes.push(pendingMcp.note);
299
380
  if (pendingMcp.content !== null) {
300
- fs2.writeFileSync(pendingMcp.filePath, pendingMcp.content, "utf8");
381
+ fs4.writeFileSync(pendingMcp.filePath, pendingMcp.content, "utf8");
301
382
  }
302
383
  mcp = { path: pendingMcp.filePath, action: pendingMcp.action };
303
384
  }
304
385
  return { cwd, written, gitignored: ignore.added, notes, ...mcp === void 0 ? {} : { mcp } };
305
386
  }
306
387
  function prepareMcpConfig(cwd) {
307
- const filePath = path3.join(cwd, ".mcp.json");
388
+ const filePath = path4.join(cwd, ".mcp.json");
308
389
  assertWritableInsideRepository(cwd, filePath);
309
390
  const desired = { command: "npx", args: ["-y", "codebase-snapshot@latest", "mcp"] };
310
391
  let parsed = {};
311
392
  let existing = null;
312
- if (fs2.existsSync(filePath)) {
313
- existing = fs2.readFileSync(filePath, "utf8");
393
+ if (fs4.existsSync(filePath)) {
394
+ existing = fs4.readFileSync(filePath, "utf8");
314
395
  let candidate;
315
396
  try {
316
397
  candidate = JSON.parse(existing);
@@ -589,29 +670,33 @@ Options:
589
670
  --all-members Audit every snapshot a --workspace run wrote
590
671
  --deep Replay every full body against the source on disk
591
672
 
592
- impact and brief:
593
- --diff <ref> Compare the working tree against this git ref
594
- --paths <a,b> Treat these repository-relative paths as the change
595
- --depth <n> Reverse-import hops to follow (default: 3, max: 8)
596
- --max-results <n> Cap affected files (default: 200, max: 1000)
673
+ impact only:
597
674
  --tests-paths Print candidate test paths, one per line
598
675
  --run Run the detected test runner (text format only)
599
676
  --precise Add bounded compiler-resolved symbol references
677
+ --include-imports Include outgoing imports of changed files
678
+ --include-cycles Include import cycles in the impacted subgraph
600
679
 
601
680
  guard only:
602
681
  --hook <client> Read one hook payload from stdin: claude | copilot | codex | raw
603
682
  --changed Check the working tree against HEAD (default when no --hook)
604
683
  --max-chars <n> Cap the model-facing hook text (default 1200, max 10000)
605
- --include-imports Include outgoing imports of changed files
606
- --include-cycles Include import cycles in the impacted subgraph
607
- --no-live Require the persisted snapshot instead of the live index
608
- --no-cache Bypass the OS live-index summary cache
684
+
685
+ brief only:
609
686
  --max-tokens <n> Brief token budget (default: 12000, minimum: 500)
610
687
  --lines-per-file <n> Brief lines per file (default: 80)
611
688
  --include-tests Include candidate tests in the brief
612
689
  --copy Copy the brief to the clipboard
613
690
  --out <path> Write the brief inside the repository
614
691
 
692
+ impact, guard and brief:
693
+ --diff <ref> Compare the working tree against this git ref
694
+ --paths <a,b> Treat these repository-relative paths as the change
695
+ --depth <n> Reverse-import hops to follow (default: 3, max: 8)
696
+ --max-results <n> Cap affected files (default: 200, max: 1000)
697
+ --no-live Require the persisted snapshot instead of the live index
698
+ --no-cache Bypass the OS live-index summary cache
699
+
615
700
  skill only:
616
701
  --install Write the skill into the repository instead of printing
617
702
  --target <name> agents | claude | cursor | all (default: all)
@@ -746,10 +831,10 @@ function parseCliArgs(argv) {
746
831
  }
747
832
  if (values.cwd !== void 0) {
748
833
  const target = String(values.cwd);
749
- if (!fs2.existsSync(target)) {
834
+ if (!fs4.existsSync(target)) {
750
835
  throw new UsageError(`--cwd directory does not exist: ${target}`);
751
836
  }
752
- if (!fs2.statSync(target).isDirectory()) {
837
+ if (!fs4.statSync(target).isDirectory()) {
753
838
  throw new UsageError(`--cwd is not a directory: ${target}`);
754
839
  }
755
840
  }
@@ -857,6 +942,17 @@ function parseCliArgs(argv) {
857
942
  throw new UsageError("guard --hook already runs on the payload; do not pass --changed.");
858
943
  }
859
944
  }
945
+ if (command === "guard") {
946
+ if (paths !== void 0 && rawDiff !== void 0) {
947
+ throw new UsageError("guard accepts either --diff <ref> or --paths <a,b>, not both.");
948
+ }
949
+ if (values.changed === true && paths !== void 0) {
950
+ throw new UsageError("guard --changed reads the working tree; do not combine it with --paths.");
951
+ }
952
+ if (values.changed === true && rawDiff !== void 0) {
953
+ throw new UsageError("guard --changed reads the working tree; do not combine it with --diff.");
954
+ }
955
+ }
860
956
  const maxChars = parseCountOption(values["max-chars"], "max-chars", 200);
861
957
  if (maxChars !== void 0 && maxChars > 1e4) {
862
958
  throw new UsageError(`--max-chars must be at most 10000, received ${maxChars}.`);
@@ -979,7 +1075,7 @@ function parseCliArgs(argv) {
979
1075
  install: values.install === true,
980
1076
  noInstall: values["no-install"] === true,
981
1077
  target: values.target === void 0 ? void 0 : String(values.target),
982
- cwd: values.cwd === void 0 ? process.cwd() : path3.resolve(String(values.cwd)),
1078
+ cwd: values.cwd === void 0 ? process.cwd() : path4.resolve(String(values.cwd)),
983
1079
  outDir: values["out-dir"] === void 0 ? void 0 : String(values["out-dir"]),
984
1080
  includeMonolith: values["include-monolith"] === true || onlyNamesMonolith === true ? true : void 0,
985
1081
  includeSensitiveFiles: values["include-sensitive-files"] === true ? true : void 0,
@@ -1162,45 +1258,45 @@ function renderImpactMarkdown(report) {
1162
1258
  }
1163
1259
  function realPathInside(realRoot, candidate) {
1164
1260
  const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
1165
- const relative4 = path3.relative(fold(realRoot), fold(candidate));
1166
- return relative4.length === 0 || relative4 !== ".." && !relative4.startsWith(".." + path3.sep) && !path3.isAbsolute(relative4);
1261
+ const relative5 = path4.relative(fold(realRoot), fold(candidate));
1262
+ return relative5.length === 0 || relative5 !== ".." && !relative5.startsWith(".." + path4.sep) && !path4.isAbsolute(relative5);
1167
1263
  }
1168
- function writeInside(root, relative4, content) {
1169
- const target = path3.resolve(root, relative4);
1170
- const rel = path3.relative(path3.resolve(root), target);
1171
- if (rel.length === 0 || rel === ".." || rel.startsWith(".." + path3.sep) || path3.isAbsolute(rel)) {
1264
+ function writeInside(root, relative5, content) {
1265
+ const target = path4.resolve(root, relative5);
1266
+ const rel = path4.relative(path4.resolve(root), target);
1267
+ if (rel.length === 0 || rel === ".." || rel.startsWith(".." + path4.sep) || path4.isAbsolute(rel)) {
1172
1268
  throw new Error("--out must resolve inside the repository.");
1173
1269
  }
1174
- const parent = path3.dirname(target);
1175
- const realRoot = fs2.realpathSync(root);
1270
+ const parent = path4.dirname(target);
1271
+ const realRoot = fs4.realpathSync(root);
1176
1272
  let existingAncestor = parent;
1177
- while (!fs2.existsSync(existingAncestor)) {
1178
- const next = path3.dirname(existingAncestor);
1273
+ while (!fs4.existsSync(existingAncestor)) {
1274
+ const next = path4.dirname(existingAncestor);
1179
1275
  if (next === existingAncestor) break;
1180
1276
  existingAncestor = next;
1181
1277
  }
1182
- if (!realPathInside(realRoot, fs2.realpathSync(existingAncestor))) {
1278
+ if (!realPathInside(realRoot, fs4.realpathSync(existingAncestor))) {
1183
1279
  throw new Error("--out resolves outside the repository through a link.");
1184
1280
  }
1185
- fs2.mkdirSync(parent, { recursive: true });
1186
- if (!realPathInside(realRoot, fs2.realpathSync(parent))) {
1281
+ fs4.mkdirSync(parent, { recursive: true });
1282
+ if (!realPathInside(realRoot, fs4.realpathSync(parent))) {
1187
1283
  throw new Error("--out resolves outside the repository through a link.");
1188
1284
  }
1189
1285
  try {
1190
- const existing = fs2.lstatSync(target);
1286
+ const existing = fs4.lstatSync(target);
1191
1287
  if (existing.isSymbolicLink() || !existing.isFile() || existing.nlink > 1) {
1192
1288
  throw new Error("--out must be a regular file that is not a symbolic or hard link.");
1193
1289
  }
1194
1290
  } catch (error) {
1195
1291
  if (error.code !== "ENOENT") throw error;
1196
1292
  }
1197
- const temporary = path3.join(parent, "." + path3.basename(target) + ".tmp-" + process.pid + "-" + Math.random().toString(16).slice(2));
1198
- fs2.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx", mode: 384 });
1293
+ const temporary = path4.join(parent, "." + path4.basename(target) + ".tmp-" + process.pid + "-" + Math.random().toString(16).slice(2));
1294
+ fs4.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx", mode: 384 });
1199
1295
  try {
1200
- fs2.renameSync(temporary, target);
1296
+ fs4.renameSync(temporary, target);
1201
1297
  } catch (error) {
1202
1298
  try {
1203
- fs2.unlinkSync(temporary);
1299
+ fs4.unlinkSync(temporary);
1204
1300
  } catch (cleanupError) {
1205
1301
  warn("Could not remove temporary file " + temporary + ": " + cleanupError.message);
1206
1302
  }
@@ -1223,10 +1319,10 @@ function splitList(value) {
1223
1319
  return value.split(",").map((entry) => entry.trim()).filter(Boolean);
1224
1320
  }
1225
1321
  function displayOutPath(cwd, outDir, ...segments) {
1226
- const absolute = path3.resolve(cwd, outDir, ...segments);
1227
- const relative4 = path3.relative(cwd, absolute);
1228
- if (relative4 !== "" && relative4 !== ".." && !relative4.startsWith(`..${path3.sep}`) && !relative4.startsWith("../") && !path3.isAbsolute(relative4)) {
1229
- return relative4;
1322
+ const absolute = path4.resolve(cwd, outDir, ...segments);
1323
+ const relative5 = path4.relative(cwd, absolute);
1324
+ if (relative5 !== "" && relative5 !== ".." && !relative5.startsWith(`..${path4.sep}`) && !relative5.startsWith("../") && !path4.isAbsolute(relative5)) {
1325
+ return relative5;
1230
1326
  }
1231
1327
  return absolute;
1232
1328
  }
@@ -1235,7 +1331,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
1235
1331
  if (!hasScript) {
1236
1332
  try {
1237
1333
  const parsed = JSON.parse(
1238
- stripJsonComments(fs2.readFileSync(path3.join(cwd, "package.json"), "utf8"))
1334
+ stripJsonComments(fs4.readFileSync(path4.join(cwd, "package.json"), "utf8"))
1239
1335
  );
1240
1336
  hasScript = typeof parsed.scripts?.snapshot === "string";
1241
1337
  } catch {
@@ -1243,8 +1339,8 @@ function nextStepHint(cwd, scriptsAddedNow) {
1243
1339
  }
1244
1340
  }
1245
1341
  if (!hasScript) return `npx ${GENERATOR_NAME} generate`;
1246
- const bin = path3.join(cwd, "node_modules", ".bin", "codebase-snapshot");
1247
- const installed = fs2.existsSync(bin) || fs2.existsSync(`${bin}.cmd`);
1342
+ const bin = path4.join(cwd, "node_modules", ".bin", "codebase-snapshot");
1343
+ const installed = fs4.existsSync(bin) || fs4.existsSync(`${bin}.cmd`);
1248
1344
  return installed ? "npm run snapshot" : "npm install && npm run snapshot";
1249
1345
  }
1250
1346
  function presetSummary(init) {
@@ -1280,7 +1376,7 @@ async function runInitCommand(invocation) {
1280
1376
  if (hook) for (const note of hook.notes) info(` ${note}`);
1281
1377
  return 0;
1282
1378
  }
1283
- info(`\u2705 Created ${path3.basename(result.configPath)} (${presetSummary(result)})`);
1379
+ info(`\u2705 Created ${path4.basename(result.configPath)} (${presetSummary(result)})`);
1284
1380
  if (result.scripts.length > 0) info(` Added npm scripts: ${result.scripts.join(", ")}`);
1285
1381
  if (result.dependency.added && result.dependency.range !== null) {
1286
1382
  info(` Added devDependency: ${result.dependency.name} ${result.dependency.range}`);
@@ -1290,10 +1386,10 @@ async function runInitCommand(invocation) {
1290
1386
  }
1291
1387
  if (result.briefWritten) {
1292
1388
  info(
1293
- ` Wrote ${path3.basename(result.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path3.basename(result.briefPath))} in the config to merge it.`
1389
+ ` Wrote ${path4.basename(result.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path4.basename(result.briefPath))} in the config to merge it.`
1294
1390
  );
1295
- } else if (fs2.existsSync(result.briefPath)) {
1296
- info(` Kept ${path3.basename(result.briefPath)}: it already exists, and is never overwritten.`);
1391
+ } else if (fs4.existsSync(result.briefPath)) {
1392
+ info(` Kept ${path4.basename(result.briefPath)}: it already exists, and is never overwritten.`);
1297
1393
  }
1298
1394
  for (const note of result.notes) info(` \u26A0 ${note}`);
1299
1395
  if (hook) for (const note of hook.notes) info(` ${note}`);
@@ -1330,18 +1426,18 @@ function renderHealthText(report) {
1330
1426
  function generatorOrigin(cwd) {
1331
1427
  try {
1332
1428
  const pkg = JSON.parse(
1333
- stripJsonComments(fs2.readFileSync(path3.join(cwd, "package.json"), "utf8"))
1429
+ stripJsonComments(fs4.readFileSync(path4.join(cwd, "package.json"), "utf8"))
1334
1430
  );
1335
1431
  const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
1336
1432
  if (typeof spec === "string") return `project dependency ${spec}`;
1337
1433
  } catch {
1338
1434
  }
1339
1435
  const entry = process.argv[1] ?? "";
1340
- if (entry.includes("_npx") || entry.includes(`${path3.sep}npx${path3.sep}`)) return "via npx";
1436
+ if (entry.includes("_npx") || entry.includes(`${path4.sep}npx${path4.sep}`)) return "via npx";
1341
1437
  return "global or direct install";
1342
1438
  }
1343
1439
  function detectPackageManager(cwd) {
1344
- const has = (name) => fs2.existsSync(path3.join(cwd, name));
1440
+ const has = (name) => fs4.existsSync(path4.join(cwd, name));
1345
1441
  if (has("bun.lockb") || has("bun.lock")) return { name: "bun", command: "bun", args: ["install"] };
1346
1442
  if (has("pnpm-lock.yaml")) return { name: "pnpm", command: "pnpm", args: ["install"] };
1347
1443
  if (has("yarn.lock")) return { name: "yarn", command: "yarn", args: ["install"] };
@@ -1458,7 +1554,7 @@ async function runSetupCommand(invocation, options = {}) {
1458
1554
  }
1459
1555
  info("\n\u{1F9EA} Dry run \u2014 setup would:");
1460
1556
  info(
1461
- ` 1. ${init.reused ? `keep ${path3.basename(keptConfigPath)}` : `write ${path3.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
1557
+ ` 1. ${init.reused ? `keep ${path4.basename(keptConfigPath)}` : `write ${path4.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
1462
1558
  );
1463
1559
  info(" 2. add the npm scripts, the devDependency and the .gitignore entries");
1464
1560
  if (manager !== null) info(` 3. install with ${manager}`);
@@ -1471,9 +1567,9 @@ async function runSetupCommand(invocation, options = {}) {
1471
1567
  if (invocation.format !== "json") {
1472
1568
  if (!interactive) info(`\u{1F680} Setup for: ${invocation.cwd}`);
1473
1569
  if (init.reused) {
1474
- info(`\u267B Keeping ${path3.basename(keptConfigPath)}`);
1570
+ info(`\u267B Keeping ${path4.basename(keptConfigPath)}`);
1475
1571
  } else {
1476
- info(`\u2705 Created ${path3.basename(keptConfigPath)} (${presetSummary(init)})`);
1572
+ info(`\u2705 Created ${path4.basename(keptConfigPath)} (${presetSummary(init)})`);
1477
1573
  }
1478
1574
  if (init.scripts.length > 0) info(` Added npm scripts: ${init.scripts.join(", ")}`);
1479
1575
  if (init.dependency.added && init.dependency.range !== null) {
@@ -1484,7 +1580,7 @@ async function runSetupCommand(invocation, options = {}) {
1484
1580
  }
1485
1581
  if (init.briefWritten) {
1486
1582
  info(
1487
- ` Wrote ${path3.basename(init.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path3.basename(init.briefPath))} in the config to merge it.`
1583
+ ` Wrote ${path4.basename(init.briefPath)}: a scaffold for the half of PROMPT.md only you can write. Fill it in, then set brief: ${JSON.stringify(path4.basename(init.briefPath))} in the config to merge it.`
1488
1584
  );
1489
1585
  }
1490
1586
  if (hook) for (const note of hook.notes) info(` ${note}`);
@@ -1492,7 +1588,7 @@ async function runSetupCommand(invocation, options = {}) {
1492
1588
  info(` \u26A0 --preset ${invocation.preset} was not applied: the existing config is kept.`);
1493
1589
  }
1494
1590
  }
1495
- const hasManifest = fs2.existsSync(path3.join(invocation.cwd, "package.json"));
1591
+ const hasManifest = fs4.existsSync(path4.join(invocation.cwd, "package.json"));
1496
1592
  let install = null;
1497
1593
  if (invocation.noInstall) {
1498
1594
  if (invocation.format !== "json") info(" Skipped the install (--no-install)");
@@ -1657,7 +1753,7 @@ function runSkillCommand(invocation) {
1657
1753
  }
1658
1754
  info(`\u2705 Agent skill installed (${SKILL_NAME}):`);
1659
1755
  for (const item of result.written) {
1660
- const shown = path3.relative(invocation.cwd, item.path) || item.path;
1756
+ const shown = path4.relative(invocation.cwd, item.path) || item.path;
1661
1757
  info(` - ${item.action.padEnd(9)} ${shown}`);
1662
1758
  }
1663
1759
  if (result.gitignored.length > 0) {
@@ -1666,7 +1762,7 @@ function runSkillCommand(invocation) {
1666
1762
  info(" These files are this tool's own documentation, so they stay out of git.");
1667
1763
  }
1668
1764
  if (result.mcp !== void 0) {
1669
- const shown = path3.relative(invocation.cwd, result.mcp.path) || result.mcp.path;
1765
+ const shown = path4.relative(invocation.cwd, result.mcp.path) || result.mcp.path;
1670
1766
  info(` - ${result.mcp.action.padEnd(9)} ${shown} (codebase-snapshot MCP entry)`);
1671
1767
  }
1672
1768
  for (const note of result.notes) info(` \u26A0 ${note}`);
@@ -1748,6 +1844,11 @@ async function readStdin(limit = 1024 * 1024) {
1748
1844
  }
1749
1845
  return Buffer.concat(chunks).toString("utf8");
1750
1846
  }
1847
+ function guardHookSkipped(message) {
1848
+ warn("guard: " + message + " (hook skipped)");
1849
+ process.stdout.write("{}\n");
1850
+ return 0;
1851
+ }
1751
1852
  async function runGuardCommand(invocation, resolved) {
1752
1853
  const client = invocation.hook;
1753
1854
  try {
@@ -1765,11 +1866,11 @@ async function runGuardCommand(invocation, resolved) {
1765
1866
  const changes = resolveImpactChanges(resolved.cwd, {
1766
1867
  ...paths === void 0 ? { diff: invocation.diff ?? "HEAD" } : { paths }
1767
1868
  });
1768
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
1869
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
1769
1870
  let manifest;
1770
1871
  let trust;
1771
1872
  if (invocation.noLive) {
1772
- if (!fs2.existsSync(manifestPath)) {
1873
+ if (!fs4.existsSync(manifestPath)) {
1773
1874
  if (client !== void 0) {
1774
1875
  warn("guard: no snapshot manifest; the hook was skipped.");
1775
1876
  process.stdout.write("{}\n");
@@ -1791,9 +1892,16 @@ async function runGuardCommand(invocation, resolved) {
1791
1892
  cwd: resolved.cwd,
1792
1893
  changes,
1793
1894
  manifestPath,
1794
- ...trust === void 0 ? {} : { trust }
1895
+ ...trust === void 0 ? {} : { trust },
1896
+ ...invocation.depth === void 0 ? {} : { depth: invocation.depth },
1897
+ ...invocation.maxResults === void 0 ? {} : { maxResults: invocation.maxResults }
1795
1898
  });
1796
- const report = buildGuardReport(impact);
1899
+ const documentation = findDocumentationGaps(
1900
+ manifest,
1901
+ resolved.cwd,
1902
+ new Set(impact.changed.map((entry) => entry.path))
1903
+ );
1904
+ const report = buildGuardReport(impact, documentation);
1797
1905
  if (client !== void 0) {
1798
1906
  process.stdout.write(renderGuardHook(report, client, event, invocation.maxChars ?? 1200) + "\n");
1799
1907
  return 0;
@@ -1896,7 +2004,7 @@ ${USAGE}
1896
2004
  }
1897
2005
  if (invocation.command === "serve") {
1898
2006
  const server = await startWebServer({
1899
- cwd: path3.resolve(invocation.cwd),
2007
+ cwd: path4.resolve(invocation.cwd),
1900
2008
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1901
2009
  ...invocation.port === void 0 ? {} : { port: invocation.port },
1902
2010
  ...tokenOption,
@@ -1911,9 +2019,9 @@ ${USAGE}
1911
2019
  } else {
1912
2020
  warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
1913
2021
  }
1914
- await new Promise((resolve3) => {
2022
+ await new Promise((resolve4) => {
1915
2023
  const stop = () => {
1916
- void server.close().then(resolve3);
2024
+ void server.close().then(resolve4);
1917
2025
  };
1918
2026
  process.once("SIGINT", stop);
1919
2027
  process.once("SIGTERM", stop);
@@ -1923,7 +2031,7 @@ ${USAGE}
1923
2031
  if (invocation.command === "mcp") {
1924
2032
  if (invocation.http === true) {
1925
2033
  const transport = await startHttpTransport({
1926
- cwd: path3.resolve(invocation.cwd),
2034
+ cwd: path4.resolve(invocation.cwd),
1927
2035
  noConfig: invocation.noConfig,
1928
2036
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1929
2037
  ...invocation.port === void 0 ? {} : { port: invocation.port },
@@ -1939,9 +2047,9 @@ ${USAGE}
1939
2047
  } else {
1940
2048
  warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
1941
2049
  }
1942
- await new Promise((resolve3) => {
2050
+ await new Promise((resolve4) => {
1943
2051
  const stop = () => {
1944
- void transport.close().then(resolve3);
2052
+ void transport.close().then(resolve4);
1945
2053
  };
1946
2054
  process.once("SIGINT", stop);
1947
2055
  process.once("SIGTERM", stop);
@@ -1949,7 +2057,7 @@ ${USAGE}
1949
2057
  return 0;
1950
2058
  }
1951
2059
  return await runStdioServer({
1952
- cwd: path3.resolve(invocation.cwd),
2060
+ cwd: path4.resolve(invocation.cwd),
1953
2061
  noConfig: invocation.noConfig
1954
2062
  });
1955
2063
  }
@@ -1979,8 +2087,15 @@ ${USAGE}
1979
2087
  log: (line) => info(" " + line)
1980
2088
  });
1981
2089
  sourceProvenance = clone.provenance;
1982
- const outDir = path3.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
1983
- invocation = { ...invocation, cwd: clone.directory, outDir, noConfig: true };
2090
+ const outDir = path4.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
2091
+ const delta = invocation.delta === void 0 ? void 0 : path4.resolve(invocation.cwd, invocation.delta);
2092
+ invocation = {
2093
+ ...invocation,
2094
+ cwd: clone.directory,
2095
+ outDir,
2096
+ ...delta === void 0 ? {} : { delta },
2097
+ noConfig: true
2098
+ };
1984
2099
  info(
1985
2100
  " Source: " + parsed.source.owner + "/" + parsed.source.repo + "@" + clone.commit.slice(0, 12) + " (fetched " + clone.provenance.fetchedAt + ")"
1986
2101
  );
@@ -1990,7 +2105,7 @@ ${USAGE}
1990
2105
  const directory = clone.directory;
1991
2106
  process.once("exit", () => {
1992
2107
  try {
1993
- fs2.rmSync(directory, { recursive: true, force: true });
2108
+ fs4.rmSync(directory, { recursive: true, force: true });
1994
2109
  } catch {
1995
2110
  }
1996
2111
  });
@@ -1999,17 +2114,39 @@ ${USAGE}
1999
2114
  return fail(invocation.format, "Remote fetch failed: " + error.message);
2000
2115
  }
2001
2116
  }
2117
+ const guardHook = invocation.command === "guard" && invocation.hook !== void 0;
2002
2118
  const skipConfig = invocation.noConfig || invocation.command === "diff";
2003
- const loaded = skipConfig ? { config: null, warnings: [], errors: [], file: null } : await loadConfigFileDetailed(invocation.cwd);
2119
+ let loaded;
2120
+ if (skipConfig) {
2121
+ loaded = { config: null, warnings: [], errors: [], file: null };
2122
+ } else {
2123
+ try {
2124
+ loaded = await loadConfigFileDetailed(
2125
+ invocation.cwd,
2126
+ guardHook ? { allowExecutableConfig: false } : {}
2127
+ );
2128
+ } catch (error) {
2129
+ if (guardHook) return guardHookSkipped(error.message);
2130
+ return fail(invocation.format, error.message);
2131
+ }
2132
+ }
2004
2133
  if (invocation.noConfig) info("\u2699 --no-config: using built-in defaults, config file ignored");
2005
2134
  if (loaded.errors.length > 0) {
2135
+ if (guardHook) return guardHookSkipped(loaded.errors.join("; "));
2006
2136
  return fail(
2007
2137
  invocation.format,
2008
2138
  `The config file could not be read: ${loaded.errors.join("; ")}. Fix it, or delete it to use the defaults.`
2009
2139
  );
2010
2140
  }
2141
+ if (guardHook) {
2142
+ try {
2143
+ assertServerSafeConfig(loaded.config, loaded.file ?? invocation.cwd);
2144
+ } catch (error) {
2145
+ return guardHookSkipped(error.message);
2146
+ }
2147
+ }
2011
2148
  for (const warning of loaded.warnings) warn(`\u26A0 Config: ${warning}`);
2012
- if (loaded.file) info(`\u2699 Using config ${path3.relative(process.cwd(), loaded.file) || loaded.file}`);
2149
+ if (loaded.file) info(`\u2699 Using config ${path4.relative(process.cwd(), loaded.file) || loaded.file}`);
2013
2150
  let resolved;
2014
2151
  try {
2015
2152
  resolved = resolveConfig(
@@ -2018,6 +2155,7 @@ ${USAGE}
2018
2155
  invocation.cwd
2019
2156
  );
2020
2157
  } catch (err) {
2158
+ if (guardHook) return guardHookSkipped(err.message);
2021
2159
  return fail(invocation.format, err.message);
2022
2160
  }
2023
2161
  if (invocation.command === "guard") {
@@ -2030,9 +2168,9 @@ ${USAGE}
2030
2168
  }
2031
2169
  if (invocation.command === "health") {
2032
2170
  if (invocation.allMembers === true) {
2033
- const outRoot = path3.resolve(resolved.cwd, resolved.outDir);
2034
- const indexPath = path3.join(outRoot, "WORKSPACE.json");
2035
- if (!fs2.existsSync(indexPath)) {
2171
+ const outRoot = path4.resolve(resolved.cwd, resolved.outDir);
2172
+ const indexPath = path4.join(outRoot, "WORKSPACE.json");
2173
+ if (!fs4.existsSync(indexPath)) {
2036
2174
  return fail(
2037
2175
  invocation.format,
2038
2176
  `No workspace index at ${indexPath}. Run generate --workspace <a,b> first, or drop --all-members.`
@@ -2050,15 +2188,15 @@ ${USAGE}
2050
2188
  }
2051
2189
  const rows = [];
2052
2190
  const insidePath = (parent, child) => {
2053
- const relative4 = path3.relative(parent, child);
2054
- return relative4 === "" || relative4 !== ".." && !relative4.startsWith(`..${path3.sep}`) && !relative4.startsWith("../") && !path3.isAbsolute(relative4);
2191
+ const relative5 = path4.relative(parent, child);
2192
+ return relative5 === "" || relative5 !== ".." && !relative5.startsWith(`..${path4.sep}`) && !relative5.startsWith("../") && !path4.isAbsolute(relative5);
2055
2193
  };
2056
2194
  for (const member of index.members ?? []) {
2057
2195
  const name = member.name ?? "?";
2058
- const snapshotDir2 = path3.resolve(outRoot, name);
2196
+ const snapshotDir2 = path4.resolve(outRoot, name);
2059
2197
  const repoPath = member.path ?? name;
2060
- const repoDir = path3.resolve(resolved.cwd, repoPath);
2061
- if (name.length === 0 || path3.isAbsolute(name) || name.split(/[\\/]/).includes("..") || !insidePath(outRoot, snapshotDir2) || path3.isAbsolute(repoPath) || repoPath.split(/[\\/]/).includes("..") || !insidePath(resolved.cwd, repoDir)) {
2198
+ const repoDir = path4.resolve(resolved.cwd, repoPath);
2199
+ if (name.length === 0 || path4.isAbsolute(name) || name.split(/[\\/]/).includes("..") || !insidePath(outRoot, snapshotDir2) || path4.isAbsolute(repoPath) || repoPath.split(/[\\/]/).includes("..") || !insidePath(resolved.cwd, repoDir)) {
2062
2200
  rows.push({
2063
2201
  name,
2064
2202
  score: 0,
@@ -2071,10 +2209,10 @@ ${USAGE}
2071
2209
  let canonicalSnapshot = snapshotDir2;
2072
2210
  let canonicalRepo = repoDir;
2073
2211
  try {
2074
- const outRootReal = fs2.realpathSync(outRoot);
2075
- const cwdReal = fs2.realpathSync(resolved.cwd);
2076
- canonicalSnapshot = fs2.realpathSync(snapshotDir2);
2077
- canonicalRepo = fs2.existsSync(repoDir) ? fs2.realpathSync(repoDir) : repoDir;
2212
+ const outRootReal = fs4.realpathSync(outRoot);
2213
+ const cwdReal = fs4.realpathSync(resolved.cwd);
2214
+ canonicalSnapshot = fs4.realpathSync(snapshotDir2);
2215
+ canonicalRepo = fs4.existsSync(repoDir) ? fs4.realpathSync(repoDir) : repoDir;
2078
2216
  if (!insidePath(outRootReal, canonicalSnapshot) || !insidePath(cwdReal, canonicalRepo)) {
2079
2217
  rows.push({
2080
2218
  name,
@@ -2089,7 +2227,7 @@ ${USAGE}
2089
2227
  canonicalSnapshot = snapshotDir2;
2090
2228
  canonicalRepo = repoDir;
2091
2229
  }
2092
- if (!fs2.existsSync(path3.join(snapshotDir2, "manifest.json"))) {
2230
+ if (!fs4.existsSync(path4.join(snapshotDir2, "manifest.json"))) {
2093
2231
  rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
2094
2232
  continue;
2095
2233
  }
@@ -2098,8 +2236,8 @@ ${USAGE}
2098
2236
  const memberLoaded = await loadConfigFileDetailed(canonicalRepo, {
2099
2237
  allowExecutableConfig: false
2100
2238
  });
2101
- if (memberLoaded.errors.length === 0) {
2102
- memberSecretRules = resolveConfig(memberLoaded.config, void 0, repoDir).customSecretRules ?? [];
2239
+ if (memberLoaded.errors.length === 0 && memberLoaded.config !== null) {
2240
+ memberSecretRules = resolveConfig(memberLoaded.config, { cwd: repoDir }, repoDir).customSecretRules ?? [];
2103
2241
  }
2104
2242
  } catch {
2105
2243
  }
@@ -2136,7 +2274,7 @@ ${USAGE}
2136
2274
  if (invocation.strict === true && totals.warn > 0) return 1;
2137
2275
  return 0;
2138
2276
  }
2139
- const snapshotDir = path3.resolve(resolved.cwd, resolved.outDir);
2277
+ const snapshotDir = path4.resolve(resolved.cwd, resolved.outDir);
2140
2278
  const report = auditSnapshot({
2141
2279
  snapshotDir,
2142
2280
  repoDir: resolved.cwd,
@@ -2149,13 +2287,13 @@ ${USAGE}
2149
2287
  return 0;
2150
2288
  }
2151
2289
  if (invocation.command === "report") {
2152
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2153
- if (!fs2.existsSync(manifestPath)) {
2290
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2291
+ if (!fs4.existsSync(manifestPath)) {
2154
2292
  return fail(invocation.format, `Manifest not found at ${manifestPath}. Run generate first.`);
2155
2293
  }
2156
2294
  let manifest;
2157
2295
  try {
2158
- manifest = JSON.parse(fs2.readFileSync(manifestPath, "utf8"));
2296
+ manifest = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
2159
2297
  } catch (err) {
2160
2298
  return fail(invocation.format, `Could not read ${manifestPath}: ${err.message}`);
2161
2299
  }
@@ -2212,7 +2350,7 @@ ${USAGE}
2212
2350
  if (manifest.delta !== void 0) {
2213
2351
  const delta = manifest.delta;
2214
2352
  info("\n Selection (delta):");
2215
- info(` - Against: ${path3.basename(delta.base.path)} (${delta.base.fingerprint.slice(0, 12)})`);
2353
+ info(` - Against: ${path4.basename(delta.base.path)} (${delta.base.fingerprint.slice(0, 12)})`);
2216
2354
  info(
2217
2355
  ` - Changed: ${delta.changed.length} changed, ${delta.added.length} added, ${delta.removed.length} removed, ${delta.unchanged.length} unchanged`
2218
2356
  );
@@ -2222,11 +2360,11 @@ ${USAGE}
2222
2360
  }
2223
2361
  if (invocation.command === "impact") {
2224
2362
  try {
2225
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2363
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2226
2364
  let manifest;
2227
2365
  let live = null;
2228
2366
  if (invocation.noLive) {
2229
- if (!fs2.existsSync(manifestPath)) {
2367
+ if (!fs4.existsSync(manifestPath)) {
2230
2368
  return fail(invocation.format, "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live.");
2231
2369
  }
2232
2370
  manifest = loadManifest(manifestPath);
@@ -2344,11 +2482,11 @@ ${USAGE}
2344
2482
  }
2345
2483
  if (invocation.command === "brief") {
2346
2484
  try {
2347
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2485
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2348
2486
  let manifest;
2349
2487
  let live = null;
2350
2488
  if (invocation.noLive) {
2351
- if (!fs2.existsSync(manifestPath)) {
2489
+ if (!fs4.existsSync(manifestPath)) {
2352
2490
  return fail(invocation.format, "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live.");
2353
2491
  }
2354
2492
  manifest = loadManifest(manifestPath);
@@ -2368,7 +2506,7 @@ ${USAGE}
2368
2506
  if (invocation.diff !== void 0 || question === void 0 && invocation.paths === void 0) {
2369
2507
  const ref = invocation.diff ?? "HEAD";
2370
2508
  const resolvedBase = resolveDiffBase(resolved.cwd, ref);
2371
- const diffArgs = resolvedBase === null ? ["-c", "core.quotepath=false", "-c", "diff.noprefix=false", "-c", "diff.mnemonicPrefix=false", "-c", "core.fsmonitor=false", "diff", "--cached", "--no-color", "--no-ext-diff", "--no-textconv", "-U3"] : ["-c", "core.quotepath=false", "-c", "diff.noprefix=false", "-c", "diff.mnemonicPrefix=false", "-c", "core.fsmonitor=false", "diff", "--no-color", "--no-ext-diff", "--no-textconv", "-U3", resolvedBase, "--"];
2509
+ const diffArgs = resolvedBase === null ? ["-c", "core.quotepath=false", "-c", "diff.noprefix=false", "-c", "diff.mnemonicPrefix=false", "-c", "core.fsmonitor=false", "diff", "--cached", "--no-color", "--no-ext-diff", "--no-textconv", "--relative", "-U3"] : ["-c", "core.quotepath=false", "-c", "diff.noprefix=false", "-c", "diff.mnemonicPrefix=false", "-c", "core.fsmonitor=false", "diff", "--no-color", "--no-ext-diff", "--no-textconv", "--relative", "-U3", resolvedBase, "--"];
2372
2510
  const result = spawnSync("git", diffArgs, {
2373
2511
  cwd: resolved.cwd,
2374
2512
  encoding: "utf8",
@@ -2378,6 +2516,17 @@ ${USAGE}
2378
2516
  if (result.status === 0) {
2379
2517
  const reportExcludes = [...resolved.excludePatterns, ...resolved.presetExclude];
2380
2518
  const filtered = filterAndRedactDiff(result.stdout, resolved.secretRules, {
2519
+ cwd: resolved.cwd,
2520
+ // The removed side of a hunk is not in the working tree; read it at the same ref so a
2521
+ // partially changed PEM block or block scalar is masked on both sides.
2522
+ readOld: (relativePath) => {
2523
+ const shown = spawnSync(
2524
+ "git",
2525
+ ["-c", "core.quotepath=false", "show", ref + ":" + relativePath],
2526
+ { cwd: resolved.cwd, encoding: "utf8", shell: false, maxBuffer: 64 * 1024 * 1024 }
2527
+ );
2528
+ return shown.status === 0 ? shown.stdout : null;
2529
+ },
2381
2530
  // The diff report generated by `generate` applies the repository's include/exclude
2382
2531
  // rules; `brief --diff` used to pass only the secret rules, so a tracked file the
2383
2532
  // config excluded still appeared in the review pack.
@@ -2385,7 +2534,7 @@ ${USAGE}
2385
2534
  });
2386
2535
  diffText = filtered.text;
2387
2536
  if (filtered.omittedSensitive > 0) {
2388
- diffNotes.push(filtered.omittedSensitive + " sensitive file section(s) were omitted from the diff.");
2537
+ diffNotes.push(filtered.omittedSensitive + " sensitive or excluded file section(s) were omitted from the diff.");
2389
2538
  }
2390
2539
  if (filtered.omittedUnparseable > 0) {
2391
2540
  diffNotes.push(filtered.omittedUnparseable + " unparseable file section(s) were omitted from the diff.");
@@ -2400,10 +2549,10 @@ ${USAGE}
2400
2549
  if (isSensitivePath(relativePath)) return null;
2401
2550
  const file = manifest.files.find((candidate) => candidate.relativePath === relativePath);
2402
2551
  if (file === void 0) return null;
2403
- const snapshotDir = path3.resolve(resolved.cwd, resolved.outDir);
2552
+ const snapshotDir = path4.resolve(resolved.cwd, resolved.outDir);
2404
2553
  const read = readConfinedText(
2405
2554
  snapshotDir,
2406
- path3.posix.join("parts", file.part),
2555
+ path4.posix.join("parts", file.part),
2407
2556
  16 * 1024 * 1024
2408
2557
  );
2409
2558
  if (!read.ok) return null;
@@ -2414,7 +2563,7 @@ ${USAGE}
2414
2563
  manifest,
2415
2564
  ...question === void 0 ? {} : { question },
2416
2565
  ...changes === void 0 ? {} : { changes },
2417
- ...diffText === void 0 ? {} : { diff: diffText },
2566
+ ...diffText === void 0 ? {} : { diff: diffText, diffIsRedacted: true },
2418
2567
  ...diffNotes.length === 0 ? {} : { diffNotes },
2419
2568
  readBody,
2420
2569
  secretRules: resolved.secretRules,
@@ -2428,7 +2577,7 @@ ${USAGE}
2428
2577
  });
2429
2578
  if (invocation.out !== void 0) {
2430
2579
  const written = writeInside(resolved.cwd, invocation.out, brief.markdown);
2431
- info("Wrote " + path3.relative(resolved.cwd, written));
2580
+ info("Wrote " + path4.relative(resolved.cwd, written));
2432
2581
  } else if (invocation.format !== "json") {
2433
2582
  process.stdout.write(brief.markdown);
2434
2583
  }
@@ -2504,10 +2653,10 @@ ${USAGE}
2504
2653
  "--workspace writes one snapshot per member; --remote, --delta, --slice, --budget-tokens and --sign do not combine with it."
2505
2654
  );
2506
2655
  }
2507
- const outRoot = path3.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
2508
- const workspaceCwd = path3.resolve(invocation.cwd);
2509
- const outRootRelative = path3.relative(outRoot, workspaceCwd);
2510
- if (outRootRelative === "" || outRootRelative !== ".." && !outRootRelative.startsWith(`..${path3.sep}`) && !outRootRelative.startsWith("../") && !path3.isAbsolute(outRootRelative)) {
2656
+ const outRoot = path4.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
2657
+ const workspaceCwd = path4.resolve(invocation.cwd);
2658
+ const outRootRelative = path4.relative(outRoot, workspaceCwd);
2659
+ if (outRootRelative === "" || outRootRelative !== ".." && !outRootRelative.startsWith(`..${path4.sep}`) && !outRootRelative.startsWith("../") && !path4.isAbsolute(outRootRelative)) {
2511
2660
  return fail(
2512
2661
  invocation.format,
2513
2662
  `--workspace refuses --out-dir ${outRoot}: it is the working directory or one of its ancestors.`
@@ -2515,8 +2664,8 @@ ${USAGE}
2515
2664
  }
2516
2665
  const plannedNames = /* @__PURE__ */ new Map();
2517
2666
  for (const member of members) {
2518
- const directory = path3.resolve(invocation.cwd, member);
2519
- const name = path3.basename(directory);
2667
+ const directory = path4.resolve(invocation.cwd, member);
2668
+ const name = path4.basename(directory);
2520
2669
  const previous = plannedNames.get(name);
2521
2670
  if (previous !== void 0) {
2522
2671
  return fail(
@@ -2529,11 +2678,11 @@ ${USAGE}
2529
2678
  const records = [];
2530
2679
  let failed = 0;
2531
2680
  for (const member of members) {
2532
- const directory = path3.resolve(invocation.cwd, member);
2533
- const name = path3.basename(directory);
2681
+ const directory = path4.resolve(invocation.cwd, member);
2682
+ const name = path4.basename(directory);
2534
2683
  let stat;
2535
2684
  try {
2536
- stat = fs2.statSync(directory);
2685
+ stat = fs4.statSync(directory);
2537
2686
  } catch {
2538
2687
  warn("\u26A0 Workspace member missing: " + member);
2539
2688
  failed += 1;
@@ -2550,7 +2699,7 @@ ${USAGE}
2550
2699
  {
2551
2700
  ...generateCliOptions(invocation),
2552
2701
  cwd: directory,
2553
- outDir: path3.join(outRoot, name)
2702
+ outDir: path4.join(outRoot, name)
2554
2703
  },
2555
2704
  directory
2556
2705
  );
@@ -2570,17 +2719,17 @@ ${USAGE}
2570
2719
  failed += 1;
2571
2720
  }
2572
2721
  }
2573
- if (!invocation.dryRun) fs2.mkdirSync(outRoot, { recursive: true });
2722
+ if (!invocation.dryRun) fs4.mkdirSync(outRoot, { recursive: true });
2574
2723
  const links = [];
2575
2724
  for (const record of records) {
2576
2725
  const counts = /* @__PURE__ */ new Map();
2577
2726
  for (const entry of record.imports) {
2578
2727
  for (const specifier of entry.imports) {
2579
2728
  if (!specifier.startsWith(".")) continue;
2580
- const resolved2 = path3.resolve(record.path, path3.dirname(entry.path), specifier);
2729
+ const resolved2 = path4.resolve(record.path, path4.dirname(entry.path), specifier);
2581
2730
  for (const other of records) {
2582
2731
  if (other === record) continue;
2583
- const prefix = other.path + path3.sep;
2732
+ const prefix = other.path + path4.sep;
2584
2733
  if (!resolved2.startsWith(prefix) && resolved2 !== other.path) continue;
2585
2734
  const bucket = counts.get(other.name) ?? { count: 0, examples: [] };
2586
2735
  bucket.count += 1;
@@ -2605,14 +2754,14 @@ ${USAGE}
2605
2754
  // Store the member path relative to the workspace cwd, as manifest paths already are.
2606
2755
  members: records.map(({ imports: _imports, ...rest }) => ({
2607
2756
  ...rest,
2608
- path: path3.relative(workspaceCwd, rest.path).split(path3.sep).join("/") || "."
2757
+ path: path4.relative(workspaceCwd, rest.path).split(path4.sep).join("/") || "."
2609
2758
  })),
2610
2759
  links
2611
2760
  };
2612
2761
  if (!invocation.dryRun) {
2613
- const workspacePath = path3.join(outRoot, "WORKSPACE.json");
2762
+ const workspacePath = path4.join(outRoot, "WORKSPACE.json");
2614
2763
  try {
2615
- const stats = fs2.lstatSync(workspacePath);
2764
+ const stats = fs4.lstatSync(workspacePath);
2616
2765
  if (stats.isSymbolicLink() || !stats.isFile()) {
2617
2766
  return fail(invocation.format, `${workspacePath} is not a regular file; refusing to replace it.`);
2618
2767
  }
@@ -2621,11 +2770,11 @@ ${USAGE}
2621
2770
  }
2622
2771
  const tempPath = `${workspacePath}.${process.pid}.${Date.now()}.tmp`;
2623
2772
  try {
2624
- fs2.writeFileSync(tempPath, JSON.stringify(document, null, 2) + "\n", "utf8");
2625
- fs2.renameSync(tempPath, workspacePath);
2773
+ fs4.writeFileSync(tempPath, JSON.stringify(document, null, 2) + "\n", "utf8");
2774
+ fs4.renameSync(tempPath, workspacePath);
2626
2775
  } catch (error) {
2627
2776
  try {
2628
- fs2.rmSync(tempPath, { force: true });
2777
+ fs4.rmSync(tempPath, { force: true });
2629
2778
  } catch {
2630
2779
  }
2631
2780
  throw error;
@@ -2653,14 +2802,14 @@ ${USAGE}
2653
2802
  try {
2654
2803
  let deltaBase;
2655
2804
  if (invocation.delta !== void 0) {
2656
- const basePath = path3.resolve(invocation.cwd, invocation.delta);
2657
- const manifestPath = fs2.existsSync(basePath) && fs2.statSync(basePath).isDirectory() ? path3.join(basePath, "manifest.json") : basePath;
2658
- if (!fs2.existsSync(manifestPath)) {
2805
+ const basePath = path4.resolve(invocation.cwd, invocation.delta);
2806
+ const manifestPath = fs4.existsSync(basePath) && fs4.statSync(basePath).isDirectory() ? path4.join(basePath, "manifest.json") : basePath;
2807
+ if (!fs4.existsSync(manifestPath)) {
2659
2808
  return fail(invocation.format, "No manifest at " + manifestPath + ". Point --delta at a snapshot directory or its manifest.json.");
2660
2809
  }
2661
2810
  let base;
2662
2811
  try {
2663
- base = JSON.parse(fs2.readFileSync(manifestPath, "utf8"));
2812
+ base = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
2664
2813
  } catch (error) {
2665
2814
  return fail(invocation.format, "Could not read " + manifestPath + ": " + error.message);
2666
2815
  }
@@ -2668,8 +2817,8 @@ ${USAGE}
2668
2817
  if (shape !== null) {
2669
2818
  return fail(invocation.format, manifestPath + " is not a snapshot manifest: " + shape);
2670
2819
  }
2671
- const relativeBase = path3.relative(invocation.cwd, manifestPath).split(path3.sep).join("/");
2672
- const recordedBase = relativeBase === "" || relativeBase === ".." || relativeBase.startsWith(`..${path3.sep}`) || relativeBase.startsWith("../") || path3.isAbsolute(relativeBase) ? path3.basename(manifestPath) : relativeBase;
2820
+ const relativeBase = path4.relative(invocation.cwd, manifestPath).split(path4.sep).join("/");
2821
+ const recordedBase = relativeBase === "" || relativeBase === ".." || relativeBase.startsWith(`..${path4.sep}`) || relativeBase.startsWith("../") || path4.isAbsolute(relativeBase) ? path4.basename(manifestPath) : relativeBase;
2673
2822
  deltaBase = { manifest: base, path: recordedBase };
2674
2823
  info(" Delta base: " + recordedBase + " (" + base.files.length + " files, fingerprint " + base.fingerprint.slice(0, 12) + ")");
2675
2824
  }
@@ -2687,9 +2836,9 @@ ${USAGE}
2687
2836
  ...invocation.sign === true && !invocation.dryRun ? { sign: { key: loadSigningKey() } } : {}
2688
2837
  });
2689
2838
  if (invocation.sign === true && !invocation.dryRun) {
2690
- const signaturePath = path3.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
2839
+ const signaturePath = path4.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
2691
2840
  try {
2692
- const record = JSON.parse(fs2.readFileSync(signaturePath, "utf8"));
2841
+ const record = JSON.parse(fs4.readFileSync(signaturePath, "utf8"));
2693
2842
  info(
2694
2843
  " Signature: ed25519, " + (record.keyOrigin ?? "unknown") + " key, " + (record.fingerprint ?? manifest.fingerprint).slice(0, 12)
2695
2844
  );
@@ -2842,19 +2991,19 @@ function finishWatchRun(state, now) {
2842
2991
  };
2843
2992
  }
2844
2993
  function comparablePath(value) {
2845
- const absolute = path3.resolve(value);
2994
+ const absolute = path4.resolve(value);
2846
2995
  return process.platform === "win32" ? absolute.toLowerCase() : absolute;
2847
2996
  }
2848
2997
  function isSameOrInside(parent, candidate) {
2849
- const relative4 = path3.relative(parent, candidate);
2850
- return relative4 === "" || relative4 !== ".." && !relative4.startsWith(`..${path3.sep}`) && !path3.isAbsolute(relative4);
2998
+ const relative5 = path4.relative(parent, candidate);
2999
+ return relative5 === "" || relative5 !== ".." && !relative5.startsWith(`..${path4.sep}`) && !path4.isAbsolute(relative5);
2851
3000
  }
2852
3001
  function isGeneratedWatchPath(candidate, paths) {
2853
- const absolute = comparablePath(path3.resolve(paths.cwd, candidate));
2854
- const outDir = comparablePath(path3.resolve(paths.cwd, paths.outDir));
2855
- const tmpDir = comparablePath(path3.resolve(paths.cwd, paths.tmpDir));
3002
+ const absolute = comparablePath(path4.resolve(paths.cwd, candidate));
3003
+ const outDir = comparablePath(path4.resolve(paths.cwd, paths.outDir));
3004
+ const tmpDir = comparablePath(path4.resolve(paths.cwd, paths.tmpDir));
2856
3005
  if (isSameOrInside(outDir, absolute) || isSameOrInside(tmpDir, absolute)) return true;
2857
- const offsets = [path3.basename(outDir), path3.basename(tmpDir)].filter((name) => name.length > 0);
3006
+ const offsets = [path4.basename(outDir), path4.basename(tmpDir)].filter((name) => name.length > 0);
2858
3007
  const leftover = absolute.split(/[\\/]+/).some(
2859
3008
  (segment) => offsets.some(
2860
3009
  (name) => segment.startsWith(`${name}.backup-`) || segment.startsWith(`${name}.partial-`)
@@ -2877,8 +3026,8 @@ function decideWatchEvent(state, event, paths) {
2877
3026
  function watchPathsFor(config) {
2878
3027
  return {
2879
3028
  cwd: config.cwd,
2880
- outDir: path3.resolve(config.cwd, config.outDir),
2881
- tmpDir: path3.resolve(config.cwd, config.tmpDir)
3029
+ outDir: path4.resolve(config.cwd, config.outDir),
3030
+ tmpDir: path4.resolve(config.cwd, config.tmpDir)
2882
3031
  };
2883
3032
  }
2884
3033
  function watchSupportProblem(platform = process.platform, version = process.versions.node) {
@@ -2952,11 +3101,11 @@ async function runWatchLoop(invocation, resolved, options) {
2952
3101
  info("\u{1F440} Watching for changes. Press Ctrl+C to stop.");
2953
3102
  let watcher;
2954
3103
  try {
2955
- watcher = fs2.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
3104
+ watcher = fs4.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
2956
3105
  const decision = decideWatchEvent(
2957
3106
  state,
2958
3107
  {
2959
- path: filename ? path3.resolve(resolved.cwd, filename.toString()) : null,
3108
+ path: filename ? path4.resolve(resolved.cwd, filename.toString()) : null,
2960
3109
  now: performance.now()
2961
3110
  },
2962
3111
  paths
@@ -2982,12 +3131,12 @@ async function runWatchLoop(invocation, resolved, options) {
2982
3131
  info(`\u26A0 Watch error: ${err.message}`);
2983
3132
  info(" The watcher may have missed changes. Restart with Ctrl+C if they stop arriving.");
2984
3133
  });
2985
- await new Promise((resolve3) => {
3134
+ await new Promise((resolve4) => {
2986
3135
  const stop = () => {
2987
3136
  stopped = true;
2988
3137
  if (timer) clearTimeout(timer);
2989
3138
  watcher.close();
2990
- resolve3();
3139
+ resolve4();
2991
3140
  };
2992
3141
  process.once("SIGINT", stop);
2993
3142
  process.once("SIGTERM", stop);
@@ -2997,12 +3146,12 @@ async function runWatchLoop(invocation, resolved, options) {
2997
3146
  var entryFile = process.argv[1] ?? "";
2998
3147
  var sameFile = (left, right) => {
2999
3148
  try {
3000
- return fs2.realpathSync(path3.resolve(left)) === fs2.realpathSync(path3.resolve(right));
3149
+ return fs4.realpathSync(path4.resolve(left)) === fs4.realpathSync(path4.resolve(right));
3001
3150
  } catch {
3002
3151
  return false;
3003
3152
  }
3004
3153
  };
3005
- var entryName = path3.basename(entryFile).toLowerCase();
3154
+ var entryName = path4.basename(entryFile).toLowerCase();
3006
3155
  var invokedDirectly = (entryName === "cli.js" || entryName === "cli.cjs") && entryFile.length > 0 && sameFile(entryFile, fileURLToPath(import.meta.url));
3007
3156
  if (invokedDirectly) {
3008
3157
  void main().then(