nulladrift 0.5.0 → 0.6.1

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/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/index.ts
4
4
  import { parseArgs } from "util";
5
- import { resolve as resolve3 } from "path";
5
+ import { resolve as resolve4 } from "path";
6
6
 
7
7
  // ../core/src/changes.ts
8
8
  var CHANGE_KINDS = [
@@ -11,6 +11,17 @@ var CHANGE_KINDS = [
11
11
  "server.renamed",
12
12
  "server.transport.changed",
13
13
  "server.identity.changed",
14
+ /*
15
+ * Two kinds rather than one, because they call for opposite defaults.
16
+ *
17
+ * A version moving is the ordinary life of a dependency: most of them are patch releases that
18
+ * nobody needs to read, and a policy blocking on them would fail every build in the week a
19
+ * popular package ships. A version *not* moving while its contents do has no innocent
20
+ * explanation -- a registry or mirror serving different bytes under a published version, or an
21
+ * image tag repointed -- and that one should stop a build on the default policy.
22
+ */
23
+ "server.artifact.changed",
24
+ "server.artifact.substituted",
14
25
  "server.protocol.changed",
15
26
  "server.instructions.changed",
16
27
  "server.capabilities.widened",
@@ -44,6 +55,8 @@ var SEVERITY = {
44
55
  "server.renamed": "low",
45
56
  "server.transport.changed": "high",
46
57
  "server.identity.changed": "medium",
58
+ "server.artifact.changed": "medium",
59
+ "server.artifact.substituted": "high",
47
60
  "server.protocol.changed": "medium",
48
61
  "server.instructions.changed": "high",
49
62
  "server.capabilities.widened": "medium",
@@ -177,6 +190,122 @@ function resealMcpServer(entry) {
177
190
  };
178
191
  }
179
192
 
193
+ // ../core/src/lock/credentials.ts
194
+ var REDACTED = "REDACTED";
195
+ var CREDENTIAL_NAME = /(?:^|[-_.])(?:api[-_]?key|apikey|access[-_]?key|secret(?:[-_]?key)?|client[-_]?secret|token|access[-_]?token|auth[-_]?token|refresh[-_]?token|bearer|password|passwd|pass|pwd|private[-_]?key|credentials?)$/i;
196
+ var ISSUER_FORMATS = [
197
+ /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
198
+ // AWS access key id
199
+ /\bgh[pousr]_[A-Za-z0-9]{36,}\b/g,
200
+ // GitHub
201
+ /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
202
+ /\bglpat-[A-Za-z0-9_-]{20,}/g,
203
+ // GitLab
204
+ /\bxox[abprs]-[A-Za-z0-9-]{10,}/g,
205
+ // Slack
206
+ /\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}\b/g,
207
+ // Stripe
208
+ /\bsk-ant-[A-Za-z0-9_-]{20,}/g,
209
+ // Anthropic
210
+ /\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{32,}/g,
211
+ // OpenAI
212
+ /\bAIza[0-9A-Za-z_-]{35}\b/g,
213
+ // Google API key
214
+ /\bnpm_[A-Za-z0-9]{36}\b/g,
215
+ /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
216
+ // JWT
217
+ ];
218
+ var PLACEHOLDER = /\$\{|^\$[A-Za-z_]/;
219
+ function looksRandom(value) {
220
+ if (value.length < 32 || !/^[A-Za-z0-9_-]+$/.test(value)) return false;
221
+ if (!/[a-z]/.test(value) || !/[A-Z]/.test(value) || !/[0-9]/.test(value)) return false;
222
+ const kind = (character) => /[a-z]/.test(character) ? 0 : /[A-Z]/.test(character) ? 1 : /[0-9]/.test(character) ? 2 : 3;
223
+ let switches = 0;
224
+ for (let index = 1; index < value.length; index += 1) {
225
+ if (kind(value[index] ?? "") !== kind(value[index - 1] ?? "")) switches += 1;
226
+ }
227
+ return switches >= value.length / 3;
228
+ }
229
+ function decoded(value) {
230
+ try {
231
+ return decodeURIComponent(value);
232
+ } catch {
233
+ return value;
234
+ }
235
+ }
236
+ function isSecretValue(value) {
237
+ if (value === "" || value === REDACTED || PLACEHOLDER.test(value)) return false;
238
+ if (/^(?:[./~]|[A-Za-z]:\\|[a-z][a-z0-9+.-]*:\/\/)/i.test(value)) return false;
239
+ return true;
240
+ }
241
+ function redactFormats(value) {
242
+ let out = value;
243
+ for (const format of ISSUER_FORMATS) out = out.replace(format, REDACTED);
244
+ return out;
245
+ }
246
+ function redactUrl(value) {
247
+ if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) return value;
248
+ let url;
249
+ try {
250
+ url = new URL(value);
251
+ } catch {
252
+ return value;
253
+ }
254
+ let changed = false;
255
+ if (url.password && !PLACEHOLDER.test(decoded(url.password))) {
256
+ url.password = REDACTED;
257
+ changed = true;
258
+ }
259
+ for (const [key, parameter] of [...url.searchParams]) {
260
+ if (CREDENTIAL_NAME.test(key) && isSecretValue(parameter)) {
261
+ url.searchParams.set(key, REDACTED);
262
+ changed = true;
263
+ }
264
+ }
265
+ return changed ? url.toString() : value;
266
+ }
267
+ function redactArgs(args) {
268
+ const out = [...args];
269
+ for (let index = 0; index < out.length; index += 1) {
270
+ const argument = out[index] ?? "";
271
+ const assignment = /^(-{0,2}[A-Za-z][A-Za-z0-9_.-]*)=(.*)$/s.exec(argument);
272
+ if (assignment) {
273
+ const [, name = "", value = ""] = assignment;
274
+ if (CREDENTIAL_NAME.test(name.replace(/^-+/, "")) && isSecretValue(value)) {
275
+ out[index] = `${name}=${REDACTED}`;
276
+ continue;
277
+ }
278
+ if (!PLACEHOLDER.test(value)) out[index] = `${name}=${looksRandom(value) ? REDACTED : redactFormats(redactUrl(value))}`;
279
+ continue;
280
+ }
281
+ const flag = /^-{1,2}([A-Za-z][A-Za-z0-9_.-]*)$/.exec(argument);
282
+ const next = out[index + 1];
283
+ if (flag && next !== void 0 && !next.startsWith("-") && CREDENTIAL_NAME.test(flag[1] ?? "") && isSecretValue(next)) {
284
+ out[index + 1] = REDACTED;
285
+ index += 1;
286
+ continue;
287
+ }
288
+ if (PLACEHOLDER.test(argument)) continue;
289
+ if (looksRandom(argument)) {
290
+ out[index] = REDACTED;
291
+ continue;
292
+ }
293
+ out[index] = redactFormats(redactUrl(argument));
294
+ }
295
+ return out;
296
+ }
297
+ function redactPath(pathname) {
298
+ return pathname.split("/").map((segment) => {
299
+ if (segment === "" || PLACEHOLDER.test(decoded(segment))) return segment;
300
+ if (looksRandom(segment)) return REDACTED;
301
+ return redactFormats(segment);
302
+ }).join("/");
303
+ }
304
+ function countRedacted(transport2) {
305
+ const occurrences = (text) => text.split(REDACTED).length - 1;
306
+ return (transport2.args ?? []).reduce((total, argument) => total + occurrences(argument), 0) + occurrences(transport2.url ?? "");
307
+ }
308
+
180
309
  // ../core/src/lock/jsonschema.ts
181
310
  var MAX_REF_DEPTH = 32;
182
311
  var MAX_VISIT_DEPTH = 12;
@@ -185,12 +314,12 @@ function asObject(value) {
185
314
  return value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value) ? value : void 0;
186
315
  }
187
316
  function decodeToken(token) {
188
- let decoded = token;
317
+ let decoded2 = token;
189
318
  try {
190
- decoded = decodeURIComponent(token);
319
+ decoded2 = decodeURIComponent(token);
191
320
  } catch {
192
321
  }
193
- return decoded.replace(/~1/g, "/").replace(/~0/g, "~");
322
+ return decoded2.replace(/~1/g, "/").replace(/~0/g, "~");
194
323
  }
195
324
  function resolvePointer(root, ref) {
196
325
  if (!ref.startsWith("#")) return void 0;
@@ -317,6 +446,7 @@ function sanitizeUrl(raw) {
317
446
  url.hash = "";
318
447
  url.username = "";
319
448
  url.password = "";
449
+ url.pathname = redactPath(url.pathname);
320
450
  return url.toString();
321
451
  } catch {
322
452
  return raw;
@@ -683,9 +813,40 @@ function compareMembers(name, before, after, spec, deep) {
683
813
  }
684
814
  return changes;
685
815
  }
816
+ function compareProvenance(name, before, after) {
817
+ const was = before.provenance;
818
+ const now = after.provenance;
819
+ if (!was || !now) return [];
820
+ if (was.ecosystem !== now.ecosystem || was.name !== now.name) return [];
821
+ const surfaceHeld = before.digest === after.digest;
822
+ const unexplained = surfaceHeld ? ", and the declared surface did not change: nothing else in this report describes what the new code does" : "";
823
+ const integrityMoved = was.integrity !== void 0 && now.integrity !== void 0 && was.integrity !== now.integrity;
824
+ if (was.version !== void 0 && was.version === now.version) {
825
+ if (!integrityMoved) return [];
826
+ if (was.ecosystem === "npm") {
827
+ return [
828
+ change(
829
+ "server.artifact.substituted",
830
+ name,
831
+ `${was.name}@${was.version} now has different contents than when it was pinned: the same version, different bytes`,
832
+ { before: was, after: now }
833
+ )
834
+ ];
835
+ }
836
+ return [change("server.artifact.changed", name, `the files published for ${was.name}@${was.version} are not the ones that were pinned${unexplained}`, { before: was, after: now })];
837
+ }
838
+ if (was.version !== now.version) {
839
+ const moved = `the package behind this server moved from ${was.version ?? "an unknown version"} to ${now.version ?? "an unknown version"}`;
840
+ return [change("server.artifact.changed", name, `${moved}${unexplained}`, { before: was, after: now })];
841
+ }
842
+ if (!integrityMoved) return [];
843
+ const what = was.ecosystem === "oci" ? `the image ${was.name}:${was.requested ?? "latest"} now resolves to a different digest` : "the file this server runs from has different contents than when it was pinned";
844
+ return [change("server.artifact.changed", name, `${what}${unexplained}`, { before: was, after: now })];
845
+ }
686
846
  function compareServer(name, before, after) {
687
- if (before.digest === after.digest) return [];
688
- const changes = [];
847
+ const provenance2 = compareProvenance(name, before, after);
848
+ if (before.digest === after.digest) return provenance2;
849
+ const changes = [...provenance2];
689
850
  if (!same(before.transport, after.transport)) {
690
851
  changes.push(change("server.transport.changed", name, "the server is reached differently than when it was pinned", { before: before.transport, after: after.transport }));
691
852
  }
@@ -1021,10 +1182,10 @@ import { z } from "zod";
1021
1182
 
1022
1183
  // src/config/expand.ts
1023
1184
  import { homedir } from "os";
1024
- var PLACEHOLDER = /\$\{([^}]+)\}/g;
1185
+ var PLACEHOLDER2 = /\$\{([^}]+)\}/g;
1025
1186
  function expand(input, context) {
1026
1187
  const unresolved = [];
1027
- const value = input.replace(PLACEHOLDER, (match, body) => {
1188
+ const value = input.replace(PLACEHOLDER2, (match, body) => {
1028
1189
  if (body === "workspaceFolder") return context.workspaceFolder;
1029
1190
  if (body === "userHome") return homedir();
1030
1191
  if (body === "pathSeparator" || body === "/") return "/";
@@ -1121,7 +1282,11 @@ function resolveTransport(name, entry, context) {
1121
1282
  type: "stdio",
1122
1283
  command: take(entry.command),
1123
1284
  args: (entry.args ?? []).map((argument) => take(String(argument))),
1124
- asWritten: { command: String(entry.command), args: (entry.args ?? []).map((argument) => String(argument)) },
1285
+ asWritten: {
1286
+ command: String(entry.command),
1287
+ args: (entry.args ?? []).map((argument) => String(argument)),
1288
+ ...entry.cwd ? { cwd: String(entry.cwd) } : {}
1289
+ },
1125
1290
  env: Object.fromEntries(Object.entries(scalarsToStrings(entry.env)).map(([key, value]) => [key, take(value)])),
1126
1291
  cwd: entry.cwd ? take(entry.cwd) : void 0
1127
1292
  };
@@ -1349,13 +1514,13 @@ function lockTransport(server2) {
1349
1514
  const { transport: transport2 } = server2;
1350
1515
  if (transport2.type === "stdio") {
1351
1516
  const command = transport2.asWritten?.command ?? transport2.command;
1352
- const args = transport2.asWritten?.args ?? transport2.args;
1517
+ const args = redactArgs(transport2.asWritten?.args ?? transport2.args);
1353
1518
  return {
1354
1519
  type: "stdio",
1355
1520
  command,
1356
1521
  args: args.length > 0 ? args : void 0,
1357
1522
  envKeys: Object.keys(transport2.env).length > 0 ? Object.keys(transport2.env).sort() : void 0,
1358
- cwd: transport2.cwd
1523
+ cwd: transport2.asWritten ? transport2.asWritten.cwd : transport2.cwd
1359
1524
  };
1360
1525
  }
1361
1526
  const headerKeys = Object.keys(transport2.headers);
@@ -1455,31 +1620,428 @@ function buildLockedServer(server2, surface, policy) {
1455
1620
  return { kind: "mcp-server", ...entry, digest: digest(toJson(covered)) };
1456
1621
  }
1457
1622
 
1623
+ // src/lock/provenance.ts
1624
+ import { createHash as createHash2 } from "crypto";
1625
+ import { readFile as readFile3 } from "fs/promises";
1626
+ import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
1627
+
1628
+ // src/lib/version.ts
1629
+ var VERSION = "0.6.1";
1630
+ var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
1631
+
1632
+ // src/lock/provenance.ts
1633
+ var NPM_NAME = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i;
1634
+ var NPM_EXACT = /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
1635
+ var NPM_TAG = /^[a-z][\w.-]*$/i;
1636
+ function splitNpmSpec(spec) {
1637
+ const at = spec.lastIndexOf("@");
1638
+ const name = at > 0 ? spec.slice(0, at) : spec;
1639
+ const requested = at > 0 ? spec.slice(at + 1) : void 0;
1640
+ if (!NPM_NAME.test(name)) return void 0;
1641
+ if (requested !== void 0 && requested.length === 0) return void 0;
1642
+ return requested === void 0 ? { name } : { name, requested };
1643
+ }
1644
+ function normalizePypi(name) {
1645
+ return name.replace(/[-_.]+/g, "-").toLowerCase();
1646
+ }
1647
+ var PYPI_EXACT = /^\d[\w.!+-]*$/;
1648
+ function splitPypiSpec(spec) {
1649
+ const text = spec.trim();
1650
+ if (/^(git\+|hg\+|svn\+|bzr\+|https?:|file:|\.|\/|~)/.test(text)) return void 0;
1651
+ const match = /^([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)(?:\[[^\]]*\])?\s*(?:(===?|>=|<=|~=|!=|>|<|@)\s*(\S.*))?$/.exec(text);
1652
+ if (!match) return void 0;
1653
+ const name = normalizePypi(match[1]);
1654
+ const operator = match[2];
1655
+ const value = match[3]?.trim();
1656
+ if (operator === void 0) return { name };
1657
+ if (value === void 0 || value.length === 0) return void 0;
1658
+ return operator === "==" || operator === "===" || operator === "@" ? { name, requested: value } : { name, requested: `${operator}${value}` };
1659
+ }
1660
+ function splitImage(reference) {
1661
+ let rest = reference;
1662
+ let digest2;
1663
+ const at = rest.indexOf("@");
1664
+ if (at >= 0) {
1665
+ digest2 = rest.slice(at + 1);
1666
+ rest = rest.slice(0, at);
1667
+ if (!/^sha256:[a-f0-9]{64}$/.test(digest2)) return void 0;
1668
+ }
1669
+ let tag;
1670
+ const colon = rest.lastIndexOf(":");
1671
+ if (colon > rest.lastIndexOf("/")) {
1672
+ tag = rest.slice(colon + 1);
1673
+ rest = rest.slice(0, colon);
1674
+ if (!/^[\w][\w.-]{0,127}$/.test(tag)) return void 0;
1675
+ }
1676
+ if (!/^[a-z0-9]+(?:[._:-][a-z0-9]+)*(?:\/[a-z0-9]+(?:[._-][a-z0-9]+)*)*$/i.test(rest)) return void 0;
1677
+ return { name: rest, ...tag === void 0 ? {} : { tag }, ...digest2 === void 0 ? {} : { digest: digest2 } };
1678
+ }
1679
+ var NPM_VALUE_FLAGS = /* @__PURE__ */ new Set(["-p", "--package", "-c", "--call", "--registry", "--cache", "--userconfig", "--prefix", "-w", "--workspace", "--node-options"]);
1680
+ var UV_VALUE_FLAGS = /* @__PURE__ */ new Set([
1681
+ "--from",
1682
+ "--with",
1683
+ "--with-editable",
1684
+ "--with-requirements",
1685
+ "--python",
1686
+ "-p",
1687
+ "--index",
1688
+ "--index-url",
1689
+ "--extra-index-url",
1690
+ "--default-index",
1691
+ "--find-links",
1692
+ "-f",
1693
+ "--constraint",
1694
+ "-c",
1695
+ "--override",
1696
+ "--build-constraint",
1697
+ "--refresh-package",
1698
+ "--reinstall-package",
1699
+ "--upgrade-package",
1700
+ "-P",
1701
+ "--directory",
1702
+ "--project",
1703
+ "--config-file",
1704
+ "--cache-dir",
1705
+ "--color",
1706
+ "--resolution",
1707
+ "--prerelease",
1708
+ "--exclude-newer",
1709
+ "--link-mode",
1710
+ "--env-file",
1711
+ "--spec",
1712
+ "--pip-args",
1713
+ "--keyring-provider",
1714
+ "--index-strategy"
1715
+ ]);
1716
+ var DOCKER_VALUE_FLAGS = /* @__PURE__ */ new Set([
1717
+ "-a",
1718
+ "--attach",
1719
+ "--add-host",
1720
+ "--annotation",
1721
+ "--blkio-weight",
1722
+ "--blkio-weight-device",
1723
+ "--cap-add",
1724
+ "--cap-drop",
1725
+ "--cgroup-parent",
1726
+ "--cgroupns",
1727
+ "--cidfile",
1728
+ "-c",
1729
+ "--cpu-shares",
1730
+ "--cpu-period",
1731
+ "--cpu-quota",
1732
+ "--cpu-rt-period",
1733
+ "--cpu-rt-runtime",
1734
+ "--cpus",
1735
+ "--cpuset-cpus",
1736
+ "--cpuset-mems",
1737
+ "--device",
1738
+ "--device-cgroup-rule",
1739
+ "--device-read-bps",
1740
+ "--device-read-iops",
1741
+ "--device-write-bps",
1742
+ "--device-write-iops",
1743
+ "--dns",
1744
+ "--dns-option",
1745
+ "--dns-search",
1746
+ "--domainname",
1747
+ "--entrypoint",
1748
+ "-e",
1749
+ "--env",
1750
+ "--env-file",
1751
+ "--expose",
1752
+ "--gpus",
1753
+ "--group-add",
1754
+ "--health-cmd",
1755
+ "--health-interval",
1756
+ "--health-retries",
1757
+ "--health-start-period",
1758
+ "--health-start-interval",
1759
+ "--health-timeout",
1760
+ "-h",
1761
+ "--hostname",
1762
+ "--ip",
1763
+ "--ip6",
1764
+ "--ipc",
1765
+ "--isolation",
1766
+ "--kernel-memory",
1767
+ "-l",
1768
+ "--label",
1769
+ "--label-file",
1770
+ "--link",
1771
+ "--link-local-ip",
1772
+ "--log-driver",
1773
+ "--log-opt",
1774
+ "--mac-address",
1775
+ "-m",
1776
+ "--memory",
1777
+ "--memory-reservation",
1778
+ "--memory-swap",
1779
+ "--memory-swappiness",
1780
+ "--mount",
1781
+ "--name",
1782
+ "--network",
1783
+ "--net",
1784
+ "--network-alias",
1785
+ "--net-alias",
1786
+ "--oom-score-adj",
1787
+ "--pid",
1788
+ "--pids-limit",
1789
+ "--platform",
1790
+ "-p",
1791
+ "--publish",
1792
+ "--pull",
1793
+ "--restart",
1794
+ "--runtime",
1795
+ "--security-opt",
1796
+ "--shm-size",
1797
+ "--stop-signal",
1798
+ "--stop-timeout",
1799
+ "--storage-opt",
1800
+ "--sysctl",
1801
+ "--tmpfs",
1802
+ "--ulimit",
1803
+ "-u",
1804
+ "--user",
1805
+ "--userns",
1806
+ "--uts",
1807
+ "-v",
1808
+ "--volume",
1809
+ "--volume-driver",
1810
+ "--volumes-from",
1811
+ "-w",
1812
+ "--workdir",
1813
+ "--detach-keys"
1814
+ ]);
1815
+ var DOCKER_VALUE_SHORT = /* @__PURE__ */ new Set(["a", "c", "e", "h", "l", "m", "p", "u", "v", "w"]);
1816
+ function firstPositional(args, valueFlags, explicitFlags, shortValues) {
1817
+ let explicit;
1818
+ for (let index = 0; index < args.length; index += 1) {
1819
+ const arg = args[index];
1820
+ if (arg === "--") return { positional: args[index + 1], explicit };
1821
+ const equals = arg.indexOf("=");
1822
+ if (arg.startsWith("--") && equals > 0) {
1823
+ if (explicitFlags.includes(arg.slice(0, equals))) explicit = arg.slice(equals + 1);
1824
+ continue;
1825
+ }
1826
+ if (explicitFlags.includes(arg)) {
1827
+ explicit = args[index + 1];
1828
+ index += 1;
1829
+ continue;
1830
+ }
1831
+ if (arg.startsWith("-") && arg.length > 1) {
1832
+ if (valueFlags.has(arg)) index += 1;
1833
+ else if (shortValues && !arg.startsWith("--") && arg.length > 2 && shortValues.has(arg.at(-1))) index += 1;
1834
+ continue;
1835
+ }
1836
+ return { positional: arg, explicit };
1837
+ }
1838
+ return { explicit };
1839
+ }
1840
+ function commandName(command) {
1841
+ return (command.split(/[\\/]/).pop() ?? command).replace(/\.(cmd|exe|bat|ps1)$/i, "").toLowerCase();
1842
+ }
1843
+ var SCRIPT_FILE = /\.(?:[cm]?[jt]s|tsx?|py|pyw)$/i;
1844
+ function looksLikePath(value) {
1845
+ return isAbsolute2(value) || value.startsWith("./") || value.startsWith("../") || value.startsWith("~/") || /[\\/]/.test(value);
1846
+ }
1847
+ var SCRIPT_RUNNERS = /* @__PURE__ */ new Set(["node", "nodejs", "deno", "bun", "tsx", "ts-node", "python", "python3"]);
1848
+ function referenceOf(transport2, projectRoot) {
1849
+ const name = commandName(transport2.command);
1850
+ const args = transport2.args;
1851
+ const base = transport2.cwd ?? projectRoot;
1852
+ const npm = (rest) => {
1853
+ const { positional, explicit } = firstPositional(rest, NPM_VALUE_FLAGS, ["-p", "--package"]);
1854
+ if (explicit === void 0 && rest.some((arg) => arg === "-c" || arg === "--call" || arg.startsWith("--call="))) return void 0;
1855
+ const spec = explicit ?? positional;
1856
+ const parsed = spec === void 0 ? void 0 : splitNpmSpec(spec);
1857
+ return parsed ? { ecosystem: "npm", ...parsed } : void 0;
1858
+ };
1859
+ const pypi = (rest) => {
1860
+ const { positional, explicit } = firstPositional(rest, UV_VALUE_FLAGS, ["--from", "--spec"]);
1861
+ const spec = explicit ?? positional;
1862
+ const parsed = spec === void 0 ? void 0 : splitPypiSpec(spec);
1863
+ return parsed ? { ecosystem: "pypi", ...parsed } : void 0;
1864
+ };
1865
+ if (name === "npx" || name === "bunx" || name === "pnpx") return npm(args);
1866
+ if ((name === "pnpm" || name === "yarn") && args[0] === "dlx") return npm(args.slice(1));
1867
+ if (name === "npm" && (args[0] === "exec" || args[0] === "x")) return npm(args.slice(1));
1868
+ if (name === "uvx") return pypi(args);
1869
+ if (name === "uv" && args[0] === "tool" && args[1] === "run") return pypi(args.slice(2));
1870
+ if (name === "pipx" && args[0] === "run") return pypi(args.slice(1));
1871
+ if ((name === "docker" || name === "podman") && args[0] === "run") {
1872
+ const { positional } = firstPositional(args.slice(1), DOCKER_VALUE_FLAGS, [], DOCKER_VALUE_SHORT);
1873
+ const image = positional === void 0 ? void 0 : splitImage(positional);
1874
+ if (!image) return void 0;
1875
+ return {
1876
+ ecosystem: "oci",
1877
+ name: image.name,
1878
+ // A digest is the most specific thing the invocation can ask for, and the one that does not move.
1879
+ ...image.digest ? { requested: image.digest, digest: image.digest } : { requested: image.tag ?? "latest" }
1880
+ };
1881
+ }
1882
+ if (SCRIPT_RUNNERS.has(name)) {
1883
+ if (args.includes("-m")) return void 0;
1884
+ const runArgs = (name === "deno" || name === "bun") && args[0] === "run" ? args.slice(1) : args;
1885
+ const { positional } = firstPositional(runArgs, /* @__PURE__ */ new Set(["-r", "--require", "--import", "--loader", "-e", "--eval", "-c"]), []);
1886
+ if (positional === void 0 || /^[a-z]+:\/\//i.test(positional)) return void 0;
1887
+ if (!looksLikePath(positional) && !SCRIPT_FILE.test(positional)) return void 0;
1888
+ const path = resolve3(base, positional);
1889
+ return { ecosystem: "file", name: portablePath(path, projectRoot), path };
1890
+ }
1891
+ if (looksLikePath(transport2.command)) {
1892
+ const path = resolve3(base, transport2.command);
1893
+ return { ecosystem: "file", name: portablePath(path, projectRoot), path };
1894
+ }
1895
+ return void 0;
1896
+ }
1897
+ function isExact(reference) {
1898
+ switch (reference.ecosystem) {
1899
+ case "npm":
1900
+ return reference.requested !== void 0 && NPM_EXACT.test(reference.requested);
1901
+ case "pypi":
1902
+ return reference.requested !== void 0 && PYPI_EXACT.test(reference.requested);
1903
+ case "oci":
1904
+ return reference.digest !== void 0;
1905
+ case "file":
1906
+ return false;
1907
+ }
1908
+ }
1909
+ var DEFAULT_TIMEOUT_MS = 1e4;
1910
+ async function getJson(url, options) {
1911
+ const response = await (options.fetch ?? fetch)(url, {
1912
+ // Identified, like every other request this tool makes: see USER_AGENT.
1913
+ headers: { accept: "application/json", "user-agent": USER_AGENT },
1914
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
1915
+ });
1916
+ if (!response.ok) return void 0;
1917
+ return response.json();
1918
+ }
1919
+ async function resolveNpm(reference, options) {
1920
+ const asked = reference.requested ?? "latest";
1921
+ if (!NPM_EXACT.test(asked) && !NPM_TAG.test(asked)) return void 0;
1922
+ const registry = (process.env["npm_config_registry"] ?? "https://registry.npmjs.org").replace(/\/+$/, "");
1923
+ const body = await getJson(`${registry}/${reference.name.replace("/", "%2F")}/${encodeURIComponent(asked)}`, options);
1924
+ if (typeof body?.version !== "string") return void 0;
1925
+ const integrity = typeof body.dist?.integrity === "string" ? body.dist.integrity : typeof body.dist?.shasum === "string" ? `sha1:${body.dist.shasum}` : void 0;
1926
+ return { ecosystem: "npm", name: reference.name, version: body.version, ...integrity ? { integrity } : {}, ...requestedOf(reference) };
1927
+ }
1928
+ async function resolvePypi(reference, options) {
1929
+ if (reference.requested !== void 0 && !PYPI_EXACT.test(reference.requested)) return void 0;
1930
+ const base = (process.env["NULLADRIFT_PYPI_URL"] ?? "https://pypi.org/pypi").replace(/\/+$/, "");
1931
+ const url = reference.requested ? `${base}/${reference.name}/${encodeURIComponent(reference.requested)}/json` : `${base}/${reference.name}/json`;
1932
+ const body = await getJson(url, options);
1933
+ if (typeof body?.info?.version !== "string") return void 0;
1934
+ const files = (body.urls ?? []).filter((file) => typeof file.filename === "string");
1935
+ const chosen = files.find((file) => file.packagetype === "sdist") ?? files.filter((file) => /-none-any\.whl$/.test(file.filename)).sort((a, b) => a.filename.localeCompare(b.filename))[0];
1936
+ const sha = chosen?.digests?.sha256;
1937
+ return {
1938
+ ecosystem: "pypi",
1939
+ name: reference.name,
1940
+ version: body.info.version,
1941
+ ...typeof sha === "string" && /^[a-f0-9]{64}$/.test(sha) ? { integrity: `sha256:${sha}` } : {},
1942
+ ...requestedOf(reference)
1943
+ };
1944
+ }
1945
+ function imageLocation(name) {
1946
+ const parts = name.split("/");
1947
+ const first = parts[0];
1948
+ const hasHost = parts.length > 1 && (first.includes(".") || first.includes(":") || first === "localhost");
1949
+ let host = hasHost ? first : "registry-1.docker.io";
1950
+ if (host === "docker.io" || host === "index.docker.io") host = "registry-1.docker.io";
1951
+ let repository = hasHost ? parts.slice(1).join("/") : name;
1952
+ if (host === "registry-1.docker.io" && !repository.includes("/")) repository = `library/${repository}`;
1953
+ return { host, repository };
1954
+ }
1955
+ function bearerChallenge(header) {
1956
+ if (!header || !/^bearer\s/i.test(header)) return void 0;
1957
+ const fields = {};
1958
+ for (const match of header.slice(7).matchAll(/(\w+)="([^"]*)"/g)) fields[match[1].toLowerCase()] = match[2];
1959
+ if (!fields["realm"]?.startsWith("https://")) return void 0;
1960
+ return { realm: fields["realm"], service: fields["service"], scope: fields["scope"] };
1961
+ }
1962
+ var MANIFEST_TYPES = [
1963
+ "application/vnd.oci.image.index.v1+json",
1964
+ "application/vnd.docker.distribution.manifest.list.v2+json",
1965
+ "application/vnd.oci.image.manifest.v1+json",
1966
+ "application/vnd.docker.distribution.manifest.v2+json"
1967
+ ].join(", ");
1968
+ async function resolveOci(reference, options) {
1969
+ if (reference.digest) return { ecosystem: "oci", name: reference.name, integrity: reference.digest, ...requestedOf(reference) };
1970
+ const doFetch = options.fetch ?? fetch;
1971
+ const { host, repository } = imageLocation(reference.name);
1972
+ const url = `https://${host}/v2/${repository}/manifests/${encodeURIComponent(reference.requested ?? "latest")}`;
1973
+ const ask = (authorization) => doFetch(url, {
1974
+ method: "HEAD",
1975
+ headers: { accept: MANIFEST_TYPES, "user-agent": USER_AGENT, ...authorization ? { authorization } : {} },
1976
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
1977
+ });
1978
+ let response = await ask();
1979
+ if (response.status === 401) {
1980
+ const challenge = bearerChallenge(response.headers.get("www-authenticate"));
1981
+ if (!challenge) return void 0;
1982
+ const tokenUrl = new URL(challenge.realm);
1983
+ if (challenge.service) tokenUrl.searchParams.set("service", challenge.service);
1984
+ tokenUrl.searchParams.set("scope", challenge.scope ?? `repository:${repository}:pull`);
1985
+ const grant = await getJson(tokenUrl.toString(), options);
1986
+ const token = typeof grant?.token === "string" ? grant.token : typeof grant?.access_token === "string" ? grant.access_token : void 0;
1987
+ if (!token) return void 0;
1988
+ response = await ask(`Bearer ${token}`);
1989
+ }
1990
+ if (!response.ok) return void 0;
1991
+ const digest2 = response.headers.get("docker-content-digest");
1992
+ if (!digest2 || !/^sha256:[a-f0-9]{64}$/.test(digest2)) return void 0;
1993
+ return { ecosystem: "oci", name: reference.name, integrity: digest2, ...requestedOf(reference) };
1994
+ }
1995
+ async function resolveFile(reference) {
1996
+ if (!reference.path) return void 0;
1997
+ const bytes = await readFile3(reference.path);
1998
+ return { ecosystem: "file", name: reference.name, integrity: `sha256:${createHash2("sha256").update(bytes).digest("hex")}` };
1999
+ }
2000
+ function requestedOf(reference) {
2001
+ return reference.requested === void 0 ? {} : { requested: reference.requested };
2002
+ }
2003
+ async function resolveReference(reference, options = {}) {
2004
+ try {
2005
+ switch (reference.ecosystem) {
2006
+ case "npm":
2007
+ return await resolveNpm(reference, options);
2008
+ case "pypi":
2009
+ return await resolvePypi(reference, options);
2010
+ case "oci":
2011
+ return await resolveOci(reference, options);
2012
+ case "file":
2013
+ return await resolveFile(reference);
2014
+ }
2015
+ } catch {
2016
+ return void 0;
2017
+ }
2018
+ }
2019
+ function carriedForward(previous, reference) {
2020
+ if (!previous) return void 0;
2021
+ if (previous.ecosystem !== reference.ecosystem || previous.name !== reference.name) return void 0;
2022
+ if (previous.requested !== reference.requested || !isExact(reference)) return void 0;
2023
+ return previous;
2024
+ }
2025
+
1458
2026
  // src/mcp/connect.ts
1459
2027
  import { Client, SSEClientTransport, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
1460
2028
  import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotocol/client/stdio";
1461
2029
 
1462
2030
  // src/mcp/oauth.ts
1463
2031
  import { spawn } from "child_process";
1464
- import { createHash as createHash2, randomUUID } from "crypto";
2032
+ import { createHash as createHash3, randomUUID } from "crypto";
1465
2033
  import { readFileSync } from "fs";
1466
- import { mkdir, readFile as readFile3, rm, writeFile } from "fs/promises";
2034
+ import { mkdir, readFile as readFile4, rm, writeFile } from "fs/promises";
1467
2035
  import { homedir as homedir3, platform as platform2 } from "os";
1468
2036
  import { dirname, join as join2 } from "path";
1469
2037
  import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
1470
-
1471
- // src/lib/version.ts
1472
- var VERSION = "0.5.0";
1473
- var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
1474
-
1475
- // src/mcp/oauth.ts
1476
2038
  var DEFAULT_CALLBACK_PATH = "/callback";
1477
2039
  function authDir() {
1478
2040
  const base = process.env["XDG_CONFIG_HOME"] ?? join2(homedir3(), ".config");
1479
2041
  return join2(base, "nulladrift", "auth");
1480
2042
  }
1481
2043
  function credentialPath(url) {
1482
- return join2(authDir(), `${createHash2("sha256").update(url).digest("hex").slice(0, 16)}.json`);
2044
+ return join2(authDir(), `${createHash3("sha256").update(url).digest("hex").slice(0, 16)}.json`);
1483
2045
  }
1484
2046
  var InteractiveAuthRequiredError = class extends Error {
1485
2047
  constructor(serverName) {
@@ -1500,7 +2062,7 @@ var FileTokenProvider = class {
1500
2062
  options;
1501
2063
  cache;
1502
2064
  /** One per login attempt, held in memory and checked against what comes back on the callback. */
1503
- stateValue = createHash2("sha256").update(randomUUID()).digest("hex").slice(0, 32);
2065
+ stateValue = createHash3("sha256").update(randomUUID()).digest("hex").slice(0, 32);
1504
2066
  get redirectUrl() {
1505
2067
  return this.options.redirectUrl;
1506
2068
  }
@@ -1522,7 +2084,7 @@ var FileTokenProvider = class {
1522
2084
  async read() {
1523
2085
  if (this.cache) return this.cache;
1524
2086
  try {
1525
- this.cache = JSON.parse(await readFile3(credentialPath(this.serverUrl), "utf8"));
2087
+ this.cache = JSON.parse(await readFile4(credentialPath(this.serverUrl), "utf8"));
1526
2088
  } catch {
1527
2089
  this.cache = { serverUrl: this.serverUrl };
1528
2090
  }
@@ -1668,7 +2230,7 @@ function isAuthFailure(error) {
1668
2230
  }
1669
2231
 
1670
2232
  // src/mcp/connect.ts
1671
- var DEFAULT_TIMEOUT_MS = 3e4;
2233
+ var DEFAULT_TIMEOUT_MS2 = 3e4;
1672
2234
  var STDERR_KEEP_BYTES = 2e3;
1673
2235
  function buildTransport(server2, captureStderr = () => {
1674
2236
  }, options = {}) {
@@ -1699,7 +2261,7 @@ function diagnosticLines(stderr, limit = 3) {
1699
2261
  const chosen = named.length > 0 ? named : lines;
1700
2262
  return chosen.slice(0, limit).map((line) => line.trim());
1701
2263
  }
1702
- async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS, options = {}) {
2264
+ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
1703
2265
  let stderrBuffer = "";
1704
2266
  const captureStderr = (chunk) => {
1705
2267
  stderrBuffer = (stderrBuffer + chunk).slice(-STDERR_KEEP_BYTES);
@@ -1808,7 +2370,7 @@ function readServerInfo(client) {
1808
2370
  websiteUrl: info.websiteUrl
1809
2371
  };
1810
2372
  }
1811
- async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS) {
2373
+ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
1812
2374
  const connection = await connect(server2, timeoutMs);
1813
2375
  const { client } = connection;
1814
2376
  try {
@@ -1836,6 +2398,20 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS) {
1836
2398
  }
1837
2399
 
1838
2400
  // src/audit.ts
2401
+ async function provenanceOf(server2, options) {
2402
+ if (server2.transport.type !== "stdio") return { unverified: false };
2403
+ const reference = referenceOf(server2.transport, options.projectRoot);
2404
+ if (!reference) return { unverified: false };
2405
+ const previous = options.previous?.subjects[server2.name]?.provenance;
2406
+ if (options.provenance === false) {
2407
+ const kept2 = carriedForward(previous, reference);
2408
+ return { ...kept2 ? { provenance: kept2 } : {}, unverified: true };
2409
+ }
2410
+ const resolved = await resolveReference(reference, { timeoutMs: options.timeoutMs });
2411
+ if (resolved) return { provenance: resolved, unverified: false };
2412
+ const kept = carriedForward(previous, reference);
2413
+ return { ...kept ? { provenance: kept } : {}, unverified: true };
2414
+ }
1839
2415
  async function mapWithLimit(items, limit, worker) {
1840
2416
  const results = new Array(items.length);
1841
2417
  let next = 0;
@@ -1869,12 +2445,14 @@ async function captureAll(options) {
1869
2445
  const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
1870
2446
  try {
1871
2447
  const surface = await withDeadline(
1872
- options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
2448
+ options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
1873
2449
  server2.name,
1874
- () => captureSurface(server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
2450
+ () => captureSurface(server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2)
1875
2451
  );
2452
+ const entry = buildLockedServer(server2, surface, options.policy);
2453
+ const { provenance: provenance2, unverified: unverified2 } = await provenanceOf(server2, options);
1876
2454
  options.onServerDone?.(server2.name, "captured");
1877
- return { name: server2.name, entry: buildLockedServer(server2, surface, options.policy) };
2455
+ return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2 };
1878
2456
  } catch (error) {
1879
2457
  options.onServerDone?.(server2.name, "failed");
1880
2458
  const reason = error instanceof UnreachableServerError ? error.message : error.message;
@@ -1884,9 +2462,12 @@ async function captureAll(options) {
1884
2462
  });
1885
2463
  const subjects = {};
1886
2464
  const unreachable = [];
2465
+ const unverified = [];
1887
2466
  for (const result of captured) {
1888
- if ("entry" in result && result.entry) subjects[result.name] = result.entry;
1889
- else if ("failure" in result && result.failure) unreachable.push(result.failure);
2467
+ if ("entry" in result && result.entry) {
2468
+ subjects[result.name] = result.entry;
2469
+ if (result.unverified) unverified.push(result.name);
2470
+ } else if ("failure" in result && result.failure) unreachable.push(result.failure);
1890
2471
  }
1891
2472
  for (const skipped of discovery.skipped) {
1892
2473
  unreachable.push({ server: skipped.serverName, reason: skipped.message, kind: "unreachable" });
@@ -1902,12 +2483,13 @@ async function captureAll(options) {
1902
2483
  subjects
1903
2484
  },
1904
2485
  unreachable,
1905
- discovery
2486
+ discovery,
2487
+ unverified: unverified.sort()
1906
2488
  };
1907
2489
  }
1908
2490
 
1909
2491
  // src/lock/io.ts
1910
- import { lstat, readFile as readFile4, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
2492
+ import { lstat, readFile as readFile5, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
1911
2493
 
1912
2494
  // src/lock/schema.ts
1913
2495
  import { z as z2 } from "zod";
@@ -1990,6 +2572,13 @@ var transport = z2.union([
1990
2572
  headerKeys: z2.array(z2.string()).optional()
1991
2573
  })
1992
2574
  ]);
2575
+ var provenance = z2.object({
2576
+ ecosystem: z2.enum(["npm", "pypi", "oci", "file"]),
2577
+ name: z2.string(),
2578
+ version: z2.string().optional(),
2579
+ integrity: z2.string().optional(),
2580
+ requested: z2.string().optional()
2581
+ });
1993
2582
  var server = z2.object({
1994
2583
  kind: z2.literal("mcp-server"),
1995
2584
  source: z2.object({
@@ -1998,6 +2587,7 @@ var server = z2.object({
1998
2587
  scope: z2.enum(["project", "user", "local"]).optional()
1999
2588
  }),
2000
2589
  transport,
2590
+ provenance: provenance.optional(),
2001
2591
  protocol: z2.object({
2002
2592
  era: z2.enum(["modern", "legacy"]),
2003
2593
  version: z2.string(),
@@ -2172,7 +2762,7 @@ function parseLockfile(text, path) {
2172
2762
  async function readLockfile(path) {
2173
2763
  let text;
2174
2764
  try {
2175
- text = await readFile4(path, "utf8");
2765
+ text = await readFile5(path, "utf8");
2176
2766
  } catch (error) {
2177
2767
  const code = error.code;
2178
2768
  if (code === "ENOENT") throw new LockfileError(`no lockfile at ${path}. Run \`nulladrift init\` first.`);
@@ -2305,6 +2895,15 @@ function renderHumanReport(report) {
2305
2895
  lines.push(` ${label} ${bold(failure.server)}`, ` ${failure.reason}`, "");
2306
2896
  }
2307
2897
  }
2898
+ const unverified = report.unverified ?? [];
2899
+ if (unverified.length > 0) {
2900
+ lines.push(
2901
+ yellow(`Could not establish what ${unverified.length} server(s) run:`),
2902
+ ...unverified.map((server2) => ` ${bold(server2)}`),
2903
+ dim(" Their surfaces were checked; the package or file behind them was not. A pin the config names exactly is kept."),
2904
+ ""
2905
+ );
2906
+ }
2308
2907
  lines.push(...renderSteering(report));
2309
2908
  if (report.changes.length === 0 && report.unreachable.length === 0 && (report.violations ?? []).length === 0) {
2310
2909
  lines.push(green(`\u2713 ${report.serversChecked} server(s) match ${report.lockPath}`));
@@ -2339,6 +2938,18 @@ function renderHumanReport(report) {
2339
2938
  `;
2340
2939
  }
2341
2940
 
2941
+ // src/report/redacted.ts
2942
+ function redactedLine(count) {
2943
+ const values = count === 1 ? "1 value that looks like a credential is" : `${count} values that look like credentials are`;
2944
+ return `${values} left out of the lock. Write each as \${VAR} instead, and rotate any an earlier mcp.lock committed.`;
2945
+ }
2946
+ function redactedNotes(lock) {
2947
+ return Object.entries(lock.subjects).flatMap(([name, entry]) => {
2948
+ const count = countRedacted(entry.transport);
2949
+ return count > 0 ? [`${name}: ${redactedLine(count)}`] : [];
2950
+ });
2951
+ }
2952
+
2342
2953
  // src/report/json.ts
2343
2954
  function renderJsonReport(report, exitCode) {
2344
2955
  return `${JSON.stringify(
@@ -2381,8 +2992,8 @@ function renderJsonReport(report, exitCode) {
2381
2992
  }
2382
2993
 
2383
2994
  // src/report/sarif.ts
2384
- import { isAbsolute as isAbsolute2, relative as relative2, sep as sep2 } from "path";
2385
- import { createHash as createHash3 } from "crypto";
2995
+ import { isAbsolute as isAbsolute3, relative as relative2, sep as sep2 } from "path";
2996
+ import { createHash as createHash4 } from "crypto";
2386
2997
 
2387
2998
  // src/lib/meta.ts
2388
2999
  var BUILT_IN_DOCS_URL = void 0;
@@ -2416,15 +3027,17 @@ var RULE_HELP = {
2416
3027
  "tool.input_schema.widened": "The tool accepts input it previously rejected, enlarging what the agent can be induced to send.",
2417
3028
  "tool.header_params.changed": "x-mcp-header mirrors an argument's value into an HTTP header, where proxies and other intermediaries can read it.",
2418
3029
  "server.transport.changed": "The configured name now points at a different command or URL. This is a different server, not a changed one.",
2419
- "server.identity.changed": "The server reports a different identity or version than the one that was reviewed."
3030
+ "server.identity.changed": "The server reports a different identity or version than the one that was reviewed.",
3031
+ "server.artifact.changed": "The package, image or file behind this server is a different release than the one pinned. When the declared surface did not change, nothing else in the report describes what the new code does; read the release, not just this diff.",
3032
+ "server.artifact.substituted": "The same published version now has different contents. Registries treat a version as immutable, so this means a mirror, proxy or registry served different bytes, or an image tag was repointed. Treat it as a supply-chain incident until shown otherwise."
2420
3033
  };
2421
3034
  function fingerprint(change2) {
2422
- return createHash3("sha256").update(`${change2.kind}\0${change2.server}\0${change2.member ?? ""}`).digest("hex").slice(0, 32);
3035
+ return createHash4("sha256").update(`${change2.kind}\0${change2.server}\0${change2.member ?? ""}`).digest("hex").slice(0, 32);
2423
3036
  }
2424
3037
  function sarifUri(report) {
2425
3038
  if (report.projectRoot === void 0) return report.lockPath;
2426
3039
  const rel = relative2(report.projectRoot, report.lockPath);
2427
- if (rel === "" || rel.startsWith("..") || isAbsolute2(rel)) return report.lockPath;
3040
+ if (rel === "" || rel.startsWith("..") || isAbsolute3(rel)) return report.lockPath;
2428
3041
  return rel.split(sep2).join("/");
2429
3042
  }
2430
3043
  function renderSarifReport(report, options = {}) {
@@ -2627,8 +3240,8 @@ ${body}`;
2627
3240
  }
2628
3241
 
2629
3242
  // src/telemetry/index.ts
2630
- import { createHash as createHash4, randomUUID as randomUUID2 } from "crypto";
2631
- import { mkdir as mkdir2, readFile as readFile5, rm as rm3, writeFile as writeFile3 } from "fs/promises";
3243
+ import { createHash as createHash5, randomUUID as randomUUID2 } from "crypto";
3244
+ import { mkdir as mkdir2, readFile as readFile6, rm as rm3, writeFile as writeFile3 } from "fs/promises";
2632
3245
  import { homedir as homedir4 } from "os";
2633
3246
  import { dirname as dirname2, join as join3 } from "path";
2634
3247
  var PAYLOAD_SCHEMA = 2;
@@ -2643,7 +3256,7 @@ function isCi() {
2643
3256
  }
2644
3257
  async function readConfig() {
2645
3258
  try {
2646
- const parsed = JSON.parse(await readFile5(configPath(), "utf8"));
3259
+ const parsed = JSON.parse(await readFile6(configPath(), "utf8"));
2647
3260
  return typeof parsed === "object" && parsed !== null ? parsed : {};
2648
3261
  } catch {
2649
3262
  return {};
@@ -2691,7 +3304,7 @@ function buildPayload(report, changes, installId) {
2691
3304
  }
2692
3305
  function reportHash(payload) {
2693
3306
  const { schema, auditVersion, context, serverCount, driftedServerCount, changes } = payload;
2694
- return createHash4("sha256").update(JSON.stringify({ schema, auditVersion, context, serverCount, driftedServerCount, changes })).digest("hex");
3307
+ return createHash5("sha256").update(JSON.stringify({ schema, auditVersion, context, serverCount, driftedServerCount, changes })).digest("hex");
2695
3308
  }
2696
3309
  async function send(payload) {
2697
3310
  const endpoint = telemetryEndpoint();
@@ -2730,8 +3343,12 @@ async function buildReport(options) {
2730
3343
  configFiles: options.configFiles,
2731
3344
  timeoutMs: options.timeoutMs,
2732
3345
  // The committed policy governs the check, so every consumer of the repo audits identically.
2733
- policy: committed.policy
3346
+ policy: committed.policy,
3347
+ previous: committed,
3348
+ provenance: options.provenance
2734
3349
  });
3350
+ for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
3351
+ `);
2735
3352
  const changes = diffLockfiles(committed, result.lock);
2736
3353
  const allowUnreachable = options.allowUnreachable || committed.policy?.allowUnreachable === true;
2737
3354
  const report = {
@@ -2748,6 +3365,8 @@ async function buildReport(options) {
2748
3365
  */
2749
3366
  violations: capabilityViolations(result.lock, committed.policy?.deniedCapabilities),
2750
3367
  unreachable: result.unreachable,
3368
+ // Reported beside the verdict and never part of it; see `AuditReport.unverified`.
3369
+ unverified: result.unverified,
2751
3370
  serversChecked: Object.keys(result.lock.subjects).length,
2752
3371
  lockPath: options.lockPath,
2753
3372
  projectRoot: options.projectRoot
@@ -2920,7 +3539,8 @@ async function runInit(options) {
2920
3539
  const result = await captureAll({
2921
3540
  projectRoot: options.projectRoot,
2922
3541
  configFiles: options.configFiles,
2923
- timeoutMs: options.timeoutMs
3542
+ timeoutMs: options.timeoutMs,
3543
+ provenance: options.provenance
2924
3544
  });
2925
3545
  const names = Object.keys(result.lock.subjects);
2926
3546
  if (names.length === 0 && result.unreachable.length === 0) {
@@ -2950,6 +3570,8 @@ async function runInit(options) {
2950
3570
  lines.push(` ${green("\u2713")} ${bold(name)} ${dim(counts)}`);
2951
3571
  const deprecated = entry?.transport.type === "sse" ? " \xB7 HTTP+SSE transport is deprecated in the spec" : "";
2952
3572
  lines.push(` ${dim(`${entry?.protocol.era}/${entry?.protocol.version} \xB7 from ${entry?.source.file}${deprecated}`)}`);
3573
+ const redacted = entry ? countRedacted(entry.transport) : 0;
3574
+ if (redacted > 0) lines.push(` ${yellow(redactedLine(redacted))}`);
2953
3575
  const tools = entry?.tools ?? [];
2954
3576
  const capabilities = surfaceCapabilities(tools);
2955
3577
  if (capabilities.length > 0) {
@@ -3035,8 +3657,8 @@ async function awaitCallback(expectedState) {
3035
3657
  server2.listen(0, "127.0.0.1", ready);
3036
3658
  });
3037
3659
  const { port } = server2.address();
3038
- const received = new Promise((resolve4, reject) => {
3039
- settle = resolve4;
3660
+ const received = new Promise((resolve5, reject) => {
3661
+ settle = resolve5;
3040
3662
  fail = reject;
3041
3663
  setTimeout(() => reject(new Error(`no callback within ${CALLBACK_TIMEOUT_MS / 1e3}s`)), CALLBACK_TIMEOUT_MS).unref();
3042
3664
  });
@@ -3162,7 +3784,44 @@ function describeRefusal(status, body) {
3162
3784
  };
3163
3785
  }
3164
3786
 
3787
+ // src/lib/build-token.ts
3788
+ var BUILD_TOKEN_HEADER = "nulladrift-build-token";
3789
+ var DEFAULT_AUDIENCE = "nulladrift";
3790
+ async function acquireBuildToken(options = {}) {
3791
+ const env = options.env ?? process.env;
3792
+ const explicit = env["NULLADRIFT_ID_TOKEN"];
3793
+ if (explicit) return { token: explicit, source: "environment" };
3794
+ if (env["GITHUB_ACTIONS"] !== "true") return void 0;
3795
+ const requestUrl = env["ACTIONS_ID_TOKEN_REQUEST_URL"];
3796
+ const requestToken = env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"];
3797
+ if (!requestUrl || !requestToken) {
3798
+ return { hint: "add `permissions: id-token: write` to this job so the reading can prove which build sent it" };
3799
+ }
3800
+ try {
3801
+ const url = new URL(requestUrl);
3802
+ url.searchParams.set("audience", env["NULLADRIFT_BUILD_AUDIENCE"] ?? DEFAULT_AUDIENCE);
3803
+ const response = await (options.fetch ?? fetch)(url, {
3804
+ headers: { authorization: `bearer ${requestToken}`, accept: "application/json" },
3805
+ signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
3806
+ });
3807
+ if (!response.ok) return { hint: `GitHub Actions would not mint an identity token (HTTP ${response.status})` };
3808
+ const body = await response.json();
3809
+ if (typeof body.value !== "string" || body.value.length === 0) return { hint: "GitHub Actions returned no identity token" };
3810
+ return { token: body.value, source: "github-actions" };
3811
+ } catch (error) {
3812
+ return { hint: `could not reach GitHub Actions for an identity token: ${error.message}` };
3813
+ }
3814
+ }
3815
+
3165
3816
  // src/commands/push.ts
3817
+ function describeIdentity(identity2, hint) {
3818
+ if (identity2?.trust === "trusted") return `${green("signed")} ${dim(`${identity2.repository ?? ""}${identity2.ref ? ` @ ${identity2.ref}` : ""} \xB7 a trusted build`)}`;
3819
+ if (identity2?.trust === "verified") {
3820
+ return `${yellow("signed")} ${dim(`${identity2.repository ?? ""}${identity2.ref ? ` @ ${identity2.ref}` : ""} \xB7 not a build this organization lists as trusted`)}`;
3821
+ }
3822
+ if (identity2?.rejected) return `${red("build token refused")} ${dim(identity2.rejected)}`;
3823
+ return hint ? dim(`unsigned: ${hint}`) : void 0;
3824
+ }
3166
3825
  function inferProject(projectRoot) {
3167
3826
  const fromCi = process.env["GITHUB_REPOSITORY"] ?? process.env["CI_PROJECT_PATH"] ?? process.env["BUILD_REPOSITORY_NAME"];
3168
3827
  if (fromCi) return fromCi;
@@ -3192,8 +3851,11 @@ async function runPush(options) {
3192
3851
  const result = await captureAll({
3193
3852
  projectRoot: options.projectRoot,
3194
3853
  configFiles: options.configFiles,
3195
- timeoutMs: options.timeoutMs
3854
+ timeoutMs: options.timeoutMs,
3855
+ provenance: options.provenance
3196
3856
  });
3857
+ for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
3858
+ `);
3197
3859
  if (Object.keys(result.lock.subjects).length === 0 && result.unreachable.length === 0) {
3198
3860
  const looked = result.discovery.filesRead.length > 0 ? result.discovery.filesRead.join(", ") : "no client config files exist for this project";
3199
3861
  process.stderr.write(`No MCP servers found, so there is nothing to push.
@@ -3224,11 +3886,17 @@ ${dim(`Looked in: ${looked}`)}
3224
3886
  servers,
3225
3887
  unreachable: result.unreachable.map((failure) => ({ server: failure.server, reason: failure.reason }))
3226
3888
  };
3889
+ const build = await acquireBuildToken();
3890
+ const buildToken = build && "token" in build ? build.token : void 0;
3227
3891
  let response;
3228
3892
  try {
3229
3893
  response = await fetch(`${apiUrl}/api/v1/ingest`, {
3230
3894
  method: "POST",
3231
- headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
3895
+ headers: {
3896
+ "content-type": "application/json",
3897
+ authorization: `Bearer ${token}`,
3898
+ ...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {}
3899
+ },
3232
3900
  body: JSON.stringify(body),
3233
3901
  signal: AbortSignal.timeout(options.timeoutMs)
3234
3902
  });
@@ -3247,6 +3915,8 @@ ${dim(`Looked in: ${looked}`)}
3247
3915
  const lines = [""];
3248
3916
  const mark = verdict.verdict === "clean" ? green("\u2713") : verdict.verdict === "drift" ? yellow("!") : red("\u2717");
3249
3917
  lines.push(`${mark} ${bold(verdict.verdict)} ${dim(`\xB7 ${servers.length} server(s) \xB7 reading ${verdict.readingId.slice(0, 8)}`)}`);
3918
+ const identity2 = describeIdentity(verdict.identity, build && "hint" in build ? build.hint : void 0);
3919
+ if (identity2) lines.push(` ${identity2}`);
3250
3920
  for (const change2 of verdict.changes) {
3251
3921
  lines.push(` ${change2.severity === "high" ? red("\u25CF") : change2.severity === "medium" ? yellow("\u25CF") : dim("\u25CF")} ${bold(change2.server)}${change2.member ? dim(`/${change2.member}`) : ""} ${change2.summary}`);
3252
3922
  }
@@ -3300,7 +3970,14 @@ async function runReview(options) {
3300
3970
  projectRoot: options.projectRoot,
3301
3971
  configFiles: options.configFiles,
3302
3972
  timeoutMs: options.timeoutMs,
3303
- policy: committed.policy
3973
+ policy: committed.policy,
3974
+ /*
3975
+ * What review writes is what gets committed. Without the previous lock, accepting a change
3976
+ * while a registry was unreachable would drop every artifact pin in the file -- and the next
3977
+ * run would re-pin whatever had been published since, with nothing to compare it against.
3978
+ */
3979
+ previous: committed,
3980
+ provenance: options.provenance
3304
3981
  });
3305
3982
  const changes = diffLockfiles(committed, result.lock);
3306
3983
  if (changes.length === 0) {
@@ -3385,8 +4062,9 @@ ${bold("Options")}
3385
4062
  --lock <path> lockfile to read or write (default: ./${DEFAULT_LOCK_FILENAME})
3386
4063
  --cwd <path> project root to scan for client configs (default: current directory)
3387
4064
  --config <path> audit this config file too; repeatable
3388
- --timeout <ms> per-server timeout (default: ${DEFAULT_TIMEOUT_MS})
4065
+ --timeout <ms> per-server timeout (default: ${DEFAULT_TIMEOUT_MS2})
3389
4066
  --allow-unreachable a server that cannot be reached warns instead of failing
4067
+ --no-provenance do not look up what each stdio server runs (air-gapped runs)
3390
4068
  --json machine-readable output (check)
3391
4069
  --sarif SARIF 2.1.0 output (check)
3392
4070
  --sarif-steering also emit steering passages as SARIF notes (off: an alert is a gate)
@@ -3416,6 +4094,7 @@ async function main() {
3416
4094
  config: { type: "string", multiple: true },
3417
4095
  timeout: { type: "string" },
3418
4096
  "allow-unreachable": { type: "boolean", default: false },
4097
+ "no-provenance": { type: "boolean", default: false },
3419
4098
  json: { type: "boolean", default: false },
3420
4099
  sarif: { type: "boolean", default: false },
3421
4100
  "sarif-steering": { type: "boolean", default: false },
@@ -3446,22 +4125,23 @@ async function main() {
3446
4125
  `);
3447
4126
  return EXIT_INCOMPLETE;
3448
4127
  }
3449
- const timeoutMs = values.timeout === void 0 ? DEFAULT_TIMEOUT_MS : Number.parseInt(values.timeout, 10);
4128
+ const timeoutMs = values.timeout === void 0 ? DEFAULT_TIMEOUT_MS2 : Number.parseInt(values.timeout, 10);
3450
4129
  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
3451
4130
  process.stderr.write(`${red(`--timeout must be a positive number of milliseconds, got "${values.timeout}".`)}
3452
4131
  `);
3453
4132
  return EXIT_INCOMPLETE;
3454
4133
  }
3455
- const projectRoot = resolve3(values.cwd ?? process.cwd());
4134
+ const projectRoot = resolve4(values.cwd ?? process.cwd());
3456
4135
  const options = {
3457
4136
  projectRoot,
3458
- lockPath: resolve3(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
4137
+ lockPath: resolve4(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
3459
4138
  configFiles: values.config ?? [],
3460
4139
  timeoutMs,
3461
4140
  allowUnreachable: values["allow-unreachable"],
3462
4141
  format: values.sarif ? "sarif" : values.json ? "json" : "human",
3463
4142
  sarifSteering: values["sarif-steering"] === true,
3464
- comment: values.comment
4143
+ comment: values.comment,
4144
+ provenance: values["no-provenance"] !== true
3465
4145
  };
3466
4146
  switch (command) {
3467
4147
  case "init":