nulladrift 0.8.0 → 0.10.0
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 +14 -6
- package/dist/index.js +437 -82
- 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 resolve7 } from "path";
|
|
6
6
|
|
|
7
7
|
// ../core/src/changes.ts
|
|
8
8
|
var CHANGE_KINDS = [
|
|
@@ -693,7 +693,6 @@ var RULES = [
|
|
|
693
693
|
// execution, and `country_code`, `status_code` and `zip_code` are all waiting behind it.
|
|
694
694
|
{ kind: "code-eval", severity: "critical", name: /(^|_)(eval|evaluate|run_code|exec_code|interpret|compile)(_|$)/, arg: /^code$|(^|_)(source_code|code_to_run|js_code|python_code|expression|program|snippet)(_|$)/ },
|
|
695
695
|
{ kind: "credential-access", severity: "critical", name: /(^|_)(secret|secrets|credential|credentials|token|keychain|vault|password)(_|$)/, arg: /(^|_)(secret|credential|password|private_key|api_key|access_token)(_|$)/ },
|
|
696
|
-
{ kind: "file-write", severity: "high", name: /(^|_)(write|create_file|put_file|save|delete|remove|unlink|rename|move|copy|chmod|mkdir|rmdir|edit)(_|$)/, arg: /(^|_)(contents|content|data|destination|dest_path|target_path)(_|$)/ },
|
|
697
696
|
{ kind: "network-egress", severity: "high", name: /(^|_)(fetch|request|http|curl|download|upload|post|webhook|navigate|browse|send)(_|$)/, arg: /(^|_)(url|uri|endpoint|host|hostname|webhook|callback)(_|$)/ },
|
|
698
697
|
// Narrowed to things that are actually SQL-shaped. `query`, `select` and `update` on their
|
|
699
698
|
// own matched `simulate-research-query`, `browser_select_option` and `trigger-resource-update`,
|
|
@@ -702,8 +701,29 @@ var RULES = [
|
|
|
702
701
|
{ kind: "privilege", severity: "high", name: /(^|_)(sudo|root|admin|grant|revoke|permission|permissions|acl|policy)(_|$)/, arg: /(^|_)(role|scope|scopes|permission|permissions|privilege)(_|$)/ },
|
|
703
702
|
{ kind: "agent-control", severity: "high", name: /(^|_)(prompt|system_prompt|instruction|instructions|memory|context|persona)(_|$)/, arg: /(^|_)(system_prompt|instruction|instructions|persona)(_|$)/ },
|
|
704
703
|
{ kind: "env-access", severity: "medium", name: /(^|_)(env|environment|getenv|setenv|config|settings)(_|$)/, arg: /(^|_)(env|environment|env_var)(_|$)/ },
|
|
705
|
-
|
|
704
|
+
// `read`, `open` and `load` are not here; see `fileRead` below.
|
|
705
|
+
{ kind: "file-read", severity: "low", name: /(^|_)(read_file|cat|list_directory|ls|glob|search_files)(_|$)/, arg: /(^|_)(path|file|filename|filepath|directory|dir)(_|$)/ }
|
|
706
706
|
];
|
|
707
|
+
var FILE_ONLY_VERBS = /(^|_)(write|create_file|put_file|unlink|chmod|chown|mkdir|rmdir|truncate)(_|$)/;
|
|
708
|
+
var CHANGING_VERBS = /(^|_)(create|save|delete|remove|rename|move|copy|edit|append|put|overwrite|replace|patch)(_|$)/;
|
|
709
|
+
var FILE_NOUNS = /(^|_)(file|files|filename|dir|dirs|directory|directories|folder|folders|path|paths)(_|$)/;
|
|
710
|
+
var PATH_ARGS = /^(path|paths|file|files|filename|filepath|file_path|directory|dir|folder|source_path)$|(^|_)(path|filepath|filename)$/;
|
|
711
|
+
var DESTINATION_ARGS = /(^|_)(destination|dest|dest_path|target_path|output_path|out_path)(_|$)/;
|
|
712
|
+
var CONTENT_ARGS = /(^|_)(contents|content|data|text|body)$/;
|
|
713
|
+
function fileWrite(name, args) {
|
|
714
|
+
if (FILE_ONLY_VERBS.test(name)) return "name";
|
|
715
|
+
const path = args.find(([, normalized]) => PATH_ARGS.test(normalized));
|
|
716
|
+
if (CHANGING_VERBS.test(name) && (FILE_NOUNS.test(name) || path)) return "name";
|
|
717
|
+
const destination = args.find(([, normalized]) => DESTINATION_ARGS.test(normalized));
|
|
718
|
+
if (destination) return `arg:${destination[0]}`;
|
|
719
|
+
const content = args.find(([, normalized]) => CONTENT_ARGS.test(normalized));
|
|
720
|
+
if (content && path) return `arg:${content[0]}`;
|
|
721
|
+
return void 0;
|
|
722
|
+
}
|
|
723
|
+
var READING_VERBS = /(^|_)(read|open|load)(_|$)/;
|
|
724
|
+
function fileRead(name) {
|
|
725
|
+
return READING_VERBS.test(name) && FILE_NOUNS.test(name);
|
|
726
|
+
}
|
|
707
727
|
var CONFUSABLES = {
|
|
708
728
|
"\u0430": "a",
|
|
709
729
|
"\u0435": "e",
|
|
@@ -758,6 +778,9 @@ function toolCapabilities(tool2) {
|
|
|
758
778
|
const hit = rule.arg ? args.find(([, normalized]) => rule.arg?.test(normalized)) : void 0;
|
|
759
779
|
if (hit) found.set(rule.kind, { kind: rule.kind, severity: rule.severity, evidence: `arg:${hit[0]}` });
|
|
760
780
|
}
|
|
781
|
+
if (!found.has("file-read") && fileRead(name)) found.set("file-read", { kind: "file-read", severity: "low", evidence: "name" });
|
|
782
|
+
const writes = fileWrite(name, args);
|
|
783
|
+
if (writes) found.set("file-write", { kind: "file-write", severity: "high", evidence: writes });
|
|
761
784
|
return [...found.values()].sort(
|
|
762
785
|
(a, b) => CAPABILITY_SEVERITIES.indexOf(a.severity) - CAPABILITY_SEVERITIES.indexOf(b.severity) || a.kind.localeCompare(b.kind)
|
|
763
786
|
);
|
|
@@ -1113,7 +1136,7 @@ function compareProvenance(name, before, after) {
|
|
|
1113
1136
|
return [change("server.artifact.changed", name, `${what}${unexplained}`, { before: was, after: now })];
|
|
1114
1137
|
}
|
|
1115
1138
|
function orderless(entry) {
|
|
1116
|
-
const { kind: _kind, source: _source, digest: _digest, provenance: _provenance, tools, resources, resourceTemplates, prompts, ...rest } = entry;
|
|
1139
|
+
const { kind: _kind, source: _source, digest: _digest, provenance: _provenance, coverage: _coverage, tools, resources, resourceTemplates, prompts, ...rest } = entry;
|
|
1117
1140
|
const digests = (members) => (members ?? []).map((member) => member.digest).sort();
|
|
1118
1141
|
return stableKey({
|
|
1119
1142
|
...rest,
|
|
@@ -1386,29 +1409,29 @@ function surfaceText(subject) {
|
|
|
1386
1409
|
};
|
|
1387
1410
|
push("instructions", subject?.instructions);
|
|
1388
1411
|
for (const tool2 of objectsIn(subject?.tools)) {
|
|
1389
|
-
const
|
|
1390
|
-
push(`${
|
|
1391
|
-
push(`${
|
|
1392
|
-
schemaText(tool2.inputSchema, `${
|
|
1393
|
-
schemaText(tool2.outputSchema, `${
|
|
1412
|
+
const where2 = stringOr(tool2.name) ?? "?";
|
|
1413
|
+
push(`${where2}.title`, tool2.title);
|
|
1414
|
+
push(`${where2}.description`, tool2.description);
|
|
1415
|
+
schemaText(tool2.inputSchema, `${where2}.inputSchema`, out);
|
|
1416
|
+
schemaText(tool2.outputSchema, `${where2}.outputSchema`, out);
|
|
1394
1417
|
}
|
|
1395
1418
|
for (const prompt2 of objectsIn(subject?.prompts)) {
|
|
1396
|
-
const
|
|
1397
|
-
push(`prompt:${
|
|
1398
|
-
push(`prompt:${
|
|
1419
|
+
const where2 = stringOr(prompt2.name) ?? "?";
|
|
1420
|
+
push(`prompt:${where2}.title`, prompt2.title);
|
|
1421
|
+
push(`prompt:${where2}.description`, prompt2.description);
|
|
1399
1422
|
for (const argument of objectsIn(prompt2.arguments)) {
|
|
1400
|
-
push(`prompt:${
|
|
1423
|
+
push(`prompt:${where2}.${stringOr(argument.name) ?? "?"}`, argument.description);
|
|
1401
1424
|
}
|
|
1402
1425
|
}
|
|
1403
1426
|
for (const resource2 of objectsIn(subject?.resources)) {
|
|
1404
|
-
const
|
|
1405
|
-
push(`resource:${
|
|
1406
|
-
push(`resource:${
|
|
1427
|
+
const where2 = stringOr(resource2.name) ?? stringOr(resource2.uri) ?? "?";
|
|
1428
|
+
push(`resource:${where2}.title`, resource2.title);
|
|
1429
|
+
push(`resource:${where2}.description`, resource2.description);
|
|
1407
1430
|
}
|
|
1408
1431
|
for (const template of objectsIn(subject?.resourceTemplates)) {
|
|
1409
|
-
const
|
|
1410
|
-
push(`template:${
|
|
1411
|
-
push(`template:${
|
|
1432
|
+
const where2 = stringOr(template.name) ?? stringOr(template.uriTemplate) ?? "?";
|
|
1433
|
+
push(`template:${where2}.title`, template.title);
|
|
1434
|
+
push(`template:${where2}.description`, template.description);
|
|
1412
1435
|
}
|
|
1413
1436
|
return out;
|
|
1414
1437
|
}
|
|
@@ -1785,8 +1808,8 @@ function anchorCwd(server2, projectRoot) {
|
|
|
1785
1808
|
return { ...server2, transport: { ...transport2, cwd: resolve2(projectRoot, transport2.cwd) } };
|
|
1786
1809
|
}
|
|
1787
1810
|
function describeSearch(searched, filesRead) {
|
|
1788
|
-
const
|
|
1789
|
-
const lines = searched.map((path) => ` ${(
|
|
1811
|
+
const read2 = new Set(filesRead);
|
|
1812
|
+
const lines = searched.map((path) => ` ${(read2.has(path) ? "read" : "absent").padEnd(6)} ${path}`);
|
|
1790
1813
|
return lines.join("\n");
|
|
1791
1814
|
}
|
|
1792
1815
|
async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
@@ -1805,18 +1828,18 @@ async function discoverServers(projectRoot, extraFiles = [], options = {}) {
|
|
|
1805
1828
|
const problems = [];
|
|
1806
1829
|
const requested = new Set(files.filter((file) => file.client === "generic").map((file) => file.path));
|
|
1807
1830
|
for (const file of files) {
|
|
1808
|
-
const
|
|
1809
|
-
if (!
|
|
1831
|
+
const read2 = await readJsonIfPresent(file.path);
|
|
1832
|
+
if (!read2.present) {
|
|
1810
1833
|
if (requested.has(file.path)) {
|
|
1811
1834
|
problems.push({ file: portablePath(file.path, projectRoot), reason: "no such file; it was named with --config" });
|
|
1812
1835
|
}
|
|
1813
1836
|
continue;
|
|
1814
1837
|
}
|
|
1815
|
-
if (!
|
|
1816
|
-
problems.push({ file: portablePath(file.path, projectRoot), reason:
|
|
1838
|
+
if (!read2.ok) {
|
|
1839
|
+
problems.push({ file: portablePath(file.path, projectRoot), reason: read2.reason });
|
|
1817
1840
|
continue;
|
|
1818
1841
|
}
|
|
1819
|
-
const raw =
|
|
1842
|
+
const raw = read2.value;
|
|
1820
1843
|
filesRead.push(file.path);
|
|
1821
1844
|
const source = { client: file.client, file: portablePath(file.path, projectRoot) };
|
|
1822
1845
|
let mapKey = CLIENT_MAP_KEY[file.client];
|
|
@@ -1996,7 +2019,7 @@ function buildLockedServer(server2, surface, policy) {
|
|
|
1996
2019
|
resourceTemplates: resourceTemplates.map((template) => template.digest),
|
|
1997
2020
|
prompts: prompts.map((prompt2) => prompt2.digest)
|
|
1998
2021
|
};
|
|
1999
|
-
return { kind: "mcp-server", ...entry, digest: digest(toJson(covered)) };
|
|
2022
|
+
return { kind: "mcp-server", ...entry, ...surface.coverage ? { coverage: surface.coverage } : {}, digest: digest(toJson(covered)) };
|
|
2000
2023
|
}
|
|
2001
2024
|
|
|
2002
2025
|
// src/lock/provenance.ts
|
|
@@ -2005,7 +2028,7 @@ import { readFile as readFile3 } from "fs/promises";
|
|
|
2005
2028
|
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
2006
2029
|
|
|
2007
2030
|
// src/lib/version.ts
|
|
2008
|
-
var VERSION = "0.
|
|
2031
|
+
var VERSION = "0.10.0";
|
|
2009
2032
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
2010
2033
|
|
|
2011
2034
|
// src/lock/provenance.ts
|
|
@@ -2349,9 +2372,9 @@ function launchPinned(transport2, provenance2) {
|
|
|
2349
2372
|
}
|
|
2350
2373
|
function imageLocation(name) {
|
|
2351
2374
|
const parts = name.split("/");
|
|
2352
|
-
const
|
|
2353
|
-
const hasHost = parts.length > 1 && (
|
|
2354
|
-
let host = hasHost ?
|
|
2375
|
+
const first2 = parts[0];
|
|
2376
|
+
const hasHost = parts.length > 1 && (first2.includes(".") || first2.includes(":") || first2 === "localhost");
|
|
2377
|
+
let host = hasHost ? first2 : "registry-1.docker.io";
|
|
2355
2378
|
if (host === "docker.io" || host === "index.docker.io") host = "registry-1.docker.io";
|
|
2356
2379
|
let repository = hasHost ? parts.slice(1).join("/") : name;
|
|
2357
2380
|
if (host === "registry-1.docker.io" && !repository.includes("/")) repository = `library/${repository}`;
|
|
@@ -2846,6 +2869,61 @@ function isAuthFailure(error) {
|
|
|
2846
2869
|
return /\b(401|403)\b|unauthorized|forbidden|invalid or missing[^\n]{0,80}?token|authentication required|invalid_client|dynamic client registration/.test(text);
|
|
2847
2870
|
}
|
|
2848
2871
|
|
|
2872
|
+
// src/mcp/network.ts
|
|
2873
|
+
var MAX_DEPTH2 = 8;
|
|
2874
|
+
function networkError(error) {
|
|
2875
|
+
const pending = [{ value: error, depth: 0 }];
|
|
2876
|
+
while (pending.length > 0) {
|
|
2877
|
+
const { value, depth } = pending.shift();
|
|
2878
|
+
if (value === null || typeof value !== "object" || depth > MAX_DEPTH2) continue;
|
|
2879
|
+
const candidate = value;
|
|
2880
|
+
if (typeof candidate.code === "string" && /^(E[A-Z]+|UND_ERR_[A-Z_]+|CERT_[A-Z_]+|ERR_TLS_[A-Z_]+|UNABLE_TO_[A-Z_]+|[A-Z_]*SELF_SIGNED[A-Z_]*)$/.test(candidate.code)) {
|
|
2881
|
+
return {
|
|
2882
|
+
code: candidate.code,
|
|
2883
|
+
address: typeof candidate.address === "string" ? candidate.address : void 0,
|
|
2884
|
+
port: typeof candidate.port === "number" ? candidate.port : void 0,
|
|
2885
|
+
hostname: typeof candidate.hostname === "string" ? candidate.hostname : void 0
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
pending.push({ value: candidate.cause, depth: depth + 1 });
|
|
2889
|
+
if (Array.isArray(candidate.errors)) for (const inner of candidate.errors.slice(0, 8)) pending.push({ value: inner, depth: depth + 1 });
|
|
2890
|
+
}
|
|
2891
|
+
return void 0;
|
|
2892
|
+
}
|
|
2893
|
+
function where(found) {
|
|
2894
|
+
const host = found.hostname ?? found.address;
|
|
2895
|
+
if (!host) return "";
|
|
2896
|
+
const shown = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
2897
|
+
return found.port !== void 0 ? `${shown}:${found.port}` : shown;
|
|
2898
|
+
}
|
|
2899
|
+
function describeNetworkFailure(error) {
|
|
2900
|
+
const found = networkError(error);
|
|
2901
|
+
if (!found) return void 0;
|
|
2902
|
+
const at = where(found);
|
|
2903
|
+
switch (found.code) {
|
|
2904
|
+
case "ECONNREFUSED":
|
|
2905
|
+
return `connection refused${at ? ` by ${at}` : ""}: nothing is listening there. Is the server running, and is the port right?`;
|
|
2906
|
+
case "ENOTFOUND":
|
|
2907
|
+
return `${at ? `the host name ${found.hostname ?? at}` : "the host name"} does not resolve. Check the URL for a typo, or the DNS this machine uses.`;
|
|
2908
|
+
case "EAI_AGAIN":
|
|
2909
|
+
return `looking up ${found.hostname ?? "the host name"} failed for now (EAI_AGAIN): DNS did not answer. Try again, or check this machine's network.`;
|
|
2910
|
+
case "ETIMEDOUT":
|
|
2911
|
+
case "UND_ERR_CONNECT_TIMEOUT":
|
|
2912
|
+
return `connecting${at ? ` to ${at}` : ""} timed out. A firewall may be dropping the traffic, or the host is down.`;
|
|
2913
|
+
case "ECONNRESET":
|
|
2914
|
+
case "UND_ERR_SOCKET":
|
|
2915
|
+
return `the connection${at ? ` to ${at}` : ""} was dropped before the server answered.`;
|
|
2916
|
+
case "EHOSTUNREACH":
|
|
2917
|
+
case "ENETUNREACH":
|
|
2918
|
+
return `there is no route to ${at || "the host"} from this machine (${found.code}).`;
|
|
2919
|
+
default:
|
|
2920
|
+
if (/CERT|TLS|SELF_SIGNED|UNABLE_TO/.test(found.code)) {
|
|
2921
|
+
return `the server's TLS certificate was not accepted (${found.code}). Fix the certificate, or set NODE_EXTRA_CA_CERTS to the CA that signed it.`;
|
|
2922
|
+
}
|
|
2923
|
+
return `${found.code}${at ? ` at ${at}` : ""}`;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2849
2927
|
// src/mcp/connect.ts
|
|
2850
2928
|
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
2851
2929
|
var STDERR_KEEP_BYTES = 2e3;
|
|
@@ -3023,6 +3101,16 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3023
3101
|
}
|
|
3024
3102
|
);
|
|
3025
3103
|
refuseUnsendable(server2);
|
|
3104
|
+
const changes = /* @__PURE__ */ new Set();
|
|
3105
|
+
for (const [list, method] of [
|
|
3106
|
+
["tools", "notifications/tools/list_changed"],
|
|
3107
|
+
["resources", "notifications/resources/list_changed"],
|
|
3108
|
+
["prompts", "notifications/prompts/list_changed"]
|
|
3109
|
+
]) {
|
|
3110
|
+
client.setNotificationHandler(method, () => {
|
|
3111
|
+
changes.add(list);
|
|
3112
|
+
});
|
|
3113
|
+
}
|
|
3026
3114
|
let transport2;
|
|
3027
3115
|
const guard = new SurfaceGuard(() => {
|
|
3028
3116
|
void transport2?.close().catch(() => {
|
|
@@ -3041,9 +3129,10 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3041
3129
|
});
|
|
3042
3130
|
if (guard.refusal !== void 0) throw new UnreachableServerError(server2.name, guard.refusal, error);
|
|
3043
3131
|
const detail = stderrBuffer.trim();
|
|
3132
|
+
const network = describeNetworkFailure(error);
|
|
3044
3133
|
throw new UnreachableServerError(
|
|
3045
3134
|
server2.name,
|
|
3046
|
-
`${error.message}${detail ? `
|
|
3135
|
+
`${error.message}${network ? ` (${network})` : ""}${detail ? `
|
|
3047
3136
|
server stderr: ${diagnosticLines(detail).join("\n ")}` : ""}`,
|
|
3048
3137
|
error
|
|
3049
3138
|
);
|
|
@@ -3052,6 +3141,8 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS2, options = {}) {
|
|
|
3052
3141
|
client,
|
|
3053
3142
|
stderr: () => stderrBuffer,
|
|
3054
3143
|
refused: () => guard.refusal,
|
|
3144
|
+
watchChanges: () => changes.clear(),
|
|
3145
|
+
changed: () => [...changes].sort(),
|
|
3055
3146
|
close: async () => {
|
|
3056
3147
|
await client.close().catch(() => {
|
|
3057
3148
|
});
|
|
@@ -3071,11 +3162,11 @@ function describeValidationIssues(message) {
|
|
|
3071
3162
|
return void 0;
|
|
3072
3163
|
}
|
|
3073
3164
|
if (!Array.isArray(issues) || issues.length === 0) return void 0;
|
|
3074
|
-
const
|
|
3165
|
+
const where2 = (issue) => (issue.path ?? []).map((part) => typeof part === "number" ? `[${part}]` : `.${String(part)}`).join("").replace(/^\./, "");
|
|
3075
3166
|
const byMessage = /* @__PURE__ */ new Map();
|
|
3076
3167
|
for (const issue of issues) {
|
|
3077
3168
|
const text = issue.message ?? "did not validate";
|
|
3078
|
-
byMessage.set(text, [...byMessage.get(text) ?? [],
|
|
3169
|
+
byMessage.set(text, [...byMessage.get(text) ?? [], where2(issue)]);
|
|
3079
3170
|
}
|
|
3080
3171
|
const lines = [...byMessage].slice(0, 3).map(([text, paths]) => {
|
|
3081
3172
|
const rest = paths.length > 1 ? ` (and ${paths.length - 1} more like it)` : "";
|
|
@@ -3104,11 +3195,11 @@ async function listAllTools(client, timeoutMs) {
|
|
|
3104
3195
|
const result = await client.request({ method: "tools/list", params: cursor === void 0 ? {} : { cursor } }, { timeout: timeoutMs });
|
|
3105
3196
|
for (const tool2 of result.tools) tools.push(tool2);
|
|
3106
3197
|
cursor = result.nextCursor;
|
|
3107
|
-
if (cursor === void 0) return tools;
|
|
3108
|
-
if (cursors.has(cursor))
|
|
3198
|
+
if (cursor === void 0) return { tools };
|
|
3199
|
+
if (cursors.has(cursor)) return { tools, partial: `tools/list repeated a page cursor after ${page + 1} page(s), so its listing never ends; the pages before the repeat were read` };
|
|
3109
3200
|
cursors.add(cursor);
|
|
3110
3201
|
}
|
|
3111
|
-
|
|
3202
|
+
return { tools, partial: `tools/list did not end within ${MAX_LIST_PAGES} pages; the first ${MAX_LIST_PAGES} were read` };
|
|
3112
3203
|
}
|
|
3113
3204
|
async function listOrEmpty(label, serverName, fetchList) {
|
|
3114
3205
|
try {
|
|
@@ -3160,7 +3251,7 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
|
3160
3251
|
}
|
|
3161
3252
|
connection = opened;
|
|
3162
3253
|
try {
|
|
3163
|
-
return await readSurface(opened
|
|
3254
|
+
return await readSurface(opened, server2, timeoutMs);
|
|
3164
3255
|
} catch (error) {
|
|
3165
3256
|
const refused = opened.refused();
|
|
3166
3257
|
if (refused !== void 0) throw new UnreachableServerError(server2.name, refused, error);
|
|
@@ -3176,10 +3267,31 @@ async function captureSurface(server2, timeoutMs = DEFAULT_TIMEOUT_MS2) {
|
|
|
3176
3267
|
clearTimeout(timer);
|
|
3177
3268
|
}
|
|
3178
3269
|
}
|
|
3179
|
-
|
|
3270
|
+
var LIST_PASSES = 2;
|
|
3271
|
+
async function readSurface(connection, server2, timeoutMs) {
|
|
3272
|
+
for (let pass = 1; ; pass += 1) {
|
|
3273
|
+
connection.watchChanges();
|
|
3274
|
+
const surface = await readLists(connection.client, server2, timeoutMs);
|
|
3275
|
+
const moved = connection.changed();
|
|
3276
|
+
if (moved.length === 0) return surface;
|
|
3277
|
+
if (pass >= LIST_PASSES) {
|
|
3278
|
+
const reasons = [
|
|
3279
|
+
...surface.coverage?.reasons ?? [],
|
|
3280
|
+
`the server said its ${moved.join(" and ")} changed while being read, on ${LIST_PASSES} passes running, so no read is known to be current`
|
|
3281
|
+
];
|
|
3282
|
+
return { ...surface, coverage: { complete: false, reasons } };
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
async function readLists(client, server2, timeoutMs) {
|
|
3180
3287
|
const capabilities = client.getServerCapabilities();
|
|
3288
|
+
let toolsPartial;
|
|
3181
3289
|
const [tools, resources, resourceTemplates, prompts] = await Promise.all([
|
|
3182
|
-
capabilities?.tools ? listOrEmpty("tools/list", server2.name, async () =>
|
|
3290
|
+
capabilities?.tools ? listOrEmpty("tools/list", server2.name, async () => {
|
|
3291
|
+
const listed = await listAllTools(client, timeoutMs);
|
|
3292
|
+
toolsPartial = listed.partial;
|
|
3293
|
+
return listed.tools;
|
|
3294
|
+
}) : [],
|
|
3183
3295
|
// Each list call is bounded by the server's timeout too. With none, the SDK's default
|
|
3184
3296
|
// applied per page (60s, up to 64 pages), so one slow server could hold a run for an hour.
|
|
3185
3297
|
capabilities?.resources ? listOrEmpty("resources/list", server2.name, async () => (await client.listResources(void 0, { ...FRESH, timeout: timeoutMs })).resources) : [],
|
|
@@ -3195,7 +3307,8 @@ async function readSurface(client, server2, timeoutMs) {
|
|
|
3195
3307
|
tools,
|
|
3196
3308
|
resources,
|
|
3197
3309
|
resourceTemplates,
|
|
3198
|
-
prompts
|
|
3310
|
+
prompts,
|
|
3311
|
+
...toolsPartial ? { coverage: { complete: false, reasons: [toolsPartial] } } : {}
|
|
3199
3312
|
};
|
|
3200
3313
|
}
|
|
3201
3314
|
|
|
@@ -3290,7 +3403,8 @@ async function captureAll(options) {
|
|
|
3290
3403
|
unverified: unverified.sort(),
|
|
3291
3404
|
displaced,
|
|
3292
3405
|
unaudited,
|
|
3293
|
-
conflicted: discovery.conflicts.map((conflict) => conflict.name)
|
|
3406
|
+
conflicted: discovery.conflicts.map((conflict) => conflict.name),
|
|
3407
|
+
partial: Object.entries(subjects).filter(([, entry]) => entry.coverage !== void 0).map(([server2, entry]) => ({ server: server2, reasons: entry.coverage.reasons })).sort((a, b) => a.server.localeCompare(b.server))
|
|
3294
3408
|
};
|
|
3295
3409
|
}
|
|
3296
3410
|
function acknowledged(committed, name, now) {
|
|
@@ -3465,6 +3579,7 @@ var server = z2.object({
|
|
|
3465
3579
|
}),
|
|
3466
3580
|
transport,
|
|
3467
3581
|
provenance: provenance.optional(),
|
|
3582
|
+
coverage: z2.object({ complete: z2.literal(false), reasons: z2.array(z2.string()) }).optional(),
|
|
3468
3583
|
protocol: z2.object({
|
|
3469
3584
|
era: z2.enum(["modern", "legacy"]),
|
|
3470
3585
|
version: z2.string(),
|
|
@@ -3496,6 +3611,7 @@ var lockfileSchema = z2.object({
|
|
|
3496
3611
|
policy: z2.object({
|
|
3497
3612
|
ignoreMetaPrefixes: z2.array(z2.string()).optional(),
|
|
3498
3613
|
allowUnreachable: z2.boolean().optional(),
|
|
3614
|
+
allowPartial: z2.boolean().optional(),
|
|
3499
3615
|
/*
|
|
3500
3616
|
* Validated against the real list rather than accepted as free strings: a policy with
|
|
3501
3617
|
* `process_exec` in it would otherwise parse, forbid nothing, and read in the diff of
|
|
@@ -3517,7 +3633,7 @@ var lockfileSchema = z2.object({
|
|
|
3517
3633
|
var DEFAULT_LOCK_FILENAME = "mcp.lock";
|
|
3518
3634
|
var KEY_ORDER = {
|
|
3519
3635
|
root: ["lockfileVersion", "generatedBy", "policy", "subjects", "unaudited"],
|
|
3520
|
-
policy: ["ignoreMetaPrefixes", "allowUnreachable", "deniedCapabilities"],
|
|
3636
|
+
policy: ["ignoreMetaPrefixes", "allowUnreachable", "allowPartial", "deniedCapabilities"],
|
|
3521
3637
|
server: ["kind", "source", "transport", "protocol", "serverInfo", "capabilities", "instructions", "tools", "resources", "resourceTemplates", "prompts", "digest"],
|
|
3522
3638
|
source: ["client", "file", "scope"],
|
|
3523
3639
|
transport: ["type", "command", "args", "envKeys", "cwd", "url", "headerKeys"],
|
|
@@ -3637,9 +3753,9 @@ function parseLockfile(text, path) {
|
|
|
3637
3753
|
}
|
|
3638
3754
|
const parsed = lockfileSchema.safeParse(raw);
|
|
3639
3755
|
if (!parsed.success) {
|
|
3640
|
-
const
|
|
3641
|
-
const
|
|
3642
|
-
throw new LockfileError(`${path} is not a valid lockfile${
|
|
3756
|
+
const first2 = parsed.error.issues[0];
|
|
3757
|
+
const where2 = first2 && first2.path.length > 0 ? ` at ${first2.path.join(".")}` : "";
|
|
3758
|
+
throw new LockfileError(`${path} is not a valid lockfile${where2}: ${first2?.message ?? "unknown error"}`);
|
|
3643
3759
|
}
|
|
3644
3760
|
return parsed.data;
|
|
3645
3761
|
}
|
|
@@ -3708,8 +3824,8 @@ function renderTextChange(before, after) {
|
|
|
3708
3824
|
return lines;
|
|
3709
3825
|
}
|
|
3710
3826
|
function renderChange(change2) {
|
|
3711
|
-
const
|
|
3712
|
-
const lines = [` ${MARK[change2.severity](change2.severity.padEnd(6))} ${bold(
|
|
3827
|
+
const where2 = visibleControls(change2.member ? `${change2.server} \u203A ${change2.member}` : change2.server);
|
|
3828
|
+
const lines = [` ${MARK[change2.severity](change2.severity.padEnd(6))} ${bold(where2)} ${dim(change2.kind)}`, ` ${visibleControls(change2.summary)}`];
|
|
3713
3829
|
if (change2.kind === "tool.description.changed" || change2.kind === "server.instructions.changed") {
|
|
3714
3830
|
lines.push(...renderTextChange(change2.before, change2.after));
|
|
3715
3831
|
}
|
|
@@ -3789,8 +3905,17 @@ function renderHumanReport(report) {
|
|
|
3789
3905
|
""
|
|
3790
3906
|
);
|
|
3791
3907
|
}
|
|
3908
|
+
const partial = report.partial ?? [];
|
|
3909
|
+
if (partial.length > 0) {
|
|
3910
|
+
lines.push(yellow(`Could not read ${partial.length} server(s) in full:`));
|
|
3911
|
+
for (const entry of partial) {
|
|
3912
|
+
lines.push(` ${bold(visibleControls(entry.server))}`);
|
|
3913
|
+
for (const reason of entry.reasons) lines.push(` ${visibleLines(reason, " ")}`);
|
|
3914
|
+
}
|
|
3915
|
+
lines.push(dim(" Compared as far as they were read. This fails the audit; --allow-partial makes it a warning."), "");
|
|
3916
|
+
}
|
|
3792
3917
|
lines.push(...renderSteering(report));
|
|
3793
|
-
if (report.changes.length === 0 && report.unreachable.length === 0 && (report.violations ?? []).length === 0) {
|
|
3918
|
+
if (report.changes.length === 0 && report.unreachable.length === 0 && (report.violations ?? []).length === 0 && partial.length === 0) {
|
|
3794
3919
|
lines.push(green(`\u2713 ${report.serversChecked} server(s) match ${report.lockPath}`));
|
|
3795
3920
|
return `${lines.join("\n")}
|
|
3796
3921
|
`;
|
|
@@ -3856,7 +3981,9 @@ function renderJsonReport(report, exitCode) {
|
|
|
3856
3981
|
/** Unlike steering, these DO decide the exit code. */
|
|
3857
3982
|
violations: (report.violations ?? []).length,
|
|
3858
3983
|
/** Answered, but what they run could not be established. Never part of the verdict. */
|
|
3859
|
-
unverified: (report.unverified ?? []).length
|
|
3984
|
+
unverified: (report.unverified ?? []).length,
|
|
3985
|
+
/** Read, but not in full. Part of the verdict (exit 2) unless --allow-partial. */
|
|
3986
|
+
partial: (report.partial ?? []).length
|
|
3860
3987
|
},
|
|
3861
3988
|
changes: report.changes.map((change2) => ({
|
|
3862
3989
|
kind: change2.kind,
|
|
@@ -3871,7 +3998,8 @@ function renderJsonReport(report, exitCode) {
|
|
|
3871
3998
|
/** Text that began addressing the model since the lock was approved. Reported, never gated. */
|
|
3872
3999
|
steering: report.steering ?? [],
|
|
3873
4000
|
violations: report.violations ?? [],
|
|
3874
|
-
unverified: report.unverified ?? []
|
|
4001
|
+
unverified: report.unverified ?? [],
|
|
4002
|
+
partial: report.partial ?? []
|
|
3875
4003
|
},
|
|
3876
4004
|
null,
|
|
3877
4005
|
2
|
|
@@ -3908,6 +4036,7 @@ var LEVEL = {
|
|
|
3908
4036
|
var DENIED_RULE = "policy.capability.denied";
|
|
3909
4037
|
var STEERING_RULE = "steering.passage.arrived";
|
|
3910
4038
|
var UNVERIFIED_RULE = "server.artifact.unverified";
|
|
4039
|
+
var PARTIAL_RULE = "server.surface.partial";
|
|
3911
4040
|
var RULE_HELP = {
|
|
3912
4041
|
"tool.capability.gained": "A tool gained a capability it did not declare before, derived from its name, its argument names and the shape of its schema. The severity is the capability's, not the schema change's: gaining a `command` argument is not the same finding as gaining an optional string.",
|
|
3913
4042
|
"tool.description.changed": "A tool description is injected into the model's context. A change here can carry instructions to the agent and should be read in full, not skimmed.",
|
|
@@ -3934,6 +4063,7 @@ function renderSarifReport(report, options = {}) {
|
|
|
3934
4063
|
const violations = report.violations ?? [];
|
|
3935
4064
|
const steering = options.steering ? report.steering ?? [] : [];
|
|
3936
4065
|
const unverified = report.unverified ?? [];
|
|
4066
|
+
const partial = report.partial ?? [];
|
|
3937
4067
|
const at = (name, qualified) => [
|
|
3938
4068
|
{
|
|
3939
4069
|
physicalLocation: { artifactLocation: { uri: sarifUri(report), uriBaseId: "%SRCROOT%" } },
|
|
@@ -3955,6 +4085,13 @@ function renderSarifReport(report, options = {}) {
|
|
|
3955
4085
|
fullDescription: { text: "A passage a model is shown started reading as an instruction since this lock was approved. A signal to read, not a verdict: legitimate servers trip the same shape. It does not affect the exit code." },
|
|
3956
4086
|
defaultConfiguration: { level: "note" }
|
|
3957
4087
|
}] : [],
|
|
4088
|
+
...partial.length > 0 ? [{
|
|
4089
|
+
id: PARTIAL_RULE,
|
|
4090
|
+
name: "ServerSurfacePartial",
|
|
4091
|
+
shortDescription: { text: "A server's surface could not be read in full" },
|
|
4092
|
+
fullDescription: { text: "The listing did not end within the page limit, or the server said it changed while being read on every pass. Compared as far as it was read; the audit did not finish." },
|
|
4093
|
+
defaultConfiguration: { level: "warning" }
|
|
4094
|
+
}] : [],
|
|
3958
4095
|
...unverified.length > 0 ? [{
|
|
3959
4096
|
id: UNVERIFIED_RULE,
|
|
3960
4097
|
name: "ServerArtifactUnverified",
|
|
@@ -4010,6 +4147,13 @@ function renderSarifReport(report, options = {}) {
|
|
|
4010
4147
|
partialFingerprints: { "mcpAuditChange/v1": `${server2}/${signal.field}/${signal.kind}` }
|
|
4011
4148
|
}))
|
|
4012
4149
|
),
|
|
4150
|
+
...partial.map((entry) => ({
|
|
4151
|
+
ruleId: PARTIAL_RULE,
|
|
4152
|
+
level: "warning",
|
|
4153
|
+
message: { text: `${entry.server}: could not be read in full. ${entry.reasons.join("; ")}` },
|
|
4154
|
+
locations: at(entry.server, entry.server),
|
|
4155
|
+
partialFingerprints: { "mcpAuditChange/v1": `${entry.server}/partial` }
|
|
4156
|
+
})),
|
|
4013
4157
|
...unverified.map((server2) => ({
|
|
4014
4158
|
ruleId: UNVERIFIED_RULE,
|
|
4015
4159
|
level: "note",
|
|
@@ -4043,12 +4187,13 @@ function code(text) {
|
|
|
4043
4187
|
return `${fence}${pad}${body}${pad}${fence}`;
|
|
4044
4188
|
}
|
|
4045
4189
|
function row(change2) {
|
|
4046
|
-
const
|
|
4047
|
-
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(
|
|
4190
|
+
const where2 = change2.member ? `${change2.server}/${change2.member}` : change2.server;
|
|
4191
|
+
return `| ${MARK2[change2.severity]} ${change2.severity} | ${code(where2)} | ${plain(change2.kind)} | ${plain(change2.summary)} |`;
|
|
4048
4192
|
}
|
|
4049
4193
|
function renderMarkdownReport(report, options = {}) {
|
|
4050
4194
|
const violations = report.violations ?? [];
|
|
4051
|
-
|
|
4195
|
+
const partial = report.partial ?? [];
|
|
4196
|
+
if (report.changes.length === 0 && report.unreachable.length === 0 && violations.length === 0 && partial.length === 0) return null;
|
|
4052
4197
|
const lines = [];
|
|
4053
4198
|
const high = report.changes.filter((change2) => change2.severity === "high").length;
|
|
4054
4199
|
if (report.changes.length === 0 && violations.length > 0) {
|
|
@@ -4116,6 +4261,18 @@ function renderMarkdownReport(report, options = {}) {
|
|
|
4116
4261
|
""
|
|
4117
4262
|
);
|
|
4118
4263
|
}
|
|
4264
|
+
if (partial.length > 0) {
|
|
4265
|
+
lines.push(
|
|
4266
|
+
`<details><summary>${partial.length} server${partial.length === 1 ? "" : "s"} could not be read in full</summary>`,
|
|
4267
|
+
"",
|
|
4268
|
+
"Compared as far as they were read. A clean comparison against part of a surface says nothing about the rest, so this fails the audit unless `--allow-partial` is set.",
|
|
4269
|
+
"",
|
|
4270
|
+
...partial.map((entry) => `- ${code(entry.server)}: ${plain(entry.reasons.join("; "))}`),
|
|
4271
|
+
"",
|
|
4272
|
+
"</details>",
|
|
4273
|
+
""
|
|
4274
|
+
);
|
|
4275
|
+
}
|
|
4119
4276
|
const unverified = report.unverified ?? [];
|
|
4120
4277
|
if (unverified.length > 0) {
|
|
4121
4278
|
lines.push(
|
|
@@ -4308,6 +4465,7 @@ async function buildReport(options) {
|
|
|
4308
4465
|
`);
|
|
4309
4466
|
const changes = compareWithLock(committed, result);
|
|
4310
4467
|
const allowUnreachable = options.allowUnreachable || committed.policy?.allowUnreachable === true;
|
|
4468
|
+
const allowPartial = options.allowPartial === true || committed.policy?.allowPartial === true;
|
|
4311
4469
|
const report = {
|
|
4312
4470
|
changes,
|
|
4313
4471
|
/*
|
|
@@ -4324,6 +4482,7 @@ async function buildReport(options) {
|
|
|
4324
4482
|
unreachable: result.unreachable,
|
|
4325
4483
|
// Reported beside the verdict and never part of it; see `AuditReport.unverified`.
|
|
4326
4484
|
unverified: result.unverified,
|
|
4485
|
+
partial: result.partial,
|
|
4327
4486
|
serversChecked: Object.keys(result.lock.subjects).length,
|
|
4328
4487
|
lockPath: options.lockPath,
|
|
4329
4488
|
projectRoot: options.projectRoot
|
|
@@ -4337,7 +4496,11 @@ async function buildReport(options) {
|
|
|
4337
4496
|
* able to make it pass: policy is the thing acceptance cannot overrule.
|
|
4338
4497
|
*/
|
|
4339
4498
|
driftCount: changes.length + (report.violations?.length ?? 0),
|
|
4340
|
-
|
|
4499
|
+
/*
|
|
4500
|
+
* A surface only partly read is neither drift nor clean: the audit did not finish, which is
|
|
4501
|
+
* what an unreachable server already means, for the same reason.
|
|
4502
|
+
*/
|
|
4503
|
+
incompleteCount: (allowUnreachable ? 0 : result.unreachable.length) + (allowPartial ? 0 : result.partial.length)
|
|
4341
4504
|
})
|
|
4342
4505
|
};
|
|
4343
4506
|
}
|
|
@@ -4559,6 +4722,10 @@ async function runInit(options) {
|
|
|
4559
4722
|
lines.push(` ${dim("A signal to read, not a verdict. It never fails a build.")}`);
|
|
4560
4723
|
}
|
|
4561
4724
|
}
|
|
4725
|
+
for (const partial of result.partial) {
|
|
4726
|
+
lines.push(` ${yellow("\u25D0")} ${bold(visibleControls(partial.server))} ${dim("pinned as far as it could be read")}`);
|
|
4727
|
+
for (const reason of partial.reasons) lines.push(` ${visibleLines(reason, " ")}`);
|
|
4728
|
+
}
|
|
4562
4729
|
for (const failure of result.unreachable) {
|
|
4563
4730
|
lines.push(` ${red("\u2717")} ${bold(visibleControls(failure.server))} ${dim("not pinned")}`, ` ${visibleLines(failure.reason, " ")}`);
|
|
4564
4731
|
}
|
|
@@ -4579,6 +4746,7 @@ async function runInit(options) {
|
|
|
4579
4746
|
process.stdout.write(lines.join("\n"));
|
|
4580
4747
|
await maybeOfferTelemetry();
|
|
4581
4748
|
if (result.unreachable.length > 0 && !options.allowUnreachable) return EXIT_INCOMPLETE;
|
|
4749
|
+
if (result.partial.length > 0 && !options.allowPartial) return EXIT_INCOMPLETE;
|
|
4582
4750
|
return EXIT_CLEAN;
|
|
4583
4751
|
}
|
|
4584
4752
|
|
|
@@ -4623,8 +4791,8 @@ async function awaitCallback(expectedState) {
|
|
|
4623
4791
|
server2.listen(0, "127.0.0.1", ready);
|
|
4624
4792
|
});
|
|
4625
4793
|
const { port } = server2.address();
|
|
4626
|
-
const received = new Promise((
|
|
4627
|
-
settle =
|
|
4794
|
+
const received = new Promise((resolve8, reject) => {
|
|
4795
|
+
settle = resolve8;
|
|
4628
4796
|
fail = reject;
|
|
4629
4797
|
setTimeout(() => reject(new Error(`no callback within ${CALLBACK_TIMEOUT_MS / 1e3}s`)), CALLBACK_TIMEOUT_MS).unref();
|
|
4630
4798
|
});
|
|
@@ -4641,9 +4809,9 @@ async function findServer(projectRoot, configFiles, name) {
|
|
|
4641
4809
|
const named = new Set(configFiles.map((file) => portablePath(resolve5(projectRoot, file), projectRoot)));
|
|
4642
4810
|
const chosen = conflict.definitions.filter((definition) => named.has(definition.file));
|
|
4643
4811
|
if (chosen.length === 1) return chosen[0].server;
|
|
4644
|
-
const
|
|
4812
|
+
const where2 = conflict.definitions.map((definition) => ` ${definition.file}: ${describeTarget(definition.server)}`).join("\n");
|
|
4645
4813
|
return { error: `"${name}" is defined differently in more than one config:
|
|
4646
|
-
${
|
|
4814
|
+
${where2}
|
|
4647
4815
|
Name the one you mean with --config <file>.` };
|
|
4648
4816
|
}
|
|
4649
4817
|
const server2 = discovery.servers.find((candidate) => candidate.name === name);
|
|
@@ -4818,29 +4986,181 @@ async function fromGithubActions(audience, env, options) {
|
|
|
4818
4986
|
}
|
|
4819
4987
|
}
|
|
4820
4988
|
|
|
4989
|
+
// src/lib/origin.ts
|
|
4990
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3, statSync as statSync2 } from "fs";
|
|
4991
|
+
import { dirname as dirname4, isAbsolute as isAbsolute4, join as join5, resolve as resolve6 } from "path";
|
|
4992
|
+
var MAX_PROJECT = 200;
|
|
4993
|
+
var MAX_REF = 200;
|
|
4994
|
+
function first(env, ...names) {
|
|
4995
|
+
for (const name of names) {
|
|
4996
|
+
const value = env[name]?.trim();
|
|
4997
|
+
if (value) return value;
|
|
4998
|
+
}
|
|
4999
|
+
return void 0;
|
|
5000
|
+
}
|
|
5001
|
+
function shortRef(ref) {
|
|
5002
|
+
return ref.replace(/^refs\/(heads|tags)\//, "");
|
|
5003
|
+
}
|
|
5004
|
+
function repositoryPath(remote) {
|
|
5005
|
+
const url = remote.trim();
|
|
5006
|
+
let path;
|
|
5007
|
+
const scp = /^(?:[^/@:\s]+@)?[^/:\s\\]{2,}:(?!\/)([^\\]+)$/.exec(url);
|
|
5008
|
+
if (scp) path = scp[1];
|
|
5009
|
+
else {
|
|
5010
|
+
try {
|
|
5011
|
+
path = new URL(url).pathname;
|
|
5012
|
+
} catch {
|
|
5013
|
+
return void 0;
|
|
5014
|
+
}
|
|
5015
|
+
}
|
|
5016
|
+
const azure = /\/_git\/([^/]+)/.exec(path ?? "");
|
|
5017
|
+
if (azure) path = azure[1];
|
|
5018
|
+
const cleaned = (path ?? "").replace(/^\/+|\/+$/g, "").replace(/\.git$/, "");
|
|
5019
|
+
return cleaned && !cleaned.includes("..") ? cleaned : void 0;
|
|
5020
|
+
}
|
|
5021
|
+
function projectFromCi(env) {
|
|
5022
|
+
const named = first(env, "GITHUB_REPOSITORY", "CI_PROJECT_PATH", "BITBUCKET_REPO_FULL_NAME", "BUILD_REPOSITORY_NAME");
|
|
5023
|
+
if (named) return named;
|
|
5024
|
+
const user = first(env, "CIRCLE_PROJECT_USERNAME");
|
|
5025
|
+
const repo = first(env, "CIRCLE_PROJECT_REPONAME");
|
|
5026
|
+
if (user && repo) return `${user}/${repo}`;
|
|
5027
|
+
const buildkite = first(env, "BUILDKITE_REPO");
|
|
5028
|
+
return buildkite ? repositoryPath(buildkite) : void 0;
|
|
5029
|
+
}
|
|
5030
|
+
function refFromCi(env) {
|
|
5031
|
+
const ref = first(
|
|
5032
|
+
env,
|
|
5033
|
+
"GITHUB_REF_NAME",
|
|
5034
|
+
"CI_COMMIT_REF_NAME",
|
|
5035
|
+
"BUILD_SOURCEBRANCH",
|
|
5036
|
+
"BITBUCKET_BRANCH",
|
|
5037
|
+
"BITBUCKET_TAG",
|
|
5038
|
+
"CIRCLE_BRANCH",
|
|
5039
|
+
"CIRCLE_TAG",
|
|
5040
|
+
"BUILDKITE_BRANCH"
|
|
5041
|
+
);
|
|
5042
|
+
return ref ? shortRef(ref) : void 0;
|
|
5043
|
+
}
|
|
5044
|
+
function commitFromCi(env) {
|
|
5045
|
+
return first(env, "GITHUB_SHA", "CI_COMMIT_SHA", "BUILD_SOURCEVERSION", "BITBUCKET_COMMIT", "CIRCLE_SHA1", "BUILDKITE_COMMIT");
|
|
5046
|
+
}
|
|
5047
|
+
function read(path) {
|
|
5048
|
+
try {
|
|
5049
|
+
if (!statSync2(path).isFile() || statSync2(path).size > 4 * 1024 * 1024) return void 0;
|
|
5050
|
+
return readFileSync3(path, "utf8");
|
|
5051
|
+
} catch {
|
|
5052
|
+
return void 0;
|
|
5053
|
+
}
|
|
5054
|
+
}
|
|
5055
|
+
function gitDirectories(start) {
|
|
5056
|
+
let dir = resolve6(start);
|
|
5057
|
+
for (let depth = 0; depth < 64; depth += 1) {
|
|
5058
|
+
const dotGit = join5(dir, ".git");
|
|
5059
|
+
if (existsSync2(dotGit)) {
|
|
5060
|
+
let gitDir = dotGit;
|
|
5061
|
+
try {
|
|
5062
|
+
if (statSync2(dotGit).isFile()) {
|
|
5063
|
+
const pointer = /^gitdir:\s*(.+)$/m.exec(read(dotGit) ?? "")?.[1]?.trim();
|
|
5064
|
+
if (!pointer) return void 0;
|
|
5065
|
+
gitDir = isAbsolute4(pointer) ? pointer : resolve6(dir, pointer);
|
|
5066
|
+
}
|
|
5067
|
+
} catch {
|
|
5068
|
+
return void 0;
|
|
5069
|
+
}
|
|
5070
|
+
const common = read(join5(gitDir, "commondir"))?.trim();
|
|
5071
|
+
return { gitDir, commonDir: common ? resolve6(gitDir, common) : gitDir };
|
|
5072
|
+
}
|
|
5073
|
+
const parent = dirname4(dir);
|
|
5074
|
+
if (parent === dir) return void 0;
|
|
5075
|
+
dir = parent;
|
|
5076
|
+
}
|
|
5077
|
+
return void 0;
|
|
5078
|
+
}
|
|
5079
|
+
function resolveRef(commonDir, ref) {
|
|
5080
|
+
if (!/^refs\/[\w./-]+$/.test(ref) || ref.includes("..")) return void 0;
|
|
5081
|
+
const loose = read(join5(commonDir, ref))?.trim();
|
|
5082
|
+
if (loose && /^[0-9a-f]{40,64}$/.test(loose)) return loose;
|
|
5083
|
+
for (const line of (read(join5(commonDir, "packed-refs")) ?? "").split("\n")) {
|
|
5084
|
+
const [sha, name] = line.trim().split(" ");
|
|
5085
|
+
if (name === ref && sha && /^[0-9a-f]{40,64}$/.test(sha)) return sha;
|
|
5086
|
+
}
|
|
5087
|
+
return void 0;
|
|
5088
|
+
}
|
|
5089
|
+
function remoteUrl(commonDir) {
|
|
5090
|
+
const config = read(join5(commonDir, "config"));
|
|
5091
|
+
if (!config) return void 0;
|
|
5092
|
+
const remotes = /* @__PURE__ */ new Map();
|
|
5093
|
+
let current;
|
|
5094
|
+
for (const raw of config.split("\n")) {
|
|
5095
|
+
const line = raw.trim();
|
|
5096
|
+
const section = /^\[\s*remote\s+"([^"]+)"\s*\]$/.exec(line);
|
|
5097
|
+
if (section) {
|
|
5098
|
+
current = section[1];
|
|
5099
|
+
continue;
|
|
5100
|
+
}
|
|
5101
|
+
if (line.startsWith("[")) {
|
|
5102
|
+
current = void 0;
|
|
5103
|
+
continue;
|
|
5104
|
+
}
|
|
5105
|
+
const url = /^url\s*=\s*(.+)$/.exec(line);
|
|
5106
|
+
if (current && url?.[1] && !remotes.has(current)) remotes.set(current, url[1].trim());
|
|
5107
|
+
}
|
|
5108
|
+
return remotes.get("origin") ?? remotes.values().next().value;
|
|
5109
|
+
}
|
|
5110
|
+
function repositoryFacts(root) {
|
|
5111
|
+
const dirs = gitDirectories(root);
|
|
5112
|
+
if (!dirs) return {};
|
|
5113
|
+
const head = read(join5(dirs.gitDir, "HEAD"))?.trim() ?? "";
|
|
5114
|
+
const symbolic = /^ref:\s*(refs\/\S+)$/.exec(head)?.[1];
|
|
5115
|
+
const commit = symbolic ? resolveRef(dirs.commonDir, symbolic) : /^[0-9a-f]{40,64}$/.test(head) ? head : void 0;
|
|
5116
|
+
const remote = remoteUrl(dirs.commonDir);
|
|
5117
|
+
return {
|
|
5118
|
+
project: remote ? repositoryPath(remote) : void 0,
|
|
5119
|
+
// A detached HEAD has a commit and no branch, which is what CI checkouts usually are.
|
|
5120
|
+
ref: symbolic?.startsWith("refs/heads/") ? shortRef(symbolic) : void 0,
|
|
5121
|
+
commit
|
|
5122
|
+
};
|
|
5123
|
+
}
|
|
5124
|
+
function readingOrigin(root, flags, env = process.env) {
|
|
5125
|
+
const repo = repositoryFacts(root);
|
|
5126
|
+
const usable = (value, max) => value && value.length <= max ? value : void 0;
|
|
5127
|
+
let project;
|
|
5128
|
+
let projectFrom;
|
|
5129
|
+
const ci = usable(projectFromCi(env), MAX_PROJECT);
|
|
5130
|
+
const fromRepo = usable(repo.project, MAX_PROJECT);
|
|
5131
|
+
if (flags.project) {
|
|
5132
|
+
project = flags.project;
|
|
5133
|
+
projectFrom = "flag";
|
|
5134
|
+
} else if (ci) {
|
|
5135
|
+
project = ci;
|
|
5136
|
+
projectFrom = "ci";
|
|
5137
|
+
} else if (fromRepo) {
|
|
5138
|
+
project = fromRepo;
|
|
5139
|
+
projectFrom = "repository";
|
|
5140
|
+
} else {
|
|
5141
|
+
project = resolve6(root).split(/[\\/]/).filter(Boolean).pop() ?? "default";
|
|
5142
|
+
projectFrom = "folder";
|
|
5143
|
+
}
|
|
5144
|
+
return {
|
|
5145
|
+
project,
|
|
5146
|
+
projectFrom,
|
|
5147
|
+
ref: flags.ref ?? usable(refFromCi(env), MAX_REF) ?? usable(repo.ref, MAX_REF),
|
|
5148
|
+
commit: flags.commit ?? commitFromCi(env) ?? repo.commit
|
|
5149
|
+
};
|
|
5150
|
+
}
|
|
5151
|
+
|
|
4821
5152
|
// src/commands/push.ts
|
|
4822
5153
|
function describeIdentity(identity3, hint) {
|
|
4823
5154
|
const shown = (text) => visibleControls(text);
|
|
4824
|
-
const
|
|
5155
|
+
const where2 = shown(`${identity3?.repository ?? ""}${identity3?.ref ? ` @ ${identity3.ref}` : ""}`);
|
|
4825
5156
|
const contents = identity3?.boundToReading ? " \xB7 contents signed" : identity3?.bindingRefused ? ` \xB7 contents not signed: ${shown(identity3.bindingRefused)}` : "";
|
|
4826
|
-
if (identity3?.trust === "trusted") return `${green("signed")} ${dim(`${
|
|
5157
|
+
if (identity3?.trust === "trusted") return `${green("signed")} ${dim(`${where2} \xB7 a trusted build${contents}`)}`;
|
|
4827
5158
|
if (identity3?.trust === "verified") {
|
|
4828
|
-
return `${yellow("signed")} ${dim(`${
|
|
5159
|
+
return `${yellow("signed")} ${dim(`${where2} \xB7 not a build this organization lists as trusted${contents}`)}`;
|
|
4829
5160
|
}
|
|
4830
5161
|
if (identity3?.rejected) return `${red("build token refused")} ${dim(shown(identity3.rejected))}`;
|
|
4831
5162
|
return hint ? dim(`unsigned: ${hint}`) : void 0;
|
|
4832
5163
|
}
|
|
4833
|
-
function inferProject(projectRoot) {
|
|
4834
|
-
const fromCi = process.env["GITHUB_REPOSITORY"] ?? process.env["CI_PROJECT_PATH"] ?? process.env["BUILD_REPOSITORY_NAME"];
|
|
4835
|
-
if (fromCi) return fromCi;
|
|
4836
|
-
return projectRoot.split("/").filter(Boolean).pop() ?? "default";
|
|
4837
|
-
}
|
|
4838
|
-
function inferRef() {
|
|
4839
|
-
return process.env["GITHUB_REF_NAME"] ?? process.env["CI_COMMIT_REF_NAME"] ?? void 0;
|
|
4840
|
-
}
|
|
4841
|
-
function inferCommit() {
|
|
4842
|
-
return process.env["GITHUB_SHA"] ?? process.env["CI_COMMIT_SHA"] ?? void 0;
|
|
4843
|
-
}
|
|
4844
5164
|
function refuseApiUrl(apiUrl) {
|
|
4845
5165
|
let url;
|
|
4846
5166
|
try {
|
|
@@ -4916,10 +5236,29 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4916
5236
|
promptCount: entry.prompts?.length ?? 0,
|
|
4917
5237
|
surface: entry
|
|
4918
5238
|
}));
|
|
5239
|
+
for (const [flag, value, max] of [
|
|
5240
|
+
["--project", options.project, 200],
|
|
5241
|
+
["--ref", options.ref, 200],
|
|
5242
|
+
["--commit", options.commit, 100]
|
|
5243
|
+
]) {
|
|
5244
|
+
const control = value !== void 0 && [...value].some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
5245
|
+
if (value !== void 0 && (value.trim() === "" || value.length > max || control)) {
|
|
5246
|
+
process.stderr.write(`${red(`${flag} has to be 1 to ${max} characters, with no control characters.`)}
|
|
5247
|
+
`);
|
|
5248
|
+
return EXIT_INCOMPLETE;
|
|
5249
|
+
}
|
|
5250
|
+
}
|
|
5251
|
+
const origin = readingOrigin(options.projectRoot, { project: options.project, ref: options.ref, commit: options.commit });
|
|
5252
|
+
if (origin.projectFrom === "folder") {
|
|
5253
|
+
process.stderr.write(
|
|
5254
|
+
`${yellow("note:")} reporting as project "${visibleControls(origin.project)}", this folder's name: no --project, CI variable or git remote names it. Pass --project so every push names it the same way.
|
|
5255
|
+
`
|
|
5256
|
+
);
|
|
5257
|
+
}
|
|
4919
5258
|
const body = {
|
|
4920
|
-
project:
|
|
4921
|
-
ref:
|
|
4922
|
-
commit:
|
|
5259
|
+
project: origin.project,
|
|
5260
|
+
ref: origin.ref,
|
|
5261
|
+
commit: origin.commit,
|
|
4923
5262
|
context: options.watch ? "watch" : process.env["CI"] !== void 0 && process.env["CI"] !== "false" ? "ci" : "local",
|
|
4924
5263
|
collectorVersion: VERSION,
|
|
4925
5264
|
servers,
|
|
@@ -4973,7 +5312,8 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4973
5312
|
const lines = [""];
|
|
4974
5313
|
const mark = verdict.verdict === "clean" ? green("\u2713") : verdict.verdict === "drift" ? yellow("!") : red("\u2717");
|
|
4975
5314
|
const shown = (text) => visibleControls(String(text ?? ""));
|
|
4976
|
-
lines.push(`${mark} ${bold(shown(verdict.verdict))} ${dim(`\xB7 ${servers.length} server(s) \xB7 reading ${shown(verdict.readingId).slice(0, 8)}`)}`);
|
|
5315
|
+
lines.push(`${mark} ${bold(shown(verdict.verdict))} ${dim(`\xB7 ${shown(origin.project)} \xB7 ${servers.length} server(s) \xB7 reading ${shown(verdict.readingId).slice(0, 8)}`)}`);
|
|
5316
|
+
if (origin.ref || origin.commit) lines.push(` ${dim(`at ${shown(origin.ref ?? "a detached commit")}${origin.commit ? ` @ ${shown(origin.commit).slice(0, 7)}` : ""}`)}`);
|
|
4977
5317
|
const identity3 = describeIdentity(verdict.identity, build && "hint" in build ? build.hint : void 0);
|
|
4978
5318
|
if (identity3) lines.push(` ${identity3}`);
|
|
4979
5319
|
for (const change2 of verdict.changes) {
|
|
@@ -4985,6 +5325,13 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4985
5325
|
if (verdict.verdict !== "clean") lines.push("", dim(`Review it at ${shown(verdict.url)}`));
|
|
4986
5326
|
lines.push("");
|
|
4987
5327
|
process.stdout.write(lines.join("\n"));
|
|
5328
|
+
if (result.partial.length > 0 && options.allowPartial !== true) {
|
|
5329
|
+
process.stderr.write(
|
|
5330
|
+
`${yellow("incomplete:")} ${result.partial.map((entry) => visibleControls(entry.server)).join(", ")} could not be read in full. Pass --allow-partial to accept that.
|
|
5331
|
+
`
|
|
5332
|
+
);
|
|
5333
|
+
return EXIT_INCOMPLETE;
|
|
5334
|
+
}
|
|
4988
5335
|
return verdict.exitCode === 0 ? EXIT_CLEAN : verdict.exitCode === 1 ? EXIT_DRIFT : EXIT_INCOMPLETE;
|
|
4989
5336
|
}
|
|
4990
5337
|
|
|
@@ -5043,7 +5390,7 @@ async function runReview(options) {
|
|
|
5043
5390
|
if (changes.length === 0) {
|
|
5044
5391
|
process.stdout.write(`${green(`\u2713 nothing to review; ${options.lockPath} is up to date`)}
|
|
5045
5392
|
`);
|
|
5046
|
-
return result.unreachable.length > 0 && !options.allowUnreachable ? EXIT_INCOMPLETE : EXIT_CLEAN;
|
|
5393
|
+
return result.unreachable.length > 0 && !options.allowUnreachable || result.partial.length > 0 && !options.allowPartial ? EXIT_INCOMPLETE : EXIT_CLEAN;
|
|
5047
5394
|
}
|
|
5048
5395
|
const grouped = /* @__PURE__ */ new Map();
|
|
5049
5396
|
for (const change2 of changes) {
|
|
@@ -5112,6 +5459,7 @@ ${green(`\u2713 accepted ${accepted} server(s) into ${options.lockPath}`)}
|
|
|
5112
5459
|
if (declined > 0) process.stdout.write(`${yellow(`${declined} server(s) left unaccepted; \`check\` will still fail on them.`)}
|
|
5113
5460
|
`);
|
|
5114
5461
|
if (result.unreachable.length > 0 && !options.allowUnreachable) return EXIT_INCOMPLETE;
|
|
5462
|
+
if (result.partial.length > 0 && !options.allowPartial) return EXIT_INCOMPLETE;
|
|
5115
5463
|
return declined > 0 ? EXIT_DRIFT : EXIT_CLEAN;
|
|
5116
5464
|
}
|
|
5117
5465
|
|
|
@@ -5133,6 +5481,7 @@ ${bold("Options")}
|
|
|
5133
5481
|
--config <path> audit this config file too; repeatable
|
|
5134
5482
|
--timeout <ms> per-server timeout (default: ${DEFAULT_TIMEOUT_MS2})
|
|
5135
5483
|
--allow-unreachable a server that cannot be reached warns instead of failing
|
|
5484
|
+
--allow-partial a server whose tool list could not be read in full warns instead of failing
|
|
5136
5485
|
--no-provenance do not look up what each stdio server runs (air-gapped runs)
|
|
5137
5486
|
--user-configs also pin servers from your own configs (~/.claude.json, Claude Desktop, ...)
|
|
5138
5487
|
--json machine-readable output (check)
|
|
@@ -5142,7 +5491,9 @@ ${bold("Options")}
|
|
|
5142
5491
|
--force re-pin over an existing lockfile, discarding it (init)
|
|
5143
5492
|
--api <url> control plane to push to (push; or NULLADRIFT_API_URL)
|
|
5144
5493
|
--token <token> collector token (push; or NULLADRIFT_TOKEN)
|
|
5145
|
-
--project <name> project
|
|
5494
|
+
--project <name> project to report under (push; else from CI, then the git remote, then the folder)
|
|
5495
|
+
--ref <branch> branch or tag to record (push; else from CI, then the checked-out branch)
|
|
5496
|
+
--commit <sha> commit to record (push; else from CI, then HEAD)
|
|
5146
5497
|
--watch mark this as a scheduled reading rather than one a build asked for (push)
|
|
5147
5498
|
--comment post the findings on the pull request being reviewed (check; needs CI)
|
|
5148
5499
|
-h, --help this text
|
|
@@ -5164,6 +5515,7 @@ async function main() {
|
|
|
5164
5515
|
config: { type: "string", multiple: true },
|
|
5165
5516
|
timeout: { type: "string" },
|
|
5166
5517
|
"allow-unreachable": { type: "boolean", default: false },
|
|
5518
|
+
"allow-partial": { type: "boolean", default: false },
|
|
5167
5519
|
"no-provenance": { type: "boolean", default: false },
|
|
5168
5520
|
"user-configs": { type: "boolean", default: false },
|
|
5169
5521
|
json: { type: "boolean", default: false },
|
|
@@ -5174,6 +5526,8 @@ async function main() {
|
|
|
5174
5526
|
api: { type: "string" },
|
|
5175
5527
|
token: { type: "string" },
|
|
5176
5528
|
project: { type: "string" },
|
|
5529
|
+
ref: { type: "string" },
|
|
5530
|
+
commit: { type: "string" },
|
|
5177
5531
|
watch: { type: "boolean", default: false },
|
|
5178
5532
|
comment: { type: "boolean", default: false },
|
|
5179
5533
|
help: { type: "boolean", short: "h", default: false },
|
|
@@ -5202,13 +5556,14 @@ async function main() {
|
|
|
5202
5556
|
`);
|
|
5203
5557
|
return EXIT_INCOMPLETE;
|
|
5204
5558
|
}
|
|
5205
|
-
const projectRoot =
|
|
5559
|
+
const projectRoot = resolve7(values.cwd ?? process.cwd());
|
|
5206
5560
|
const options = {
|
|
5207
5561
|
projectRoot,
|
|
5208
|
-
lockPath:
|
|
5562
|
+
lockPath: resolve7(projectRoot, values.lock ?? DEFAULT_LOCK_FILENAME),
|
|
5209
5563
|
configFiles: values.config ?? [],
|
|
5210
5564
|
timeoutMs,
|
|
5211
5565
|
allowUnreachable: values["allow-unreachable"],
|
|
5566
|
+
allowPartial: values["allow-partial"],
|
|
5212
5567
|
format: values.sarif ? "sarif" : values.json ? "json" : "human",
|
|
5213
5568
|
sarifSteering: values["sarif-steering"] === true,
|
|
5214
5569
|
comment: values.comment,
|
|
@@ -5221,7 +5576,7 @@ async function main() {
|
|
|
5221
5576
|
case "check":
|
|
5222
5577
|
return runCheck(options);
|
|
5223
5578
|
case "push":
|
|
5224
|
-
return runPush({ ...options, apiUrl: values.api, token: values.token, project: values.project, watch: values.watch });
|
|
5579
|
+
return runPush({ ...options, apiUrl: values.api, token: values.token, project: values.project, ref: values.ref, commit: values.commit, watch: values.watch });
|
|
5225
5580
|
case "review":
|
|
5226
5581
|
return runReview({ ...options, acceptAll: values["accept-all"] });
|
|
5227
5582
|
case "login":
|