@mfdaves/okf-mcp 0.3.2-rc.1 → 0.3.3-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/README.md +46 -9
- package/okf/bundles/okf-mcp/distribution/reference-bundle.md +6 -2
- package/okf/bundles/okf-mcp/interfaces/mcp-tools.md +4 -0
- package/okf/bundles/okf-mcp/overview/okf-mcp.md +2 -2
- package/okf/bundles/okf-mcp/runtime/indexer.md +4 -0
- package/okf/bundles/okf-mcp/runtime/mcp-server.md +7 -1
- package/okf/bundles/okf-mcp/specs/concept-format.md +1 -1
- package/package.json +3 -1
- package/server.json +36 -0
- package/src/authoring.js +5 -2
- package/src/indexer.js +46 -9
- package/src/mcp-protocol.js +283 -0
- package/src/mcp-server.js +378 -182
package/README.md
CHANGED
|
@@ -8,18 +8,18 @@ The core intentionally has no database, embeddings, build step, or hosted-servic
|
|
|
8
8
|
|
|
9
9
|
## Install And Run
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
exact version
|
|
11
|
+
This checkout is the `0.3.3-rc.1` release candidate published under npm's
|
|
12
|
+
`next` tag. Pin the exact version while testing it:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
npx -y @mfdaves/okf-mcp@0.3.
|
|
16
|
-
npx -y @mfdaves/okf-mcp@0.3.
|
|
15
|
+
npx -y @mfdaves/okf-mcp@0.3.3-rc.1 --version
|
|
16
|
+
npx -y @mfdaves/okf-mcp@0.3.3-rc.1 --project ./okf.project.yaml validate
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
For a persistent installation:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
npm install --global @mfdaves/okf-mcp@0.3.
|
|
22
|
+
npm install --global @mfdaves/okf-mcp@0.3.3-rc.1
|
|
23
23
|
|
|
24
24
|
okf --version
|
|
25
25
|
okf --project ./okf.project.yaml validate
|
|
@@ -142,7 +142,7 @@ Example client configuration:
|
|
|
142
142
|
"command": "npx",
|
|
143
143
|
"args": [
|
|
144
144
|
"-y",
|
|
145
|
-
"@mfdaves/okf-mcp@0.3.
|
|
145
|
+
"@mfdaves/okf-mcp@0.3.3-rc.1",
|
|
146
146
|
"--bundle",
|
|
147
147
|
"app=/absolute/path/to/repo/okf/bundles/app",
|
|
148
148
|
"mcp"
|
|
@@ -161,7 +161,7 @@ Project config mode, with read-only project helpers but without proposal mutatio
|
|
|
161
161
|
"command": "npx",
|
|
162
162
|
"args": [
|
|
163
163
|
"-y",
|
|
164
|
-
"@mfdaves/okf-mcp@0.3.
|
|
164
|
+
"@mfdaves/okf-mcp@0.3.3-rc.1",
|
|
165
165
|
"--project",
|
|
166
166
|
"/absolute/path/to/repo/okf.project.yaml",
|
|
167
167
|
"mcp"
|
|
@@ -173,6 +173,30 @@ Project config mode, with read-only project helpers but without proposal mutatio
|
|
|
173
173
|
|
|
174
174
|
Add `--authoring` to enable proposal creation, acceptance, and rejection. Add `--allow-remote-tool` to let MCP clients load arbitrary supported public remote bundles at runtime. Configured remote bundles remain readable without that runtime-loading flag.
|
|
175
175
|
|
|
176
|
+
The stdio server supports MCP protocol versions `2025-11-25`, `2025-06-18`,
|
|
177
|
+
`2025-03-26`, and `2024-11-05`. It returns a requested supported version.
|
|
178
|
+
For a well-formed unsupported version, it returns its preferred supported
|
|
179
|
+
version, `2025-11-25`, so the client can continue or disconnect.
|
|
180
|
+
|
|
181
|
+
The transport uses standard JSON-RPC error codes for malformed messages,
|
|
182
|
+
invalid requests, unknown methods, invalid method parameters, missing
|
|
183
|
+
resources, and internal failures. Notifications never receive responses.
|
|
184
|
+
Expected failures from a known tool, such as a missing concept, a read-only
|
|
185
|
+
bundle, a failed remote fetch, or a proposal conflict, are returned as MCP
|
|
186
|
+
tool results with `isError: true`.
|
|
187
|
+
|
|
188
|
+
## MCP Registry Metadata
|
|
189
|
+
|
|
190
|
+
`server.json` describes the npm package as the stdio server
|
|
191
|
+
`io.github.mfdaves/okf-mcp`. Registry-aware clients should prompt for an
|
|
192
|
+
absolute `okf.project.yaml` path, pass it through `--project`, and append the
|
|
193
|
+
fixed `mcp` command.
|
|
194
|
+
|
|
195
|
+
The package, lockfile, CLI, MCP `serverInfo`, `package.json` `mcpName`, and
|
|
196
|
+
both versions in `server.json` are kept synchronized by the package smoke
|
|
197
|
+
gate. Release candidates remain available through npm's `next` tag; only a
|
|
198
|
+
verified stable version is published to the official MCP Registry.
|
|
199
|
+
|
|
176
200
|
## Concept Format
|
|
177
201
|
|
|
178
202
|
The server exposes one resource per Markdown document:
|
|
@@ -237,6 +261,11 @@ Most MCP tools are read-only over the current index. `load_remote_bundle` mutate
|
|
|
237
261
|
|
|
238
262
|
Every MCP tool includes a purpose-specific description, descriptions for its input parameters, and standard annotations covering read-only behavior, destructive behavior, idempotency, and external access.
|
|
239
263
|
|
|
264
|
+
Tool arguments are validated against the advertised input schemas before
|
|
265
|
+
execution. Unsupported fields, missing required values, incorrect primitive
|
|
266
|
+
types, and out-of-range integers are rejected without coercion. Unknown or
|
|
267
|
+
disabled tool names remain protocol-level invalid-parameter errors.
|
|
268
|
+
|
|
240
269
|
Tool discovery and direct invocation use the same capability checks:
|
|
241
270
|
|
|
242
271
|
| Mode | Proposal mutations | Runtime remote load | Configured remote reads |
|
|
@@ -396,7 +425,11 @@ Use `list_remote_bundles` to inspect what was loaded.
|
|
|
396
425
|
- `limit`
|
|
397
426
|
- `offset`
|
|
398
427
|
|
|
399
|
-
|
|
428
|
+
`list_concepts` also accepts a text `query` and applies it together with its
|
|
429
|
+
listing filters. Tags and types are matched case-insensitively. Arbitrary
|
|
430
|
+
frontmatter filters support exact scalar matching and array-contains
|
|
431
|
+
matching. `relationType` selects concepts with an outgoing relation of that
|
|
432
|
+
type.
|
|
400
433
|
|
|
401
434
|
Example:
|
|
402
435
|
|
|
@@ -413,6 +446,10 @@ Example:
|
|
|
413
446
|
|
|
414
447
|
Markdown links between OKF documents become `markdown_link` edges. Frontmatter `relations` become typed `relation` edges.
|
|
415
448
|
|
|
449
|
+
Links to a nested bundle directory resolve to that directory's reserved
|
|
450
|
+
`index.md` when there is no exact document target. This applies to local and
|
|
451
|
+
remote bundles and to candidate validation during proposal authoring.
|
|
452
|
+
|
|
416
453
|
Graph tools return compact JSON:
|
|
417
454
|
|
|
418
455
|
```json
|
|
@@ -499,6 +536,6 @@ Generated output is regular Markdown/YAML OKF and is validated by the same index
|
|
|
499
536
|
## Limitations
|
|
500
537
|
|
|
501
538
|
- The MCP server implements the stdio JSON-RPC methods needed for resources and tools directly instead of using an SDK, so advanced SDK conveniences are out of scope.
|
|
502
|
-
- MCP initialization
|
|
539
|
+
- MCP initialization negotiates an explicit supported version and falls back to `2025-11-25` for well-formed unsupported versions.
|
|
503
540
|
- There is no file watcher. Restart the server after external file changes. Concepts accepted through MCP authoring refresh the MCP server index immediately.
|
|
504
541
|
- The HTTP API is a lightweight built-in server, not a full hosted multi-tenant service.
|
|
@@ -17,6 +17,8 @@ relations:
|
|
|
17
17
|
target: repo://okf.project.yaml
|
|
18
18
|
- type: configured_by
|
|
19
19
|
target: repo://package.json
|
|
20
|
+
- type: configured_by
|
|
21
|
+
target: repo://server.json
|
|
20
22
|
- type: configured_by
|
|
21
23
|
target: repo://.github/workflows/release.yml
|
|
22
24
|
- type: configured_by
|
|
@@ -33,9 +35,11 @@ The latest public bundle can be loaded from:
|
|
|
33
35
|
|
|
34
36
|
Consumers that need reproducibility should replace `main` with a release tag. Remote loading indexes only the Markdown tree and does not execute repository code.
|
|
35
37
|
|
|
36
|
-
The public npm package is `@mfdaves/okf-mcp`. Its allowlist includes `okf.project.yaml` and the `okf` directory so installed artifacts carry the same reference bundle
|
|
38
|
+
The public npm package is `@mfdaves/okf-mcp`. Its allowlist includes `okf.project.yaml`, `server.json`, and the `okf` directory so installed artifacts carry the same reference bundle and MCP Registry metadata. The package declares the Registry name `io.github.mfdaves/okf-mcp`.
|
|
39
|
+
|
|
40
|
+
The package smoke gate verifies that package, lockfile, CLI, MCP server, and Registry versions and identities agree. It installs the generated tarball into a clean temporary project, executes both binaries, validates this bundle, negotiates MCP `2025-11-25`, checks fallback negotiation and notification silence, pings the server, discovers tools, and retrieves a concept over stdio.
|
|
37
41
|
|
|
38
|
-
The repository release skill defines the package identity, capability matrix, self-validation, tarball, clean-install, prerelease, and registry synchronization gates. The trusted-publishing workflow repeats those checks against an exact Git release tag before publishing.
|
|
42
|
+
The repository release skill defines the package identity, capability matrix, protocol, schema enforcement, self-validation, tarball, clean-install, prerelease, and registry synchronization gates. The trusted-publishing workflow repeats those checks against an exact Git release tag before publishing. Release-candidate metadata is not published to the MCP Registry; stable Registry publication follows successful npm and `npx` verification.
|
|
39
43
|
|
|
40
44
|
Concept ids use the stable `okf://okf-mcp/...` namespace. Internal relations target those stable ids, while `repo://` references connect durable concepts to their current implementation sources without turning source files into concepts.
|
|
41
45
|
|
|
@@ -32,3 +32,7 @@ Validation tools inspect bundles, projects, and candidate concepts without writi
|
|
|
32
32
|
Project mode exposes read-only candidate validation, path suggestion, and proposal inspection helpers. Proposal creation, acceptance, and rejection additionally require `--authoring`. Runtime calls to `load_remote_bundle` require `--allow-remote-tool`; configured remote bundles remain readable without that flag.
|
|
33
33
|
|
|
34
34
|
Every tool supplies a purpose-specific description, descriptions for all input parameters, and MCP annotations for read behavior, destructive behavior, idempotency, and external access. Tool discovery and direct invocation use the same capability checks, so a hidden tool also fails when called by name. Annotations remain hints to clients; server-side validation is authoritative.
|
|
35
|
+
|
|
36
|
+
Tool arguments are validated against the advertised schema without coercion. Unknown or disabled tools and malformed call envelopes are protocol errors. Once a known enabled tool receives a structurally valid call, expected validation, storage, network, read-only, and proposal-conflict failures are returned as tool results with `isError: true`. A validation operation that successfully reports invalid OKF remains a successful tool result.
|
|
37
|
+
|
|
38
|
+
`list_concepts` applies its optional text query together with its structured filters. Relation-type filtering selects concepts with an outgoing relation of the requested type.
|
|
@@ -21,8 +21,8 @@ relations:
|
|
|
21
21
|
|
|
22
22
|
`okf-mcp` turns directories of OKF Markdown concepts into a searchable in-memory knowledge graph. It provides a command-line interface, a JSON-RPC stdio MCP server, generator plugins, remote GitHub bundles, and an optional HTTP authoring API.
|
|
23
23
|
|
|
24
|
-
The
|
|
24
|
+
The runtime uses `js-yaml` for standards-oriented YAML parsing and has no database, embedding service, or build step. Local bundle mode performs no network calls. Project mode adds configuration, typed relations, proposal storage, and guarded writes to local bundle directories.
|
|
25
25
|
|
|
26
26
|
The primary runtime entry is the [MCP stdio server](../runtime/mcp-server.md). Concept interpretation and graph construction belong to the [indexer](../runtime/indexer.md). Durable knowledge changes follow the [concept authoring workflow](../workflows/concept-authoring.md) and [authoring safety policy](../policies/authoring-safety.md).
|
|
27
27
|
|
|
28
|
-
The HTTP server is an authoring API rather than a remotely hosted MCP transport. The canonical public architectural reference is this [published reference bundle](../distribution/reference-bundle.md).
|
|
28
|
+
The HTTP server is an authoring API rather than a remotely hosted MCP transport. The canonical public architectural reference is this [published reference bundle](../distribution/reference-bundle.md), shipped with the npm package and described for discovery by the MCP Registry metadata.
|
|
@@ -17,6 +17,8 @@ relations:
|
|
|
17
17
|
target: repo://test/okf-mcp.test.js
|
|
18
18
|
- type: checked_by
|
|
19
19
|
target: repo://test/conformance.test.js
|
|
20
|
+
- type: checked_by
|
|
21
|
+
target: repo://test/directory-links.test.js
|
|
20
22
|
---
|
|
21
23
|
|
|
22
24
|
# OKF Indexer
|
|
@@ -27,6 +29,8 @@ Both canonical ids and path-derived URIs resolve through the URI map. Graph oper
|
|
|
27
29
|
|
|
28
30
|
Markdown links become `markdown_link` edges. Frontmatter relations become typed `relation` edges. Internal targets are validated, while non-OKF schemes are recorded as external references.
|
|
29
31
|
|
|
32
|
+
Markdown targets resolve to an exact document first. When no exact document exists, a directory link resolves to that directory's reserved `index.md`. This rule is shared by local indexing, remote indexing, and authoring candidate validation, so the resulting edge uses the nested index document's canonical URI.
|
|
33
|
+
|
|
30
34
|
Validation is layered. OKF conformance checks parseable mapping frontmatter, a non-empty concept `type`, and the reserved structures of `index.md` and `log.md`. Unknown fields and unknown type values remain conformant. Project validity additionally covers missing roots, invalid paths, duplicate bundle ids, duplicate concept URIs, unsupported relation types, broken Markdown links, and broken internal targets.
|
|
31
35
|
|
|
32
36
|
Results expose `conformant`, `validForProject`, and structured diagnostics. `valid` is a compatibility alias for `validForProject`. Valid concepts continue to be served even when other files produce diagnostics.
|
|
@@ -13,6 +13,8 @@ relations:
|
|
|
13
13
|
target: okf://okf-mcp/workflows/concept-authoring
|
|
14
14
|
- type: configured_by
|
|
15
15
|
target: repo://src/mcp-server.js
|
|
16
|
+
- type: configured_by
|
|
17
|
+
target: repo://src/mcp-protocol.js
|
|
16
18
|
- type: checked_by
|
|
17
19
|
target: repo://test/okf-mcp.test.js
|
|
18
20
|
- type: checked_by
|
|
@@ -21,7 +23,11 @@ relations:
|
|
|
21
23
|
|
|
22
24
|
# MCP Stdio Server
|
|
23
25
|
|
|
24
|
-
The MCP server reads newline-delimited JSON-RPC messages from stdin and writes responses to stdout. It implements initialization, resource listing and reading, tool listing, and tool calls without an SDK dependency.
|
|
26
|
+
The MCP server reads newline-delimited JSON-RPC messages from stdin and writes responses to stdout. It implements initialization, ping, resource listing and reading, tool listing, and tool calls without an SDK dependency.
|
|
27
|
+
|
|
28
|
+
The server supports protocol versions `2025-11-25`, `2025-06-18`, `2025-03-26`, and `2024-11-05`. Initialization returns a requested supported version. A well-formed unsupported version negotiates to the preferred supported version, `2025-11-25`, so the client can decide whether to continue. Missing or malformed initialization parameters remain invalid.
|
|
29
|
+
|
|
30
|
+
The transport validates the JSON-RPC envelope before dispatch. Parse errors, invalid requests, unknown methods, invalid method parameters, missing resources, and internal failures use their corresponding protocol error classes. Valid notifications never receive responses, including notifications with unknown methods or failing handlers. Stdout is reserved for protocol messages.
|
|
25
31
|
|
|
26
32
|
Each indexed Markdown document is exposed as a `text/markdown` resource. The [MCP tool catalog](../interfaces/mcp-tools.md) exposes discovery, search, graph navigation, validation, remote loading, and proposal-based authoring.
|
|
27
33
|
|
|
@@ -25,7 +25,7 @@ The optional `id` field defines a stable `okf://` URI. Without it, the URI is de
|
|
|
25
25
|
|
|
26
26
|
Frontmatter is parsed as a YAML mapping with the safe core schema. Nested mappings, arrays, block scalars, and unknown extension keys are preserved. Duplicate mapping keys and unsupported custom tags are rejected. Unknown concept type values do not fail OKF conformance.
|
|
27
27
|
|
|
28
|
-
Files named `index.md` and `log.md` are reserved resources and are not concepts. Reserved indexes group local Markdown links under headings. Reserved logs use an H1 title followed by newest-first ISO-dated H2 sections containing list entries.
|
|
28
|
+
Files named `index.md` and `log.md` are reserved resources and are not concepts. Reserved indexes group local Markdown links under headings. A link to a bundle directory resolves to that directory's nested `index.md` when no exact document target exists. Reserved logs use an H1 title followed by newest-first ISO-dated H2 sections containing list entries.
|
|
29
29
|
|
|
30
30
|
Internal `okf://` relation targets and Markdown links are checked as project rules rather than redefining minimum document conformance. Other schemes such as `repo://` are retained as opaque external references.
|
|
31
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mfdaves/okf-mcp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-rc.1",
|
|
4
4
|
"description": "Local-first Open Knowledge Format validator, graph index, CLI, and MCP stdio server.",
|
|
5
5
|
"homepage": "https://github.com/mfdaves/okf-mcp#readme",
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/mfdaves/okf-mcp/issues"
|
|
12
12
|
},
|
|
13
|
+
"mcpName": "io.github.mfdaves/okf-mcp",
|
|
13
14
|
"type": "commonjs",
|
|
14
15
|
"main": "src/index.js",
|
|
15
16
|
"bin": {
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"src",
|
|
41
42
|
"okf",
|
|
42
43
|
"okf.project.yaml",
|
|
44
|
+
"server.json",
|
|
43
45
|
"README.md",
|
|
44
46
|
"LICENSE"
|
|
45
47
|
],
|
package/server.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.mfdaves/okf-mcp",
|
|
4
|
+
"title": "okf-mcp",
|
|
5
|
+
"description": "Validate, search, graph, and safely author local Open Knowledge Format bundles.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/mfdaves/okf-mcp",
|
|
8
|
+
"source": "github"
|
|
9
|
+
},
|
|
10
|
+
"websiteUrl": "https://github.com/mfdaves/okf-mcp#readme",
|
|
11
|
+
"version": "0.3.3-rc.1",
|
|
12
|
+
"packages": [
|
|
13
|
+
{
|
|
14
|
+
"registryType": "npm",
|
|
15
|
+
"identifier": "@mfdaves/okf-mcp",
|
|
16
|
+
"version": "0.3.3-rc.1",
|
|
17
|
+
"transport": {
|
|
18
|
+
"type": "stdio"
|
|
19
|
+
},
|
|
20
|
+
"packageArguments": [
|
|
21
|
+
{
|
|
22
|
+
"type": "named",
|
|
23
|
+
"name": "--project",
|
|
24
|
+
"description": "Absolute path to the OKF project configuration.",
|
|
25
|
+
"isRequired": true,
|
|
26
|
+
"format": "filepath",
|
|
27
|
+
"placeholder": "/absolute/path/to/okf.project.yaml"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "positional",
|
|
31
|
+
"value": "mcp"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
package/src/authoring.js
CHANGED
|
@@ -158,7 +158,7 @@ class ConceptAuthoringService {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
doc.links.forEach((link) => {
|
|
161
|
-
const resolved = resolveLinkPath(bundle, doc.path, link.href);
|
|
161
|
+
const resolved = resolveLinkPath(bundle, doc.path, link.href, index.byPathUri);
|
|
162
162
|
if (!resolved) {
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
@@ -166,7 +166,10 @@ class ConceptAuthoringService {
|
|
|
166
166
|
warnings.push({ code: "link_outside_root", bundle: bundleId, path: doc.path, href: link.href, message: "Markdown link resolves outside bundle root." });
|
|
167
167
|
return;
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
const targetPathUri = `okf://${bundleId}/${resolved.path}`;
|
|
170
|
+
const target = index.byPathUri && index.byPathUri.get(targetPathUri);
|
|
171
|
+
const targetExists = Boolean(target && target.pathUri === targetPathUri);
|
|
172
|
+
if (!targetExists && resolved.uri !== doc.uri && resolved.uri !== doc.pathUri) {
|
|
170
173
|
warnings.push({ code: "broken_link", bundle: bundleId, path: doc.path, href: link.href, target: resolved.path, message: "Markdown link target does not exist in bundle." });
|
|
171
174
|
}
|
|
172
175
|
});
|
package/src/indexer.js
CHANGED
|
@@ -126,27 +126,59 @@ function walkMarkdown(root) {
|
|
|
126
126
|
return out.sort();
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
function
|
|
129
|
+
function documentAtPath(documentsByPath, pathUri) {
|
|
130
|
+
if (!documentsByPath || typeof documentsByPath.get !== "function") {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const document = documentsByPath.get(pathUri);
|
|
134
|
+
return document && document.pathUri === pathUri ? document : null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function resolveIndexedLink(bundleId, resolved, href, documentsByPath) {
|
|
138
|
+
if (!documentsByPath || typeof documentsByPath.get !== "function") {
|
|
139
|
+
return resolved;
|
|
140
|
+
}
|
|
141
|
+
const directTarget = documentAtPath(documentsByPath, resolved.uri);
|
|
142
|
+
if (directTarget) {
|
|
143
|
+
return Object.assign({}, resolved, { uri: directTarget.uri });
|
|
144
|
+
}
|
|
145
|
+
const clean = String(href || "").split("#")[0];
|
|
146
|
+
if (!clean.endsWith("/") && path.posix.extname(resolved.path)) {
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
149
|
+
const indexPath = normalizeSlashes(path.posix.join(resolved.path, "index.md"));
|
|
150
|
+
const indexTarget = documentAtPath(documentsByPath, `okf://${bundleId}/${indexPath}`);
|
|
151
|
+
if (!indexTarget) {
|
|
152
|
+
return resolved;
|
|
153
|
+
}
|
|
154
|
+
return Object.assign({}, resolved, {
|
|
155
|
+
path: indexPath,
|
|
156
|
+
uri: indexTarget.uri,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function resolveLinkPath(bundle, fromPath, href, documentsByPath) {
|
|
130
161
|
const clean = String(href || "").split("#")[0];
|
|
131
162
|
if (!clean || clean.startsWith("http://") || clean.startsWith("https://") || clean.startsWith("mailto:")) {
|
|
132
163
|
return null;
|
|
133
164
|
}
|
|
134
165
|
if (bundle.remote) {
|
|
135
|
-
const
|
|
166
|
+
const normalizedPath = clean.startsWith("/")
|
|
136
167
|
? path.posix.normalize(clean.slice(1))
|
|
137
168
|
: path.posix.normalize(path.posix.join(path.posix.dirname(fromPath), clean));
|
|
138
|
-
|
|
169
|
+
const resolvedPath = normalizedPath === "." ? "" : normalizedPath.replace(/\/+$/g, "");
|
|
170
|
+
if (resolvedPath.startsWith("../") || resolvedPath === "..") {
|
|
139
171
|
return {
|
|
140
172
|
outsideRoot: true,
|
|
141
173
|
path: normalizeSlashes(clean),
|
|
142
174
|
uri: null,
|
|
143
175
|
};
|
|
144
176
|
}
|
|
145
|
-
return {
|
|
177
|
+
return resolveIndexedLink(bundle.id, {
|
|
146
178
|
outsideRoot: false,
|
|
147
179
|
path: resolvedPath,
|
|
148
180
|
uri: `okf://${bundle.id}/${resolvedPath}`,
|
|
149
|
-
};
|
|
181
|
+
}, clean, documentsByPath);
|
|
150
182
|
}
|
|
151
183
|
const base = clean.startsWith("/")
|
|
152
184
|
? path.join(bundle.root, clean.slice(1))
|
|
@@ -159,11 +191,11 @@ function resolveLinkPath(bundle, fromPath, href) {
|
|
|
159
191
|
uri: null,
|
|
160
192
|
};
|
|
161
193
|
}
|
|
162
|
-
return {
|
|
194
|
+
return resolveIndexedLink(bundle.id, {
|
|
163
195
|
outsideRoot: false,
|
|
164
196
|
path: relativePath,
|
|
165
197
|
uri: `okf://${bundle.id}/${relativePath}`,
|
|
166
|
-
};
|
|
198
|
+
}, clean, documentsByPath);
|
|
167
199
|
}
|
|
168
200
|
|
|
169
201
|
function relationFrom(value, doc) {
|
|
@@ -262,7 +294,11 @@ function buildIndex(bundleArgs, options) {
|
|
|
262
294
|
});
|
|
263
295
|
|
|
264
296
|
const byUri = new Map();
|
|
297
|
+
const byPathUri = new Map();
|
|
265
298
|
documents.forEach((doc) => {
|
|
299
|
+
if (!byPathUri.has(doc.pathUri)) {
|
|
300
|
+
byPathUri.set(doc.pathUri, doc);
|
|
301
|
+
}
|
|
266
302
|
if (byUri.has(doc.uri)) {
|
|
267
303
|
errors.push({ code: "duplicate_uri", uri: doc.uri, message: "Duplicate OKF URI." });
|
|
268
304
|
}
|
|
@@ -280,7 +316,7 @@ function buildIndex(bundleArgs, options) {
|
|
|
280
316
|
documents.forEach((doc) => {
|
|
281
317
|
const bundle = bundles.find((entry) => entry.id === doc.bundle);
|
|
282
318
|
doc.links.forEach((link) => {
|
|
283
|
-
const resolved = resolveLinkPath(bundle, doc.path, link.href);
|
|
319
|
+
const resolved = resolveLinkPath(bundle, doc.path, link.href, byPathUri);
|
|
284
320
|
if (!resolved) {
|
|
285
321
|
return;
|
|
286
322
|
}
|
|
@@ -294,7 +330,7 @@ function buildIndex(bundleArgs, options) {
|
|
|
294
330
|
});
|
|
295
331
|
return;
|
|
296
332
|
}
|
|
297
|
-
const target =
|
|
333
|
+
const target = documentAtPath(byPathUri, `okf://${doc.bundle}/${resolved.path}`);
|
|
298
334
|
const edge = {
|
|
299
335
|
source: doc.uri,
|
|
300
336
|
target: target ? target.uri : resolved.uri,
|
|
@@ -358,6 +394,7 @@ function buildIndex(bundleArgs, options) {
|
|
|
358
394
|
errors,
|
|
359
395
|
edges,
|
|
360
396
|
byUri,
|
|
397
|
+
byPathUri,
|
|
361
398
|
};
|
|
362
399
|
return attachValidation(index);
|
|
363
400
|
}
|