@osd-project/osd-cli 0.0.0 → 0.8.3

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.
Files changed (52) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +585 -4
  3. package/THIRD_PARTY_NOTICES.md +96 -0
  4. package/dist/auth-store.d.ts +38 -0
  5. package/dist/auth-store.js +239 -0
  6. package/dist/brand-catalog.d.ts +65 -0
  7. package/dist/brand-catalog.js +175 -0
  8. package/dist/connect-gate.d.ts +31 -0
  9. package/dist/connect-gate.js +82 -0
  10. package/dist/contracts.d.ts +61 -0
  11. package/dist/contracts.js +145 -0
  12. package/dist/exit-codes.d.ts +32 -0
  13. package/dist/exit-codes.js +40 -0
  14. package/dist/format.d.ts +71 -0
  15. package/dist/format.js +99 -0
  16. package/dist/generated/schemas.d.ts +2 -0
  17. package/dist/generated/schemas.js +1781 -0
  18. package/dist/guarded-fetch.d.ts +28 -0
  19. package/dist/guarded-fetch.js +252 -0
  20. package/dist/help.d.ts +27 -0
  21. package/dist/help.js +32 -0
  22. package/dist/http-fetch.d.ts +1 -0
  23. package/dist/http-fetch.js +17 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +821 -0
  26. package/dist/logout.d.ts +16 -0
  27. package/dist/logout.js +82 -0
  28. package/dist/mcp-auth.d.ts +70 -0
  29. package/dist/mcp-auth.js +603 -0
  30. package/dist/mcp-card.d.ts +23 -0
  31. package/dist/mcp-card.js +18 -0
  32. package/dist/mcp-client.d.ts +77 -0
  33. package/dist/mcp-client.js +193 -0
  34. package/dist/net-guard.d.ts +66 -0
  35. package/dist/net-guard.js +152 -0
  36. package/dist/proxy-config.d.ts +51 -0
  37. package/dist/proxy-config.js +147 -0
  38. package/dist/request.d.ts +32 -0
  39. package/dist/request.js +62 -0
  40. package/dist/resolve-endpoint.d.ts +62 -0
  41. package/dist/resolve-endpoint.js +172 -0
  42. package/dist/search.d.ts +39 -0
  43. package/dist/search.js +69 -0
  44. package/dist/skill.d.ts +155 -0
  45. package/dist/skill.js +320 -0
  46. package/dist/updates.d.ts +101 -0
  47. package/dist/updates.js +541 -0
  48. package/dist/verify.d.ts +92 -0
  49. package/dist/verify.js +379 -0
  50. package/package.json +51 -3
  51. package/skill/osd/SKILL.md +400 -0
  52. package/skill/osd/references/connect-mcp.md +48 -0
package/dist/verify.js ADDED
@@ -0,0 +1,379 @@
1
+ import { fetchBrandCatalog, normalizeBrandDomain } from "./brand-catalog.js";
2
+ import { ExitCode } from "./exit-codes.js";
3
+ import { schemasAvailable, supportsLocalContractVersion, validateCatalog, validateCatalogEntry, } from "./contracts.js";
4
+ /**
5
+ * Structural verification: a registry candidate is brand-endorsed iff
6
+ * it exactly matches one entry in the brand domain's own published catalog.
7
+ *
8
+ * The match is structural only. A "verified" verdict means the bytes agree,
9
+ * not that any signature or identity claim was checked (there is no
10
+ * cryptographic validation in v1).
11
+ */
12
+ /**
13
+ * Marks the missing side of a field present on only one side of a diff.
14
+ * A unique symbol so no real JSON value can collide with it; rendered as the
15
+ * string "ABSENT" at output boundaries via renderDiffValue.
16
+ */
17
+ export const ABSENT = Symbol("osd.verify.ABSENT");
18
+ /** Maps the ABSENT sentinel to its wire string for human/--json output. */
19
+ export function renderDiffValue(value) {
20
+ return value === ABSENT ? "ABSENT" : value;
21
+ }
22
+ /**
23
+ * Resolver-added annotation keys excluded from comparison. Stripped
24
+ * from the TOP LEVEL of the REGISTRY side only, never recursively: the brand
25
+ * side is published entry data where every field participates, and
26
+ * trustManifest.provenance inside either side is entry data too.
27
+ *
28
+ * Exception at the anchored comparison: when the brand entry itself carries
29
+ * one of these keys, that key is genuine published entry data, so it stays on
30
+ * both sides and participates in the match. Stripping it unconditionally
31
+ * would make such an entry un-verifiable (brand key vs registry ABSENT on
32
+ * every byte-identical pair). Reserving this vocabulary in the catalogEntry
33
+ * schema is tracked as a follow-up, which will make the collision
34
+ * schema-invalid instead of a runtime concern.
35
+ */
36
+ const ANNOTATION_KEYS = new Set(["score", "source", "provenance", "warnings", "conflicts", "verification"]);
37
+ function stripAnnotations(entry, brandEntry) {
38
+ return Object.fromEntries(Object.entries(entry).filter(([key]) => !ANNOTATION_KEYS.has(key) || (brandEntry !== undefined && Object.hasOwn(brandEntry, key))));
39
+ }
40
+ function isPlainObject(value) {
41
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42
+ }
43
+ /**
44
+ * Canonical serialization for equality: object keys sorted, array elements
45
+ * sorted by their own canonical form (all contract arrays are unordered).
46
+ */
47
+ function canonical(value) {
48
+ if (Array.isArray(value)) {
49
+ return `[${value.map(canonical).sort().join(",")}]`;
50
+ }
51
+ if (isPlainObject(value)) {
52
+ const entries = Object.keys(value)
53
+ .sort()
54
+ .map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`);
55
+ return `{${entries.join(",")}}`;
56
+ }
57
+ return JSON.stringify(value) ?? "undefined";
58
+ }
59
+ /**
60
+ * Comparison recursion is depth-bounded so a hostile or pathological payload
61
+ * cannot overflow the stack (canonical/duplicate scans recurse per level).
62
+ * 512 is far beyond any legitimate catalog entry.
63
+ */
64
+ const MAX_COMPARISON_DEPTH = 512;
65
+ function exceedsDepth(value, depth = 0) {
66
+ if (depth > MAX_COMPARISON_DEPTH)
67
+ return true;
68
+ if (Array.isArray(value))
69
+ return value.some((element) => exceedsDepth(element, depth + 1));
70
+ if (isPlainObject(value))
71
+ return Object.values(value).some((nested) => exceedsDepth(nested, depth + 1));
72
+ return false;
73
+ }
74
+ /**
75
+ * Path of the first array containing duplicate members, or null. Duplicate
76
+ * members of an unordered array are treated as invalid input, on either
77
+ * side of the comparison.
78
+ */
79
+ function firstDuplicateArrayPath(value, path) {
80
+ if (Array.isArray(value)) {
81
+ const seen = new Set();
82
+ for (const element of value) {
83
+ const form = canonical(element);
84
+ if (seen.has(form))
85
+ return path === "" ? "/" : path;
86
+ seen.add(form);
87
+ }
88
+ for (let i = 0; i < value.length; i++) {
89
+ const nested = firstDuplicateArrayPath(value[i], `${path}/${i}`);
90
+ if (nested !== null)
91
+ return nested;
92
+ }
93
+ return null;
94
+ }
95
+ if (isPlainObject(value)) {
96
+ for (const [key, nested] of Object.entries(value)) {
97
+ const found = firstDuplicateArrayPath(nested, `${path}/${key}`);
98
+ if (found !== null)
99
+ return found;
100
+ }
101
+ }
102
+ return null;
103
+ }
104
+ function diffInto(path, registryValue, brandValue, out) {
105
+ if (registryValue === ABSENT || brandValue === ABSENT) {
106
+ out.push({ path, registryValue, brandValue });
107
+ return;
108
+ }
109
+ if (canonical(registryValue) === canonical(brandValue))
110
+ return;
111
+ if (isPlainObject(registryValue) && isPlainObject(brandValue)) {
112
+ const keys = new Set([...Object.keys(registryValue), ...Object.keys(brandValue)]);
113
+ for (const key of [...keys].sort()) {
114
+ diffInto(`${path}/${key}`, Object.hasOwn(registryValue, key) ? registryValue[key] : ABSENT, Object.hasOwn(brandValue, key) ? brandValue[key] : ABSENT, out);
115
+ }
116
+ return;
117
+ }
118
+ out.push({ path, registryValue, brandValue });
119
+ }
120
+ /**
121
+ * Field-level structural diff between a registry candidate and a brand
122
+ * catalog entry. An empty diff means the entries match. Only the
123
+ * registry side is stripped of resolver annotations, and only for keys the
124
+ * brand entry does not itself carry (see ANNOTATION_KEYS). Arrays compare as
125
+ * multisets; objects compare key-order-free; no string normalization of any
126
+ * kind (a trailing slash is a mismatch).
127
+ */
128
+ export function compareEntries(registryEntry, brandEntry) {
129
+ const out = [];
130
+ const brand = isPlainObject(brandEntry) ? brandEntry : undefined;
131
+ diffInto("", stripAnnotations(registryEntry, brand), brandEntry, out);
132
+ return out;
133
+ }
134
+ function isRecord(value) {
135
+ return typeof value === "object" && value !== null && !Array.isArray(value);
136
+ }
137
+ /** Extracts the selected contract version's authoritative brand-domain field. */
138
+ export function extractBrandDomain(candidate, contractVersion) {
139
+ if (!isRecord(candidate))
140
+ return undefined;
141
+ if (contractVersion === "0.3.0") {
142
+ return candidate["osd:brandDomain"];
143
+ }
144
+ if (contractVersion !== "0.1.0")
145
+ return undefined;
146
+ const metadata = candidate.metadata;
147
+ if (!isRecord(metadata))
148
+ return undefined;
149
+ const osd = metadata.osd;
150
+ if (!isRecord(osd))
151
+ return undefined;
152
+ return osd.brandDomain;
153
+ }
154
+ /**
155
+ * Parses and validates a fetched catalog ONCE per fetch: JSON parse, schema
156
+ * validation, depth guard, duplicate-member scan. Returns either the prepared
157
+ * entries or the malformedCatalog outcome for the whole batch.
158
+ */
159
+ function prepareCatalog(fetched, contractVersion) {
160
+ let catalog;
161
+ try {
162
+ catalog = JSON.parse(fetched.body);
163
+ }
164
+ catch {
165
+ return { kind: "malformedCatalog", message: `${fetched.catalogUrl} did not return valid JSON` };
166
+ }
167
+ const validation = validateCatalog(catalog, contractVersion);
168
+ if (!validation.valid) {
169
+ return {
170
+ kind: "malformedCatalog",
171
+ message: `${fetched.catalogUrl} failed catalog validation: ${validation.errors.join("; ")}`,
172
+ };
173
+ }
174
+ if (validation.skipped) {
175
+ return { kind: "malformedCatalog", message: `cannot validate catalog: ${validation.reason}` };
176
+ }
177
+ if (exceedsDepth(catalog)) {
178
+ return {
179
+ kind: "malformedCatalog",
180
+ message: `${fetched.catalogUrl} is nested too deeply to compare (>${MAX_COMPARISON_DEPTH} levels)`,
181
+ };
182
+ }
183
+ const duplicatePath = firstDuplicateArrayPath(catalog, "");
184
+ if (duplicatePath !== null) {
185
+ return {
186
+ kind: "malformedCatalog",
187
+ message: `${fetched.catalogUrl} has duplicate members in an unordered array at ${duplicatePath}`,
188
+ };
189
+ }
190
+ return { entries: catalog.entries, catalogUrl: fetched.catalogUrl };
191
+ }
192
+ /**
193
+ * Entry selection: verified iff ANY catalog entry
194
+ * structurally matches; else mismatch with a diff against the entry sharing
195
+ * the candidate's identifier; else no_match.
196
+ */
197
+ function selectVerdict(candidate, catalog) {
198
+ for (const entry of catalog.entries) {
199
+ if (compareEntries(candidate, entry).length === 0) {
200
+ return { kind: "verified", catalogUrl: catalog.catalogUrl };
201
+ }
202
+ }
203
+ const candidateIdentifier = stripAnnotations(candidate).identifier;
204
+ const sameIdentifier = catalog.entries.find((entry) => entry.identifier === candidateIdentifier);
205
+ if (sameIdentifier !== undefined) {
206
+ return { kind: "mismatch", catalogUrl: catalog.catalogUrl, diff: compareEntries(candidate, sameIdentifier) };
207
+ }
208
+ return { kind: "noMatch", catalogUrl: catalog.catalogUrl };
209
+ }
210
+ /** Candidate-side conformance checks shared by standalone verify and search --verify. */
211
+ function candidateProblem(candidate, contractVersion) {
212
+ if (!isRecord(candidate)) {
213
+ return "candidate must be a single catalog entry object";
214
+ }
215
+ const validation = validateCatalogEntry(candidate, contractVersion);
216
+ if (!validation.valid) {
217
+ return `candidate does not conform to osd-catalog-entry: ${validation.errors.join("; ")}`;
218
+ }
219
+ if (exceedsDepth(candidate)) {
220
+ return `candidate is nested too deeply to compare (>${MAX_COMPARISON_DEPTH} levels)`;
221
+ }
222
+ const duplicatePath = firstDuplicateArrayPath(stripAnnotations(candidate), "");
223
+ if (duplicatePath !== null) {
224
+ return `candidate has duplicate members in an unordered array at ${duplicatePath}`;
225
+ }
226
+ return null;
227
+ }
228
+ /**
229
+ * Verifies one candidate against its brand domain's published catalog.
230
+ * Makes no trust decision: the outcome says whether the brand's own domain
231
+ * endorses the candidate structurally; what to do with that is the caller's.
232
+ */
233
+ export async function runVerify(options) {
234
+ if (!schemasAvailable()) {
235
+ return { kind: "schemasMissing" };
236
+ }
237
+ if (!supportsLocalContractVersion(options.contractVersion)) {
238
+ return { kind: "unsupportedContractVersion", contractVersion: options.contractVersion };
239
+ }
240
+ const problem = candidateProblem(options.candidate, options.contractVersion);
241
+ if (problem !== null) {
242
+ return { kind: "invalidCandidate", message: problem };
243
+ }
244
+ const candidate = options.candidate;
245
+ const fetched = await fetchBrandCatalog(extractBrandDomain(candidate, options.contractVersion), options.contractVersion, {
246
+ lookup: options.lookup,
247
+ });
248
+ switch (fetched.kind) {
249
+ case "invalidBrandDomain":
250
+ return { kind: "invalidCandidate", message: fetched.message };
251
+ case "unsupportedContractVersion":
252
+ return { kind: "unsupportedContractVersion", contractVersion: fetched.contractVersion };
253
+ case "unreachable":
254
+ return { kind: "unreachable", message: fetched.message, catalogUrl: fetched.catalogUrl };
255
+ case "ok": {
256
+ const prepared = prepareCatalog(fetched, options.contractVersion);
257
+ if ("kind" in prepared) {
258
+ return prepared;
259
+ }
260
+ return selectVerdict(candidate, prepared);
261
+ }
262
+ }
263
+ }
264
+ function annotationFor(outcome) {
265
+ switch (outcome.kind) {
266
+ case "verified":
267
+ return { verdict: "verified", catalogUrl: outcome.catalogUrl };
268
+ case "mismatch":
269
+ return {
270
+ verdict: "mismatch",
271
+ catalogUrl: outcome.catalogUrl,
272
+ diff: outcome.diff.map((entry) => ({
273
+ path: entry.path,
274
+ registryValue: renderDiffValue(entry.registryValue),
275
+ brandValue: renderDiffValue(entry.brandValue),
276
+ })),
277
+ };
278
+ case "noMatch":
279
+ return { verdict: "no_match", catalogUrl: outcome.catalogUrl };
280
+ case "unreachable":
281
+ // Carry catalogUrl so the human output can print the
282
+ // structural-match disclosure note for this result too.
283
+ return outcome.catalogUrl === undefined
284
+ ? { verdict: "unreachable", detail: outcome.message }
285
+ : { verdict: "unreachable", detail: outcome.message, catalogUrl: outcome.catalogUrl };
286
+ case "malformedCatalog":
287
+ return { verdict: "malformed", detail: outcome.message };
288
+ case "invalidCandidate":
289
+ return { verdict: "invalid", detail: outcome.message };
290
+ case "unsupportedContractVersion":
291
+ return { verdict: "invalid", detail: `unsupported contract version ${outcome.contractVersion}` };
292
+ case "schemasMissing":
293
+ return { verdict: "invalid", detail: "embedded contract schemas missing" };
294
+ }
295
+ }
296
+ /**
297
+ * Annotates every search result with a `verification` object (attached to the
298
+ * result data itself, so both human and --json output carry it). Fetches one
299
+ * catalog per distinct (normalized) brandDomain, in parallel, and parses it
300
+ * once per domain. Never throws; the search command maps the worst verdict
301
+ * onto its exit code via exitCodeForVerification.
302
+ */
303
+ export async function verifySearchResults(results, contractVersion, options = {}) {
304
+ const byHost = new Map();
305
+ for (const result of results) {
306
+ // A schema-invalid registry response is tolerated upstream as
307
+ // success-with-warnings, so items can be non-objects at runtime; they
308
+ // cannot carry an annotation, and this function must never throw.
309
+ if (!isRecord(result))
310
+ continue;
311
+ const rawDomain = extractBrandDomain(result, contractVersion);
312
+ if (typeof rawDomain !== "string") {
313
+ result.verification = { verdict: "invalid", detail: "result has no OSD brand domain" };
314
+ continue;
315
+ }
316
+ // Dedup fetches by normalized host; invalid spellings still group together
317
+ // and fail fast in the fetcher (no lookup, no network).
318
+ const host = normalizeBrandDomain(rawDomain) ?? rawDomain;
319
+ const group = byHost.get(host) ?? [];
320
+ group.push(result);
321
+ byHost.set(host, group);
322
+ }
323
+ await Promise.all([...byHost.entries()].map(async ([host, group]) => {
324
+ const fetched = await fetchBrandCatalog(host, contractVersion, { lookup: options.lookup });
325
+ const prepared = fetched.kind === "ok" ? prepareCatalog(fetched, contractVersion) : null;
326
+ for (const result of group) {
327
+ let outcome;
328
+ if (fetched.kind !== "ok") {
329
+ outcome =
330
+ fetched.kind === "invalidBrandDomain"
331
+ ? { kind: "invalidCandidate", message: fetched.message }
332
+ : fetched.kind === "unsupportedContractVersion"
333
+ ? { kind: "unsupportedContractVersion", contractVersion: fetched.contractVersion }
334
+ : { kind: "unreachable", message: fetched.message, catalogUrl: fetched.catalogUrl };
335
+ }
336
+ else if (prepared !== null && "kind" in prepared) {
337
+ outcome = prepared;
338
+ }
339
+ else if (prepared !== null) {
340
+ const problem = candidateProblem(result, contractVersion);
341
+ outcome = problem !== null ? { kind: "invalidCandidate", message: problem } : selectVerdict(result, prepared);
342
+ }
343
+ else {
344
+ outcome = { kind: "unreachable", message: "catalog was not fetched" };
345
+ }
346
+ result.verification = annotationFor(outcome);
347
+ }
348
+ }));
349
+ }
350
+ /**
351
+ * Maps per-result verification annotations to the `search --verify` exit
352
+ * code: the worst verdict wins -- mismatch (6, definitive conflict) over
353
+ * no_match (5) over the inconclusive-or-broken verdicts unreachable, invalid
354
+ * and malformed (1). No results, or all verified, stays Success.
355
+ */
356
+ export function exitCodeForVerification(results) {
357
+ let worst = ExitCode.Success;
358
+ for (const result of results) {
359
+ // Same tolerance as verifySearchResults: a schema-invalid response can
360
+ // carry non-object items, and this function must never throw.
361
+ if (!isRecord(result))
362
+ continue;
363
+ const verdict = result.verification?.verdict;
364
+ switch (verdict) {
365
+ case undefined:
366
+ case "verified":
367
+ continue;
368
+ case "mismatch":
369
+ return ExitCode.Mismatch;
370
+ case "no_match":
371
+ worst = ExitCode.NoMatch;
372
+ continue;
373
+ default:
374
+ if (worst === ExitCode.Success)
375
+ worst = ExitCode.GeneralError;
376
+ }
377
+ }
378
+ return worst;
379
+ }
package/package.json CHANGED
@@ -1,10 +1,58 @@
1
1
  {
2
2
  "name": "@osd-project/osd-cli",
3
- "version": "0.0.0",
4
- "description": "Placeholder for the first npm publish. The real package is published from https://github.com/osd-project/osd-cli",
3
+ "version": "0.8.3",
4
+ "description": "Search OSD registries, verify candidates, and use discovered MCP endpoints.",
5
5
  "license": "Apache-2.0",
6
+ "type": "module",
7
+ "bin": {
8
+ "osd": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "skill",
13
+ "THIRD_PARTY_NOTICES.md"
14
+ ],
15
+ "engines": {
16
+ "node": ">=22.19.0"
17
+ },
18
+ "dependencies": {
19
+ "@modelcontextprotocol/client": "2.4.0",
20
+ "ajv": "^8.17.1",
21
+ "ajv-formats": "^3.0.1",
22
+ "commander": "^13.1.0",
23
+ "ipaddr.js": "^2.5.0",
24
+ "jsonc-parser": "^3.3.1",
25
+ "open": "^11.0.4",
26
+ "undici": "^8.12.2"
27
+ },
28
+ "devDependencies": {
29
+ "@modelcontextprotocol/server": "2.4.0",
30
+ "@types/node": "^22.12.0",
31
+ "selfsigned": "^5.5.0",
32
+ "tsx": "^4.19.2",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^4.1.11",
35
+ "zod": "^4.6.6"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
6
40
  "repository": {
7
41
  "type": "git",
8
42
  "url": "git+https://github.com/osd-project/osd-cli.git"
43
+ },
44
+ "homepage": "https://github.com/osd-project/osd-cli#readme",
45
+ "bugs": {
46
+ "url": "https://github.com/osd-project/osd-cli/issues"
47
+ },
48
+ "scripts": {
49
+ "build": "pnpm run gen-schemas && pnpm run gen-skill && tsc -p tsconfig.json",
50
+ "gen-schemas": "node scripts/gen-schemas.mjs",
51
+ "gen-skill": "node scripts/gen-skill.mjs",
52
+ "dev": "pnpm run gen-schemas && pnpm run gen-skill && tsx src/index.ts",
53
+ "typecheck": "pnpm run gen-schemas && pnpm run gen-skill && tsc -p tsconfig.json --noEmit",
54
+ "test": "pnpm run build && vitest run",
55
+ "e2e": "vitest run --config e2e/vitest.config.ts",
56
+ "e2e:typecheck": "tsc -p e2e/tsconfig.json"
9
57
  }
10
- }
58
+ }