@mfdaves/okf-mcp 0.7.0 → 0.9.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/README.md +79 -18
- package/okf/{bundles/okf-mcp → okf-mcp}/distribution/reference-bundle.md +1 -1
- package/okf/{bundles/okf-mcp → okf-mcp}/index.md +3 -0
- package/okf/{bundles/okf-mcp → okf-mcp}/interfaces/mcp-tools.md +13 -5
- package/okf/{bundles/okf-mcp → okf-mcp}/overview/okf-mcp.md +5 -3
- package/okf/{bundles/okf-mcp → okf-mcp}/policies/authoring-safety.md +9 -1
- package/okf/{bundles/okf-mcp → okf-mcp}/runtime/file-concept-store.md +1 -1
- package/okf/{bundles/okf-mcp → okf-mcp}/runtime/mcp-server.md +6 -2
- package/okf/okf-mcp/runtime/producer-host.md +28 -0
- package/okf/{bundles/okf-mcp → okf-mcp}/specs/concept-format.md +1 -1
- package/okf/okf-mcp/specs/producer-api.md +26 -0
- package/okf/{bundles/okf-mcp → okf-mcp}/workflows/concept-authoring.md +1 -1
- package/okf/okf-mcp/workflows/producer-publication.md +28 -0
- package/okf.project.yaml +1 -1
- package/package.json +2 -2
- package/server.json +11 -3
- package/src/authoring.js +47 -11
- package/src/cli.js +46 -4
- package/src/graph.js +2 -2
- package/src/index.js +2 -0
- package/src/indexer.js +166 -8
- package/src/live-authoring.js +132 -50
- package/src/mcp-server.js +189 -13
- package/src/producer-publisher.js +462 -0
- package/src/producers.js +507 -0
- package/src/project.js +65 -0
- package/src/search.js +19 -0
- package/src/store.js +1 -0
- /package/okf/{bundles/okf-mcp → okf-mcp}/interfaces/http-authoring-api.md +0 -0
- /package/okf/{bundles/okf-mcp → okf-mcp}/runtime/indexer.md +0 -0
- /package/okf/{bundles/okf-mcp → okf-mcp}/specs/attested-computation.md +0 -0
- /package/okf/{bundles/okf-mcp → okf-mcp}/specs/git-sources.md +0 -0
- /package/okf/{bundles/okf-mcp → okf-mcp}/workflows/concept-update.md +0 -0
- /package/okf/{bundles/okf-mcp → okf-mcp}/workflows/v02-migration.md +0 -0
package/src/authoring.js
CHANGED
|
@@ -7,6 +7,8 @@ const yaml = require("js-yaml");
|
|
|
7
7
|
const { parseMarkdownText, normalizeSlashes } = require("./parser");
|
|
8
8
|
const {
|
|
9
9
|
bundleExcludesPath,
|
|
10
|
+
conceptMatchSummary,
|
|
11
|
+
findConceptMatches,
|
|
10
12
|
resolveLinkPath,
|
|
11
13
|
semanticReferences,
|
|
12
14
|
} = require("./indexer");
|
|
@@ -27,6 +29,22 @@ function slug(value, fallback) {
|
|
|
27
29
|
.replace(/^-+|-+$/g, "") || String(fallback || "concept");
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
function isConfiguredGeneratorOutput(project, absolutePath) {
|
|
33
|
+
if (!project || !project.root || !absolutePath) return false;
|
|
34
|
+
const pluginOutput = (project.plugins || []).some((plugin) => {
|
|
35
|
+
if (!plugin || !plugin.output) return false;
|
|
36
|
+
const relative = path.relative(path.resolve(project.root, String(plugin.output)), absolutePath);
|
|
37
|
+
return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative));
|
|
38
|
+
});
|
|
39
|
+
if (pluginOutput) return true;
|
|
40
|
+
const managedBundles = new Set((project.producers || []).map((producer) => producer && producer.bundle));
|
|
41
|
+
return (project.bundles || []).some((bundle) => {
|
|
42
|
+
if (!bundle || !managedBundles.has(bundle.id)) return false;
|
|
43
|
+
const relative = path.relative(path.resolve(bundle.root), absolutePath);
|
|
44
|
+
return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
30
48
|
function normalizeConceptPath(value) {
|
|
31
49
|
const raw = normalizeSlashes(String(value || "").trim());
|
|
32
50
|
if (!raw) {
|
|
@@ -79,15 +97,12 @@ function deriveConceptPathSuggestion(index, bundle, input) {
|
|
|
79
97
|
let strategy = prefix ? "explicit_prefix" : "type_slug";
|
|
80
98
|
let evidence = { matchingConcepts: 0, dominantDirectoryCount: 0, dominantDirectoryRatio: 0 };
|
|
81
99
|
|
|
82
|
-
if (
|
|
83
|
-
const matching = index
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
&& document.type === type
|
|
89
|
-
&& typeof document.path === "string"
|
|
90
|
-
));
|
|
100
|
+
if (type !== "Attested Computation" && index) {
|
|
101
|
+
const matching = findConceptMatches(index, {
|
|
102
|
+
bundle: bundle.id,
|
|
103
|
+
type,
|
|
104
|
+
pathPrefix: prefix,
|
|
105
|
+
});
|
|
91
106
|
const counts = new Map();
|
|
92
107
|
matching.forEach((document) => {
|
|
93
108
|
const directory = path.posix.dirname(document.path);
|
|
@@ -185,14 +200,34 @@ class ConceptAuthoringService {
|
|
|
185
200
|
|
|
186
201
|
suggestConceptPath(input) {
|
|
187
202
|
const bundle = this.getBundle(input && input.bundle);
|
|
188
|
-
const
|
|
203
|
+
const index = this.store.getIndex();
|
|
204
|
+
const suggestion = deriveConceptPathSuggestion(index, bundle, input || {});
|
|
189
205
|
const target = this.store.resolveConceptFile(bundle.id, suggestion.path);
|
|
206
|
+
const titleMatches = findConceptMatches(index, {
|
|
207
|
+
bundle: bundle.id,
|
|
208
|
+
type: input && input.type,
|
|
209
|
+
title: input && input.title,
|
|
210
|
+
});
|
|
211
|
+
const matches = titleMatches.slice(0, 5).map((doc) => conceptMatchSummary(doc));
|
|
212
|
+
const available = !fs.existsSync(target.absolutePath);
|
|
213
|
+
const only = matches.length === 1 && matches[0];
|
|
214
|
+
const generatorOwned = only && (only.generatedFile
|
|
215
|
+
|| only.generatedBy && only.generatedBy.startsWith("process:")
|
|
216
|
+
|| isConfiguredGeneratorOutput(this.store.project, titleMatches[0].absolutePath));
|
|
190
217
|
return {
|
|
191
218
|
bundle: bundle.id,
|
|
192
219
|
path: suggestion.path,
|
|
193
220
|
uri: `okf://${bundle.id}/${suggestion.path.replace(/\.md$/i, "")}`,
|
|
194
221
|
absolutePath: target.absolutePath,
|
|
195
|
-
available
|
|
222
|
+
available,
|
|
223
|
+
creatable: available && titleMatches.length === 0,
|
|
224
|
+
titleMatches: matches,
|
|
225
|
+
titleMatchesOmitted: Math.max(0, titleMatches.length - matches.length),
|
|
226
|
+
...(matches.length === 1 ? { existingConcept: matches[0] } : {}),
|
|
227
|
+
recommendedOperation: titleMatches.length
|
|
228
|
+
? titleMatches.length > 1 ? "review_matches"
|
|
229
|
+
: generatorOwned ? "change_generator" : "update"
|
|
230
|
+
: available ? "create" : "inspect_existing",
|
|
196
231
|
strategy: suggestion.strategy,
|
|
197
232
|
evidence: suggestion.evidence,
|
|
198
233
|
};
|
|
@@ -868,6 +903,7 @@ class ConceptAuthoringService {
|
|
|
868
903
|
module.exports = {
|
|
869
904
|
ConceptAuthoringService,
|
|
870
905
|
deriveConceptPathSuggestion,
|
|
906
|
+
isConfiguredGeneratorOutput,
|
|
871
907
|
normalizeConceptPath,
|
|
872
908
|
renderConceptMarkdown,
|
|
873
909
|
renderFrontmatter,
|
package/src/cli.js
CHANGED
|
@@ -15,6 +15,8 @@ const { searchConcepts } = require("./search");
|
|
|
15
15
|
const { conceptSummary } = require("./indexer");
|
|
16
16
|
const { findOkfRoot, findProjectConfig, loadProjectConfig } = require("./project");
|
|
17
17
|
const { generateProject } = require("./plugins");
|
|
18
|
+
const { ProducerService, producerReceipt } = require("./producers");
|
|
19
|
+
const { FileConceptStore } = require("./store");
|
|
18
20
|
const { runStdioServer } = require("./mcp-server");
|
|
19
21
|
const { fetchRemoteBundles } = require("./remote");
|
|
20
22
|
const { runHttpServer } = require("./http-server");
|
|
@@ -32,8 +34,10 @@ const packageMetadata = require("../package.json");
|
|
|
32
34
|
|
|
33
35
|
const COMMANDS = new Set([
|
|
34
36
|
"mcp", "validate", "graph", "search", "concept", "neighbors", "paths", "generate", "serve",
|
|
35
|
-
"provenance", "edge-kinds", "computation", "asset", "source", "migrate",
|
|
37
|
+
"provenance", "edge-kinds", "computation", "asset", "source", "migrate", "producer",
|
|
36
38
|
]);
|
|
39
|
+
const PRODUCER_ACTIONS = new Set(["list", "preview", "run"]);
|
|
40
|
+
const WRITE_COMMANDS = new Set(["mcp", "producer"]);
|
|
37
41
|
|
|
38
42
|
class UsageError extends Error {
|
|
39
43
|
constructor(message) {
|
|
@@ -459,6 +463,7 @@ function usage() {
|
|
|
459
463
|
" okf-mcp --project <okf.project.yaml> <command>",
|
|
460
464
|
" okf-mcp [--project <okf.project.yaml>] [--authoring] [--write --actor <actor>] [--git-commit] mcp",
|
|
461
465
|
" okf-mcp --project <okf.project.yaml> serve [--host 127.0.0.1] [--port 8765]",
|
|
466
|
+
" okf-mcp --project <okf.project.yaml> producer run <name> --write --actor <actor>",
|
|
462
467
|
" okf-mcp <command> --bundle <path-or-id=path>",
|
|
463
468
|
"",
|
|
464
469
|
"Commands:",
|
|
@@ -479,6 +484,9 @@ function usage() {
|
|
|
479
484
|
" migrate check [bundle] Check staged v0.2 migration readiness.",
|
|
480
485
|
" migrate preview [bundle] [actor-mappings-json]",
|
|
481
486
|
" generate Run configured generator plugins.",
|
|
487
|
+
" producer list List configured external metadata producers.",
|
|
488
|
+
" producer preview <name> Validate one producer's candidate bundle without writing.",
|
|
489
|
+
" producer run <name> Publish one producer (requires --write --actor).",
|
|
482
490
|
" serve Start the HTTP OKF API server.",
|
|
483
491
|
"",
|
|
484
492
|
"Options:",
|
|
@@ -486,7 +494,7 @@ function usage() {
|
|
|
486
494
|
" --repo <concept-id=path> Map a Git Repository concept to a checkout or bare repo; repeatable.",
|
|
487
495
|
" --authoring Enable MCP proposal authoring tools.",
|
|
488
496
|
" --write Enable direct validated-batch MCP concept writes (requires --actor).",
|
|
489
|
-
" --actor <actor> Stamp live writes with human:id, process:id, or provider/model.",
|
|
497
|
+
" --actor <actor> Stamp live writes and producer runs with human:id, process:id, or provider/model.",
|
|
490
498
|
" --git-commit Commit each live write batch when the catalog is in a clean Git repo.",
|
|
491
499
|
" --allow-remote-tool Enable runtime remote-bundle loading over MCP.",
|
|
492
500
|
" --allow-computation-authoring Enable coordinated computation proposals (also requires --authoring).",
|
|
@@ -668,8 +676,11 @@ async function main(argv, runtime) {
|
|
|
668
676
|
if (!COMMANDS.has(command)) {
|
|
669
677
|
throw usageError(`Unknown OKF command: ${command}`);
|
|
670
678
|
}
|
|
671
|
-
if (command
|
|
672
|
-
throw usageError("--write, --actor, and --git-commit are available only with the mcp
|
|
679
|
+
if (!WRITE_COMMANDS.has(command) && (args.write || args.actor || args.gitCommit)) {
|
|
680
|
+
throw usageError("--write, --actor, and --git-commit are available only with the mcp and producer commands.");
|
|
681
|
+
}
|
|
682
|
+
if (command === "producer" && args.gitCommit) {
|
|
683
|
+
throw usageError("--git-commit is available only with the mcp command.");
|
|
673
684
|
}
|
|
674
685
|
if (command === "mcp") {
|
|
675
686
|
const bundles = resolveLegacyBundles(args);
|
|
@@ -716,6 +727,37 @@ async function main(argv, runtime) {
|
|
|
716
727
|
printJson(generateProject(project));
|
|
717
728
|
return;
|
|
718
729
|
}
|
|
730
|
+
if (command === "producer") {
|
|
731
|
+
if (!args.project) {
|
|
732
|
+
throw usageError("producer requires --project.");
|
|
733
|
+
}
|
|
734
|
+
const action = args.positional[1] || "list";
|
|
735
|
+
if (!PRODUCER_ACTIONS.has(action)) {
|
|
736
|
+
throw usageError("producer action must be list, preview, or run.");
|
|
737
|
+
}
|
|
738
|
+
const loaded = await loadProjectBundles(args.project);
|
|
739
|
+
const service = new ProducerService({
|
|
740
|
+
project: loaded.project,
|
|
741
|
+
store: FileConceptStore.fromProject(args.project, { proposalRoot: args.proposalRoot || "" }),
|
|
742
|
+
bundles: (loaded.bundles || []).filter((bundle) => !bundle.remote),
|
|
743
|
+
});
|
|
744
|
+
if (action === "list") {
|
|
745
|
+
printJson(service.list());
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
const name = args.positional[2];
|
|
749
|
+
if (!name) {
|
|
750
|
+
throw usageError(`producer ${action} requires a configured producer name.`);
|
|
751
|
+
}
|
|
752
|
+
if (action === "run" && !args.write) {
|
|
753
|
+
throw usageError("producer run requires --write --actor <human:id|process:id|provider/model>.");
|
|
754
|
+
}
|
|
755
|
+
const receipt = action === "run" ? await service.run(name) : await service.preview(name);
|
|
756
|
+
printJson(producerReceipt(receipt, "full"));
|
|
757
|
+
const succeeded = action === "run" ? receipt.applied === true : receipt.valid === true;
|
|
758
|
+
process.exitCode = succeeded ? 0 : 1;
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
719
761
|
const index = await loadIndex(args);
|
|
720
762
|
const repositoryMappings = parseRepositoryMappings(args.repositories);
|
|
721
763
|
if (command === "validate") {
|
package/src/graph.js
CHANGED
|
@@ -180,9 +180,9 @@ function findPaths(index, source, target, maxPaths, options) {
|
|
|
180
180
|
const adjacency = new Map();
|
|
181
181
|
index.edges.filter((edge) => !edge.broken && edgeAllowed(edge, options)).forEach((edge) => {
|
|
182
182
|
if (!adjacency.has(edge.source)) {
|
|
183
|
-
adjacency.set(edge.source,
|
|
183
|
+
adjacency.set(edge.source, new Set());
|
|
184
184
|
}
|
|
185
|
-
adjacency.get(edge.source).
|
|
185
|
+
adjacency.get(edge.source).add(edge.target);
|
|
186
186
|
});
|
|
187
187
|
const queue = [[canonicalSource]];
|
|
188
188
|
const paths = [];
|
package/src/index.js
CHANGED
package/src/indexer.js
CHANGED
|
@@ -171,23 +171,169 @@ function registerPortableConceptId(map, ambiguous, key, document) {
|
|
|
171
171
|
map.set(normalized, document);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
function portableConceptKeys(value) {
|
|
175
|
+
const normalized = normalizeSlashes(String(value || ""))
|
|
176
|
+
.replace(/^\/+/, "")
|
|
177
|
+
.split("#")[0];
|
|
178
|
+
if (!normalized) return [];
|
|
179
|
+
return normalized.toLowerCase().endsWith(".md")
|
|
180
|
+
? [normalized, normalized.slice(0, -3)]
|
|
181
|
+
: [normalized, `${normalized}.md`];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function portableConceptMatches(index, value) {
|
|
185
|
+
for (const key of portableConceptKeys(value)) {
|
|
186
|
+
const matches = (index.documents || []).filter((doc) => doc.conceptId === key || doc.path === key);
|
|
187
|
+
if (matches.length) {
|
|
188
|
+
return matches.sort((left, right) => left.uri.localeCompare(right.uri));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
|
|
174
194
|
function resolveConcept(index, locator) {
|
|
175
195
|
const raw = String(locator || "").trim();
|
|
176
196
|
if (!raw || !index) {
|
|
177
197
|
return null;
|
|
178
198
|
}
|
|
179
|
-
const
|
|
199
|
+
const fragmentless = normalizeSlashes(raw).split("#")[0];
|
|
200
|
+
const byUri = index.byUri && (index.byUri.get(raw) || index.byUri.get(fragmentless));
|
|
180
201
|
if (byUri) {
|
|
181
202
|
return byUri;
|
|
182
203
|
}
|
|
183
|
-
|
|
184
|
-
|
|
204
|
+
if ((index.ambiguousAliases || new Set()).has(raw)
|
|
205
|
+
|| (index.ambiguousAliases || new Set()).has(fragmentless)) {
|
|
185
206
|
return null;
|
|
186
207
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|| index.
|
|
190
|
-
|
|
208
|
+
const uriMatch = fragmentless.match(/^okf:\/\/([^/]+)\/(.+)$/);
|
|
209
|
+
if (fragmentless.startsWith("okf://")) {
|
|
210
|
+
if (!uriMatch || (index.bundles || []).some((bundle) => bundle.id === uriMatch[1])) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const key of portableConceptKeys(uriMatch ? `${uriMatch[1]}/${uriMatch[2]}` : fragmentless)) {
|
|
215
|
+
if ((index.ambiguousConceptIds || new Set()).has(key)) return null;
|
|
216
|
+
const owner = index.byConceptId && index.byConceptId.get(key);
|
|
217
|
+
if (owner) return owner;
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function normalizeConceptTitle(value) {
|
|
223
|
+
return String(value || "").normalize("NFKC").trim().replace(/\s+/gu, " ").toLowerCase();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function conceptTitleSlug(value) {
|
|
227
|
+
return normalizeConceptTitle(value)
|
|
228
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
229
|
+
.replace(/^-+|-+$/g, "");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function conceptIsGeneratedFile(doc) {
|
|
233
|
+
const frontmatter = doc && doc.frontmatter || {};
|
|
234
|
+
return Boolean(doc && (doc.generatedFile === true || doc.isGenerated === true)
|
|
235
|
+
|| frontmatter.generated_file === true || frontmatter.generatedFile === true);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function conceptMatchSummary(doc, matchReasons) {
|
|
239
|
+
const generated = doc && doc.signals && doc.signals.generated;
|
|
240
|
+
return {
|
|
241
|
+
uri: doc.uri,
|
|
242
|
+
bundle: doc.bundle,
|
|
243
|
+
path: doc.path,
|
|
244
|
+
conceptId: doc.conceptId || doc.path.replace(/\.md$/i, ""),
|
|
245
|
+
type: doc.type || doc.frontmatter && doc.frontmatter.type,
|
|
246
|
+
title: doc.title,
|
|
247
|
+
generatedBy: generated && generated.by || null,
|
|
248
|
+
...(conceptIsGeneratedFile(doc) ? { generatedFile: true } : {}),
|
|
249
|
+
...(matchReasons && matchReasons.length ? { matchReasons } : {}),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function findConceptMatches(index, options) {
|
|
254
|
+
const config = options || {};
|
|
255
|
+
const title = config.title === undefined ? null : normalizeConceptTitle(config.title);
|
|
256
|
+
const prefix = normalizeSlashes(String(config.pathPrefix || "")).replace(/^\/+|\/+$/g, "");
|
|
257
|
+
const documents = index && Array.isArray(index.concepts)
|
|
258
|
+
? index.concepts
|
|
259
|
+
: index && Array.isArray(index.documents) ? index.documents : [];
|
|
260
|
+
return documents
|
|
261
|
+
.filter((doc) => (
|
|
262
|
+
doc && doc.valid !== false && !doc.reserved
|
|
263
|
+
&& typeof doc.path === "string"
|
|
264
|
+
&& (!config.bundle || doc.bundle === config.bundle)
|
|
265
|
+
&& (!config.type || doc.type === config.type)
|
|
266
|
+
&& (title === null || normalizeConceptTitle(doc.title) === title)
|
|
267
|
+
&& (!prefix || doc.path === prefix || doc.path.startsWith(`${prefix}/`))
|
|
268
|
+
))
|
|
269
|
+
.sort((left, right) => left.path.localeCompare(right.path) || left.uri.localeCompare(right.uri));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function recoveryReceipt(locator, entries, limit, allowRetry, forcedAmbiguity) {
|
|
273
|
+
const maximum = Math.max(1, Math.min(Number(limit || 5), 20));
|
|
274
|
+
const candidates = entries.slice(0, maximum)
|
|
275
|
+
.map((entry) => conceptMatchSummary(entry.doc, entry.reasons));
|
|
276
|
+
const actionable = entries.length === 1 && entries[0].doc.valid && !entries[0].doc.reserved;
|
|
277
|
+
return {
|
|
278
|
+
status: forcedAmbiguity || entries.length > 1 ? "ambiguous"
|
|
279
|
+
: actionable ? "replacement_found" : "not_found",
|
|
280
|
+
requestedLocator: locator,
|
|
281
|
+
candidates,
|
|
282
|
+
omitted: Math.max(0, entries.length - candidates.length),
|
|
283
|
+
...(allowRetry && !forcedAmbiguity && actionable
|
|
284
|
+
? { retryWith: { uri: entries[0].doc.uri } } : {}),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function recoverConceptLocator(index, locator, options) {
|
|
289
|
+
const config = options || {};
|
|
290
|
+
const raw = normalizeSlashes(String(locator || "").trim()).split("#")[0];
|
|
291
|
+
const uriMatch = raw.match(/^okf:\/\/([^/]+)\/(.+)$/);
|
|
292
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(raw) && !uriMatch) {
|
|
293
|
+
return { status: "not_found", requestedLocator: raw, candidates: [], omitted: 0 };
|
|
294
|
+
}
|
|
295
|
+
const knownBundle = uriMatch && (index.bundles || []).some((entry) => entry.id === uriMatch[1]);
|
|
296
|
+
const bundle = knownBundle ? uriMatch[1] : config.bundle || "";
|
|
297
|
+
const portablePath = (uriMatch && knownBundle
|
|
298
|
+
? uriMatch[2]
|
|
299
|
+
: raw.replace(/^okf:\/\//, ""))
|
|
300
|
+
.replace(/^\/+/, "");
|
|
301
|
+
const aliasOwners = (index.documents || []).filter((doc) => (
|
|
302
|
+
(index.ambiguousAliases || new Set()).has(raw) && (doc.uriAliases || []).includes(raw)
|
|
303
|
+
)).sort((left, right) => left.uri.localeCompare(right.uri));
|
|
304
|
+
const exact = aliasOwners.length ? aliasOwners : knownBundle ? [] : portableConceptMatches(index, portablePath);
|
|
305
|
+
if (exact.length) {
|
|
306
|
+
const portableAmbiguous = portableConceptKeys(portablePath)
|
|
307
|
+
.some((key) => (index.ambiguousConceptIds || new Set()).has(key));
|
|
308
|
+
return recoveryReceipt(raw, exact.map((doc) => ({
|
|
309
|
+
doc, reasons: [aliasOwners.length ? "uri_alias" : "portable_id"],
|
|
310
|
+
})), config.limit, !aliasOwners.length && !portableAmbiguous,
|
|
311
|
+
aliasOwners.length > 0 || portableAmbiguous);
|
|
312
|
+
}
|
|
313
|
+
const requestedPath = portablePath.replace(/\.md$/i, "");
|
|
314
|
+
const requestedBase = path.posix.basename(requestedPath).toLowerCase();
|
|
315
|
+
const requestedSlug = conceptTitleSlug(requestedBase);
|
|
316
|
+
const ranked = [];
|
|
317
|
+
if (!requestedSlug) return recoveryReceipt(raw, [], config.limit, false);
|
|
318
|
+
findConceptMatches(index, { bundle }).forEach((doc) => {
|
|
319
|
+
const base = path.posix.basename(doc.conceptId || doc.path.replace(/\.md$/i, "")).toLowerCase();
|
|
320
|
+
const reasons = [];
|
|
321
|
+
if (base === requestedBase) reasons.push("path_basename");
|
|
322
|
+
if (conceptTitleSlug(doc.title) === requestedSlug) reasons.push("title_slug");
|
|
323
|
+
if ((doc.aliases || []).some((alias) => conceptTitleSlug(alias) === requestedSlug)) reasons.push("alias");
|
|
324
|
+
if (!reasons.length) return;
|
|
325
|
+
ranked.push({
|
|
326
|
+
doc,
|
|
327
|
+
reasons,
|
|
328
|
+
score: (reasons.includes("path_basename") ? 4 : 0)
|
|
329
|
+
+ (reasons.includes("title_slug") ? 2 : 0)
|
|
330
|
+
+ (reasons.includes("alias") ? 1 : 0),
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
ranked.sort((left, right) => right.score - left.score
|
|
334
|
+
|| left.doc.path.localeCompare(right.doc.path)
|
|
335
|
+
|| left.doc.uri.localeCompare(right.doc.uri));
|
|
336
|
+
return recoveryReceipt(raw, ranked, config.limit, true);
|
|
191
337
|
}
|
|
192
338
|
|
|
193
339
|
function resolveIndexedLink(bundleId, resolved, href, documentsByPath) {
|
|
@@ -326,6 +472,9 @@ function buildIndex(bundleArgs, options) {
|
|
|
326
472
|
const documentOverrides = config.documentOverrides instanceof Map
|
|
327
473
|
? config.documentOverrides
|
|
328
474
|
: new Map();
|
|
475
|
+
const documentDeletions = config.documentDeletions instanceof Set
|
|
476
|
+
? config.documentDeletions
|
|
477
|
+
: new Set();
|
|
329
478
|
const strictLinks = Boolean(config.strictLinks);
|
|
330
479
|
const requestedBundles = uniqueBundleIds((bundleArgs || []).map(parseBundleArg));
|
|
331
480
|
const allowedRelationTypes = new Set((config.relationTypes || DEFAULT_RELATION_TYPES).map(String));
|
|
@@ -414,6 +563,9 @@ function buildIndex(bundleArgs, options) {
|
|
|
414
563
|
return;
|
|
415
564
|
}
|
|
416
565
|
const key = documentOverrideKey(bundle.id, relativePath);
|
|
566
|
+
if (documentDeletions.has(key)) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
417
569
|
indexLocalDocument(
|
|
418
570
|
relativePath,
|
|
419
571
|
documentOverrides.has(key) ? String(documentOverrides.get(key)) : undefined,
|
|
@@ -426,7 +578,7 @@ function buildIndex(bundleArgs, options) {
|
|
|
426
578
|
return;
|
|
427
579
|
}
|
|
428
580
|
const relativePath = normalizeSlashes(String(key).slice(prefix.length));
|
|
429
|
-
if (indexedPaths.has(relativePath) || !bundleAllowsPath(bundle, relativePath)) {
|
|
581
|
+
if (documentDeletions.has(key) || indexedPaths.has(relativePath) || !bundleAllowsPath(bundle, relativePath)) {
|
|
430
582
|
return;
|
|
431
583
|
}
|
|
432
584
|
indexLocalDocument(
|
|
@@ -825,6 +977,7 @@ function attachProject(index, project) {
|
|
|
825
977
|
path: project.path,
|
|
826
978
|
root: project.root,
|
|
827
979
|
plugins: project.plugins,
|
|
980
|
+
producers: project.producers,
|
|
828
981
|
remoteBundles: project.remoteBundles,
|
|
829
982
|
strictLinks: project.strictLinks,
|
|
830
983
|
};
|
|
@@ -900,10 +1053,15 @@ module.exports = {
|
|
|
900
1053
|
attachProject,
|
|
901
1054
|
conceptSummary,
|
|
902
1055
|
conceptSignals,
|
|
1056
|
+
conceptIsGeneratedFile,
|
|
1057
|
+
conceptMatchSummary,
|
|
903
1058
|
bundleAllowsPath,
|
|
904
1059
|
bundleExcludesPath,
|
|
1060
|
+
findConceptMatches,
|
|
905
1061
|
loadProjectBundles,
|
|
1062
|
+
normalizeConceptTitle,
|
|
906
1063
|
parseBundleArg,
|
|
1064
|
+
recoverConceptLocator,
|
|
907
1065
|
resolveLinkPath,
|
|
908
1066
|
resolveConcept,
|
|
909
1067
|
semanticReferences,
|