@mfdaves/okf-mcp 0.3.3 → 0.5.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 (40) hide show
  1. package/.agents/skills/okf-v02-migration/SKILL.md +37 -0
  2. package/.agents/skills/okf-v02-migration/agents/openai.yaml +6 -0
  3. package/.agents/skills/okf-v02-migration/references/field-mapping.md +26 -0
  4. package/README.md +192 -78
  5. package/okf/bundles/okf-mcp/distribution/reference-bundle.md +2 -2
  6. package/okf/bundles/okf-mcp/index.md +7 -0
  7. package/okf/bundles/okf-mcp/interfaces/http-authoring-api.md +2 -2
  8. package/okf/bundles/okf-mcp/interfaces/mcp-tools.md +8 -4
  9. package/okf/bundles/okf-mcp/overview/okf-mcp.md +2 -2
  10. package/okf/bundles/okf-mcp/policies/authoring-safety.md +5 -3
  11. package/okf/bundles/okf-mcp/runtime/file-concept-store.md +7 -5
  12. package/okf/bundles/okf-mcp/runtime/indexer.md +6 -4
  13. package/okf/bundles/okf-mcp/runtime/mcp-server.md +6 -6
  14. package/okf/bundles/okf-mcp/specs/attested-computation.md +24 -0
  15. package/okf/bundles/okf-mcp/specs/concept-format.md +5 -3
  16. package/okf/bundles/okf-mcp/specs/git-sources.md +23 -0
  17. package/okf/bundles/okf-mcp/workflows/v02-migration.md +24 -0
  18. package/package.json +9 -3
  19. package/server.json +5 -5
  20. package/src/assets.js +469 -0
  21. package/src/authoring.js +492 -20
  22. package/src/cli.js +467 -37
  23. package/src/computation.js +366 -0
  24. package/src/git-source.js +551 -0
  25. package/src/graph.js +71 -18
  26. package/src/http-server.js +8 -1
  27. package/src/index.js +5 -0
  28. package/src/indexer.js +428 -24
  29. package/src/markdown.js +129 -0
  30. package/src/mcp-server.js +447 -313
  31. package/src/migration.js +687 -0
  32. package/src/parser.js +135 -54
  33. package/src/plugins.js +30 -50
  34. package/src/project.js +74 -17
  35. package/src/remote.js +232 -17
  36. package/src/search.js +69 -6
  37. package/src/store.js +421 -25
  38. package/src/v02.js +545 -0
  39. package/src/validation.js +13 -2
  40. package/src/mcp-protocol.js +0 -283
package/src/indexer.js CHANGED
@@ -3,6 +3,13 @@
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
5
  const { normalizeSlashes, parseMarkdownFile, parseMarkdownText, safeRelativePath } = require("./parser");
6
+ const {
7
+ buildAssetRegistry,
8
+ collectAssetReferences,
9
+ isExternalReference,
10
+ isLocalAssetReference,
11
+ mimeIsText,
12
+ } = require("./assets");
6
13
  const { DEFAULT_RELATION_TYPES, loadProjectConfig } = require("./project");
7
14
  const { fetchRemoteBundles } = require("./remote");
8
15
  const { validateIndex } = require("./validation");
@@ -20,6 +27,7 @@ function parseBundleArg(arg, index) {
20
27
  remote: Boolean(arg.remote),
21
28
  remoteSource: arg.remoteSource || null,
22
29
  documents: Array.isArray(arg.documents) ? arg.documents : [],
30
+ assets: Array.isArray(arg.assets) ? arg.assets : [],
23
31
  include: Array.isArray(arg.include) ? arg.include : [],
24
32
  exclude: Array.isArray(arg.exclude) ? arg.exclude : [],
25
33
  };
@@ -48,6 +56,7 @@ function uniqueBundleIds(bundles) {
48
56
  remote: Boolean(bundle.remote),
49
57
  remoteSource: bundle.remoteSource || null,
50
58
  documents: Array.isArray(bundle.documents) ? bundle.documents : [],
59
+ assets: Array.isArray(bundle.assets) ? bundle.assets : [],
51
60
  include: bundle.include || [],
52
61
  exclude: bundle.exclude || [],
53
62
  };
@@ -65,8 +74,13 @@ function patternToRegex(pattern) {
65
74
  const char = text[index];
66
75
  if (char === "*") {
67
76
  if (text[index + 1] === "*") {
68
- source += ".*";
69
- index += 1;
77
+ if (text[index + 2] === "/") {
78
+ source += "(?:.*/)?";
79
+ index += 2;
80
+ } else {
81
+ source += ".*";
82
+ index += 1;
83
+ }
70
84
  } else {
71
85
  source += "[^/]*";
72
86
  }
@@ -107,6 +121,11 @@ function bundleAllowsPath(bundle, relativePath) {
107
121
  return true;
108
122
  }
109
123
 
124
+ function bundleExcludesPath(bundle, relativePath) {
125
+ const exclude = Array.isArray(bundle && bundle.exclude) ? bundle.exclude : [];
126
+ return exclude.some((pattern) => matchesPattern(relativePath, pattern));
127
+ }
128
+
110
129
  function walkMarkdown(root) {
111
130
  const out = [];
112
131
  if (!fs.existsSync(root)) {
@@ -134,6 +153,39 @@ function documentAtPath(documentsByPath, pathUri) {
134
153
  return document && document.pathUri === pathUri ? document : null;
135
154
  }
136
155
 
156
+ function registerPortableConceptId(map, ambiguous, key, document) {
157
+ const normalized = normalizeSlashes(String(key || "")).replace(/^\/+/, "").split("#")[0];
158
+ if (!normalized || ambiguous.has(normalized)) {
159
+ return;
160
+ }
161
+ const owner = map.get(normalized);
162
+ if (owner && owner !== document) {
163
+ map.delete(normalized);
164
+ ambiguous.add(normalized);
165
+ return;
166
+ }
167
+ map.set(normalized, document);
168
+ }
169
+
170
+ function resolveConcept(index, locator) {
171
+ const raw = String(locator || "").trim();
172
+ if (!raw || !index) {
173
+ return null;
174
+ }
175
+ const byUri = index.byUri && index.byUri.get(raw);
176
+ if (byUri) {
177
+ return byUri;
178
+ }
179
+ const normalized = normalizeSlashes(raw).replace(/^\/+/, "").split("#")[0];
180
+ if (!normalized || !index.byConceptId) {
181
+ return null;
182
+ }
183
+ return index.byConceptId.get(normalized)
184
+ || index.byConceptId.get(normalized.replace(/\.md$/i, ""))
185
+ || index.byConceptId.get(`${normalized}.md`)
186
+ || null;
187
+ }
188
+
137
189
  function resolveIndexedLink(bundleId, resolved, href, documentsByPath) {
138
190
  if (!documentsByPath || typeof documentsByPath.get !== "function") {
139
191
  return resolved;
@@ -218,10 +270,59 @@ function relationFrom(value, doc) {
218
270
  return { type: "related_to", target: "", source: doc.uri };
219
271
  }
220
272
 
273
+ function assetUri(bundle, relativePath) {
274
+ return `okf-asset://${bundle}/${normalizeSlashes(relativePath).split("/").map(encodeURIComponent).join("/")}`;
275
+ }
276
+
277
+ function relativeReferencePath(fromPath, reference) {
278
+ const raw = normalizeSlashes(String(reference || "").trim()).split("#")[0];
279
+ if (!raw || isExternalReference(raw)) {
280
+ return null;
281
+ }
282
+ const relative = raw.startsWith("/")
283
+ ? path.posix.normalize(raw.slice(1))
284
+ : path.posix.normalize(path.posix.join(path.posix.dirname(fromPath), raw));
285
+ if (!relative || relative === "." || relative === ".." || relative.startsWith("../") || path.posix.isAbsolute(relative)) {
286
+ return null;
287
+ }
288
+ return normalizeSlashes(relative);
289
+ }
290
+
291
+ function semanticReferences(doc) {
292
+ const frontmatter = doc.frontmatter || {};
293
+ const references = [];
294
+ function add(kind, field, value, metadata) {
295
+ if (typeof value === "string" && value.trim()) {
296
+ references.push({ kind, field, value: value.trim(), metadata: metadata || null });
297
+ }
298
+ }
299
+ add("resource", "resource", frontmatter.resource);
300
+ const sources = doc.signals && Array.isArray(doc.signals.sources)
301
+ ? doc.signals.sources
302
+ : Array.isArray(frontmatter.sources)
303
+ ? frontmatter.sources
304
+ : [];
305
+ sources.forEach((source, index) => {
306
+ if (source && typeof source === "object" && !Array.isArray(source)) {
307
+ add("source", `sources[${index}].resource`, source.resource, source);
308
+ }
309
+ });
310
+ add("computation", "computation", frontmatter.computation);
311
+ if (frontmatter.executor && typeof frontmatter.executor === "object" && !Array.isArray(frontmatter.executor)) {
312
+ add("executor", "executor.resource", frontmatter.executor.resource);
313
+ }
314
+ if (frontmatter.attester && typeof frontmatter.attester === "object" && !Array.isArray(frontmatter.attester)) {
315
+ add("attester", "attester.resource", frontmatter.attester.resource);
316
+ }
317
+ return references;
318
+ }
319
+
221
320
  function buildIndex(bundleArgs, options) {
222
321
  const config = options || {};
223
- const bundles = uniqueBundleIds((bundleArgs || []).map(parseBundleArg));
322
+ const strictLinks = Boolean(config.strictLinks);
323
+ const requestedBundles = uniqueBundleIds((bundleArgs || []).map(parseBundleArg));
224
324
  const allowedRelationTypes = new Set((config.relationTypes || DEFAULT_RELATION_TYPES).map(String));
325
+ const allowCustomRelationTypes = Boolean(config.allowCustomRelationTypes);
225
326
  const documents = [];
226
327
  const concepts = [];
227
328
  const reserved = [];
@@ -229,12 +330,15 @@ function buildIndex(bundleArgs, options) {
229
330
  const errors = [];
230
331
  const externalReferences = new Map();
231
332
  const seenBundleIds = new Set();
333
+ const bundles = [];
232
334
 
233
- bundles.forEach((bundle) => {
335
+ requestedBundles.forEach((bundle) => {
234
336
  if (seenBundleIds.has(bundle.id)) {
235
- errors.push({ code: "duplicate_bundle_id", bundle: bundle.id, message: "Duplicate bundle id." });
337
+ errors.push({ code: "duplicate_bundle_id", bundle: bundle.id, message: "Duplicate bundle id; the later bundle was ignored." });
338
+ return;
236
339
  }
237
340
  seenBundleIds.add(bundle.id);
341
+ bundles.push(bundle);
238
342
  });
239
343
 
240
344
  bundles.forEach((bundle) => {
@@ -245,7 +349,13 @@ function buildIndex(bundleArgs, options) {
245
349
  return;
246
350
  }
247
351
  try {
248
- const doc = parseMarkdownText(bundle, relativePath, String(remoteDoc.text || ""), remoteDoc.source || relativePath);
352
+ const doc = parseMarkdownText(
353
+ bundle,
354
+ relativePath,
355
+ String(remoteDoc.text || ""),
356
+ remoteDoc.source || relativePath,
357
+ { asOf: config.asOf },
358
+ );
249
359
  documents.push(doc);
250
360
  if (doc.reserved) {
251
361
  reserved.push(doc);
@@ -274,7 +384,7 @@ function buildIndex(bundleArgs, options) {
274
384
  return;
275
385
  }
276
386
  try {
277
- const doc = parseMarkdownFile(bundle, filePath);
387
+ const doc = parseMarkdownFile(bundle, filePath, { asOf: config.asOf });
278
388
  documents.push(doc);
279
389
  if (doc.reserved) {
280
390
  reserved.push(doc);
@@ -295,21 +405,91 @@ function buildIndex(bundleArgs, options) {
295
405
 
296
406
  const byUri = new Map();
297
407
  const byPathUri = new Map();
408
+ const byCanonicalUri = new Map();
409
+ const byConceptId = new Map();
410
+ const ambiguousConceptIds = new Set();
411
+ const ambiguousAliases = new Set();
298
412
  documents.forEach((doc) => {
299
413
  if (!byPathUri.has(doc.pathUri)) {
300
414
  byPathUri.set(doc.pathUri, doc);
301
415
  }
302
- if (byUri.has(doc.uri)) {
303
- errors.push({ code: "duplicate_uri", uri: doc.uri, message: "Duplicate OKF URI." });
416
+ if (byCanonicalUri.has(doc.uri)) {
417
+ errors.push({ code: "duplicate_concept_id", uri: doc.uri, message: "Duplicate canonical OKF Concept ID." });
418
+ return;
304
419
  }
420
+ byCanonicalUri.set(doc.uri, doc);
305
421
  byUri.set(doc.uri, doc);
306
- if (doc.pathUri !== doc.uri) {
307
- if (byUri.has(doc.pathUri)) {
308
- errors.push({ code: "duplicate_uri", uri: doc.pathUri, message: "Duplicate OKF path URI." });
309
- } else {
310
- byUri.set(doc.pathUri, doc);
422
+ registerPortableConceptId(byConceptId, ambiguousConceptIds, doc.conceptId, doc);
423
+ registerPortableConceptId(byConceptId, ambiguousConceptIds, doc.path, doc);
424
+ });
425
+
426
+ const localDocuments = documents.filter((doc) => {
427
+ const bundle = bundles.find((entry) => entry.id === doc.bundle);
428
+ return bundle && !bundle.remote;
429
+ });
430
+ const localAssetRegistry = buildAssetRegistry(localDocuments, bundles, {
431
+ maxAssetBytes: config.maxAssetBytes,
432
+ allowResolvedPath: (bundle, relativePath) => !bundleExcludesPath(bundle, relativePath),
433
+ skipResolvedPath: (_bundle, relativePath) => relativePath.toLowerCase().endsWith(".md"),
434
+ });
435
+ warnings.push.apply(warnings, localAssetRegistry.diagnostics);
436
+ const assets = localAssetRegistry.assets.filter((asset) => (
437
+ !documentAtPath(byPathUri, `okf://${asset.bundle}/${asset.path}`)
438
+ ));
439
+ bundles.filter((bundle) => bundle.remote).forEach((bundle) => {
440
+ const unresolved = bundle.remoteSource && bundle.remoteSource.unresolvedReferences || [];
441
+ warnings.push.apply(warnings, unresolved.map((entry) => Object.assign({
442
+ severity: "warning",
443
+ layer: "project",
444
+ bundle: bundle.id,
445
+ message: `Referenced remote asset is unavailable: ${entry.resolvedPath || entry.target || "<unknown>"}`,
446
+ }, entry)));
447
+ (bundle.assets || []).forEach((asset) => {
448
+ assets.push(Object.assign({}, asset, {
449
+ bundle: bundle.id,
450
+ uri: asset.uri || assetUri(bundle.id, asset.path),
451
+ remote: true,
452
+ }));
453
+ });
454
+ });
455
+
456
+ assets.forEach((asset) => {
457
+ asset.uri = asset.uri || assetUri(asset.bundle, asset.path);
458
+ });
459
+ const byAssetKey = new Map(assets.map((asset) => [`${asset.bundle}\u0000${asset.path}`, asset]));
460
+ const byAssetUri = new Map(assets.map((asset) => [asset.uri, asset]));
461
+ const aliasOwners = new Map();
462
+ documents.forEach((doc) => {
463
+ (doc.uriAliases || [doc.pathUri]).forEach((alias) => {
464
+ const canonicalOwner = byCanonicalUri.get(alias);
465
+ if (canonicalOwner && canonicalOwner !== doc) {
466
+ errors.push({
467
+ code: "uri_alias_conflicts_canonical",
468
+ uri: alias,
469
+ bundle: doc.bundle,
470
+ path: doc.path,
471
+ message: "Compatibility URI alias conflicts with another canonical Concept ID; the canonical target wins.",
472
+ });
473
+ return;
311
474
  }
312
- }
475
+ const aliasOwner = aliasOwners.get(alias);
476
+ if (aliasOwner && aliasOwner !== doc) {
477
+ ambiguousAliases.add(alias);
478
+ byUri.delete(alias);
479
+ errors.push({
480
+ code: "ambiguous_uri_alias",
481
+ uri: alias,
482
+ bundle: doc.bundle,
483
+ path: doc.path,
484
+ message: "Compatibility URI alias resolves to more than one document.",
485
+ });
486
+ return;
487
+ }
488
+ if (!ambiguousAliases.has(alias)) {
489
+ aliasOwners.set(alias, doc);
490
+ byUri.set(alias, doc);
491
+ }
492
+ });
313
493
  });
314
494
 
315
495
  const edges = [];
@@ -358,17 +538,40 @@ function buildIndex(bundleArgs, options) {
358
538
  errors.push({ code: "missing_relation_target", bundle: doc.bundle, path: doc.path, relationType: type, message: "Relation has no target." });
359
539
  return;
360
540
  }
361
- if (!allowedRelationTypes.has(type)) {
541
+ const safeCustomType = /^[A-Za-z0-9_.-]+$/.test(type);
542
+ if (!allowedRelationTypes.has(type) && !(allowCustomRelationTypes && safeCustomType)) {
362
543
  errors.push({ code: "invalid_relation_type", bundle: doc.bundle, path: doc.path, relationType: type, message: `Unsupported relation type: ${type}` });
544
+ } else if (allowCustomRelationTypes && safeCustomType) {
545
+ allowedRelationTypes.add(type);
546
+ }
547
+ let targetDocument = byUri.get(targetUri) || null;
548
+ let internalTarget = targetUri.startsWith("okf://");
549
+ if (!targetDocument && !/^[A-Za-z][A-Za-z0-9+.-]*:/u.test(targetUri)) {
550
+ internalTarget = true;
551
+ const resolved = resolveLinkPath(bundle, doc.path, targetUri, byPathUri);
552
+ if (resolved && !resolved.outsideRoot) {
553
+ targetDocument = documentAtPath(byPathUri, `okf://${doc.bundle}/${resolved.path}`);
554
+ if (!targetDocument && !path.posix.extname(resolved.path)) {
555
+ targetDocument = documentAtPath(byPathUri, `okf://${doc.bundle}/${resolved.path}.md`);
556
+ }
557
+ }
558
+ if (!targetDocument) {
559
+ const normalizedTarget = normalizeSlashes(targetUri).replace(/^\/+/, "").replace(/\.md$/i, "");
560
+ const portableTarget = byConceptId.get(normalizedTarget);
561
+ if (portableTarget && portableTarget.bundle === doc.bundle) {
562
+ targetDocument = portableTarget;
563
+ }
564
+ }
363
565
  }
364
- const target = byUri.get(targetUri);
365
- const isOkfTarget = targetUri.startsWith("okf://");
366
- const isExternal = !isOkfTarget;
566
+ const target = targetDocument && !targetDocument.reserved && targetDocument.valid
567
+ ? targetDocument
568
+ : null;
569
+ const isExternal = !internalTarget;
367
570
  if (isExternal) {
368
571
  externalReferences.set(targetUri, { uri: targetUri, kind: "external" });
369
572
  }
370
- if (isOkfTarget && !target) {
371
- errors.push({ code: "broken_relation", bundle: doc.bundle, path: doc.path, target: targetUri, relationType: type, message: "Relation target does not exist." });
573
+ if (internalTarget && !target) {
574
+ errors.push({ code: "broken_relation", bundle: doc.bundle, path: doc.path, target: targetUri, relationType: type, message: "Relation target does not resolve to a valid concept." });
372
575
  }
373
576
  edges.push({
374
577
  source: doc.uri,
@@ -377,10 +580,133 @@ function buildIndex(bundleArgs, options) {
377
580
  relationType: type,
378
581
  text: relation.label || type,
379
582
  description: relation.description || "",
380
- broken: isOkfTarget && !target,
583
+ broken: internalTarget && !target,
381
584
  external: isExternal,
382
585
  });
383
586
  });
587
+ semanticReferences(doc).forEach((reference) => {
588
+ const rawTarget = reference.value;
589
+ let target = null;
590
+ let external = false;
591
+ let broken = false;
592
+ let resolvedAs = "opaque";
593
+ if (rawTarget.startsWith("okf://")) {
594
+ const targetDoc = byUri.get(rawTarget);
595
+ target = targetDoc ? targetDoc.uri : rawTarget;
596
+ const validTarget = Boolean(targetDoc && !targetDoc.reserved && targetDoc.valid);
597
+ broken = !validTarget;
598
+ resolvedAs = validTarget ? "concept" : targetDoc ? "invalid_concept" : "unresolved";
599
+ if (!validTarget) {
600
+ warnings.push({
601
+ code: "broken_semantic_reference",
602
+ severity: "warning",
603
+ layer: "project",
604
+ bundle: doc.bundle,
605
+ path: doc.path,
606
+ field: reference.field,
607
+ target: rawTarget,
608
+ edgeKind: reference.kind,
609
+ message: targetDoc
610
+ ? "Standard OKF semantic reference targets an invalid or reserved document."
611
+ : "Standard OKF semantic reference targets an unknown internal concept.",
612
+ });
613
+ }
614
+ } else if (isExternalReference(rawTarget)) {
615
+ target = rawTarget;
616
+ external = true;
617
+ resolvedAs = "external";
618
+ } else {
619
+ const targetPath = relativeReferencePath(doc.path, rawTarget);
620
+ const targetDoc = targetPath
621
+ ? documentAtPath(byPathUri, `okf://${doc.bundle}/${targetPath}`)
622
+ || byUri.get(`okf://${doc.bundle}/${targetPath.replace(/\.md$/i, "")}`)
623
+ : null;
624
+ const targetAsset = targetPath ? byAssetKey.get(`${doc.bundle}\u0000${targetPath}`) : null;
625
+ if (targetDoc && !targetDoc.reserved && targetDoc.valid) {
626
+ target = targetDoc.uri;
627
+ resolvedAs = "concept";
628
+ } else if (targetDoc) {
629
+ target = targetDoc.uri;
630
+ broken = true;
631
+ resolvedAs = "invalid_concept";
632
+ } else if (targetAsset) {
633
+ target = targetAsset.uri;
634
+ resolvedAs = "asset";
635
+ } else {
636
+ target = rawTarget;
637
+ const opaqueSource = reference.kind === "source" && !isLocalAssetReference(rawTarget, { allowBare: false });
638
+ external = opaqueSource;
639
+ broken = !opaqueSource;
640
+ resolvedAs = opaqueSource ? "opaque" : "unresolved";
641
+ }
642
+ }
643
+ if (broken && !rawTarget.startsWith("okf://")) {
644
+ warnings.push({
645
+ code: "broken_semantic_reference",
646
+ severity: "warning",
647
+ layer: "project",
648
+ bundle: doc.bundle,
649
+ path: doc.path,
650
+ field: reference.field,
651
+ target: rawTarget,
652
+ edgeKind: reference.kind,
653
+ message: "Standard OKF semantic reference does not resolve to a valid local concept or indexed asset.",
654
+ });
655
+ }
656
+ if (external) {
657
+ externalReferences.set(target, { uri: target, kind: "external" });
658
+ }
659
+ edges.push({
660
+ source: doc.uri,
661
+ target,
662
+ kind: reference.kind,
663
+ field: reference.field,
664
+ reference: rawTarget,
665
+ sourceEntry: reference.kind === "source" ? reference.metadata : undefined,
666
+ resolvedAs,
667
+ broken,
668
+ external,
669
+ });
670
+ });
671
+ });
672
+
673
+ concepts.forEach((doc) => {
674
+ const contract = doc.signals && doc.signals.computation;
675
+ if (!contract) {
676
+ return;
677
+ }
678
+ const contractEdges = edges.filter((edge) => (
679
+ edge.source === doc.uri
680
+ && ["computation", "executor", "attester"].includes(edge.kind)
681
+ ));
682
+ const requiredKinds = contract.computation && contract.computation.mode === "file"
683
+ ? ["computation", "executor", "attester"]
684
+ : ["executor", "attester"];
685
+ const assetsReady = requiredKinds.every((kind) => {
686
+ const edge = contractEdges.find((entry) => entry.kind === kind);
687
+ if (!edge || edge.broken) {
688
+ return false;
689
+ }
690
+ if (kind === "computation") {
691
+ if (edge.resolvedAs !== "asset") {
692
+ return false;
693
+ }
694
+ const asset = byAssetUri.get(edge.target);
695
+ return Boolean(asset && (!mimeIsText(asset.mimeType) || asset.kind === "text"));
696
+ }
697
+ if (edge.resolvedAs === "concept") {
698
+ return true;
699
+ }
700
+ if (edge.resolvedAs !== "asset") {
701
+ return false;
702
+ }
703
+ const asset = byAssetUri.get(edge.target);
704
+ return Boolean(asset && (!mimeIsText(asset.mimeType) || asset.kind === "text"));
705
+ });
706
+ contract.structuralReady = Boolean(contract.ready);
707
+ contract.assetsReady = assetsReady;
708
+ contract.ready = Boolean(contract.structuralReady && assetsReady);
709
+ contract.attestationReady = contract.ready;
384
710
  });
385
711
 
386
712
  const index = {
@@ -390,18 +716,47 @@ function buildIndex(bundleArgs, options) {
390
716
  reserved,
391
717
  relationTypes: Array.from(allowedRelationTypes),
392
718
  externalReferences: Array.from(externalReferences.values()),
719
+ assets,
393
720
  warnings,
394
721
  errors,
395
722
  edges,
723
+ strictLinks,
396
724
  byUri,
397
725
  byPathUri,
726
+ byCanonicalUri,
727
+ byConceptId,
728
+ byAssetKey,
729
+ byAssetUri,
730
+ ambiguousAliases,
731
+ ambiguousConceptIds,
398
732
  };
733
+ bundles.forEach((bundle) => {
734
+ const rootIndex = documents.find((doc) => doc.bundle === bundle.id && doc.path === "index.md");
735
+ const okfVersion = rootIndex
736
+ && rootIndex.frontmatter
737
+ && Object.prototype.hasOwnProperty.call(rootIndex.frontmatter, "okf_version")
738
+ ? rootIndex.frontmatter.okf_version
739
+ : null;
740
+ bundle.okfVersion = okfVersion === null ? null : String(okfVersion);
741
+ bundle.versionStatus = bundle.okfVersion === "0.2"
742
+ ? "understood"
743
+ : bundle.okfVersion === "0.1"
744
+ ? "legacy"
745
+ : bundle.okfVersion
746
+ ? "unsupported"
747
+ : "undeclared";
748
+ bundle.documentCount = documents.filter((doc) => doc.bundle === bundle.id).length;
749
+ bundle.assetCount = assets.filter((asset) => asset.bundle === bundle.id).length;
750
+ });
399
751
  return attachValidation(index);
400
752
  }
401
753
 
402
754
  function buildProjectIndex(projectPath) {
403
755
  const project = loadProjectConfig(projectPath);
404
- const index = buildIndex(project.bundles, { relationTypes: project.relationTypes });
756
+ const index = buildIndex(project.bundles, {
757
+ relationTypes: project.relationTypes,
758
+ strictLinks: project.strictLinks,
759
+ });
405
760
  return attachProject(index, project);
406
761
  }
407
762
 
@@ -417,7 +772,12 @@ async function loadProjectBundles(projectPath, options) {
417
772
 
418
773
  async function buildProjectIndexAsync(projectPath, options) {
419
774
  const loaded = await loadProjectBundles(projectPath, options);
420
- const index = buildIndex(loaded.bundles, { relationTypes: loaded.project.relationTypes });
775
+ const index = buildIndex(loaded.bundles, {
776
+ relationTypes: loaded.project.relationTypes,
777
+ strictLinks: options && options.strictLinks !== undefined
778
+ ? options.strictLinks
779
+ : loaded.project.strictLinks,
780
+ });
421
781
  return attachProject(index, loaded.project);
422
782
  }
423
783
 
@@ -432,7 +792,9 @@ function attachProject(index, project) {
432
792
  root: project.root,
433
793
  plugins: project.plugins,
434
794
  remoteBundles: project.remoteBundles,
795
+ strictLinks: project.strictLinks,
435
796
  };
797
+ index.strictLinks = Boolean(index.strictLinks || project.strictLinks);
436
798
  return attachValidation(index);
437
799
  }
438
800
 
@@ -445,17 +807,55 @@ function attachValidation(index) {
445
807
  return index;
446
808
  }
447
809
 
810
+ function conceptSignals(doc, detailed) {
811
+ const signals = doc.signals || {};
812
+ const computation = signals.computation;
813
+ const output = {
814
+ status: signals.status,
815
+ staleAfter: signals.staleAfter,
816
+ freshness: signals.freshness,
817
+ asOf: signals.asOf,
818
+ trustTier: signals.trustTier,
819
+ sourceCount: Array.isArray(signals.sources) ? signals.sources.length : 0,
820
+ hasSources: Array.isArray(signals.sources) && signals.sources.length > 0,
821
+ sourcesOrigin: signals.sourcesOrigin,
822
+ generated: signals.generated,
823
+ generatedOrigin: signals.generatedOrigin,
824
+ computation: computation ? {
825
+ runtime: computation.runtime,
826
+ mode: computation.computation && computation.computation.mode,
827
+ attestationReady: Boolean(computation.attestationReady),
828
+ structuralReady: Boolean(computation.structuralReady),
829
+ assetsReady: Boolean(computation.assetsReady),
830
+ } : null,
831
+ };
832
+ if (detailed) {
833
+ output.resource = signals.resource;
834
+ output.sources = signals.sources || [];
835
+ output.usageWindow = signals.usageWindow;
836
+ output.verifiedEvents = signals.verifiedEvents || [];
837
+ output.diagnostics = signals.diagnostics || [];
838
+ if (computation) {
839
+ output.computation = Object.assign({}, computation);
840
+ }
841
+ }
842
+ return output;
843
+ }
844
+
448
845
  function conceptSummary(doc) {
449
846
  return {
450
847
  uri: doc.uri,
451
848
  bundle: doc.bundle,
452
849
  path: doc.path,
453
850
  pathUri: doc.pathUri,
851
+ conceptId: doc.conceptId,
852
+ uriAliases: doc.uriAliases || [],
454
853
  type: doc.type,
455
854
  title: doc.title,
456
855
  description: doc.description,
457
856
  tags: doc.tags,
458
857
  aliases: doc.aliases,
858
+ signals: conceptSignals(doc, false),
459
859
  };
460
860
  }
461
861
 
@@ -465,10 +865,14 @@ module.exports = {
465
865
  buildProjectIndexAsync,
466
866
  attachProject,
467
867
  conceptSummary,
868
+ conceptSignals,
468
869
  bundleAllowsPath,
870
+ bundleExcludesPath,
469
871
  loadProjectBundles,
470
872
  parseBundleArg,
471
873
  resolveLinkPath,
874
+ resolveConcept,
875
+ semanticReferences,
472
876
  sanitizeBundleId,
473
877
  validateIndex,
474
878
  };