@mfdaves/okf-mcp 0.9.0 → 0.12.0-rc.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 (97) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +176 -19
  3. package/bin/okf-mcp.js +6 -1
  4. package/okf/okf-mcp/policies/authoring-safety.md +11 -1
  5. package/package.json +17 -5
  6. package/server.json +2 -2
  7. package/src/assets.js +165 -73
  8. package/src/authoring/candidates.js +391 -0
  9. package/src/authoring/git-preflight.js +225 -0
  10. package/src/authoring/git-publish.js +776 -0
  11. package/src/authoring/live.js +789 -0
  12. package/src/authoring/paths.js +112 -0
  13. package/src/authoring/policy-hook.js +221 -0
  14. package/src/authoring/proposal-policy.js +137 -0
  15. package/src/authoring/receipts.js +329 -0
  16. package/src/authoring/render.js +38 -0
  17. package/src/authoring/shared.js +75 -0
  18. package/src/authoring/staging.js +216 -0
  19. package/src/authoring.js +386 -287
  20. package/src/cache/files.js +147 -0
  21. package/src/cache/lock.js +201 -0
  22. package/src/cache/paths.js +197 -0
  23. package/src/cache/store.js +703 -0
  24. package/src/catalog-text.js +19 -0
  25. package/src/cli.js +184 -151
  26. package/src/computation.js +99 -61
  27. package/src/context/assemble.js +567 -0
  28. package/src/context/cli-options.js +88 -0
  29. package/src/context/score.js +234 -0
  30. package/src/context/sections.js +274 -0
  31. package/src/embed/interface.js +160 -0
  32. package/src/embed/openai.js +715 -0
  33. package/src/embed/prepare.js +182 -0
  34. package/src/embed/units.js +96 -0
  35. package/src/git-source.js +112 -52
  36. package/src/graph.js +95 -37
  37. package/src/http-server.js +36 -17
  38. package/src/index.js +15 -0
  39. package/src/indexer/assemble.js +566 -0
  40. package/src/indexer/build.js +290 -0
  41. package/src/indexer/cache.js +81 -0
  42. package/src/indexer/edges.js +430 -0
  43. package/src/indexer/index.js +44 -0
  44. package/src/indexer/paths.js +178 -0
  45. package/src/indexer/resolve.js +282 -0
  46. package/src/indexer/update.js +720 -0
  47. package/src/indexer.js +3 -1068
  48. package/src/live-authoring.js +4 -2329
  49. package/src/markdown.js +21 -16
  50. package/src/mcp/registry.js +328 -0
  51. package/src/mcp/resources.js +45 -0
  52. package/src/mcp/server.js +472 -0
  53. package/src/mcp/tools/catalog.js +244 -0
  54. package/src/mcp/tools/computation.js +83 -0
  55. package/src/mcp/tools/context.js +133 -0
  56. package/src/mcp/tools/graph.js +167 -0
  57. package/src/mcp/tools/live-authoring.js +316 -0
  58. package/src/mcp/tools/migration.js +86 -0
  59. package/src/mcp/tools/producers.js +79 -0
  60. package/src/mcp/tools/proposals.js +213 -0
  61. package/src/mcp/tools/provenance.js +87 -0
  62. package/src/mcp/tools/remote.js +79 -0
  63. package/src/mcp/tools/search.js +242 -0
  64. package/src/mcp-server.js +3 -1611
  65. package/src/migration.js +431 -253
  66. package/src/parser.js +245 -130
  67. package/src/plugins.js +71 -48
  68. package/src/policy/write-policy.js +713 -0
  69. package/src/producer-publisher.js +195 -77
  70. package/src/producers.js +265 -101
  71. package/src/project.js +277 -93
  72. package/src/remote.js +96 -61
  73. package/src/search/cli-options.js +107 -0
  74. package/src/search/confidence.js +61 -0
  75. package/src/search/dense.js +304 -0
  76. package/src/search/embedding-cli.js +57 -0
  77. package/src/search/embedding-config.js +217 -0
  78. package/src/search/fusion.js +249 -0
  79. package/src/search/hybrid.js +526 -0
  80. package/src/search/languages.js +200 -0
  81. package/src/search/lexical.js +695 -0
  82. package/src/search/query.js +620 -0
  83. package/src/search/stem/among.js +43 -0
  84. package/src/search/stem/base-stemmer.js +311 -0
  85. package/src/search/stem/en-regions.js +456 -0
  86. package/src/search/stem/en-suffixes.js +664 -0
  87. package/src/search/stem/en-tables.js +176 -0
  88. package/src/search/stem/en.js +238 -0
  89. package/src/search/stem/it-regions.js +459 -0
  90. package/src/search/stem/it-suffixes.js +471 -0
  91. package/src/search/stem/it-tables.js +257 -0
  92. package/src/search/stem/it.js +155 -0
  93. package/src/search-index.js +2 -81
  94. package/src/search.js +2 -252
  95. package/src/store.js +134 -81
  96. package/src/v02.js +301 -105
  97. package/src/validation.js +24 -20
package/src/parser.js CHANGED
@@ -21,11 +21,73 @@ function validOkfConceptUri(value) {
21
21
  }
22
22
  const match = value.match(/^okf:\/\/([^/\s?#]+)\/([^\s?#]+)$/);
23
23
  return Boolean(
24
- match
25
- && match[2].split("/").every((segment) => segment && segment !== "." && segment !== ".."),
24
+ match && match[2].split("/").every((segment) => segment && segment !== "." && segment !== ".."),
26
25
  );
27
26
  }
28
27
 
28
+ // js-yaml's message ends with a code frame of the offending source lines,
29
+ // and several reasons quote anchors, aliases, tags or handles taken from
30
+ // them. Frontmatter is catalog text, which never reaches an error message
31
+ // (B-6, S-3), so the message carries a constant category chosen by matching
32
+ // the reason's leading words against this table, plus the position. Only
33
+ // the table's own strings are ever emitted.
34
+ const YAML_ERROR_CATEGORIES = [
35
+ ["duplicated mapping key", "duplicated mapping key"],
36
+ ["bad indentation", "bad indentation"],
37
+ ["deficient indentation", "bad indentation"],
38
+ ["bad explicit indentation", "bad indentation"],
39
+ ["tab characters must not be used", "bad indentation"],
40
+ ["unidentified alias", "unidentified alias"],
41
+ ["alias node", "unidentified alias"],
42
+ ["name of an alias", "unidentified alias"],
43
+ ["name of an anchor", "invalid anchor"],
44
+ ["duplication of an anchor", "invalid anchor"],
45
+ ["unknown tag", "unknown tag"],
46
+ ["unknown scalar tag", "unknown scalar tag"],
47
+ ["unacceptable node kind", "unknown tag"],
48
+ ["undeclared tag handle", "unknown tag"],
49
+ ["tag name", "unknown tag"],
50
+ ["tag suffix", "unknown tag"],
51
+ ["named tag handle", "unknown tag"],
52
+ ["duplication of a tag", "unknown tag"],
53
+ ["unexpected end", "unexpected end"],
54
+ ["incomplete explicit mapping", "incomplete explicit mapping"],
55
+ ["end of the stream or a document separator", "unexpected content"],
56
+ ["missed comma", "flow collection"],
57
+ ["expected the node content", "flow collection"],
58
+ ["expected ':'", "mapping entry"],
59
+ ["can not read a block mapping", "mapping entry"],
60
+ ["a whitespace character is expected", "mapping entry"],
61
+ ["unknown escape sequence", "invalid escape"],
62
+ ["expected hexadecimal", "invalid escape"],
63
+ ["the stream contains non-printable", "non-printable characters"],
64
+ ["nesting exceeded", "nesting too deep"],
65
+ ["expected a document, but the input is empty", "empty document"],
66
+ ];
67
+ const MAX_YAML_REASON = 120;
68
+
69
+ function yamlFrontmatterError(error) {
70
+ const reason = typeof error?.reason === "string" ? error.reason : "";
71
+ const match = YAML_ERROR_CATEGORIES.find(([prefix]) => reason.startsWith(prefix));
72
+ const category = match ? match[1] : "malformed";
73
+ const mark = error?.mark;
74
+ const position =
75
+ mark && Number.isInteger(mark.line) && Number.isInteger(mark.column)
76
+ ? ` at ${mark.line + 1}:${mark.column + 1}`
77
+ : "";
78
+ const wrapped = new Error(`Invalid YAML frontmatter (${category})${position}`);
79
+ wrapped.code = "invalid_yaml";
80
+ wrapped.category = category;
81
+ // The raw reason may quote catalog text. It stays off the enumerable
82
+ // surface, and out of `details`, which tool errors forward to MCP
83
+ // clients: truncated, for a local debugger only.
84
+ Object.defineProperty(wrapped, "yamlReason", {
85
+ value: reason.slice(0, MAX_YAML_REASON),
86
+ enumerable: false,
87
+ });
88
+ return wrapped;
89
+ }
90
+
29
91
  function parseFrontmatterYaml(source) {
30
92
  let parsed;
31
93
  try {
@@ -34,8 +96,7 @@ function parseFrontmatterYaml(source) {
34
96
  json: false,
35
97
  });
36
98
  } catch (error) {
37
- const detail = error && error.message ? error.message : String(error);
38
- throw new Error(`Invalid YAML mapping: ${detail}`);
99
+ throw yamlFrontmatterError(error);
39
100
  }
40
101
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
41
102
  throw new Error("YAML document root must be a mapping.");
@@ -114,11 +175,13 @@ function hasLocalLink(node) {
114
175
  const walker = node.walker();
115
176
  let event;
116
177
  while ((event = walker.next())) {
117
- if (event.entering
118
- && event.node.type === "link"
119
- && event.node.destination
120
- && !isExternalMarkdownTarget(event.node.destination)
121
- && !String(event.node.destination).startsWith("#")) {
178
+ if (
179
+ event.entering &&
180
+ event.node.type === "link" &&
181
+ event.node.destination &&
182
+ !isExternalMarkdownTarget(event.node.destination) &&
183
+ !String(event.node.destination).startsWith("#")
184
+ ) {
122
185
  return true;
123
186
  }
124
187
  }
@@ -167,67 +230,80 @@ function validateReservedIndex(bundle, relativePath, split) {
167
230
  const rootIndex = normalizeSlashes(relativePath) === "index.md";
168
231
  if (split.frontmatter) {
169
232
  if (!rootIndex) {
170
- diagnostics.push(conformanceDiagnostic(
171
- bundle,
172
- relativePath,
173
- "reserved_index_frontmatter_not_allowed",
174
- "Only a bundle-root index.md may declare frontmatter.",
175
- ));
233
+ diagnostics.push(
234
+ conformanceDiagnostic(
235
+ bundle,
236
+ relativePath,
237
+ "reserved_index_frontmatter_not_allowed",
238
+ "Only a bundle-root index.md may declare frontmatter.",
239
+ ),
240
+ );
176
241
  } else {
177
242
  const keys = Object.keys(split.frontmatter);
178
243
  if (keys.some((key) => key !== "okf_version")) {
179
- diagnostics.push(conformanceDiagnostic(
180
- bundle,
181
- relativePath,
182
- "reserved_index_invalid_frontmatter",
183
- "Bundle-root index.md frontmatter may contain only okf_version.",
184
- ));
244
+ diagnostics.push(
245
+ conformanceDiagnostic(
246
+ bundle,
247
+ relativePath,
248
+ "reserved_index_invalid_frontmatter",
249
+ "Bundle-root index.md frontmatter may contain only okf_version.",
250
+ ),
251
+ );
185
252
  }
186
253
  if (
187
- !Object.prototype.hasOwnProperty.call(split.frontmatter, "okf_version")
188
- || split.frontmatter.okf_version === null
189
- || typeof split.frontmatter.okf_version === "object"
190
- || String(split.frontmatter.okf_version).trim() === ""
254
+ !Object.prototype.hasOwnProperty.call(split.frontmatter, "okf_version") ||
255
+ split.frontmatter.okf_version === null ||
256
+ typeof split.frontmatter.okf_version === "object" ||
257
+ String(split.frontmatter.okf_version).trim() === ""
191
258
  ) {
192
- diagnostics.push(conformanceDiagnostic(
193
- bundle,
194
- relativePath,
195
- "reserved_index_invalid_okf_version",
196
- "Bundle-root index.md frontmatter must declare a non-empty scalar okf_version.",
197
- ));
259
+ diagnostics.push(
260
+ conformanceDiagnostic(
261
+ bundle,
262
+ relativePath,
263
+ "reserved_index_invalid_okf_version",
264
+ "Bundle-root index.md frontmatter must declare a non-empty scalar okf_version.",
265
+ ),
266
+ );
198
267
  }
199
268
  }
200
269
  }
201
270
  const structure = markdownStructure(split.body);
202
271
  const blocks = topLevelBlocks(structure.tree);
203
272
  if (!structure.headings.length) {
204
- diagnostics.push(conformanceDiagnostic(
205
- bundle,
206
- relativePath,
207
- "reserved_index_missing_heading",
208
- "Reserved index.md must contain at least one Markdown heading.",
209
- ));
273
+ diagnostics.push(
274
+ conformanceDiagnostic(
275
+ bundle,
276
+ relativePath,
277
+ "reserved_index_missing_heading",
278
+ "Reserved index.md must contain at least one Markdown heading.",
279
+ ),
280
+ );
210
281
  }
211
282
  if (blocks.length && blocks[0].type !== "heading") {
212
- diagnostics.push(conformanceDiagnostic(
213
- bundle,
214
- relativePath,
215
- "reserved_index_heading_order",
216
- "Reserved index.md content must begin with a heading.",
217
- ));
283
+ diagnostics.push(
284
+ conformanceDiagnostic(
285
+ bundle,
286
+ relativePath,
287
+ "reserved_index_heading_order",
288
+ "Reserved index.md content must begin with a heading.",
289
+ ),
290
+ );
218
291
  }
219
- const groupedLink = blocks.some((block, index) => (
220
- block.type === "list"
221
- && blocks.slice(0, index).some((entry) => entry.type === "heading")
222
- && hasLocalLink(block)
223
- ));
292
+ const groupedLink = blocks.some(
293
+ (block, index) =>
294
+ block.type === "list" &&
295
+ blocks.slice(0, index).some((entry) => entry.type === "heading") &&
296
+ hasLocalLink(block),
297
+ );
224
298
  if (!groupedLink) {
225
- diagnostics.push(conformanceDiagnostic(
226
- bundle,
227
- relativePath,
228
- "reserved_index_missing_link",
229
- "Reserved index.md must contain at least one local Markdown link entry.",
230
- ));
299
+ diagnostics.push(
300
+ conformanceDiagnostic(
301
+ bundle,
302
+ relativePath,
303
+ "reserved_index_missing_link",
304
+ "Reserved index.md must contain at least one local Markdown link entry.",
305
+ ),
306
+ );
231
307
  }
232
308
  return diagnostics;
233
309
  }
@@ -235,98 +311,116 @@ function validateReservedIndex(bundle, relativePath, split) {
235
311
  function validateReservedLog(bundle, relativePath, split) {
236
312
  const diagnostics = [];
237
313
  if (split.frontmatter) {
238
- diagnostics.push(conformanceDiagnostic(
239
- bundle,
240
- relativePath,
241
- "reserved_log_frontmatter_not_allowed",
242
- "Reserved log.md must not declare YAML frontmatter.",
243
- ));
314
+ diagnostics.push(
315
+ conformanceDiagnostic(
316
+ bundle,
317
+ relativePath,
318
+ "reserved_log_frontmatter_not_allowed",
319
+ "Reserved log.md must not declare YAML frontmatter.",
320
+ ),
321
+ );
244
322
  }
245
323
  const structure = markdownStructure(split.body);
246
324
  const blocks = topLevelBlocks(structure.tree);
247
325
  const headings = structure.headings;
248
326
  const h1 = headings.filter((heading) => heading.level === 1);
249
327
  if (!h1.length) {
250
- diagnostics.push(conformanceDiagnostic(
251
- bundle,
252
- relativePath,
253
- "reserved_log_missing_h1",
254
- "Reserved log.md must start with an H1 title.",
255
- ));
328
+ diagnostics.push(
329
+ conformanceDiagnostic(
330
+ bundle,
331
+ relativePath,
332
+ "reserved_log_missing_h1",
333
+ "Reserved log.md must start with an H1 title.",
334
+ ),
335
+ );
256
336
  } else if (!blocks.length || blocks[0] !== h1[0].node) {
257
- diagnostics.push(conformanceDiagnostic(
258
- bundle,
259
- relativePath,
260
- "reserved_log_h1_order",
261
- "The H1 title in reserved log.md must precede its dated sections.",
262
- ));
337
+ diagnostics.push(
338
+ conformanceDiagnostic(
339
+ bundle,
340
+ relativePath,
341
+ "reserved_log_h1_order",
342
+ "The H1 title in reserved log.md must precede its dated sections.",
343
+ ),
344
+ );
263
345
  }
264
346
  if (h1.length > 1) {
265
- diagnostics.push(conformanceDiagnostic(
266
- bundle,
267
- relativePath,
268
- "reserved_log_multiple_h1",
269
- "Reserved log.md must contain exactly one H1 title.",
270
- ));
347
+ diagnostics.push(
348
+ conformanceDiagnostic(
349
+ bundle,
350
+ relativePath,
351
+ "reserved_log_multiple_h1",
352
+ "Reserved log.md must contain exactly one H1 title.",
353
+ ),
354
+ );
271
355
  }
272
356
 
273
357
  const h2 = headings.filter((heading) => heading.level === 2);
274
358
  const sections = [];
275
359
  h2.forEach((heading) => {
276
360
  if (!/^\d{4}-\d{2}-\d{2}$/.test(heading.text)) {
277
- diagnostics.push(conformanceDiagnostic(
278
- bundle,
279
- relativePath,
280
- "reserved_log_invalid_date_heading",
281
- `Log H2 heading must be a strict ISO date (YYYY-MM-DD): ${heading.text}`,
282
- ));
361
+ diagnostics.push(
362
+ conformanceDiagnostic(
363
+ bundle,
364
+ relativePath,
365
+ "reserved_log_invalid_date_heading",
366
+ `Log H2 heading must be a strict ISO date (YYYY-MM-DD): ${heading.text}`,
367
+ ),
368
+ );
283
369
  return;
284
370
  }
285
371
  if (!validIsoDate(heading.text)) {
286
- diagnostics.push(conformanceDiagnostic(
287
- bundle,
288
- relativePath,
289
- "reserved_log_invalid_date",
290
- `Log H2 heading is not a valid calendar date: ${heading.text}`,
291
- ));
372
+ diagnostics.push(
373
+ conformanceDiagnostic(
374
+ bundle,
375
+ relativePath,
376
+ "reserved_log_invalid_date",
377
+ `Log H2 heading is not a valid calendar date: ${heading.text}`,
378
+ ),
379
+ );
292
380
  return;
293
381
  }
294
382
  sections.push(heading);
295
383
  });
296
384
  if (!sections.length) {
297
- diagnostics.push(conformanceDiagnostic(
298
- bundle,
299
- relativePath,
300
- "reserved_log_missing_date_section",
301
- "Reserved log.md must contain at least one valid ISO-dated H2 section.",
302
- ));
385
+ diagnostics.push(
386
+ conformanceDiagnostic(
387
+ bundle,
388
+ relativePath,
389
+ "reserved_log_missing_date_section",
390
+ "Reserved log.md must contain at least one valid ISO-dated H2 section.",
391
+ ),
392
+ );
303
393
  }
304
394
  for (let index = 1; index < sections.length; index += 1) {
305
395
  if (sections[index - 1].text <= sections[index].text) {
306
- diagnostics.push(conformanceDiagnostic(
307
- bundle,
308
- relativePath,
309
- "reserved_log_dates_not_descending",
310
- "Log date sections must be ordered newest first without duplicate dates.",
311
- ));
396
+ diagnostics.push(
397
+ conformanceDiagnostic(
398
+ bundle,
399
+ relativePath,
400
+ "reserved_log_dates_not_descending",
401
+ "Log date sections must be ordered newest first without duplicate dates.",
402
+ ),
403
+ );
312
404
  break;
313
405
  }
314
406
  }
315
407
  sections.forEach((section) => {
316
- const nextHeading = headings.find((heading) => (
317
- heading.startLine > section.startLine && heading.level <= section.level
318
- ));
408
+ const nextHeading = headings.find(
409
+ (heading) => heading.startLine > section.startLine && heading.level <= section.level,
410
+ );
319
411
  const end = nextHeading ? nextHeading.startLine : Number.POSITIVE_INFINITY;
320
- const hasListItem = structure.items.some((item) => (
321
- item.startLine > section.startLine && item.startLine < end
322
- ));
412
+ const hasListItem = structure.items.some(
413
+ (item) => item.startLine > section.startLine && item.startLine < end,
414
+ );
323
415
  if (!hasListItem) {
324
- diagnostics.push(conformanceDiagnostic(
325
- bundle,
326
- relativePath,
327
- "reserved_log_missing_list_item",
328
- `Log date section ${section.text} must contain at least one prose list item.`,
329
- ));
416
+ diagnostics.push(
417
+ conformanceDiagnostic(
418
+ bundle,
419
+ relativePath,
420
+ "reserved_log_missing_list_item",
421
+ `Log date section ${section.text} must contain at least one prose list item.`,
422
+ ),
423
+ );
330
424
  }
331
425
  });
332
426
  return diagnostics;
@@ -349,11 +443,19 @@ function parseMarkdownText(bundle, relativePath, text, sourcePath, options) {
349
443
  const frontmatter = split.frontmatter || {};
350
444
  const warnings = [];
351
445
  if (!reserved && !split.frontmatter) {
352
- warnings.push({ code: "missing_frontmatter", path: relativePath, message: "Concept file has no YAML frontmatter." });
446
+ warnings.push({
447
+ code: "missing_frontmatter",
448
+ path: relativePath,
449
+ message: "Concept file has no YAML frontmatter.",
450
+ });
353
451
  }
354
452
  const validType = typeof frontmatter.type === "string" && frontmatter.type.trim() !== "";
355
453
  if (!reserved && !validType) {
356
- warnings.push({ code: "missing_type", path: relativePath, message: "Concept file type must be a non-empty string." });
454
+ warnings.push({
455
+ code: "missing_type",
456
+ path: relativePath,
457
+ message: "Concept file type must be a non-empty string.",
458
+ });
357
459
  }
358
460
  const hasCustomId = Object.prototype.hasOwnProperty.call(frontmatter, "id");
359
461
  const customIdValid = hasCustomId && validOkfConceptUri(frontmatter.id);
@@ -361,28 +463,41 @@ function parseMarkdownText(bundle, relativePath, text, sourcePath, options) {
361
463
  warnings.push({
362
464
  code: "invalid_id",
363
465
  path: relativePath,
364
- message: "Concept id must match okf://<bundle>/<concept-id> with non-empty safe path segments.",
466
+ message:
467
+ "Concept id must match okf://<bundle>/<concept-id> with non-empty safe path segments.",
365
468
  });
366
469
  }
367
470
  const conformanceDiagnostics = reserved
368
471
  ? validateReservedDocument(bundle, relativePath, split)
369
472
  : warnings
370
- .filter((warning) => warning.code === "missing_frontmatter" || warning.code === "missing_type")
371
- .map((warning) => conformanceDiagnostic(bundle, relativePath, warning.code, warning.message));
372
- const title = frontmatter.title || extractTitle(split.body, path.basename(relativePath).replace(/\.md$/i, ""));
473
+ .filter(
474
+ (warning) => warning.code === "missing_frontmatter" || warning.code === "missing_type",
475
+ )
476
+ .map((warning) =>
477
+ conformanceDiagnostic(bundle, relativePath, warning.code, warning.message),
478
+ );
479
+ const title =
480
+ frontmatter.title ||
481
+ extractTitle(split.body, path.basename(relativePath).replace(/\.md$/i, ""));
373
482
  const pathUri = `okf://${bundle.id}/${relativePath}`;
374
- const conceptId = reserved
375
- ? relativePath
376
- : normalizeSlashes(relativePath).replace(/\.md$/i, "");
483
+ const conceptId = reserved ? relativePath : normalizeSlashes(relativePath).replace(/\.md$/i, "");
377
484
  const uri = `okf://${bundle.id}/${conceptId}`;
378
485
  const customId = customIdValid ? frontmatter.id : null;
379
- const signals = normalizeV02Signals({ frontmatter, body: split.body }, {
380
- asOf: options && options.asOf,
381
- });
382
- const v02Diagnostics = signals.diagnostics.map((entry) => Object.assign({
383
- bundle: bundle.id,
384
- path: relativePath,
385
- }, entry));
486
+ const signals = normalizeV02Signals(
487
+ { frontmatter, body: split.body, path: relativePath },
488
+ {
489
+ asOf: options && options.asOf,
490
+ },
491
+ );
492
+ const v02Diagnostics = signals.diagnostics.map((entry) =>
493
+ Object.assign(
494
+ {
495
+ bundle: bundle.id,
496
+ path: relativePath,
497
+ },
498
+ entry,
499
+ ),
500
+ );
386
501
  warnings.push.apply(warnings, v02Diagnostics);
387
502
  return {
388
503
  bundle: bundle.id,
package/src/plugins.js CHANGED
@@ -14,7 +14,11 @@ function normalizeSlashes(value) {
14
14
  }
15
15
 
16
16
  function slug(value) {
17
- return String(value || "concept").replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || "concept";
17
+ return (
18
+ String(value || "concept")
19
+ .replace(/[^A-Za-z0-9_.-]+/g, "-")
20
+ .replace(/^-+|-+$/g, "") || "concept"
21
+ );
18
22
  }
19
23
 
20
24
  function conceptMarkdown(frontmatter, bodyLines) {
@@ -83,28 +87,31 @@ function writeGeneratedFiles(root, files) {
83
87
  function generateFilesystemConcepts(project, plugin) {
84
88
  const root = sourceRoot(project, plugin);
85
89
  const out = new Map();
86
- const extensions = Array.isArray(plugin.extensions) ? plugin.extensions.map((ext) => ext.startsWith(".") ? ext : `.${ext}`) : [".md"];
90
+ const extensions = Array.isArray(plugin.extensions)
91
+ ? plugin.extensions.map((ext) => (ext.startsWith(".") ? ext : `.${ext}`))
92
+ : [".md"];
87
93
  walkFiles(root, extensions).forEach((filePath) => {
88
94
  const relative = normalizeSlashes(path.relative(project.root, filePath));
89
95
  const title = path.basename(filePath);
90
96
  const idSlug = slug(relative.replace(/\.[^.]+$/, ""));
91
- out.set(`${idSlug}.md`, conceptMarkdown({
92
- id: `okf://${plugin.bundle || "generated"}/${idSlug}`,
93
- type: plugin.conceptType || "Repository File",
94
- title,
95
- description: `Repository file ${relative}.`,
96
- resource: `repo://${relative}`,
97
- sources: [{ resource: `repo://${relative}`, title }],
98
- generated: generatedMetadata(plugin),
99
- // Compatibility extension retained for existing generated catalogs.
100
- source: `repo://${relative}`,
101
- tags: Array.isArray(plugin.tags) ? plugin.tags : ["generated", "file"],
102
- }, [
103
- `# ${title}`,
104
- "",
105
- `Repository file: \`${relative}\``,
106
- "",
107
- ]));
97
+ out.set(
98
+ `${idSlug}.md`,
99
+ conceptMarkdown(
100
+ {
101
+ id: `okf://${plugin.bundle || "generated"}/${idSlug}`,
102
+ type: plugin.conceptType || "Repository File",
103
+ title,
104
+ description: `Repository file ${relative}.`,
105
+ resource: `repo://${relative}`,
106
+ sources: [{ resource: `repo://${relative}`, title }],
107
+ generated: generatedMetadata(plugin),
108
+ // Compatibility extension retained for existing generated catalogs.
109
+ source: `repo://${relative}`,
110
+ tags: Array.isArray(plugin.tags) ? plugin.tags : ["generated", "file"],
111
+ },
112
+ [`# ${title}`, "", `Repository file: \`${relative}\``, ""],
113
+ ),
114
+ );
108
115
  });
109
116
  return {
110
117
  output: outputRoot(project, plugin),
@@ -124,30 +131,45 @@ function generateJsonSpecConcepts(project, plugin) {
124
131
  const json = JSON.parse(raw);
125
132
  const key = pickSpecKey(json, filePath);
126
133
  const relative = normalizeSlashes(path.relative(project.root, filePath));
127
- const destination = json.destination && json.destination.table ? json.destination.table : json.table || json.tablename || "";
128
- const relations = destination && plugin.destinationBundle
129
- ? [{ type: "persists_to", target: `okf://${plugin.destinationBundle}/${slug(destination)}` }]
130
- : [];
131
- out.set(`${slug(key)}.md`, conceptMarkdown({
132
- id: `okf://${plugin.bundle || "generated"}/${slug(key)}`,
133
- type: plugin.conceptType || "JSON Spec",
134
- title: key,
135
- description: json.description || `Generated concept for JSON spec ${key}.`,
136
- resource: `repo://${relative}`,
137
- sources: [{ resource: `repo://${relative}`, title: key }],
138
- generated: generatedMetadata(plugin),
139
- // Compatibility extension retained for existing generated catalogs.
140
- source: `repo://${relative}`,
141
- tags: Array.isArray(plugin.tags) ? plugin.tags : ["generated", "spec"],
142
- relations,
143
- }, [
144
- `# ${key}`,
145
- "",
146
- json.description || `Generated concept for JSON spec \`${key}\`.`,
147
- "",
148
- `Source: \`${relative}\``,
149
- "",
150
- ]));
134
+ const destination =
135
+ json.destination && json.destination.table
136
+ ? json.destination.table
137
+ : json.table || json.tablename || "";
138
+ const relations =
139
+ destination && plugin.destinationBundle
140
+ ? [
141
+ {
142
+ type: "persists_to",
143
+ target: `okf://${plugin.destinationBundle}/${slug(destination)}`,
144
+ },
145
+ ]
146
+ : [];
147
+ out.set(
148
+ `${slug(key)}.md`,
149
+ conceptMarkdown(
150
+ {
151
+ id: `okf://${plugin.bundle || "generated"}/${slug(key)}`,
152
+ type: plugin.conceptType || "JSON Spec",
153
+ title: key,
154
+ description: json.description || `Generated concept for JSON spec ${key}.`,
155
+ resource: `repo://${relative}`,
156
+ sources: [{ resource: `repo://${relative}`, title: key }],
157
+ generated: generatedMetadata(plugin),
158
+ // Compatibility extension retained for existing generated catalogs.
159
+ source: `repo://${relative}`,
160
+ tags: Array.isArray(plugin.tags) ? plugin.tags : ["generated", "spec"],
161
+ relations,
162
+ },
163
+ [
164
+ `# ${key}`,
165
+ "",
166
+ json.description || `Generated concept for JSON spec \`${key}\`.`,
167
+ "",
168
+ `Source: \`${relative}\``,
169
+ "",
170
+ ],
171
+ ),
172
+ );
151
173
  });
152
174
  return {
153
175
  output: outputRoot(project, plugin),
@@ -162,11 +184,12 @@ function generateProject(project) {
162
184
  const results = [];
163
185
  project.plugins.forEach((plugin) => {
164
186
  const type = plugin.type || plugin.name;
165
- const generated = type === "filesystem"
166
- ? generateFilesystemConcepts(project, plugin)
167
- : type === "json-spec"
168
- ? generateJsonSpecConcepts(project, plugin)
169
- : null;
187
+ const generated =
188
+ type === "filesystem"
189
+ ? generateFilesystemConcepts(project, plugin)
190
+ : type === "json-spec"
191
+ ? generateJsonSpecConcepts(project, plugin)
192
+ : null;
170
193
  if (!generated) {
171
194
  throw new Error(`Unknown OKF generator plugin: ${type}`);
172
195
  }