@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
@@ -22,16 +22,19 @@ function stableJson(value) {
22
22
  return `[${value.map(stableJson).join(",")}]`;
23
23
  }
24
24
  if (value && typeof value === "object") {
25
- return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
25
+ return `{${Object.keys(value)
26
+ .sort()
27
+ .map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`)
28
+ .join(",")}}`;
26
29
  }
27
30
  return JSON.stringify(value);
28
31
  }
29
32
 
30
33
  function contractEdges(index, doc) {
31
- return index.edges.filter((edge) => (
32
- edge.source === doc.uri
33
- && ["computation", "executor", "attester"].includes(edge.kind)
34
- ));
34
+ return index.edges.filter(
35
+ (edge) =>
36
+ edge.source === doc.uri && ["computation", "executor", "attester"].includes(edge.kind),
37
+ );
35
38
  }
36
39
 
37
40
  function targetMetadata(index, edge) {
@@ -117,11 +120,14 @@ function inspectAttestedComputation(index, uri, options) {
117
120
  ...(config.includeComputation && bytes <= maxContentBytes ? { content } : {}),
118
121
  };
119
122
  } else {
120
- computation = Object.assign({
121
- mode: contract.computation && contract.computation.mode || "missing",
122
- resource: contract.computation && contract.computation.path || null,
123
- contentIncluded: false,
124
- }, targetMetadata(index, computationEdge));
123
+ computation = Object.assign(
124
+ {
125
+ mode: (contract.computation && contract.computation.mode) || "missing",
126
+ resource: (contract.computation && contract.computation.path) || null,
127
+ contentIncluded: false,
128
+ },
129
+ targetMetadata(index, computationEdge),
130
+ );
125
131
  if (config.includeComputation && computation.resolvedAs === "asset") {
126
132
  const asset = index.byAssetUri.get(computation.uri);
127
133
  const maxContentBytes = Number(config.maxContentBytes || 65536);
@@ -131,18 +137,25 @@ function inspectAttestedComputation(index, uri, options) {
131
137
  }
132
138
  }
133
139
  }
134
- const executor = Object.assign({
135
- resource: contract.executor && contract.executor.resource || null,
136
- receiptFields: contract.executor && contract.executor.receipt || [],
137
- }, targetMetadata(index, executorEdge));
138
- const attester = Object.assign({
139
- resource: contract.attester && contract.attester.resource || null,
140
- }, targetMetadata(index, attesterEdge));
141
- const assetDiagnostics = (index.warnings || []).filter((entry) => (
142
- entry.bundle === doc.bundle
143
- && entry.path === doc.path
144
- && String(entry.code || "").startsWith("asset_")
145
- ));
140
+ const executor = Object.assign(
141
+ {
142
+ resource: (contract.executor && contract.executor.resource) || null,
143
+ receiptFields: (contract.executor && contract.executor.receipt) || [],
144
+ },
145
+ targetMetadata(index, executorEdge),
146
+ );
147
+ const attester = Object.assign(
148
+ {
149
+ resource: (contract.attester && contract.attester.resource) || null,
150
+ },
151
+ targetMetadata(index, attesterEdge),
152
+ );
153
+ const assetDiagnostics = (index.warnings || []).filter(
154
+ (entry) =>
155
+ entry.bundle === doc.bundle &&
156
+ entry.path === doc.path &&
157
+ String(entry.code || "").startsWith("asset_"),
158
+ );
146
159
  return {
147
160
  uri: doc.uri,
148
161
  requestedUri: uri,
@@ -179,10 +192,16 @@ function prepareAttestedComputation(index, uri, parameters, options) {
179
192
  const declared = inspection.parameters || [];
180
193
  const declaredNames = declared.map((entry) => entry.name);
181
194
  const presentNames = Object.keys(parameters).sort();
182
- const missing = declared.filter((entry) => entry.required && !Object.prototype.hasOwnProperty.call(parameters, entry.name)).map((entry) => entry.name);
195
+ const missing = declared
196
+ .filter(
197
+ (entry) => entry.required && !Object.prototype.hasOwnProperty.call(parameters, entry.name),
198
+ )
199
+ .map((entry) => entry.name);
183
200
  const unexpected = presentNames.filter((name) => !declaredNames.includes(name));
184
201
  if (missing.length || unexpected.length) {
185
- throw new Error(`Parameter contract mismatch (missing: ${missing.join(", ") || "none"}; unexpected: ${unexpected.join(", ") || "none"}).`);
202
+ throw new Error(
203
+ `Parameter contract mismatch (missing: ${missing.join(", ") || "none"}; unexpected: ${unexpected.join(", ") || "none"}).`,
204
+ );
186
205
  }
187
206
  return {
188
207
  prepared: true,
@@ -209,7 +228,9 @@ function checkComputationReceipt(index, uri, receipt) {
209
228
  }
210
229
  const expectedFields = inspection.executor.receiptFields || [];
211
230
  const presentFields = Object.keys(receipt).sort();
212
- const missingFields = expectedFields.filter((field) => !Object.prototype.hasOwnProperty.call(receipt, field));
231
+ const missingFields = expectedFields.filter(
232
+ (field) => !Object.prototype.hasOwnProperty.call(receipt, field),
233
+ );
213
234
  const unexpectedFields = presentFields.filter((field) => !expectedFields.includes(field));
214
235
  return {
215
236
  uri: inspection.uri,
@@ -228,12 +249,17 @@ function readBundleAsset(index, input) {
228
249
  const args = input || {};
229
250
  const asset = args.uri
230
251
  ? index.byAssetUri && index.byAssetUri.get(args.uri)
231
- : index.byAssetKey && index.byAssetKey.get(`${args.bundle}\u0000${String(args.path || "").replace(/\\/g, "/")}`);
252
+ : index.byAssetKey &&
253
+ index.byAssetKey.get(`${args.bundle}\u0000${String(args.path || "").replace(/\\/g, "/")}`);
232
254
  if (!asset) {
233
255
  throw new Error("Unknown or unreferenced bundle asset.");
234
256
  }
235
257
  const maxContentBytes = Number(args.maxContentBytes || 65536);
236
- if (!Number.isSafeInteger(maxContentBytes) || maxContentBytes < 1 || maxContentBytes > 1024 * 1024) {
258
+ if (
259
+ !Number.isSafeInteger(maxContentBytes) ||
260
+ maxContentBytes < 1 ||
261
+ maxContentBytes > 1024 * 1024
262
+ ) {
237
263
  throw new Error("maxContentBytes must be between 1 and 1048576.");
238
264
  }
239
265
  if (asset.size > maxContentBytes) {
@@ -275,7 +301,10 @@ function readBundleAsset(index, input) {
275
301
  function getProvenance(index, uri, options) {
276
302
  const config = options || {};
277
303
  const root = requireConcept(index, uri);
278
- const maxDepth = Math.max(0, Math.min(Number(config.maxDepth === undefined ? 3 : config.maxDepth), 10));
304
+ const maxDepth = Math.max(
305
+ 0,
306
+ Math.min(Number(config.maxDepth === undefined ? 3 : config.maxDepth), 10),
307
+ );
279
308
  const maxNodes = Math.max(1, Math.min(Number(config.maxNodes || 100), 1000));
280
309
  const includeExternal = config.includeExternal === true;
281
310
  const nodes = [];
@@ -307,42 +336,51 @@ function getProvenance(index, uri, options) {
307
336
  if (current.depth >= maxDepth) {
308
337
  continue;
309
338
  }
310
- index.edges.filter((edge) => edge.source === doc.uri && edge.kind === "source").forEach((edge) => {
311
- const targetDoc = index.byUri.get(edge.target);
312
- const targetAsset = index.byAssetUri && index.byAssetUri.get(edge.target);
313
- if (targetDoc) {
314
- edges.push(edge);
315
- if (current.ancestry.includes(targetDoc.uri)) {
316
- cycles.push(current.ancestry.concat(targetDoc.uri));
317
- } else {
318
- queue.push({ uri: targetDoc.uri, depth: current.depth + 1, ancestry: current.ancestry.concat(targetDoc.uri) });
319
- }
320
- } else if (targetAsset) {
321
- edges.push(edge);
322
- if (!seen.has(targetAsset.uri) && nodes.length < maxNodes) {
323
- seen.add(targetAsset.uri);
324
- nodes.push({
325
- id: targetAsset.uri,
326
- kind: "asset",
327
- bundle: targetAsset.bundle,
328
- path: targetAsset.path,
329
- mimeType: targetAsset.mimeType,
330
- size: targetAsset.size,
331
- sha256: targetAsset.sha256,
332
- });
333
- }
334
- } else if (edge.external || edge.resolvedAs === "opaque") {
335
- if (includeExternal) {
339
+ index.edges
340
+ .filter((edge) => edge.source === doc.uri && edge.kind === "source")
341
+ .forEach((edge) => {
342
+ const targetDoc = index.byUri.get(edge.target);
343
+ const targetAsset = index.byAssetUri && index.byAssetUri.get(edge.target);
344
+ if (targetDoc) {
336
345
  edges.push(edge);
337
- if (!seen.has(edge.target) && nodes.length < maxNodes) {
338
- seen.add(edge.target);
339
- nodes.push({ id: edge.target, kind: edge.resolvedAs === "opaque" ? "opaque" : "external" });
346
+ if (current.ancestry.includes(targetDoc.uri)) {
347
+ cycles.push(current.ancestry.concat(targetDoc.uri));
348
+ } else {
349
+ queue.push({
350
+ uri: targetDoc.uri,
351
+ depth: current.depth + 1,
352
+ ancestry: current.ancestry.concat(targetDoc.uri),
353
+ });
340
354
  }
355
+ } else if (targetAsset) {
356
+ edges.push(edge);
357
+ if (!seen.has(targetAsset.uri) && nodes.length < maxNodes) {
358
+ seen.add(targetAsset.uri);
359
+ nodes.push({
360
+ id: targetAsset.uri,
361
+ kind: "asset",
362
+ bundle: targetAsset.bundle,
363
+ path: targetAsset.path,
364
+ mimeType: targetAsset.mimeType,
365
+ size: targetAsset.size,
366
+ sha256: targetAsset.sha256,
367
+ });
368
+ }
369
+ } else if (edge.external || edge.resolvedAs === "opaque") {
370
+ if (includeExternal) {
371
+ edges.push(edge);
372
+ if (!seen.has(edge.target) && nodes.length < maxNodes) {
373
+ seen.add(edge.target);
374
+ nodes.push({
375
+ id: edge.target,
376
+ kind: edge.resolvedAs === "opaque" ? "opaque" : "external",
377
+ });
378
+ }
379
+ }
380
+ } else {
381
+ unresolved.push({ source: edge.source, resource: edge.reference, field: edge.field });
341
382
  }
342
- } else {
343
- unresolved.push({ source: edge.source, resource: edge.reference, field: edge.field });
344
- }
345
- });
383
+ });
346
384
  }
347
385
  return {
348
386
  root: root.uri,