nulladrift 0.6.1 → 0.6.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/README.md +23 -7
- package/dist/index.js +675 -167
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
5
|
+
import { resolve as resolve5 } from "path";
|
|
6
6
|
|
|
7
7
|
// ../core/src/changes.ts
|
|
8
8
|
var CHANGE_KINDS = [
|
|
@@ -139,7 +139,7 @@ function toJson(value, depth = 0) {
|
|
|
139
139
|
if (value === null) return null;
|
|
140
140
|
if (Array.isArray(value)) return value.map((member) => toJson(member, depth + 1));
|
|
141
141
|
if (typeof value === "object") {
|
|
142
|
-
const out =
|
|
142
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
143
143
|
for (const [key, member] of Object.entries(value)) {
|
|
144
144
|
if (member === void 0) continue;
|
|
145
145
|
out[key] = toJson(member, depth + 1);
|
|
@@ -192,7 +192,76 @@ function resealMcpServer(entry) {
|
|
|
192
192
|
|
|
193
193
|
// ../core/src/lock/credentials.ts
|
|
194
194
|
var REDACTED = "REDACTED";
|
|
195
|
-
var
|
|
195
|
+
var CREDENTIAL_WORDS = /* @__PURE__ */ new Set([
|
|
196
|
+
"key",
|
|
197
|
+
"apikey",
|
|
198
|
+
"token",
|
|
199
|
+
"secret",
|
|
200
|
+
"password",
|
|
201
|
+
"passwd",
|
|
202
|
+
"pwd",
|
|
203
|
+
"pass",
|
|
204
|
+
"pat",
|
|
205
|
+
"auth",
|
|
206
|
+
"bearer",
|
|
207
|
+
"credential",
|
|
208
|
+
"credentials",
|
|
209
|
+
"privatekey",
|
|
210
|
+
"accesskey",
|
|
211
|
+
"clientsecret",
|
|
212
|
+
"sig",
|
|
213
|
+
"signature",
|
|
214
|
+
"jwt",
|
|
215
|
+
"cookie"
|
|
216
|
+
]);
|
|
217
|
+
var DESCRIBES_IT = /* @__PURE__ */ new Set([
|
|
218
|
+
"file",
|
|
219
|
+
"path",
|
|
220
|
+
"dir",
|
|
221
|
+
"directory",
|
|
222
|
+
"url",
|
|
223
|
+
"uri",
|
|
224
|
+
"endpoint",
|
|
225
|
+
"host",
|
|
226
|
+
"type",
|
|
227
|
+
"mode",
|
|
228
|
+
"method",
|
|
229
|
+
"header",
|
|
230
|
+
"name",
|
|
231
|
+
"id",
|
|
232
|
+
"env",
|
|
233
|
+
"var",
|
|
234
|
+
"length",
|
|
235
|
+
"limit",
|
|
236
|
+
"count",
|
|
237
|
+
"max",
|
|
238
|
+
"min",
|
|
239
|
+
"size",
|
|
240
|
+
"timeout",
|
|
241
|
+
"ttl",
|
|
242
|
+
"format",
|
|
243
|
+
"prefix",
|
|
244
|
+
"location",
|
|
245
|
+
"store",
|
|
246
|
+
"provider",
|
|
247
|
+
"region",
|
|
248
|
+
"scope",
|
|
249
|
+
"scopes",
|
|
250
|
+
"version",
|
|
251
|
+
"algorithm",
|
|
252
|
+
"kind",
|
|
253
|
+
"expiry"
|
|
254
|
+
]);
|
|
255
|
+
function nameWords(name) {
|
|
256
|
+
return name.replace(/^-+/, "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
257
|
+
}
|
|
258
|
+
function isCredentialName(name) {
|
|
259
|
+
const words = nameWords(name);
|
|
260
|
+
const last = words[words.length - 1];
|
|
261
|
+
if (last === void 0 || DESCRIBES_IT.has(last) || words[0] === "no") return false;
|
|
262
|
+
return words.some((word) => CREDENTIAL_WORDS.has(word));
|
|
263
|
+
}
|
|
264
|
+
var CREDENTIAL_HEADERS = /* @__PURE__ */ new Set(["authorization", "proxy-authorization", "cookie", "set-cookie"]);
|
|
196
265
|
var ISSUER_FORMATS = [
|
|
197
266
|
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
198
267
|
// AWS access key id
|
|
@@ -249,7 +318,7 @@ function redactUrl(value) {
|
|
|
249
318
|
try {
|
|
250
319
|
url = new URL(value);
|
|
251
320
|
} catch {
|
|
252
|
-
return value;
|
|
321
|
+
return redactPairs(value);
|
|
253
322
|
}
|
|
254
323
|
let changed = false;
|
|
255
324
|
if (url.password && !PLACEHOLDER.test(decoded(url.password))) {
|
|
@@ -257,13 +326,77 @@ function redactUrl(value) {
|
|
|
257
326
|
changed = true;
|
|
258
327
|
}
|
|
259
328
|
for (const [key, parameter] of [...url.searchParams]) {
|
|
260
|
-
if (
|
|
329
|
+
if (isCredentialName(key) && isSecretValue(parameter)) {
|
|
261
330
|
url.searchParams.set(key, REDACTED);
|
|
262
331
|
changed = true;
|
|
263
332
|
}
|
|
264
333
|
}
|
|
334
|
+
const path = redactPath(url.pathname);
|
|
335
|
+
if (path !== url.pathname) {
|
|
336
|
+
url.pathname = path;
|
|
337
|
+
changed = true;
|
|
338
|
+
}
|
|
339
|
+
const hash = url.hash ? redactPairs(url.hash) : url.hash;
|
|
340
|
+
if (hash !== url.hash) {
|
|
341
|
+
url.hash = hash;
|
|
342
|
+
changed = true;
|
|
343
|
+
}
|
|
265
344
|
return changed ? url.toString() : value;
|
|
266
345
|
}
|
|
346
|
+
function redactPairs(text) {
|
|
347
|
+
return text.replace(
|
|
348
|
+
/(^|[?&;#\s,])([A-Za-z_][A-Za-z0-9_.-]*)=([^&;#\s,]*)/g,
|
|
349
|
+
(whole, lead, name, value) => isCredentialName(name) && isSecretValue(value) ? `${lead}${name}=${REDACTED}` : whole
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
function redactHeader(text) {
|
|
353
|
+
const header = /^([A-Za-z][A-Za-z0-9-]*)\s*:\s*(\S.*)$/s.exec(text);
|
|
354
|
+
if (!header) return void 0;
|
|
355
|
+
const [, name = "", value = ""] = header;
|
|
356
|
+
if (!(CREDENTIAL_HEADERS.has(name.toLowerCase()) || isCredentialName(name)) || PLACEHOLDER.test(value)) return void 0;
|
|
357
|
+
return `${name}: ${REDACTED}`;
|
|
358
|
+
}
|
|
359
|
+
function redactJson(text) {
|
|
360
|
+
if (!/^\s*[[{]/.test(text)) return void 0;
|
|
361
|
+
let parsed;
|
|
362
|
+
try {
|
|
363
|
+
parsed = JSON.parse(text);
|
|
364
|
+
} catch {
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
let changed = false;
|
|
368
|
+
const walk = (node) => {
|
|
369
|
+
if (Array.isArray(node)) return node.map(walk);
|
|
370
|
+
if (node !== null && typeof node === "object") {
|
|
371
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
372
|
+
for (const [key, child] of Object.entries(node)) {
|
|
373
|
+
if (typeof child === "string" && isCredentialName(key) && isSecretValue(child)) {
|
|
374
|
+
out[key] = REDACTED;
|
|
375
|
+
changed = true;
|
|
376
|
+
} else if (typeof child === "string") {
|
|
377
|
+
const next = redactText(child);
|
|
378
|
+
if (next !== child) changed = true;
|
|
379
|
+
out[key] = next;
|
|
380
|
+
} else {
|
|
381
|
+
out[key] = walk(child);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return out;
|
|
385
|
+
}
|
|
386
|
+
return node;
|
|
387
|
+
};
|
|
388
|
+
const result = walk(parsed);
|
|
389
|
+
return changed ? JSON.stringify(result) : void 0;
|
|
390
|
+
}
|
|
391
|
+
function redactText(text) {
|
|
392
|
+
if (PLACEHOLDER.test(text) && !/[?&;#]/.test(text)) return text;
|
|
393
|
+
if (looksRandom(text)) return REDACTED;
|
|
394
|
+
const json = redactJson(text);
|
|
395
|
+
if (json !== void 0) return json;
|
|
396
|
+
const header = redactHeader(text);
|
|
397
|
+
if (header !== void 0) return header;
|
|
398
|
+
return redactFormats(redactPairs(redactUrl(text)));
|
|
399
|
+
}
|
|
267
400
|
function redactArgs(args) {
|
|
268
401
|
const out = [...args];
|
|
269
402
|
for (let index = 0; index < out.length; index += 1) {
|
|
@@ -271,33 +404,40 @@ function redactArgs(args) {
|
|
|
271
404
|
const assignment = /^(-{0,2}[A-Za-z][A-Za-z0-9_.-]*)=(.*)$/s.exec(argument);
|
|
272
405
|
if (assignment) {
|
|
273
406
|
const [, name = "", value = ""] = assignment;
|
|
274
|
-
if (
|
|
407
|
+
if (isCredentialName(name) && isSecretValue(value)) {
|
|
275
408
|
out[index] = `${name}=${REDACTED}`;
|
|
276
409
|
continue;
|
|
277
410
|
}
|
|
278
|
-
if (!PLACEHOLDER.test(value)) out[index] = `${name}=${
|
|
411
|
+
if (!PLACEHOLDER.test(value) || /[?&;#]/.test(value)) out[index] = `${name}=${redactText(value)}`;
|
|
279
412
|
continue;
|
|
280
413
|
}
|
|
281
414
|
const flag = /^-{1,2}([A-Za-z][A-Za-z0-9_.-]*)$/.exec(argument);
|
|
282
415
|
const next = out[index + 1];
|
|
283
|
-
if (flag && next !== void 0 && !next.startsWith("-")
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
416
|
+
if (flag && next !== void 0 && !next.startsWith("-")) {
|
|
417
|
+
const name = flag[1] ?? "";
|
|
418
|
+
if (isCredentialName(name) && isSecretValue(next) && !looksLikeAnOperand(next)) {
|
|
419
|
+
out[index + 1] = REDACTED;
|
|
420
|
+
index += 1;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
if (["u", "user", "basic-auth"].includes(name.toLowerCase()) && /^[^:\s]+:[^\s]+$/.test(next) && !PLACEHOLDER.test(next)) {
|
|
424
|
+
out[index + 1] = `${next.slice(0, next.indexOf(":"))}:${REDACTED}`;
|
|
425
|
+
index += 1;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
292
428
|
}
|
|
293
|
-
out[index] =
|
|
429
|
+
out[index] = redactText(argument);
|
|
294
430
|
}
|
|
295
431
|
return out;
|
|
296
432
|
}
|
|
433
|
+
function looksLikeAnOperand(value) {
|
|
434
|
+
return value.startsWith("@") || value.includes("/") || /\.(m?[jt]s|cjs|py|json|ya?ml|toml|sh|exe)$/i.test(value);
|
|
435
|
+
}
|
|
297
436
|
function redactPath(pathname) {
|
|
298
437
|
return pathname.split("/").map((segment) => {
|
|
299
438
|
if (segment === "" || PLACEHOLDER.test(decoded(segment))) return segment;
|
|
300
439
|
if (looksRandom(segment)) return REDACTED;
|
|
440
|
+
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(segment) || /^[0-9a-f]{32,}$/i.test(segment)) return REDACTED;
|
|
301
441
|
return redactFormats(segment);
|
|
302
442
|
}).join("/");
|
|
303
443
|
}
|
|
@@ -337,20 +477,20 @@ function effectiveSchema(node, root, seenRefs = /* @__PURE__ */ new Set(), depth
|
|
|
337
477
|
const object = asObject(node);
|
|
338
478
|
if (object === void 0) return void 0;
|
|
339
479
|
if (depth > MAX_REF_DEPTH) return object;
|
|
340
|
-
const out =
|
|
480
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
341
481
|
const merge = (source) => {
|
|
342
482
|
for (const [key, value] of Object.entries(source)) {
|
|
343
483
|
if (key === "$ref" || key === "allOf") continue;
|
|
344
484
|
if (key === "properties") {
|
|
345
|
-
const merged =
|
|
485
|
+
const merged = Object.assign(/* @__PURE__ */ Object.create(null), asObject(out["properties"]) ?? {});
|
|
346
486
|
for (const [name, schema] of Object.entries(asObject(value) ?? {})) {
|
|
347
|
-
if (!(name
|
|
487
|
+
if (!Object.hasOwn(merged, name)) Object.defineProperty(merged, name, { value: schema, enumerable: true, writable: true, configurable: true });
|
|
348
488
|
}
|
|
349
489
|
out["properties"] = merged;
|
|
350
490
|
} else if (key === "required" && Array.isArray(value)) {
|
|
351
491
|
const already = Array.isArray(out["required"]) ? out["required"] : [];
|
|
352
492
|
out["required"] = [...new Set([...already, ...value].filter((entry) => typeof entry === "string"))];
|
|
353
|
-
} else if (!(key
|
|
493
|
+
} else if (!Object.hasOwn(out, key)) {
|
|
354
494
|
out[key] = value;
|
|
355
495
|
}
|
|
356
496
|
}
|
|
@@ -399,7 +539,7 @@ function isEscalation(previous, next) {
|
|
|
399
539
|
function normalizeSchema(value) {
|
|
400
540
|
if (Array.isArray(value)) return value.map(normalizeSchema);
|
|
401
541
|
if (value === null || typeof value !== "object") return value;
|
|
402
|
-
const out =
|
|
542
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
403
543
|
for (const [key, member] of Object.entries(value)) {
|
|
404
544
|
if (key === "required" && Array.isArray(member) && member.every((entry) => typeof entry === "string")) {
|
|
405
545
|
out[key] = [...member].sort();
|
|
@@ -411,8 +551,11 @@ function normalizeSchema(value) {
|
|
|
411
551
|
}
|
|
412
552
|
function extractHeaderParams(schema) {
|
|
413
553
|
const found = [];
|
|
414
|
-
|
|
554
|
+
let budget = MAX_HEADER_VISITS;
|
|
555
|
+
const walk = (node, path, depth, refsOnPath) => {
|
|
415
556
|
if (depth > MAX_VISIT_DEPTH) return;
|
|
557
|
+
if (budget <= 0) return;
|
|
558
|
+
budget -= 1;
|
|
416
559
|
const object = effectiveSchema(node, schema);
|
|
417
560
|
if (!object) return;
|
|
418
561
|
const properties = asObject(object["properties"]);
|
|
@@ -422,17 +565,26 @@ function extractHeaderParams(schema) {
|
|
|
422
565
|
if (!resolved) continue;
|
|
423
566
|
const header = resolved["x-mcp-header"];
|
|
424
567
|
if (typeof header === "string" && header.length > 0) found.push(`${[...path, name].join(".")} -> ${header}`);
|
|
425
|
-
|
|
568
|
+
const ref = asObject(child)?.["$ref"];
|
|
569
|
+
if (typeof ref === "string" && refsOnPath.has(ref)) continue;
|
|
570
|
+
walk(child, [...path, name], depth + 1, typeof ref === "string" ? /* @__PURE__ */ new Set([...refsOnPath, ref]) : refsOnPath);
|
|
426
571
|
}
|
|
427
572
|
}
|
|
428
|
-
for (const branch of alternatives(object))
|
|
573
|
+
for (const branch of alternatives(object)) {
|
|
574
|
+
const ref = asObject(branch.schema)?.["$ref"];
|
|
575
|
+
if (typeof ref === "string" && refsOnPath.has(ref)) continue;
|
|
576
|
+
walk(branch.schema, path, depth + 1, typeof ref === "string" ? /* @__PURE__ */ new Set([...refsOnPath, ref]) : refsOnPath);
|
|
577
|
+
}
|
|
429
578
|
};
|
|
430
|
-
|
|
579
|
+
const rootRef = asObject(schema)?.["$ref"];
|
|
580
|
+
walk(schema, [], 0, new Set(typeof rootRef === "string" ? [rootRef] : []));
|
|
581
|
+
if (budget <= 0) found.push(`(schema too large to scan for headers past ${MAX_HEADER_VISITS} nodes)`);
|
|
431
582
|
return [...new Set(found)].sort();
|
|
432
583
|
}
|
|
584
|
+
var MAX_HEADER_VISITS = 2e4;
|
|
433
585
|
function stripIgnoredMeta(meta, ignoredPrefixes) {
|
|
434
586
|
if (meta === null || meta === void 0 || typeof meta !== "object" || Array.isArray(meta)) return void 0;
|
|
435
|
-
const out =
|
|
587
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
436
588
|
for (const [key, value] of Object.entries(meta)) {
|
|
437
589
|
if (ignoredPrefixes.some((prefix) => key.startsWith(prefix))) continue;
|
|
438
590
|
out[key] = value;
|
|
@@ -440,6 +592,7 @@ function stripIgnoredMeta(meta, ignoredPrefixes) {
|
|
|
440
592
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
441
593
|
}
|
|
442
594
|
function sanitizeUrl(raw) {
|
|
595
|
+
if (raw.includes("${")) return sanitizeText(raw);
|
|
443
596
|
try {
|
|
444
597
|
const url = new URL(raw);
|
|
445
598
|
url.search = "";
|
|
@@ -449,9 +602,15 @@ function sanitizeUrl(raw) {
|
|
|
449
602
|
url.pathname = redactPath(url.pathname);
|
|
450
603
|
return url.toString();
|
|
451
604
|
} catch {
|
|
452
|
-
return raw;
|
|
605
|
+
return sanitizeText(raw);
|
|
453
606
|
}
|
|
454
607
|
}
|
|
608
|
+
function sanitizeText(raw) {
|
|
609
|
+
const withoutUser = raw.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/@]*@/i, "$1");
|
|
610
|
+
const base = withoutUser.split(/[?#]/)[0] ?? withoutUser;
|
|
611
|
+
const parts = /^([a-z][a-z0-9+.-]*:\/\/[^/]*)(\/.*)?$/i.exec(base);
|
|
612
|
+
return parts ? `${parts[1]}${parts[2] ? redactPath(parts[2]) : ""}` : base;
|
|
613
|
+
}
|
|
455
614
|
|
|
456
615
|
// ../core/src/risk/untrusted.ts
|
|
457
616
|
function objectsIn(value) {
|
|
@@ -1144,7 +1303,7 @@ function newSteering(committed, observed) {
|
|
|
1144
1303
|
|
|
1145
1304
|
// src/lib/ui.ts
|
|
1146
1305
|
var enabled = process.stdout.isTTY === true && process.env["NO_COLOR"] === void 0 && process.env["TERM"] !== "dumb";
|
|
1147
|
-
var wrap = (
|
|
1306
|
+
var wrap = (code2) => (text) => enabled ? `\x1B[${code2}m${text}\x1B[0m` : text;
|
|
1148
1307
|
var bold = wrap(1);
|
|
1149
1308
|
var dim = wrap(2);
|
|
1150
1309
|
var red = wrap(31);
|
|
@@ -1164,7 +1323,8 @@ function truncate(text, limit = 160) {
|
|
|
1164
1323
|
const collapsed = visibleControls(text).replace(/\s+/g, " ").trim();
|
|
1165
1324
|
return collapsed.length <= limit ? collapsed : `${collapsed.slice(0, limit - 1)}\u2026`;
|
|
1166
1325
|
}
|
|
1167
|
-
function elideMiddle(
|
|
1326
|
+
function elideMiddle(raw, limit) {
|
|
1327
|
+
const path = visibleControls(raw);
|
|
1168
1328
|
if (path.length <= limit) return path;
|
|
1169
1329
|
const keep = Math.floor((limit - 1) / 2);
|
|
1170
1330
|
return `${path.slice(0, keep)}\u2026${path.slice(-keep)}`;
|
|
@@ -1183,9 +1343,29 @@ import { z } from "zod";
|
|
|
1183
1343
|
// src/config/expand.ts
|
|
1184
1344
|
import { homedir } from "os";
|
|
1185
1345
|
var PLACEHOLDER2 = /\$\{([^}]+)\}/g;
|
|
1346
|
+
var RUN_CREDENTIALS = /* @__PURE__ */ new Set([
|
|
1347
|
+
"CI_JOB_TOKEN",
|
|
1348
|
+
"CI_REGISTRY_PASSWORD",
|
|
1349
|
+
"CI_DEPLOY_PASSWORD",
|
|
1350
|
+
"CI_DEPENDENCY_PROXY_PASSWORD",
|
|
1351
|
+
"CI_REPOSITORY_URL",
|
|
1352
|
+
"BUILDKITE_AGENT_ACCESS_TOKEN",
|
|
1353
|
+
"BITBUCKET_STEP_OIDC_TOKEN",
|
|
1354
|
+
"SYSTEM_ACCESSTOKEN"
|
|
1355
|
+
]);
|
|
1356
|
+
function isRunCredential(name) {
|
|
1357
|
+
const upper = name.toUpperCase();
|
|
1358
|
+
return RUN_CREDENTIALS.has(upper) || upper.startsWith("NULLADRIFT_") || upper.startsWith("ACTIONS_") || upper.startsWith("CI_JOB_JWT") || upper.startsWith("CIRCLE_OIDC_TOKEN");
|
|
1359
|
+
}
|
|
1186
1360
|
function expand(input, context) {
|
|
1187
1361
|
const unresolved = [];
|
|
1362
|
+
const refused = [];
|
|
1188
1363
|
const value = input.replace(PLACEHOLDER2, (match, body) => {
|
|
1364
|
+
const named = body.startsWith("env:") ? body.slice(4) : body.includes(":-") ? body.slice(0, body.indexOf(":-")) : body;
|
|
1365
|
+
if (isRunCredential(named)) {
|
|
1366
|
+
refused.push(match);
|
|
1367
|
+
return match;
|
|
1368
|
+
}
|
|
1189
1369
|
if (body === "workspaceFolder") return context.workspaceFolder;
|
|
1190
1370
|
if (body === "userHome") return homedir();
|
|
1191
1371
|
if (body === "pathSeparator" || body === "/") return "/";
|
|
@@ -1210,7 +1390,7 @@ function expand(input, context) {
|
|
|
1210
1390
|
unresolved.push(match);
|
|
1211
1391
|
return match;
|
|
1212
1392
|
});
|
|
1213
|
-
return { value, unresolved };
|
|
1393
|
+
return { value, unresolved, refused };
|
|
1214
1394
|
}
|
|
1215
1395
|
|
|
1216
1396
|
// src/config/parsers.ts
|
|
@@ -1227,6 +1407,7 @@ var serverEntrySchema = z.looseObject({
|
|
|
1227
1407
|
oauth: z.looseObject({
|
|
1228
1408
|
clientId: z.string().optional(),
|
|
1229
1409
|
clientSecret: z.string().optional(),
|
|
1410
|
+
issuer: z.string().optional(),
|
|
1230
1411
|
scope: z.string().optional(),
|
|
1231
1412
|
scopes: z.array(z.string()).optional()
|
|
1232
1413
|
}).optional()
|
|
@@ -1247,11 +1428,20 @@ function scalarsToStrings(record) {
|
|
|
1247
1428
|
}
|
|
1248
1429
|
return out;
|
|
1249
1430
|
}
|
|
1431
|
+
function refusedCredentials(name, refused) {
|
|
1432
|
+
const names = [...new Set(refused)];
|
|
1433
|
+
return new UnsupportedServerError(
|
|
1434
|
+
name,
|
|
1435
|
+
`configuration uses ${names.join(", ")}, which ${names.length === 1 ? "holds" : "hold"} this run's own credentials (the CI job's token or identity, or Nulladrift's). They are never given to a server under audit. Give the server a credential of its own.`
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1250
1438
|
function resolveTransport(name, entry, context) {
|
|
1251
1439
|
const unresolved = [];
|
|
1440
|
+
const refused = [];
|
|
1252
1441
|
const take = (input) => {
|
|
1253
1442
|
const result = expand(input, context);
|
|
1254
1443
|
unresolved.push(...result.unresolved);
|
|
1444
|
+
refused.push(...result.refused);
|
|
1255
1445
|
return result.value;
|
|
1256
1446
|
};
|
|
1257
1447
|
const declared = entry.type === "streamable-http" ? "http" : entry.type;
|
|
@@ -1272,6 +1462,7 @@ function resolveTransport(name, entry, context) {
|
|
|
1272
1462
|
// Expanded here so a secret can live in the environment rather than the config file.
|
|
1273
1463
|
clientId: oauth.clientId === void 0 ? void 0 : take(oauth.clientId),
|
|
1274
1464
|
clientSecret: oauth.clientSecret === void 0 ? void 0 : take(oauth.clientSecret),
|
|
1465
|
+
issuer: oauth.issuer === void 0 ? void 0 : take(oauth.issuer),
|
|
1275
1466
|
scope: oauth.scope ?? oauth.scopes?.join(" ")
|
|
1276
1467
|
}
|
|
1277
1468
|
}
|
|
@@ -1291,6 +1482,13 @@ function resolveTransport(name, entry, context) {
|
|
|
1291
1482
|
cwd: entry.cwd ? take(entry.cwd) : void 0
|
|
1292
1483
|
};
|
|
1293
1484
|
}
|
|
1485
|
+
if (transport2.type !== "stdio" && transport2.oauth?.clientSecret !== void 0 && !transport2.oauth.issuer) {
|
|
1486
|
+
throw new UnsupportedServerError(
|
|
1487
|
+
name,
|
|
1488
|
+
"oauth.clientSecret is set without oauth.issuer. Set oauth.issuer to the authorization server's issuer URL, so the secret can only be sent there and not to an authorization server the MCP server chooses."
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
if (refused.length > 0) throw refusedCredentials(name, refused);
|
|
1294
1492
|
if (unresolved.length > 0) {
|
|
1295
1493
|
const names = [...new Set(unresolved)].join(", ");
|
|
1296
1494
|
throw new UnsupportedServerError(
|
|
@@ -1310,17 +1508,27 @@ function detectMapKey(raw) {
|
|
|
1310
1508
|
}
|
|
1311
1509
|
async function readEnvFile(path) {
|
|
1312
1510
|
const out = {};
|
|
1313
|
-
const
|
|
1314
|
-
for (
|
|
1315
|
-
const trimmed =
|
|
1511
|
+
const lines = (await readFile(path, "utf8")).split(/\r?\n/);
|
|
1512
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
1513
|
+
const trimmed = (lines[index] ?? "").trim();
|
|
1316
1514
|
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
1317
|
-
const
|
|
1515
|
+
const body = trimmed.replace(/^export\s+/, "");
|
|
1516
|
+
const at = body.indexOf("=");
|
|
1318
1517
|
if (at <= 0) continue;
|
|
1319
|
-
const key =
|
|
1320
|
-
let value =
|
|
1321
|
-
|
|
1322
|
-
|
|
1518
|
+
const key = body.slice(0, at).trim();
|
|
1519
|
+
let value = body.slice(at + 1).trim();
|
|
1520
|
+
const quote = value[0];
|
|
1521
|
+
if (quote === '"' || quote === "'") {
|
|
1522
|
+
let rest = value.slice(1);
|
|
1523
|
+
const closed = (text) => text.endsWith(quote) && !text.endsWith(`\\${quote}`);
|
|
1524
|
+
while (!closed(rest) && index + 1 < lines.length) {
|
|
1525
|
+
index += 1;
|
|
1526
|
+
rest += `
|
|
1527
|
+
${lines[index] ?? ""}`;
|
|
1528
|
+
}
|
|
1529
|
+
value = closed(rest) ? rest.slice(0, -1) : rest;
|
|
1323
1530
|
}
|
|
1531
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
|
|
1324
1532
|
out[key] = value;
|
|
1325
1533
|
}
|
|
1326
1534
|
return out;
|
|
@@ -1332,6 +1540,10 @@ async function parseServerMap(raw, mapKey, source, context) {
|
|
|
1332
1540
|
const map = raw[mapKey];
|
|
1333
1541
|
if (typeof map !== "object" || map === null) return { servers, skipped };
|
|
1334
1542
|
for (const [name, value] of Object.entries(map)) {
|
|
1543
|
+
if (name === "__proto__") {
|
|
1544
|
+
skipped.push(new UnsupportedServerError(name, "a server cannot be named __proto__; rename it"));
|
|
1545
|
+
continue;
|
|
1546
|
+
}
|
|
1335
1547
|
const entry = serverEntrySchema.safeParse(value);
|
|
1336
1548
|
if (!entry.success) {
|
|
1337
1549
|
skipped.push(new UnsupportedServerError(name, `entry is not a server definition: ${entry.error.issues[0]?.message ?? "unknown"}`));
|
|
@@ -1344,6 +1556,7 @@ async function parseServerMap(raw, mapKey, source, context) {
|
|
|
1344
1556
|
const transport2 = resolveTransport(name, entry.data, context);
|
|
1345
1557
|
if (transport2.type === "stdio" && entry.data.envFile !== void 0) {
|
|
1346
1558
|
const expanded = expand(entry.data.envFile, context);
|
|
1559
|
+
if (expanded.refused.length > 0) throw refusedCredentials(name, expanded.refused);
|
|
1347
1560
|
if (expanded.unresolved.length > 0) {
|
|
1348
1561
|
throw new UnsupportedServerError(name, `envFile path contains unresolved placeholders: ${expanded.unresolved.join(", ")}`);
|
|
1349
1562
|
}
|
|
@@ -1417,9 +1630,9 @@ async function readJsonIfPresent(path) {
|
|
|
1417
1630
|
try {
|
|
1418
1631
|
text = await readFile2(path, "utf8");
|
|
1419
1632
|
} catch (error) {
|
|
1420
|
-
const
|
|
1421
|
-
if (
|
|
1422
|
-
if (
|
|
1633
|
+
const code2 = error.code;
|
|
1634
|
+
if (code2 === "ENOENT" || code2 === "ENOTDIR") return { present: false };
|
|
1635
|
+
if (code2 === "EACCES") return { present: true, ok: false, reason: "permission denied" };
|
|
1423
1636
|
throw error;
|
|
1424
1637
|
}
|
|
1425
1638
|
try {
|
|
@@ -1430,7 +1643,9 @@ async function readJsonIfPresent(path) {
|
|
|
1430
1643
|
}
|
|
1431
1644
|
function anchorCwd(server2, projectRoot) {
|
|
1432
1645
|
const { transport: transport2 } = server2;
|
|
1433
|
-
if (transport2.type !== "stdio"
|
|
1646
|
+
if (transport2.type !== "stdio") return server2;
|
|
1647
|
+
if (transport2.cwd === void 0) return { ...server2, transport: { ...transport2, cwd: projectRoot } };
|
|
1648
|
+
if (isAbsolute(transport2.cwd)) return server2;
|
|
1434
1649
|
return { ...server2, transport: { ...transport2, cwd: resolve2(projectRoot, transport2.cwd) } };
|
|
1435
1650
|
}
|
|
1436
1651
|
function describeSearch(searched, filesRead) {
|
|
@@ -1438,11 +1653,13 @@ function describeSearch(searched, filesRead) {
|
|
|
1438
1653
|
const lines = searched.map((path) => ` ${(read.has(path) ? "read" : "absent").padEnd(6)} ${path}`);
|
|
1439
1654
|
return lines.join("\n");
|
|
1440
1655
|
}
|
|
1441
|
-
async function discoverServers(projectRoot, extraFiles = []) {
|
|
1656
|
+
async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
1442
1657
|
const context = { workspaceFolder: projectRoot, env: process.env };
|
|
1658
|
+
const candidates = candidateConfigFiles(projectRoot);
|
|
1659
|
+
const userFiles = candidates.filter((file) => file.scope === "user");
|
|
1443
1660
|
const files = [
|
|
1444
1661
|
...extraFiles.map((path) => ({ client: "generic", path: resolve2(projectRoot, path) })),
|
|
1445
|
-
...
|
|
1662
|
+
...candidates.filter((file) => options.userConfigs === true || file.scope !== "user")
|
|
1446
1663
|
];
|
|
1447
1664
|
const byName2 = /* @__PURE__ */ new Map();
|
|
1448
1665
|
const skipped = [];
|
|
@@ -1489,6 +1706,9 @@ async function discoverServers(projectRoot, extraFiles = []) {
|
|
|
1489
1706
|
skipped,
|
|
1490
1707
|
filesRead,
|
|
1491
1708
|
searched: files.map((file) => file.path),
|
|
1709
|
+
userConfigsSkipped: options.userConfigs === true ? [] : (await Promise.all(userFiles.map(async (file) => (await readJsonIfPresent(file.path)).present ? portablePath(file.path, projectRoot) : void 0))).filter(
|
|
1710
|
+
(path) => path !== void 0
|
|
1711
|
+
),
|
|
1492
1712
|
shadowed,
|
|
1493
1713
|
problems
|
|
1494
1714
|
};
|
|
@@ -1626,7 +1846,7 @@ import { readFile as readFile3 } from "fs/promises";
|
|
|
1626
1846
|
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
1627
1847
|
|
|
1628
1848
|
// src/lib/version.ts
|
|
1629
|
-
var VERSION = "0.6.
|
|
1849
|
+
var VERSION = "0.6.2";
|
|
1630
1850
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
1631
1851
|
|
|
1632
1852
|
// src/lock/provenance.ts
|
|
@@ -1686,6 +1906,7 @@ var UV_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
1686
1906
|
"-p",
|
|
1687
1907
|
"--index",
|
|
1688
1908
|
"--index-url",
|
|
1909
|
+
"-i",
|
|
1689
1910
|
"--extra-index-url",
|
|
1690
1911
|
"--default-index",
|
|
1691
1912
|
"--find-links",
|
|
@@ -1906,6 +2127,15 @@ function isExact(reference) {
|
|
|
1906
2127
|
return false;
|
|
1907
2128
|
}
|
|
1908
2129
|
}
|
|
2130
|
+
var NPM_PUBLIC = "https://registry.npmjs.org";
|
|
2131
|
+
function npmEnv(env, name) {
|
|
2132
|
+
const wanted = name.toLowerCase();
|
|
2133
|
+
for (const [key, value] of Object.entries(env)) if (key.toLowerCase() === wanted && value) return value;
|
|
2134
|
+
return void 0;
|
|
2135
|
+
}
|
|
2136
|
+
function resolverNpmRegistry(env = process.env) {
|
|
2137
|
+
return (npmEnv(env, "npm_config_registry") ?? NPM_PUBLIC).replace(/\/+$/, "");
|
|
2138
|
+
}
|
|
1909
2139
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
1910
2140
|
async function getJson(url, options) {
|
|
1911
2141
|
const response = await (options.fetch ?? fetch)(url, {
|
|
@@ -1919,7 +2149,7 @@ async function getJson(url, options) {
|
|
|
1919
2149
|
async function resolveNpm(reference, options) {
|
|
1920
2150
|
const asked = reference.requested ?? "latest";
|
|
1921
2151
|
if (!NPM_EXACT.test(asked) && !NPM_TAG.test(asked)) return void 0;
|
|
1922
|
-
const registry = (
|
|
2152
|
+
const registry = resolverNpmRegistry();
|
|
1923
2153
|
const body = await getJson(`${registry}/${reference.name.replace("/", "%2F")}/${encodeURIComponent(asked)}`, options);
|
|
1924
2154
|
if (typeof body?.version !== "string") return void 0;
|
|
1925
2155
|
const integrity = typeof body.dist?.integrity === "string" ? body.dist.integrity : typeof body.dist?.shasum === "string" ? `sha1:${body.dist.shasum}` : void 0;
|
|
@@ -2023,6 +2253,191 @@ function carriedForward(previous, reference) {
|
|
|
2023
2253
|
return previous;
|
|
2024
2254
|
}
|
|
2025
2255
|
|
|
2256
|
+
// src/lock/source.ts
|
|
2257
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
2258
|
+
import { homedir as homedir3 } from "os";
|
|
2259
|
+
import { dirname, join as join2, resolve as resolve4 } from "path";
|
|
2260
|
+
var PYPI_PUBLIC = "https://pypi.org/simple";
|
|
2261
|
+
function canonicalRegistry(url) {
|
|
2262
|
+
const trimmed = url.trim().replace(/\/+$/, "");
|
|
2263
|
+
try {
|
|
2264
|
+
const parsed = new URL(trimmed);
|
|
2265
|
+
const host = parsed.host.toLowerCase() === "registry.yarnpkg.com" ? "registry.npmjs.org" : parsed.host.toLowerCase();
|
|
2266
|
+
return `${parsed.protocol}//${host}${parsed.pathname.replace(/\/+$/, "")}`;
|
|
2267
|
+
} catch {
|
|
2268
|
+
return trimmed;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
function readSmall(path) {
|
|
2272
|
+
try {
|
|
2273
|
+
const stat = statSync(path);
|
|
2274
|
+
if (!stat.isFile() || stat.size > 1e6) return void 0;
|
|
2275
|
+
return readFileSync(path, "utf8");
|
|
2276
|
+
} catch {
|
|
2277
|
+
return void 0;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
function readIni(path, env) {
|
|
2281
|
+
const out = /* @__PURE__ */ new Map();
|
|
2282
|
+
for (const line of (readSmall(path) ?? "").split(/\r?\n/)) {
|
|
2283
|
+
const match = /^\s*([^;#=\s][^=]*?)\s*=\s*(.*?)\s*$/.exec(line);
|
|
2284
|
+
if (!match) continue;
|
|
2285
|
+
const value = match[2].replace(/^(["'])(.*)\1$/, "$2").replace(/\$\{([^}]+)\}/g, (_, name) => env[name] ?? "");
|
|
2286
|
+
out.set(match[1].toLowerCase(), value);
|
|
2287
|
+
}
|
|
2288
|
+
return out;
|
|
2289
|
+
}
|
|
2290
|
+
function launcherOptions(args, valueFlags, explicitFlags) {
|
|
2291
|
+
const out = [];
|
|
2292
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
2293
|
+
const arg = args[index];
|
|
2294
|
+
if (arg === "--" || !arg.startsWith("-") || arg.length === 1) break;
|
|
2295
|
+
const equals = arg.indexOf("=");
|
|
2296
|
+
if (arg.startsWith("--") && equals > 0) {
|
|
2297
|
+
out.push([arg.slice(0, equals).toLowerCase(), arg.slice(equals + 1)]);
|
|
2298
|
+
continue;
|
|
2299
|
+
}
|
|
2300
|
+
if (valueFlags.has(arg) || explicitFlags.includes(arg)) {
|
|
2301
|
+
out.push([arg.toLowerCase(), args[index + 1]]);
|
|
2302
|
+
index += 1;
|
|
2303
|
+
continue;
|
|
2304
|
+
}
|
|
2305
|
+
out.push([arg.toLowerCase(), void 0]);
|
|
2306
|
+
}
|
|
2307
|
+
return out;
|
|
2308
|
+
}
|
|
2309
|
+
function afterSubcommand(name, args) {
|
|
2310
|
+
if ((name === "pnpm" || name === "yarn") && args[0] === "dlx") return args.slice(1);
|
|
2311
|
+
if (name === "npm" && (args[0] === "exec" || args[0] === "x")) return args.slice(1);
|
|
2312
|
+
if (name === "uv" && args[0] === "tool" && args[1] === "run") return args.slice(2);
|
|
2313
|
+
if (name === "pipx" && args[0] === "run") return args.slice(1);
|
|
2314
|
+
return args;
|
|
2315
|
+
}
|
|
2316
|
+
function ancestors(start) {
|
|
2317
|
+
const out = [];
|
|
2318
|
+
for (let dir = resolve4(start); ; dir = dirname(dir)) {
|
|
2319
|
+
out.push(dir);
|
|
2320
|
+
if (dirname(dir) === dir) return out;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
function npmPrefix(start) {
|
|
2324
|
+
return ancestors(start).find((dir) => existsSync(join2(dir, "package.json")) || existsSync(join2(dir, "node_modules"))) ?? resolve4(start);
|
|
2325
|
+
}
|
|
2326
|
+
function npmElsewhere(transport2, reference, context) {
|
|
2327
|
+
const env = context.env ?? process.env;
|
|
2328
|
+
const name = commandName(transport2.command);
|
|
2329
|
+
const base = transport2.cwd ?? context.projectRoot;
|
|
2330
|
+
const launcherEnv = { ...env, ...transport2.env };
|
|
2331
|
+
const options = launcherOptions(afterSubcommand(name, transport2.args), NPM_VALUE_FLAGS, ["-p", "--package"]);
|
|
2332
|
+
const prefix = npmPrefix(base);
|
|
2333
|
+
if (name !== "pnpm" && name !== "yarn" && name !== "pnpx") {
|
|
2334
|
+
const bin = reference.name.split("/").pop();
|
|
2335
|
+
for (const dir of ancestors(base)) {
|
|
2336
|
+
if (existsSync(join2(dir, "node_modules", ...reference.name.split("/"), "package.json")) || existsSync(join2(dir, "node_modules", ".bin", bin))) {
|
|
2337
|
+
return "a copy installed in node_modules runs instead of the registry's";
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
const cli = new Map(options.filter(([flag]) => flag.startsWith("--")).map(([flag, value]) => [flag.slice(2), value ?? ""]));
|
|
2342
|
+
const userconfig = cli.get("userconfig") ?? npmEnv(launcherEnv, "npm_config_userconfig");
|
|
2343
|
+
const levels = [
|
|
2344
|
+
(key) => cli.get(key),
|
|
2345
|
+
(key) => npmEnv(launcherEnv, `npm_config_${key}`),
|
|
2346
|
+
/* @__PURE__ */ ((rc) => (key) => rc.get(key))(readIni(join2(prefix, ".npmrc"), launcherEnv)),
|
|
2347
|
+
/* @__PURE__ */ ((rc) => (key) => rc.get(key))(readIni(userconfig ? resolve4(base, userconfig) : join2(context.home ?? homedir3(), ".npmrc"), launcherEnv))
|
|
2348
|
+
];
|
|
2349
|
+
const setting = (key) => {
|
|
2350
|
+
for (const level of levels) {
|
|
2351
|
+
const value = level(key);
|
|
2352
|
+
if (value !== void 0) return value;
|
|
2353
|
+
}
|
|
2354
|
+
return void 0;
|
|
2355
|
+
};
|
|
2356
|
+
const scope = reference.name.startsWith("@") ? reference.name.slice(0, reference.name.indexOf("/")).toLowerCase() : void 0;
|
|
2357
|
+
const registry = (scope ? setting(`${scope}:registry`) : void 0) ?? setting("registry") ?? NPM_PUBLIC;
|
|
2358
|
+
if (canonicalRegistry(registry) !== canonicalRegistry(resolverNpmRegistry(env))) return "the launcher is pointed at a different npm registry";
|
|
2359
|
+
if (name === "yarn") {
|
|
2360
|
+
for (const dir of [prefix, context.home ?? homedir3()]) {
|
|
2361
|
+
const text = readSmall(join2(dir, ".yarnrc.yml")) ?? "";
|
|
2362
|
+
const server2 = /^\s*npmRegistryServer:\s*["']?([^"'\s#]+)/m.exec(text)?.[1];
|
|
2363
|
+
if (server2 && canonicalRegistry(server2) !== canonicalRegistry(resolverNpmRegistry(env)) || /^\s*npmScopes:/m.test(text)) {
|
|
2364
|
+
return "the launcher is pointed at a different npm registry";
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
if (name === "bunx" || name === "bun") {
|
|
2369
|
+
for (const dir of [prefix, context.home ?? homedir3()]) {
|
|
2370
|
+
if (/^\s*(?:registry\s*=|\[install\.scopes\])/m.test(readSmall(join2(dir, "bunfig.toml")) ?? "")) {
|
|
2371
|
+
return "the launcher is pointed at a different npm registry";
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
return void 0;
|
|
2376
|
+
}
|
|
2377
|
+
var PYPI_SOURCE_FLAGS = /* @__PURE__ */ new Set([
|
|
2378
|
+
"--index",
|
|
2379
|
+
"--index-url",
|
|
2380
|
+
"-i",
|
|
2381
|
+
"--extra-index-url",
|
|
2382
|
+
"--default-index",
|
|
2383
|
+
"--find-links",
|
|
2384
|
+
"-f",
|
|
2385
|
+
"--no-index",
|
|
2386
|
+
"--pip-args",
|
|
2387
|
+
"--config-file"
|
|
2388
|
+
]);
|
|
2389
|
+
var PYPI_SOURCE_ENV = [
|
|
2390
|
+
"UV_INDEX",
|
|
2391
|
+
"UV_INDEX_URL",
|
|
2392
|
+
"UV_DEFAULT_INDEX",
|
|
2393
|
+
"UV_EXTRA_INDEX_URL",
|
|
2394
|
+
"UV_FIND_LINKS",
|
|
2395
|
+
"UV_NO_INDEX",
|
|
2396
|
+
"UV_CONFIG_FILE",
|
|
2397
|
+
"PIP_INDEX_URL",
|
|
2398
|
+
"PIP_EXTRA_INDEX_URL",
|
|
2399
|
+
"PIP_FIND_LINKS",
|
|
2400
|
+
"PIP_NO_INDEX",
|
|
2401
|
+
"PIP_CONFIG_FILE"
|
|
2402
|
+
];
|
|
2403
|
+
var PYPI_INDEX_KEY = /^\s*(?:index-url|extra-index-url|default-index|find-links|no-index|\[\[(?:tool\.uv\.)?index\]\])/m;
|
|
2404
|
+
function pypiElsewhere(transport2, context) {
|
|
2405
|
+
const env = context.env ?? process.env;
|
|
2406
|
+
const name = commandName(transport2.command);
|
|
2407
|
+
const base = transport2.cwd ?? context.projectRoot;
|
|
2408
|
+
const home = context.home ?? homedir3();
|
|
2409
|
+
const launcherEnv = { ...env, ...transport2.env };
|
|
2410
|
+
if (launcherOptions(afterSubcommand(name, transport2.args), UV_VALUE_FLAGS, ["--from", "--spec"]).some(([flag]) => PYPI_SOURCE_FLAGS.has(flag))) {
|
|
2411
|
+
return "the launcher is given another package index";
|
|
2412
|
+
}
|
|
2413
|
+
for (const variable of PYPI_SOURCE_ENV) {
|
|
2414
|
+
const value = launcherEnv[variable];
|
|
2415
|
+
if (value && canonicalRegistry(value) !== PYPI_PUBLIC) return "the launcher is given another package index";
|
|
2416
|
+
}
|
|
2417
|
+
const files = [
|
|
2418
|
+
...ancestors(base).flatMap((dir) => [join2(dir, "uv.toml"), join2(dir, "pyproject.toml")]),
|
|
2419
|
+
join2(launcherEnv["XDG_CONFIG_HOME"] ?? join2(home, ".config"), "uv", "uv.toml"),
|
|
2420
|
+
"/etc/uv/uv.toml",
|
|
2421
|
+
...name === "pipx" ? [join2(home, ".config", "pip", "pip.conf"), join2(home, ".pip", "pip.conf"), join2(home, "Library", "Application Support", "pip", "pip.conf"), "/etc/pip.conf"] : []
|
|
2422
|
+
];
|
|
2423
|
+
for (const file of files) {
|
|
2424
|
+
const text = readSmall(file);
|
|
2425
|
+
if (text === void 0) continue;
|
|
2426
|
+
if (file.endsWith("pyproject.toml") && !/\[\[?tool\.uv/.test(text)) continue;
|
|
2427
|
+
if (PYPI_INDEX_KEY.test(text) && !indexIsPublic(text)) return "a config file gives the launcher another package index";
|
|
2428
|
+
}
|
|
2429
|
+
return void 0;
|
|
2430
|
+
}
|
|
2431
|
+
function indexIsPublic(text) {
|
|
2432
|
+
const urls = [...text.matchAll(/^\s*(?:index-url|extra-index-url|default-index|url)\s*=\s*["']?([^"'\s#]+)/gm)].map((match) => match[1]);
|
|
2433
|
+
return urls.length > 0 && urls.every((url) => canonicalRegistry(url) === PYPI_PUBLIC) && !/^\s*(?:find-links|no-index)/m.test(text);
|
|
2434
|
+
}
|
|
2435
|
+
function fetchedElsewhere(transport2, reference, context) {
|
|
2436
|
+
if (reference.ecosystem === "npm") return npmElsewhere(transport2, reference, context);
|
|
2437
|
+
if (reference.ecosystem === "pypi") return pypiElsewhere(transport2, context);
|
|
2438
|
+
return void 0;
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2026
2441
|
// src/mcp/connect.ts
|
|
2027
2442
|
import { Client, SSEClientTransport, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
2028
2443
|
import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
@@ -2030,18 +2445,18 @@ import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotoc
|
|
|
2030
2445
|
// src/mcp/oauth.ts
|
|
2031
2446
|
import { spawn } from "child_process";
|
|
2032
2447
|
import { createHash as createHash3, randomUUID } from "crypto";
|
|
2033
|
-
import { readFileSync } from "fs";
|
|
2448
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
2034
2449
|
import { mkdir, readFile as readFile4, rm, writeFile } from "fs/promises";
|
|
2035
|
-
import { homedir as
|
|
2036
|
-
import { dirname, join as
|
|
2450
|
+
import { homedir as homedir4, platform as platform2 } from "os";
|
|
2451
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
2037
2452
|
import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
|
|
2038
2453
|
var DEFAULT_CALLBACK_PATH = "/callback";
|
|
2039
2454
|
function authDir() {
|
|
2040
|
-
const base = process.env["XDG_CONFIG_HOME"] ??
|
|
2041
|
-
return
|
|
2455
|
+
const base = process.env["XDG_CONFIG_HOME"] ?? join3(homedir4(), ".config");
|
|
2456
|
+
return join3(base, "nulladrift", "auth");
|
|
2042
2457
|
}
|
|
2043
2458
|
function credentialPath(url) {
|
|
2044
|
-
return
|
|
2459
|
+
return join3(authDir(), `${createHash3("sha256").update(url).digest("hex").slice(0, 16)}.json`);
|
|
2045
2460
|
}
|
|
2046
2461
|
var InteractiveAuthRequiredError = class extends Error {
|
|
2047
2462
|
constructor(serverName) {
|
|
@@ -2094,7 +2509,7 @@ var FileTokenProvider = class {
|
|
|
2094
2509
|
const next = { ...await this.read(), ...patch, serverUrl: this.serverUrl };
|
|
2095
2510
|
this.cache = next;
|
|
2096
2511
|
const path = credentialPath(this.serverUrl);
|
|
2097
|
-
await mkdir(
|
|
2512
|
+
await mkdir(dirname2(path), { recursive: true, mode: 448 });
|
|
2098
2513
|
await writeFile(path, `${JSON.stringify(next, null, 2)}
|
|
2099
2514
|
`, { encoding: "utf8", mode: 384 });
|
|
2100
2515
|
}
|
|
@@ -2147,25 +2562,35 @@ var FileTokenProvider = class {
|
|
|
2147
2562
|
}
|
|
2148
2563
|
async redirectToAuthorization(authorizationUrl) {
|
|
2149
2564
|
if (!this.options.interactive) throw new InteractiveAuthRequiredError(this.serverName);
|
|
2150
|
-
openInBrowser(authorizationUrl)
|
|
2151
|
-
|
|
2565
|
+
if (openInBrowser(authorizationUrl)) {
|
|
2566
|
+
process.stderr.write(`
|
|
2152
2567
|
If a browser did not open, visit:
|
|
2153
2568
|
${authorizationUrl.toString()}
|
|
2154
2569
|
|
|
2155
2570
|
`);
|
|
2571
|
+
} else {
|
|
2572
|
+
process.stderr.write(`
|
|
2573
|
+
Not opening ${authorizationUrl.protocol} address the server named; an authorization page has to be https. Address:
|
|
2574
|
+
${authorizationUrl.toString()}
|
|
2575
|
+
|
|
2576
|
+
`);
|
|
2577
|
+
}
|
|
2156
2578
|
}
|
|
2157
2579
|
};
|
|
2158
2580
|
function openInBrowser(url) {
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2581
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
2582
|
+
if (!(url.protocol === "https:" || url.protocol === "http:" && loopback)) return false;
|
|
2583
|
+
const target = url.toString();
|
|
2584
|
+
const [command, args] = platform2() === "darwin" ? ["open", [target]] : platform2() === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", target]] : ["xdg-open", [target]];
|
|
2161
2585
|
try {
|
|
2162
|
-
spawn(command, args, { detached: true, stdio: "ignore" }).unref();
|
|
2586
|
+
spawn(command, args, { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
2163
2587
|
} catch {
|
|
2164
2588
|
}
|
|
2589
|
+
return true;
|
|
2165
2590
|
}
|
|
2166
2591
|
function hasStoredCredentials(url) {
|
|
2167
2592
|
try {
|
|
2168
|
-
const stored = JSON.parse(
|
|
2593
|
+
const stored = JSON.parse(readFileSync2(credentialPath(url), "utf8"));
|
|
2169
2594
|
return typeof stored.tokens?.access_token === "string" && stored.tokens.access_token.length > 0;
|
|
2170
2595
|
} catch {
|
|
2171
2596
|
return false;
|
|
@@ -2178,6 +2603,8 @@ function createAuthProvider(server2, options = {}) {
|
|
|
2178
2603
|
return new ClientCredentialsProvider({
|
|
2179
2604
|
clientId: oauth.clientId,
|
|
2180
2605
|
clientSecret: oauth.clientSecret,
|
|
2606
|
+
// The SDK then refuses to send the secret to any other authorization server (SEP-2352).
|
|
2607
|
+
...oauth.issuer === void 0 ? {} : { expectedIssuer: oauth.issuer },
|
|
2181
2608
|
clientName: `nulladrift ${VERSION}`,
|
|
2182
2609
|
...oauth.scope === void 0 ? {} : { scope: oauth.scope }
|
|
2183
2610
|
});
|
|
@@ -2342,6 +2769,21 @@ function describeListFailure(error) {
|
|
|
2342
2769
|
}
|
|
2343
2770
|
return message;
|
|
2344
2771
|
}
|
|
2772
|
+
var MAX_LIST_PAGES = 64;
|
|
2773
|
+
async function listAllTools(client, timeoutMs) {
|
|
2774
|
+
const tools = [];
|
|
2775
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
2776
|
+
let cursor;
|
|
2777
|
+
for (let page = 0; page < MAX_LIST_PAGES; page += 1) {
|
|
2778
|
+
const result = await client.request({ method: "tools/list", params: cursor === void 0 ? {} : { cursor } }, { timeout: timeoutMs });
|
|
2779
|
+
tools.push(...result.tools);
|
|
2780
|
+
cursor = result.nextCursor;
|
|
2781
|
+
if (cursor === void 0) return tools;
|
|
2782
|
+
if (cursors.has(cursor)) throw new Error("tools/list: the server repeated a page cursor, so the listing would never end");
|
|
2783
|
+
cursors.add(cursor);
|
|
2784
|
+
}
|
|
2785
|
+
throw new Error(`tools/list: more than ${MAX_LIST_PAGES} pages; the server's pagination did not end`);
|
|
2786
|
+
}
|
|
2345
2787
|
async function listOrEmpty(label, serverName, fetchList) {
|
|
2346
2788
|
try {
|
|
2347
2789
|
return await fetchList();
|
|
@@ -2371,30 +2813,59 @@ function readServerInfo(client) {
|
|
|
2371
2813
|
};
|
|
2372
2814
|
}
|
|
2373
2815
|
async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
2374
|
-
|
|
2375
|
-
|
|
2816
|
+
let connection;
|
|
2817
|
+
let expired = false;
|
|
2818
|
+
let timer;
|
|
2819
|
+
const late = () => new UnreachableServerError(server2.name, `did not finish within ${timeoutMs}ms`);
|
|
2820
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
2821
|
+
timer = setTimeout(() => {
|
|
2822
|
+
expired = true;
|
|
2823
|
+
void connection?.close();
|
|
2824
|
+
reject(late());
|
|
2825
|
+
}, timeoutMs);
|
|
2826
|
+
timer.unref?.();
|
|
2827
|
+
});
|
|
2828
|
+
const work = (async () => {
|
|
2829
|
+
const opened = await connect(server2, timeoutMs);
|
|
2830
|
+
if (expired) {
|
|
2831
|
+
await opened.close();
|
|
2832
|
+
throw late();
|
|
2833
|
+
}
|
|
2834
|
+
connection = opened;
|
|
2835
|
+
try {
|
|
2836
|
+
return await readSurface(opened.client, server2, timeoutMs);
|
|
2837
|
+
} finally {
|
|
2838
|
+
await opened.close();
|
|
2839
|
+
}
|
|
2840
|
+
})();
|
|
2841
|
+
work.catch(() => void 0);
|
|
2376
2842
|
try {
|
|
2377
|
-
|
|
2378
|
-
const [tools, resources, resourceTemplates, prompts] = await Promise.all([
|
|
2379
|
-
capabilities?.tools ? listOrEmpty("tools/list", server2.name, async () => (await client.listTools(void 0, FRESH)).tools) : [],
|
|
2380
|
-
capabilities?.resources ? listOrEmpty("resources/list", server2.name, async () => (await client.listResources(void 0, FRESH)).resources) : [],
|
|
2381
|
-
capabilities?.resources ? listOrEmpty("resources/templates/list", server2.name, async () => (await client.listResourceTemplates(void 0, FRESH)).resourceTemplates) : [],
|
|
2382
|
-
capabilities?.prompts ? listOrEmpty("prompts/list", server2.name, async () => (await client.listPrompts(void 0, FRESH)).prompts) : []
|
|
2383
|
-
]);
|
|
2384
|
-
return {
|
|
2385
|
-
protocol: readProtocol(client),
|
|
2386
|
-
serverInfo: readServerInfo(client),
|
|
2387
|
-
capabilities: capabilities ? toJson(capabilities) : void 0,
|
|
2388
|
-
// Clients place this in the model's system prompt, so it is part of the capability surface.
|
|
2389
|
-
instructions: client.getInstructions(),
|
|
2390
|
-
tools,
|
|
2391
|
-
resources,
|
|
2392
|
-
resourceTemplates,
|
|
2393
|
-
prompts
|
|
2394
|
-
};
|
|
2843
|
+
return await Promise.race([work, deadline]);
|
|
2395
2844
|
} finally {
|
|
2396
|
-
|
|
2397
|
-
}
|
|
2845
|
+
clearTimeout(timer);
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
async function readSurface(client, server2, timeoutMs) {
|
|
2849
|
+
const capabilities = client.getServerCapabilities();
|
|
2850
|
+
const [tools, resources, resourceTemplates, prompts] = await Promise.all([
|
|
2851
|
+
capabilities?.tools ? listOrEmpty("tools/list", server2.name, async () => listAllTools(client, timeoutMs)) : [],
|
|
2852
|
+
// Each list call is bounded by the server's timeout too. With none, the SDK's default
|
|
2853
|
+
// applied per page (60s, up to 64 pages), so one slow server could hold a run for an hour.
|
|
2854
|
+
capabilities?.resources ? listOrEmpty("resources/list", server2.name, async () => (await client.listResources(void 0, { ...FRESH, timeout: timeoutMs })).resources) : [],
|
|
2855
|
+
capabilities?.resources ? listOrEmpty("resources/templates/list", server2.name, async () => (await client.listResourceTemplates(void 0, { ...FRESH, timeout: timeoutMs })).resourceTemplates) : [],
|
|
2856
|
+
capabilities?.prompts ? listOrEmpty("prompts/list", server2.name, async () => (await client.listPrompts(void 0, { ...FRESH, timeout: timeoutMs })).prompts) : []
|
|
2857
|
+
]);
|
|
2858
|
+
return {
|
|
2859
|
+
protocol: readProtocol(client),
|
|
2860
|
+
serverInfo: readServerInfo(client),
|
|
2861
|
+
capabilities: capabilities ? toJson(capabilities) : void 0,
|
|
2862
|
+
// Clients place this in the model's system prompt, so it is part of the capability surface.
|
|
2863
|
+
instructions: client.getInstructions(),
|
|
2864
|
+
tools,
|
|
2865
|
+
resources,
|
|
2866
|
+
resourceTemplates,
|
|
2867
|
+
prompts
|
|
2868
|
+
};
|
|
2398
2869
|
}
|
|
2399
2870
|
|
|
2400
2871
|
// src/audit.ts
|
|
@@ -2402,6 +2873,7 @@ async function provenanceOf(server2, options) {
|
|
|
2402
2873
|
if (server2.transport.type !== "stdio") return { unverified: false };
|
|
2403
2874
|
const reference = referenceOf(server2.transport, options.projectRoot);
|
|
2404
2875
|
if (!reference) return { unverified: false };
|
|
2876
|
+
if (fetchedElsewhere(server2.transport, reference, { projectRoot: options.projectRoot })) return { unverified: true };
|
|
2405
2877
|
const previous = options.previous?.subjects[server2.name]?.provenance;
|
|
2406
2878
|
if (options.provenance === false) {
|
|
2407
2879
|
const kept2 = carriedForward(previous, reference);
|
|
@@ -2426,31 +2898,13 @@ async function mapWithLimit(items, limit, worker) {
|
|
|
2426
2898
|
await Promise.all(runners);
|
|
2427
2899
|
return results;
|
|
2428
2900
|
}
|
|
2429
|
-
async function withDeadline(ms, name, run) {
|
|
2430
|
-
let timer;
|
|
2431
|
-
try {
|
|
2432
|
-
return await Promise.race([
|
|
2433
|
-
run(),
|
|
2434
|
-
new Promise((_resolve, reject) => {
|
|
2435
|
-
timer = setTimeout(() => reject(new UnreachableServerError(name, `did not finish within ${ms}ms`)), ms);
|
|
2436
|
-
timer.unref?.();
|
|
2437
|
-
})
|
|
2438
|
-
]);
|
|
2439
|
-
} finally {
|
|
2440
|
-
if (timer) clearTimeout(timer);
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
2901
|
async function captureAll(options) {
|
|
2444
|
-
const discovery = await discoverServers(options.projectRoot, options.configFiles);
|
|
2902
|
+
const discovery = await discoverServers(options.projectRoot, options.configFiles, { userConfigs: options.userConfigs === true });
|
|
2445
2903
|
const captured = await mapWithLimit(discovery.servers, options.concurrency ?? 4, async (server2) => {
|
|
2446
2904
|
try {
|
|
2447
|
-
const surface = await withDeadline(
|
|
2448
|
-
options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
|
|
2449
|
-
server2.name,
|
|
2450
|
-
() => captureSurface(server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2)
|
|
2451
|
-
);
|
|
2452
|
-
const entry = buildLockedServer(server2, surface, options.policy);
|
|
2453
2905
|
const { provenance: provenance2, unverified: unverified2 } = await provenanceOf(server2, options);
|
|
2906
|
+
const surface = await captureSurface(server2, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2);
|
|
2907
|
+
const entry = buildLockedServer(server2, surface, options.policy);
|
|
2454
2908
|
options.onServerDone?.(server2.name, "captured");
|
|
2455
2909
|
return { name: server2.name, entry: provenance2 ? { ...entry, provenance: provenance2 } : entry, unverified: unverified2 };
|
|
2456
2910
|
} catch (error) {
|
|
@@ -2489,14 +2943,25 @@ async function captureAll(options) {
|
|
|
2489
2943
|
}
|
|
2490
2944
|
|
|
2491
2945
|
// src/lock/io.ts
|
|
2946
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
2492
2947
|
import { lstat, readFile as readFile5, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
|
|
2493
2948
|
|
|
2494
2949
|
// src/lock/schema.ts
|
|
2495
2950
|
import { z as z2 } from "zod";
|
|
2496
|
-
|
|
2497
|
-
|
|
2951
|
+
function isJsonValue(value, depth = 0) {
|
|
2952
|
+
if (depth > 256) return false;
|
|
2953
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
2954
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
2955
|
+
if (Array.isArray(value)) return value.every((member) => isJsonValue(member, depth + 1));
|
|
2956
|
+
if (typeof value !== "object") return false;
|
|
2957
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2958
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
2959
|
+
return Object.values(value).every((member) => isJsonValue(member, depth + 1));
|
|
2960
|
+
}
|
|
2961
|
+
var jsonObject = z2.custom(
|
|
2962
|
+
(value) => value !== null && typeof value === "object" && !Array.isArray(value) && isJsonValue(value),
|
|
2963
|
+
"expected a JSON object"
|
|
2498
2964
|
);
|
|
2499
|
-
var jsonObject = z2.record(z2.string(), jsonValue);
|
|
2500
2965
|
var digestString = z2.string().regex(/^sha256:[0-9a-f]{64}$/, "expected a sha256 digest");
|
|
2501
2966
|
var icon = z2.object({
|
|
2502
2967
|
src: z2.string(),
|
|
@@ -2670,13 +3135,14 @@ function isPlainObject(value) {
|
|
|
2670
3135
|
function printScalar(value) {
|
|
2671
3136
|
return JSON.stringify(value);
|
|
2672
3137
|
}
|
|
3138
|
+
var childKind = (key) => Object.hasOwn(CHILD_KIND, key) ? CHILD_KIND[key] : void 0;
|
|
2673
3139
|
function printObject(value, kind, depth) {
|
|
2674
|
-
const declared = kind ? KEY_ORDER[kind] : [];
|
|
3140
|
+
const declared = kind && Object.hasOwn(KEY_ORDER, kind) ? KEY_ORDER[kind] : [];
|
|
2675
3141
|
const present = Object.keys(value).filter((key) => value[key] !== void 0);
|
|
2676
3142
|
const ordered = kind ? [...declared.filter((key) => present.includes(key)), ...present.filter((key) => !declared.includes(key)).sort()] : present.sort();
|
|
2677
3143
|
if (ordered.length === 0) return "{}";
|
|
2678
3144
|
const pad = INDENT.repeat(depth + 1);
|
|
2679
|
-
const body = ordered.map((key) => `${pad}${JSON.stringify(key)}: ${printNode(value[key],
|
|
3145
|
+
const body = ordered.map((key) => `${pad}${JSON.stringify(key)}: ${printNode(value[key], childKind(key), depth + 1)}`).join(",\n");
|
|
2680
3146
|
return `{
|
|
2681
3147
|
${body}
|
|
2682
3148
|
${INDENT.repeat(depth)}}`;
|
|
@@ -2720,7 +3186,7 @@ ${pad}}`;
|
|
|
2720
3186
|
parts.push(`${pad}${JSON.stringify(key)}: ${body}`);
|
|
2721
3187
|
continue;
|
|
2722
3188
|
}
|
|
2723
|
-
parts.push(`${pad}${JSON.stringify(key)}: ${printNode(value,
|
|
3189
|
+
parts.push(`${pad}${JSON.stringify(key)}: ${printNode(value, childKind(key), 1)}`);
|
|
2724
3190
|
}
|
|
2725
3191
|
return `{
|
|
2726
3192
|
${parts.join(",\n")}
|
|
@@ -2764,8 +3230,8 @@ async function readLockfile(path) {
|
|
|
2764
3230
|
try {
|
|
2765
3231
|
text = await readFile5(path, "utf8");
|
|
2766
3232
|
} catch (error) {
|
|
2767
|
-
const
|
|
2768
|
-
if (
|
|
3233
|
+
const code2 = error.code;
|
|
3234
|
+
if (code2 === "ENOENT") throw new LockfileError(`no lockfile at ${path}. Run \`nulladrift init\` first.`);
|
|
2769
3235
|
throw new LockfileError(`could not read ${path}: ${error.message}`);
|
|
2770
3236
|
}
|
|
2771
3237
|
const lock = parseLockfile(text, path);
|
|
@@ -2784,8 +3250,8 @@ async function writeLockfile(path, lock) {
|
|
|
2784
3250
|
if (error instanceof LockfileError) throw error;
|
|
2785
3251
|
}
|
|
2786
3252
|
try {
|
|
2787
|
-
const temporary = `${path}.${
|
|
2788
|
-
await writeFile2(temporary, serializeLockfile(lock), "utf8");
|
|
3253
|
+
const temporary = `${path}.${randomUUID2()}.tmp`;
|
|
3254
|
+
await writeFile2(temporary, serializeLockfile(lock), { encoding: "utf8", flag: "wx" });
|
|
2789
3255
|
try {
|
|
2790
3256
|
await rename(temporary, path);
|
|
2791
3257
|
} catch (error) {
|
|
@@ -2794,9 +3260,9 @@ async function writeLockfile(path, lock) {
|
|
|
2794
3260
|
throw error;
|
|
2795
3261
|
}
|
|
2796
3262
|
} catch (error) {
|
|
2797
|
-
const
|
|
2798
|
-
if (
|
|
2799
|
-
if (
|
|
3263
|
+
const code2 = error.code;
|
|
3264
|
+
if (code2 === "ENOENT") throw new LockfileError(`cannot write ${path}: the directory does not exist. Note that --lock is resolved against --cwd.`);
|
|
3265
|
+
if (code2 === "EACCES" || code2 === "EPERM") throw new LockfileError(`cannot write ${path}: permission denied.`);
|
|
2800
3266
|
throw new LockfileError(`cannot write ${path}: ${error.message}`);
|
|
2801
3267
|
}
|
|
2802
3268
|
}
|
|
@@ -2824,8 +3290,8 @@ function renderTextChange(before, after) {
|
|
|
2824
3290
|
return lines;
|
|
2825
3291
|
}
|
|
2826
3292
|
function renderChange(change2) {
|
|
2827
|
-
const where = change2.member ? `${change2.server} \u203A ${change2.member}` : change2.server;
|
|
2828
|
-
const lines = [` ${MARK[change2.severity](change2.severity.padEnd(6))} ${bold(where)} ${dim(change2.kind)}`, ` ${change2.summary}`];
|
|
3293
|
+
const where = visibleControls(change2.member ? `${change2.server} \u203A ${change2.member}` : change2.server);
|
|
3294
|
+
const lines = [` ${MARK[change2.severity](change2.severity.padEnd(6))} ${bold(where)} ${dim(change2.kind)}`, ` ${visibleControls(change2.summary)}`];
|
|
2829
3295
|
if (change2.kind === "tool.description.changed" || change2.kind === "server.instructions.changed") {
|
|
2830
3296
|
lines.push(...renderTextChange(change2.before, change2.after));
|
|
2831
3297
|
}
|
|
@@ -2840,7 +3306,7 @@ function renderSteering(report) {
|
|
|
2840
3306
|
""
|
|
2841
3307
|
];
|
|
2842
3308
|
for (const { server: server2, signals } of found) {
|
|
2843
|
-
lines.push(` ${bold(server2)}`);
|
|
3309
|
+
lines.push(` ${bold(visibleControls(server2))}`);
|
|
2844
3310
|
const byField = /* @__PURE__ */ new Map();
|
|
2845
3311
|
for (const signal of signals) byField.set(signal.field, [...byField.get(signal.field) ?? [], signal.quote]);
|
|
2846
3312
|
const fields = [...byField];
|
|
@@ -2859,7 +3325,7 @@ function renderViolations(report) {
|
|
|
2859
3325
|
const lines = ["", bold(red(`${found.length} capability(ies) this project does not permit:`)), ""];
|
|
2860
3326
|
for (const violation of found) {
|
|
2861
3327
|
lines.push(
|
|
2862
|
-
` ${red("denied")} ${bold(`${violation.server} \u203A ${violation.tool}`)} ${dim(violation.kind)}`,
|
|
3328
|
+
` ${red("denied")} ${bold(visibleControls(`${violation.server} \u203A ${violation.tool}`))} ${dim(violation.kind)}`,
|
|
2863
3329
|
` ${violation.severity} \xB7 ${violation.evidence}`
|
|
2864
3330
|
);
|
|
2865
3331
|
}
|
|
@@ -2883,7 +3349,7 @@ function renderHumanReport(report) {
|
|
|
2883
3349
|
if (quiet.length > 0) {
|
|
2884
3350
|
lines.push(
|
|
2885
3351
|
yellow(`${quiet.length === 1 ? "This server" : "These servers"} changed without shipping a new version:`),
|
|
2886
|
-
...quiet.map((server2) => ` ${bold(server2)}`),
|
|
3352
|
+
...quiet.map((server2) => ` ${bold(visibleControls(server2))}`),
|
|
2887
3353
|
""
|
|
2888
3354
|
);
|
|
2889
3355
|
}
|
|
@@ -2892,14 +3358,14 @@ function renderHumanReport(report) {
|
|
|
2892
3358
|
lines.push(bold(`Could not audit ${report.unreachable.length} server(s):`), "");
|
|
2893
3359
|
for (const failure of report.unreachable) {
|
|
2894
3360
|
const label = failure.kind === "auth" ? yellow("needs creds") : failure.kind === "forbidden" ? yellow("not permitted") : red("unreachable");
|
|
2895
|
-
lines.push(` ${label} ${bold(failure.server)}`, ` ${failure.reason}`, "");
|
|
3361
|
+
lines.push(` ${label} ${bold(visibleControls(failure.server))}`, ` ${visibleControls(failure.reason)}`, "");
|
|
2896
3362
|
}
|
|
2897
3363
|
}
|
|
2898
3364
|
const unverified = report.unverified ?? [];
|
|
2899
3365
|
if (unverified.length > 0) {
|
|
2900
3366
|
lines.push(
|
|
2901
3367
|
yellow(`Could not establish what ${unverified.length} server(s) run:`),
|
|
2902
|
-
...unverified.map((server2) => ` ${bold(server2)}`),
|
|
3368
|
+
...unverified.map((server2) => ` ${bold(visibleControls(server2))}`),
|
|
2903
3369
|
dim(" Their surfaces were checked; the package or file behind them was not. A pin the config names exactly is kept."),
|
|
2904
3370
|
""
|
|
2905
3371
|
);
|
|
@@ -3128,12 +3594,19 @@ var AUDIT_FAILURE_LABEL = {
|
|
|
3128
3594
|
unreachable: "unreachable"
|
|
3129
3595
|
};
|
|
3130
3596
|
var MARK2 = { high: "\u{1F534}", medium: "\u{1F7E0}", low: "\u26AA" };
|
|
3131
|
-
function
|
|
3132
|
-
return visibleControls(text).replace(
|
|
3597
|
+
function plain(text) {
|
|
3598
|
+
return visibleControls(text).replace(/\r?\n/g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/([\\`*_{}[\]()#+!|~])/g, "\\$1").replace(/@/g, "@").replace(/:\/\//g, "://").trim();
|
|
3599
|
+
}
|
|
3600
|
+
function code(text) {
|
|
3601
|
+
const body = visibleControls(text).replace(/\r?\n/g, " ").replace(/\|/g, "\\|").trim();
|
|
3602
|
+
const longest = Math.max(0, ...(body.match(/`+/g) ?? []).map((run) => run.length));
|
|
3603
|
+
const fence = "`".repeat(longest + 1);
|
|
3604
|
+
const pad = body.startsWith("`") || body.endsWith("`") ? " " : "";
|
|
3605
|
+
return `${fence}${pad}${body}${pad}${fence}`;
|
|
3133
3606
|
}
|
|
3134
3607
|
function row(change2) {
|
|
3135
3608
|
const where = change2.member ? `${change2.server}/${change2.member}` : change2.server;
|
|
3136
|
-
return `| ${MARK2[change2.severity]} ${change2.severity} |
|
|
3609
|
+
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(where)} | ${plain(change2.kind)} | ${plain(change2.summary)} |`;
|
|
3137
3610
|
}
|
|
3138
3611
|
function renderMarkdownReport(report, options = {}) {
|
|
3139
3612
|
if (report.changes.length === 0 && report.unreachable.length === 0) return null;
|
|
@@ -3151,7 +3624,7 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3151
3624
|
const quiet = serversThatShippedNothing(report.changes);
|
|
3152
3625
|
if (quiet.length > 0) {
|
|
3153
3626
|
lines.push(
|
|
3154
|
-
`> **${quiet.length === 1 ? "This server" : "These servers"} changed without shipping a new version:** ${quiet.map((server2) =>
|
|
3627
|
+
`> **${quiet.length === 1 ? "This server" : "These servers"} changed without shipping a new version:** ${quiet.map((server2) => code(server2)).join(", ")}`,
|
|
3155
3628
|
">",
|
|
3156
3629
|
"> Same package, same version, a different declaration. Nothing was published.",
|
|
3157
3630
|
""
|
|
@@ -3171,7 +3644,7 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3171
3644
|
"| Server | Field | Passage |",
|
|
3172
3645
|
"| --- | --- | --- |",
|
|
3173
3646
|
...steering.flatMap(
|
|
3174
|
-
({ server: server2, signals }) => signals.slice(0, 10).map((signal) => `|
|
|
3647
|
+
({ server: server2, signals }) => signals.slice(0, 10).map((signal) => `| ${code(server2)} | ${code(signal.field)} | ${plain(signal.quote)} |`)
|
|
3175
3648
|
),
|
|
3176
3649
|
"",
|
|
3177
3650
|
"</details>",
|
|
@@ -3183,7 +3656,7 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
3183
3656
|
`<details><summary>${report.unreachable.length} server${report.unreachable.length === 1 ? "" : "s"} could not be read</summary>`,
|
|
3184
3657
|
"",
|
|
3185
3658
|
...report.unreachable.map(
|
|
3186
|
-
(failure) => `-
|
|
3659
|
+
(failure) => `- ${code(failure.server)} \xB7 ${AUDIT_FAILURE_LABEL[failure.kind]}: ${plain(failure.reason)}`
|
|
3187
3660
|
),
|
|
3188
3661
|
"",
|
|
3189
3662
|
"</details>",
|
|
@@ -3240,16 +3713,16 @@ ${body}`;
|
|
|
3240
3713
|
}
|
|
3241
3714
|
|
|
3242
3715
|
// src/telemetry/index.ts
|
|
3243
|
-
import { createHash as createHash5, randomUUID as
|
|
3716
|
+
import { createHash as createHash5, randomUUID as randomUUID3 } from "crypto";
|
|
3244
3717
|
import { mkdir as mkdir2, readFile as readFile6, rm as rm3, writeFile as writeFile3 } from "fs/promises";
|
|
3245
|
-
import { homedir as
|
|
3246
|
-
import { dirname as
|
|
3718
|
+
import { homedir as homedir5 } from "os";
|
|
3719
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
3247
3720
|
var PAYLOAD_SCHEMA = 2;
|
|
3248
3721
|
var SEND_TIMEOUT_MS = 2e3;
|
|
3249
3722
|
var ID_ROTATION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
3250
3723
|
function configPath() {
|
|
3251
|
-
const base = process.env["XDG_CONFIG_HOME"] ??
|
|
3252
|
-
return
|
|
3724
|
+
const base = process.env["XDG_CONFIG_HOME"] ?? join4(homedir5(), ".config");
|
|
3725
|
+
return join4(base, "nulladrift", "config.json");
|
|
3253
3726
|
}
|
|
3254
3727
|
function isCi() {
|
|
3255
3728
|
return process.env["CI"] !== void 0 && process.env["CI"] !== "false";
|
|
@@ -3264,7 +3737,7 @@ async function readConfig() {
|
|
|
3264
3737
|
}
|
|
3265
3738
|
async function writeConfig(patch) {
|
|
3266
3739
|
const path = configPath();
|
|
3267
|
-
await mkdir2(
|
|
3740
|
+
await mkdir2(dirname3(path), { recursive: true });
|
|
3268
3741
|
await writeFile3(path, `${JSON.stringify({ ...await readConfig(), ...patch }, null, 2)}
|
|
3269
3742
|
`, "utf8");
|
|
3270
3743
|
}
|
|
@@ -3283,7 +3756,7 @@ async function resolveInstallId(now = Date.now()) {
|
|
|
3283
3756
|
const issuedAt = config.installIdIssuedAt ? Date.parse(config.installIdIssuedAt) : Number.NaN;
|
|
3284
3757
|
const fresh = config.installId !== void 0 && Number.isFinite(issuedAt) && now - issuedAt < ID_ROTATION_MS;
|
|
3285
3758
|
if (fresh && config.installId !== void 0) return config.installId;
|
|
3286
|
-
const installId =
|
|
3759
|
+
const installId = randomUUID3();
|
|
3287
3760
|
await writeConfig({ installId, installIdIssuedAt: new Date(now).toISOString(), lastReportHash: void 0 });
|
|
3288
3761
|
return installId;
|
|
3289
3762
|
}
|
|
@@ -3294,7 +3767,7 @@ function buildPayload(report, changes, installId) {
|
|
|
3294
3767
|
schema: PAYLOAD_SCHEMA,
|
|
3295
3768
|
installId,
|
|
3296
3769
|
// Distinguishes two runs from the same installation; not stored, and not an identifier.
|
|
3297
|
-
runId:
|
|
3770
|
+
runId: randomUUID3(),
|
|
3298
3771
|
auditVersion: VERSION,
|
|
3299
3772
|
context: isCi() ? "ci" : "local",
|
|
3300
3773
|
serverCount: report.serversChecked,
|
|
@@ -3345,7 +3818,8 @@ async function buildReport(options) {
|
|
|
3345
3818
|
// The committed policy governs the check, so every consumer of the repo audits identically.
|
|
3346
3819
|
policy: committed.policy,
|
|
3347
3820
|
previous: committed,
|
|
3348
|
-
provenance: options.provenance
|
|
3821
|
+
provenance: options.provenance,
|
|
3822
|
+
userConfigs: options.userConfigs
|
|
3349
3823
|
});
|
|
3350
3824
|
for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
|
|
3351
3825
|
`);
|
|
@@ -3540,7 +4014,8 @@ async function runInit(options) {
|
|
|
3540
4014
|
projectRoot: options.projectRoot,
|
|
3541
4015
|
configFiles: options.configFiles,
|
|
3542
4016
|
timeoutMs: options.timeoutMs,
|
|
3543
|
-
provenance: options.provenance
|
|
4017
|
+
provenance: options.provenance,
|
|
4018
|
+
userConfigs: options.userConfigs
|
|
3544
4019
|
});
|
|
3545
4020
|
const names = Object.keys(result.lock.subjects);
|
|
3546
4021
|
if (names.length === 0 && result.unreachable.length === 0) {
|
|
@@ -3567,9 +4042,9 @@ async function runInit(options) {
|
|
|
3567
4042
|
`${entry?.resourceTemplates?.length ?? 0} templates`,
|
|
3568
4043
|
`${entry?.prompts?.length ?? 0} prompts`
|
|
3569
4044
|
].join(", ");
|
|
3570
|
-
lines.push(` ${green("\u2713")} ${bold(name)} ${dim(counts)}`);
|
|
4045
|
+
lines.push(` ${green("\u2713")} ${bold(visibleControls(name))} ${dim(counts)}`);
|
|
3571
4046
|
const deprecated = entry?.transport.type === "sse" ? " \xB7 HTTP+SSE transport is deprecated in the spec" : "";
|
|
3572
|
-
lines.push(` ${dim(`${entry?.protocol.era}/${entry?.protocol.version} \xB7 from ${entry?.source.file}${deprecated}`)}`);
|
|
4047
|
+
lines.push(` ${dim(visibleControls(`${entry?.protocol.era}/${entry?.protocol.version} \xB7 from ${entry?.source.file}${deprecated}`))}`);
|
|
3573
4048
|
const redacted = entry ? countRedacted(entry.transport) : 0;
|
|
3574
4049
|
if (redacted > 0) lines.push(` ${yellow(redactedLine(redacted))}`);
|
|
3575
4050
|
const tools = entry?.tools ?? [];
|
|
@@ -3579,7 +4054,7 @@ async function runInit(options) {
|
|
|
3579
4054
|
const paint = worst.length > 0 ? yellow : dim;
|
|
3580
4055
|
lines.push(` ${paint(`can: ${capabilities.map((capability) => capability.kind).join(", ")}`)}`);
|
|
3581
4056
|
for (const capability of worst) {
|
|
3582
|
-
lines.push(` ${dim(`${capability.kind} \xB7 ${capability.tools.slice(0, 3).join(", ")}${capability.tools.length > 3 ? ` +${capability.tools.length - 3}` : ""}`)}`);
|
|
4057
|
+
lines.push(` ${dim(visibleControls(`${capability.kind} \xB7 ${capability.tools.slice(0, 3).join(", ")}${capability.tools.length > 3 ? ` +${capability.tools.length - 3}` : ""}`))}`);
|
|
3583
4058
|
}
|
|
3584
4059
|
}
|
|
3585
4060
|
const steering = (entry ? surfaceText(entry) : []).flatMap(
|
|
@@ -3603,6 +4078,12 @@ async function runInit(options) {
|
|
|
3603
4078
|
for (const failure of result.unreachable) {
|
|
3604
4079
|
lines.push(` ${red("\u2717")} ${bold(failure.server)} ${dim("not pinned")}`, ` ${failure.reason}`);
|
|
3605
4080
|
}
|
|
4081
|
+
if (result.discovery.userConfigsSkipped.length > 0) {
|
|
4082
|
+
lines.push(
|
|
4083
|
+
dim(` note: your own configs were not pinned (${result.discovery.userConfigsSkipped.join(", ")}). mcp.lock is the project's and is committed;`),
|
|
4084
|
+
dim(" pass --user-configs to include their servers anyway.")
|
|
4085
|
+
);
|
|
4086
|
+
}
|
|
3606
4087
|
for (const shadow of result.discovery.shadowed) {
|
|
3607
4088
|
lines.push(dim(` note: "${shadow.name}" is defined in both ${shadow.keptFrom} and ${shadow.alsoIn}; kept the first.`));
|
|
3608
4089
|
}
|
|
@@ -3632,14 +4113,14 @@ async function awaitCallback(expectedState) {
|
|
|
3632
4113
|
return;
|
|
3633
4114
|
}
|
|
3634
4115
|
const error = url.searchParams.get("error");
|
|
3635
|
-
const
|
|
4116
|
+
const code2 = url.searchParams.get("code");
|
|
3636
4117
|
const state = url.searchParams.get("state");
|
|
3637
4118
|
if (error !== null) {
|
|
3638
4119
|
response.writeHead(400, { "content-type": "text/plain" }).end(`authorization failed: ${error}`);
|
|
3639
4120
|
fail?.(new Error(`${error}${url.searchParams.get("error_description") ? `: ${url.searchParams.get("error_description")}` : ""}`));
|
|
3640
4121
|
return;
|
|
3641
4122
|
}
|
|
3642
|
-
if (
|
|
4123
|
+
if (code2 === null) {
|
|
3643
4124
|
response.writeHead(400, { "content-type": "text/plain" }).end("no authorization code in the callback");
|
|
3644
4125
|
fail?.(new Error("callback carried no authorization code"));
|
|
3645
4126
|
return;
|
|
@@ -3650,15 +4131,15 @@ async function awaitCallback(expectedState) {
|
|
|
3650
4131
|
return;
|
|
3651
4132
|
}
|
|
3652
4133
|
response.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end("<!doctype html><title>nulladrift</title><p>Authorized. You can close this tab.");
|
|
3653
|
-
settle?.({ code, state, iss: url.searchParams.get("iss") ?? void 0 });
|
|
4134
|
+
settle?.({ code: code2, state, iss: url.searchParams.get("iss") ?? void 0 });
|
|
3654
4135
|
});
|
|
3655
4136
|
await new Promise((ready, broke) => {
|
|
3656
4137
|
server2.once("error", broke);
|
|
3657
4138
|
server2.listen(0, "127.0.0.1", ready);
|
|
3658
4139
|
});
|
|
3659
4140
|
const { port } = server2.address();
|
|
3660
|
-
const received = new Promise((
|
|
3661
|
-
settle =
|
|
4141
|
+
const received = new Promise((resolve6, reject) => {
|
|
4142
|
+
settle = resolve6;
|
|
3662
4143
|
fail = reject;
|
|
3663
4144
|
setTimeout(() => reject(new Error(`no callback within ${CALLBACK_TIMEOUT_MS / 1e3}s`)), CALLBACK_TIMEOUT_MS).unref();
|
|
3664
4145
|
});
|
|
@@ -3669,7 +4150,7 @@ async function awaitCallback(expectedState) {
|
|
|
3669
4150
|
};
|
|
3670
4151
|
}
|
|
3671
4152
|
async function findServer(projectRoot, configFiles, name) {
|
|
3672
|
-
const discovery = await discoverServers(projectRoot, configFiles);
|
|
4153
|
+
const discovery = await discoverServers(projectRoot, configFiles, { userConfigs: true });
|
|
3673
4154
|
const server2 = discovery.servers.find((candidate) => candidate.name === name);
|
|
3674
4155
|
if (!server2) {
|
|
3675
4156
|
const known = discovery.servers.map((candidate) => candidate.name);
|
|
@@ -3697,7 +4178,7 @@ async function runLogin(options) {
|
|
|
3697
4178
|
Object.assign(authenticating, { stateValue: provider.stateValue });
|
|
3698
4179
|
try {
|
|
3699
4180
|
process.stdout.write(`${bold(`Authorizing ${found.name}`)}
|
|
3700
|
-
${dim(serverUrl)}
|
|
4181
|
+
${dim(sanitizeUrl(serverUrl))}
|
|
3701
4182
|
`);
|
|
3702
4183
|
const started = await auth(authenticating, { serverUrl });
|
|
3703
4184
|
if (started === "AUTHORIZED") {
|
|
@@ -3705,8 +4186,8 @@ ${dim(serverUrl)}
|
|
|
3705
4186
|
`);
|
|
3706
4187
|
return EXIT_CLEAN;
|
|
3707
4188
|
}
|
|
3708
|
-
const { code, iss } = await callback.wait();
|
|
3709
|
-
const finished = await auth(authenticating, { serverUrl, authorizationCode:
|
|
4189
|
+
const { code: code2, iss } = await callback.wait();
|
|
4190
|
+
const finished = await auth(authenticating, { serverUrl, authorizationCode: code2, ...iss === void 0 ? {} : { iss } });
|
|
3710
4191
|
if (finished !== "AUTHORIZED") {
|
|
3711
4192
|
process.stderr.write(`${red("authorization did not complete")}
|
|
3712
4193
|
`);
|
|
@@ -3747,10 +4228,10 @@ async function runLogout(options) {
|
|
|
3747
4228
|
function envelope(body) {
|
|
3748
4229
|
try {
|
|
3749
4230
|
const parsed = JSON.parse(body);
|
|
3750
|
-
const
|
|
4231
|
+
const code2 = parsed.error?.code;
|
|
3751
4232
|
const message = parsed.error?.message;
|
|
3752
|
-
if (typeof
|
|
3753
|
-
return { code, message };
|
|
4233
|
+
if (typeof code2 !== "string" || typeof message !== "string") return null;
|
|
4234
|
+
return { code: code2, message };
|
|
3754
4235
|
} catch {
|
|
3755
4236
|
return null;
|
|
3756
4237
|
}
|
|
@@ -3833,6 +4314,18 @@ function inferRef() {
|
|
|
3833
4314
|
function inferCommit() {
|
|
3834
4315
|
return process.env["GITHUB_SHA"] ?? process.env["CI_COMMIT_SHA"] ?? void 0;
|
|
3835
4316
|
}
|
|
4317
|
+
function refuseApiUrl(apiUrl) {
|
|
4318
|
+
let url;
|
|
4319
|
+
try {
|
|
4320
|
+
url = new URL(apiUrl);
|
|
4321
|
+
} catch {
|
|
4322
|
+
return "the control plane's address is not a URL.";
|
|
4323
|
+
}
|
|
4324
|
+
if (url.username || url.password) return "the control plane's address carries credentials. Pass the token with --token or NULLADRIFT_TOKEN instead.";
|
|
4325
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
4326
|
+
if (url.protocol === "https:" || url.protocol === "http:" && loopback) return void 0;
|
|
4327
|
+
return `the control plane has to be reached over https (http only on this machine), not ${url.protocol}`;
|
|
4328
|
+
}
|
|
3836
4329
|
async function runPush(options) {
|
|
3837
4330
|
const apiUrl = (options.apiUrl ?? process.env["NULLADRIFT_API_URL"] ?? "").replace(/\/+$/, "");
|
|
3838
4331
|
const token = options.token ?? process.env["NULLADRIFT_TOKEN"] ?? "";
|
|
@@ -3848,11 +4341,18 @@ async function runPush(options) {
|
|
|
3848
4341
|
);
|
|
3849
4342
|
return EXIT_INCOMPLETE;
|
|
3850
4343
|
}
|
|
4344
|
+
const refusal = refuseApiUrl(apiUrl);
|
|
4345
|
+
if (refusal) {
|
|
4346
|
+
process.stderr.write(`${red("push refused:")} ${refusal}
|
|
4347
|
+
`);
|
|
4348
|
+
return EXIT_INCOMPLETE;
|
|
4349
|
+
}
|
|
3851
4350
|
const result = await captureAll({
|
|
3852
4351
|
projectRoot: options.projectRoot,
|
|
3853
4352
|
configFiles: options.configFiles,
|
|
3854
4353
|
timeoutMs: options.timeoutMs,
|
|
3855
|
-
provenance: options.provenance
|
|
4354
|
+
provenance: options.provenance,
|
|
4355
|
+
userConfigs: options.userConfigs
|
|
3856
4356
|
});
|
|
3857
4357
|
for (const note of redactedNotes(result.lock)) process.stderr.write(`${yellow("note:")} ${note}
|
|
3858
4358
|
`);
|
|
@@ -3884,7 +4384,9 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
3884
4384
|
context: options.watch ? "watch" : process.env["CI"] !== void 0 && process.env["CI"] !== "false" ? "ci" : "local",
|
|
3885
4385
|
collectorVersion: VERSION,
|
|
3886
4386
|
servers,
|
|
3887
|
-
|
|
4387
|
+
// The error, not the server's stderr: stderr is where a server prints its tokens and paths, and
|
|
4388
|
+
// this leaves the machine. The full reason is still printed locally.
|
|
4389
|
+
unreachable: result.unreachable.map((failure) => ({ server: failure.server, reason: failure.reason.split("\n server stderr:")[0] ?? failure.reason }))
|
|
3888
4390
|
};
|
|
3889
4391
|
const build = await acquireBuildToken();
|
|
3890
4392
|
const buildToken = build && "token" in build ? build.token : void 0;
|
|
@@ -3898,6 +4400,8 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
3898
4400
|
...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {}
|
|
3899
4401
|
},
|
|
3900
4402
|
body: JSON.stringify(body),
|
|
4403
|
+
// A redirect would carry the reading and the identity token to wherever it points.
|
|
4404
|
+
redirect: "error",
|
|
3901
4405
|
signal: AbortSignal.timeout(options.timeoutMs)
|
|
3902
4406
|
});
|
|
3903
4407
|
} catch (error) {
|
|
@@ -3906,8 +4410,8 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
3906
4410
|
return EXIT_INCOMPLETE;
|
|
3907
4411
|
}
|
|
3908
4412
|
if (!response.ok) {
|
|
3909
|
-
const
|
|
3910
|
-
process.stderr.write(`${
|
|
4413
|
+
const refusal2 = describeRefusal(response.status, await response.text());
|
|
4414
|
+
process.stderr.write(`${refusal2.planLimit ? yellow("plan limit:") : red("push failed:")} ${refusal2.text}
|
|
3911
4415
|
`);
|
|
3912
4416
|
return EXIT_INCOMPLETE;
|
|
3913
4417
|
}
|
|
@@ -3956,7 +4460,7 @@ function describeSurface(subject, previous) {
|
|
|
3956
4460
|
return lines;
|
|
3957
4461
|
}
|
|
3958
4462
|
function describe(change2) {
|
|
3959
|
-
const head = ` ${change2.severity === "high" ? red("\u25CF") : change2.severity === "medium" ? yellow("\u25CF") : dim("\u25CF")} ${change2.member ? `${bold(change2.member)}: ` : ""}${change2.summary} ${dim(change2.kind)}`;
|
|
4463
|
+
const head = ` ${change2.severity === "high" ? red("\u25CF") : change2.severity === "medium" ? yellow("\u25CF") : dim("\u25CF")} ${change2.member ? `${bold(visibleControls(change2.member))}: ` : ""}${visibleControls(change2.summary)} ${dim(change2.kind)}`;
|
|
3960
4464
|
if (change2.kind !== "tool.description.changed" && change2.kind !== "server.instructions.changed") return head;
|
|
3961
4465
|
const before = typeof change2.before === "string" ? `
|
|
3962
4466
|
${red(`- ${truncate(change2.before, 220)}`)}` : "";
|
|
@@ -3977,7 +4481,8 @@ async function runReview(options) {
|
|
|
3977
4481
|
* run would re-pin whatever had been published since, with nothing to compare it against.
|
|
3978
4482
|
*/
|
|
3979
4483
|
previous: committed,
|
|
3980
|
-
provenance: options.provenance
|
|
4484
|
+
provenance: options.provenance,
|
|
4485
|
+
userConfigs: options.userConfigs
|
|
3981
4486
|
});
|
|
3982
4487
|
const changes = diffLockfiles(committed, result.lock);
|
|
3983
4488
|
if (changes.length === 0) {
|
|
@@ -4008,7 +4513,7 @@ async function runReview(options) {
|
|
|
4008
4513
|
const context = describeSurface(result.lock.subjects[serverName], committed.subjects[serverName]);
|
|
4009
4514
|
process.stdout.write(
|
|
4010
4515
|
`
|
|
4011
|
-
${bold(serverName)}
|
|
4516
|
+
${bold(visibleControls(serverName))}
|
|
4012
4517
|
${serverChanges.map(describe).join("\n")}
|
|
4013
4518
|
${context.length > 0 ? `${context.join("\n")}
|
|
4014
4519
|
` : ""}`
|
|
@@ -4065,6 +4570,7 @@ ${bold("Options")}
|
|
|
4065
4570
|
--timeout <ms> per-server timeout (default: ${DEFAULT_TIMEOUT_MS2})
|
|
4066
4571
|
--allow-unreachable a server that cannot be reached warns instead of failing
|
|
4067
4572
|
--no-provenance do not look up what each stdio server runs (air-gapped runs)
|
|
4573
|
+
--user-configs also pin servers from your own configs (~/.claude.json, Claude Desktop, ...)
|
|
4068
4574
|
--json machine-readable output (check)
|
|
4069
4575
|
--sarif SARIF 2.1.0 output (check)
|
|
4070
4576
|
--sarif-steering also emit steering passages as SARIF notes (off: an alert is a gate)
|
|
@@ -4095,6 +4601,7 @@ async function main() {
|
|
|
4095
4601
|
timeout: { type: "string" },
|
|
4096
4602
|
"allow-unreachable": { type: "boolean", default: false },
|
|
4097
4603
|
"no-provenance": { type: "boolean", default: false },
|
|
4604
|
+
"user-configs": { type: "boolean", default: false },
|
|
4098
4605
|
json: { type: "boolean", default: false },
|
|
4099
4606
|
sarif: { type: "boolean", default: false },
|
|
4100
4607
|
"sarif-steering": { type: "boolean", default: false },
|
|
@@ -4131,17 +4638,18 @@ async function main() {
|
|
|
4131
4638
|
`);
|
|
4132
4639
|
return EXIT_INCOMPLETE;
|
|
4133
4640
|
}
|
|
4134
|
-
const projectRoot =
|
|
4641
|
+
const projectRoot = resolve5(values.cwd ?? process.cwd());
|
|
4135
4642
|
const options = {
|
|
4136
4643
|
projectRoot,
|
|
4137
|
-
lockPath:
|
|
4644
|
+
lockPath: resolve5(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
|
|
4138
4645
|
configFiles: values.config ?? [],
|
|
4139
4646
|
timeoutMs,
|
|
4140
4647
|
allowUnreachable: values["allow-unreachable"],
|
|
4141
4648
|
format: values.sarif ? "sarif" : values.json ? "json" : "human",
|
|
4142
4649
|
sarifSteering: values["sarif-steering"] === true,
|
|
4143
4650
|
comment: values.comment,
|
|
4144
|
-
provenance: values["no-provenance"] !== true
|
|
4651
|
+
provenance: values["no-provenance"] !== true,
|
|
4652
|
+
userConfigs: values["user-configs"] === true
|
|
4145
4653
|
};
|
|
4146
4654
|
switch (command) {
|
|
4147
4655
|
case "init":
|
|
@@ -4165,9 +4673,9 @@ ${dim("Run `nulladrift --help`.")}
|
|
|
4165
4673
|
return EXIT_INCOMPLETE;
|
|
4166
4674
|
}
|
|
4167
4675
|
}
|
|
4168
|
-
main().then((
|
|
4169
|
-
process.exitCode =
|
|
4170
|
-
setTimeout(() => process.exit(
|
|
4676
|
+
main().then((code2) => {
|
|
4677
|
+
process.exitCode = code2;
|
|
4678
|
+
setTimeout(() => process.exit(code2), 2e3).unref();
|
|
4171
4679
|
}).catch((error) => {
|
|
4172
4680
|
const message = error instanceof LockfileError ? error.message : error.stack ?? String(error);
|
|
4173
4681
|
process.stderr.write(`${red("nulladrift failed:")} ${message}
|