codebase-snapshot 0.20.4 → 0.20.6

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { O as OutputFormat, P as PromptTask, D as DiscoveryMode, C as CliOptions, R as ResolvedSnapshotConfig } from './types-Drw1J0e0.cjs';
1
+ import { O as OutputFormat, P as PromptTask, D as DiscoveryMode, C as CliOptions, R as ResolvedSnapshotConfig } from './types-CykWdR6V.cjs';
2
2
 
3
3
  /**
4
4
  * The machine-readable description of this tool.
@@ -460,6 +460,8 @@ declare function parsePositiveInteger(raw: string | undefined, optionName: strin
460
460
  * as well as raw byte counts.
461
461
  */
462
462
  declare function parseByteOption(raw: string | undefined, optionName: string, minimum: number, unit?: string): number | undefined;
463
+ /** Parses a TCP port, where 0 is the documented "pick an ephemeral port" value. */
464
+ declare function parsePort(raw: string | undefined): number | undefined;
463
465
  /**
464
466
  * Parses a whole-number option such as `--attachment-slots 20`.
465
467
  *
@@ -586,4 +588,4 @@ declare function watchPathsFor(config: ResolvedSnapshotConfig): WatchPaths;
586
588
  */
587
589
  declare function watchSupportProblem(platform?: string, version?: string): string | null;
588
590
 
589
- export { CLI_OPTIONS, UsageError, WATCH_DEBOUNCE_MS, WATCH_SETTLE_MS, type WatchAction, type WatchDecision, type WatchEvent, type WatchPaths, type WatchState, beginWatchRun, buildAgentContract, cleanInstallEnv, decideWatchEvent, finishWatchRun, generateCliOptions, initialWatchState, isGeneratedWatchPath, main, parseByteOption, parseCliArgs, parseCountOption, parsePositiveInteger, watchPathsFor, watchSupportProblem };
591
+ export { CLI_OPTIONS, UsageError, WATCH_DEBOUNCE_MS, WATCH_SETTLE_MS, type WatchAction, type WatchDecision, type WatchEvent, type WatchPaths, type WatchState, beginWatchRun, buildAgentContract, cleanInstallEnv, decideWatchEvent, finishWatchRun, generateCliOptions, initialWatchState, isGeneratedWatchPath, main, parseByteOption, parseCliArgs, parseCountOption, parsePort, parsePositiveInteger, watchPathsFor, watchSupportProblem };
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { O as OutputFormat, P as PromptTask, D as DiscoveryMode, C as CliOptions, R as ResolvedSnapshotConfig } from './types-Drw1J0e0.js';
1
+ import { O as OutputFormat, P as PromptTask, D as DiscoveryMode, C as CliOptions, R as ResolvedSnapshotConfig } from './types-CykWdR6V.js';
2
2
 
3
3
  /**
4
4
  * The machine-readable description of this tool.
@@ -460,6 +460,8 @@ declare function parsePositiveInteger(raw: string | undefined, optionName: strin
460
460
  * as well as raw byte counts.
461
461
  */
462
462
  declare function parseByteOption(raw: string | undefined, optionName: string, minimum: number, unit?: string): number | undefined;
463
+ /** Parses a TCP port, where 0 is the documented "pick an ephemeral port" value. */
464
+ declare function parsePort(raw: string | undefined): number | undefined;
463
465
  /**
464
466
  * Parses a whole-number option such as `--attachment-slots 20`.
465
467
  *
@@ -586,4 +588,4 @@ declare function watchPathsFor(config: ResolvedSnapshotConfig): WatchPaths;
586
588
  */
587
589
  declare function watchSupportProblem(platform?: string, version?: string): string | null;
588
590
 
589
- export { CLI_OPTIONS, UsageError, WATCH_DEBOUNCE_MS, WATCH_SETTLE_MS, type WatchAction, type WatchDecision, type WatchEvent, type WatchPaths, type WatchState, beginWatchRun, buildAgentContract, cleanInstallEnv, decideWatchEvent, finishWatchRun, generateCliOptions, initialWatchState, isGeneratedWatchPath, main, parseByteOption, parseCliArgs, parseCountOption, parsePositiveInteger, watchPathsFor, watchSupportProblem };
591
+ export { CLI_OPTIONS, UsageError, WATCH_DEBOUNCE_MS, WATCH_SETTLE_MS, type WatchAction, type WatchDecision, type WatchEvent, type WatchPaths, type WatchState, beginWatchRun, buildAgentContract, cleanInstallEnv, decideWatchEvent, finishWatchRun, generateCliOptions, initialWatchState, isGeneratedWatchPath, main, parseByteOption, parseCliArgs, parseCountOption, parsePort, parsePositiveInteger, watchPathsFor, watchSupportProblem };
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
- import { startHttpTransport } from './chunk-QB5TNXMZ.js';
2
- import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, 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, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-AQZNT3QL.js';
3
- export { buildAgentContract } from './chunk-AQZNT3QL.js';
1
+ import { startHttpTransport } from './chunk-E4VHKJJU.js';
2
+ import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, 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, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-KPDO7W5D.js';
3
+ export { buildAgentContract } from './chunk-KPDO7W5D.js';
4
4
  import { spawnSync } from 'child_process';
5
5
  import * as fs2 from 'fs';
6
6
  import * as path2 from 'path';
@@ -341,6 +341,13 @@ function parseByteOption(raw, optionName, minimum, unit = "byte count") {
341
341
  }
342
342
  return value;
343
343
  }
344
+ function parsePort(raw) {
345
+ const value = parsePositiveInteger(raw, "port", 0);
346
+ if (value !== void 0 && value > 65535) {
347
+ throw new UsageError(`--port must be at most 65535, received "${raw}".`);
348
+ }
349
+ return value;
350
+ }
344
351
  function parseCountOption(raw, optionName, minimum = 0) {
345
352
  if (raw === void 0) return void 0;
346
353
  const trimmed = raw.trim();
@@ -629,7 +636,7 @@ function parseCliArgs(argv) {
629
636
  sarif: values.sarif === true ? true : void 0,
630
637
  strict: values.strict === true ? true : void 0,
631
638
  http: values.http === true ? true : void 0,
632
- port: parsePositiveInteger(values.port, "port", 1),
639
+ port: parsePort(values.port),
633
640
  host: values.host === void 0 ? void 0 : String(values.host),
634
641
  token: values.token === void 0 ? void 0 : String(values.token),
635
642
  noAuth: values["no-auth"] === true ? true : void 0,
@@ -1267,6 +1274,8 @@ ${USAGE}
1267
1274
  }
1268
1275
  throw err;
1269
1276
  }
1277
+ const environmentToken = process.env.SNAPSHOT_TOKEN?.trim();
1278
+ const tokenOption = invocation.noAuth === true ? { token: null } : invocation.token !== void 0 ? { token: invocation.token } : environmentToken !== void 0 && environmentToken !== "" ? { token: environmentToken } : {};
1270
1279
  if (invocation.command === "init") {
1271
1280
  return await runInitCommand(invocation);
1272
1281
  }
@@ -1286,8 +1295,7 @@ ${USAGE}
1286
1295
  cwd: path2.resolve(invocation.cwd),
1287
1296
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1288
1297
  ...invocation.port === void 0 ? {} : { port: invocation.port },
1289
- ...invocation.noAuth === true ? { token: null } : {},
1290
- ...invocation.token === void 0 ? {} : { token: invocation.token },
1298
+ ...tokenOption,
1291
1299
  ...invocation.allowPrivate === true ? { allowPrivate: true } : {},
1292
1300
  log: (line) => warn(line)
1293
1301
  });
@@ -1314,13 +1322,12 @@ ${USAGE}
1314
1322
  cwd: path2.resolve(invocation.cwd),
1315
1323
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1316
1324
  ...invocation.port === void 0 ? {} : { port: invocation.port },
1317
- ...invocation.noAuth === true ? { token: null } : {},
1318
- ...invocation.token === void 0 ? {} : { token: invocation.token },
1325
+ ...tokenOption,
1319
1326
  ...invocation.allowOrigins === void 0 ? {} : { allowedOrigins: invocation.allowOrigins },
1320
1327
  log: (line) => warn(line)
1321
1328
  });
1322
1329
  info("MCP over HTTP: " + transport.url);
1323
- info(" tools: 12 (see describe --format json)");
1330
+ info(" tools: " + buildTools().length + " (see describe --format json)");
1324
1331
  if (transport.token !== null) {
1325
1332
  info(" Authorization: Bearer " + transport.token);
1326
1333
  info(" (generated for this run; pass --token to choose one)");
@@ -1427,10 +1434,25 @@ ${USAGE}
1427
1434
  return fail(invocation.format, `Could not read ${indexPath}: ${error.message}`);
1428
1435
  }
1429
1436
  const rows = [];
1437
+ const insidePath = (parent, child) => {
1438
+ const relative3 = path2.relative(parent, child);
1439
+ return relative3 === "" || !relative3.startsWith("..") && !path2.isAbsolute(relative3);
1440
+ };
1430
1441
  for (const member of index.members ?? []) {
1431
1442
  const name = member.name ?? "?";
1432
- const snapshotDir2 = path2.join(outRoot, name);
1433
- const repoDir = path2.resolve(resolved.cwd, member.path ?? name);
1443
+ const snapshotDir2 = path2.resolve(outRoot, name);
1444
+ const repoPath = member.path ?? name;
1445
+ const repoDir = path2.resolve(resolved.cwd, repoPath);
1446
+ if (name.length === 0 || path2.isAbsolute(name) || name.split("/").includes("..") || !insidePath(outRoot, snapshotDir2) || path2.isAbsolute(repoPath) || repoPath.split(/[\\/]/).includes("..") || !insidePath(resolved.cwd, repoDir)) {
1447
+ rows.push({
1448
+ name,
1449
+ score: 0,
1450
+ counts: { pass: 0, warn: 0, fail: 1 },
1451
+ failed: [],
1452
+ error: "the workspace index names a path outside the workspace"
1453
+ });
1454
+ continue;
1455
+ }
1434
1456
  if (!fs2.existsSync(path2.join(snapshotDir2, "manifest.json"))) {
1435
1457
  rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
1436
1458
  continue;
@@ -1598,6 +1620,27 @@ ${USAGE}
1598
1620
  );
1599
1621
  }
1600
1622
  const outRoot = path2.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
1623
+ const workspaceCwd = path2.resolve(invocation.cwd);
1624
+ const outRootRelative = path2.relative(outRoot, workspaceCwd);
1625
+ if (outRootRelative === "" || !outRootRelative.startsWith("..") && !path2.isAbsolute(outRootRelative)) {
1626
+ return fail(
1627
+ invocation.format,
1628
+ `--workspace refuses --out-dir ${outRoot}: it is the working directory or one of its ancestors.`
1629
+ );
1630
+ }
1631
+ const plannedNames = /* @__PURE__ */ new Map();
1632
+ for (const member of members) {
1633
+ const directory = path2.resolve(invocation.cwd, member);
1634
+ const name = path2.basename(directory);
1635
+ const previous = plannedNames.get(name);
1636
+ if (previous !== void 0) {
1637
+ return fail(
1638
+ invocation.format,
1639
+ `--workspace members "${previous}" and "${member}" share the basename "${name}"; each member needs a distinct directory name.`
1640
+ );
1641
+ }
1642
+ plannedNames.set(name, member);
1643
+ }
1601
1644
  const records = [];
1602
1645
  let failed = 0;
1603
1646
  for (const member of members) {
@@ -1617,7 +1660,10 @@ ${USAGE}
1617
1660
  continue;
1618
1661
  }
1619
1662
  try {
1620
- const manifest = generateSnapshot({ cwd: directory, outDir: path2.join(outRoot, name) });
1663
+ const manifest = generateSnapshot(
1664
+ { cwd: directory, outDir: path2.join(outRoot, name) },
1665
+ { dryRun: invocation.dryRun }
1666
+ );
1621
1667
  records.push({
1622
1668
  name,
1623
1669
  path: directory,
@@ -1633,7 +1679,7 @@ ${USAGE}
1633
1679
  failed += 1;
1634
1680
  }
1635
1681
  }
1636
- fs2.mkdirSync(outRoot, { recursive: true });
1682
+ if (!invocation.dryRun) fs2.mkdirSync(outRoot, { recursive: true });
1637
1683
  const links = [];
1638
1684
  for (const record of records) {
1639
1685
  const counts = /* @__PURE__ */ new Map();
@@ -1656,16 +1702,48 @@ ${USAGE}
1656
1702
  links.push({ from: record.name, to, specifiers: bucket.count, examples: bucket.examples });
1657
1703
  }
1658
1704
  }
1659
- links.sort((left, right) => (left.from + ">" + left.to).localeCompare(right.from + ">" + right.to));
1705
+ links.sort((left, right) => {
1706
+ const a = left.from + ">" + left.to;
1707
+ const b = right.from + ">" + right.to;
1708
+ return a < b ? -1 : a > b ? 1 : 0;
1709
+ });
1660
1710
  const document = {
1661
1711
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1662
1712
  generator: GENERATOR_VERSION,
1663
- members: records.map(({ imports: _imports, ...rest }) => rest),
1713
+ // The index is published; an absolute host path in it names the author's home directory.
1714
+ // Store the member path relative to the workspace cwd, as manifest paths already are.
1715
+ members: records.map(({ imports: _imports, ...rest }) => ({
1716
+ ...rest,
1717
+ path: path2.relative(workspaceCwd, rest.path).split(path2.sep).join("/") || "."
1718
+ })),
1664
1719
  links
1665
1720
  };
1666
- fs2.writeFileSync(path2.join(outRoot, "WORKSPACE.json"), JSON.stringify(document, null, 2) + "\n", "utf8");
1721
+ if (!invocation.dryRun) {
1722
+ const workspacePath = path2.join(outRoot, "WORKSPACE.json");
1723
+ try {
1724
+ const stats = fs2.lstatSync(workspacePath);
1725
+ if (stats.isSymbolicLink() || !stats.isFile()) {
1726
+ return fail(invocation.format, `${workspacePath} is not a regular file; refusing to replace it.`);
1727
+ }
1728
+ } catch (error) {
1729
+ if (error.code !== "ENOENT") throw error;
1730
+ }
1731
+ const tempPath = `${workspacePath}.${process.pid}.${Date.now()}.tmp`;
1732
+ try {
1733
+ fs2.writeFileSync(tempPath, JSON.stringify(document, null, 2) + "\n", "utf8");
1734
+ fs2.renameSync(tempPath, workspacePath);
1735
+ } catch (error) {
1736
+ try {
1737
+ fs2.rmSync(tempPath, { force: true });
1738
+ } catch {
1739
+ }
1740
+ throw error;
1741
+ }
1742
+ }
1667
1743
  emit(invocation.format, document, () => {
1668
- info("\n\u{1F5C2} Workspace: " + records.length + " of " + members.length + " member(s) written under " + outRoot);
1744
+ info(
1745
+ "\n\u{1F5C2} Workspace: " + records.length + " of " + members.length + (invocation.dryRun ? " member(s) planned; nothing was written." : " member(s) written under " + outRoot)
1746
+ );
1669
1747
  for (const record of records) {
1670
1748
  info(" - " + record.name + " (" + record.fingerprint.slice(0, 12) + ")");
1671
1749
  }
@@ -1699,8 +1777,10 @@ ${USAGE}
1699
1777
  if (shape !== null) {
1700
1778
  return fail(invocation.format, manifestPath + " is not a snapshot manifest: " + shape);
1701
1779
  }
1702
- deltaBase = { manifest: base, path: manifestPath };
1703
- info(" Delta base: " + manifestPath + " (" + base.files.length + " files, fingerprint " + base.fingerprint.slice(0, 12) + ")");
1780
+ const relativeBase = path2.relative(invocation.cwd, manifestPath).split(path2.sep).join("/");
1781
+ const recordedBase = relativeBase === "" || relativeBase.startsWith("..") || path2.isAbsolute(relativeBase) ? path2.basename(manifestPath) : relativeBase;
1782
+ deltaBase = { manifest: base, path: recordedBase };
1783
+ info(" Delta base: " + recordedBase + " (" + base.files.length + " files, fingerprint " + base.fingerprint.slice(0, 12) + ")");
1704
1784
  }
1705
1785
  const manifest = generateSnapshot(resolved, {
1706
1786
  dryRun: invocation.dryRun,
@@ -2039,4 +2119,4 @@ if (invokedDirectly) {
2039
2119
  );
2040
2120
  }
2041
2121
 
2042
- export { CLI_OPTIONS, UsageError, WATCH_DEBOUNCE_MS, WATCH_SETTLE_MS, beginWatchRun, cleanInstallEnv, decideWatchEvent, finishWatchRun, generateCliOptions, initialWatchState, isGeneratedWatchPath, main, parseByteOption, parseCliArgs, parseCountOption, parsePositiveInteger, watchPathsFor, watchSupportProblem };
2122
+ export { CLI_OPTIONS, UsageError, WATCH_DEBOUNCE_MS, WATCH_SETTLE_MS, beginWatchRun, cleanInstallEnv, decideWatchEvent, finishWatchRun, generateCliOptions, initialWatchState, isGeneratedWatchPath, main, parseByteOption, parseCliArgs, parseCountOption, parsePort, parsePositiveInteger, watchPathsFor, watchSupportProblem };
@@ -1,3 +1,5 @@
1
+ import { c as SnapshotConfig, f as Manifest } from './types-CykWdR6V.js';
2
+
1
3
  /** The options `resolveConfig` was called with, as the CLI would have passed them. */
2
4
  interface WorkspaceCliOptions {
3
5
  cwd: string;
@@ -100,6 +102,10 @@ declare function generateInWorker(cwd: string, cliOptions: WorkspaceCliOptions,
100
102
  runId?: string;
101
103
  /** Directories whose locks/staging this run may own; used only for abandoned-worker cleanup. */
102
104
  lockRoots?: readonly string[];
105
+ /** A configuration already loaded on this thread; skips a second, possibly untrusted, load. */
106
+ config?: SnapshotConfig;
107
+ /** Provenance for a clone this process made; it is a value, so it crosses the boundary. */
108
+ source?: Manifest["source"];
103
109
  }): Promise<WorkerResults>;
104
110
 
105
111
  export { type GenerateSummary as G, type WorkerResults as W, generateInWorker as g, workerEntry as w };
@@ -1,3 +1,5 @@
1
+ import { c as SnapshotConfig, f as Manifest } from './types-CykWdR6V.cjs';
2
+
1
3
  /** The options `resolveConfig` was called with, as the CLI would have passed them. */
2
4
  interface WorkspaceCliOptions {
3
5
  cwd: string;
@@ -100,6 +102,10 @@ declare function generateInWorker(cwd: string, cliOptions: WorkspaceCliOptions,
100
102
  runId?: string;
101
103
  /** Directories whose locks/staging this run may own; used only for abandoned-worker cleanup. */
102
104
  lockRoots?: readonly string[];
105
+ /** A configuration already loaded on this thread; skips a second, possibly untrusted, load. */
106
+ config?: SnapshotConfig;
107
+ /** Provenance for a clone this process made; it is a value, so it crosses the boundary. */
108
+ source?: Manifest["source"];
103
109
  }): Promise<WorkerResults>;
104
110
 
105
111
  export { type GenerateSummary as G, type WorkerResults as W, generateInWorker as g, workerEntry as w };