@docs-sdk-dev/reader 0.0.0-stage → 0.4.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/annotation-projection.d.ts +35 -0
  4. package/dist/annotation-projection.js +78 -0
  5. package/dist/annotation-projection.js.map +1 -0
  6. package/dist/artifacts.d.ts +19 -0
  7. package/dist/artifacts.js +33 -0
  8. package/dist/artifacts.js.map +1 -0
  9. package/dist/ask.d.ts +41 -0
  10. package/dist/ask.js +89 -0
  11. package/dist/ask.js.map +1 -0
  12. package/dist/collection-view.d.ts +190 -0
  13. package/dist/collection-view.js +170 -0
  14. package/dist/collection-view.js.map +1 -0
  15. package/dist/composition.d.ts +199 -0
  16. package/dist/composition.js +473 -0
  17. package/dist/composition.js.map +1 -0
  18. package/dist/condition.d.ts +17 -0
  19. package/dist/condition.js +61 -0
  20. package/dist/condition.js.map +1 -0
  21. package/dist/content-schema.d.ts +182 -0
  22. package/dist/content-schema.js +288 -0
  23. package/dist/content-schema.js.map +1 -0
  24. package/dist/context-search.d.ts +168 -0
  25. package/dist/context-search.js +73 -0
  26. package/dist/context-search.js.map +1 -0
  27. package/dist/context-store.d.ts +93 -0
  28. package/dist/context-store.js +438 -0
  29. package/dist/context-store.js.map +1 -0
  30. package/dist/dimension-runtime.d.ts +203 -0
  31. package/dist/dimension-runtime.js +737 -0
  32. package/dist/dimension-runtime.js.map +1 -0
  33. package/dist/dimensions.d.ts +84 -0
  34. package/dist/dimensions.js +136 -0
  35. package/dist/dimensions.js.map +1 -0
  36. package/dist/directory-navigation.d.ts +60 -0
  37. package/dist/directory-navigation.js +41 -0
  38. package/dist/directory-navigation.js.map +1 -0
  39. package/dist/directory-sections.d.ts +9 -0
  40. package/dist/directory-sections.js +76 -0
  41. package/dist/directory-sections.js.map +1 -0
  42. package/dist/document-reader.d.ts +1017 -0
  43. package/dist/document-reader.js +396 -0
  44. package/dist/document-reader.js.map +1 -0
  45. package/dist/document-selection.d.ts +412 -0
  46. package/dist/document-selection.js +45 -0
  47. package/dist/document-selection.js.map +1 -0
  48. package/dist/evidence.d.ts +102 -0
  49. package/dist/evidence.js +104 -0
  50. package/dist/evidence.js.map +1 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +23 -0
  53. package/dist/model.d.ts +89 -0
  54. package/dist/model.js +31 -0
  55. package/dist/model.js.map +1 -0
  56. package/dist/module.d.ts +657 -0
  57. package/dist/module.js +199 -0
  58. package/dist/module.js.map +1 -0
  59. package/dist/navigation-view.d.ts +33 -0
  60. package/dist/navigation-view.js +68 -0
  61. package/dist/navigation-view.js.map +1 -0
  62. package/dist/node.d.ts +2004 -0
  63. package/dist/node.js +210 -0
  64. package/dist/node.js.map +1 -0
  65. package/dist/open-docs.d.ts +1396 -0
  66. package/dist/open-docs.js +198 -0
  67. package/dist/open-docs.js.map +1 -0
  68. package/dist/outline.d.ts +97 -0
  69. package/dist/outline.js +171 -0
  70. package/dist/outline.js.map +1 -0
  71. package/dist/persistence.d.ts +82 -0
  72. package/dist/persistence.js +377 -0
  73. package/dist/persistence.js.map +1 -0
  74. package/dist/projection-catalog.d.ts +23 -0
  75. package/dist/projection-catalog.js +45 -0
  76. package/dist/projection-catalog.js.map +1 -0
  77. package/dist/publication.d.ts +59 -0
  78. package/dist/publication.js +11 -0
  79. package/dist/publication.js.map +1 -0
  80. package/dist/reader.d.ts +236 -0
  81. package/dist/reader.js +400 -0
  82. package/dist/reader.js.map +1 -0
  83. package/dist/references.d.ts +54 -0
  84. package/dist/references.js +70 -0
  85. package/dist/references.js.map +1 -0
  86. package/dist/retrieval.d.ts +82 -0
  87. package/dist/retrieval.js +135 -0
  88. package/dist/retrieval.js.map +1 -0
  89. package/dist/search-view.d.ts +11 -0
  90. package/dist/search-view.js +30 -0
  91. package/dist/search-view.js.map +1 -0
  92. package/dist/search.d.ts +95 -0
  93. package/dist/search.js +234 -0
  94. package/dist/search.js.map +1 -0
  95. package/dist/semantic.d.ts +177 -0
  96. package/dist/semantic.js +104 -0
  97. package/dist/semantic.js.map +1 -0
  98. package/dist/skills.d.ts +21 -0
  99. package/dist/skills.js +42 -0
  100. package/dist/skills.js.map +1 -0
  101. package/docs/index.md +10 -0
  102. package/docs/sdk/composition.md +72 -0
  103. package/docs/sdk/reader-storage.md +70 -0
  104. package/docs/sdk/reader.md +99 -0
  105. package/docs/zh-CN/sdk/composition.md +72 -0
  106. package/docs/zh-CN/sdk/reader-storage.md +70 -0
  107. package/docs/zh-CN/sdk/reader.md +99 -0
  108. package/package.json +69 -4
@@ -0,0 +1,412 @@
1
+ import type { createReader, Manifest } from "./document-reader.js";
2
+ import type { Identity } from "./model.js";
3
+ import type { Context } from "./semantic.js";
4
+ /** Resolve editions and context projections without reading document bodies. */
5
+ export declare function createDocumentSelector(reader: ReturnType<typeof createReader>, manifest: Pick<Manifest, "documents">): (identity: Identity, options?: {
6
+ match?: "exact" | "edition";
7
+ fallback?: Context;
8
+ }) => {
9
+ status: "exact" | "fallback";
10
+ value: {
11
+ key: string;
12
+ identity: Identity & {
13
+ dimensions: Record<string, string>;
14
+ };
15
+ route: string;
16
+ title: string;
17
+ availability?: Context;
18
+ navigationHidden?: boolean;
19
+ outlineView?: import("./outline.js").OutlineView | null;
20
+ description?: string;
21
+ meta?: Record<string, import("./content-schema.js").JsonValue>;
22
+ showMetadata?: readonly string[];
23
+ presentation?: {
24
+ layout?: string | false;
25
+ actions?: readonly {
26
+ text: string;
27
+ href: string;
28
+ }[];
29
+ rendererProfile?: string;
30
+ };
31
+ origin?: {
32
+ kind: "generated" | "overlay" | "authored";
33
+ collection: string;
34
+ source: string;
35
+ upstreamRevision: string;
36
+ authored?: string;
37
+ };
38
+ mode: "template" | "replacement" | "markdown";
39
+ template?: {
40
+ id: string;
41
+ revision: string;
42
+ };
43
+ provenance: import("./model.js").Provenance[];
44
+ markdown: string;
45
+ contextDefaults?: Context;
46
+ contextVariants?: {
47
+ context: Context;
48
+ markdown: string;
49
+ sections: {
50
+ id: string;
51
+ title?: string;
52
+ documentOffset?: number;
53
+ markdown: string;
54
+ provenance: import("./model.js").Provenance[];
55
+ outline?: import("./outline.js").OutlineContribution[];
56
+ headings?: {
57
+ id: string;
58
+ text: string;
59
+ depth: number;
60
+ }[];
61
+ headingRanges?: readonly (readonly [number, number])[];
62
+ outlineRanges?: Record<string, readonly [number, number]>;
63
+ headingFiles?: Record<number, string>;
64
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
65
+ }[];
66
+ }[];
67
+ sections: {
68
+ id: string;
69
+ title?: string;
70
+ documentOffset?: number;
71
+ markdown: string;
72
+ provenance: import("./model.js").Provenance[];
73
+ outline?: import("./outline.js").OutlineContribution[];
74
+ headings?: {
75
+ id: string;
76
+ text: string;
77
+ depth: number;
78
+ }[];
79
+ headingRanges?: readonly (readonly [number, number])[];
80
+ outlineRanges?: Record<string, readonly [number, number]>;
81
+ headingFiles?: Record<number, string>;
82
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
83
+ }[];
84
+ losses?: (import("./model.js").ProjectionLoss & {
85
+ section: string;
86
+ })[];
87
+ };
88
+ resolution: Pick<import("./dimension-runtime.js").DimensionInspection<{
89
+ key: string;
90
+ identity: Identity & {
91
+ dimensions: Record<string, string>;
92
+ };
93
+ route: string;
94
+ title: string;
95
+ availability?: Context;
96
+ navigationHidden?: boolean;
97
+ outlineView?: import("./outline.js").OutlineView | null;
98
+ description?: string;
99
+ meta?: Record<string, import("./content-schema.js").JsonValue>;
100
+ showMetadata?: readonly string[];
101
+ presentation?: {
102
+ layout?: string | false;
103
+ actions?: readonly {
104
+ text: string;
105
+ href: string;
106
+ }[];
107
+ rendererProfile?: string;
108
+ };
109
+ origin?: {
110
+ kind: "generated" | "overlay" | "authored";
111
+ collection: string;
112
+ source: string;
113
+ upstreamRevision: string;
114
+ authored?: string;
115
+ };
116
+ mode: "template" | "replacement" | "markdown";
117
+ template?: {
118
+ id: string;
119
+ revision: string;
120
+ };
121
+ provenance: import("./model.js").Provenance[];
122
+ markdown: string;
123
+ contextDefaults?: Context;
124
+ contextVariants?: {
125
+ context: Context;
126
+ markdown: string;
127
+ sections: {
128
+ id: string;
129
+ title?: string;
130
+ documentOffset?: number;
131
+ markdown: string;
132
+ provenance: import("./model.js").Provenance[];
133
+ outline?: import("./outline.js").OutlineContribution[];
134
+ headings?: {
135
+ id: string;
136
+ text: string;
137
+ depth: number;
138
+ }[];
139
+ headingRanges?: readonly (readonly [number, number])[];
140
+ outlineRanges?: Record<string, readonly [number, number]>;
141
+ headingFiles?: Record<number, string>;
142
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
143
+ }[];
144
+ }[];
145
+ sections: {
146
+ id: string;
147
+ title?: string;
148
+ documentOffset?: number;
149
+ markdown: string;
150
+ provenance: import("./model.js").Provenance[];
151
+ outline?: import("./outline.js").OutlineContribution[];
152
+ headings?: {
153
+ id: string;
154
+ text: string;
155
+ depth: number;
156
+ }[];
157
+ headingRanges?: readonly (readonly [number, number])[];
158
+ outlineRanges?: Record<string, readonly [number, number]>;
159
+ headingFiles?: Record<number, string>;
160
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
161
+ }[];
162
+ losses?: (import("./model.js").ProjectionLoss & {
163
+ section: string;
164
+ })[];
165
+ }>, "effective" | "reasons" | "requested" | "resolved" | "status"> | undefined;
166
+ effective: Context | undefined;
167
+ } | ({
168
+ status: "not-found";
169
+ } & {
170
+ resolution?: Pick<import("./dimension-runtime.js").DimensionInspection<{
171
+ key: string;
172
+ identity: Identity & {
173
+ dimensions: Record<string, string>;
174
+ };
175
+ route: string;
176
+ title: string;
177
+ availability?: Context;
178
+ navigationHidden?: boolean;
179
+ outlineView?: import("./outline.js").OutlineView | null;
180
+ description?: string;
181
+ meta?: Record<string, import("./content-schema.js").JsonValue>;
182
+ showMetadata?: readonly string[];
183
+ presentation?: {
184
+ layout?: string | false;
185
+ actions?: readonly {
186
+ text: string;
187
+ href: string;
188
+ }[];
189
+ rendererProfile?: string;
190
+ };
191
+ origin?: {
192
+ kind: "generated" | "overlay" | "authored";
193
+ collection: string;
194
+ source: string;
195
+ upstreamRevision: string;
196
+ authored?: string;
197
+ };
198
+ mode: "template" | "replacement" | "markdown";
199
+ template?: {
200
+ id: string;
201
+ revision: string;
202
+ };
203
+ provenance: import("./model.js").Provenance[];
204
+ markdown: string;
205
+ contextDefaults?: Context;
206
+ contextVariants?: {
207
+ context: Context;
208
+ markdown: string;
209
+ sections: {
210
+ id: string;
211
+ title?: string;
212
+ documentOffset?: number;
213
+ markdown: string;
214
+ provenance: import("./model.js").Provenance[];
215
+ outline?: import("./outline.js").OutlineContribution[];
216
+ headings?: {
217
+ id: string;
218
+ text: string;
219
+ depth: number;
220
+ }[];
221
+ headingRanges?: readonly (readonly [number, number])[];
222
+ outlineRanges?: Record<string, readonly [number, number]>;
223
+ headingFiles?: Record<number, string>;
224
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
225
+ }[];
226
+ }[];
227
+ sections: {
228
+ id: string;
229
+ title?: string;
230
+ documentOffset?: number;
231
+ markdown: string;
232
+ provenance: import("./model.js").Provenance[];
233
+ outline?: import("./outline.js").OutlineContribution[];
234
+ headings?: {
235
+ id: string;
236
+ text: string;
237
+ depth: number;
238
+ }[];
239
+ headingRanges?: readonly (readonly [number, number])[];
240
+ outlineRanges?: Record<string, readonly [number, number]>;
241
+ headingFiles?: Record<number, string>;
242
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
243
+ }[];
244
+ losses?: (import("./model.js").ProjectionLoss & {
245
+ section: string;
246
+ })[];
247
+ }>, "effective" | "reasons" | "requested" | "resolved" | "status">;
248
+ }) | ({
249
+ status: "unsupported-context";
250
+ available: Context[];
251
+ } & {
252
+ resolution?: Pick<import("./dimension-runtime.js").DimensionInspection<{
253
+ key: string;
254
+ identity: Identity & {
255
+ dimensions: Record<string, string>;
256
+ };
257
+ route: string;
258
+ title: string;
259
+ availability?: Context;
260
+ navigationHidden?: boolean;
261
+ outlineView?: import("./outline.js").OutlineView | null;
262
+ description?: string;
263
+ meta?: Record<string, import("./content-schema.js").JsonValue>;
264
+ showMetadata?: readonly string[];
265
+ presentation?: {
266
+ layout?: string | false;
267
+ actions?: readonly {
268
+ text: string;
269
+ href: string;
270
+ }[];
271
+ rendererProfile?: string;
272
+ };
273
+ origin?: {
274
+ kind: "generated" | "overlay" | "authored";
275
+ collection: string;
276
+ source: string;
277
+ upstreamRevision: string;
278
+ authored?: string;
279
+ };
280
+ mode: "template" | "replacement" | "markdown";
281
+ template?: {
282
+ id: string;
283
+ revision: string;
284
+ };
285
+ provenance: import("./model.js").Provenance[];
286
+ markdown: string;
287
+ contextDefaults?: Context;
288
+ contextVariants?: {
289
+ context: Context;
290
+ markdown: string;
291
+ sections: {
292
+ id: string;
293
+ title?: string;
294
+ documentOffset?: number;
295
+ markdown: string;
296
+ provenance: import("./model.js").Provenance[];
297
+ outline?: import("./outline.js").OutlineContribution[];
298
+ headings?: {
299
+ id: string;
300
+ text: string;
301
+ depth: number;
302
+ }[];
303
+ headingRanges?: readonly (readonly [number, number])[];
304
+ outlineRanges?: Record<string, readonly [number, number]>;
305
+ headingFiles?: Record<number, string>;
306
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
307
+ }[];
308
+ }[];
309
+ sections: {
310
+ id: string;
311
+ title?: string;
312
+ documentOffset?: number;
313
+ markdown: string;
314
+ provenance: import("./model.js").Provenance[];
315
+ outline?: import("./outline.js").OutlineContribution[];
316
+ headings?: {
317
+ id: string;
318
+ text: string;
319
+ depth: number;
320
+ }[];
321
+ headingRanges?: readonly (readonly [number, number])[];
322
+ outlineRanges?: Record<string, readonly [number, number]>;
323
+ headingFiles?: Record<number, string>;
324
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
325
+ }[];
326
+ losses?: (import("./model.js").ProjectionLoss & {
327
+ section: string;
328
+ })[];
329
+ }>, "effective" | "reasons" | "requested" | "resolved" | "status">;
330
+ }) | ({
331
+ status: "ambiguous";
332
+ candidates: Context[];
333
+ } & {
334
+ resolution?: Pick<import("./dimension-runtime.js").DimensionInspection<{
335
+ key: string;
336
+ identity: Identity & {
337
+ dimensions: Record<string, string>;
338
+ };
339
+ route: string;
340
+ title: string;
341
+ availability?: Context;
342
+ navigationHidden?: boolean;
343
+ outlineView?: import("./outline.js").OutlineView | null;
344
+ description?: string;
345
+ meta?: Record<string, import("./content-schema.js").JsonValue>;
346
+ showMetadata?: readonly string[];
347
+ presentation?: {
348
+ layout?: string | false;
349
+ actions?: readonly {
350
+ text: string;
351
+ href: string;
352
+ }[];
353
+ rendererProfile?: string;
354
+ };
355
+ origin?: {
356
+ kind: "generated" | "overlay" | "authored";
357
+ collection: string;
358
+ source: string;
359
+ upstreamRevision: string;
360
+ authored?: string;
361
+ };
362
+ mode: "template" | "replacement" | "markdown";
363
+ template?: {
364
+ id: string;
365
+ revision: string;
366
+ };
367
+ provenance: import("./model.js").Provenance[];
368
+ markdown: string;
369
+ contextDefaults?: Context;
370
+ contextVariants?: {
371
+ context: Context;
372
+ markdown: string;
373
+ sections: {
374
+ id: string;
375
+ title?: string;
376
+ documentOffset?: number;
377
+ markdown: string;
378
+ provenance: import("./model.js").Provenance[];
379
+ outline?: import("./outline.js").OutlineContribution[];
380
+ headings?: {
381
+ id: string;
382
+ text: string;
383
+ depth: number;
384
+ }[];
385
+ headingRanges?: readonly (readonly [number, number])[];
386
+ outlineRanges?: Record<string, readonly [number, number]>;
387
+ headingFiles?: Record<number, string>;
388
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
389
+ }[];
390
+ }[];
391
+ sections: {
392
+ id: string;
393
+ title?: string;
394
+ documentOffset?: number;
395
+ markdown: string;
396
+ provenance: import("./model.js").Provenance[];
397
+ outline?: import("./outline.js").OutlineContribution[];
398
+ headings?: {
399
+ id: string;
400
+ text: string;
401
+ depth: number;
402
+ }[];
403
+ headingRanges?: readonly (readonly [number, number])[];
404
+ outlineRanges?: Record<string, readonly [number, number]>;
405
+ headingFiles?: Record<number, string>;
406
+ headingIndexes?: import("./model.js").MarkdownHeadingIndexes;
407
+ }[];
408
+ losses?: (import("./model.js").ProjectionLoss & {
409
+ section: string;
410
+ })[];
411
+ }>, "effective" | "reasons" | "requested" | "resolved" | "status">;
412
+ });
@@ -0,0 +1,45 @@
1
+ // src/document-selection.ts
2
+ /** Resolve editions and context projections without reading document bodies. */
3
+ function createDocumentSelector(reader, manifest) {
4
+ const contextual = manifest.documents.some((page) => page.availability || page.contextVariants?.length);
5
+ return function selectDocument(identity, options = {}) {
6
+ const exact = options.match === "exact";
7
+ const requested = identity.dimensions ?? {};
8
+ const preferences = exact && contextual ? new Set(reader.context(identity).definitions.filter((axis) => axis.kind === "preference").map((axis) => axis.name)) : void 0;
9
+ const resolveFor = (values) => {
10
+ const dimensions = preferences ? Object.fromEntries(Object.entries(values).filter(([key]) => !preferences.has(key))) : values;
11
+ const target = {
12
+ ...identity,
13
+ dimensions
14
+ };
15
+ return exact ? reader.resolve(target) : reader.resolveEdition(target);
16
+ };
17
+ const primary = resolveFor(requested);
18
+ const fallback = !exact && primary.status === "unsupported-context" ? options.fallback : void 0;
19
+ const selected = fallback === void 0 ? requested : {
20
+ ...requested,
21
+ ...fallback
22
+ };
23
+ const result = fallback === void 0 ? primary : resolveFor(selected);
24
+ if (result.status !== "exact") return result;
25
+ const effective = contextual ? reader.context(result.value.identity, {
26
+ requested: selected,
27
+ edition: result.value.identity.dimensions
28
+ }).effective : void 0;
29
+ const page = effective ? reader.projection(result.value.identity, effective) : result.value;
30
+ if (!page) return {
31
+ status: "unsupported-context",
32
+ available: [result.value.availability ?? result.value.identity.dimensions],
33
+ resolution: result.resolution
34
+ };
35
+ return {
36
+ status: fallback !== void 0 || result.resolution?.status === "fallback" ? "fallback" : "exact",
37
+ value: page,
38
+ resolution: result.resolution,
39
+ effective
40
+ };
41
+ };
42
+ }
43
+
44
+ export { createDocumentSelector };
45
+ //# sourceMappingURL=document-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-selection.js","names":[],"sources":["../src/document-selection.ts"],"sourcesContent":["import type { createReader, Manifest } from \"./document-reader.js\"\nimport type { Identity } from \"./model.js\"\nimport type { Context } from \"./semantic.js\"\n\n/** Resolve editions and context projections without reading document bodies. */\nexport function createDocumentSelector(\n reader: ReturnType<typeof createReader>,\n manifest: Pick<Manifest, \"documents\">,\n) {\n const contextual = manifest.documents.some(\n (page) => page.availability || page.contextVariants?.length,\n )\n return function selectDocument(\n identity: Identity,\n options: { match?: \"exact\" | \"edition\"; fallback?: Context } = {},\n ) {\n const exact = options.match === \"exact\"\n const requested = identity.dimensions ?? {}\n const preferences =\n exact && contextual\n ? new Set(\n reader\n .context(identity)\n .definitions.filter((axis) => axis.kind === \"preference\")\n .map((axis) => axis.name),\n )\n : undefined\n const resolveFor = (values: Context): ReturnType<typeof reader.resolveEdition> => {\n const dimensions = preferences\n ? Object.fromEntries(Object.entries(values).filter(([key]) => !preferences.has(key)))\n : values\n const target = { ...identity, dimensions }\n return exact ? reader.resolve(target) : reader.resolveEdition(target)\n }\n const primary = resolveFor(requested)\n const fallback =\n !exact && primary.status === \"unsupported-context\" ? options.fallback : undefined\n const selected = fallback === undefined ? requested : { ...requested, ...fallback }\n const result = fallback === undefined ? primary : resolveFor(selected)\n if (result.status !== \"exact\") return result\n const effective = contextual\n ? reader.context(result.value.identity, {\n requested: selected,\n edition: result.value.identity.dimensions,\n }).effective\n : undefined\n const page = effective ? reader.projection(result.value.identity, effective) : result.value\n if (!page)\n return {\n status: \"unsupported-context\" as const,\n available: [result.value.availability ?? result.value.identity.dimensions],\n resolution: result.resolution,\n }\n return {\n status:\n fallback !== undefined || result.resolution?.status === \"fallback\"\n ? (\"fallback\" as const)\n : (\"exact\" as const),\n value: page,\n resolution: result.resolution,\n effective,\n }\n }\n}\n"],"mappings":";;AAKA,SAAgB,uBACd,QACA,UACA;CACA,MAAM,aAAa,SAAS,UAAU,MACnC,SAAS,KAAK,gBAAgB,KAAK,iBAAiB,MACvD;CACA,OAAO,SAAS,eACd,UACA,UAA+D,CAAC,GAChE;EACA,MAAM,QAAQ,QAAQ,UAAU;EAChC,MAAM,YAAY,SAAS,cAAc,CAAC;EAC1C,MAAM,cACJ,SAAS,aACL,IAAI,IACF,OACG,QAAQ,QAAQ,CAAC,CACjB,YAAY,QAAQ,SAAS,KAAK,SAAS,YAAY,CAAC,CACxD,KAAK,SAAS,KAAK,IAAI,CAC5B,IACA;EACN,MAAM,cAAc,WAA8D;GAChF,MAAM,aAAa,cACf,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,IAAI,GAAG,CAAC,CAAC,IAClF;GACJ,MAAM,SAAS;IAAE,GAAG;IAAU;GAAW;GACzC,OAAO,QAAQ,OAAO,QAAQ,MAAM,IAAI,OAAO,eAAe,MAAM;EACtE;EACA,MAAM,UAAU,WAAW,SAAS;EACpC,MAAM,WACJ,CAAC,SAAS,QAAQ,WAAW,wBAAwB,QAAQ,WAAW;EAC1E,MAAM,WAAW,aAAa,SAAY,YAAY;GAAE,GAAG;GAAW,GAAG;EAAS;EAClF,MAAM,SAAS,aAAa,SAAY,UAAU,WAAW,QAAQ;EACrE,IAAI,OAAO,WAAW,SAAS,OAAO;EACtC,MAAM,YAAY,aACd,OAAO,QAAQ,OAAO,MAAM,UAAU;GACpC,WAAW;GACX,SAAS,OAAO,MAAM,SAAS;EACjC,CAAC,CAAC,CAAC,YACH;EACJ,MAAM,OAAO,YAAY,OAAO,WAAW,OAAO,MAAM,UAAU,SAAS,IAAI,OAAO;EACtF,IAAI,CAAC,MACH,OAAO;GACL,QAAQ;GACR,WAAW,CAAC,OAAO,MAAM,gBAAgB,OAAO,MAAM,SAAS,UAAU;GACzE,YAAY,OAAO;EACrB;EACF,OAAO;GACL,QACE,aAAa,UAAa,OAAO,YAAY,WAAW,aACnD,aACA;GACP,OAAO;GACP,YAAY,OAAO;GACnB;EACF;CACF;AACF"}
@@ -0,0 +1,102 @@
1
+ import type { openPinnedReader } from "./document-reader.js";
2
+ import { type Context, type EntityVariant } from "./semantic.js";
3
+ import type { Provenance } from "./model.js";
4
+ /** Hash this canonical UTF-8 payload with SHA-256 to match the recorded Example Runtime environment. */
5
+ export declare function evidenceEnvironmentPayload(target: Record<string, unknown>, toolchain: Record<string, string>, lockfileSha256: string): string;
6
+ export interface CheckEnvironment {
7
+ /** Exact versions recorded by the verifier. */
8
+ software: Record<string, string>;
9
+ validator: {
10
+ id: string;
11
+ version: string;
12
+ };
13
+ environmentDigest: string;
14
+ }
15
+ export interface FactCheckReceipt extends CheckEnvironment {
16
+ entity: string;
17
+ variant: string;
18
+ revision: string;
19
+ check: string;
20
+ outcome: "passed" | "failed" | "skipped";
21
+ source: string;
22
+ implementationRevision: string;
23
+ report: {
24
+ source: string;
25
+ revision: string;
26
+ };
27
+ }
28
+ /** Reuse one recorded check only for the exact fact, installed versions, validator and measured environment. */
29
+ export declare function assessFactCheck(receipt: FactCheckReceipt, current: {
30
+ entity: string;
31
+ variant: EntityVariant;
32
+ } & CheckEnvironment): {
33
+ status: "stale";
34
+ reasons: string[];
35
+ } | {
36
+ reasons?: undefined;
37
+ status: "failed" | "passed" | "unverified";
38
+ };
39
+ export interface FactFinding {
40
+ entity: string;
41
+ contract: string;
42
+ message: string;
43
+ severity: "warning" | "error";
44
+ waived?: string;
45
+ evidence: Provenance[];
46
+ }
47
+ /** Inspect checks recorded by one pinned publication. The reader never invokes a provider or validator. */
48
+ export declare function createEvidenceReader(publication: Pick<Awaited<ReturnType<typeof openPinnedReader>>, "manifest" | "readText">, facts?: {
49
+ revision: string;
50
+ subject: (subject: string) => Promise<null> | Promise<Pick<import("./semantic.js").SemanticIndex, "entities" | "relations">>;
51
+ loaded: () => string[];
52
+ entities({ subjectPrefix, type, after, }?: {
53
+ subjectPrefix?: string;
54
+ type?: string;
55
+ after?: string;
56
+ }): AsyncGenerator<import("./semantic.js").SemanticEntity<unknown>, void, unknown>;
57
+ entity(id: string): Promise<import("./semantic.js").SemanticEntity<unknown> | null>;
58
+ resolve(id: string, context?: Context): Promise<import("./semantic.js").Resolution<EntityVariant<unknown>>>;
59
+ relations(id: string, options?: import("./reader.js").RelationQuery): Promise<import("./semantic.js").Relation[]>;
60
+ trace(id: string, context?: Context, options?: import("./reader.js").TraceOptions): Promise<import("./semantic.js").Resolution<import("./reader.js").TraceStep[]>>;
61
+ loadAll(): Promise<import("./semantic.js").SemanticIndex>;
62
+ } | undefined): (entity: string, context?: Context, options?: {
63
+ contracts?: boolean;
64
+ }) => Promise<{
65
+ status: "not-found";
66
+ } | {
67
+ status: "unsupported-context";
68
+ available: Context[];
69
+ } | {
70
+ status: "ambiguous";
71
+ candidates: Context[];
72
+ } | {
73
+ status: "exact";
74
+ entity: string;
75
+ variant: string;
76
+ revision: string;
77
+ sources: {
78
+ git?: {
79
+ source: string;
80
+ commit: string;
81
+ path: string;
82
+ ownership: "upstream";
83
+ };
84
+ source: string;
85
+ revision?: string;
86
+ symbol?: string;
87
+ layer?: "template" | "collection" | "entry";
88
+ position?: "before" | "body" | "after";
89
+ range?: {
90
+ start: number;
91
+ end: number;
92
+ };
93
+ extractor?: {
94
+ name: string;
95
+ version: string;
96
+ };
97
+ evidence?: import("./semantic.js").Evidence;
98
+ origin: "authored" | "declared" | "extracted" | "inferred" | "unclassified";
99
+ }[];
100
+ checks: FactCheckReceipt[];
101
+ findings?: FactFinding[] | undefined;
102
+ }>;
@@ -0,0 +1,104 @@
1
+ import { createSemanticLoader } from "./reader.js";
2
+ import { canonicalJson } from "./semantic.js";
3
+
4
+ // src/evidence.ts
5
+ /** Hash this canonical UTF-8 payload with SHA-256 to match the recorded Example Runtime environment. */
6
+ function evidenceEnvironmentPayload(target, toolchain, lockfileSha256) {
7
+ return canonicalJson({
8
+ target,
9
+ toolchain,
10
+ lockfile: lockfileSha256
11
+ });
12
+ }
13
+ const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
14
+ const digest = (value) => typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
15
+ const versions = (value) => object(value) && Object.keys(value).length > 0 && Object.values(value).every((v) => typeof v === "string" && !!v);
16
+ /** Reuse one recorded check only for the exact fact, installed versions, validator and measured environment. */
17
+ function assessFactCheck(receipt, current) {
18
+ const stale = [];
19
+ if (current.entity !== receipt.entity || current.variant.variantId !== receipt.variant) stale.push("subject");
20
+ if (current.variant.revision !== receipt.revision) stale.push("revision");
21
+ if (Object.entries(receipt.software).some(([pkg, version]) => !Object.hasOwn(current.software, pkg) || current.software[pkg] !== version)) stale.push("software");
22
+ if (canonicalJson(current.validator) !== canonicalJson(receipt.validator)) stale.push("validator");
23
+ if (current.environmentDigest !== receipt.environmentDigest) stale.push("environment");
24
+ return stale.length ? {
25
+ status: "stale",
26
+ reasons: stale
27
+ } : { status: receipt.outcome === "skipped" ? "unverified" : receipt.outcome };
28
+ }
29
+ function exampleChecks(entity, variant, receipts) {
30
+ const data = variant.data;
31
+ if (!entity.startsWith("example:") || !object(data) || !object(data.verification) || !object(data.adapter) || !Array.isArray(data.checks)) return [];
32
+ const { environmentDigest, software, reportDigest, manifest } = data.verification;
33
+ if (!digest(environmentDigest) || !digest(reportDigest) || typeof manifest !== "string" || !versions(software) || typeof data.adapter.id !== "string" || !data.adapter.id || typeof data.adapter.version !== "string" || !data.adapter.version) return [];
34
+ const source = variant.provenance.find((item) => item.source === manifest);
35
+ const local = data.verification.kind === "local";
36
+ if (local && (data.adapter.id !== "docs-sdk/verify-examples" || source?.revision !== reportDigest)) return [];
37
+ const receipt = receipts.find((item) => local ? item.adapter === "example-verification:" + manifest && item.implementationRevision === "1" : item.adapter === "example-runtime:" + manifest && item.implementationRevision === "v1:" + source?.revision);
38
+ if (!source || !digest(source.revision) || !receipt?.facts?.some((fact) => fact.variant === variant.variantId && fact.revision === variant.factRevision) || !variant.provenance.every((item) => receipt.reads.some((input) => input.path === item.source && input.revision === item.revision))) return [];
39
+ const report = variant.provenance.find((item) => item.revision === reportDigest);
40
+ if (!report) return [];
41
+ const validator = {
42
+ id: data.adapter.id,
43
+ version: data.adapter.version
44
+ };
45
+ return data.checks.flatMap((check) => {
46
+ if (!object(check) || typeof check.kind !== "string" || ![
47
+ "passed",
48
+ "failed",
49
+ "skipped"
50
+ ].includes(String(check.status))) return [];
51
+ return [{
52
+ entity,
53
+ variant: variant.variantId,
54
+ revision: variant.revision,
55
+ check: check.kind,
56
+ outcome: check.status,
57
+ environmentDigest,
58
+ validator,
59
+ software,
60
+ source: receipt.adapter,
61
+ implementationRevision: receipt.implementationRevision,
62
+ report: {
63
+ source: report.source,
64
+ revision: reportDigest
65
+ }
66
+ }];
67
+ });
68
+ }
69
+ /** Inspect checks recorded by one pinned publication. The reader never invokes a provider or validator. */
70
+ function createEvidenceReader(publication, facts = publication.manifest.semantic && createSemanticLoader(publication.manifest.semantic, publication.readText)) {
71
+ const { manifest, readText } = publication;
72
+ let report;
73
+ return async function evidence(entity, context = {}, options = {}) {
74
+ if (!facts) return { status: "not-found" };
75
+ const result = await facts.resolve(entity, context);
76
+ if (result.status !== "exact") return result;
77
+ const variant = result.value;
78
+ const checks = exampleChecks(entity, variant, manifest.sources ?? []);
79
+ const sources = variant.provenance.map((source) => ({
80
+ ...source,
81
+ origin: source.evidence === "extracted" && source.extractor && source.revision ? "extracted" : entity.startsWith("document:") && object(variant.data) && variant.data.mode === "markdown" ? "authored" : source.evidence === "declared" || source.evidence === "inferred" ? source.evidence : "unclassified"
82
+ }));
83
+ let findings;
84
+ if (options.contracts && manifest.contracts) {
85
+ report ??= readText(manifest.contracts.path).then((text) => JSON.parse(text)).catch((error) => {
86
+ report = void 0;
87
+ throw error;
88
+ });
89
+ findings = (await report).findings.filter((finding) => finding.entity === variant.variantId);
90
+ }
91
+ return {
92
+ status: "exact",
93
+ entity,
94
+ variant: variant.variantId,
95
+ revision: variant.revision,
96
+ sources,
97
+ checks,
98
+ ...findings && { findings }
99
+ };
100
+ };
101
+ }
102
+
103
+ export { assessFactCheck, createEvidenceReader, evidenceEnvironmentPayload };
104
+ //# sourceMappingURL=evidence.js.map