@glassbox-ai/engine 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +33 -2
- package/dist/action/acc.d.ts +48 -0
- package/dist/action/acc.js +117 -0
- package/dist/action/builtin-tools.d.ts +5 -0
- package/dist/action/builtin-tools.js +74 -0
- package/dist/action/inline.d.ts +14 -0
- package/dist/action/inline.js +54 -0
- package/dist/action/paths.d.ts +71 -0
- package/dist/action/paths.js +398 -0
- package/dist/action/powershell.d.ts +9 -0
- package/dist/action/powershell.js +848 -0
- package/dist/action/protected-write.d.ts +11 -0
- package/dist/action/protected-write.js +113 -0
- package/dist/action/schedule.d.ts +43 -0
- package/dist/action/schedule.js +213 -0
- package/dist/action/shell/analyze.d.ts +28 -0
- package/dist/action/shell/analyze.js +2057 -0
- package/dist/action/shell/parse.d.ts +74 -0
- package/dist/action/shell/parse.js +1037 -0
- package/dist/action/shell/view.d.ts +6 -0
- package/dist/action/shell/view.js +89 -0
- package/dist/action/sql.d.ts +3 -0
- package/dist/action/sql.js +259 -0
- package/dist/action/tools.d.ts +20 -0
- package/dist/action/tools.js +305 -0
- package/dist/action/upload.d.ts +17 -0
- package/dist/action/upload.js +72 -0
- package/dist/analysis/fields.d.ts +14 -0
- package/dist/analysis/fields.js +136 -0
- package/dist/analysis/findings.d.ts +25 -0
- package/dist/analysis/findings.js +82 -0
- package/dist/analysis/gate.d.ts +16 -0
- package/dist/analysis/gate.js +662 -0
- package/dist/analysis/manifest.d.ts +3 -0
- package/dist/analysis/manifest.js +369 -0
- package/dist/analysis/match.d.ts +54 -0
- package/dist/analysis/match.js +352 -0
- package/dist/analysis/scan.d.ts +17 -0
- package/dist/analysis/scan.js +97 -0
- package/dist/canon/confusables.generated.d.ts +3 -0
- package/dist/canon/confusables.generated.js +6 -0
- package/dist/canon/decode.d.ts +11 -0
- package/dist/canon/decode.js +147 -0
- package/dist/canon/views.d.ts +36 -0
- package/dist/canon/views.js +283 -0
- package/dist/evidence/evidence.d.ts +12 -0
- package/dist/evidence/evidence.js +149 -0
- package/dist/fingerprint/diff.d.ts +3 -0
- package/dist/fingerprint/diff.js +273 -0
- package/dist/fingerprint/fingerprint.d.ts +4 -0
- package/dist/fingerprint/fingerprint.js +77 -0
- package/dist/grade/score.d.ts +19 -0
- package/dist/grade/score.js +89 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +152 -0
- package/dist/intake/json.d.ts +17 -0
- package/dist/intake/json.js +284 -0
- package/dist/intake/snapshot.d.ts +14 -0
- package/dist/intake/snapshot.js +130 -0
- package/dist/limits.d.ts +4 -0
- package/dist/limits.js +30 -0
- package/dist/policy/decide.d.ts +32 -0
- package/dist/policy/decide.js +105 -0
- package/dist/rules/ids.d.ts +2 -0
- package/dist/rules/ids.js +99 -0
- package/dist/ruleset/baseline-tests.generated.d.ts +6 -0
- package/dist/ruleset/baseline-tests.generated.js +2935 -0
- package/dist/ruleset/baseline.d.ts +3 -0
- package/dist/ruleset/baseline.generated.d.ts +3 -0
- package/dist/ruleset/baseline.generated.js +5 -0
- package/dist/ruleset/baseline.js +44 -0
- package/dist/ruleset/fakes.d.ts +3 -0
- package/dist/ruleset/fakes.js +26 -0
- package/dist/ruleset/load.d.ts +13 -0
- package/dist/ruleset/load.js +187 -0
- package/dist/ruleset/schema.d.ts +120 -0
- package/dist/ruleset/schema.js +54 -0
- package/dist/ruleset/selftest.d.ts +18 -0
- package/dist/ruleset/selftest.js +42 -0
- package/dist/ruleset-entry.d.ts +5 -0
- package/dist/ruleset-entry.js +7 -0
- package/dist/secrets/detect.d.ts +17 -0
- package/dist/secrets/detect.js +236 -0
- package/dist/secrets/redact.d.ts +19 -0
- package/dist/secrets/redact.js +116 -0
- package/dist/types.d.ts +455 -0
- package/dist/types.js +10 -0
- package/dist/util/hash.d.ts +4 -0
- package/dist/util/hash.js +16 -0
- package/dist/util/initclock.d.ts +3 -0
- package/dist/util/initclock.js +17 -0
- package/dist/util/jcs.d.ts +4 -0
- package/dist/util/jcs.js +91 -0
- package/dist/util/misc.d.ts +17 -0
- package/dist/util/misc.js +77 -0
- package/dist/util/re.d.ts +14 -0
- package/dist/util/re.js +47 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +57 -4
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// Fingerprint diff and the cloaking check.
|
|
2
|
+
import { FindingFactory } from "../analysis/findings.js";
|
|
3
|
+
import { displayTokens } from "../evidence/evidence.js";
|
|
4
|
+
import { EMBEDDED_BASELINE } from "../ruleset/baseline.js";
|
|
5
|
+
import { isRecord, ptrSeg } from "../util/misc.js";
|
|
6
|
+
import { jcs } from "../util/jcs.js";
|
|
7
|
+
import { isFingerprint } from "./fingerprint.js";
|
|
8
|
+
const RULE = {
|
|
9
|
+
"tool-added": "CP-RUGPULL-001", "tool-removed": "CP-RUGPULL-002", "description-changed": "CP-RUGPULL-003", "title-changed": "CP-RUGPULL-004",
|
|
10
|
+
"schema-widened": "CP-RUGPULL-005", "schema-narrowed": "CP-RUGPULL-006", "schema-changed-indeterminate": "CP-RUGPULL-007", "annotations-escalated": "CP-RUGPULL-008",
|
|
11
|
+
"annotations-changed": "CP-RUGPULL-009", "server-instructions-changed": "CP-RUGPULL-010", "serverinfo-changed": "CP-RUGPULL-011", "prompt-added": "CP-RUGPULL-012",
|
|
12
|
+
"resource-added": "CP-RUGPULL-012", "output-schema-changed": "CP-RUGPULL-013", "fingerprint-incomparable": "CP-RUGPULL-014",
|
|
13
|
+
};
|
|
14
|
+
const esc = (s) => displayTokens(s.slice(0, 120)).join("");
|
|
15
|
+
const IGNORED = new Set(["description", "title", "examples", "$comment", "deprecated"]);
|
|
16
|
+
const same = (a, b) => { try {
|
|
17
|
+
return jcs(a ?? null) === jcs(b ?? null);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
} };
|
|
22
|
+
function compareSchema(a, b, eff, depth = 0) {
|
|
23
|
+
if (depth > 32) {
|
|
24
|
+
eff.indeterminate = true;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (same(a, b))
|
|
28
|
+
return;
|
|
29
|
+
if (!isRecord(a) || !isRecord(b)) {
|
|
30
|
+
if (a === undefined || a === null)
|
|
31
|
+
eff.narrow = true;
|
|
32
|
+
else if (b === undefined || b === null)
|
|
33
|
+
eff.widen = true;
|
|
34
|
+
else
|
|
35
|
+
eff.indeterminate = true;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
39
|
+
for (const k of keys) {
|
|
40
|
+
if (IGNORED.has(k))
|
|
41
|
+
continue;
|
|
42
|
+
const x = a[k], y = b[k];
|
|
43
|
+
if (same(x, y))
|
|
44
|
+
continue;
|
|
45
|
+
switch (k) {
|
|
46
|
+
case "properties": {
|
|
47
|
+
const px = isRecord(x) ? x : {}, py = isRecord(y) ? y : {};
|
|
48
|
+
for (const p of new Set([...Object.keys(px), ...Object.keys(py)])) {
|
|
49
|
+
if (!(p in px))
|
|
50
|
+
eff.widen = true;
|
|
51
|
+
else if (!(p in py))
|
|
52
|
+
eff.narrow = true;
|
|
53
|
+
else
|
|
54
|
+
compareSchema(px[p], py[p], eff, depth + 1);
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "required": {
|
|
59
|
+
const sx = new Set(Array.isArray(x) ? x : []), sy = new Set(Array.isArray(y) ? y : []);
|
|
60
|
+
if ([...sx].some((v) => !sy.has(v)))
|
|
61
|
+
eff.widen = true;
|
|
62
|
+
if ([...sy].some((v) => !sx.has(v)))
|
|
63
|
+
eff.narrow = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "additionalProperties":
|
|
67
|
+
if (x === false && y !== false)
|
|
68
|
+
eff.widen = true;
|
|
69
|
+
else if (y === false && x !== false)
|
|
70
|
+
eff.narrow = true;
|
|
71
|
+
else if (isRecord(x) && isRecord(y))
|
|
72
|
+
compareSchema(x, y, eff, depth + 1);
|
|
73
|
+
else if (x === undefined || x === true)
|
|
74
|
+
eff.narrow = true;
|
|
75
|
+
else
|
|
76
|
+
eff.indeterminate = true;
|
|
77
|
+
break;
|
|
78
|
+
case "enum":
|
|
79
|
+
case "const": {
|
|
80
|
+
if (y === undefined) {
|
|
81
|
+
eff.widen = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (x === undefined) {
|
|
85
|
+
eff.narrow = true;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
const ex = new Set((Array.isArray(x) ? x : [x]).map((v) => jcs(v))), ey = new Set((Array.isArray(y) ? y : [y]).map((v) => jcs(v)));
|
|
89
|
+
if ([...ey].some((v) => !ex.has(v)))
|
|
90
|
+
eff.widen = true;
|
|
91
|
+
if ([...ex].some((v) => !ey.has(v)))
|
|
92
|
+
eff.narrow = true;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "type": {
|
|
96
|
+
const tx = new Set(Array.isArray(x) ? x : x === undefined ? [] : [x]), ty = new Set(Array.isArray(y) ? y : y === undefined ? [] : [y]);
|
|
97
|
+
if (ty.size === 0)
|
|
98
|
+
eff.widen = true;
|
|
99
|
+
else if (tx.size === 0)
|
|
100
|
+
eff.narrow = true;
|
|
101
|
+
else {
|
|
102
|
+
if ([...ty].some((v) => !tx.has(v)))
|
|
103
|
+
eff.widen = true;
|
|
104
|
+
if ([...tx].some((v) => !ty.has(v)))
|
|
105
|
+
eff.narrow = true;
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case "minLength":
|
|
110
|
+
case "minimum":
|
|
111
|
+
case "minItems":
|
|
112
|
+
case "exclusiveMinimum":
|
|
113
|
+
case "minProperties":
|
|
114
|
+
if (y === undefined || (typeof x === "number" && typeof y === "number" && y < x))
|
|
115
|
+
eff.widen = true;
|
|
116
|
+
else
|
|
117
|
+
eff.narrow = true;
|
|
118
|
+
break;
|
|
119
|
+
case "maxLength":
|
|
120
|
+
case "maximum":
|
|
121
|
+
case "maxItems":
|
|
122
|
+
case "exclusiveMaximum":
|
|
123
|
+
case "maxProperties":
|
|
124
|
+
if (y === undefined || (typeof x === "number" && typeof y === "number" && y > x))
|
|
125
|
+
eff.widen = true;
|
|
126
|
+
else
|
|
127
|
+
eff.narrow = true;
|
|
128
|
+
break;
|
|
129
|
+
case "pattern":
|
|
130
|
+
case "format":
|
|
131
|
+
if (y === undefined)
|
|
132
|
+
eff.widen = true;
|
|
133
|
+
else if (x === undefined)
|
|
134
|
+
eff.narrow = true;
|
|
135
|
+
else
|
|
136
|
+
eff.indeterminate = true;
|
|
137
|
+
break;
|
|
138
|
+
case "items":
|
|
139
|
+
compareSchema(x, y, eff, depth + 1);
|
|
140
|
+
break;
|
|
141
|
+
case "anyOf":
|
|
142
|
+
case "oneOf": {
|
|
143
|
+
const lx = Array.isArray(x) ? x.length : 0, ly = Array.isArray(y) ? y.length : 0;
|
|
144
|
+
if (ly > lx)
|
|
145
|
+
eff.widen = true;
|
|
146
|
+
else if (ly < lx)
|
|
147
|
+
eff.narrow = true;
|
|
148
|
+
else
|
|
149
|
+
eff.indeterminate = true;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case "allOf": {
|
|
153
|
+
const lx = Array.isArray(x) ? x.length : 0, ly = Array.isArray(y) ? y.length : 0;
|
|
154
|
+
if (ly < lx)
|
|
155
|
+
eff.widen = true;
|
|
156
|
+
else if (ly > lx)
|
|
157
|
+
eff.narrow = true;
|
|
158
|
+
else
|
|
159
|
+
eff.indeterminate = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
default:
|
|
163
|
+
eff.indeterminate = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** All "description" strings inside a schema, keyed by pointer. */
|
|
168
|
+
function descriptions(s, base = "") {
|
|
169
|
+
const out = new Map();
|
|
170
|
+
const stack = [{ v: s, p: base, d: 0 }];
|
|
171
|
+
while (stack.length > 0) {
|
|
172
|
+
const { v, p, d } = stack.pop();
|
|
173
|
+
if (d > 32)
|
|
174
|
+
continue;
|
|
175
|
+
if (Array.isArray(v))
|
|
176
|
+
v.forEach((x, i) => stack.push({ v: x, p: `${p}/${i}`, d: d + 1 }));
|
|
177
|
+
else if (isRecord(v))
|
|
178
|
+
for (const k of Object.keys(v)) {
|
|
179
|
+
if (k === "description" && typeof v[k] === "string")
|
|
180
|
+
out.set(p, v[k]);
|
|
181
|
+
stack.push({ v: v[k], p: `${p}/${ptrSeg(k)}`, d: d + 1 });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
function annotationsEscalated(a, b) {
|
|
187
|
+
const g = (o, k) => (isRecord(o) ? o[k] : undefined);
|
|
188
|
+
return (g(a, "readOnlyHint") === true && g(b, "readOnlyHint") !== true) ||
|
|
189
|
+
(g(a, "destructiveHint") !== true && g(b, "destructiveHint") === true) ||
|
|
190
|
+
(g(a, "openWorldHint") === false && g(b, "openWorldHint") === true);
|
|
191
|
+
}
|
|
192
|
+
function toolChanges(p, n, out) {
|
|
193
|
+
const item = n.name;
|
|
194
|
+
const ptr = `/tools/${ptrSeg(item)}`;
|
|
195
|
+
if (p.parts.description !== n.parts.description)
|
|
196
|
+
out.push({ kind: "description-changed", item, pointer: `${ptr}/description`, detail: `description of tool "${esc(item)}" changed` });
|
|
197
|
+
if (p.parts.title !== n.parts.title)
|
|
198
|
+
out.push({ kind: "title-changed", item, pointer: `${ptr}/title`, detail: `title of tool "${esc(item)}" changed` });
|
|
199
|
+
if (p.parts.inputSchema !== n.parts.inputSchema) {
|
|
200
|
+
const dp = descriptions(p.snapshot.inputSchema), dn = descriptions(n.snapshot.inputSchema);
|
|
201
|
+
for (const [k, v] of dn)
|
|
202
|
+
if (dp.has(k) && dp.get(k) !== v)
|
|
203
|
+
out.push({ kind: "description-changed", item, pointer: `${ptr}/inputSchema${k}/description`, detail: `a parameter description of "${esc(item)}" changed` });
|
|
204
|
+
const eff = { widen: false, narrow: false, indeterminate: false };
|
|
205
|
+
compareSchema(p.snapshot.inputSchema, n.snapshot.inputSchema, eff);
|
|
206
|
+
if (eff.widen)
|
|
207
|
+
out.push({ kind: "schema-widened", item, pointer: `${ptr}/inputSchema`, detail: `input schema of "${esc(item)}" now accepts more` });
|
|
208
|
+
else if (eff.indeterminate)
|
|
209
|
+
out.push({ kind: "schema-changed-indeterminate", item, pointer: `${ptr}/inputSchema`, detail: `input schema of "${esc(item)}" changed in a way that can't be classified` });
|
|
210
|
+
else if (eff.narrow)
|
|
211
|
+
out.push({ kind: "schema-narrowed", item, pointer: `${ptr}/inputSchema`, detail: `input schema of "${esc(item)}" now accepts less` });
|
|
212
|
+
}
|
|
213
|
+
if (p.parts.outputSchema !== n.parts.outputSchema)
|
|
214
|
+
out.push({ kind: "output-schema-changed", item, pointer: `${ptr}/outputSchema`, detail: `output schema of "${esc(item)}" changed` });
|
|
215
|
+
if (p.parts.annotations !== n.parts.annotations) {
|
|
216
|
+
out.push(annotationsEscalated(p.snapshot.annotations, n.snapshot.annotations)
|
|
217
|
+
? { kind: "annotations-escalated", item, pointer: `${ptr}/annotations`, detail: `annotations of "${esc(item)}" now describe it as more dangerous` }
|
|
218
|
+
: { kind: "annotations-changed", item, pointer: `${ptr}/annotations`, detail: `annotations of "${esc(item)}" changed` });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export function diffImpl(prev, next, opts) {
|
|
222
|
+
const ff = new FindingFactory(EMBEDDED_BASELINE, "snippet");
|
|
223
|
+
const changes = [];
|
|
224
|
+
const mk = (c) => ff.make({ ruleId: RULE[c.kind], location: c.pointer });
|
|
225
|
+
if (!isFingerprint(prev) || !isFingerprint(next) || prev.algorithm !== "glassbox-fp-v1" || next.algorithm !== "glassbox-fp-v1" || prev.truncated || next.truncated) {
|
|
226
|
+
const c = { kind: "fingerprint-incomparable", item: "", pointer: "", detail: "the fingerprints can't be compared" };
|
|
227
|
+
const f = mk(c);
|
|
228
|
+
return { changed: true, changes: [c], findings: f ? [f] : [], degraded: true };
|
|
229
|
+
}
|
|
230
|
+
if (prev.manifest === next.manifest)
|
|
231
|
+
return { changed: false, changes: [], findings: [], degraded: false };
|
|
232
|
+
const pt = new Map(prev.tools.map((t) => [t.name, t]));
|
|
233
|
+
const nt = new Map(next.tools.map((t) => [t.name, t]));
|
|
234
|
+
for (const [name, t] of nt) {
|
|
235
|
+
const p = pt.get(name);
|
|
236
|
+
if (!p) {
|
|
237
|
+
changes.push({ kind: "tool-added", item: name, pointer: `/tools/${ptrSeg(name)}`, detail: `tool "${esc(name)}" added` });
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (p.hash !== t.hash)
|
|
241
|
+
toolChanges(p, t, changes);
|
|
242
|
+
}
|
|
243
|
+
for (const name of pt.keys())
|
|
244
|
+
if (!nt.has(name))
|
|
245
|
+
changes.push({ kind: "tool-removed", item: name, pointer: `/tools/${ptrSeg(name)}`, detail: `tool "${esc(name)}" removed` });
|
|
246
|
+
if (prev.server.instructions !== next.server.instructions)
|
|
247
|
+
changes.push({ kind: "server-instructions-changed", item: "", pointer: "/initialize/instructions", detail: "server instructions changed" });
|
|
248
|
+
if (prev.server.serverInfo !== next.server.serverInfo) {
|
|
249
|
+
const ps = prev.serverSnapshot ?? { name: null, title: null }, ns = next.serverSnapshot ?? { name: null, title: null };
|
|
250
|
+
if (ps.name !== ns.name || ps.title !== ns.title)
|
|
251
|
+
changes.push({ kind: "serverinfo-changed", item: "", pointer: "/initialize/serverInfo", detail: "server name or title changed" });
|
|
252
|
+
}
|
|
253
|
+
const pp = new Set(prev.prompts.map((x) => x.name)), pr = new Set(prev.resources.map((x) => x.name));
|
|
254
|
+
for (const x of next.prompts)
|
|
255
|
+
if (!pp.has(x.name))
|
|
256
|
+
changes.push({ kind: "prompt-added", item: x.name, pointer: `/prompts/${ptrSeg(x.name)}`, detail: `prompt "${esc(x.name)}" added` });
|
|
257
|
+
for (const x of next.resources)
|
|
258
|
+
if (!pr.has(x.name))
|
|
259
|
+
changes.push({ kind: "resource-added", item: x.name, pointer: `/resources/${ptrSeg(x.name)}`, detail: `resource "${esc(x.name)}" added` });
|
|
260
|
+
const findings = [];
|
|
261
|
+
for (const c of changes) {
|
|
262
|
+
const f = mk(c);
|
|
263
|
+
if (f)
|
|
264
|
+
findings.push(f);
|
|
265
|
+
}
|
|
266
|
+
if (opts?.baseline === "public-grade") {
|
|
267
|
+
const f = ff.make({ ruleId: "CP-CLOAK-001", location: "" });
|
|
268
|
+
if (f)
|
|
269
|
+
findings.push(f);
|
|
270
|
+
}
|
|
271
|
+
return { changed: true, changes, findings, degraded: false };
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { sha256Hex } from "../util/hash.js";
|
|
2
|
+
import { jcs } from "../util/jcs.js";
|
|
3
|
+
import { get, getString, isRecord } from "../util/misc.js";
|
|
4
|
+
import { DEFAULT_LIMITS } from "../limits.js";
|
|
5
|
+
import { redactString, redactValue } from "../secrets/redact.js";
|
|
6
|
+
const H = (v) => sha256Hex(jcs(v === undefined ? null : v));
|
|
7
|
+
/** Snapshots are output, so they are redacted (hashes are computed over the raw values). */
|
|
8
|
+
const cap = (v) => {
|
|
9
|
+
try {
|
|
10
|
+
return jcs(v ?? null).length > 16 * 1024 ? "[truncated]" : redactValue(v ?? null, DEFAULT_LIMITS).value;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const capText = (s) => redactString(s.slice(0, 16 * 1024), "description", DEFAULT_LIMITS).text;
|
|
17
|
+
function items(list, key) {
|
|
18
|
+
if (!Array.isArray(list))
|
|
19
|
+
return [];
|
|
20
|
+
const out = list.map((x, i) => ({ name: getString(x, key) ?? getString(x, "name") ?? `#${i}`, hash: H(x) }));
|
|
21
|
+
return dedupNames(out.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : a.hash < b.hash ? -1 : 1)));
|
|
22
|
+
}
|
|
23
|
+
function dedupNames(xs) {
|
|
24
|
+
const seen = new Map();
|
|
25
|
+
return xs.map((x) => {
|
|
26
|
+
const n = seen.get(x.name) ?? 0;
|
|
27
|
+
seen.set(x.name, n + 1);
|
|
28
|
+
return n === 0 ? x : { ...x, name: `${x.name}~${n}` };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function fingerprintOf(m, limits) {
|
|
32
|
+
const init = get(m, "initialize");
|
|
33
|
+
const instructions = get(init, "instructions");
|
|
34
|
+
const serverInfo = get(init, "serverInfo");
|
|
35
|
+
const toolsRaw = Array.isArray(get(m, "tools")) ? get(m, "tools") : [];
|
|
36
|
+
const truncated = toolsRaw.length > limits.maxTools;
|
|
37
|
+
const tools = dedupNames(toolsRaw.slice(0, limits.maxTools).map((t, i) => {
|
|
38
|
+
const name = getString(t, "name") ?? `#${i}`;
|
|
39
|
+
const part = (k) => H(get(t, k) ?? null);
|
|
40
|
+
return {
|
|
41
|
+
name,
|
|
42
|
+
hash: H({ name, title: get(t, "title") ?? null, description: get(t, "description") ?? null, inputSchema: get(t, "inputSchema") ?? null, outputSchema: get(t, "outputSchema") ?? null, annotations: get(t, "annotations") ?? null }),
|
|
43
|
+
parts: { title: part("title"), description: part("description"), inputSchema: part("inputSchema"), outputSchema: part("outputSchema"), annotations: part("annotations") },
|
|
44
|
+
snapshot: { description: typeof get(t, "description") === "string" ? capText(get(t, "description")) : "", inputSchema: cap(get(t, "inputSchema")), annotations: cap(get(t, "annotations")), title: capText(getString(t, "title") ?? "") },
|
|
45
|
+
};
|
|
46
|
+
}).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : a.hash < b.hash ? -1 : 1)));
|
|
47
|
+
const prompts = items(get(m, "prompts"), "name");
|
|
48
|
+
const resources = items(get(m, "resources"), "uri");
|
|
49
|
+
const resourceTemplates = items(get(m, "resourceTemplates"), "uriTemplate");
|
|
50
|
+
const server = {
|
|
51
|
+
instructions: instructions === undefined ? null : H(instructions),
|
|
52
|
+
serverInfo: serverInfo === undefined ? null : H(serverInfo),
|
|
53
|
+
};
|
|
54
|
+
const manifest = H({
|
|
55
|
+
instructions: instructions ?? null,
|
|
56
|
+
serverInfo: serverInfo ?? null,
|
|
57
|
+
tools: tools.map((t) => t.hash),
|
|
58
|
+
prompts: prompts.map((p) => p.hash),
|
|
59
|
+
resources: resources.map((r) => r.hash),
|
|
60
|
+
resourceTemplates: resourceTemplates.map((r) => r.hash),
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
algorithm: "glassbox-fp-v1",
|
|
64
|
+
manifest,
|
|
65
|
+
server,
|
|
66
|
+
serverSnapshot: { name: getString(serverInfo, "name") ?? null, title: getString(serverInfo, "title") ?? null, version: getString(serverInfo, "version") ?? null },
|
|
67
|
+
tools,
|
|
68
|
+
prompts,
|
|
69
|
+
resources,
|
|
70
|
+
resourceTemplates,
|
|
71
|
+
truncated,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function isFingerprint(v) {
|
|
75
|
+
return isRecord(v) && typeof v["manifest"] === "string" && Array.isArray(v["tools"]) && isRecord(v["server"]);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Finding, Grade } from "../types.js";
|
|
2
|
+
export interface Score {
|
|
3
|
+
score: number;
|
|
4
|
+
grade: Grade;
|
|
5
|
+
caps: {
|
|
6
|
+
cap: Grade;
|
|
7
|
+
reason: string;
|
|
8
|
+
findingIds: string[];
|
|
9
|
+
}[];
|
|
10
|
+
deductions: {
|
|
11
|
+
findingId: string;
|
|
12
|
+
points: number;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
export declare function letter(score: number): Grade;
|
|
16
|
+
export declare function scoreFindings(findings: readonly Finding[], opts: {
|
|
17
|
+
partial: boolean;
|
|
18
|
+
}): Score;
|
|
19
|
+
//# sourceMappingURL=score.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const POINTS = { info: 0, low: 3, medium: 8, high: 20, critical: 40 };
|
|
2
|
+
const WEIGHT = {
|
|
3
|
+
"tool-poisoning": 1, "hidden-content": 1, shadowing: 1, exfiltration: 1, "secret-exposure": 1, integrity: 0.8, "resource-limit": 1,
|
|
4
|
+
"capability-mismatch": 0.7, hygiene: 0.5, "prompt-injection": 1, "dangerous-action": 0, "rug-pull": 0, "server-request": 0, "toxic-flow": 0,
|
|
5
|
+
obfuscation: 0, "self-protection": 0,
|
|
6
|
+
};
|
|
7
|
+
const CATEGORY_CAP = { "resource-limit": 30, "capability-mismatch": 30, hygiene: 10 };
|
|
8
|
+
const SEV = ["info", "low", "medium", "high", "critical"];
|
|
9
|
+
const NEVER_A = new Set(["tool-poisoning", "shadowing"]);
|
|
10
|
+
/** Name collisions and spoofed names: CP-SHADOW-010 (also shadowing) and CP-HIDDEN-004 (mixed-script names). */
|
|
11
|
+
const NEVER_A_RULES = new Set(["CP-SHADOW-010", "CP-HIDDEN-004"]);
|
|
12
|
+
/**
|
|
13
|
+
* CP-SPOOF-001 ("official", "endorsed by") is filed under tool-poisoning but is a claim, not a
|
|
14
|
+
* spoofed name or an instruction, and fires on benign text such as "Official SDK client.".
|
|
15
|
+
*/
|
|
16
|
+
const NEVER_A_EXCEPT = new Set(["CP-SPOOF-001"]);
|
|
17
|
+
const GRADES = ["A", "B", "C", "D", "F"];
|
|
18
|
+
const worse = (a, b) => (GRADES.indexOf(a) >= GRADES.indexOf(b) ? a : b);
|
|
19
|
+
export function letter(score) {
|
|
20
|
+
return score >= 90 ? "A" : score >= 80 ? "B" : score >= 70 ? "C" : score >= 60 ? "D" : "F";
|
|
21
|
+
}
|
|
22
|
+
export function scoreFindings(findings, opts) {
|
|
23
|
+
const scored = findings
|
|
24
|
+
.filter((f) => f.confidence >= 0.3 && (WEIGHT[f.category] ?? 1) > 0 && POINTS[f.severity] > 0)
|
|
25
|
+
.slice()
|
|
26
|
+
.sort((a, b) => SEV.indexOf(b.severity) - SEV.indexOf(a.severity) || b.confidence - a.confidence || (a.location < b.location ? -1 : a.location > b.location ? 1 : 0));
|
|
27
|
+
// Per rule: repetition factors and a total cap of 2× the first deduction.
|
|
28
|
+
const byRule = new Map();
|
|
29
|
+
for (const f of scored) {
|
|
30
|
+
const list = byRule.get(f.ruleId) ?? [];
|
|
31
|
+
const k = list.length;
|
|
32
|
+
const factor = k === 0 ? 1 : k === 1 ? 0.5 : 0.25;
|
|
33
|
+
list.push({ f, pts: POINTS[f.severity] * f.confidence * (WEIGHT[f.category] ?? 1) * factor });
|
|
34
|
+
byRule.set(f.ruleId, list);
|
|
35
|
+
}
|
|
36
|
+
const perFinding = new Map();
|
|
37
|
+
const byCategory = new Map();
|
|
38
|
+
for (const list of byRule.values()) {
|
|
39
|
+
const first = list[0]?.pts ?? 0;
|
|
40
|
+
const total = list.reduce((a, x) => a + x.pts, 0);
|
|
41
|
+
const scale = total > 2 * first && total > 0 ? (2 * first) / total : 1;
|
|
42
|
+
for (const x of list) {
|
|
43
|
+
const pts = x.pts * scale;
|
|
44
|
+
const cat = byCategory.get(x.f.category) ?? [];
|
|
45
|
+
cat.push({ id: x.f.id, pts });
|
|
46
|
+
byCategory.set(x.f.category, cat);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const [cat, list] of byCategory) {
|
|
50
|
+
const total = list.reduce((a, x) => a + x.pts, 0);
|
|
51
|
+
const cap = CATEGORY_CAP[cat];
|
|
52
|
+
const scale = cap !== undefined && total > cap ? cap / total : 1;
|
|
53
|
+
for (const x of list)
|
|
54
|
+
perFinding.set(x.id, (perFinding.get(x.id) ?? 0) + x.pts * scale);
|
|
55
|
+
}
|
|
56
|
+
const sum = [...perFinding.values()].reduce((a, b) => a + b, 0);
|
|
57
|
+
const score = Math.max(0, Math.round(100 - sum + 1e-9));
|
|
58
|
+
let grade = letter(score);
|
|
59
|
+
const caps = [];
|
|
60
|
+
const confident = findings.filter((f) => f.confidence >= 0.3 && (WEIGHT[f.category] ?? 1) > 0);
|
|
61
|
+
// The worst finding caps the grade (grading rev 7): critical → F, high → D, medium → C.
|
|
62
|
+
const crit = confident.filter((f) => f.severity === "critical");
|
|
63
|
+
if (crit.length)
|
|
64
|
+
caps.push({ cap: "F", reason: "Capped at F: a critical finding was found in the metadata.", findingIds: crit.map((f) => f.id) });
|
|
65
|
+
const hidden = confident.filter((f) => f.category === "hidden-content" && SEV.indexOf(f.severity) >= 2);
|
|
66
|
+
if (hidden.length)
|
|
67
|
+
caps.push({ cap: "D", reason: "Capped at D: hidden content of medium severity or higher was found in the metadata.", findingIds: hidden.map((f) => f.id) });
|
|
68
|
+
const high = confident.filter((f) => f.severity === "high");
|
|
69
|
+
if (high.length)
|
|
70
|
+
caps.push({ cap: "D", reason: "Capped at D: a high-severity finding was found in the metadata.", findingIds: high.map((f) => f.id) });
|
|
71
|
+
const medium = confident.filter((f) => f.severity === "medium");
|
|
72
|
+
if (medium.length)
|
|
73
|
+
caps.push({ cap: "C", reason: "Capped at C: a medium-severity finding was found in the metadata.", findingIds: medium.map((f) => f.id) });
|
|
74
|
+
// Poisoning, shadowing, name collisions and spoofed names never get an A, whatever their severity.
|
|
75
|
+
const never = confident.filter((f) => (NEVER_A.has(f.category) && !NEVER_A_EXCEPT.has(f.ruleId)) || NEVER_A_RULES.has(f.ruleId));
|
|
76
|
+
if (never.length)
|
|
77
|
+
caps.push({ cap: "B", reason: "Capped at B: the metadata shows tool poisoning, shadowing, a name collision or a spoofed name.", findingIds: never.map((f) => f.id) });
|
|
78
|
+
if (opts.partial)
|
|
79
|
+
caps.push({ cap: "B", reason: "Capped at B: the scan hit a limit, so part of the metadata wasn't analyzed.", findingIds: [] });
|
|
80
|
+
for (const c of caps)
|
|
81
|
+
grade = worse(grade, c.cap);
|
|
82
|
+
return {
|
|
83
|
+
score,
|
|
84
|
+
grade,
|
|
85
|
+
caps,
|
|
86
|
+
deductions: [...perFinding].map(([findingId, points]) => ({ findingId, points: Math.round(points * 1000) / 1000 })),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=score.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ActionContext, ActionRisk, AnalyzeOptions, Decision, DiffOptions, Finding, Fingerprint, FingerprintResult, LoadedRuleset, ManifestDiff, RedactOptions, Redacted, ServerReport, SessionContext } from "./types.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
/** Built-in Claude Code tools the engine knows, by category. Any other built-in tool is unanalyzable. */
|
|
4
|
+
export { BUILTIN_TOOLS } from "./action/builtin-tools.js";
|
|
5
|
+
/** Actions that always ask (deny in autopilot), whatever the user set up or the ruleset says. */
|
|
6
|
+
export { HARD_FLOOR_TAGS } from "./policy/decide.js";
|
|
7
|
+
export declare const ENGINE_VERSION: string;
|
|
8
|
+
export declare const EMBEDDED_BASELINE: LoadedRuleset;
|
|
9
|
+
/** The only wording a grade may be presented with. */
|
|
10
|
+
export declare const GRADE_SCOPE_STATEMENT = "A grade checks what a server says about its tools. It doesn't inspect the server's code.";
|
|
11
|
+
export declare function analyzeServer(manifest: unknown, opts?: AnalyzeOptions): ServerReport;
|
|
12
|
+
export declare function fingerprint(manifest: unknown): FingerprintResult;
|
|
13
|
+
export declare function diffFingerprints(prev: Fingerprint, next: Fingerprint, opts?: DiffOptions): ManifestDiff;
|
|
14
|
+
export declare function checkToolCall(input: unknown, ctx: SessionContext): Decision;
|
|
15
|
+
export declare function checkToolResult(input: unknown, ctx: SessionContext): Decision;
|
|
16
|
+
export declare function checkServerRequest(input: unknown, ctx: SessionContext): Decision;
|
|
17
|
+
export declare function classifyAction(input: unknown, ctx?: ActionContext): ActionRisk;
|
|
18
|
+
export declare function redact(value: unknown, opts?: RedactOptions): Redacted;
|
|
19
|
+
export declare function renderForModel(findings: readonly Finding[]): string;
|
|
20
|
+
/** Splits Claude Code tool names: mcp__<server>__<tool> and mcp__plugin_<plugin>_<server>__<tool>. */
|
|
21
|
+
export declare function parseClaudeCodeToolName(name: string): {
|
|
22
|
+
serverId: string;
|
|
23
|
+
toolName: string;
|
|
24
|
+
plugin?: string;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// @glassbox-ai/engine public API. Every function is synchronous, pure and
|
|
2
|
+
// total: none of them throws, and a failure never becomes a silent allow.
|
|
3
|
+
import { classifyBuiltin, classifyMcp } from "./action/tools.js";
|
|
4
|
+
import { pathCtxFrom } from "./action/paths.js";
|
|
5
|
+
import { DEFAULT_LIMITS } from "./limits.js";
|
|
6
|
+
import { analyzeServerImpl } from "./analysis/manifest.js";
|
|
7
|
+
import { checkServerRequestImpl, checkToolCallImpl, checkToolResultImpl, errorDecision, HIGH_RISK_UNKNOWN, intake } from "./analysis/gate.js";
|
|
8
|
+
import { renderForModel as render } from "./evidence/evidence.js";
|
|
9
|
+
import { fingerprintOf } from "./fingerprint/fingerprint.js";
|
|
10
|
+
import { diffImpl } from "./fingerprint/diff.js";
|
|
11
|
+
import { EMBEDDED_BASELINE as BASELINE } from "./ruleset/baseline.js";
|
|
12
|
+
import { redact as redactImpl } from "./secrets/redact.js";
|
|
13
|
+
import { scoreFindings } from "./grade/score.js";
|
|
14
|
+
import { get, getString, isRecord } from "./util/misc.js";
|
|
15
|
+
import { ENGINE_VERSION as VERSION } from "./version.js";
|
|
16
|
+
import { resolveLimits } from "./limits.js";
|
|
17
|
+
export * from "./types.js";
|
|
18
|
+
/** Built-in Claude Code tools the engine knows, by category. Any other built-in tool is unanalyzable. */
|
|
19
|
+
export { BUILTIN_TOOLS } from "./action/builtin-tools.js";
|
|
20
|
+
/** Actions that always ask (deny in autopilot), whatever the user set up or the ruleset says. */
|
|
21
|
+
export { HARD_FLOOR_TAGS } from "./policy/decide.js";
|
|
22
|
+
export const ENGINE_VERSION = VERSION;
|
|
23
|
+
export const EMBEDDED_BASELINE = BASELINE;
|
|
24
|
+
/** The only wording a grade may be presented with. */
|
|
25
|
+
export const GRADE_SCOPE_STATEMENT = "A grade checks what a server says about its tools. It doesn't inspect the server's code.";
|
|
26
|
+
const t = () => performance.now();
|
|
27
|
+
export function analyzeServer(manifest, opts) {
|
|
28
|
+
const t0 = t();
|
|
29
|
+
try {
|
|
30
|
+
return analyzeServerImpl(manifest, isRecord(opts) ? opts : undefined, t0);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
const s = scoreFindings([], { partial: true });
|
|
34
|
+
const fp = fingerprintOf(null, DEFAULT_LIMITS);
|
|
35
|
+
return {
|
|
36
|
+
grade: "F", score: 0, partial: true, caps: [{ cap: "F", reason: "Capped at F: the metadata couldn't be analyzed.", findingIds: [] }], deductions: s.deductions,
|
|
37
|
+
findings: [], capabilityProfile: [], scope: "metadata-only", fingerprint: fp, rulesetVersion: "unknown", engineVersion: VERSION,
|
|
38
|
+
degraded: true, degradedReasons: ["internal-error"], elapsedMs: Math.max(0, t() - t0),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function fingerprint(manifest) {
|
|
43
|
+
try {
|
|
44
|
+
const ink = intake(manifest, DEFAULT_LIMITS);
|
|
45
|
+
if (ink.tooBig || !isRecord(ink.value))
|
|
46
|
+
return { ok: false, findings: [], degraded: true };
|
|
47
|
+
return { ok: true, fingerprint: fingerprintOf(ink.value, DEFAULT_LIMITS), findings: [] };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return { ok: false, findings: [], degraded: true };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function diffFingerprints(prev, next, opts) {
|
|
54
|
+
try {
|
|
55
|
+
return diffImpl(prev, next, isRecord(opts) ? opts : undefined);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return { changed: true, changes: [{ kind: "fingerprint-incomparable", item: "", pointer: "", detail: "the fingerprints can't be compared" }], findings: [], degraded: true };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function checkToolCall(input, ctx) {
|
|
62
|
+
const t0 = t();
|
|
63
|
+
try {
|
|
64
|
+
return checkToolCallImpl(input, ctx, t0);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return errorDecision(t0, modeOf(ctx));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function checkToolResult(input, ctx) {
|
|
71
|
+
const t0 = t();
|
|
72
|
+
try {
|
|
73
|
+
return checkToolResultImpl(input, ctx, t0);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return errorDecision(t0, modeOf(ctx), { ...HIGH_RISK_UNKNOWN, level: "read" });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function checkServerRequest(input, ctx) {
|
|
80
|
+
const t0 = t();
|
|
81
|
+
try {
|
|
82
|
+
return checkServerRequestImpl(input, ctx, t0);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return errorDecision(t0, modeOf(ctx));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function modeOf(ctx) {
|
|
89
|
+
try {
|
|
90
|
+
const m = getString(get(ctx, "policy"), "mode");
|
|
91
|
+
return m === "strict" || m === "balanced" || m === "autopilot" ? m : undefined;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export function classifyAction(input, ctx) {
|
|
98
|
+
try {
|
|
99
|
+
const limits = resolveLimits(undefined);
|
|
100
|
+
const ink = intake(input, limits);
|
|
101
|
+
const v = ink.value;
|
|
102
|
+
const serverId = getString(v, "serverId");
|
|
103
|
+
const toolName = getString(v, "toolName");
|
|
104
|
+
if (serverId === undefined || toolName === undefined)
|
|
105
|
+
return HIGH_RISK_UNKNOWN;
|
|
106
|
+
const c = (isRecord(ctx) ? ctx : {});
|
|
107
|
+
const pctx = pathCtxFrom({
|
|
108
|
+
platform: c.platform === "win32" || c.platform === "darwin" ? c.platform : "linux",
|
|
109
|
+
homeDir: typeof c.homeDir === "string" ? c.homeDir : "/home/unknown",
|
|
110
|
+
cwd: typeof c.cwd === "string" ? c.cwd : null,
|
|
111
|
+
caseInsensitiveFs: c.caseInsensitiveFs === true,
|
|
112
|
+
glassboxDirs: Array.isArray(c.glassboxDirs) ? c.glassboxDirs : [],
|
|
113
|
+
});
|
|
114
|
+
const tc = { pctx, maxCommandBytes: limits.maxCommandBytes, maxSqlBytes: limits.maxSqlBytes };
|
|
115
|
+
const args = get(v, "arguments") ?? Object.create(null);
|
|
116
|
+
const acc = serverId === "builtin" ? classifyBuiltin(toolName, args, tc) : classifyMcp(toolName, args, isRecord(get(v, "descriptor")) ? get(v, "descriptor") : undefined, tc).acc;
|
|
117
|
+
return { level: acc.level, tags: [...acc.tags].sort(), unanalyzable: acc.unanalyzableFlag, selfProtection: acc.selfProtection, reasons: [...acc.reasons, ...acc.unanalyzableReasons].slice(0, 20) };
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return HIGH_RISK_UNKNOWN;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function redact(value, opts) {
|
|
124
|
+
return redactImpl(value, isRecord(opts) ? opts : undefined);
|
|
125
|
+
}
|
|
126
|
+
export function renderForModel(findings) {
|
|
127
|
+
return render(findings);
|
|
128
|
+
}
|
|
129
|
+
/** Splits Claude Code tool names: mcp__<server>__<tool> and mcp__plugin_<plugin>_<server>__<tool>. */
|
|
130
|
+
export function parseClaudeCodeToolName(name) {
|
|
131
|
+
try {
|
|
132
|
+
if (typeof name !== "string" || !name.startsWith("mcp__"))
|
|
133
|
+
return { serverId: "builtin", toolName: typeof name === "string" ? name : "" };
|
|
134
|
+
const rest = name.slice(5);
|
|
135
|
+
const sep = rest.indexOf("__");
|
|
136
|
+
if (sep < 0)
|
|
137
|
+
return { serverId: "builtin", toolName: name };
|
|
138
|
+
const server = rest.slice(0, sep);
|
|
139
|
+
const tool = rest.slice(sep + 2);
|
|
140
|
+
if (server.startsWith("plugin_")) {
|
|
141
|
+
const p = server.slice(7);
|
|
142
|
+
const u = p.indexOf("_");
|
|
143
|
+
if (u > 0)
|
|
144
|
+
return { serverId: p.slice(u + 1), toolName: tool, plugin: p.slice(0, u) };
|
|
145
|
+
}
|
|
146
|
+
return { serverId: server, toolName: tool };
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return { serverId: "builtin", toolName: "" };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface IntakeIssue {
|
|
2
|
+
code: string;
|
|
3
|
+
pointer?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ParseResult {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
value: unknown;
|
|
8
|
+
issues: IntakeIssue[];
|
|
9
|
+
degraded: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ParseOptions {
|
|
12
|
+
maxDepth?: number;
|
|
13
|
+
maxNodes?: number;
|
|
14
|
+
maxStringBytes?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseJsonStrict(input: string | Uint8Array, opts?: ParseOptions): ParseResult;
|
|
17
|
+
//# sourceMappingURL=json.d.ts.map
|