@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.
- package/CHANGELOG.md +69 -0
- package/README.md +176 -19
- package/bin/okf-mcp.js +6 -1
- package/okf/okf-mcp/policies/authoring-safety.md +11 -1
- package/package.json +17 -5
- package/server.json +2 -2
- package/src/assets.js +165 -73
- package/src/authoring/candidates.js +391 -0
- package/src/authoring/git-preflight.js +225 -0
- package/src/authoring/git-publish.js +776 -0
- package/src/authoring/live.js +789 -0
- package/src/authoring/paths.js +112 -0
- package/src/authoring/policy-hook.js +221 -0
- package/src/authoring/proposal-policy.js +137 -0
- package/src/authoring/receipts.js +329 -0
- package/src/authoring/render.js +38 -0
- package/src/authoring/shared.js +75 -0
- package/src/authoring/staging.js +216 -0
- package/src/authoring.js +386 -287
- package/src/cache/files.js +147 -0
- package/src/cache/lock.js +201 -0
- package/src/cache/paths.js +197 -0
- package/src/cache/store.js +703 -0
- package/src/catalog-text.js +19 -0
- package/src/cli.js +184 -151
- package/src/computation.js +99 -61
- package/src/context/assemble.js +567 -0
- package/src/context/cli-options.js +88 -0
- package/src/context/score.js +234 -0
- package/src/context/sections.js +274 -0
- package/src/embed/interface.js +160 -0
- package/src/embed/openai.js +715 -0
- package/src/embed/prepare.js +182 -0
- package/src/embed/units.js +96 -0
- package/src/git-source.js +112 -52
- package/src/graph.js +95 -37
- package/src/http-server.js +36 -17
- package/src/index.js +15 -0
- package/src/indexer/assemble.js +566 -0
- package/src/indexer/build.js +290 -0
- package/src/indexer/cache.js +81 -0
- package/src/indexer/edges.js +430 -0
- package/src/indexer/index.js +44 -0
- package/src/indexer/paths.js +178 -0
- package/src/indexer/resolve.js +282 -0
- package/src/indexer/update.js +720 -0
- package/src/indexer.js +3 -1068
- package/src/live-authoring.js +4 -2329
- package/src/markdown.js +21 -16
- package/src/mcp/registry.js +328 -0
- package/src/mcp/resources.js +45 -0
- package/src/mcp/server.js +472 -0
- package/src/mcp/tools/catalog.js +244 -0
- package/src/mcp/tools/computation.js +83 -0
- package/src/mcp/tools/context.js +133 -0
- package/src/mcp/tools/graph.js +167 -0
- package/src/mcp/tools/live-authoring.js +316 -0
- package/src/mcp/tools/migration.js +86 -0
- package/src/mcp/tools/producers.js +79 -0
- package/src/mcp/tools/proposals.js +213 -0
- package/src/mcp/tools/provenance.js +87 -0
- package/src/mcp/tools/remote.js +79 -0
- package/src/mcp/tools/search.js +242 -0
- package/src/mcp-server.js +3 -1611
- package/src/migration.js +431 -253
- package/src/parser.js +245 -130
- package/src/plugins.js +71 -48
- package/src/policy/write-policy.js +713 -0
- package/src/producer-publisher.js +195 -77
- package/src/producers.js +265 -101
- package/src/project.js +277 -93
- package/src/remote.js +96 -61
- package/src/search/cli-options.js +107 -0
- package/src/search/confidence.js +61 -0
- package/src/search/dense.js +304 -0
- package/src/search/embedding-cli.js +57 -0
- package/src/search/embedding-config.js +217 -0
- package/src/search/fusion.js +249 -0
- package/src/search/hybrid.js +526 -0
- package/src/search/languages.js +200 -0
- package/src/search/lexical.js +695 -0
- package/src/search/query.js +620 -0
- package/src/search/stem/among.js +43 -0
- package/src/search/stem/base-stemmer.js +311 -0
- package/src/search/stem/en-regions.js +456 -0
- package/src/search/stem/en-suffixes.js +664 -0
- package/src/search/stem/en-tables.js +176 -0
- package/src/search/stem/en.js +238 -0
- package/src/search/stem/it-regions.js +459 -0
- package/src/search/stem/it-suffixes.js +471 -0
- package/src/search/stem/it-tables.js +257 -0
- package/src/search/stem/it.js +155 -0
- package/src/search-index.js +2 -81
- package/src/search.js +2 -252
- package/src/store.js +134 -81
- package/src/v02.js +301 -105
- package/src/validation.js +24 -20
package/src/computation.js
CHANGED
|
@@ -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)
|
|
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(
|
|
32
|
-
edge
|
|
33
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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 &&
|
|
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 (
|
|
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(
|
|
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
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (
|
|
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 (
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
}
|
|
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,
|