@mfdaves/okf-mcp 0.5.1 → 0.7.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.
package/src/indexer.js CHANGED
@@ -47,6 +47,10 @@ function parseBundleArg(arg, index) {
47
47
  };
48
48
  }
49
49
 
50
+ function documentOverrideKey(bundleId, relativePath) {
51
+ return `${bundleId}\u0000${normalizeSlashes(relativePath)}`;
52
+ }
53
+
50
54
  function uniqueBundleIds(bundles) {
51
55
  return bundles.map((bundle) => {
52
56
  const base = sanitizeBundleId(bundle.id);
@@ -319,6 +323,9 @@ function semanticReferences(doc) {
319
323
 
320
324
  function buildIndex(bundleArgs, options) {
321
325
  const config = options || {};
326
+ const documentOverrides = config.documentOverrides instanceof Map
327
+ ? config.documentOverrides
328
+ : new Map();
322
329
  const strictLinks = Boolean(config.strictLinks);
323
330
  const requestedBundles = uniqueBundleIds((bundleArgs || []).map(parseBundleArg));
324
331
  const allowedRelationTypes = new Set((config.relationTypes || DEFAULT_RELATION_TYPES).map(String));
@@ -378,13 +385,13 @@ function buildIndex(bundleArgs, options) {
378
385
  errors.push({ code: "missing_bundle_root", bundle: bundle.id, path: bundle.root, message: "Bundle root does not exist." });
379
386
  return;
380
387
  }
381
- walkMarkdown(bundle.root).forEach((filePath) => {
382
- const relativePath = safeRelativePath(bundle.root, filePath) || normalizeSlashes(filePath);
383
- if (!bundleAllowsPath(bundle, relativePath)) {
384
- return;
385
- }
388
+ const indexedPaths = new Set();
389
+ const indexLocalDocument = (relativePath, text, source) => {
390
+ indexedPaths.add(relativePath);
386
391
  try {
387
- const doc = parseMarkdownFile(bundle, filePath, { asOf: config.asOf });
392
+ const doc = text === undefined
393
+ ? parseMarkdownFile(bundle, source, { asOf: config.asOf })
394
+ : parseMarkdownText(bundle, relativePath, text, source, { asOf: config.asOf });
388
395
  documents.push(doc);
389
396
  if (doc.reserved) {
390
397
  reserved.push(doc);
@@ -400,6 +407,33 @@ function buildIndex(bundleArgs, options) {
400
407
  message: error.message,
401
408
  });
402
409
  }
410
+ };
411
+ walkMarkdown(bundle.root).forEach((filePath) => {
412
+ const relativePath = safeRelativePath(bundle.root, filePath) || normalizeSlashes(filePath);
413
+ if (!bundleAllowsPath(bundle, relativePath)) {
414
+ return;
415
+ }
416
+ const key = documentOverrideKey(bundle.id, relativePath);
417
+ indexLocalDocument(
418
+ relativePath,
419
+ documentOverrides.has(key) ? String(documentOverrides.get(key)) : undefined,
420
+ filePath,
421
+ );
422
+ });
423
+ const prefix = `${bundle.id}\u0000`;
424
+ documentOverrides.forEach((text, key) => {
425
+ if (!String(key).startsWith(prefix)) {
426
+ return;
427
+ }
428
+ const relativePath = normalizeSlashes(String(key).slice(prefix.length));
429
+ if (indexedPaths.has(relativePath) || !bundleAllowsPath(bundle, relativePath)) {
430
+ return;
431
+ }
432
+ indexLocalDocument(
433
+ relativePath,
434
+ String(text),
435
+ path.join(bundle.root, ...relativePath.split("/")),
436
+ );
403
437
  });
404
438
  });
405
439