@mfdaves/okf-mcp 0.9.1 → 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 +172 -17
- 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
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,147 @@ 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
|
+
// `languages`: "auto" (default), "none", or the stemming language codes for
|
|
372
|
+
// lexical search (plan R-2); validated against the search language registry.
|
|
373
|
+
function normalizeLanguagesConfig(config, errors) {
|
|
374
|
+
if (config.languages === undefined || config.languages === null) {
|
|
375
|
+
return "auto";
|
|
376
|
+
}
|
|
377
|
+
const value = config.languages;
|
|
378
|
+
if (typeof value !== "string" && !Array.isArray(value)) {
|
|
379
|
+
errors.push({
|
|
380
|
+
code: "invalid_languages",
|
|
381
|
+
field: "languages",
|
|
382
|
+
message: 'languages must be "auto", "none", or an array of language codes.',
|
|
235
383
|
});
|
|
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);
|
|
384
|
+
return "auto";
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
return normalizeLanguages(value);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
errors.push({ code: "invalid_languages", field: "languages", message: error.message });
|
|
390
|
+
return "auto";
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// `autoFill` (R-1, 0.11.0-rc.2): under search mode auto, the any-term
|
|
395
|
+
// results follow the all-term hits when there are fewer than this many of
|
|
396
|
+
// them. An integer from 0 (fall back only when nothing matches every term)
|
|
397
|
+
// to 250; unset keeps the search default (3).
|
|
398
|
+
function normalizeAutoFillConfig(config, errors) {
|
|
399
|
+
if (config.autoFill === undefined || config.autoFill === null) {
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
const value = config.autoFill;
|
|
403
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 250) {
|
|
404
|
+
errors.push({
|
|
405
|
+
code: "invalid_auto_fill",
|
|
406
|
+
field: "autoFill",
|
|
407
|
+
message: "autoFill must be an integer between 0 and 250.",
|
|
408
|
+
});
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
411
|
+
return value;
|
|
271
412
|
}
|
|
272
413
|
|
|
273
414
|
function normalizeRemoteBundles(config, errors) {
|
|
@@ -278,32 +419,51 @@ function normalizeRemoteBundles(config, errors) {
|
|
|
278
419
|
}
|
|
279
420
|
const seen = new Set();
|
|
280
421
|
return remotes.map((remote, index) => {
|
|
281
|
-
const id = configId(remote
|
|
422
|
+
const id = configId(remote?.id, `remote-${index + 1}`);
|
|
282
423
|
if (seen.has(id)) {
|
|
283
|
-
errors.push({
|
|
424
|
+
errors.push({
|
|
425
|
+
code: "duplicate_remote_bundle_id",
|
|
426
|
+
bundle: id,
|
|
427
|
+
message: "Duplicate remote bundle id.",
|
|
428
|
+
});
|
|
284
429
|
}
|
|
285
430
|
seen.add(id);
|
|
286
|
-
const provider = String(
|
|
431
|
+
const provider = String(remote?.provider || "github");
|
|
287
432
|
if (provider !== "github") {
|
|
288
|
-
errors.push({
|
|
433
|
+
errors.push({
|
|
434
|
+
code: "unsupported_remote_provider",
|
|
435
|
+
bundle: id,
|
|
436
|
+
provider,
|
|
437
|
+
message: "Only github remote bundles are supported.",
|
|
438
|
+
});
|
|
289
439
|
}
|
|
290
|
-
if (!remote
|
|
291
|
-
errors.push({
|
|
440
|
+
if (!remote?.url) {
|
|
441
|
+
errors.push({
|
|
442
|
+
code: "missing_remote_url",
|
|
443
|
+
bundle: id,
|
|
444
|
+
message: "Remote bundle url is required.",
|
|
445
|
+
});
|
|
292
446
|
}
|
|
293
447
|
return {
|
|
294
448
|
id,
|
|
295
449
|
provider,
|
|
296
|
-
url: remote
|
|
297
|
-
include: Array.isArray(remote
|
|
298
|
-
exclude: Array.isArray(remote
|
|
450
|
+
url: remote?.url ? String(remote.url) : "",
|
|
451
|
+
include: Array.isArray(remote?.include) ? remote.include : [],
|
|
452
|
+
exclude: Array.isArray(remote?.exclude) ? remote.exclude : [],
|
|
299
453
|
};
|
|
300
454
|
});
|
|
301
455
|
}
|
|
302
456
|
|
|
457
|
+
// `writePolicy`: per-actor rules for live writes (plan W-1), parsed here so
|
|
458
|
+
// a malformed policy is a project error and no writable store starts on it.
|
|
459
|
+
function normalizeWritePolicyConfig(config, errors) {
|
|
460
|
+
const parsed = parseWritePolicy(config.writePolicy);
|
|
461
|
+
errors.push(...parsed.errors);
|
|
462
|
+
return parsed.policy;
|
|
463
|
+
}
|
|
464
|
+
|
|
303
465
|
function loadProjectConfig(configPath) {
|
|
304
|
-
const requestedPath = configPath
|
|
305
|
-
? path.resolve(configPath)
|
|
306
|
-
: findProjectConfig(process.cwd());
|
|
466
|
+
const requestedPath = configPath ? path.resolve(configPath) : findProjectConfig(process.cwd());
|
|
307
467
|
if (!requestedPath) {
|
|
308
468
|
throw new Error("No okf.project.yaml or okf.project.json found. Pass --project or --bundle.");
|
|
309
469
|
}
|
|
@@ -313,24 +473,44 @@ function loadProjectConfig(configPath) {
|
|
|
313
473
|
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
314
474
|
errors.push({ code: "invalid_project_config", message: "Project config must be an object." });
|
|
315
475
|
}
|
|
316
|
-
const config =
|
|
476
|
+
const config =
|
|
477
|
+
!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig) ? {} : rawConfig;
|
|
317
478
|
validateRelationTypes(config, errors);
|
|
318
479
|
if (config.strictLinks !== undefined && typeof config.strictLinks !== "boolean") {
|
|
319
|
-
errors.push({
|
|
480
|
+
errors.push({
|
|
481
|
+
code: "invalid_strict_links",
|
|
482
|
+
field: "strictLinks",
|
|
483
|
+
message: "strictLinks must be a boolean.",
|
|
484
|
+
});
|
|
320
485
|
}
|
|
321
|
-
const relationTypes = new Set(
|
|
486
|
+
const relationTypes = new Set(
|
|
487
|
+
DEFAULT_RELATION_TYPES.concat(
|
|
488
|
+
Array.isArray(config.relationTypes) ? config.relationTypes.map(String) : [],
|
|
489
|
+
),
|
|
490
|
+
);
|
|
322
491
|
const bundles = normalizeBundles(config, resolvedPath, errors);
|
|
323
492
|
const remoteBundles = normalizeRemoteBundles(config, errors);
|
|
324
493
|
const localBundleIds = new Set(bundles.map((bundle) => bundle.id));
|
|
325
494
|
const allBundleIds = new Set(bundles.map((bundle) => bundle.id));
|
|
326
495
|
remoteBundles.forEach((bundle) => {
|
|
327
496
|
if (allBundleIds.has(bundle.id)) {
|
|
328
|
-
errors.push({
|
|
497
|
+
errors.push({
|
|
498
|
+
code: "duplicate_bundle_id",
|
|
499
|
+
bundle: bundle.id,
|
|
500
|
+
message: "Remote bundle id duplicates a local bundle id.",
|
|
501
|
+
});
|
|
329
502
|
}
|
|
330
503
|
allBundleIds.add(bundle.id);
|
|
331
504
|
});
|
|
332
505
|
validatePlugins(config, path.dirname(resolvedPath), allBundleIds, errors);
|
|
333
506
|
const producers = normalizeProducers(config, localBundleIds, errors);
|
|
507
|
+
const languages = normalizeLanguagesConfig(config, errors);
|
|
508
|
+
const autoFill = normalizeAutoFillConfig(config, errors);
|
|
509
|
+
const writePolicy = normalizeWritePolicyConfig(config, errors);
|
|
510
|
+
// Hybrid search (WP3c): embedder, cacheDir, fusion.alpha, embedUnits; null when off.
|
|
511
|
+
// WP3c-2: fusion.alpha may be "adaptive", with fusion.adaptive { low, mid, high }.
|
|
512
|
+
// WP3c-2: confidence.minSimilarity, the abstention similarity threshold.
|
|
513
|
+
const embedding = normalizeEmbeddingConfig(config, errors);
|
|
334
514
|
return {
|
|
335
515
|
path: resolvedPath,
|
|
336
516
|
root: path.dirname(resolvedPath),
|
|
@@ -341,6 +521,10 @@ function loadProjectConfig(configPath) {
|
|
|
341
521
|
plugins: Array.isArray(config.plugins) ? config.plugins : [],
|
|
342
522
|
producers,
|
|
343
523
|
strictLinks: Boolean(config.strictLinks),
|
|
524
|
+
languages,
|
|
525
|
+
autoFill,
|
|
526
|
+
writePolicy,
|
|
527
|
+
embedding,
|
|
344
528
|
errors,
|
|
345
529
|
raw: config,
|
|
346
530
|
};
|