@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/graph.js CHANGED
@@ -1,19 +1,28 @@
1
1
  "use strict";
2
2
 
3
3
  const { applyFilters } = require("./search");
4
- const { conceptSummary } = require("./indexer");
4
+ const { conceptSummary, resolveConcept } = require("./indexer");
5
5
 
6
6
  function nodeFor(doc) {
7
+ const summary = conceptSummary(doc);
8
+ return Object.assign({ id: doc.uri }, summary);
9
+ }
10
+
11
+ function assetNodeFor(asset) {
7
12
  return {
8
- id: doc.uri,
9
- bundle: doc.bundle,
10
- path: doc.path,
11
- pathUri: doc.pathUri,
12
- type: doc.type,
13
- title: doc.title,
14
- tags: doc.tags,
15
- aliases: doc.aliases,
16
- description: doc.description,
13
+ id: asset.uri,
14
+ bundle: asset.bundle,
15
+ path: asset.path,
16
+ type: "Bundle Asset",
17
+ title: asset.path,
18
+ tags: ["asset"].concat(asset.roles || []),
19
+ aliases: [],
20
+ description: `${asset.mimeType} (${asset.size} bytes)`,
21
+ asset: true,
22
+ mimeType: asset.mimeType,
23
+ size: asset.size,
24
+ sha256: asset.sha256,
25
+ roles: asset.roles || [],
17
26
  };
18
27
  }
19
28
 
@@ -74,18 +83,25 @@ function trimGraph(nodes, edges, options) {
74
83
  }
75
84
 
76
85
  function canonicalUri(index, uri) {
77
- const doc = uri ? index.byUri.get(uri) : null;
86
+ const doc = resolveConcept(index, uri);
78
87
  return doc ? doc.uri : uri;
79
88
  }
80
89
 
90
+ function edgeAllowed(edge, options) {
91
+ const kinds = options && Array.isArray(options.edgeKinds) ? options.edgeKinds : [];
92
+ return !kinds.length || kinds.includes(edge.kind);
93
+ }
94
+
81
95
  function getGraph(index, options) {
82
96
  const docs = docsByFilter(index, options || {});
83
97
  const uris = new Set(docs.map((doc) => doc.uri));
84
98
  const nodes = docs.map(nodeFor).sort((a, b) => a.id.localeCompare(b.id));
85
99
  const includeExternal = Boolean(options && options.includeExternal);
100
+ const includeAssets = Boolean(options && options.includeAssets);
86
101
  const externalUris = new Set();
102
+ const assetUris = new Set();
87
103
  const edges = index.edges.filter((edge) => {
88
- if (edge.broken || !uris.has(edge.source)) {
104
+ if (edge.broken || !edgeAllowed(edge, options) || !uris.has(edge.source)) {
89
105
  return false;
90
106
  }
91
107
  if (uris.has(edge.target)) {
@@ -95,21 +111,31 @@ function getGraph(index, options) {
95
111
  externalUris.add(edge.target);
96
112
  return true;
97
113
  }
114
+ if (includeAssets && index.byAssetUri && index.byAssetUri.has(edge.target)) {
115
+ assetUris.add(edge.target);
116
+ return true;
117
+ }
98
118
  return false;
99
119
  });
100
120
  externalUris.forEach((uri) => nodes.push(externalNodeFor(uri)));
121
+ assetUris.forEach((uri) => nodes.push(assetNodeFor(index.byAssetUri.get(uri))));
101
122
  return trimGraph(nodes, edges, options || {});
102
123
  }
103
124
 
104
- function getNeighbors(index, uri) {
125
+ function getNeighbors(index, uri, options) {
105
126
  const canonical = canonicalUri(index, uri);
106
127
  const inbound = [];
107
128
  const outbound = [];
108
129
  index.edges.forEach((edge) => {
130
+ if (edge.broken || !edgeAllowed(edge, options)) {
131
+ return;
132
+ }
109
133
  if (edge.source === canonical && index.byUri.has(edge.target)) {
110
134
  outbound.push({ edge, node: nodeFor(index.byUri.get(edge.target)) });
111
- } else if (edge.source === canonical && edge.external) {
135
+ } else if (edge.source === canonical && edge.external && options && options.includeExternal) {
112
136
  outbound.push({ edge, node: externalNodeFor(edge.target) });
137
+ } else if (edge.source === canonical && options && options.includeAssets && index.byAssetUri && index.byAssetUri.has(edge.target)) {
138
+ outbound.push({ edge, node: assetNodeFor(index.byAssetUri.get(edge.target)) });
113
139
  }
114
140
  if (edge.target === canonical && index.byUri.has(edge.source)) {
115
141
  inbound.push({ edge, node: nodeFor(index.byUri.get(edge.source)) });
@@ -129,7 +155,7 @@ function getSubgraph(index, options) {
129
155
  frontier.forEach((uri) => seen.add(uri));
130
156
  for (let level = 0; level < depth && frontier.length && seen.size < maxNodes; level += 1) {
131
157
  const next = [];
132
- index.edges.filter((edge) => !edge.broken).forEach((edge) => {
158
+ index.edges.filter((edge) => !edge.broken && edgeAllowed(edge, options)).forEach((edge) => {
133
159
  if (frontier.includes(edge.source) && allowedUris.has(edge.target) && !seen.has(edge.target)) {
134
160
  seen.add(edge.target);
135
161
  next.push(edge.target);
@@ -143,16 +169,16 @@ function getSubgraph(index, options) {
143
169
  }
144
170
  const nodes = Array.from(seen).map((uri) => index.byUri.get(uri)).filter(Boolean).map(nodeFor);
145
171
  const uris = new Set(nodes.map((node) => node.id));
146
- const edges = index.edges.filter((edge) => !edge.broken && uris.has(edge.source) && uris.has(edge.target));
172
+ const edges = index.edges.filter((edge) => !edge.broken && edgeAllowed(edge, options) && uris.has(edge.source) && uris.has(edge.target));
147
173
  return trimGraph(nodes, edges, Object.assign({}, options, { maxNodes }));
148
174
  }
149
175
 
150
- function findPaths(index, source, target, maxPaths) {
176
+ function findPaths(index, source, target, maxPaths, options) {
151
177
  const canonicalSource = canonicalUri(index, source);
152
178
  const canonicalTarget = canonicalUri(index, target);
153
179
  const limit = boundedInteger(maxPaths, 3, 1, 50);
154
180
  const adjacency = new Map();
155
- index.edges.filter((edge) => !edge.broken).forEach((edge) => {
181
+ index.edges.filter((edge) => !edge.broken && edgeAllowed(edge, options)).forEach((edge) => {
156
182
  if (!adjacency.has(edge.source)) {
157
183
  adjacency.set(edge.source, []);
158
184
  }
@@ -188,9 +214,26 @@ function graphSummary(index) {
188
214
  const byTag = {};
189
215
  const byBundle = {};
190
216
  const byRelationType = {};
217
+ const byEdgeKind = {};
218
+ const byStatus = {};
219
+ const byTrustTier = {};
220
+ const byFreshness = {};
221
+ const byRuntime = {};
222
+ let attestationReady = 0;
191
223
  index.concepts.forEach((doc) => {
192
224
  byType[doc.type] = (byType[doc.type] || 0) + 1;
193
225
  byBundle[doc.bundle] = (byBundle[doc.bundle] || 0) + 1;
226
+ const signals = doc.signals || {};
227
+ byStatus[signals.status || "unknown"] = (byStatus[signals.status || "unknown"] || 0) + 1;
228
+ byTrustTier[signals.trustTier || "unverified"] = (byTrustTier[signals.trustTier || "unverified"] || 0) + 1;
229
+ byFreshness[signals.freshness || "unspecified"] = (byFreshness[signals.freshness || "unspecified"] || 0) + 1;
230
+ if (signals.computation) {
231
+ const runtime = signals.computation.runtime || "invalid";
232
+ byRuntime[runtime] = (byRuntime[runtime] || 0) + 1;
233
+ if (signals.computation.attestationReady) {
234
+ attestationReady += 1;
235
+ }
236
+ }
194
237
  doc.tags.forEach((tag) => {
195
238
  byTag[tag] = (byTag[tag] || 0) + 1;
196
239
  });
@@ -198,6 +241,7 @@ function graphSummary(index) {
198
241
  const inbound = new Map();
199
242
  const outbound = new Map();
200
243
  index.edges.filter((edge) => !edge.broken).forEach((edge) => {
244
+ byEdgeKind[edge.kind] = (byEdgeKind[edge.kind] || 0) + 1;
201
245
  outbound.set(edge.source, (outbound.get(edge.source) || 0) + 1);
202
246
  inbound.set(edge.target, (inbound.get(edge.target) || 0) + 1);
203
247
  if (edge.kind === "relation") {
@@ -217,15 +261,23 @@ function graphSummary(index) {
217
261
  documents: index.documents.length,
218
262
  concepts: index.concepts.length,
219
263
  reserved: index.reserved.length,
264
+ assets: (index.assets || []).length,
220
265
  edges: index.edges.length,
221
266
  brokenLinks: index.edges.filter((edge) => edge.kind === "markdown_link" && edge.broken).length,
222
267
  brokenRelations: index.edges.filter((edge) => edge.kind === "relation" && edge.broken).length,
223
268
  relations: index.edges.filter((edge) => edge.kind === "relation").length,
269
+ brokenSemanticReferences: index.edges.filter((edge) => ["resource", "source", "computation", "executor", "attester"].includes(edge.kind) && edge.broken).length,
270
+ attestationReady,
224
271
  externalReferences: index.externalReferences ? index.externalReferences.length : 0,
225
272
  byBundle,
226
273
  byType,
227
274
  byTag,
228
275
  byRelationType,
276
+ byEdgeKind,
277
+ byStatus,
278
+ byTrustTier,
279
+ byFreshness,
280
+ byRuntime,
229
281
  orphanConcepts,
230
282
  topLinkedConcepts,
231
283
  warnings: index.warnings,
@@ -275,4 +327,5 @@ module.exports = {
275
327
  getSubgraph,
276
328
  graphSummary,
277
329
  nodeFor,
330
+ assetNodeFor,
278
331
  };
@@ -91,6 +91,7 @@ function createHttpHandler(service, options) {
91
91
  return;
92
92
  }
93
93
  if (req.method === "GET" && url.pathname === "/v1/proposals") {
94
+ requireWriteAuth(req, writeToken);
94
95
  sendJson(res, 200, await service.listProposals({
95
96
  bundle: url.searchParams.get("bundle") || "",
96
97
  status: url.searchParams.get("status") || "",
@@ -99,6 +100,7 @@ function createHttpHandler(service, options) {
99
100
  }
100
101
  const proposalMatch = url.pathname.match(/^\/v1\/proposals\/([^/]+)(?:\/(accept|reject))?$/);
101
102
  if (proposalMatch && req.method === "GET" && !proposalMatch[2]) {
103
+ requireWriteAuth(req, writeToken);
102
104
  sendJson(res, 200, await service.getProposal({ proposalId: proposalMatch[1] }));
103
105
  return;
104
106
  }
@@ -122,7 +124,12 @@ function createHttpHandler(service, options) {
122
124
 
123
125
  async function runHttpServer(options) {
124
126
  const config = options || {};
125
- const store = config.store || FileConceptStore.fromProject(config.projectPath, { proposalRoot: config.proposalRoot });
127
+ const store = config.store || (config.rootPath
128
+ ? FileConceptStore.fromRoot(config.rootPath, {
129
+ proposalRoot: config.proposalRoot,
130
+ strictLinks: config.strictLinks,
131
+ })
132
+ : FileConceptStore.fromProject(config.projectPath, { proposalRoot: config.proposalRoot }));
126
133
  const service = config.service || new ConceptAuthoringService(store);
127
134
  const server = http.createServer(createHttpHandler(service, { writeToken: config.writeToken }));
128
135
  const host = config.host || "127.0.0.1";
package/src/index.js CHANGED
@@ -2,12 +2,17 @@
2
2
 
3
3
  module.exports = {
4
4
  ...require("./parser"),
5
+ ...require("./v02"),
6
+ ...require("./assets"),
5
7
  ...require("./indexer"),
6
8
  ...require("./search"),
7
9
  ...require("./graph"),
8
10
  ...require("./project"),
9
11
  ...require("./plugins"),
10
12
  ...require("./remote"),
13
+ ...require("./computation"),
14
+ ...require("./git-source"),
15
+ ...require("./migration"),
11
16
  ...require("./authoring"),
12
17
  ...require("./store"),
13
18
  ...require("./http-server"),