@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Catalog text is data, never instructions (plan B-6, S-3). Diagnostic and
|
|
4
|
+
// error messages never echo vocabulary a concept used but nobody declared
|
|
5
|
+
// (an undeclared relation type, a repeated computation parameter name): any
|
|
6
|
+
// such value, however identifier-like, could carry text meant for an agent.
|
|
7
|
+
// The messages are constant apart from the concept path and an ordinal, so
|
|
8
|
+
// an operator can find the entry; the value itself stays in the structured
|
|
9
|
+
// fields beside the message (relationType, field).
|
|
10
|
+
|
|
11
|
+
function undeclaredRelationTypeMessage(conceptPath, position) {
|
|
12
|
+
return `Relation #${position + 1} of ${conceptPath} uses an undeclared type.`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function repeatedParameterMessage(conceptPath, position) {
|
|
16
|
+
return `Computation parameter #${position + 1} of ${conceptPath || "this concept"} repeats an earlier name.`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { repeatedParameterMessage, undeclaredRelationTypeMessage };
|
package/src/cli.js
CHANGED
|
@@ -5,7 +5,6 @@ const fs = require("fs");
|
|
|
5
5
|
const {
|
|
6
6
|
attachProject,
|
|
7
7
|
buildIndex,
|
|
8
|
-
buildProjectIndexAsync,
|
|
9
8
|
loadProjectBundles,
|
|
10
9
|
resolveConcept,
|
|
11
10
|
validateIndex,
|
|
@@ -14,6 +13,11 @@ const { exportGraph, findPaths, getNeighbors, graphSummary } = require("./graph"
|
|
|
14
13
|
const { searchConcepts } = require("./search");
|
|
15
14
|
const { conceptSummary } = require("./indexer");
|
|
16
15
|
const { findOkfRoot, findProjectConfig, loadProjectConfig } = require("./project");
|
|
16
|
+
const { normalizeLanguages } = require("./search/languages");
|
|
17
|
+
const { loadWritePolicyFile } = require("./policy/write-policy");
|
|
18
|
+
const embeddingCli = require("./search/embedding-cli");
|
|
19
|
+
const { createSearchOptions, withSearchLanguages } = require("./search/cli-options");
|
|
20
|
+
const contextCli = require("./context/cli-options");
|
|
17
21
|
const { generateProject } = require("./plugins");
|
|
18
22
|
const { ProducerService, producerReceipt } = require("./producers");
|
|
19
23
|
const { FileConceptStore } = require("./store");
|
|
@@ -33,8 +37,23 @@ const { validActor } = require("./v02");
|
|
|
33
37
|
const packageMetadata = require("../package.json");
|
|
34
38
|
|
|
35
39
|
const COMMANDS = new Set([
|
|
36
|
-
"mcp",
|
|
37
|
-
"
|
|
40
|
+
"mcp",
|
|
41
|
+
"validate",
|
|
42
|
+
"graph",
|
|
43
|
+
"search",
|
|
44
|
+
"context",
|
|
45
|
+
"concept",
|
|
46
|
+
"neighbors",
|
|
47
|
+
"paths",
|
|
48
|
+
"generate",
|
|
49
|
+
"serve",
|
|
50
|
+
"provenance",
|
|
51
|
+
"edge-kinds",
|
|
52
|
+
"computation",
|
|
53
|
+
"asset",
|
|
54
|
+
"source",
|
|
55
|
+
"migrate",
|
|
56
|
+
"producer",
|
|
38
57
|
]);
|
|
39
58
|
const PRODUCER_ACTIONS = new Set(["list", "preview", "run"]);
|
|
40
59
|
const WRITE_COMMANDS = new Set(["mcp", "producer"]);
|
|
@@ -97,9 +116,11 @@ function parseArgs(argv) {
|
|
|
97
116
|
let authoring = false;
|
|
98
117
|
let write = false;
|
|
99
118
|
let actor = "";
|
|
119
|
+
let policy = "";
|
|
100
120
|
let gitCommit = false;
|
|
101
121
|
let allowRemoteTool = false;
|
|
102
122
|
let strictLinks = false;
|
|
123
|
+
let languages = "";
|
|
103
124
|
let allowComputationAuthoring = false;
|
|
104
125
|
let includeAssets = false;
|
|
105
126
|
let includeExternal = false;
|
|
@@ -107,14 +128,7 @@ function parseArgs(argv) {
|
|
|
107
128
|
let receiptFile = "";
|
|
108
129
|
let maxContentBytes = 65536;
|
|
109
130
|
const generatedPaths = [];
|
|
110
|
-
const search =
|
|
111
|
-
types: [],
|
|
112
|
-
tagsAny: [],
|
|
113
|
-
statuses: [],
|
|
114
|
-
trustTiers: [],
|
|
115
|
-
freshness: [],
|
|
116
|
-
frontmatter: {},
|
|
117
|
-
};
|
|
131
|
+
const search = createSearchOptions();
|
|
118
132
|
for (let index = 0; index < argv.length; index += 1) {
|
|
119
133
|
const arg = argv[index];
|
|
120
134
|
if (arg === "--root" || arg === "-r") {
|
|
@@ -238,6 +252,16 @@ function parseArgs(argv) {
|
|
|
238
252
|
gitCommit = true;
|
|
239
253
|
continue;
|
|
240
254
|
}
|
|
255
|
+
if (arg === "--policy" || arg.startsWith("--policy=")) {
|
|
256
|
+
const inline = arg.startsWith("--policy=");
|
|
257
|
+
const value = inline ? arg.slice("--policy=".length) : argv[index + 1];
|
|
258
|
+
if (policy) throw usageError("--policy may be supplied only once.");
|
|
259
|
+
if (!value || (!inline && value.startsWith("-")))
|
|
260
|
+
throw usageError("--policy requires a value.");
|
|
261
|
+
policy = value;
|
|
262
|
+
index += inline ? 0 : 1;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
241
265
|
if (arg === "--allow-remote-tool") {
|
|
242
266
|
allowRemoteTool = true;
|
|
243
267
|
continue;
|
|
@@ -250,6 +274,19 @@ function parseArgs(argv) {
|
|
|
250
274
|
strictLinks = true;
|
|
251
275
|
continue;
|
|
252
276
|
}
|
|
277
|
+
if (arg === "--languages") {
|
|
278
|
+
if (!argv[index + 1] || String(argv[index + 1]).startsWith("-")) {
|
|
279
|
+
throw usageError("--languages requires auto, none, or language codes such as it,en.");
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
normalizeLanguages(argv[index + 1]);
|
|
283
|
+
} catch (error) {
|
|
284
|
+
throw usageError(`--languages: ${error.message}`);
|
|
285
|
+
}
|
|
286
|
+
languages = argv[index + 1];
|
|
287
|
+
index += 1;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
253
290
|
if (arg === "--include-assets") {
|
|
254
291
|
includeAssets = true;
|
|
255
292
|
continue;
|
|
@@ -288,57 +325,9 @@ function parseArgs(argv) {
|
|
|
288
325
|
index += 1;
|
|
289
326
|
continue;
|
|
290
327
|
}
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
"--status": "statuses",
|
|
295
|
-
"--trust-tier": "trustTiers",
|
|
296
|
-
"--freshness": "freshness",
|
|
297
|
-
};
|
|
298
|
-
if (Object.prototype.hasOwnProperty.call(searchValueOptions, arg)) {
|
|
299
|
-
if (!argv[index + 1] || String(argv[index + 1]).startsWith("-")) {
|
|
300
|
-
throw usageError(`${arg} requires a value.`);
|
|
301
|
-
}
|
|
302
|
-
search[searchValueOptions[arg]].push(argv[index + 1]);
|
|
303
|
-
index += 1;
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
const scalarSearchOptions = {
|
|
307
|
-
"--as-of": "asOf",
|
|
308
|
-
"--runtime": "runtime",
|
|
309
|
-
"--linked-to": "linkedTo",
|
|
310
|
-
"--linked-from": "linkedFrom",
|
|
311
|
-
"--relation-type": "relationType",
|
|
312
|
-
"--path-prefix": "pathPrefix",
|
|
313
|
-
};
|
|
314
|
-
if (Object.prototype.hasOwnProperty.call(scalarSearchOptions, arg)) {
|
|
315
|
-
if (!argv[index + 1] || String(argv[index + 1]).startsWith("-")) {
|
|
316
|
-
throw usageError(`${arg} requires a value.`);
|
|
317
|
-
}
|
|
318
|
-
search[scalarSearchOptions[arg]] = argv[index + 1];
|
|
319
|
-
index += 1;
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
if (arg === "--frontmatter") {
|
|
323
|
-
const value = argv[index + 1];
|
|
324
|
-
const separator = value && value.indexOf("=");
|
|
325
|
-
if (!value || separator <= 0) {
|
|
326
|
-
throw usageError("--frontmatter requires key=value.");
|
|
327
|
-
}
|
|
328
|
-
search.frontmatter[value.slice(0, separator)] = value.slice(separator + 1);
|
|
329
|
-
index += 1;
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (arg === "--has-sources" || arg === "--no-sources") {
|
|
333
|
-
search.hasSources = arg === "--has-sources";
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
if (arg === "--attestation-ready") {
|
|
337
|
-
search.attestationReady = true;
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
if (arg === "--orphan-only") {
|
|
341
|
-
search.orphanOnly = true;
|
|
328
|
+
const consumed = contextCli.parseCommandOption(arg, argv, index, search, usageError);
|
|
329
|
+
if (consumed >= 0) {
|
|
330
|
+
index += consumed;
|
|
342
331
|
continue;
|
|
343
332
|
}
|
|
344
333
|
if (arg === "--host") {
|
|
@@ -411,15 +400,18 @@ function parseArgs(argv) {
|
|
|
411
400
|
if (write && !actor) {
|
|
412
401
|
throw usageError("--write requires --actor <human:id|process:id|provider/model>.");
|
|
413
402
|
}
|
|
414
|
-
if (
|
|
403
|
+
if (actor && !validActor(actor)) {
|
|
415
404
|
throw usageError("--actor must use human:<id>, process:<id>, or provider/model syntax.");
|
|
416
405
|
}
|
|
417
|
-
if (actor && !write) {
|
|
418
|
-
throw usageError("--actor requires --write.");
|
|
406
|
+
if (actor && !write && !authoring) {
|
|
407
|
+
throw usageError("--actor requires --write or --authoring.");
|
|
419
408
|
}
|
|
420
409
|
if (gitCommit && !write) {
|
|
421
410
|
throw usageError("--git-commit requires --write.");
|
|
422
411
|
}
|
|
412
|
+
if (policy && !write && !authoring) {
|
|
413
|
+
throw usageError("--policy requires --write or --authoring.");
|
|
414
|
+
}
|
|
423
415
|
return {
|
|
424
416
|
bundles,
|
|
425
417
|
remoteBundles,
|
|
@@ -433,10 +425,12 @@ function parseArgs(argv) {
|
|
|
433
425
|
authoring,
|
|
434
426
|
write,
|
|
435
427
|
actor,
|
|
428
|
+
policy,
|
|
436
429
|
gitCommit,
|
|
437
430
|
allowRemoteTool,
|
|
438
431
|
allowComputationAuthoring,
|
|
439
432
|
strictLinks,
|
|
433
|
+
languages,
|
|
440
434
|
includeAssets,
|
|
441
435
|
includeExternal,
|
|
442
436
|
parametersFile,
|
|
@@ -471,6 +465,7 @@ function usage() {
|
|
|
471
465
|
" validate Validate project or bundles.",
|
|
472
466
|
" graph [json|dot|mermaid] Export graph.",
|
|
473
467
|
" search <query> Search concepts.",
|
|
468
|
+
" context <query> Budgeted sections; search filters, --budget, --limit, --provenance.",
|
|
474
469
|
" concept <id-or-locator> Print one concept.",
|
|
475
470
|
" neighbors <id-or-locator> Print inbound/outbound neighbors.",
|
|
476
471
|
" paths <from> <to> Find directed paths between concept locators.",
|
|
@@ -494,11 +489,14 @@ function usage() {
|
|
|
494
489
|
" --repo <concept-id=path> Map a Git Repository concept to a checkout or bare repo; repeatable.",
|
|
495
490
|
" --authoring Enable MCP proposal authoring tools.",
|
|
496
491
|
" --write Enable direct validated-batch MCP concept writes (requires --actor).",
|
|
497
|
-
" --actor <actor> Stamp live writes and producer runs with human:id, process:id, or provider/model.",
|
|
492
|
+
" --actor <actor> Stamp live writes, proposals, and producer runs with human:id, process:id, or provider/model.",
|
|
498
493
|
" --git-commit Commit each live write batch when the catalog is in a clean Git repo.",
|
|
494
|
+
" --policy <file> Write policy (YAML) for --root writes and proposals; a project declares writePolicy in okf.project.yaml.",
|
|
499
495
|
" --allow-remote-tool Enable runtime remote-bundle loading over MCP.",
|
|
500
496
|
" --allow-computation-authoring Enable coordinated computation proposals (also requires --authoring).",
|
|
501
497
|
" --strict-links Treat broken internal Markdown links as project-invalid.",
|
|
498
|
+
" --languages <codes> Search stemming languages for --root/--bundle mode: auto (default, detected per bundle), none, or codes such as it,en.",
|
|
499
|
+
embeddingCli.EMBEDDING_USAGE,
|
|
502
500
|
" --include-assets Include referenced asset nodes where supported.",
|
|
503
501
|
" --include-external Include external provenance or graph leaves.",
|
|
504
502
|
" --generated-path <path> Mark a generated migration target; repeat as needed.",
|
|
@@ -506,8 +504,10 @@ function usage() {
|
|
|
506
504
|
" --receipt-file <path|-> Read a computation receipt from a file or stdin.",
|
|
507
505
|
" --max-content-bytes <n> Bound asset reads to 1..1048576 bytes (default 65536).",
|
|
508
506
|
" Search filters: --status, --trust-tier, --freshness, --as-of, --has-sources,",
|
|
509
|
-
" --runtime, --attestation-ready, --frontmatter key=value
|
|
510
|
-
"
|
|
507
|
+
" --runtime, --attestation-ready, --frontmatter key=value,",
|
|
508
|
+
" --mode auto|all|any, --min-coverage <0..1>, --min-relevance <0..1>, --freshness-prior.",
|
|
509
|
+
" Text search matches every term and falls back to any term (mode auto); it accepts at most",
|
|
510
|
+
" 512 characters and 16 terms after stop words, and reports mode, coverage, and lowConfidence.",
|
|
511
511
|
" --version, -v Print the package version.",
|
|
512
512
|
" --help, -h Print this help.",
|
|
513
513
|
" --debug Include stack traces in error output.",
|
|
@@ -544,7 +544,8 @@ function parseRepositoryMappings(values) {
|
|
|
544
544
|
(values || []).forEach((value) => {
|
|
545
545
|
const text = String(value || "");
|
|
546
546
|
const separator = text.indexOf("=");
|
|
547
|
-
const conceptId =
|
|
547
|
+
const conceptId =
|
|
548
|
+
separator > 0 ? text.slice(0, separator).replace(/^\/+/, "").replace(/\.md$/i, "") : "";
|
|
548
549
|
const repositoryPath = separator > 0 ? text.slice(separator + 1) : "";
|
|
549
550
|
if (!conceptId || !repositoryPath) {
|
|
550
551
|
throw usageError("--repo requires repository-concept-id=checkout-or-bare-repository-path.");
|
|
@@ -571,7 +572,13 @@ function parseRemoteBundleArg(value, index) {
|
|
|
571
572
|
}
|
|
572
573
|
|
|
573
574
|
function discoverProject(args, startDir) {
|
|
574
|
-
if (
|
|
575
|
+
if (
|
|
576
|
+
!args.project &&
|
|
577
|
+
!args.root &&
|
|
578
|
+
!args.bundles.length &&
|
|
579
|
+
!args.remoteBundles.length &&
|
|
580
|
+
!resolveLegacyBundles(args).length
|
|
581
|
+
) {
|
|
575
582
|
args.root = findOkfRoot(startDir);
|
|
576
583
|
if (!args.root) {
|
|
577
584
|
args.project = findProjectConfig(startDir);
|
|
@@ -580,6 +587,14 @@ function discoverProject(args, startDir) {
|
|
|
580
587
|
return args;
|
|
581
588
|
}
|
|
582
589
|
|
|
590
|
+
// --policy: the --root counterpart of writePolicy, for stdio and HTTP alike.
|
|
591
|
+
function writePolicyOption(args) {
|
|
592
|
+
if (args.policy && !args.root) {
|
|
593
|
+
throw usageError("--policy requires --root; declare writePolicy in okf.project.yaml instead.");
|
|
594
|
+
}
|
|
595
|
+
return args.policy ? loadWritePolicyFile(args.policy) : undefined;
|
|
596
|
+
}
|
|
597
|
+
|
|
583
598
|
function stdioServerOptions(args) {
|
|
584
599
|
const repositoryMappings = parseRepositoryMappings(args.repositories);
|
|
585
600
|
const options = {
|
|
@@ -587,25 +602,20 @@ function stdioServerOptions(args) {
|
|
|
587
602
|
allowAuthoring: Boolean(args.authoring),
|
|
588
603
|
allowRuntimeRemoteLoad: Boolean(args.allowRemoteTool),
|
|
589
604
|
};
|
|
590
|
-
if (repositoryMappings.size)
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (args.authoring && args.allowComputationAuthoring) {
|
|
594
|
-
options.allowComputationAuthoring = true;
|
|
595
|
-
}
|
|
605
|
+
if (repositoryMappings.size) options.repositoryMappings = repositoryMappings;
|
|
606
|
+
if (args.authoring && args.allowComputationAuthoring) options.allowComputationAuthoring = true;
|
|
607
|
+
if (args.actor) options.actor = args.actor;
|
|
596
608
|
if (args.write) {
|
|
597
609
|
options.allowWrite = true;
|
|
598
|
-
options.actor = args.actor;
|
|
599
610
|
if (args.gitCommit) {
|
|
600
611
|
options.gitCommit = true;
|
|
601
612
|
}
|
|
602
613
|
}
|
|
603
|
-
if (args.strictLinks)
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
614
|
+
if (args.strictLinks) options.strictLinks = true;
|
|
615
|
+
if (args.policy) options.writePolicy = writePolicyOption(args);
|
|
616
|
+
if (args.languages) options.languages = args.languages;
|
|
617
|
+
Object.assign(options, embeddingCli.embeddingServerOptions(args));
|
|
618
|
+
if (args.proposalRoot) options.proposalRoot = args.proposalRoot;
|
|
609
619
|
if (args.project) {
|
|
610
620
|
options.projectPath = args.project;
|
|
611
621
|
} else if (args.root) {
|
|
@@ -617,26 +627,29 @@ function stdioServerOptions(args) {
|
|
|
617
627
|
async function loadIndex(args) {
|
|
618
628
|
const remoteConfigs = args.remoteBundles.map(parseRemoteBundleArg);
|
|
619
629
|
if (args.project) {
|
|
620
|
-
if (!remoteConfigs.length) {
|
|
621
|
-
return buildProjectIndexAsync(args.project, { strictLinks: args.strictLinks || undefined });
|
|
622
|
-
}
|
|
623
630
|
const loaded = await loadProjectBundles(args.project);
|
|
624
631
|
const remoteBundles = await fetchRemoteBundles(remoteConfigs);
|
|
625
632
|
const index = buildIndex(loaded.bundles.concat(remoteBundles), {
|
|
626
633
|
relationTypes: loaded.project.relationTypes,
|
|
627
634
|
strictLinks: args.strictLinks || loaded.project.strictLinks,
|
|
628
635
|
});
|
|
629
|
-
return
|
|
636
|
+
return withSearchLanguages(
|
|
637
|
+
attachProject(index, loaded.project),
|
|
638
|
+
args.languages || loaded.project.languages,
|
|
639
|
+
);
|
|
630
640
|
}
|
|
631
641
|
const bundles = resolveLegacyBundles(args);
|
|
632
642
|
const fetchedRemoteBundles = await fetchRemoteBundles(remoteConfigs);
|
|
633
643
|
if (!bundles.length && !fetchedRemoteBundles.length) {
|
|
634
644
|
throw usageError("At least one --bundle root or --project config is required.");
|
|
635
645
|
}
|
|
636
|
-
return
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
646
|
+
return withSearchLanguages(
|
|
647
|
+
buildIndex(bundles.concat(fetchedRemoteBundles), {
|
|
648
|
+
strictLinks: args.strictLinks,
|
|
649
|
+
allowCustomRelationTypes: true,
|
|
650
|
+
}),
|
|
651
|
+
args.languages,
|
|
652
|
+
);
|
|
640
653
|
}
|
|
641
654
|
|
|
642
655
|
function printJson(value) {
|
|
@@ -655,7 +668,8 @@ function requireValidConcept(index, locator) {
|
|
|
655
668
|
}
|
|
656
669
|
|
|
657
670
|
async function main(argv, runtime) {
|
|
658
|
-
const
|
|
671
|
+
const split = embeddingCli.splitEmbeddingArgs(argv || []);
|
|
672
|
+
const args = Object.assign(parseArgs(split.argv), { embedding: split.embedding });
|
|
659
673
|
if (args.help) {
|
|
660
674
|
process.stdout.write(usage());
|
|
661
675
|
return;
|
|
@@ -677,11 +691,16 @@ async function main(argv, runtime) {
|
|
|
677
691
|
throw usageError(`Unknown OKF command: ${command}`);
|
|
678
692
|
}
|
|
679
693
|
if (!WRITE_COMMANDS.has(command) && (args.write || args.actor || args.gitCommit)) {
|
|
680
|
-
throw usageError(
|
|
694
|
+
throw usageError(
|
|
695
|
+
"--write, --actor, and --git-commit are available only with the mcp and producer commands.",
|
|
696
|
+
);
|
|
681
697
|
}
|
|
682
698
|
if (command === "producer" && args.gitCommit) {
|
|
683
699
|
throw usageError("--git-commit is available only with the mcp command.");
|
|
684
700
|
}
|
|
701
|
+
if (command === "producer" && args.policy) {
|
|
702
|
+
throw usageError("--policy is available only with the mcp command.");
|
|
703
|
+
}
|
|
685
704
|
if (command === "mcp") {
|
|
686
705
|
const bundles = resolveLegacyBundles(args);
|
|
687
706
|
if (args.project) {
|
|
@@ -708,13 +727,14 @@ async function main(argv, runtime) {
|
|
|
708
727
|
if (!args.project && !args.root) {
|
|
709
728
|
throw usageError("serve requires --root or --project.");
|
|
710
729
|
}
|
|
711
|
-
const result = await runHttpServer({
|
|
730
|
+
const result = await (runtime?.runHttpServer || runHttpServer)({
|
|
712
731
|
projectPath: args.project,
|
|
713
732
|
rootPath: args.root,
|
|
714
733
|
host: args.host,
|
|
715
734
|
port: args.port,
|
|
716
735
|
writeToken: args.writeToken || process.env.OKF_WRITE_TOKEN || "",
|
|
717
736
|
proposalRoot: args.proposalRoot || "",
|
|
737
|
+
writePolicy: writePolicyOption(args),
|
|
718
738
|
});
|
|
719
739
|
process.stderr.write(`OKF HTTP server listening on ${result.url}\n`);
|
|
720
740
|
return;
|
|
@@ -750,7 +770,9 @@ async function main(argv, runtime) {
|
|
|
750
770
|
throw usageError(`producer ${action} requires a configured producer name.`);
|
|
751
771
|
}
|
|
752
772
|
if (action === "run" && !args.write) {
|
|
753
|
-
throw usageError(
|
|
773
|
+
throw usageError(
|
|
774
|
+
"producer run requires --write --actor <human:id|process:id|provider/model>.",
|
|
775
|
+
);
|
|
754
776
|
}
|
|
755
777
|
const receipt = action === "run" ? await service.run(name) : await service.preview(name);
|
|
756
778
|
printJson(producerReceipt(receipt, "full"));
|
|
@@ -767,11 +789,13 @@ async function main(argv, runtime) {
|
|
|
767
789
|
return;
|
|
768
790
|
}
|
|
769
791
|
if (command === "graph") {
|
|
770
|
-
process.stdout.write(
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
792
|
+
process.stdout.write(
|
|
793
|
+
exportGraph(index, {
|
|
794
|
+
format: args.positional[1] || "json",
|
|
795
|
+
includeExternal: args.includeExternal,
|
|
796
|
+
includeAssets: args.includeAssets,
|
|
797
|
+
}) + "\n",
|
|
798
|
+
);
|
|
775
799
|
return;
|
|
776
800
|
}
|
|
777
801
|
if (command === "search") {
|
|
@@ -782,28 +806,33 @@ async function main(argv, runtime) {
|
|
|
782
806
|
printJson(searchConcepts(index, filters));
|
|
783
807
|
return;
|
|
784
808
|
}
|
|
809
|
+
if (command === "context") return printJson(contextCli.runContext(index, args, usageError));
|
|
785
810
|
if (command === "concept") {
|
|
786
811
|
const locator = args.positional[1];
|
|
787
812
|
if (!locator) {
|
|
788
813
|
throw usageError("concept requires a Concept ID or locator.");
|
|
789
814
|
}
|
|
790
815
|
const doc = requireValidConcept(index, locator);
|
|
791
|
-
printJson(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
(
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
816
|
+
printJson(
|
|
817
|
+
Object.assign(conceptSummary(doc), {
|
|
818
|
+
frontmatter: doc.frontmatter,
|
|
819
|
+
body: doc.body,
|
|
820
|
+
links: doc.links,
|
|
821
|
+
referencedAssets: (index.assets || [])
|
|
822
|
+
.filter((asset) =>
|
|
823
|
+
(asset.referencedBy || []).some((reference) => reference.uri === doc.uri),
|
|
824
|
+
)
|
|
825
|
+
.map((asset) => ({
|
|
826
|
+
uri: asset.uri,
|
|
827
|
+
path: asset.path,
|
|
828
|
+
mimeType: asset.mimeType,
|
|
829
|
+
size: asset.size,
|
|
830
|
+
sha256: asset.sha256,
|
|
831
|
+
roles: asset.roles,
|
|
832
|
+
})),
|
|
833
|
+
gitSources: describeConceptGitSources(index, doc, repositoryMappings),
|
|
834
|
+
}),
|
|
835
|
+
);
|
|
807
836
|
return;
|
|
808
837
|
}
|
|
809
838
|
if (command === "neighbors") {
|
|
@@ -811,10 +840,12 @@ async function main(argv, runtime) {
|
|
|
811
840
|
throw usageError("neighbors requires a URI.");
|
|
812
841
|
}
|
|
813
842
|
const doc = requireValidConcept(index, args.positional[1]);
|
|
814
|
-
printJson(
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
843
|
+
printJson(
|
|
844
|
+
getNeighbors(index, doc.uri, {
|
|
845
|
+
includeAssets: args.includeAssets,
|
|
846
|
+
includeExternal: args.includeExternal,
|
|
847
|
+
}),
|
|
848
|
+
);
|
|
818
849
|
return;
|
|
819
850
|
}
|
|
820
851
|
if (command === "paths") {
|
|
@@ -857,7 +888,9 @@ async function main(argv, runtime) {
|
|
|
857
888
|
}
|
|
858
889
|
if (operation === "prepare") {
|
|
859
890
|
if (args.positional[3]) {
|
|
860
|
-
throw usageError(
|
|
891
|
+
throw usageError(
|
|
892
|
+
"Raw computation parameters are not accepted in argv; use --parameters-file <path|->.",
|
|
893
|
+
);
|
|
861
894
|
}
|
|
862
895
|
const parameters = args.parametersFile
|
|
863
896
|
? readJsonObjectSource(args.parametersFile, "computation parameters", runtime)
|
|
@@ -865,17 +898,14 @@ async function main(argv, runtime) {
|
|
|
865
898
|
if (!parameters) {
|
|
866
899
|
throw usageError("computation prepare requires --parameters-file <path|->.");
|
|
867
900
|
}
|
|
868
|
-
printJson(prepareAttestedComputation(
|
|
869
|
-
index,
|
|
870
|
-
uri,
|
|
871
|
-
parameters,
|
|
872
|
-
{ asOf: args.search.asOf },
|
|
873
|
-
));
|
|
901
|
+
printJson(prepareAttestedComputation(index, uri, parameters, { asOf: args.search.asOf }));
|
|
874
902
|
return;
|
|
875
903
|
}
|
|
876
904
|
if (operation === "check-receipt") {
|
|
877
905
|
if (args.positional[3]) {
|
|
878
|
-
throw usageError(
|
|
906
|
+
throw usageError(
|
|
907
|
+
"Raw computation receipts are not accepted in argv; use --receipt-file <path|->.",
|
|
908
|
+
);
|
|
879
909
|
}
|
|
880
910
|
const receipt = args.receiptFile
|
|
881
911
|
? readJsonObjectSource(args.receiptFile, "computation receipt", runtime)
|
|
@@ -883,11 +913,7 @@ async function main(argv, runtime) {
|
|
|
883
913
|
if (!receipt) {
|
|
884
914
|
throw usageError("computation check-receipt requires --receipt-file <path|->.");
|
|
885
915
|
}
|
|
886
|
-
printJson(checkComputationReceipt(
|
|
887
|
-
index,
|
|
888
|
-
uri,
|
|
889
|
-
receipt,
|
|
890
|
-
));
|
|
916
|
+
printJson(checkComputationReceipt(index, uri, receipt));
|
|
891
917
|
return;
|
|
892
918
|
}
|
|
893
919
|
throw usageError(`Unknown computation operation: ${operation}`);
|
|
@@ -896,23 +922,23 @@ async function main(argv, runtime) {
|
|
|
896
922
|
if (!args.positional[1]) {
|
|
897
923
|
throw usageError("asset requires an okf-asset URI.");
|
|
898
924
|
}
|
|
899
|
-
printJson(
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
925
|
+
printJson(
|
|
926
|
+
readBundleAsset(index, {
|
|
927
|
+
uri: args.positional[1],
|
|
928
|
+
maxContentBytes: args.maxContentBytes,
|
|
929
|
+
}),
|
|
930
|
+
);
|
|
903
931
|
return;
|
|
904
932
|
}
|
|
905
933
|
if (command === "source") {
|
|
906
934
|
if (!args.positional[1] || !args.positional[2]) {
|
|
907
935
|
throw usageError("source requires <concept-id-or-locator> and <source-id>.");
|
|
908
936
|
}
|
|
909
|
-
printJson(
|
|
910
|
-
index,
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
{ maxBytes: args.maxContentBytes },
|
|
915
|
-
));
|
|
937
|
+
printJson(
|
|
938
|
+
readConceptGitSource(index, args.positional[1], args.positional[2], repositoryMappings, {
|
|
939
|
+
maxBytes: args.maxContentBytes,
|
|
940
|
+
}),
|
|
941
|
+
);
|
|
916
942
|
return;
|
|
917
943
|
}
|
|
918
944
|
if (command === "migrate") {
|
|
@@ -922,10 +948,12 @@ async function main(argv, runtime) {
|
|
|
922
948
|
}
|
|
923
949
|
let bundleArgument = args.positional[2] || "";
|
|
924
950
|
let actorMappingsArgument = args.positional[3] || "";
|
|
925
|
-
if (
|
|
926
|
-
|
|
927
|
-
&&
|
|
928
|
-
&&
|
|
951
|
+
if (
|
|
952
|
+
operation === "preview" &&
|
|
953
|
+
index.bundles.length === 1 &&
|
|
954
|
+
!actorMappingsArgument &&
|
|
955
|
+
bundleArgument.trim().startsWith("{")
|
|
956
|
+
) {
|
|
929
957
|
actorMappingsArgument = bundleArgument;
|
|
930
958
|
bundleArgument = "";
|
|
931
959
|
}
|
|
@@ -939,9 +967,14 @@ async function main(argv, runtime) {
|
|
|
939
967
|
const actorMappings = actorMappingsArgument
|
|
940
968
|
? parseJsonObject(actorMappingsArgument, "actor mappings")
|
|
941
969
|
: {};
|
|
942
|
-
const result =
|
|
943
|
-
|
|
944
|
-
|
|
970
|
+
const result =
|
|
971
|
+
operation === "check"
|
|
972
|
+
? checkV02Migration(index, { bundle, actorMappings, generatedPaths: args.generatedPaths })
|
|
973
|
+
: buildV02MigrationPlan(index, {
|
|
974
|
+
bundle,
|
|
975
|
+
actorMappings,
|
|
976
|
+
generatedPaths: args.generatedPaths,
|
|
977
|
+
});
|
|
945
978
|
printJson(result);
|
|
946
979
|
const report = operation === "check" ? result : result.report;
|
|
947
980
|
process.exitCode = report.blockers.length ? 1 : 0;
|