@redditech/agent-protocol 0.0.0-stage → 0.2.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +394 -2
  4. package/dist/adl.d.ts +141 -0
  5. package/dist/adl.js +3601 -0
  6. package/dist/agent-stack-fixtures.d.ts +743 -0
  7. package/dist/agent-stack-fixtures.js +1554 -0
  8. package/dist/ai-catalog.d.ts +128 -0
  9. package/dist/ai-catalog.js +373 -0
  10. package/dist/attestation-reputation.d.ts +102 -0
  11. package/dist/attestation-reputation.js +279 -0
  12. package/dist/audd-rail-config.d.ts +102 -0
  13. package/dist/audd-rail-config.js +294 -0
  14. package/dist/browser-wallet-approval.d.ts +293 -0
  15. package/dist/browser-wallet-approval.js +1201 -0
  16. package/dist/discovery-source.d.ts +115 -0
  17. package/dist/discovery-source.js +251 -0
  18. package/dist/evidence-archive.d.ts +73 -0
  19. package/dist/evidence-archive.js +238 -0
  20. package/dist/index.d.ts +23 -0
  21. package/dist/index.js +23 -0
  22. package/dist/mpp-tempo-receipt-shapes.d.ts +201 -0
  23. package/dist/mpp-tempo-receipt-shapes.js +330 -0
  24. package/dist/okf-adapter.d.ts +229 -0
  25. package/dist/okf-adapter.js +556 -0
  26. package/dist/okf-conformance.d.ts +208 -0
  27. package/dist/okf-conformance.js +651 -0
  28. package/dist/okf-instruction-safety.d.ts +192 -0
  29. package/dist/okf-instruction-safety.js +509 -0
  30. package/dist/onboarding-analyser-handoff.d.ts +391 -0
  31. package/dist/onboarding-analyser-handoff.js +959 -0
  32. package/dist/onboarding-state-machine.d.ts +228 -0
  33. package/dist/onboarding-state-machine.js +432 -0
  34. package/dist/payment-records.d.ts +181 -0
  35. package/dist/payment-records.js +599 -0
  36. package/dist/policy.d.ts +33 -0
  37. package/dist/policy.js +45 -0
  38. package/dist/provider-trust.d.ts +113 -0
  39. package/dist/provider-trust.js +346 -0
  40. package/dist/quasar-registry-compatibility.d.ts +113 -0
  41. package/dist/quasar-registry-compatibility.js +214 -0
  42. package/dist/ranking-explainability.d.ts +202 -0
  43. package/dist/ranking-explainability.js +302 -0
  44. package/dist/receipt-v2.d.ts +202 -0
  45. package/dist/receipt-v2.js +418 -0
  46. package/dist/repo-explorer-evidence-manifest.d.ts +387 -0
  47. package/dist/repo-explorer-evidence-manifest.js +1187 -0
  48. package/dist/source-diagnostics.d.ts +84 -0
  49. package/dist/source-diagnostics.js +193 -0
  50. package/dist/source-trust-conformance-matrix.d.ts +207 -0
  51. package/dist/source-trust-conformance-matrix.js +672 -0
  52. package/examples/ard-no-spend-ai-catalog.json +51 -0
  53. package/examples/ard-no-spend-demo.mjs +355 -0
  54. package/examples/interpretation-guide-scenarios.mjs +302 -0
  55. package/package.json +144 -4
@@ -0,0 +1,672 @@
1
+ /**
2
+ * Source/trust conformance matrix for auth.md and ARD/AI Catalog provider
3
+ * metadata (#450, epics #336 / #363).
4
+ *
5
+ * Proves — with deterministic fixtures only — that `auth.md` documents and
6
+ * ARD/AI Catalog provider metadata enter RAP as UNTRUSTED source metadata and
7
+ * stay untrusted until explicit RAP-side trust/evidence gates classify them.
8
+ * Discovery relevance is a search signal and never a trust decision; see
9
+ * `docs/DISCOVER-DECIDE-PROVE-BOUNDARIES.md` (#452) — this module references
10
+ * that boundary and enforces it (`relevance_ignored_for_trust`), it does not
11
+ * restate it.
12
+ *
13
+ * This module is PURE: no network, no filesystem access, no live auth.md
14
+ * fetch, no catalog crawl, no LLM/provider call, no MCP/tool call, no wallet
15
+ * or RPC action, no hosted-registry write, no publication, no payment, no
16
+ * trust/reputation mutation. It only classifies in-memory metadata the caller
17
+ * already holds. Fail-closed on malformed input and on every unsafe finding.
18
+ *
19
+ * Vocabulary reuse (no new words where existing ones fit):
20
+ * - Trust states mirror the #343 lane vocabulary stated in the boundaries doc
21
+ * (trusted / listed-untrusted / claimed / unverified / failed-verification /
22
+ * blocked / needs-human-review) and overlap with the #506 actionability lane
23
+ * states (`claimed`, `failed_verification`, `blocked`, `needs_human_review`).
24
+ * - Finding severities reuse the repo static-analysis vocabulary
25
+ * (`info` / `warning` / `blocked` — `source-diagnostics.ts`, `okf-conformance.ts`).
26
+ * - Finding codes reuse `provider-trust.ts` reason codes wherever one exists
27
+ * (`malformed_trust_metadata`, `credential_leakage_rejected`,
28
+ * `no_trust_metadata`, `external_claim_not_verified_by_rap`, `rap_verified`,
29
+ * `rap_verification_failed`) and add only the auth-surface gates #450 names.
30
+ * - auth.md registration/credential vocabulary aligns with the auth.md
31
+ * discovery lane (`agent-provider` / `email-verification` / `anonymous`;
32
+ * `access_token` / `api_key`). Identity-assertion names are DRAFT and
33
+ * illustrative — auth.md is an external format; confirm before relying.
34
+ *
35
+ * Outputs are projections consumable by:
36
+ * - #343 provider trust registry work (`registryProjection` maps every matrix
37
+ * state onto the existing `ProviderTrustVerificationStatus` vocabulary and
38
+ * carries the normalized `ProviderTrustRecord` when one exists), and
39
+ * - #344 source-aware diagnostics (`diagnosticsProjection` uses the
40
+ * `source-diagnostics.ts` lane + severity vocabulary).
41
+ */
42
+ import { normalizeAiCatalogProviderTrustRecord, providerTrustFixtures, } from './provider-trust.js';
43
+ export const SOURCE_TRUST_CONFORMANCE_MATRIX_SCHEMA_VERSION = 'reddi.source-trust-conformance-matrix.v1';
44
+ /** Where the boundary between discovery relevance and trust/policy/payment/evidence/reputation is defined. */
45
+ export const SOURCE_TRUST_BOUNDARIES_DOC_REF = 'docs/DISCOVER-DECIDE-PROVE-BOUNDARIES.md';
46
+ export const SOURCE_TRUST_STATES = [
47
+ 'trusted',
48
+ 'listed_untrusted',
49
+ 'claimed',
50
+ 'unverified',
51
+ 'failed_verification',
52
+ 'blocked',
53
+ 'needs_human_review',
54
+ ];
55
+ export const SOURCE_TRUST_REQUIRED_CASES = [
56
+ 'malformed_metadata',
57
+ 'credential_leakage',
58
+ 'anonymous_write_scope',
59
+ 'unsupported_credential_type',
60
+ 'unsupported_identity_assertion',
61
+ 'missing_trust_evidence',
62
+ 'high_relevance_blocked_candidate',
63
+ ];
64
+ /** Supported auth.md credential types (aligned with the auth.md discovery lane). */
65
+ export const SUPPORTED_AUTH_MD_CREDENTIAL_TYPES = ['access_token', 'api_key'];
66
+ /** Supported auth.md registration types (aligned with the auth.md discovery lane). */
67
+ export const SUPPORTED_AUTH_MD_REGISTRATION_TYPES = ['agent-provider', 'email-verification', 'anonymous'];
68
+ /**
69
+ * Supported identity-assertion mechanisms. DRAFT/illustrative — auth.md is an
70
+ * external format and these names are unconfirmed against a live spec; the
71
+ * fail-closed behavior (unknown assertion ⇒ blocked) is the contract, not the
72
+ * exact allowlist.
73
+ */
74
+ export const SUPPORTED_AUTH_MD_IDENTITY_ASSERTIONS = ['publisher_domain', 'oidc_id_token'];
75
+ const STATE_LABELS = {
76
+ trusted: 'trusted',
77
+ listed_untrusted: 'listed untrusted',
78
+ claimed: 'claimed',
79
+ unverified: 'unverified',
80
+ failed_verification: 'failed verification',
81
+ blocked: 'blocked',
82
+ needs_human_review: 'needs human review',
83
+ };
84
+ // Same credential-shape heuristics as provider-trust.ts so both surfaces
85
+ // reject leakage identically.
86
+ const SENSITIVE_KEY_PATTERN = /(^|[_-])(api[_-]?key|authorization|bearer|cookie|credential|mnemonic|password|private[_-]?key|refresh[_-]?token|secret|seed|session[_-]?token|token)($|[_-])|apiKey|accessToken|refreshToken|sessionToken|privateKey/i;
87
+ const SENSITIVE_VALUE_PATTERN = /(-----BEGIN [A-Z ]*PRIVATE KEY-----|authorization:\s*bearer\s+|bearer\s+[a-z0-9._-]{8,}|sk-[a-z0-9_-]{8,})/i;
88
+ function isPlainObject(value) {
89
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
90
+ return false;
91
+ const prototype = Object.getPrototypeOf(value);
92
+ return prototype === Object.prototype || prototype === null;
93
+ }
94
+ function finding(code, severity, path, message) {
95
+ return { code, severity, path, message };
96
+ }
97
+ function findCredentialMaterial(value, path = '$') {
98
+ if (typeof value === 'string')
99
+ return SENSITIVE_VALUE_PATTERN.test(value) ? path : undefined;
100
+ if (!value || typeof value !== 'object')
101
+ return undefined;
102
+ if (Array.isArray(value)) {
103
+ for (let index = 0; index < value.length; index += 1) {
104
+ const found = findCredentialMaterial(value[index], `${path}[${index}]`);
105
+ if (found)
106
+ return found;
107
+ }
108
+ return undefined;
109
+ }
110
+ for (const [key, child] of Object.entries(value)) {
111
+ const childPath = `${path}.${key}`;
112
+ if (SENSITIVE_KEY_PATTERN.test(key))
113
+ return childPath;
114
+ const found = findCredentialMaterial(child, childPath);
115
+ if (found)
116
+ return found;
117
+ }
118
+ return undefined;
119
+ }
120
+ function stringArray(value) {
121
+ if (!Array.isArray(value))
122
+ return [];
123
+ return value.filter((item) => typeof item === 'string');
124
+ }
125
+ function readAuthSurface(source) {
126
+ const scopesRaw = Array.isArray(source.scopes) ? source.scopes : [];
127
+ const scopes = [];
128
+ for (const entry of scopesRaw) {
129
+ if (!isPlainObject(entry))
130
+ continue;
131
+ const name = typeof entry.name === 'string' ? entry.name : '';
132
+ const access = entry.access === 'write' ? 'write' : 'read';
133
+ scopes.push({
134
+ name,
135
+ access,
136
+ registrationTypes: Array.isArray(entry.registrationTypes) ? stringArray(entry.registrationTypes) : undefined,
137
+ });
138
+ }
139
+ return {
140
+ credentialTypes: stringArray(source.credentialTypes),
141
+ identityAssertions: stringArray(source.identityAssertions),
142
+ registrationTypes: stringArray(source.registrationTypes),
143
+ scopes,
144
+ };
145
+ }
146
+ /**
147
+ * Fail-closed auth-surface gates shared by both source kinds: anonymous write
148
+ * scopes, unsupported credential types, and unsupported identity assertions
149
+ * are all rejected regardless of how relevant the candidate looks.
150
+ */
151
+ function evaluateAuthSurface(surface, basePath, findings) {
152
+ for (let index = 0; index < surface.scopes.length; index += 1) {
153
+ const scope = surface.scopes[index];
154
+ if (scope.access !== 'write')
155
+ continue;
156
+ const offeredTo = scope.registrationTypes ?? surface.registrationTypes;
157
+ if (offeredTo.includes('anonymous')) {
158
+ findings.push(finding('anonymous_write_scope_rejected', 'blocked', `${basePath}.scopes[${index}]`, `write scope "${scope.name}" is offered to anonymous registrations; anonymous write scopes fail closed.`));
159
+ }
160
+ }
161
+ for (const credentialType of surface.credentialTypes) {
162
+ if (!SUPPORTED_AUTH_MD_CREDENTIAL_TYPES.includes(credentialType)) {
163
+ findings.push(finding('unsupported_credential_type', 'blocked', `${basePath}.credentialTypes`, `credential type "${credentialType}" is not supported (supported: ${SUPPORTED_AUTH_MD_CREDENTIAL_TYPES.join(', ')}).`));
164
+ }
165
+ }
166
+ for (const assertion of surface.identityAssertions) {
167
+ if (!SUPPORTED_AUTH_MD_IDENTITY_ASSERTIONS.includes(assertion)) {
168
+ findings.push(finding('unsupported_identity_assertion', 'blocked', `${basePath}.identityAssertions`, `identity assertion "${assertion}" is not supported (supported: ${SUPPORTED_AUTH_MD_IDENTITY_ASSERTIONS.join(', ')}).`));
169
+ }
170
+ }
171
+ }
172
+ function hasAuthMdTrustClaims(trust) {
173
+ if (!trust)
174
+ return false;
175
+ return Boolean(trust.trustManifest
176
+ || trust.publisherIdentity
177
+ || (Array.isArray(trust.provenance) && trust.provenance.length > 0)
178
+ || (Array.isArray(trust.attestations) && trust.attestations.length > 0)
179
+ || (Array.isArray(trust.verificationReferences) && trust.verificationReferences.length > 0));
180
+ }
181
+ function runAuthMdGates(metadata, rapVerification) {
182
+ const findings = [];
183
+ if (!isPlainObject(metadata)) {
184
+ findings.push(finding('malformed_source_metadata', 'blocked', '$', 'auth.md metadata must be a plain object; malformed metadata fails closed.'));
185
+ return { findings, hasTrustClaims: false };
186
+ }
187
+ const credentialPath = findCredentialMaterial(metadata);
188
+ if (credentialPath) {
189
+ findings.push(finding('credential_leakage_rejected', 'blocked', credentialPath, 'auth.md metadata contains credential-shaped material; it is rejected, never stored.'));
190
+ }
191
+ evaluateAuthSurface(readAuthSurface(metadata), '$', findings);
192
+ const trust = isPlainObject(metadata.trust) ? metadata.trust : undefined;
193
+ if (trust && typeof trust.status === 'string' && trust.status.toLowerCase() === 'verified') {
194
+ findings.push(finding('self_asserted_verification_ignored', 'warning', '$.trust.status', 'external metadata self-asserts a verified status; external claims cannot verify themselves — routed to human review.'));
195
+ }
196
+ const hasTrustClaims = hasAuthMdTrustClaims(trust);
197
+ appendVerificationFindings(hasTrustClaims, rapVerification, findings);
198
+ return { findings, hasTrustClaims };
199
+ }
200
+ function runAiCatalogGates(catalog, resourceId, rapVerification) {
201
+ const findings = [];
202
+ const result = normalizeAiCatalogProviderTrustRecord(catalog, resourceId, rapVerification ? { verification: rapVerification } : {});
203
+ if (!result.ok) {
204
+ for (const error of result.errors) {
205
+ const code = error.code === 'malformed_trust_metadata'
206
+ ? 'malformed_trust_metadata'
207
+ : error.code === 'credential_leakage_rejected'
208
+ ? 'credential_leakage_rejected'
209
+ : 'malformed_source_metadata';
210
+ findings.push(finding(code, 'blocked', error.path, error.message));
211
+ }
212
+ return { findings, hasTrustClaims: false };
213
+ }
214
+ const resource = catalog.resources.find((item) => item.id === resourceId);
215
+ if (resource && isPlainObject(resource.auth)) {
216
+ evaluateAuthSurface(readAuthSurface(resource.auth), '$.auth', findings);
217
+ }
218
+ const record = result.record;
219
+ const hasTrustClaims = record.verification.status !== 'unverified';
220
+ switch (record.verification.status) {
221
+ case 'verified':
222
+ findings.push(finding('rap_verified', 'info', '$', 'RAP-side verification marked this provider as verified.'));
223
+ break;
224
+ case 'failed_verification':
225
+ findings.push(finding('rap_verification_failed', 'blocked', '$', 'RAP-side verification failed for this provider.'));
226
+ break;
227
+ case 'claimed':
228
+ findings.push(finding('external_claim_not_verified_by_rap', 'warning', '$', 'external trust claims are present but RAP has not verified them.'));
229
+ break;
230
+ case 'unverified':
231
+ findings.push(finding('no_trust_metadata', 'warning', '$', 'no trust evidence is attached to this provider entry.'));
232
+ break;
233
+ }
234
+ return { findings, hasTrustClaims, providerTrustRecord: record };
235
+ }
236
+ function appendVerificationFindings(hasTrustClaims, rapVerification, findings) {
237
+ if (rapVerification?.status === 'verified') {
238
+ findings.push(finding('rap_verified', 'info', '$', 'RAP-side verification marked this source as verified.'));
239
+ return;
240
+ }
241
+ if (rapVerification?.status === 'failed_verification') {
242
+ findings.push(finding('rap_verification_failed', 'blocked', '$', `RAP-side verification failed${rapVerification.failureReasons?.length ? `: ${rapVerification.failureReasons.join('; ')}` : '.'}`));
243
+ return;
244
+ }
245
+ if (hasTrustClaims) {
246
+ findings.push(finding('external_claim_not_verified_by_rap', 'warning', '$', 'external trust claims are present but RAP has not verified them.'));
247
+ return;
248
+ }
249
+ findings.push(finding('no_trust_metadata', 'warning', '$', 'no trust evidence is attached to this source metadata.'));
250
+ }
251
+ function deriveState(outcome, rapVerification) {
252
+ const blockedFindings = outcome.findings.filter((item) => item.severity === 'blocked');
253
+ const verificationFailed = outcome.findings.some((item) => item.code === 'rap_verification_failed')
254
+ || rapVerification?.status === 'failed_verification';
255
+ // Fail-closed precedence: any blocking finding wins, even over a failed
256
+ // verification record, because blocked rows must never be registry-eligible.
257
+ if (blockedFindings.some((item) => item.code !== 'rap_verification_failed'))
258
+ return 'blocked';
259
+ if (verificationFailed)
260
+ return 'failed_verification';
261
+ const needsReview = outcome.findings.some((item) => item.code === 'self_asserted_verification_ignored');
262
+ const verified = outcome.findings.some((item) => item.code === 'rap_verified');
263
+ const warnings = outcome.findings.filter((item) => item.severity === 'warning');
264
+ if (needsReview)
265
+ return 'needs_human_review';
266
+ if (verified) {
267
+ // Verified with residual warnings does not silently become trusted.
268
+ return warnings.length > 0 ? 'needs_human_review' : 'trusted';
269
+ }
270
+ return outcome.hasTrustClaims ? 'claimed' : 'unverified';
271
+ }
272
+ function registryStatusFor(state, hasTrustClaims) {
273
+ switch (state) {
274
+ case 'trusted':
275
+ return 'verified';
276
+ case 'failed_verification':
277
+ case 'blocked':
278
+ return 'failed_verification';
279
+ case 'claimed':
280
+ return 'claimed';
281
+ case 'needs_human_review':
282
+ return hasTrustClaims ? 'claimed' : 'unverified';
283
+ case 'listed_untrusted':
284
+ case 'unverified':
285
+ return 'unverified';
286
+ }
287
+ }
288
+ function findingLane(code) {
289
+ switch (code) {
290
+ case 'relevance_ignored_for_trust':
291
+ return 'capability_match';
292
+ case 'listed_untrusted_on_entry':
293
+ return 'discovery_source';
294
+ default:
295
+ return 'trust_evidence';
296
+ }
297
+ }
298
+ function buildDiagnosticsProjection(row) {
299
+ const messages = [];
300
+ messages.push({
301
+ lane: 'capability_match',
302
+ severity: 'info',
303
+ code: 'relevance_only_not_trust',
304
+ summary: row.relevanceScore === undefined
305
+ ? `Candidate ${row.candidateId} has no relevance score; relevance would not affect trust either way.`
306
+ : `Candidate ${row.candidateId} has relevance score ${row.relevanceScore}; relevance is a search signal, never a trust decision (${SOURCE_TRUST_BOUNDARIES_DOC_REF}).`,
307
+ });
308
+ for (const item of row.findings) {
309
+ messages.push({
310
+ lane: findingLane(item.code),
311
+ severity: item.severity,
312
+ code: item.code,
313
+ summary: item.message,
314
+ action: item.severity === 'blocked'
315
+ ? 'Fail closed: exclude this candidate from registry listing, policy preflight, payment, and invocation.'
316
+ : item.severity === 'warning'
317
+ ? 'Run RAP-side trust verification before treating this candidate as trusted.'
318
+ : undefined,
319
+ });
320
+ }
321
+ messages.push({
322
+ lane: 'trust_evidence',
323
+ severity: row.state === 'trusted' ? 'info' : row.state === 'blocked' || row.state === 'failed_verification' ? 'blocked' : 'warning',
324
+ code: `source_trust_state_${row.state}`,
325
+ summary: `Source/trust conformance state: ${STATE_LABELS[row.state]}.`,
326
+ action: row.state === 'needs_human_review' ? 'Route to operator review; do not auto-upgrade trust.' : undefined,
327
+ });
328
+ return messages;
329
+ }
330
+ export function classifySourceTrustCandidate(input) {
331
+ const gatesRun = input.gates !== 'not_run';
332
+ const findings = [];
333
+ let outcome = { findings: [], hasTrustClaims: false };
334
+ findings.push(finding('listed_untrusted_on_entry', 'info', '$', `${input.source.kind} metadata enters RAP as untrusted source metadata; no trust is granted by ingestion.`));
335
+ if (gatesRun) {
336
+ outcome = input.source.kind === 'auth-md'
337
+ ? runAuthMdGates(input.source.metadata, input.rapVerification)
338
+ : runAiCatalogGates(input.source.catalog, input.source.resourceId, input.rapVerification);
339
+ findings.push(...outcome.findings);
340
+ }
341
+ if (input.relevance?.score !== undefined) {
342
+ findings.push(finding('relevance_ignored_for_trust', 'info', '$.relevance.score', `relevance score ${input.relevance.score} is recorded for search/ranking only and is ignored by every trust gate.`));
343
+ }
344
+ const state = gatesRun ? deriveState(outcome, input.rapVerification) : 'listed_untrusted';
345
+ return {
346
+ schemaVersion: SOURCE_TRUST_CONFORMANCE_MATRIX_SCHEMA_VERSION,
347
+ candidateId: input.candidateId,
348
+ sourceKind: input.source.kind,
349
+ entryState: 'listed_untrusted',
350
+ state,
351
+ stateLabel: STATE_LABELS[state],
352
+ findings,
353
+ discoveryBoundary: {
354
+ relevanceScore: input.relevance?.score,
355
+ scoreMeaning: 'relevance_only_not_trust',
356
+ relevanceInfluencedTrust: false,
357
+ boundariesDocRef: SOURCE_TRUST_BOUNDARIES_DOC_REF,
358
+ },
359
+ registryProjection: {
360
+ verificationStatus: registryStatusFor(state, outcome.hasTrustClaims),
361
+ reasonCodes: findings.map((item) => item.code),
362
+ registryEligible: state !== 'blocked',
363
+ providerTrustRecord: outcome.providerTrustRecord,
364
+ },
365
+ diagnosticsProjection: buildDiagnosticsProjection({
366
+ candidateId: input.candidateId,
367
+ state,
368
+ findings,
369
+ relevanceScore: input.relevance?.score,
370
+ }),
371
+ };
372
+ }
373
+ const AUTH_MD_TRUSTED_METADATA = {
374
+ url: 'https://agents.reddi.tech/.well-known/auth.md',
375
+ authorizationServer: 'https://auth.reddi.tech',
376
+ registrationTypes: ['agent-provider', 'email-verification'],
377
+ credentialTypes: ['access_token', 'api_key'],
378
+ identityAssertions: ['publisher_domain', 'oidc_id_token'],
379
+ scopes: [
380
+ { name: 'catalog.read', access: 'read' },
381
+ { name: 'listings.write', access: 'write', registrationTypes: ['agent-provider'] },
382
+ ],
383
+ publisher: { id: 'reddi.tech', domain: 'reddi.tech' },
384
+ trust: {
385
+ trustManifest: 'https://agents.reddi.tech/trust-manifest.json',
386
+ provenance: ['https://agents.reddi.tech/provenance/auth.json'],
387
+ attestations: [{ type: 'build-provenance', ref: 'sha256:auth-md-attestation-fixture' }],
388
+ verificationReferences: ['https://agents.reddi.tech/verification/auth.json'],
389
+ publisherIdentity: { domain: 'reddi.tech', status: 'claimed' },
390
+ },
391
+ };
392
+ /**
393
+ * Fixture cases proving every #450 state and required case, across BOTH
394
+ * source kinds. Deterministic, in-memory, no live fetch anywhere.
395
+ */
396
+ export const sourceTrustConformanceFixtureCases = {
397
+ trustedAuthMd: {
398
+ description: 'auth.md metadata with full trust evidence and a passing RAP-side verification gate becomes trusted.',
399
+ input: {
400
+ candidateId: 'auth-md:reddi.tech',
401
+ source: { kind: 'auth-md', metadata: AUTH_MD_TRUSTED_METADATA },
402
+ rapVerification: { status: 'verified', verifier: 'rap-fixture-verifier', checkedAt: '2026-07-06T00:00:00Z' },
403
+ },
404
+ expectedState: 'trusted',
405
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'rap_verified'],
406
+ },
407
+ listedUntrustedEntryArd: {
408
+ description: 'ARD/AI Catalog provider metadata that has only been ingested (no gates run) is listed-untrusted.',
409
+ input: {
410
+ candidateId: 'ai-catalog:urn:ai:reddi.tech:specialists:code-review:entry',
411
+ source: { kind: 'ai-catalog', catalog: providerTrustFixtures.verifiedCatalog, resourceId: 'urn:ai:reddi.tech:specialists:code-review' },
412
+ gates: 'not_run',
413
+ },
414
+ expectedState: 'listed_untrusted',
415
+ expectedFindingCodes: ['listed_untrusted_on_entry'],
416
+ },
417
+ listedUntrustedEntryAuthMd: {
418
+ description: 'auth.md metadata that has only been ingested (no gates run) is listed-untrusted.',
419
+ input: {
420
+ candidateId: 'auth-md:reddi.tech:entry',
421
+ source: { kind: 'auth-md', metadata: AUTH_MD_TRUSTED_METADATA },
422
+ gates: 'not_run',
423
+ },
424
+ expectedState: 'listed_untrusted',
425
+ expectedFindingCodes: ['listed_untrusted_on_entry'],
426
+ },
427
+ claimedArd: {
428
+ description: 'ARD/AI Catalog provider metadata with external trust claims stays claimed until RAP verifies it.',
429
+ input: {
430
+ candidateId: 'ai-catalog:urn:ai:reddi.tech:specialists:code-review',
431
+ source: { kind: 'ai-catalog', catalog: providerTrustFixtures.verifiedCatalog, resourceId: 'urn:ai:reddi.tech:specialists:code-review' },
432
+ },
433
+ expectedState: 'claimed',
434
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'external_claim_not_verified_by_rap'],
435
+ },
436
+ unverifiedAuthMdMissingTrustEvidence: {
437
+ description: 'auth.md metadata with no trust evidence at all is unverified (missing-trust-evidence case).',
438
+ requiredCase: 'missing_trust_evidence',
439
+ input: {
440
+ candidateId: 'auth-md:example.com:no-trust-evidence',
441
+ source: {
442
+ kind: 'auth-md',
443
+ metadata: {
444
+ url: 'https://agents.example.com/.well-known/auth.md',
445
+ authorizationServer: 'https://auth.example.com',
446
+ registrationTypes: ['email-verification'],
447
+ credentialTypes: ['access_token'],
448
+ scopes: [{ name: 'catalog.read', access: 'read' }],
449
+ },
450
+ },
451
+ },
452
+ expectedState: 'unverified',
453
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'no_trust_metadata'],
454
+ },
455
+ failedVerificationArd: {
456
+ description: 'ARD/AI Catalog provider metadata whose RAP-side verification failed is failed-verification.',
457
+ input: {
458
+ candidateId: 'ai-catalog:urn:ai:reddi.tech:specialists:code-review:failed',
459
+ source: { kind: 'ai-catalog', catalog: providerTrustFixtures.verifiedCatalog, resourceId: 'urn:ai:reddi.tech:specialists:code-review' },
460
+ rapVerification: { status: 'failed_verification', verifier: 'rap-fixture-verifier', failureReasons: ['signature did not match trust manifest'] },
461
+ },
462
+ expectedState: 'failed_verification',
463
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'rap_verification_failed'],
464
+ },
465
+ malformedAuthMdMetadata: {
466
+ description: 'malformed auth.md metadata (not even an object) fails closed to blocked.',
467
+ requiredCase: 'malformed_metadata',
468
+ input: {
469
+ candidateId: 'auth-md:example.com:malformed',
470
+ source: { kind: 'auth-md', metadata: 42 },
471
+ },
472
+ expectedState: 'blocked',
473
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'malformed_source_metadata'],
474
+ },
475
+ malformedArdTrustMetadata: {
476
+ description: 'ARD/AI Catalog provider metadata with malformed trust metadata fails closed to blocked.',
477
+ requiredCase: 'malformed_metadata',
478
+ input: {
479
+ candidateId: 'ai-catalog:urn:example:agents:malformed-trust',
480
+ source: { kind: 'ai-catalog', catalog: providerTrustFixtures.malformedTrustCatalog, resourceId: 'urn:example:agents:malformed-trust' },
481
+ },
482
+ expectedState: 'blocked',
483
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'malformed_trust_metadata'],
484
+ },
485
+ credentialLeakageAuthMd: {
486
+ description: 'auth.md metadata carrying credential-shaped material is rejected outright.',
487
+ requiredCase: 'credential_leakage',
488
+ input: {
489
+ candidateId: 'auth-md:example.com:credential-leak',
490
+ source: {
491
+ kind: 'auth-md',
492
+ metadata: {
493
+ url: 'https://agents.example.com/.well-known/auth.md',
494
+ authorizationServer: 'https://auth.example.com',
495
+ credentialTypes: ['access_token'],
496
+ raw: {
497
+ example: 'Authorization: Bearer fixture-not-a-real-credential',
498
+ },
499
+ },
500
+ },
501
+ },
502
+ expectedState: 'blocked',
503
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'credential_leakage_rejected'],
504
+ },
505
+ anonymousWriteScopeAuthMd: {
506
+ description: 'auth.md metadata offering a write scope to anonymous registrations fails closed.',
507
+ requiredCase: 'anonymous_write_scope',
508
+ input: {
509
+ candidateId: 'auth-md:example.com:anonymous-write',
510
+ source: {
511
+ kind: 'auth-md',
512
+ metadata: {
513
+ url: 'https://agents.example.com/.well-known/auth.md',
514
+ authorizationServer: 'https://auth.example.com',
515
+ registrationTypes: ['anonymous', 'email-verification'],
516
+ credentialTypes: ['access_token'],
517
+ scopes: [
518
+ { name: 'catalog.read', access: 'read' },
519
+ { name: 'listings.write', access: 'write', registrationTypes: ['anonymous'] },
520
+ ],
521
+ },
522
+ },
523
+ },
524
+ expectedState: 'blocked',
525
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'anonymous_write_scope_rejected'],
526
+ },
527
+ unsupportedCredentialTypeAuthMd: {
528
+ description: 'auth.md metadata declaring an unsupported credential type fails closed.',
529
+ requiredCase: 'unsupported_credential_type',
530
+ input: {
531
+ candidateId: 'auth-md:example.com:unsupported-credential',
532
+ source: {
533
+ kind: 'auth-md',
534
+ metadata: {
535
+ url: 'https://agents.example.com/.well-known/auth.md',
536
+ authorizationServer: 'https://auth.example.com',
537
+ credentialTypes: ['access_token', 'implicit_browser_grant'],
538
+ scopes: [{ name: 'catalog.read', access: 'read' }],
539
+ },
540
+ },
541
+ },
542
+ expectedState: 'blocked',
543
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'unsupported_credential_type'],
544
+ },
545
+ unsupportedIdentityAssertionAuthMd: {
546
+ description: 'auth.md metadata declaring an unsupported identity assertion fails closed.',
547
+ requiredCase: 'unsupported_identity_assertion',
548
+ input: {
549
+ candidateId: 'auth-md:example.com:unsupported-assertion',
550
+ source: {
551
+ kind: 'auth-md',
552
+ metadata: {
553
+ url: 'https://agents.example.com/.well-known/auth.md',
554
+ authorizationServer: 'https://auth.example.com',
555
+ credentialTypes: ['access_token'],
556
+ identityAssertions: ['self_signed_screenshot'],
557
+ scopes: [{ name: 'catalog.read', access: 'read' }],
558
+ },
559
+ },
560
+ },
561
+ expectedState: 'blocked',
562
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'unsupported_identity_assertion'],
563
+ },
564
+ anonymousWriteScopeArd: {
565
+ description: 'ARD/AI Catalog provider auth metadata offering anonymous write scopes fails closed too.',
566
+ requiredCase: 'anonymous_write_scope',
567
+ input: {
568
+ candidateId: 'ai-catalog:urn:example:agents:anonymous-write',
569
+ source: {
570
+ kind: 'ai-catalog',
571
+ catalog: {
572
+ schemaVersion: 'ai-catalog.v1',
573
+ publisher: { id: 'example.com' },
574
+ rawSnapshotRef: 'sha256:anonymous-write-fixture',
575
+ resources: [
576
+ {
577
+ id: 'urn:example:agents:anonymous-write',
578
+ type: 'application/mcp-server-card+json',
579
+ mediaType: 'application/mcp-server-card+json',
580
+ name: 'Anonymous Write Agent',
581
+ url: 'https://agents.example.com/anonymous-write/mcp.json',
582
+ auth: {
583
+ registrationTypes: ['anonymous'],
584
+ scopes: [{ name: 'listings.write', access: 'write' }],
585
+ },
586
+ raw: {
587
+ identifier: 'urn:example:agents:anonymous-write',
588
+ displayName: 'Anonymous Write Agent',
589
+ mediaType: 'application/mcp-server-card+json',
590
+ url: 'https://agents.example.com/anonymous-write/mcp.json',
591
+ },
592
+ },
593
+ ],
594
+ },
595
+ resourceId: 'urn:example:agents:anonymous-write',
596
+ },
597
+ },
598
+ expectedState: 'blocked',
599
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'anonymous_write_scope_rejected'],
600
+ },
601
+ highRelevanceBlockedArd: {
602
+ description: 'a maximally relevant ARD/AI Catalog candidate with credential leakage is still blocked; relevance never rescues trust.',
603
+ requiredCase: 'high_relevance_blocked_candidate',
604
+ input: {
605
+ candidateId: 'ai-catalog:urn:example:agents:credential-bearing',
606
+ source: { kind: 'ai-catalog', catalog: providerTrustFixtures.credentialBearingCatalog, resourceId: 'urn:example:agents:credential-bearing' },
607
+ relevance: { score: 0.99, source: 'fixture-ranker' },
608
+ },
609
+ expectedState: 'blocked',
610
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'credential_leakage_rejected', 'relevance_ignored_for_trust'],
611
+ },
612
+ needsHumanReviewAuthMd: {
613
+ description: 'auth.md metadata that self-asserts a verified status is routed to human review, never auto-trusted.',
614
+ input: {
615
+ candidateId: 'auth-md:example.com:self-asserted-verified',
616
+ source: {
617
+ kind: 'auth-md',
618
+ metadata: {
619
+ url: 'https://agents.example.com/.well-known/auth.md',
620
+ authorizationServer: 'https://auth.example.com',
621
+ credentialTypes: ['access_token'],
622
+ scopes: [{ name: 'catalog.read', access: 'read' }],
623
+ trust: {
624
+ trustManifest: 'https://agents.example.com/trust-manifest.json',
625
+ status: 'verified',
626
+ },
627
+ },
628
+ },
629
+ },
630
+ expectedState: 'needs_human_review',
631
+ expectedFindingCodes: ['listed_untrusted_on_entry', 'self_asserted_verification_ignored'],
632
+ },
633
+ };
634
+ export function buildSourceTrustConformanceMatrix(cases = sourceTrustConformanceFixtureCases) {
635
+ const rows = Object.entries(cases).map(([fixtureId, fixture]) => ({
636
+ fixtureId,
637
+ description: fixture.description,
638
+ requiredCase: fixture.requiredCase,
639
+ ...classifySourceTrustCandidate(fixture.input),
640
+ }));
641
+ const states = Object.fromEntries(SOURCE_TRUST_STATES.map((state) => [state, 0]));
642
+ const requiredCases = Object.fromEntries(SOURCE_TRUST_REQUIRED_CASES.map((item) => [item, 0]));
643
+ const sourceKinds = { 'auth-md': 0, 'ai-catalog': 0 };
644
+ for (const row of rows) {
645
+ states[row.state] += 1;
646
+ sourceKinds[row.sourceKind] += 1;
647
+ if (row.requiredCase)
648
+ requiredCases[row.requiredCase] += 1;
649
+ }
650
+ const missingStates = SOURCE_TRUST_STATES.filter((state) => states[state] === 0);
651
+ const missingRequiredCases = SOURCE_TRUST_REQUIRED_CASES.filter((item) => requiredCases[item] === 0);
652
+ return {
653
+ schemaVersion: SOURCE_TRUST_CONFORMANCE_MATRIX_SCHEMA_VERSION,
654
+ boundary: {
655
+ untrustedUntilGated: true,
656
+ distinguishesRelevanceFrom: ['trust', 'policy', 'payment', 'evidence', 'reputation'],
657
+ boundariesDocRef: SOURCE_TRUST_BOUNDARIES_DOC_REF,
658
+ },
659
+ rows,
660
+ coverage: {
661
+ states,
662
+ requiredCases,
663
+ sourceKinds,
664
+ missingStates,
665
+ missingRequiredCases,
666
+ complete: missingStates.length === 0
667
+ && missingRequiredCases.length === 0
668
+ && sourceKinds['auth-md'] > 0
669
+ && sourceKinds['ai-catalog'] > 0,
670
+ },
671
+ };
672
+ }