@mfdaves/okf-mcp 0.9.1 → 0.13.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 +100 -0
- package/README.md +452 -26
- package/bin/okf-mcp.js +6 -1
- package/okf/okf-mcp/distribution/reference-bundle.md +10 -3
- package/okf/okf-mcp/index.md +2 -1
- package/okf/okf-mcp/interfaces/http-authoring-api.md +11 -2
- package/okf/okf-mcp/interfaces/mcp-http.md +64 -0
- package/okf/okf-mcp/interfaces/mcp-tools.md +25 -6
- package/okf/okf-mcp/overview/okf-mcp.md +16 -6
- package/okf/okf-mcp/policies/authoring-safety.md +28 -5
- package/okf/okf-mcp/runtime/indexer.md +14 -1
- package/okf/okf-mcp/runtime/mcp-server.md +16 -8
- package/okf/okf-mcp/specs/producer-api.md +16 -2
- package/package.json +17 -5
- package/server.json +38 -2
- package/src/assets.js +165 -73
- package/src/authoring/candidates.js +434 -0
- package/src/authoring/git-preflight.js +225 -0
- package/src/authoring/git-publish.js +783 -0
- package/src/authoring/live.js +757 -0
- package/src/authoring/paths.js +112 -0
- package/src/authoring/policy-hook.js +221 -0
- package/src/authoring/proposal-policy.js +159 -0
- package/src/authoring/receipts.js +373 -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/commands.js +448 -0
- package/src/cli/http-options.js +193 -0
- package/src/cli/options.js +554 -0
- package/src/cli/usage.js +96 -0
- package/src/cli.js +18 -932
- 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/error-details.js +53 -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/auth.js +409 -0
- package/src/mcp/http.js +317 -0
- package/src/mcp/principal.js +59 -0
- package/src/mcp/registry.js +356 -0
- package/src/mcp/resources.js +45 -0
- package/src/mcp/server.js +567 -0
- package/src/mcp/tools/catalog.js +247 -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 +225 -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 +202 -78
- package/src/producers.js +311 -103
- package/src/project.js +346 -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/tool-packs.js +346 -0
- package/src/v02.js +301 -105
- package/src/validation.js +24 -20
package/src/project.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
5
|
const { parseFrontmatterYaml, splitFrontmatter } = require("./parser");
|
|
6
|
+
const { normalizeLanguages } = require("./search/languages");
|
|
7
|
+
const { parseWritePolicy } = require("./policy/write-policy");
|
|
8
|
+
const { normalizeEmbeddingConfig } = require("./search/embedding-config");
|
|
6
9
|
|
|
7
10
|
const DEFAULT_RELATION_TYPES = [
|
|
8
11
|
"depends_on",
|
|
@@ -106,8 +109,7 @@ function findOkfRoot(startDir) {
|
|
|
106
109
|
if (fs.existsSync(indexPath) && fs.statSync(indexPath).isFile()) {
|
|
107
110
|
try {
|
|
108
111
|
const split = splitFrontmatter(fs.readFileSync(indexPath, "utf8"));
|
|
109
|
-
if (split.frontmatter
|
|
110
|
-
&& Object.prototype.hasOwnProperty.call(split.frontmatter, "okf_version")) {
|
|
112
|
+
if (split.frontmatter && Object.hasOwn(split.frontmatter, "okf_version")) {
|
|
111
113
|
return current;
|
|
112
114
|
}
|
|
113
115
|
} catch {
|
|
@@ -135,35 +137,45 @@ function normalizeBundles(config, configPath, errors) {
|
|
|
135
137
|
const rootDir = path.dirname(path.resolve(configPath));
|
|
136
138
|
const bundles = Array.isArray(config.bundles) ? config.bundles : [];
|
|
137
139
|
if (!bundles.length) {
|
|
138
|
-
errors.push({
|
|
140
|
+
errors.push({
|
|
141
|
+
code: "missing_bundles",
|
|
142
|
+
message: "Project config must define at least one bundle.",
|
|
143
|
+
});
|
|
139
144
|
}
|
|
140
145
|
const seen = new Set();
|
|
141
|
-
return bundles
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
return bundles
|
|
147
|
+
.map((bundle, index) => {
|
|
148
|
+
if (typeof bundle === "string") {
|
|
149
|
+
const id = configId(path.basename(bundle), `bundle-${index + 1}`);
|
|
150
|
+
if (seen.has(id)) {
|
|
151
|
+
errors.push({ code: "duplicate_bundle_id", bundle: id, message: "Duplicate bundle id." });
|
|
152
|
+
}
|
|
153
|
+
seen.add(id);
|
|
154
|
+
return {
|
|
155
|
+
id,
|
|
156
|
+
root: resolveProjectPath(rootDir, bundle, `bundles[${index}].root`, errors),
|
|
157
|
+
include: [],
|
|
158
|
+
exclude: [],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const id = configId(bundle?.id, `bundle-${index + 1}`);
|
|
144
162
|
if (seen.has(id)) {
|
|
145
163
|
errors.push({ code: "duplicate_bundle_id", bundle: id, message: "Duplicate bundle id." });
|
|
146
164
|
}
|
|
147
165
|
seen.add(id);
|
|
148
166
|
return {
|
|
149
167
|
id,
|
|
150
|
-
root: resolveProjectPath(
|
|
151
|
-
|
|
152
|
-
|
|
168
|
+
root: resolveProjectPath(
|
|
169
|
+
rootDir,
|
|
170
|
+
(bundle && (bundle.root || bundle.path)) || ".",
|
|
171
|
+
`bundles[${index}].root`,
|
|
172
|
+
errors,
|
|
173
|
+
),
|
|
174
|
+
include: Array.isArray(bundle.include) ? bundle.include : [],
|
|
175
|
+
exclude: Array.isArray(bundle.exclude) ? bundle.exclude : [],
|
|
153
176
|
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (seen.has(id)) {
|
|
157
|
-
errors.push({ code: "duplicate_bundle_id", bundle: id, message: "Duplicate bundle id." });
|
|
158
|
-
}
|
|
159
|
-
seen.add(id);
|
|
160
|
-
return {
|
|
161
|
-
id,
|
|
162
|
-
root: resolveProjectPath(rootDir, (bundle && (bundle.root || bundle.path)) || ".", `bundles[${index}].root`, errors),
|
|
163
|
-
include: Array.isArray(bundle.include) ? bundle.include : [],
|
|
164
|
-
exclude: Array.isArray(bundle.exclude) ? bundle.exclude : [],
|
|
165
|
-
};
|
|
166
|
-
}).filter((bundle) => bundle.root);
|
|
177
|
+
})
|
|
178
|
+
.filter((bundle) => bundle.root);
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
function validateRelationTypes(config, errors) {
|
|
@@ -173,7 +185,12 @@ function validateRelationTypes(config, errors) {
|
|
|
173
185
|
}
|
|
174
186
|
(config.relationTypes || []).forEach((type) => {
|
|
175
187
|
if (!/^[A-Za-z0-9_.-]+$/.test(String(type))) {
|
|
176
|
-
errors.push({
|
|
188
|
+
errors.push({
|
|
189
|
+
code: "invalid_relation_type_name",
|
|
190
|
+
relationType: String(type),
|
|
191
|
+
message:
|
|
192
|
+
"Relation type names may contain only letters, numbers, underscores, dots, and hyphens.",
|
|
193
|
+
});
|
|
177
194
|
}
|
|
178
195
|
});
|
|
179
196
|
}
|
|
@@ -186,34 +203,62 @@ function validatePlugins(config, projectRoot, bundleIds, errors) {
|
|
|
186
203
|
(config.plugins || []).forEach((plugin, index) => {
|
|
187
204
|
const type = plugin && (plugin.type || plugin.name);
|
|
188
205
|
if (!plugin || typeof plugin !== "object" || Array.isArray(plugin)) {
|
|
189
|
-
errors.push({
|
|
206
|
+
errors.push({
|
|
207
|
+
code: "invalid_plugin",
|
|
208
|
+
plugin: index,
|
|
209
|
+
message: "Plugin entries must be objects.",
|
|
210
|
+
});
|
|
190
211
|
return;
|
|
191
212
|
}
|
|
192
213
|
if (!["filesystem", "json-spec"].includes(String(type))) {
|
|
193
|
-
errors.push({
|
|
214
|
+
errors.push({
|
|
215
|
+
code: "unknown_plugin_type",
|
|
216
|
+
plugin: plugin.name || index,
|
|
217
|
+
pluginType: type || "",
|
|
218
|
+
message: "Unknown generator plugin type.",
|
|
219
|
+
});
|
|
194
220
|
}
|
|
195
221
|
if (!plugin.root) {
|
|
196
|
-
errors.push({
|
|
222
|
+
errors.push({
|
|
223
|
+
code: "missing_plugin_root",
|
|
224
|
+
plugin: plugin.name || index,
|
|
225
|
+
message: "Plugin root is required.",
|
|
226
|
+
});
|
|
197
227
|
} else {
|
|
198
228
|
resolveProjectPath(projectRoot, plugin.root, `plugins[${index}].root`, errors);
|
|
199
229
|
}
|
|
200
230
|
if (!plugin.output) {
|
|
201
|
-
errors.push({
|
|
231
|
+
errors.push({
|
|
232
|
+
code: "missing_plugin_output",
|
|
233
|
+
plugin: plugin.name || index,
|
|
234
|
+
message: "Plugin output is required.",
|
|
235
|
+
});
|
|
202
236
|
} else {
|
|
203
237
|
resolveProjectPath(projectRoot, plugin.output, `plugins[${index}].output`, errors);
|
|
204
238
|
}
|
|
205
239
|
if (plugin.bundle && !bundleIds.has(String(plugin.bundle))) {
|
|
206
|
-
errors.push({
|
|
240
|
+
errors.push({
|
|
241
|
+
code: "unknown_plugin_bundle",
|
|
242
|
+
plugin: plugin.name || index,
|
|
243
|
+
bundle: String(plugin.bundle),
|
|
244
|
+
message: "Plugin bundle does not exist in project bundles.",
|
|
245
|
+
});
|
|
207
246
|
}
|
|
208
247
|
if (plugin.destinationBundle && !bundleIds.has(String(plugin.destinationBundle))) {
|
|
209
|
-
errors.push({
|
|
248
|
+
errors.push({
|
|
249
|
+
code: "unknown_plugin_destination_bundle",
|
|
250
|
+
plugin: plugin.name || index,
|
|
251
|
+
bundle: String(plugin.destinationBundle),
|
|
252
|
+
message: "Plugin destinationBundle does not exist in project bundles.",
|
|
253
|
+
});
|
|
210
254
|
}
|
|
211
255
|
});
|
|
212
256
|
}
|
|
213
257
|
|
|
214
258
|
function barePackageName(value) {
|
|
215
|
-
return
|
|
216
|
-
&& /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(value)
|
|
259
|
+
return (
|
|
260
|
+
typeof value === "string" && /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(value)
|
|
261
|
+
);
|
|
217
262
|
}
|
|
218
263
|
|
|
219
264
|
function normalizeProducers(config, localBundleIds, errors) {
|
|
@@ -223,51 +268,214 @@ function normalizeProducers(config, localBundleIds, errors) {
|
|
|
223
268
|
}
|
|
224
269
|
const names = new Set();
|
|
225
270
|
const bundles = new Set();
|
|
226
|
-
return (config.producers || [])
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
271
|
+
return (config.producers || [])
|
|
272
|
+
.map((producer, index) => {
|
|
273
|
+
const field = `producers[${index}]`;
|
|
274
|
+
if (!producer || typeof producer !== "object" || Array.isArray(producer)) {
|
|
275
|
+
errors.push({
|
|
276
|
+
code: "invalid_producer",
|
|
277
|
+
producer: index,
|
|
278
|
+
message: "Producer entries must be objects.",
|
|
279
|
+
});
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const allowed = new Set(["name", "type", "package", "bundle", "config"]);
|
|
283
|
+
Object.keys(producer)
|
|
284
|
+
.filter((key) => !allowed.has(key))
|
|
285
|
+
.forEach((key) => {
|
|
286
|
+
errors.push({
|
|
287
|
+
code: "unknown_producer_field",
|
|
288
|
+
producer: producer.name || index,
|
|
289
|
+
field: `${field}.${key}`,
|
|
290
|
+
message: `Unknown producer field: ${key}`,
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
const name = typeof producer.name === "string" ? producer.name.trim() : "";
|
|
294
|
+
const type = typeof producer.type === "string" ? producer.type.trim() : "";
|
|
295
|
+
const packageName = typeof producer.package === "string" ? producer.package.trim() : "";
|
|
296
|
+
const bundle = typeof producer.bundle === "string" ? producer.bundle.trim() : "";
|
|
297
|
+
if (!name || !/^[A-Za-z0-9_.-]+$/.test(name)) {
|
|
298
|
+
errors.push({
|
|
299
|
+
code: "invalid_producer_name",
|
|
300
|
+
producer: index,
|
|
301
|
+
field: `${field}.name`,
|
|
302
|
+
message:
|
|
303
|
+
"Producer name must contain only letters, numbers, underscores, dots, and hyphens.",
|
|
304
|
+
});
|
|
305
|
+
} else if (names.has(name)) {
|
|
306
|
+
errors.push({
|
|
307
|
+
code: "duplicate_producer_name",
|
|
308
|
+
producer: name,
|
|
309
|
+
message: "Producer names must be unique.",
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (name) names.add(name);
|
|
313
|
+
if (!type || !/^[A-Za-z0-9_.-]+$/.test(type)) {
|
|
314
|
+
errors.push({
|
|
315
|
+
code: "invalid_producer_type",
|
|
316
|
+
producer: name || index,
|
|
317
|
+
field: `${field}.type`,
|
|
318
|
+
message:
|
|
319
|
+
"Producer type must contain only letters, numbers, underscores, dots, and hyphens.",
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (!barePackageName(packageName)) {
|
|
323
|
+
errors.push({
|
|
324
|
+
code: "invalid_producer_package",
|
|
325
|
+
producer: name || index,
|
|
326
|
+
field: `${field}.package`,
|
|
327
|
+
message: "Producer package must be a bare npm package name without a subpath.",
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (!localBundleIds.has(bundle)) {
|
|
331
|
+
errors.push({
|
|
332
|
+
code: "unknown_producer_bundle",
|
|
333
|
+
producer: name || index,
|
|
334
|
+
bundle,
|
|
335
|
+
message: "Producer bundle must name a local project bundle.",
|
|
336
|
+
});
|
|
337
|
+
} else if (bundles.has(bundle)) {
|
|
338
|
+
errors.push({
|
|
339
|
+
code: "duplicate_producer_bundle",
|
|
340
|
+
producer: name || index,
|
|
341
|
+
bundle,
|
|
342
|
+
message: "Only one producer may manage a local bundle.",
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
if (bundle) bundles.add(bundle);
|
|
346
|
+
if (
|
|
347
|
+
producer.config !== undefined &&
|
|
348
|
+
(!producer.config || typeof producer.config !== "object" || Array.isArray(producer.config))
|
|
349
|
+
) {
|
|
350
|
+
errors.push({
|
|
351
|
+
code: "invalid_producer_config",
|
|
352
|
+
producer: name || index,
|
|
353
|
+
field: `${field}.config`,
|
|
354
|
+
message: "Producer config must be an object.",
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
name,
|
|
359
|
+
type,
|
|
360
|
+
package: packageName,
|
|
361
|
+
bundle,
|
|
362
|
+
config:
|
|
363
|
+
producer.config && typeof producer.config === "object" && !Array.isArray(producer.config)
|
|
364
|
+
? producer.config
|
|
365
|
+
: {},
|
|
366
|
+
};
|
|
367
|
+
})
|
|
368
|
+
.filter(Boolean);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Tool packs (plan D1, experimental): [{ package, config, timeoutMs? }], each
|
|
372
|
+
// an exact bare npm package name loaded from the project's node_modules
|
|
373
|
+
// (src/tool-packs.js), its trusted config object, and an optional per-call
|
|
374
|
+
// timeout in milliseconds (1 through 300,000).
|
|
375
|
+
function normalizeToolPacks(config, errors) {
|
|
376
|
+
if (config.toolPacks === undefined) return [];
|
|
377
|
+
if (!Array.isArray(config.toolPacks)) {
|
|
378
|
+
errors.push({ code: "invalid_tool_packs", message: "toolPacks must be an array." });
|
|
379
|
+
return [];
|
|
380
|
+
}
|
|
381
|
+
const packages = new Set();
|
|
382
|
+
return config.toolPacks
|
|
383
|
+
.map((entry, index) => {
|
|
384
|
+
const field = `toolPacks[${index}]`;
|
|
385
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
386
|
+
errors.push({
|
|
387
|
+
code: "invalid_tool_pack",
|
|
388
|
+
field,
|
|
389
|
+
message: "Tool pack entries must be objects.",
|
|
390
|
+
});
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
Object.keys(entry)
|
|
394
|
+
.filter((key) => !["package", "config", "timeoutMs"].includes(key))
|
|
395
|
+
.forEach((key) => {
|
|
396
|
+
errors.push({
|
|
397
|
+
code: "unknown_tool_pack_field",
|
|
398
|
+
field: `${field}.${key}`,
|
|
399
|
+
message: `Unknown tool pack field: ${key}`,
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
const packageName = typeof entry.package === "string" ? entry.package.trim() : "";
|
|
403
|
+
if (!barePackageName(packageName)) {
|
|
404
|
+
errors.push({
|
|
405
|
+
code: "invalid_tool_pack_package",
|
|
406
|
+
field: `${field}.package`,
|
|
407
|
+
message: "Tool pack package must be a bare npm package name without a subpath.",
|
|
408
|
+
});
|
|
409
|
+
} else if (packages.has(packageName)) {
|
|
410
|
+
errors.push({
|
|
411
|
+
code: "duplicate_tool_pack_package",
|
|
412
|
+
field: `${field}.package`,
|
|
413
|
+
message: "A tool pack package may be listed only once.",
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
packages.add(packageName);
|
|
417
|
+
const packConfig = entry.config === undefined ? {} : entry.config;
|
|
418
|
+
if (!packConfig || typeof packConfig !== "object" || Array.isArray(packConfig)) {
|
|
419
|
+
errors.push({
|
|
420
|
+
code: "invalid_tool_pack_config",
|
|
421
|
+
field: `${field}.config`,
|
|
422
|
+
message: "Tool pack config must be an object.",
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
const timeoutMs = entry.timeoutMs === undefined ? 30000 : entry.timeoutMs;
|
|
426
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 300000) {
|
|
427
|
+
errors.push({
|
|
428
|
+
code: "invalid_tool_pack_timeout",
|
|
429
|
+
field: `${field}.timeoutMs`,
|
|
430
|
+
message: "Tool pack timeoutMs must be an integer from 1 through 300000.",
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
return { package: packageName, config: packConfig, timeoutMs };
|
|
434
|
+
})
|
|
435
|
+
.filter(Boolean);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// `languages`: "auto" (default), "none", or the stemming language codes for
|
|
439
|
+
// lexical search (plan R-2); validated against the search language registry.
|
|
440
|
+
function normalizeLanguagesConfig(config, errors) {
|
|
441
|
+
if (config.languages === undefined || config.languages === null) {
|
|
442
|
+
return "auto";
|
|
443
|
+
}
|
|
444
|
+
const value = config.languages;
|
|
445
|
+
if (typeof value !== "string" && !Array.isArray(value)) {
|
|
446
|
+
errors.push({
|
|
447
|
+
code: "invalid_languages",
|
|
448
|
+
field: "languages",
|
|
449
|
+
message: 'languages must be "auto", "none", or an array of language codes.',
|
|
235
450
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
return
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
package: packageName,
|
|
265
|
-
bundle,
|
|
266
|
-
config: producer.config && typeof producer.config === "object" && !Array.isArray(producer.config)
|
|
267
|
-
? producer.config
|
|
268
|
-
: {},
|
|
269
|
-
};
|
|
270
|
-
}).filter(Boolean);
|
|
451
|
+
return "auto";
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
454
|
+
return normalizeLanguages(value);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
errors.push({ code: "invalid_languages", field: "languages", message: error.message });
|
|
457
|
+
return "auto";
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// `autoFill` (R-1, 0.11.0-rc.2): under search mode auto, the any-term
|
|
462
|
+
// results follow the all-term hits when there are fewer than this many of
|
|
463
|
+
// them. An integer from 0 (fall back only when nothing matches every term)
|
|
464
|
+
// to 250; unset keeps the search default (3).
|
|
465
|
+
function normalizeAutoFillConfig(config, errors) {
|
|
466
|
+
if (config.autoFill === undefined || config.autoFill === null) {
|
|
467
|
+
return undefined;
|
|
468
|
+
}
|
|
469
|
+
const value = config.autoFill;
|
|
470
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 250) {
|
|
471
|
+
errors.push({
|
|
472
|
+
code: "invalid_auto_fill",
|
|
473
|
+
field: "autoFill",
|
|
474
|
+
message: "autoFill must be an integer between 0 and 250.",
|
|
475
|
+
});
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
return value;
|
|
271
479
|
}
|
|
272
480
|
|
|
273
481
|
function normalizeRemoteBundles(config, errors) {
|
|
@@ -278,32 +486,51 @@ function normalizeRemoteBundles(config, errors) {
|
|
|
278
486
|
}
|
|
279
487
|
const seen = new Set();
|
|
280
488
|
return remotes.map((remote, index) => {
|
|
281
|
-
const id = configId(remote
|
|
489
|
+
const id = configId(remote?.id, `remote-${index + 1}`);
|
|
282
490
|
if (seen.has(id)) {
|
|
283
|
-
errors.push({
|
|
491
|
+
errors.push({
|
|
492
|
+
code: "duplicate_remote_bundle_id",
|
|
493
|
+
bundle: id,
|
|
494
|
+
message: "Duplicate remote bundle id.",
|
|
495
|
+
});
|
|
284
496
|
}
|
|
285
497
|
seen.add(id);
|
|
286
|
-
const provider = String(
|
|
498
|
+
const provider = String(remote?.provider || "github");
|
|
287
499
|
if (provider !== "github") {
|
|
288
|
-
errors.push({
|
|
500
|
+
errors.push({
|
|
501
|
+
code: "unsupported_remote_provider",
|
|
502
|
+
bundle: id,
|
|
503
|
+
provider,
|
|
504
|
+
message: "Only github remote bundles are supported.",
|
|
505
|
+
});
|
|
289
506
|
}
|
|
290
|
-
if (!remote
|
|
291
|
-
errors.push({
|
|
507
|
+
if (!remote?.url) {
|
|
508
|
+
errors.push({
|
|
509
|
+
code: "missing_remote_url",
|
|
510
|
+
bundle: id,
|
|
511
|
+
message: "Remote bundle url is required.",
|
|
512
|
+
});
|
|
292
513
|
}
|
|
293
514
|
return {
|
|
294
515
|
id,
|
|
295
516
|
provider,
|
|
296
|
-
url: remote
|
|
297
|
-
include: Array.isArray(remote
|
|
298
|
-
exclude: Array.isArray(remote
|
|
517
|
+
url: remote?.url ? String(remote.url) : "",
|
|
518
|
+
include: Array.isArray(remote?.include) ? remote.include : [],
|
|
519
|
+
exclude: Array.isArray(remote?.exclude) ? remote.exclude : [],
|
|
299
520
|
};
|
|
300
521
|
});
|
|
301
522
|
}
|
|
302
523
|
|
|
524
|
+
// `writePolicy`: per-actor rules for live writes (plan W-1), parsed here so
|
|
525
|
+
// a malformed policy is a project error and no writable store starts on it.
|
|
526
|
+
function normalizeWritePolicyConfig(config, errors) {
|
|
527
|
+
const parsed = parseWritePolicy(config.writePolicy);
|
|
528
|
+
errors.push(...parsed.errors);
|
|
529
|
+
return parsed.policy;
|
|
530
|
+
}
|
|
531
|
+
|
|
303
532
|
function loadProjectConfig(configPath) {
|
|
304
|
-
const requestedPath = configPath
|
|
305
|
-
? path.resolve(configPath)
|
|
306
|
-
: findProjectConfig(process.cwd());
|
|
533
|
+
const requestedPath = configPath ? path.resolve(configPath) : findProjectConfig(process.cwd());
|
|
307
534
|
if (!requestedPath) {
|
|
308
535
|
throw new Error("No okf.project.yaml or okf.project.json found. Pass --project or --bundle.");
|
|
309
536
|
}
|
|
@@ -313,24 +540,45 @@ function loadProjectConfig(configPath) {
|
|
|
313
540
|
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
314
541
|
errors.push({ code: "invalid_project_config", message: "Project config must be an object." });
|
|
315
542
|
}
|
|
316
|
-
const config =
|
|
543
|
+
const config =
|
|
544
|
+
!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig) ? {} : rawConfig;
|
|
317
545
|
validateRelationTypes(config, errors);
|
|
318
546
|
if (config.strictLinks !== undefined && typeof config.strictLinks !== "boolean") {
|
|
319
|
-
errors.push({
|
|
547
|
+
errors.push({
|
|
548
|
+
code: "invalid_strict_links",
|
|
549
|
+
field: "strictLinks",
|
|
550
|
+
message: "strictLinks must be a boolean.",
|
|
551
|
+
});
|
|
320
552
|
}
|
|
321
|
-
const relationTypes = new Set(
|
|
553
|
+
const relationTypes = new Set(
|
|
554
|
+
DEFAULT_RELATION_TYPES.concat(
|
|
555
|
+
Array.isArray(config.relationTypes) ? config.relationTypes.map(String) : [],
|
|
556
|
+
),
|
|
557
|
+
);
|
|
322
558
|
const bundles = normalizeBundles(config, resolvedPath, errors);
|
|
323
559
|
const remoteBundles = normalizeRemoteBundles(config, errors);
|
|
324
560
|
const localBundleIds = new Set(bundles.map((bundle) => bundle.id));
|
|
325
561
|
const allBundleIds = new Set(bundles.map((bundle) => bundle.id));
|
|
326
562
|
remoteBundles.forEach((bundle) => {
|
|
327
563
|
if (allBundleIds.has(bundle.id)) {
|
|
328
|
-
errors.push({
|
|
564
|
+
errors.push({
|
|
565
|
+
code: "duplicate_bundle_id",
|
|
566
|
+
bundle: bundle.id,
|
|
567
|
+
message: "Remote bundle id duplicates a local bundle id.",
|
|
568
|
+
});
|
|
329
569
|
}
|
|
330
570
|
allBundleIds.add(bundle.id);
|
|
331
571
|
});
|
|
332
572
|
validatePlugins(config, path.dirname(resolvedPath), allBundleIds, errors);
|
|
333
573
|
const producers = normalizeProducers(config, localBundleIds, errors);
|
|
574
|
+
const toolPacks = normalizeToolPacks(config, errors);
|
|
575
|
+
const languages = normalizeLanguagesConfig(config, errors);
|
|
576
|
+
const autoFill = normalizeAutoFillConfig(config, errors);
|
|
577
|
+
const writePolicy = normalizeWritePolicyConfig(config, errors);
|
|
578
|
+
// Hybrid search (WP3c): embedder, cacheDir, fusion.alpha, embedUnits; null when off.
|
|
579
|
+
// WP3c-2: fusion.alpha may be "adaptive", with fusion.adaptive { low, mid, high }.
|
|
580
|
+
// WP3c-2: confidence.minSimilarity, the abstention similarity threshold.
|
|
581
|
+
const embedding = normalizeEmbeddingConfig(config, errors);
|
|
334
582
|
return {
|
|
335
583
|
path: resolvedPath,
|
|
336
584
|
root: path.dirname(resolvedPath),
|
|
@@ -340,7 +588,12 @@ function loadProjectConfig(configPath) {
|
|
|
340
588
|
relationTypes: Array.from(relationTypes),
|
|
341
589
|
plugins: Array.isArray(config.plugins) ? config.plugins : [],
|
|
342
590
|
producers,
|
|
591
|
+
toolPacks,
|
|
343
592
|
strictLinks: Boolean(config.strictLinks),
|
|
593
|
+
languages,
|
|
594
|
+
autoFill,
|
|
595
|
+
writePolicy,
|
|
596
|
+
embedding,
|
|
344
597
|
errors,
|
|
345
598
|
raw: config,
|
|
346
599
|
};
|