codebase-snapshot 0.22.1 → 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,15 +1,16 @@
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, 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-7AAXOTKS.js';
3
- export { buildAgentContract } from './chunk-7AAXOTKS.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 fs3 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) };
@@ -32,7 +33,7 @@ function testGap(entry) {
32
33
  function routeGap(entry) {
33
34
  return { kind: "route", path: safePath(entry.path), methods: [...entry.methods] };
34
35
  }
35
- function buildGuardReport(impact) {
36
+ function buildGuardReport(impact, documentation = []) {
36
37
  const changedSet = new Set(impact.changed.map((entry) => entry.path));
37
38
  const changed = impact.changed.map((entry) => safePath(entry.path));
38
39
  const consumers = impact.affected.filter((entry) => !changedSet.has(entry.path));
@@ -41,10 +42,16 @@ function buildGuardReport(impact) {
41
42
  const consumerPart = take(consumers, MAX_CONSUMERS);
42
43
  const testPart = take(tests, MAX_TESTS);
43
44
  const routePart = take(routes, MAX_ROUTES);
45
+ const documentationPart = take(documentation, MAX_DOCUMENTATION);
44
46
  const gaps = [
45
47
  ...consumerPart.taken.map(toGap),
46
48
  ...testPart.taken.map(testGap),
47
- ...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
+ }))
48
55
  ];
49
56
  const symbolPruned = impact.affected.some(
50
57
  (entry) => entry.impactKind === "direct-symbol" || entry.impactKind === "reexport" || entry.impactKind === "namespace-or-cjs"
@@ -55,17 +62,19 @@ function buildGuardReport(impact) {
55
62
  gaps,
56
63
  trust: impact.trust,
57
64
  confidence: symbolPruned ? "symbol-pruned" : "file-import",
58
- truncated: impact.truncated || consumerPart.omitted > 0 || testPart.omitted > 0 || routePart.omitted > 0,
65
+ truncated: impact.truncated || consumerPart.omitted > 0 || testPart.omitted > 0 || routePart.omitted > 0 || documentationPart.omitted > 0,
59
66
  omitted: {
60
67
  consumers: consumerPart.omitted,
61
68
  tests: testPart.omitted,
62
- routes: routePart.omitted
69
+ routes: routePart.omitted,
70
+ documentation: documentationPart.omitted
63
71
  }
64
72
  };
65
73
  }
66
74
  function label(gap) {
67
75
  if (gap.kind === "test") return "test";
68
76
  if (gap.kind === "route") return "route";
77
+ if (gap.kind === "documentation") return "docs";
69
78
  return "consumer";
70
79
  }
71
80
  function renderGuardText(report) {
@@ -84,6 +93,8 @@ function renderGuardText(report) {
84
93
  if (meta.length > 0) parts.push("(" + meta.join(", ") + ")");
85
94
  } else if (gap.kind === "test") {
86
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(", ") : "") + ")");
87
98
  } else {
88
99
  parts.push("(route" + (gap.methods && gap.methods.length > 0 ? ": " + gap.methods.join(", ") : "") + ")");
89
100
  }
@@ -92,7 +103,7 @@ function renderGuardText(report) {
92
103
  if (report.truncated) {
93
104
  const omitted = report.omitted;
94
105
  lines.push(
95
- " \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"
96
107
  );
97
108
  }
98
109
  lines.push(" coverage: " + report.trust.coverage + " \xB7 confidence: " + report.confidence);
@@ -114,6 +125,8 @@ function renderGuardHookText(report, maxChars = MAX_HOOK_CHARS) {
114
125
  );
115
126
  } else if (gap.kind === "test") {
116
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(", ") + ")" : ""));
117
130
  } else {
118
131
  lines.push(" route " + gap.path + (gap.methods && gap.methods.length > 0 ? " (" + gap.methods.join(", ") + ")" : ""));
119
132
  }
@@ -137,24 +150,24 @@ function renderGuardHook(report, client, event, maxChars = MAX_HOOK_CHARS) {
137
150
  }
138
151
  function canonicalForRelative(target) {
139
152
  try {
140
- return fs3.realpathSync.native(target);
153
+ return fs4.realpathSync.native(target);
141
154
  } catch {
142
155
  try {
143
- return path3.join(fs3.realpathSync.native(path3.dirname(target)), path3.basename(target));
156
+ return path4.join(fs4.realpathSync.native(path4.dirname(target)), path4.basename(target));
144
157
  } catch {
145
- return path3.resolve(target);
158
+ return path4.resolve(target);
146
159
  }
147
160
  }
148
161
  }
149
162
  function normalizePath(cwd, raw) {
150
163
  const value = raw.trim();
151
164
  if (value.length === 0 || value.includes("\0")) return null;
152
- const absolute = path3.isAbsolute(value) ? value : path3.resolve(cwd, value);
153
- const relative4 = path3.relative(canonicalForRelative(cwd), canonicalForRelative(absolute)).split(path3.sep).join("/");
154
- 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)) {
155
168
  return null;
156
169
  }
157
- return relative4;
170
+ return relative5;
158
171
  }
159
172
  function collectPaths(value, out, depth = 0) {
160
173
  if (depth > 6 || value === null || typeof value !== "object") return;
@@ -227,25 +240,75 @@ function parseGuardHookInput(client, raw, cwd) {
227
240
  event
228
241
  };
229
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
+ }
230
293
  var SKILL_TARGETS = ["agents", "claude", "cursor", "all"];
231
294
  var REFUSED = "Refusing to install the agent skill";
232
295
  var LEGACY_AGENTS_MARKER = "<!-- codebase-snapshot:skill:start -->";
233
296
  function targetPath(cwd, target) {
234
297
  switch (target) {
235
298
  case "agents":
236
- return path3.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
299
+ return path4.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
237
300
  case "claude":
238
- return path3.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
301
+ return path4.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
239
302
  case "cursor":
240
- return path3.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
303
+ return path4.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
241
304
  }
242
305
  }
243
306
  function assertWritableInsideRepository(cwd, filePath) {
244
- const root = fs3.realpathSync(cwd);
245
- const shown = path3.relative(root, filePath) || filePath;
307
+ const root = fs4.realpathSync(cwd);
308
+ const shown = path4.relative(root, filePath) || filePath;
246
309
  let stat = null;
247
310
  try {
248
- stat = fs3.lstatSync(filePath);
311
+ stat = fs4.lstatSync(filePath);
249
312
  } catch {
250
313
  stat = null;
251
314
  }
@@ -261,32 +324,32 @@ function assertWritableInsideRepository(cwd, filePath) {
261
324
  }
262
325
  let existing = filePath;
263
326
  const missing = [];
264
- while (!fs3.existsSync(existing)) {
265
- missing.unshift(path3.basename(existing));
266
- const parent = path3.dirname(existing);
327
+ while (!fs4.existsSync(existing)) {
328
+ missing.unshift(path4.basename(existing));
329
+ const parent = path4.dirname(existing);
267
330
  if (parent === existing) break;
268
331
  existing = parent;
269
332
  }
270
- const realAncestor = fs3.realpathSync(existing);
271
- const resolved = missing.length === 0 ? realAncestor : path3.join(realAncestor, ...missing);
272
- 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}`)) {
273
336
  throw new Error(
274
337
  `${REFUSED}: ${shown} resolves outside the repository (${resolved}). Move it back inside ${root}, or remove the link, and run again.`
275
338
  );
276
339
  }
277
340
  }
278
341
  function writeIfChanged(target, filePath, content) {
279
- const existing = fs3.existsSync(filePath) ? fs3.readFileSync(filePath, "utf8") : null;
342
+ const existing = fs4.existsSync(filePath) ? fs4.readFileSync(filePath, "utf8") : null;
280
343
  if (existing === content) return { target, path: filePath, action: "unchanged" };
281
- fs3.mkdirSync(path3.dirname(filePath), { recursive: true });
282
- fs3.writeFileSync(filePath, content, "utf8");
344
+ fs4.mkdirSync(path4.dirname(filePath), { recursive: true });
345
+ fs4.writeFileSync(filePath, content, "utf8");
283
346
  return { target, path: filePath, action: existing === null ? "created" : "updated" };
284
347
  }
285
348
  function legacyAgentsNote(cwd) {
286
- const filePath = path3.join(cwd, "AGENTS.md");
349
+ const filePath = path4.join(cwd, "AGENTS.md");
287
350
  try {
288
- if (!fs3.existsSync(filePath)) return null;
289
- if (!fs3.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;
290
353
  } catch {
291
354
  return null;
292
355
  }
@@ -298,9 +361,9 @@ function installSkill(cwd, target = "all", options = {}) {
298
361
  const notes = [];
299
362
  const wanted = target === "all" ? ["agents", "claude", "cursor"] : [target];
300
363
  for (const item of wanted) assertWritableInsideRepository(cwd, targetPath(cwd, item));
301
- const createsSomething = wanted.some((item) => !fs3.existsSync(targetPath(cwd, item)));
364
+ const createsSomething = wanted.some((item) => !fs4.existsSync(targetPath(cwd, item)));
302
365
  if (createsSomething) {
303
- assertWritableInsideRepository(cwd, path3.join(cwd, ".gitignore"));
366
+ assertWritableInsideRepository(cwd, path4.join(cwd, ".gitignore"));
304
367
  }
305
368
  const pendingMcp = options.withMcp === true ? prepareMcpConfig(cwd) : null;
306
369
  for (const item of wanted) {
@@ -315,20 +378,20 @@ function installSkill(cwd, target = "all", options = {}) {
315
378
  if (pendingMcp !== null) {
316
379
  if (pendingMcp.note !== null) notes.push(pendingMcp.note);
317
380
  if (pendingMcp.content !== null) {
318
- fs3.writeFileSync(pendingMcp.filePath, pendingMcp.content, "utf8");
381
+ fs4.writeFileSync(pendingMcp.filePath, pendingMcp.content, "utf8");
319
382
  }
320
383
  mcp = { path: pendingMcp.filePath, action: pendingMcp.action };
321
384
  }
322
385
  return { cwd, written, gitignored: ignore.added, notes, ...mcp === void 0 ? {} : { mcp } };
323
386
  }
324
387
  function prepareMcpConfig(cwd) {
325
- const filePath = path3.join(cwd, ".mcp.json");
388
+ const filePath = path4.join(cwd, ".mcp.json");
326
389
  assertWritableInsideRepository(cwd, filePath);
327
390
  const desired = { command: "npx", args: ["-y", "codebase-snapshot@latest", "mcp"] };
328
391
  let parsed = {};
329
392
  let existing = null;
330
- if (fs3.existsSync(filePath)) {
331
- existing = fs3.readFileSync(filePath, "utf8");
393
+ if (fs4.existsSync(filePath)) {
394
+ existing = fs4.readFileSync(filePath, "utf8");
332
395
  let candidate;
333
396
  try {
334
397
  candidate = JSON.parse(existing);
@@ -768,10 +831,10 @@ function parseCliArgs(argv) {
768
831
  }
769
832
  if (values.cwd !== void 0) {
770
833
  const target = String(values.cwd);
771
- if (!fs3.existsSync(target)) {
834
+ if (!fs4.existsSync(target)) {
772
835
  throw new UsageError(`--cwd directory does not exist: ${target}`);
773
836
  }
774
- if (!fs3.statSync(target).isDirectory()) {
837
+ if (!fs4.statSync(target).isDirectory()) {
775
838
  throw new UsageError(`--cwd is not a directory: ${target}`);
776
839
  }
777
840
  }
@@ -1012,7 +1075,7 @@ function parseCliArgs(argv) {
1012
1075
  install: values.install === true,
1013
1076
  noInstall: values["no-install"] === true,
1014
1077
  target: values.target === void 0 ? void 0 : String(values.target),
1015
- 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)),
1016
1079
  outDir: values["out-dir"] === void 0 ? void 0 : String(values["out-dir"]),
1017
1080
  includeMonolith: values["include-monolith"] === true || onlyNamesMonolith === true ? true : void 0,
1018
1081
  includeSensitiveFiles: values["include-sensitive-files"] === true ? true : void 0,
@@ -1195,45 +1258,45 @@ function renderImpactMarkdown(report) {
1195
1258
  }
1196
1259
  function realPathInside(realRoot, candidate) {
1197
1260
  const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
1198
- const relative4 = path3.relative(fold(realRoot), fold(candidate));
1199
- 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);
1200
1263
  }
1201
- function writeInside(root, relative4, content) {
1202
- const target = path3.resolve(root, relative4);
1203
- const rel = path3.relative(path3.resolve(root), target);
1204
- 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)) {
1205
1268
  throw new Error("--out must resolve inside the repository.");
1206
1269
  }
1207
- const parent = path3.dirname(target);
1208
- const realRoot = fs3.realpathSync(root);
1270
+ const parent = path4.dirname(target);
1271
+ const realRoot = fs4.realpathSync(root);
1209
1272
  let existingAncestor = parent;
1210
- while (!fs3.existsSync(existingAncestor)) {
1211
- const next = path3.dirname(existingAncestor);
1273
+ while (!fs4.existsSync(existingAncestor)) {
1274
+ const next = path4.dirname(existingAncestor);
1212
1275
  if (next === existingAncestor) break;
1213
1276
  existingAncestor = next;
1214
1277
  }
1215
- if (!realPathInside(realRoot, fs3.realpathSync(existingAncestor))) {
1278
+ if (!realPathInside(realRoot, fs4.realpathSync(existingAncestor))) {
1216
1279
  throw new Error("--out resolves outside the repository through a link.");
1217
1280
  }
1218
- fs3.mkdirSync(parent, { recursive: true });
1219
- if (!realPathInside(realRoot, fs3.realpathSync(parent))) {
1281
+ fs4.mkdirSync(parent, { recursive: true });
1282
+ if (!realPathInside(realRoot, fs4.realpathSync(parent))) {
1220
1283
  throw new Error("--out resolves outside the repository through a link.");
1221
1284
  }
1222
1285
  try {
1223
- const existing = fs3.lstatSync(target);
1286
+ const existing = fs4.lstatSync(target);
1224
1287
  if (existing.isSymbolicLink() || !existing.isFile() || existing.nlink > 1) {
1225
1288
  throw new Error("--out must be a regular file that is not a symbolic or hard link.");
1226
1289
  }
1227
1290
  } catch (error) {
1228
1291
  if (error.code !== "ENOENT") throw error;
1229
1292
  }
1230
- const temporary = path3.join(parent, "." + path3.basename(target) + ".tmp-" + process.pid + "-" + Math.random().toString(16).slice(2));
1231
- fs3.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 });
1232
1295
  try {
1233
- fs3.renameSync(temporary, target);
1296
+ fs4.renameSync(temporary, target);
1234
1297
  } catch (error) {
1235
1298
  try {
1236
- fs3.unlinkSync(temporary);
1299
+ fs4.unlinkSync(temporary);
1237
1300
  } catch (cleanupError) {
1238
1301
  warn("Could not remove temporary file " + temporary + ": " + cleanupError.message);
1239
1302
  }
@@ -1256,10 +1319,10 @@ function splitList(value) {
1256
1319
  return value.split(",").map((entry) => entry.trim()).filter(Boolean);
1257
1320
  }
1258
1321
  function displayOutPath(cwd, outDir, ...segments) {
1259
- const absolute = path3.resolve(cwd, outDir, ...segments);
1260
- const relative4 = path3.relative(cwd, absolute);
1261
- if (relative4 !== "" && relative4 !== ".." && !relative4.startsWith(`..${path3.sep}`) && !relative4.startsWith("../") && !path3.isAbsolute(relative4)) {
1262
- 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;
1263
1326
  }
1264
1327
  return absolute;
1265
1328
  }
@@ -1268,7 +1331,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
1268
1331
  if (!hasScript) {
1269
1332
  try {
1270
1333
  const parsed = JSON.parse(
1271
- stripJsonComments(fs3.readFileSync(path3.join(cwd, "package.json"), "utf8"))
1334
+ stripJsonComments(fs4.readFileSync(path4.join(cwd, "package.json"), "utf8"))
1272
1335
  );
1273
1336
  hasScript = typeof parsed.scripts?.snapshot === "string";
1274
1337
  } catch {
@@ -1276,8 +1339,8 @@ function nextStepHint(cwd, scriptsAddedNow) {
1276
1339
  }
1277
1340
  }
1278
1341
  if (!hasScript) return `npx ${GENERATOR_NAME} generate`;
1279
- const bin = path3.join(cwd, "node_modules", ".bin", "codebase-snapshot");
1280
- const installed = fs3.existsSync(bin) || fs3.existsSync(`${bin}.cmd`);
1342
+ const bin = path4.join(cwd, "node_modules", ".bin", "codebase-snapshot");
1343
+ const installed = fs4.existsSync(bin) || fs4.existsSync(`${bin}.cmd`);
1281
1344
  return installed ? "npm run snapshot" : "npm install && npm run snapshot";
1282
1345
  }
1283
1346
  function presetSummary(init) {
@@ -1313,7 +1376,7 @@ async function runInitCommand(invocation) {
1313
1376
  if (hook) for (const note of hook.notes) info(` ${note}`);
1314
1377
  return 0;
1315
1378
  }
1316
- info(`\u2705 Created ${path3.basename(result.configPath)} (${presetSummary(result)})`);
1379
+ info(`\u2705 Created ${path4.basename(result.configPath)} (${presetSummary(result)})`);
1317
1380
  if (result.scripts.length > 0) info(` Added npm scripts: ${result.scripts.join(", ")}`);
1318
1381
  if (result.dependency.added && result.dependency.range !== null) {
1319
1382
  info(` Added devDependency: ${result.dependency.name} ${result.dependency.range}`);
@@ -1323,10 +1386,10 @@ async function runInitCommand(invocation) {
1323
1386
  }
1324
1387
  if (result.briefWritten) {
1325
1388
  info(
1326
- ` 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.`
1327
1390
  );
1328
- } else if (fs3.existsSync(result.briefPath)) {
1329
- 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.`);
1330
1393
  }
1331
1394
  for (const note of result.notes) info(` \u26A0 ${note}`);
1332
1395
  if (hook) for (const note of hook.notes) info(` ${note}`);
@@ -1363,18 +1426,18 @@ function renderHealthText(report) {
1363
1426
  function generatorOrigin(cwd) {
1364
1427
  try {
1365
1428
  const pkg = JSON.parse(
1366
- stripJsonComments(fs3.readFileSync(path3.join(cwd, "package.json"), "utf8"))
1429
+ stripJsonComments(fs4.readFileSync(path4.join(cwd, "package.json"), "utf8"))
1367
1430
  );
1368
1431
  const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
1369
1432
  if (typeof spec === "string") return `project dependency ${spec}`;
1370
1433
  } catch {
1371
1434
  }
1372
1435
  const entry = process.argv[1] ?? "";
1373
- 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";
1374
1437
  return "global or direct install";
1375
1438
  }
1376
1439
  function detectPackageManager(cwd) {
1377
- const has = (name) => fs3.existsSync(path3.join(cwd, name));
1440
+ const has = (name) => fs4.existsSync(path4.join(cwd, name));
1378
1441
  if (has("bun.lockb") || has("bun.lock")) return { name: "bun", command: "bun", args: ["install"] };
1379
1442
  if (has("pnpm-lock.yaml")) return { name: "pnpm", command: "pnpm", args: ["install"] };
1380
1443
  if (has("yarn.lock")) return { name: "yarn", command: "yarn", args: ["install"] };
@@ -1491,7 +1554,7 @@ async function runSetupCommand(invocation, options = {}) {
1491
1554
  }
1492
1555
  info("\n\u{1F9EA} Dry run \u2014 setup would:");
1493
1556
  info(
1494
- ` 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})`}`
1495
1558
  );
1496
1559
  info(" 2. add the npm scripts, the devDependency and the .gitignore entries");
1497
1560
  if (manager !== null) info(` 3. install with ${manager}`);
@@ -1504,9 +1567,9 @@ async function runSetupCommand(invocation, options = {}) {
1504
1567
  if (invocation.format !== "json") {
1505
1568
  if (!interactive) info(`\u{1F680} Setup for: ${invocation.cwd}`);
1506
1569
  if (init.reused) {
1507
- info(`\u267B Keeping ${path3.basename(keptConfigPath)}`);
1570
+ info(`\u267B Keeping ${path4.basename(keptConfigPath)}`);
1508
1571
  } else {
1509
- info(`\u2705 Created ${path3.basename(keptConfigPath)} (${presetSummary(init)})`);
1572
+ info(`\u2705 Created ${path4.basename(keptConfigPath)} (${presetSummary(init)})`);
1510
1573
  }
1511
1574
  if (init.scripts.length > 0) info(` Added npm scripts: ${init.scripts.join(", ")}`);
1512
1575
  if (init.dependency.added && init.dependency.range !== null) {
@@ -1517,7 +1580,7 @@ async function runSetupCommand(invocation, options = {}) {
1517
1580
  }
1518
1581
  if (init.briefWritten) {
1519
1582
  info(
1520
- ` 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.`
1521
1584
  );
1522
1585
  }
1523
1586
  if (hook) for (const note of hook.notes) info(` ${note}`);
@@ -1525,7 +1588,7 @@ async function runSetupCommand(invocation, options = {}) {
1525
1588
  info(` \u26A0 --preset ${invocation.preset} was not applied: the existing config is kept.`);
1526
1589
  }
1527
1590
  }
1528
- const hasManifest = fs3.existsSync(path3.join(invocation.cwd, "package.json"));
1591
+ const hasManifest = fs4.existsSync(path4.join(invocation.cwd, "package.json"));
1529
1592
  let install = null;
1530
1593
  if (invocation.noInstall) {
1531
1594
  if (invocation.format !== "json") info(" Skipped the install (--no-install)");
@@ -1690,7 +1753,7 @@ function runSkillCommand(invocation) {
1690
1753
  }
1691
1754
  info(`\u2705 Agent skill installed (${SKILL_NAME}):`);
1692
1755
  for (const item of result.written) {
1693
- const shown = path3.relative(invocation.cwd, item.path) || item.path;
1756
+ const shown = path4.relative(invocation.cwd, item.path) || item.path;
1694
1757
  info(` - ${item.action.padEnd(9)} ${shown}`);
1695
1758
  }
1696
1759
  if (result.gitignored.length > 0) {
@@ -1699,7 +1762,7 @@ function runSkillCommand(invocation) {
1699
1762
  info(" These files are this tool's own documentation, so they stay out of git.");
1700
1763
  }
1701
1764
  if (result.mcp !== void 0) {
1702
- 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;
1703
1766
  info(` - ${result.mcp.action.padEnd(9)} ${shown} (codebase-snapshot MCP entry)`);
1704
1767
  }
1705
1768
  for (const note of result.notes) info(` \u26A0 ${note}`);
@@ -1803,11 +1866,11 @@ async function runGuardCommand(invocation, resolved) {
1803
1866
  const changes = resolveImpactChanges(resolved.cwd, {
1804
1867
  ...paths === void 0 ? { diff: invocation.diff ?? "HEAD" } : { paths }
1805
1868
  });
1806
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
1869
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
1807
1870
  let manifest;
1808
1871
  let trust;
1809
1872
  if (invocation.noLive) {
1810
- if (!fs3.existsSync(manifestPath)) {
1873
+ if (!fs4.existsSync(manifestPath)) {
1811
1874
  if (client !== void 0) {
1812
1875
  warn("guard: no snapshot manifest; the hook was skipped.");
1813
1876
  process.stdout.write("{}\n");
@@ -1833,7 +1896,12 @@ async function runGuardCommand(invocation, resolved) {
1833
1896
  ...invocation.depth === void 0 ? {} : { depth: invocation.depth },
1834
1897
  ...invocation.maxResults === void 0 ? {} : { maxResults: invocation.maxResults }
1835
1898
  });
1836
- 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);
1837
1905
  if (client !== void 0) {
1838
1906
  process.stdout.write(renderGuardHook(report, client, event, invocation.maxChars ?? 1200) + "\n");
1839
1907
  return 0;
@@ -1936,7 +2004,7 @@ ${USAGE}
1936
2004
  }
1937
2005
  if (invocation.command === "serve") {
1938
2006
  const server = await startWebServer({
1939
- cwd: path3.resolve(invocation.cwd),
2007
+ cwd: path4.resolve(invocation.cwd),
1940
2008
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1941
2009
  ...invocation.port === void 0 ? {} : { port: invocation.port },
1942
2010
  ...tokenOption,
@@ -1951,9 +2019,9 @@ ${USAGE}
1951
2019
  } else {
1952
2020
  warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
1953
2021
  }
1954
- await new Promise((resolve3) => {
2022
+ await new Promise((resolve4) => {
1955
2023
  const stop = () => {
1956
- void server.close().then(resolve3);
2024
+ void server.close().then(resolve4);
1957
2025
  };
1958
2026
  process.once("SIGINT", stop);
1959
2027
  process.once("SIGTERM", stop);
@@ -1963,7 +2031,7 @@ ${USAGE}
1963
2031
  if (invocation.command === "mcp") {
1964
2032
  if (invocation.http === true) {
1965
2033
  const transport = await startHttpTransport({
1966
- cwd: path3.resolve(invocation.cwd),
2034
+ cwd: path4.resolve(invocation.cwd),
1967
2035
  noConfig: invocation.noConfig,
1968
2036
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1969
2037
  ...invocation.port === void 0 ? {} : { port: invocation.port },
@@ -1979,9 +2047,9 @@ ${USAGE}
1979
2047
  } else {
1980
2048
  warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
1981
2049
  }
1982
- await new Promise((resolve3) => {
2050
+ await new Promise((resolve4) => {
1983
2051
  const stop = () => {
1984
- void transport.close().then(resolve3);
2052
+ void transport.close().then(resolve4);
1985
2053
  };
1986
2054
  process.once("SIGINT", stop);
1987
2055
  process.once("SIGTERM", stop);
@@ -1989,7 +2057,7 @@ ${USAGE}
1989
2057
  return 0;
1990
2058
  }
1991
2059
  return await runStdioServer({
1992
- cwd: path3.resolve(invocation.cwd),
2060
+ cwd: path4.resolve(invocation.cwd),
1993
2061
  noConfig: invocation.noConfig
1994
2062
  });
1995
2063
  }
@@ -2019,8 +2087,8 @@ ${USAGE}
2019
2087
  log: (line) => info(" " + line)
2020
2088
  });
2021
2089
  sourceProvenance = clone.provenance;
2022
- const outDir = path3.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
2023
- const delta = invocation.delta === void 0 ? void 0 : path3.resolve(invocation.cwd, invocation.delta);
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);
2024
2092
  invocation = {
2025
2093
  ...invocation,
2026
2094
  cwd: clone.directory,
@@ -2037,7 +2105,7 @@ ${USAGE}
2037
2105
  const directory = clone.directory;
2038
2106
  process.once("exit", () => {
2039
2107
  try {
2040
- fs3.rmSync(directory, { recursive: true, force: true });
2108
+ fs4.rmSync(directory, { recursive: true, force: true });
2041
2109
  } catch {
2042
2110
  }
2043
2111
  });
@@ -2078,7 +2146,7 @@ ${USAGE}
2078
2146
  }
2079
2147
  }
2080
2148
  for (const warning of loaded.warnings) warn(`\u26A0 Config: ${warning}`);
2081
- 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}`);
2082
2150
  let resolved;
2083
2151
  try {
2084
2152
  resolved = resolveConfig(
@@ -2100,9 +2168,9 @@ ${USAGE}
2100
2168
  }
2101
2169
  if (invocation.command === "health") {
2102
2170
  if (invocation.allMembers === true) {
2103
- const outRoot = path3.resolve(resolved.cwd, resolved.outDir);
2104
- const indexPath = path3.join(outRoot, "WORKSPACE.json");
2105
- if (!fs3.existsSync(indexPath)) {
2171
+ const outRoot = path4.resolve(resolved.cwd, resolved.outDir);
2172
+ const indexPath = path4.join(outRoot, "WORKSPACE.json");
2173
+ if (!fs4.existsSync(indexPath)) {
2106
2174
  return fail(
2107
2175
  invocation.format,
2108
2176
  `No workspace index at ${indexPath}. Run generate --workspace <a,b> first, or drop --all-members.`
@@ -2120,15 +2188,15 @@ ${USAGE}
2120
2188
  }
2121
2189
  const rows = [];
2122
2190
  const insidePath = (parent, child) => {
2123
- const relative4 = path3.relative(parent, child);
2124
- 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);
2125
2193
  };
2126
2194
  for (const member of index.members ?? []) {
2127
2195
  const name = member.name ?? "?";
2128
- const snapshotDir2 = path3.resolve(outRoot, name);
2196
+ const snapshotDir2 = path4.resolve(outRoot, name);
2129
2197
  const repoPath = member.path ?? name;
2130
- const repoDir = path3.resolve(resolved.cwd, repoPath);
2131
- 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)) {
2132
2200
  rows.push({
2133
2201
  name,
2134
2202
  score: 0,
@@ -2141,10 +2209,10 @@ ${USAGE}
2141
2209
  let canonicalSnapshot = snapshotDir2;
2142
2210
  let canonicalRepo = repoDir;
2143
2211
  try {
2144
- const outRootReal = fs3.realpathSync(outRoot);
2145
- const cwdReal = fs3.realpathSync(resolved.cwd);
2146
- canonicalSnapshot = fs3.realpathSync(snapshotDir2);
2147
- canonicalRepo = fs3.existsSync(repoDir) ? fs3.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;
2148
2216
  if (!insidePath(outRootReal, canonicalSnapshot) || !insidePath(cwdReal, canonicalRepo)) {
2149
2217
  rows.push({
2150
2218
  name,
@@ -2159,7 +2227,7 @@ ${USAGE}
2159
2227
  canonicalSnapshot = snapshotDir2;
2160
2228
  canonicalRepo = repoDir;
2161
2229
  }
2162
- if (!fs3.existsSync(path3.join(snapshotDir2, "manifest.json"))) {
2230
+ if (!fs4.existsSync(path4.join(snapshotDir2, "manifest.json"))) {
2163
2231
  rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
2164
2232
  continue;
2165
2233
  }
@@ -2206,7 +2274,7 @@ ${USAGE}
2206
2274
  if (invocation.strict === true && totals.warn > 0) return 1;
2207
2275
  return 0;
2208
2276
  }
2209
- const snapshotDir = path3.resolve(resolved.cwd, resolved.outDir);
2277
+ const snapshotDir = path4.resolve(resolved.cwd, resolved.outDir);
2210
2278
  const report = auditSnapshot({
2211
2279
  snapshotDir,
2212
2280
  repoDir: resolved.cwd,
@@ -2219,13 +2287,13 @@ ${USAGE}
2219
2287
  return 0;
2220
2288
  }
2221
2289
  if (invocation.command === "report") {
2222
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2223
- if (!fs3.existsSync(manifestPath)) {
2290
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2291
+ if (!fs4.existsSync(manifestPath)) {
2224
2292
  return fail(invocation.format, `Manifest not found at ${manifestPath}. Run generate first.`);
2225
2293
  }
2226
2294
  let manifest;
2227
2295
  try {
2228
- manifest = JSON.parse(fs3.readFileSync(manifestPath, "utf8"));
2296
+ manifest = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
2229
2297
  } catch (err) {
2230
2298
  return fail(invocation.format, `Could not read ${manifestPath}: ${err.message}`);
2231
2299
  }
@@ -2282,7 +2350,7 @@ ${USAGE}
2282
2350
  if (manifest.delta !== void 0) {
2283
2351
  const delta = manifest.delta;
2284
2352
  info("\n Selection (delta):");
2285
- 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)})`);
2286
2354
  info(
2287
2355
  ` - Changed: ${delta.changed.length} changed, ${delta.added.length} added, ${delta.removed.length} removed, ${delta.unchanged.length} unchanged`
2288
2356
  );
@@ -2292,11 +2360,11 @@ ${USAGE}
2292
2360
  }
2293
2361
  if (invocation.command === "impact") {
2294
2362
  try {
2295
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2363
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2296
2364
  let manifest;
2297
2365
  let live = null;
2298
2366
  if (invocation.noLive) {
2299
- if (!fs3.existsSync(manifestPath)) {
2367
+ if (!fs4.existsSync(manifestPath)) {
2300
2368
  return fail(invocation.format, "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live.");
2301
2369
  }
2302
2370
  manifest = loadManifest(manifestPath);
@@ -2414,11 +2482,11 @@ ${USAGE}
2414
2482
  }
2415
2483
  if (invocation.command === "brief") {
2416
2484
  try {
2417
- const manifestPath = path3.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2485
+ const manifestPath = path4.resolve(resolved.cwd, resolved.outDir, "manifest.json");
2418
2486
  let manifest;
2419
2487
  let live = null;
2420
2488
  if (invocation.noLive) {
2421
- if (!fs3.existsSync(manifestPath)) {
2489
+ if (!fs4.existsSync(manifestPath)) {
2422
2490
  return fail(invocation.format, "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live.");
2423
2491
  }
2424
2492
  manifest = loadManifest(manifestPath);
@@ -2481,10 +2549,10 @@ ${USAGE}
2481
2549
  if (isSensitivePath(relativePath)) return null;
2482
2550
  const file = manifest.files.find((candidate) => candidate.relativePath === relativePath);
2483
2551
  if (file === void 0) return null;
2484
- const snapshotDir = path3.resolve(resolved.cwd, resolved.outDir);
2552
+ const snapshotDir = path4.resolve(resolved.cwd, resolved.outDir);
2485
2553
  const read = readConfinedText(
2486
2554
  snapshotDir,
2487
- path3.posix.join("parts", file.part),
2555
+ path4.posix.join("parts", file.part),
2488
2556
  16 * 1024 * 1024
2489
2557
  );
2490
2558
  if (!read.ok) return null;
@@ -2509,7 +2577,7 @@ ${USAGE}
2509
2577
  });
2510
2578
  if (invocation.out !== void 0) {
2511
2579
  const written = writeInside(resolved.cwd, invocation.out, brief.markdown);
2512
- info("Wrote " + path3.relative(resolved.cwd, written));
2580
+ info("Wrote " + path4.relative(resolved.cwd, written));
2513
2581
  } else if (invocation.format !== "json") {
2514
2582
  process.stdout.write(brief.markdown);
2515
2583
  }
@@ -2585,10 +2653,10 @@ ${USAGE}
2585
2653
  "--workspace writes one snapshot per member; --remote, --delta, --slice, --budget-tokens and --sign do not combine with it."
2586
2654
  );
2587
2655
  }
2588
- const outRoot = path3.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
2589
- const workspaceCwd = path3.resolve(invocation.cwd);
2590
- const outRootRelative = path3.relative(outRoot, workspaceCwd);
2591
- 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)) {
2592
2660
  return fail(
2593
2661
  invocation.format,
2594
2662
  `--workspace refuses --out-dir ${outRoot}: it is the working directory or one of its ancestors.`
@@ -2596,8 +2664,8 @@ ${USAGE}
2596
2664
  }
2597
2665
  const plannedNames = /* @__PURE__ */ new Map();
2598
2666
  for (const member of members) {
2599
- const directory = path3.resolve(invocation.cwd, member);
2600
- const name = path3.basename(directory);
2667
+ const directory = path4.resolve(invocation.cwd, member);
2668
+ const name = path4.basename(directory);
2601
2669
  const previous = plannedNames.get(name);
2602
2670
  if (previous !== void 0) {
2603
2671
  return fail(
@@ -2610,11 +2678,11 @@ ${USAGE}
2610
2678
  const records = [];
2611
2679
  let failed = 0;
2612
2680
  for (const member of members) {
2613
- const directory = path3.resolve(invocation.cwd, member);
2614
- const name = path3.basename(directory);
2681
+ const directory = path4.resolve(invocation.cwd, member);
2682
+ const name = path4.basename(directory);
2615
2683
  let stat;
2616
2684
  try {
2617
- stat = fs3.statSync(directory);
2685
+ stat = fs4.statSync(directory);
2618
2686
  } catch {
2619
2687
  warn("\u26A0 Workspace member missing: " + member);
2620
2688
  failed += 1;
@@ -2631,7 +2699,7 @@ ${USAGE}
2631
2699
  {
2632
2700
  ...generateCliOptions(invocation),
2633
2701
  cwd: directory,
2634
- outDir: path3.join(outRoot, name)
2702
+ outDir: path4.join(outRoot, name)
2635
2703
  },
2636
2704
  directory
2637
2705
  );
@@ -2651,17 +2719,17 @@ ${USAGE}
2651
2719
  failed += 1;
2652
2720
  }
2653
2721
  }
2654
- if (!invocation.dryRun) fs3.mkdirSync(outRoot, { recursive: true });
2722
+ if (!invocation.dryRun) fs4.mkdirSync(outRoot, { recursive: true });
2655
2723
  const links = [];
2656
2724
  for (const record of records) {
2657
2725
  const counts = /* @__PURE__ */ new Map();
2658
2726
  for (const entry of record.imports) {
2659
2727
  for (const specifier of entry.imports) {
2660
2728
  if (!specifier.startsWith(".")) continue;
2661
- const resolved2 = path3.resolve(record.path, path3.dirname(entry.path), specifier);
2729
+ const resolved2 = path4.resolve(record.path, path4.dirname(entry.path), specifier);
2662
2730
  for (const other of records) {
2663
2731
  if (other === record) continue;
2664
- const prefix = other.path + path3.sep;
2732
+ const prefix = other.path + path4.sep;
2665
2733
  if (!resolved2.startsWith(prefix) && resolved2 !== other.path) continue;
2666
2734
  const bucket = counts.get(other.name) ?? { count: 0, examples: [] };
2667
2735
  bucket.count += 1;
@@ -2686,14 +2754,14 @@ ${USAGE}
2686
2754
  // Store the member path relative to the workspace cwd, as manifest paths already are.
2687
2755
  members: records.map(({ imports: _imports, ...rest }) => ({
2688
2756
  ...rest,
2689
- path: path3.relative(workspaceCwd, rest.path).split(path3.sep).join("/") || "."
2757
+ path: path4.relative(workspaceCwd, rest.path).split(path4.sep).join("/") || "."
2690
2758
  })),
2691
2759
  links
2692
2760
  };
2693
2761
  if (!invocation.dryRun) {
2694
- const workspacePath = path3.join(outRoot, "WORKSPACE.json");
2762
+ const workspacePath = path4.join(outRoot, "WORKSPACE.json");
2695
2763
  try {
2696
- const stats = fs3.lstatSync(workspacePath);
2764
+ const stats = fs4.lstatSync(workspacePath);
2697
2765
  if (stats.isSymbolicLink() || !stats.isFile()) {
2698
2766
  return fail(invocation.format, `${workspacePath} is not a regular file; refusing to replace it.`);
2699
2767
  }
@@ -2702,11 +2770,11 @@ ${USAGE}
2702
2770
  }
2703
2771
  const tempPath = `${workspacePath}.${process.pid}.${Date.now()}.tmp`;
2704
2772
  try {
2705
- fs3.writeFileSync(tempPath, JSON.stringify(document, null, 2) + "\n", "utf8");
2706
- fs3.renameSync(tempPath, workspacePath);
2773
+ fs4.writeFileSync(tempPath, JSON.stringify(document, null, 2) + "\n", "utf8");
2774
+ fs4.renameSync(tempPath, workspacePath);
2707
2775
  } catch (error) {
2708
2776
  try {
2709
- fs3.rmSync(tempPath, { force: true });
2777
+ fs4.rmSync(tempPath, { force: true });
2710
2778
  } catch {
2711
2779
  }
2712
2780
  throw error;
@@ -2734,14 +2802,14 @@ ${USAGE}
2734
2802
  try {
2735
2803
  let deltaBase;
2736
2804
  if (invocation.delta !== void 0) {
2737
- const basePath = path3.resolve(invocation.cwd, invocation.delta);
2738
- const manifestPath = fs3.existsSync(basePath) && fs3.statSync(basePath).isDirectory() ? path3.join(basePath, "manifest.json") : basePath;
2739
- if (!fs3.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)) {
2740
2808
  return fail(invocation.format, "No manifest at " + manifestPath + ". Point --delta at a snapshot directory or its manifest.json.");
2741
2809
  }
2742
2810
  let base;
2743
2811
  try {
2744
- base = JSON.parse(fs3.readFileSync(manifestPath, "utf8"));
2812
+ base = JSON.parse(fs4.readFileSync(manifestPath, "utf8"));
2745
2813
  } catch (error) {
2746
2814
  return fail(invocation.format, "Could not read " + manifestPath + ": " + error.message);
2747
2815
  }
@@ -2749,8 +2817,8 @@ ${USAGE}
2749
2817
  if (shape !== null) {
2750
2818
  return fail(invocation.format, manifestPath + " is not a snapshot manifest: " + shape);
2751
2819
  }
2752
- const relativeBase = path3.relative(invocation.cwd, manifestPath).split(path3.sep).join("/");
2753
- 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;
2754
2822
  deltaBase = { manifest: base, path: recordedBase };
2755
2823
  info(" Delta base: " + recordedBase + " (" + base.files.length + " files, fingerprint " + base.fingerprint.slice(0, 12) + ")");
2756
2824
  }
@@ -2768,9 +2836,9 @@ ${USAGE}
2768
2836
  ...invocation.sign === true && !invocation.dryRun ? { sign: { key: loadSigningKey() } } : {}
2769
2837
  });
2770
2838
  if (invocation.sign === true && !invocation.dryRun) {
2771
- const signaturePath = path3.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
2839
+ const signaturePath = path4.resolve(resolved.cwd, resolved.outDir, SIGNATURE_FILE);
2772
2840
  try {
2773
- const record = JSON.parse(fs3.readFileSync(signaturePath, "utf8"));
2841
+ const record = JSON.parse(fs4.readFileSync(signaturePath, "utf8"));
2774
2842
  info(
2775
2843
  " Signature: ed25519, " + (record.keyOrigin ?? "unknown") + " key, " + (record.fingerprint ?? manifest.fingerprint).slice(0, 12)
2776
2844
  );
@@ -2923,19 +2991,19 @@ function finishWatchRun(state, now) {
2923
2991
  };
2924
2992
  }
2925
2993
  function comparablePath(value) {
2926
- const absolute = path3.resolve(value);
2994
+ const absolute = path4.resolve(value);
2927
2995
  return process.platform === "win32" ? absolute.toLowerCase() : absolute;
2928
2996
  }
2929
2997
  function isSameOrInside(parent, candidate) {
2930
- const relative4 = path3.relative(parent, candidate);
2931
- 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);
2932
3000
  }
2933
3001
  function isGeneratedWatchPath(candidate, paths) {
2934
- const absolute = comparablePath(path3.resolve(paths.cwd, candidate));
2935
- const outDir = comparablePath(path3.resolve(paths.cwd, paths.outDir));
2936
- 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));
2937
3005
  if (isSameOrInside(outDir, absolute) || isSameOrInside(tmpDir, absolute)) return true;
2938
- 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);
2939
3007
  const leftover = absolute.split(/[\\/]+/).some(
2940
3008
  (segment) => offsets.some(
2941
3009
  (name) => segment.startsWith(`${name}.backup-`) || segment.startsWith(`${name}.partial-`)
@@ -2958,8 +3026,8 @@ function decideWatchEvent(state, event, paths) {
2958
3026
  function watchPathsFor(config) {
2959
3027
  return {
2960
3028
  cwd: config.cwd,
2961
- outDir: path3.resolve(config.cwd, config.outDir),
2962
- tmpDir: path3.resolve(config.cwd, config.tmpDir)
3029
+ outDir: path4.resolve(config.cwd, config.outDir),
3030
+ tmpDir: path4.resolve(config.cwd, config.tmpDir)
2963
3031
  };
2964
3032
  }
2965
3033
  function watchSupportProblem(platform = process.platform, version = process.versions.node) {
@@ -3033,11 +3101,11 @@ async function runWatchLoop(invocation, resolved, options) {
3033
3101
  info("\u{1F440} Watching for changes. Press Ctrl+C to stop.");
3034
3102
  let watcher;
3035
3103
  try {
3036
- watcher = fs3.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
3104
+ watcher = fs4.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
3037
3105
  const decision = decideWatchEvent(
3038
3106
  state,
3039
3107
  {
3040
- path: filename ? path3.resolve(resolved.cwd, filename.toString()) : null,
3108
+ path: filename ? path4.resolve(resolved.cwd, filename.toString()) : null,
3041
3109
  now: performance.now()
3042
3110
  },
3043
3111
  paths
@@ -3063,12 +3131,12 @@ async function runWatchLoop(invocation, resolved, options) {
3063
3131
  info(`\u26A0 Watch error: ${err.message}`);
3064
3132
  info(" The watcher may have missed changes. Restart with Ctrl+C if they stop arriving.");
3065
3133
  });
3066
- await new Promise((resolve3) => {
3134
+ await new Promise((resolve4) => {
3067
3135
  const stop = () => {
3068
3136
  stopped = true;
3069
3137
  if (timer) clearTimeout(timer);
3070
3138
  watcher.close();
3071
- resolve3();
3139
+ resolve4();
3072
3140
  };
3073
3141
  process.once("SIGINT", stop);
3074
3142
  process.once("SIGTERM", stop);
@@ -3078,12 +3146,12 @@ async function runWatchLoop(invocation, resolved, options) {
3078
3146
  var entryFile = process.argv[1] ?? "";
3079
3147
  var sameFile = (left, right) => {
3080
3148
  try {
3081
- return fs3.realpathSync(path3.resolve(left)) === fs3.realpathSync(path3.resolve(right));
3149
+ return fs4.realpathSync(path4.resolve(left)) === fs4.realpathSync(path4.resolve(right));
3082
3150
  } catch {
3083
3151
  return false;
3084
3152
  }
3085
3153
  };
3086
- var entryName = path3.basename(entryFile).toLowerCase();
3154
+ var entryName = path4.basename(entryFile).toLowerCase();
3087
3155
  var invokedDirectly = (entryName === "cli.js" || entryName === "cli.cjs") && entryFile.length > 0 && sameFile(entryFile, fileURLToPath(import.meta.url));
3088
3156
  if (invokedDirectly) {
3089
3157
  void main().then(