@osd-project/osd-cli 0.0.0-stage → 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 -2
  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 +55 -3
  51. package/skill/osd/SKILL.md +400 -0
  52. package/skill/osd/references/connect-mcp.md +48 -0
@@ -0,0 +1,82 @@
1
+ import { ExitCode } from "./exit-codes.js";
2
+ import { runSearch } from "./search.js";
3
+ import { runVerify } from "./verify.js";
4
+ function refused(message, exitCode) {
5
+ return { kind: "refused", message, exitCode };
6
+ }
7
+ /**
8
+ * Looks the target up in the directory by exact url and verifies the single
9
+ * listing that claims it. Any doubt -- not listed, ambiguous, unverifiable,
10
+ * or a directory that cannot answer -- is a refusal.
11
+ */
12
+ export async function checkTargetVerified(target, options) {
13
+ const outcome = await runSearch({
14
+ target: options.registry,
15
+ // The contract requires non-empty text; the exact-url filter is what
16
+ // selects here, so scoring against the URL-as-text is irrelevant.
17
+ text: target,
18
+ filters: [`url=${target}`, "type=application/mcp-server-card+json"],
19
+ contractVersion: options.contractVersion,
20
+ // The gate's guarantee is "listed in THIS directory" -- a federated
21
+ // peer's curation must not satisfy it (and can cause false ambiguity).
22
+ federation: "none",
23
+ });
24
+ switch (outcome.kind) {
25
+ case "success":
26
+ break;
27
+ case "unreachable":
28
+ return refused(`the directory could not confirm the target: ${outcome.message}`, ExitCode.Unreachable);
29
+ case "error":
30
+ // A registry that predates the url filter rejects the url filter with HTTP 400
31
+ // INVALID_ARGUMENT ("Unsupported filter") -- that is still "the
32
+ // directory could not confirm the target", not a usage error.
33
+ return refused(`the directory could not confirm the target: HTTP ${outcome.status} ${outcome.error.errorCode}: ${outcome.error.message}`, ExitCode.GeneralError);
34
+ case "malformed":
35
+ return refused(`the directory could not confirm the target: registry returned HTTP ${outcome.status} with a body that is not a valid response.`, ExitCode.GeneralError);
36
+ case "unsupportedContractVersion":
37
+ return refused(`the directory could not confirm the target: unsupported local contract version "${outcome.contractVersion}".`, ExitCode.GeneralError);
38
+ case "schemasMissing":
39
+ return refused("the directory could not confirm the target: this build is missing its embedded contract schemas -- reinstall @osd-project/osd-cli.", ExitCode.GeneralError);
40
+ }
41
+ const results = outcome.response.results;
42
+ if (results.length === 0) {
43
+ return refused(`the target is not listed in the directory: ${target}`, ExitCode.NoMatch);
44
+ }
45
+ if (results.length > 1) {
46
+ return refused(`ambiguous: multiple listings claim this url: ${target}`, ExitCode.GeneralError);
47
+ }
48
+ // The caller connects to the URL it was handed, so the verified listing
49
+ // must claim that exact URL -- do not let registry filter semantics drift
50
+ // turn "verified X" into "connected to Y".
51
+ if (results[0].url !== target) {
52
+ return refused(`the directory's listing for this url does not match the target exactly: ${results[0].url}`, ExitCode.NoMatch);
53
+ }
54
+ const verdict = await runVerify({
55
+ candidate: results[0],
56
+ contractVersion: options.contractVersion,
57
+ lookup: options.lookup,
58
+ });
59
+ switch (verdict.kind) {
60
+ case "verified":
61
+ return { kind: "verified" };
62
+ case "noMatch":
63
+ return refused(`verification verdict no_match: the brand's catalog lists no such entry (${verdict.catalogUrl})`, ExitCode.NoMatch);
64
+ case "mismatch": {
65
+ const paths = verdict.diff
66
+ .map((entry) => entry.path)
67
+ .slice(0, 3)
68
+ .join(", ");
69
+ return refused(`verification verdict mismatch: the brand's catalog disagrees on ${paths} (${verdict.catalogUrl})`, ExitCode.Mismatch);
70
+ }
71
+ case "unreachable":
72
+ return refused(`verification verdict unreachable: ${verdict.message}`, ExitCode.Unreachable);
73
+ case "malformedCatalog":
74
+ return refused(`verification verdict malformed: ${verdict.message}`, ExitCode.GeneralError);
75
+ case "invalidCandidate":
76
+ return refused(`verification verdict invalid: ${verdict.message}`, ExitCode.GeneralError);
77
+ case "unsupportedContractVersion":
78
+ return refused(`verification verdict invalid: unsupported local contract version "${verdict.contractVersion}"`, ExitCode.GeneralError);
79
+ case "schemasMissing":
80
+ return refused("verification verdict invalid: this build is missing its embedded contract schemas -- reinstall @osd-project/osd-cli.", ExitCode.GeneralError);
81
+ }
82
+ }
@@ -0,0 +1,61 @@
1
+ export declare const DEFAULT_CONTRACT_VERSION = "0.3.0";
2
+ /**
3
+ * Whether this CLI carries the named schema for the given contract version.
4
+ *
5
+ * Schemas are embedded at build time (src/generated/schemas.ts, produced by
6
+ * scripts/gen-schemas.mjs from the repository's normative contracts/
7
+ * directory), so this is a pure in-memory lookup: no filesystem access, no
8
+ * install-layout edge cases, and a published package cannot lose its schemas
9
+ * without the build itself failing. Development and tests track the live
10
+ * contract set because the build/test/dev scripts all run the generator
11
+ * first.
12
+ */
13
+ export declare function hasLocalSchema(schemaName: string, contractVersion: string): boolean;
14
+ /**
15
+ * True when this build carries the operation schemas for the CLI's default
16
+ * contract version. False means the package was built without its codegen
17
+ * step (or the generated file was corrupted) -- callers should report THAT
18
+ * as a broken build, not as a contract-version mismatch.
19
+ */
20
+ export declare function schemasAvailable(): boolean;
21
+ /**
22
+ * Whether this CLI can validate all operation and catalog shapes for a contract version.
23
+ * Checks the transitive `$ref` dependencies as well as the target schemas: ajv.compile
24
+ * throws on an unresolvable $ref, so a missing dependency means validation CANNOT run --
25
+ * classify it as unsupported up front instead of crashing mid-validation.
26
+ */
27
+ export declare function supportsLocalContractVersion(contractVersion: string): boolean;
28
+ export type ValidationResult = {
29
+ valid: true;
30
+ skipped?: false;
31
+ } | {
32
+ valid: false;
33
+ errors: string[];
34
+ } | {
35
+ valid: true;
36
+ skipped: true;
37
+ reason: string;
38
+ };
39
+ /**
40
+ * Validates a parsed registry search response against the pinned
41
+ * `registry-search-response` schema for the given contract version.
42
+ *
43
+ * Returns a `skipped` result rather than throwing when the CLI does not have
44
+ * that contract version's schema bundled locally.
45
+ */
46
+ export declare function validateSearchResponse(body: unknown, contractVersion: string): ValidationResult;
47
+ /**
48
+ * Validates a parsed error response against the pinned `error-response` schema.
49
+ */
50
+ export declare function validateErrorResponse(body: unknown, contractVersion: string): ValidationResult;
51
+ /**
52
+ * Validates a fetched brand-domain catalog against the selected ARD manifest profile.
53
+ */
54
+ export declare function validateCatalog(body: unknown, contractVersion: string): ValidationResult;
55
+ /** Validates a document against a named schema in the selected contract release. */
56
+ export declare function validateContractDocument(schemaName: string, body: unknown, contractVersion: string): ValidationResult;
57
+ /**
58
+ * Validates a verify candidate against the pinned `osd-catalog-entry` schema
59
+ * (ARD entry + required namespaced OSD brand terms).
60
+ */
61
+ export declare function validateCatalogEntry(body: unknown, contractVersion: string): ValidationResult;
@@ -0,0 +1,145 @@
1
+ import Ajv2020Import from "ajv/dist/2020.js";
2
+ import addFormatsImport from "ajv-formats";
3
+ import { SCHEMAS } from "./generated/schemas.js";
4
+ // `ajv`/`ajv-formats` ship CJS default exports that don't line up cleanly
5
+ // with `esModuleInterop` under NodeNext resolution; unwrap explicitly.
6
+ const Ajv2020 = (Ajv2020Import.default ?? Ajv2020Import);
7
+ const addFormats = (addFormatsImport.default ?? addFormatsImport);
8
+ export const DEFAULT_CONTRACT_VERSION = "0.3.0";
9
+ const REQUIRED_OPERATION_SCHEMAS = ["registry-search-response", "error-response"];
10
+ /** The catalog schema changes from ARD v0.9's AI Catalog to the OSD ARD v0.91 profile. */
11
+ const CATALOG_SCHEMA_BY_CONTRACT_VERSION = {
12
+ "0.1.0": "ard-ai-catalog",
13
+ "0.3.0": "osd-ard-manifest",
14
+ };
15
+ /** Schemas that operation and catalog schemas transitively depend on via `$ref`, by release. */
16
+ const DEPENDENCY_SCHEMAS_BY_CONTRACT_VERSION = {
17
+ "0.1.0": ["osd-catalog-entry", "ard-ai-catalog", "osd-metadata"],
18
+ "0.3.0": ["osd-catalog-entry", "ard-entry"],
19
+ };
20
+ /**
21
+ * Whether this CLI carries the named schema for the given contract version.
22
+ *
23
+ * Schemas are embedded at build time (src/generated/schemas.ts, produced by
24
+ * scripts/gen-schemas.mjs from the repository's normative contracts/
25
+ * directory), so this is a pure in-memory lookup: no filesystem access, no
26
+ * install-layout edge cases, and a published package cannot lose its schemas
27
+ * without the build itself failing. Development and tests track the live
28
+ * contract set because the build/test/dev scripts all run the generator
29
+ * first.
30
+ */
31
+ export function hasLocalSchema(schemaName, contractVersion) {
32
+ return SCHEMAS[schemaName]?.[contractVersion] !== undefined;
33
+ }
34
+ /**
35
+ * True when this build carries the operation schemas for the CLI's default
36
+ * contract version. False means the package was built without its codegen
37
+ * step (or the generated file was corrupted) -- callers should report THAT
38
+ * as a broken build, not as a contract-version mismatch.
39
+ */
40
+ export function schemasAvailable() {
41
+ return supportsLocalContractVersion(DEFAULT_CONTRACT_VERSION);
42
+ }
43
+ /**
44
+ * Whether this CLI can validate all operation and catalog shapes for a contract version.
45
+ * Checks the transitive `$ref` dependencies as well as the target schemas: ajv.compile
46
+ * throws on an unresolvable $ref, so a missing dependency means validation CANNOT run --
47
+ * classify it as unsupported up front instead of crashing mid-validation.
48
+ */
49
+ export function supportsLocalContractVersion(contractVersion) {
50
+ const catalogSchema = CATALOG_SCHEMA_BY_CONTRACT_VERSION[contractVersion];
51
+ const dependencySchemas = DEPENDENCY_SCHEMAS_BY_CONTRACT_VERSION[contractVersion];
52
+ if (catalogSchema === undefined || dependencySchemas === undefined)
53
+ return false;
54
+ return [...REQUIRED_OPERATION_SCHEMAS, catalogSchema, ...dependencySchemas].every((schemaName) => hasLocalSchema(schemaName, contractVersion));
55
+ }
56
+ function loadSchema(schemaName, contractVersion) {
57
+ const schema = SCHEMAS[schemaName]?.[contractVersion];
58
+ if (schema === undefined) {
59
+ throw new Error(`no embedded "${schemaName}" schema for contract version ${contractVersion}`);
60
+ }
61
+ return schema;
62
+ }
63
+ const ajv = new Ajv2020({ strict: false, allErrors: true });
64
+ addFormats(ajv);
65
+ const registeredDependencyVersions = new Set();
66
+ const compiledValidators = new Map();
67
+ function registerDependencies(contractVersion) {
68
+ if (registeredDependencyVersions.has(contractVersion))
69
+ return;
70
+ for (const schemaName of DEPENDENCY_SCHEMAS_BY_CONTRACT_VERSION[contractVersion] ?? []) {
71
+ if (hasLocalSchema(schemaName, contractVersion)) {
72
+ ajv.addSchema(loadSchema(schemaName, contractVersion));
73
+ }
74
+ }
75
+ registeredDependencyVersions.add(contractVersion);
76
+ }
77
+ function getValidator(schemaName, contractVersion) {
78
+ const key = `${schemaName}@${contractVersion}`;
79
+ const cached = compiledValidators.get(key);
80
+ if (cached)
81
+ return cached;
82
+ registerDependencies(contractVersion);
83
+ const schema = loadSchema(schemaName, contractVersion);
84
+ const validate = ajv.compile(schema);
85
+ compiledValidators.set(key, validate);
86
+ return validate;
87
+ }
88
+ function formatErrors(errors) {
89
+ return (errors ?? []).map((e) => `${e.instancePath || "/"} ${e.message ?? "is invalid"}`);
90
+ }
91
+ function validateAgainst(schemaName, body, contractVersion) {
92
+ if (!hasLocalSchema(schemaName, contractVersion)) {
93
+ return {
94
+ valid: true,
95
+ skipped: true,
96
+ reason: `no local "${schemaName}" schema for contract version ${contractVersion}`,
97
+ };
98
+ }
99
+ const validate = getValidator(schemaName, contractVersion);
100
+ const valid = validate(body);
101
+ if (valid)
102
+ return { valid: true };
103
+ return { valid: false, errors: formatErrors(validate.errors) };
104
+ }
105
+ /**
106
+ * Validates a parsed registry search response against the pinned
107
+ * `registry-search-response` schema for the given contract version.
108
+ *
109
+ * Returns a `skipped` result rather than throwing when the CLI does not have
110
+ * that contract version's schema bundled locally.
111
+ */
112
+ export function validateSearchResponse(body, contractVersion) {
113
+ return validateAgainst("registry-search-response", body, contractVersion);
114
+ }
115
+ /**
116
+ * Validates a parsed error response against the pinned `error-response` schema.
117
+ */
118
+ export function validateErrorResponse(body, contractVersion) {
119
+ return validateAgainst("error-response", body, contractVersion);
120
+ }
121
+ /**
122
+ * Validates a fetched brand-domain catalog against the selected ARD manifest profile.
123
+ */
124
+ export function validateCatalog(body, contractVersion) {
125
+ const schemaName = CATALOG_SCHEMA_BY_CONTRACT_VERSION[contractVersion];
126
+ if (schemaName === undefined) {
127
+ return {
128
+ valid: true,
129
+ skipped: true,
130
+ reason: `no local catalog schema for contract version ${contractVersion}`,
131
+ };
132
+ }
133
+ return validateAgainst(schemaName, body, contractVersion);
134
+ }
135
+ /** Validates a document against a named schema in the selected contract release. */
136
+ export function validateContractDocument(schemaName, body, contractVersion) {
137
+ return validateAgainst(schemaName, body, contractVersion);
138
+ }
139
+ /**
140
+ * Validates a verify candidate against the pinned `osd-catalog-entry` schema
141
+ * (ARD entry + required namespaced OSD brand terms).
142
+ */
143
+ export function validateCatalogEntry(body, contractVersion) {
144
+ return validateAgainst("osd-catalog-entry", body, contractVersion);
145
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Process exit codes used by the OSD CLI.
3
+ *
4
+ * Kept small and stable on purpose: scripts and CI jobs depend on these
5
+ * values, not on stderr text.
6
+ */
7
+ export declare const ExitCode: {
8
+ /** The command completed and produced a result (including zero results). */
9
+ readonly Success: 0;
10
+ /** The registry/resolver returned a structured error that isn't one of the mapped codes below, or a fetched brand catalog was malformed (bad JSON, schema-invalid, duplicate array members). */
11
+ readonly GeneralError: 1;
12
+ /** The request was rejected as invalid (`INVALID_ARGUMENT`, HTTP 400), or a verify candidate was itself invalid (unparseable, schema-invalid, bad brandDomain). */
13
+ readonly InvalidArgument: 2;
14
+ /** The target does not support the requested contract version (`UNSUPPORTED_CONTRACT_VERSION`, HTTP 406). */
15
+ readonly UnsupportedContractVersion: 3;
16
+ /** The CLI could not reach the target at all (DNS, connection refused, timeout, 3xx, non-2xx, over-size or non-JSON body, private-address refusal). Inconclusive: safe to retry. */
17
+ readonly Unreachable: 4;
18
+ /** Verify verdict: no entry in the brand domain's catalog shares the candidate's identifier. Definitive: the brand does not endorse this candidate. */
19
+ readonly NoMatch: 5;
20
+ /** Verify verdict: the brand's catalog has an entry with the candidate's identifier, but the fields differ structurally. Definitive conflict. */
21
+ readonly Mismatch: 6;
22
+ /** The command-line arguments themselves were invalid. */
23
+ readonly Usage: 64;
24
+ };
25
+ export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
26
+ /**
27
+ * Maps a contract `errorCode` (see `contracts/schemas/error-response`) to an exit code.
28
+ *
29
+ * Unrecognized error codes fall back to `GeneralError` rather than throwing,
30
+ * so the CLI never crashes on an error shape it doesn't specifically know about.
31
+ */
32
+ export declare function exitCodeForErrorCode(errorCode: string): ExitCode;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Process exit codes used by the OSD CLI.
3
+ *
4
+ * Kept small and stable on purpose: scripts and CI jobs depend on these
5
+ * values, not on stderr text.
6
+ */
7
+ export const ExitCode = {
8
+ /** The command completed and produced a result (including zero results). */
9
+ Success: 0,
10
+ /** The registry/resolver returned a structured error that isn't one of the mapped codes below, or a fetched brand catalog was malformed (bad JSON, schema-invalid, duplicate array members). */
11
+ GeneralError: 1,
12
+ /** The request was rejected as invalid (`INVALID_ARGUMENT`, HTTP 400), or a verify candidate was itself invalid (unparseable, schema-invalid, bad brandDomain). */
13
+ InvalidArgument: 2,
14
+ /** The target does not support the requested contract version (`UNSUPPORTED_CONTRACT_VERSION`, HTTP 406). */
15
+ UnsupportedContractVersion: 3,
16
+ /** The CLI could not reach the target at all (DNS, connection refused, timeout, 3xx, non-2xx, over-size or non-JSON body, private-address refusal). Inconclusive: safe to retry. */
17
+ Unreachable: 4,
18
+ /** Verify verdict: no entry in the brand domain's catalog shares the candidate's identifier. Definitive: the brand does not endorse this candidate. */
19
+ NoMatch: 5,
20
+ /** Verify verdict: the brand's catalog has an entry with the candidate's identifier, but the fields differ structurally. Definitive conflict. */
21
+ Mismatch: 6,
22
+ /** The command-line arguments themselves were invalid. */
23
+ Usage: 64,
24
+ };
25
+ /**
26
+ * Maps a contract `errorCode` (see `contracts/schemas/error-response`) to an exit code.
27
+ *
28
+ * Unrecognized error codes fall back to `GeneralError` rather than throwing,
29
+ * so the CLI never crashes on an error shape it doesn't specifically know about.
30
+ */
31
+ export function exitCodeForErrorCode(errorCode) {
32
+ switch (errorCode) {
33
+ case "INVALID_ARGUMENT":
34
+ return ExitCode.InvalidArgument;
35
+ case "UNSUPPORTED_CONTRACT_VERSION":
36
+ return ExitCode.UnsupportedContractVersion;
37
+ default:
38
+ return ExitCode.GeneralError;
39
+ }
40
+ }
@@ -0,0 +1,71 @@
1
+ import type { DiffEntry, VerifyOutcome } from "./verify.js";
2
+ /**
3
+ * Per-result verification annotation, attached by `search --verify` (and
4
+ * stripped by the comparator if the result is later re-verified).
5
+ */
6
+ export interface VerificationAnnotation {
7
+ verdict: "verified" | "mismatch" | "no_match" | "unreachable" | "invalid" | "malformed";
8
+ detail?: string;
9
+ catalogUrl?: string;
10
+ diff?: DiffEntry[];
11
+ }
12
+ /**
13
+ * Shape of a search result item, matching `contracts/schemas/registry-search-response`.
14
+ */
15
+ export interface SearchResultItem {
16
+ identifier: string;
17
+ displayName: string;
18
+ type: string;
19
+ url?: string;
20
+ capabilities?: string[];
21
+ score: number;
22
+ source: string;
23
+ verification?: VerificationAnnotation;
24
+ [key: string]: unknown;
25
+ }
26
+ export interface RegistryReferral {
27
+ identifier: string;
28
+ displayName: string;
29
+ type: string;
30
+ url: string;
31
+ }
32
+ export interface SearchResponse {
33
+ results: SearchResultItem[];
34
+ referrals?: RegistryReferral[];
35
+ pageToken?: string;
36
+ }
37
+ export interface ErrorResponse {
38
+ errorCode: string;
39
+ message: string;
40
+ [key: string]: unknown;
41
+ }
42
+ /**
43
+ * Renders a search response as plain text for interactive use.
44
+ *
45
+ * This never picks a candidate on the caller's behalf: it lists every result
46
+ * and every referral in the order the target returned them.
47
+ */
48
+ export declare function formatHumanSearchResponse(response: SearchResponse): string;
49
+ /**
50
+ * Renders an error response as a single, script-safe line. No stack trace,
51
+ * no raw JSON dump -- just the contract's `errorCode` and `message`.
52
+ */
53
+ export declare function formatHumanError(status: number, error: ErrorResponse): string;
54
+ /**
55
+ * The structural-match disclosure attached to every verification verdict.
56
+ * Verdicts are exact structural matches only; no cryptographic validation
57
+ * of any kind is performed in v1.
58
+ */
59
+ export declare function verificationNote(catalogUrl: string): string;
60
+ /** The `osd verify` outcomes that are verdicts (not input/build errors). */
61
+ export type VerifyVerdictOutcome = Extract<VerifyOutcome, {
62
+ kind: "verified" | "mismatch" | "noMatch" | "unreachable";
63
+ }>;
64
+ /** Machine-readable verdict vocabulary shared by --json output and annotations. */
65
+ export declare function verdictName(kind: VerifyVerdictOutcome["kind"]): "verified" | "mismatch" | "no_match" | "unreachable";
66
+ /**
67
+ * Renders a standalone `osd verify` verdict as plain text (stdout). Wording
68
+ * stays neutral: a mismatch can be an unpropagated update, not necessarily
69
+ * fraud.
70
+ */
71
+ export declare function formatHumanVerifyOutcome(outcome: VerifyVerdictOutcome): string;
package/dist/format.js ADDED
@@ -0,0 +1,99 @@
1
+ import { renderDiffValue } from "./verify.js";
2
+ /**
3
+ * Renders a search response as plain text for interactive use.
4
+ *
5
+ * This never picks a candidate on the caller's behalf: it lists every result
6
+ * and every referral in the order the target returned them.
7
+ */
8
+ export function formatHumanSearchResponse(response) {
9
+ const lines = [];
10
+ if (response.results.length === 0) {
11
+ lines.push("No results.");
12
+ }
13
+ else {
14
+ lines.push(`${response.results.length} result(s):`);
15
+ for (const result of response.results) {
16
+ lines.push("");
17
+ lines.push(` ${result.displayName} (${result.identifier})`);
18
+ lines.push(` score: ${result.score}`);
19
+ lines.push(` source: ${result.source}`);
20
+ if (result.url)
21
+ lines.push(` url: ${result.url}`);
22
+ if (result.capabilities?.length) {
23
+ lines.push(` capabilities: ${result.capabilities.join(", ")}`);
24
+ }
25
+ if (result.verification) {
26
+ lines.push(` verification: ${result.verification.verdict}`);
27
+ if (result.verification.detail)
28
+ lines.push(` detail: ${result.verification.detail}`);
29
+ if (result.verification.catalogUrl) {
30
+ lines.push(` ${verificationNote(result.verification.catalogUrl)}`);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ if (response.referrals?.length) {
36
+ lines.push("");
37
+ lines.push(`${response.referrals.length} referral(s):`);
38
+ for (const referral of response.referrals) {
39
+ lines.push("");
40
+ lines.push(` ${referral.displayName} (${referral.identifier})`);
41
+ lines.push(` url: ${referral.url}`);
42
+ }
43
+ }
44
+ if (response.pageToken) {
45
+ lines.push("");
46
+ lines.push(`Next page token: ${response.pageToken}`);
47
+ }
48
+ return lines.join("\n");
49
+ }
50
+ /**
51
+ * Renders an error response as a single, script-safe line. No stack trace,
52
+ * no raw JSON dump -- just the contract's `errorCode` and `message`.
53
+ */
54
+ export function formatHumanError(status, error) {
55
+ return `Error: ${error.errorCode} (HTTP ${status}): ${error.message}`;
56
+ }
57
+ /**
58
+ * The structural-match disclosure attached to every verification verdict.
59
+ * Verdicts are exact structural matches only; no cryptographic validation
60
+ * of any kind is performed in v1.
61
+ */
62
+ export function verificationNote(catalogUrl) {
63
+ return `note: verdict is a structural match against ${catalogUrl} only; no cryptographic validation performed.`;
64
+ }
65
+ /** Machine-readable verdict vocabulary shared by --json output and annotations. */
66
+ export function verdictName(kind) {
67
+ return kind === "noMatch" ? "no_match" : kind;
68
+ }
69
+ /**
70
+ * Renders a standalone `osd verify` verdict as plain text (stdout). Wording
71
+ * stays neutral: a mismatch can be an unpropagated update, not necessarily
72
+ * fraud.
73
+ */
74
+ export function formatHumanVerifyOutcome(outcome) {
75
+ switch (outcome.kind) {
76
+ case "verified":
77
+ return [
78
+ `Verification: verified: candidate matches the brand catalog`,
79
+ verificationNote(outcome.catalogUrl),
80
+ ].join("\n");
81
+ case "mismatch": {
82
+ const lines = [
83
+ `Verification: mismatch: ${outcome.diff.length} field(s) differ from the brand catalog entry with the same identifier`,
84
+ ];
85
+ for (const entry of outcome.diff) {
86
+ lines.push(` ${entry.path}: registry=${JSON.stringify(renderDiffValue(entry.registryValue))} brand=${JSON.stringify(renderDiffValue(entry.brandValue))}`);
87
+ }
88
+ lines.push(verificationNote(outcome.catalogUrl));
89
+ return lines.join("\n");
90
+ }
91
+ case "noMatch":
92
+ return [
93
+ `Verification: no_match: no entry in the brand catalog shares the candidate's identifier`,
94
+ verificationNote(outcome.catalogUrl),
95
+ ].join("\n");
96
+ case "unreachable":
97
+ return `Verification: unreachable: ${outcome.message}`;
98
+ }
99
+ }
@@ -0,0 +1,2 @@
1
+ /** Every contract schema, embedded at build time: schema name -> contract version -> schema. */
2
+ export declare const SCHEMAS: Record<string, Record<string, object>>;