codebase-snapshot 0.20.5 → 0.20.7

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-DnYsA6_Y.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.
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-DnYsA6_Y.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.
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
- import { startHttpTransport } from './chunk-HYTY6T7P.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-C3WVC4FV.js';
3
- export { buildAgentContract } from './chunk-C3WVC4FV.js';
1
+ import { startHttpTransport } from './chunk-UIF7U77H.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-RSWAYB6U.js';
3
+ export { buildAgentContract } from './chunk-RSWAYB6U.js';
4
4
  import { spawnSync } from 'child_process';
5
5
  import * as fs2 from 'fs';
6
6
  import * as path2 from 'path';
@@ -1274,6 +1274,8 @@ ${USAGE}
1274
1274
  }
1275
1275
  throw err;
1276
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 } : {};
1277
1279
  if (invocation.command === "init") {
1278
1280
  return await runInitCommand(invocation);
1279
1281
  }
@@ -1293,8 +1295,7 @@ ${USAGE}
1293
1295
  cwd: path2.resolve(invocation.cwd),
1294
1296
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1295
1297
  ...invocation.port === void 0 ? {} : { port: invocation.port },
1296
- ...invocation.noAuth === true ? { token: null } : {},
1297
- ...invocation.token === void 0 ? {} : { token: invocation.token },
1298
+ ...tokenOption,
1298
1299
  ...invocation.allowPrivate === true ? { allowPrivate: true } : {},
1299
1300
  log: (line) => warn(line)
1300
1301
  });
@@ -1321,13 +1322,12 @@ ${USAGE}
1321
1322
  cwd: path2.resolve(invocation.cwd),
1322
1323
  ...invocation.host === void 0 ? {} : { host: invocation.host },
1323
1324
  ...invocation.port === void 0 ? {} : { port: invocation.port },
1324
- ...invocation.noAuth === true ? { token: null } : {},
1325
- ...invocation.token === void 0 ? {} : { token: invocation.token },
1325
+ ...tokenOption,
1326
1326
  ...invocation.allowOrigins === void 0 ? {} : { allowedOrigins: invocation.allowOrigins },
1327
1327
  log: (line) => warn(line)
1328
1328
  });
1329
1329
  info("MCP over HTTP: " + transport.url);
1330
- info(" tools: 12 (see describe --format json)");
1330
+ info(" tools: " + buildTools().length + " (see describe --format json)");
1331
1331
  if (transport.token !== null) {
1332
1332
  info(" Authorization: Bearer " + transport.token);
1333
1333
  info(" (generated for this run; pass --token to choose one)");
@@ -1434,10 +1434,25 @@ ${USAGE}
1434
1434
  return fail(invocation.format, `Could not read ${indexPath}: ${error.message}`);
1435
1435
  }
1436
1436
  const rows = [];
1437
+ const insidePath = (parent, child) => {
1438
+ const relative3 = path2.relative(parent, child);
1439
+ return relative3 === "" || !relative3.startsWith("..") && !path2.isAbsolute(relative3);
1440
+ };
1437
1441
  for (const member of index.members ?? []) {
1438
1442
  const name = member.name ?? "?";
1439
- const snapshotDir2 = path2.join(outRoot, name);
1440
- 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
+ }
1441
1456
  if (!fs2.existsSync(path2.join(snapshotDir2, "manifest.json"))) {
1442
1457
  rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
1443
1458
  continue;
@@ -1613,6 +1628,19 @@ ${USAGE}
1613
1628
  `--workspace refuses --out-dir ${outRoot}: it is the working directory or one of its ancestors.`
1614
1629
  );
1615
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
+ }
1616
1644
  const records = [];
1617
1645
  let failed = 0;
1618
1646
  for (const member of members) {
@@ -1674,19 +1702,43 @@ ${USAGE}
1674
1702
  links.push({ from: record.name, to, specifiers: bucket.count, examples: bucket.examples });
1675
1703
  }
1676
1704
  }
1677
- 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
+ });
1678
1710
  const document = {
1679
1711
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1680
1712
  generator: GENERATOR_VERSION,
1681
- 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
+ })),
1682
1719
  links
1683
1720
  };
1684
1721
  if (!invocation.dryRun) {
1685
- fs2.writeFileSync(
1686
- path2.join(outRoot, "WORKSPACE.json"),
1687
- JSON.stringify(document, null, 2) + "\n",
1688
- "utf8"
1689
- );
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
+ }
1690
1742
  }
1691
1743
  emit(invocation.format, document, () => {
1692
1744
  info(
@@ -1725,8 +1777,10 @@ ${USAGE}
1725
1777
  if (shape !== null) {
1726
1778
  return fail(invocation.format, manifestPath + " is not a snapshot manifest: " + shape);
1727
1779
  }
1728
- deltaBase = { manifest: base, path: manifestPath };
1729
- 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) + ")");
1730
1784
  }
1731
1785
  const manifest = generateSnapshot(resolved, {
1732
1786
  dryRun: invocation.dryRun,
@@ -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 };