@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/v02.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const { repeatedParameterMessage } = require("./catalog-text");
|
|
3
4
|
const { itemLiteral, markdownStructure, sectionNodes } = require("./markdown");
|
|
4
5
|
|
|
5
6
|
function isPlainObject(value) {
|
|
@@ -22,9 +23,7 @@ function validActor(value) {
|
|
|
22
23
|
if (!nonEmptyString(value) || /\s/.test(value)) {
|
|
23
24
|
return false;
|
|
24
25
|
}
|
|
25
|
-
return /^human:.+/.test(value)
|
|
26
|
-
|| /^process:.+/.test(value)
|
|
27
|
-
|| /^[^/]+\/[^/]+$/.test(value);
|
|
26
|
+
return /^human:.+/.test(value) || /^process:.+/.test(value) || /^[^/]+\/[^/]+$/.test(value);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
function diagnostic(code, field, message) {
|
|
@@ -71,12 +70,14 @@ function validIsoDateTime(value) {
|
|
|
71
70
|
const second = match[4] === undefined ? 0 : Number(match[4]);
|
|
72
71
|
const offsetHour = match[6] === undefined ? 0 : Number(match[6]);
|
|
73
72
|
const offsetMinute = match[7] === undefined ? 0 : Number(match[7]);
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
&&
|
|
73
|
+
return (
|
|
74
|
+
hour <= 23 &&
|
|
75
|
+
minute <= 59 &&
|
|
76
|
+
second <= 59 &&
|
|
77
|
+
offsetHour <= 23 &&
|
|
78
|
+
offsetMinute <= 59 &&
|
|
79
|
+
Number.isFinite(Date.parse(value))
|
|
80
|
+
);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
function normalizeAsOf(value) {
|
|
@@ -102,12 +103,19 @@ function normalizeUsageWindow(value, field, diagnostics) {
|
|
|
102
103
|
if (value === undefined) {
|
|
103
104
|
return null;
|
|
104
105
|
}
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
if (
|
|
107
|
+
!isPlainObject(value) ||
|
|
108
|
+
!validIsoDate(value.from) ||
|
|
109
|
+
!validIsoDate(value.to) ||
|
|
110
|
+
value.from > value.to
|
|
111
|
+
) {
|
|
112
|
+
diagnostics.push(
|
|
113
|
+
diagnostic(
|
|
114
|
+
"invalid_usage_window",
|
|
115
|
+
field,
|
|
116
|
+
"usage_window must contain valid from and to ISO dates with from not later than to.",
|
|
117
|
+
),
|
|
118
|
+
);
|
|
111
119
|
return null;
|
|
112
120
|
}
|
|
113
121
|
return Object.assign({}, value, {
|
|
@@ -122,7 +130,9 @@ function extractLegacyCitations(body) {
|
|
|
122
130
|
structure.headings
|
|
123
131
|
.filter((heading) => heading.level === 1 && heading.text.toLowerCase() === "citations")
|
|
124
132
|
.forEach((heading) => {
|
|
125
|
-
const lists = new Set(
|
|
133
|
+
const lists = new Set(
|
|
134
|
+
sectionNodes(heading, { stopAtAnyHeading: true }).filter((node) => node.type === "list"),
|
|
135
|
+
);
|
|
126
136
|
structure.items
|
|
127
137
|
.filter((item) => lists.has(item.node.parent))
|
|
128
138
|
.forEach((item) => {
|
|
@@ -139,7 +149,7 @@ function extractLegacyCitations(body) {
|
|
|
139
149
|
raw,
|
|
140
150
|
});
|
|
141
151
|
});
|
|
142
|
-
|
|
152
|
+
});
|
|
143
153
|
|
|
144
154
|
return citations;
|
|
145
155
|
}
|
|
@@ -156,43 +166,78 @@ function normalizeSources(frontmatter, body, diagnostics) {
|
|
|
156
166
|
};
|
|
157
167
|
}
|
|
158
168
|
if (!Array.isArray(frontmatter.sources)) {
|
|
159
|
-
diagnostics.push(
|
|
169
|
+
diagnostics.push(
|
|
170
|
+
diagnostic("invalid_sources", "sources", "sources must be a list when present."),
|
|
171
|
+
);
|
|
160
172
|
return { sources: [], origin: "native", usageWindow };
|
|
161
173
|
}
|
|
162
174
|
|
|
163
175
|
const sources = frontmatter.sources.map((entry, index) => {
|
|
164
176
|
const field = `sources[${index}]`;
|
|
165
177
|
if (!isPlainObject(entry)) {
|
|
166
|
-
diagnostics.push(
|
|
178
|
+
diagnostics.push(
|
|
179
|
+
diagnostic("invalid_source_entry", field, "Each sources entry must be a mapping."),
|
|
180
|
+
);
|
|
167
181
|
return { raw: entry, legacy: false, valid: false };
|
|
168
182
|
}
|
|
169
183
|
let valid = true;
|
|
170
184
|
if (!nonEmptyString(entry.resource)) {
|
|
171
|
-
diagnostics.push(
|
|
185
|
+
diagnostics.push(
|
|
186
|
+
diagnostic(
|
|
187
|
+
"missing_source_resource",
|
|
188
|
+
`${field}.resource`,
|
|
189
|
+
"A source entry requires a non-empty resource.",
|
|
190
|
+
),
|
|
191
|
+
);
|
|
172
192
|
valid = false;
|
|
173
193
|
}
|
|
174
194
|
if (hasOwn(entry, "id") && !nonEmptyString(entry.id)) {
|
|
175
|
-
diagnostics.push(
|
|
195
|
+
diagnostics.push(
|
|
196
|
+
diagnostic("invalid_source_id", `${field}.id`, "A source id must be a non-empty scalar."),
|
|
197
|
+
);
|
|
176
198
|
valid = false;
|
|
177
199
|
}
|
|
178
200
|
if (hasOwn(entry, "author") && !nonEmptyString(entry.author)) {
|
|
179
|
-
diagnostics.push(
|
|
201
|
+
diagnostics.push(
|
|
202
|
+
diagnostic(
|
|
203
|
+
"invalid_source_author",
|
|
204
|
+
`${field}.author`,
|
|
205
|
+
"A source author must be a non-empty actor scalar.",
|
|
206
|
+
),
|
|
207
|
+
);
|
|
180
208
|
valid = false;
|
|
181
209
|
}
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
210
|
+
if (
|
|
211
|
+
hasOwn(entry, "usage_count") &&
|
|
212
|
+
(typeof entry.usage_count !== "number" ||
|
|
213
|
+
!Number.isFinite(entry.usage_count) ||
|
|
214
|
+
entry.usage_count < 0)
|
|
215
|
+
) {
|
|
216
|
+
diagnostics.push(
|
|
217
|
+
diagnostic(
|
|
218
|
+
"invalid_source_usage_count",
|
|
219
|
+
`${field}.usage_count`,
|
|
220
|
+
"A source usage_count must be a non-negative finite number.",
|
|
221
|
+
),
|
|
222
|
+
);
|
|
188
223
|
valid = false;
|
|
189
224
|
}
|
|
190
225
|
if (hasOwn(entry, "last_modified") && !validIsoDate(entry.last_modified)) {
|
|
191
|
-
diagnostics.push(
|
|
226
|
+
diagnostics.push(
|
|
227
|
+
diagnostic(
|
|
228
|
+
"invalid_source_last_modified",
|
|
229
|
+
`${field}.last_modified`,
|
|
230
|
+
"A source last_modified value must be an ISO date.",
|
|
231
|
+
),
|
|
232
|
+
);
|
|
192
233
|
valid = false;
|
|
193
234
|
}
|
|
194
235
|
const localDiagnosticsBefore = diagnostics.length;
|
|
195
|
-
const entryUsageWindow = normalizeUsageWindow(
|
|
236
|
+
const entryUsageWindow = normalizeUsageWindow(
|
|
237
|
+
entry.usage_window,
|
|
238
|
+
`${field}.usage_window`,
|
|
239
|
+
diagnostics,
|
|
240
|
+
);
|
|
196
241
|
if (diagnostics.length > localDiagnosticsBefore) {
|
|
197
242
|
valid = false;
|
|
198
243
|
}
|
|
@@ -209,16 +254,30 @@ function normalizeGenerated(frontmatter, diagnostics) {
|
|
|
209
254
|
if (hasOwn(frontmatter, "generated")) {
|
|
210
255
|
const value = frontmatter.generated;
|
|
211
256
|
if (!isPlainObject(value)) {
|
|
212
|
-
diagnostics.push(
|
|
257
|
+
diagnostics.push(
|
|
258
|
+
diagnostic("invalid_generated", "generated", "generated must be a mapping when present."),
|
|
259
|
+
);
|
|
213
260
|
return { generated: null, origin: "native" };
|
|
214
261
|
}
|
|
215
262
|
let valid = true;
|
|
216
263
|
if (!validActor(value.by)) {
|
|
217
|
-
diagnostics.push(
|
|
264
|
+
diagnostics.push(
|
|
265
|
+
diagnostic(
|
|
266
|
+
"missing_generated_by",
|
|
267
|
+
"generated.by",
|
|
268
|
+
"generated.by requires a non-empty actor.",
|
|
269
|
+
),
|
|
270
|
+
);
|
|
218
271
|
valid = false;
|
|
219
272
|
}
|
|
220
273
|
if (hasOwn(value, "at") && !validIsoDateTime(value.at)) {
|
|
221
|
-
diagnostics.push(
|
|
274
|
+
diagnostics.push(
|
|
275
|
+
diagnostic(
|
|
276
|
+
"invalid_generated_at",
|
|
277
|
+
"generated.at",
|
|
278
|
+
"generated.at must be an ISO datetime when present.",
|
|
279
|
+
),
|
|
280
|
+
);
|
|
222
281
|
valid = false;
|
|
223
282
|
}
|
|
224
283
|
return {
|
|
@@ -233,7 +292,13 @@ function normalizeGenerated(frontmatter, diagnostics) {
|
|
|
233
292
|
}
|
|
234
293
|
if (hasOwn(frontmatter, "timestamp")) {
|
|
235
294
|
if (!validIsoDateTime(frontmatter.timestamp)) {
|
|
236
|
-
diagnostics.push(
|
|
295
|
+
diagnostics.push(
|
|
296
|
+
diagnostic(
|
|
297
|
+
"invalid_legacy_timestamp",
|
|
298
|
+
"timestamp",
|
|
299
|
+
"Legacy timestamp must be an ISO datetime.",
|
|
300
|
+
),
|
|
301
|
+
);
|
|
237
302
|
return { generated: null, origin: "legacy_timestamp" };
|
|
238
303
|
}
|
|
239
304
|
return {
|
|
@@ -255,7 +320,13 @@ function normalizeVerified(value, present, diagnostics) {
|
|
|
255
320
|
}
|
|
256
321
|
const candidates = isPlainObject(value) ? [value] : value;
|
|
257
322
|
if (!Array.isArray(candidates)) {
|
|
258
|
-
diagnostics.push(
|
|
323
|
+
diagnostics.push(
|
|
324
|
+
diagnostic(
|
|
325
|
+
"invalid_verified",
|
|
326
|
+
"verified",
|
|
327
|
+
"verified must be a mapping or a list of mappings.",
|
|
328
|
+
),
|
|
329
|
+
);
|
|
259
330
|
return { events: [], valid: false };
|
|
260
331
|
}
|
|
261
332
|
|
|
@@ -264,22 +335,38 @@ function normalizeVerified(value, present, diagnostics) {
|
|
|
264
335
|
candidates.forEach((entry, index) => {
|
|
265
336
|
const field = `verified[${index}]`;
|
|
266
337
|
if (!isPlainObject(entry)) {
|
|
267
|
-
diagnostics.push(
|
|
338
|
+
diagnostics.push(
|
|
339
|
+
diagnostic("invalid_verified_event", field, "Each verification event must be a mapping."),
|
|
340
|
+
);
|
|
268
341
|
valid = false;
|
|
269
342
|
return;
|
|
270
343
|
}
|
|
271
344
|
if (!validActor(entry.by)) {
|
|
272
|
-
diagnostics.push(
|
|
345
|
+
diagnostics.push(
|
|
346
|
+
diagnostic(
|
|
347
|
+
"invalid_verified_actor",
|
|
348
|
+
`${field}.by`,
|
|
349
|
+
"A verification event requires a non-empty actor.",
|
|
350
|
+
),
|
|
351
|
+
);
|
|
273
352
|
valid = false;
|
|
274
353
|
}
|
|
275
354
|
if (!validIsoDateTime(entry.at)) {
|
|
276
|
-
diagnostics.push(
|
|
355
|
+
diagnostics.push(
|
|
356
|
+
diagnostic(
|
|
357
|
+
"invalid_verified_at",
|
|
358
|
+
`${field}.at`,
|
|
359
|
+
"A verification event requires an ISO datetime.",
|
|
360
|
+
),
|
|
361
|
+
);
|
|
277
362
|
valid = false;
|
|
278
363
|
}
|
|
279
|
-
events.push(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
364
|
+
events.push(
|
|
365
|
+
Object.assign({}, entry, {
|
|
366
|
+
by: validActor(entry.by) ? entry.by : null,
|
|
367
|
+
at: validIsoDateTime(entry.at) ? entry.at : null,
|
|
368
|
+
}),
|
|
369
|
+
);
|
|
283
370
|
});
|
|
284
371
|
return valid ? { events, valid: true } : { events: [], valid: false };
|
|
285
372
|
}
|
|
@@ -296,11 +383,16 @@ function deriveTrustTier(events, valid) {
|
|
|
296
383
|
function normalizeLifecycle(frontmatter, asOf, diagnostics) {
|
|
297
384
|
let status = "stable";
|
|
298
385
|
if (hasOwn(frontmatter, "status")) {
|
|
299
|
-
if (
|
|
386
|
+
if (
|
|
387
|
+
typeof frontmatter.status === "string" &&
|
|
388
|
+
["draft", "stable", "deprecated"].includes(frontmatter.status)
|
|
389
|
+
) {
|
|
300
390
|
status = frontmatter.status;
|
|
301
391
|
} else {
|
|
302
392
|
status = null;
|
|
303
|
-
diagnostics.push(
|
|
393
|
+
diagnostics.push(
|
|
394
|
+
diagnostic("invalid_status", "status", "status must be draft, stable, or deprecated."),
|
|
395
|
+
);
|
|
304
396
|
}
|
|
305
397
|
}
|
|
306
398
|
|
|
@@ -312,7 +404,9 @@ function normalizeLifecycle(frontmatter, asOf, diagnostics) {
|
|
|
312
404
|
freshness = asOf >= staleAfter ? "stale" : "fresh";
|
|
313
405
|
} else {
|
|
314
406
|
freshness = "invalid";
|
|
315
|
-
diagnostics.push(
|
|
407
|
+
diagnostics.push(
|
|
408
|
+
diagnostic("invalid_stale_after", "stale_after", "stale_after must be an ISO date."),
|
|
409
|
+
);
|
|
316
410
|
}
|
|
317
411
|
}
|
|
318
412
|
return { status, staleAfter, freshness, asOf };
|
|
@@ -321,9 +415,9 @@ function normalizeLifecycle(frontmatter, asOf, diagnostics) {
|
|
|
321
415
|
function extractInlineComputation(body) {
|
|
322
416
|
const structure = markdownStructure(body);
|
|
323
417
|
const blocks = [];
|
|
324
|
-
const sections = structure.headings.filter(
|
|
325
|
-
heading.level === 1 && heading.text.toLowerCase() === "computation"
|
|
326
|
-
)
|
|
418
|
+
const sections = structure.headings.filter(
|
|
419
|
+
(heading) => heading.level === 1 && heading.text.toLowerCase() === "computation",
|
|
420
|
+
);
|
|
327
421
|
sections.forEach((heading) => {
|
|
328
422
|
const nodes = new Set(sectionNodes(heading, { stopAtAnyHeading: true }));
|
|
329
423
|
structure.codeBlocks
|
|
@@ -342,33 +436,51 @@ function extractInlineComputation(body) {
|
|
|
342
436
|
};
|
|
343
437
|
}
|
|
344
438
|
|
|
345
|
-
function normalizeParameters(value, diagnostics) {
|
|
439
|
+
function normalizeParameters(value, diagnostics, location) {
|
|
346
440
|
if (value === undefined) {
|
|
347
441
|
return [];
|
|
348
442
|
}
|
|
349
443
|
if (!Array.isArray(value)) {
|
|
350
|
-
diagnostics.push(
|
|
444
|
+
diagnostics.push(
|
|
445
|
+
diagnostic(
|
|
446
|
+
"invalid_computation_parameters",
|
|
447
|
+
"parameters",
|
|
448
|
+
"parameters must be a list when present.",
|
|
449
|
+
),
|
|
450
|
+
);
|
|
351
451
|
return null;
|
|
352
452
|
}
|
|
353
453
|
let valid = true;
|
|
354
454
|
const seen = new Set();
|
|
355
455
|
const parameters = value.map((entry, index) => {
|
|
356
456
|
const field = `parameters[${index}]`;
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
457
|
+
if (
|
|
458
|
+
!isPlainObject(entry) ||
|
|
459
|
+
!nonEmptyString(entry.name) ||
|
|
460
|
+
!nonEmptyString(entry.type) ||
|
|
461
|
+
typeof entry.required !== "boolean"
|
|
462
|
+
) {
|
|
463
|
+
diagnostics.push(
|
|
464
|
+
diagnostic(
|
|
465
|
+
"invalid_computation_parameter",
|
|
466
|
+
field,
|
|
467
|
+
"Each parameter requires non-empty name and type scalars plus a boolean required field.",
|
|
468
|
+
),
|
|
469
|
+
);
|
|
366
470
|
valid = false;
|
|
367
|
-
return isPlainObject(entry)
|
|
471
|
+
return isPlainObject(entry)
|
|
472
|
+
? Object.assign({}, entry, { valid: false })
|
|
473
|
+
: { raw: entry, valid: false };
|
|
368
474
|
}
|
|
369
475
|
const name = String(entry.name);
|
|
370
476
|
if (seen.has(name)) {
|
|
371
|
-
diagnostics.push(
|
|
477
|
+
diagnostics.push(
|
|
478
|
+
diagnostic(
|
|
479
|
+
"duplicate_computation_parameter",
|
|
480
|
+
`${field}.name`,
|
|
481
|
+
repeatedParameterMessage(location, index),
|
|
482
|
+
),
|
|
483
|
+
);
|
|
372
484
|
valid = false;
|
|
373
485
|
}
|
|
374
486
|
seen.add(name);
|
|
@@ -383,27 +495,55 @@ function normalizeParameters(value, diagnostics) {
|
|
|
383
495
|
|
|
384
496
|
function normalizeExecutor(value, diagnostics) {
|
|
385
497
|
if (value === undefined) {
|
|
386
|
-
diagnostics.push(
|
|
498
|
+
diagnostics.push(
|
|
499
|
+
diagnostic(
|
|
500
|
+
"missing_computation_executor",
|
|
501
|
+
"executor",
|
|
502
|
+
"An attestable computation requires an executor contract.",
|
|
503
|
+
),
|
|
504
|
+
);
|
|
387
505
|
return null;
|
|
388
506
|
}
|
|
389
507
|
if (!isPlainObject(value)) {
|
|
390
|
-
diagnostics.push(
|
|
508
|
+
diagnostics.push(
|
|
509
|
+
diagnostic("invalid_computation_executor", "executor", "executor must be a mapping."),
|
|
510
|
+
);
|
|
391
511
|
return null;
|
|
392
512
|
}
|
|
393
513
|
let valid = true;
|
|
394
514
|
if (!nonEmptyString(value.resource)) {
|
|
395
|
-
diagnostics.push(
|
|
515
|
+
diagnostics.push(
|
|
516
|
+
diagnostic(
|
|
517
|
+
"missing_executor_resource",
|
|
518
|
+
"executor.resource",
|
|
519
|
+
"executor.resource must be a non-empty path or URI.",
|
|
520
|
+
),
|
|
521
|
+
);
|
|
396
522
|
valid = false;
|
|
397
523
|
}
|
|
398
|
-
if (
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
524
|
+
if (
|
|
525
|
+
!Array.isArray(value.receipt) ||
|
|
526
|
+
value.receipt.length === 0 ||
|
|
527
|
+
value.receipt.some((entry) => !nonEmptyString(entry))
|
|
528
|
+
) {
|
|
529
|
+
diagnostics.push(
|
|
530
|
+
diagnostic(
|
|
531
|
+
"invalid_executor_receipt",
|
|
532
|
+
"executor.receipt",
|
|
533
|
+
"executor.receipt must be a non-empty list of field names.",
|
|
534
|
+
),
|
|
535
|
+
);
|
|
402
536
|
valid = false;
|
|
403
537
|
}
|
|
404
538
|
const receipt = Array.isArray(value.receipt) ? value.receipt.map(String) : [];
|
|
405
539
|
if (new Set(receipt).size !== receipt.length) {
|
|
406
|
-
diagnostics.push(
|
|
540
|
+
diagnostics.push(
|
|
541
|
+
diagnostic(
|
|
542
|
+
"duplicate_executor_receipt_field",
|
|
543
|
+
"executor.receipt",
|
|
544
|
+
"executor.receipt field names must be unique.",
|
|
545
|
+
),
|
|
546
|
+
);
|
|
407
547
|
valid = false;
|
|
408
548
|
}
|
|
409
549
|
return Object.assign({}, value, {
|
|
@@ -415,16 +555,30 @@ function normalizeExecutor(value, diagnostics) {
|
|
|
415
555
|
|
|
416
556
|
function normalizeAttester(value, diagnostics) {
|
|
417
557
|
if (value === undefined) {
|
|
418
|
-
diagnostics.push(
|
|
558
|
+
diagnostics.push(
|
|
559
|
+
diagnostic(
|
|
560
|
+
"missing_computation_attester",
|
|
561
|
+
"attester",
|
|
562
|
+
"An attestable computation requires an attester contract.",
|
|
563
|
+
),
|
|
564
|
+
);
|
|
419
565
|
return null;
|
|
420
566
|
}
|
|
421
567
|
if (!isPlainObject(value)) {
|
|
422
|
-
diagnostics.push(
|
|
568
|
+
diagnostics.push(
|
|
569
|
+
diagnostic("invalid_computation_attester", "attester", "attester must be a mapping."),
|
|
570
|
+
);
|
|
423
571
|
return null;
|
|
424
572
|
}
|
|
425
573
|
const valid = nonEmptyString(value.resource);
|
|
426
574
|
if (!valid) {
|
|
427
|
-
diagnostics.push(
|
|
575
|
+
diagnostics.push(
|
|
576
|
+
diagnostic(
|
|
577
|
+
"missing_attester_resource",
|
|
578
|
+
"attester.resource",
|
|
579
|
+
"attester.resource must be a non-empty path or URI.",
|
|
580
|
+
),
|
|
581
|
+
);
|
|
428
582
|
}
|
|
429
583
|
return Object.assign({}, value, {
|
|
430
584
|
resource: valid ? value.resource : null,
|
|
@@ -432,57 +586,83 @@ function normalizeAttester(value, diagnostics) {
|
|
|
432
586
|
});
|
|
433
587
|
}
|
|
434
588
|
|
|
435
|
-
function normalizeAttestedComputation(frontmatter, body, diagnostics) {
|
|
589
|
+
function normalizeAttestedComputation(frontmatter, body, diagnostics, location) {
|
|
436
590
|
if (frontmatter.type !== "Attested Computation") {
|
|
437
591
|
return null;
|
|
438
592
|
}
|
|
439
593
|
const start = diagnostics.length;
|
|
440
594
|
let runtime = null;
|
|
441
595
|
if (!hasOwn(frontmatter, "runtime")) {
|
|
442
|
-
diagnostics.push(
|
|
596
|
+
diagnostics.push(
|
|
597
|
+
diagnostic(
|
|
598
|
+
"missing_computation_runtime",
|
|
599
|
+
"runtime",
|
|
600
|
+
"An Attested Computation requires runtime.",
|
|
601
|
+
),
|
|
602
|
+
);
|
|
443
603
|
} else if (!nonEmptyString(frontmatter.runtime)) {
|
|
444
|
-
diagnostics.push(
|
|
604
|
+
diagnostics.push(
|
|
605
|
+
diagnostic("invalid_computation_runtime", "runtime", "runtime must be a non-empty scalar."),
|
|
606
|
+
);
|
|
445
607
|
} else {
|
|
446
608
|
runtime = String(frontmatter.runtime);
|
|
447
609
|
}
|
|
448
610
|
|
|
449
|
-
const parameters = normalizeParameters(frontmatter.parameters, diagnostics);
|
|
611
|
+
const parameters = normalizeParameters(frontmatter.parameters, diagnostics, location);
|
|
450
612
|
const inline = extractInlineComputation(body);
|
|
451
613
|
const hasFileField = hasOwn(frontmatter, "computation");
|
|
452
|
-
const filePath =
|
|
453
|
-
? frontmatter.computation
|
|
454
|
-
: null;
|
|
614
|
+
const filePath =
|
|
615
|
+
hasFileField && nonEmptyString(frontmatter.computation) ? frontmatter.computation : null;
|
|
455
616
|
if (hasFileField && !filePath) {
|
|
456
|
-
diagnostics.push(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
617
|
+
diagnostics.push(
|
|
618
|
+
diagnostic(
|
|
619
|
+
"invalid_computation_path",
|
|
620
|
+
"computation",
|
|
621
|
+
"computation must be a non-empty path when present.",
|
|
622
|
+
),
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
if (
|
|
626
|
+
inline.sectionCount > 1 ||
|
|
627
|
+
inline.blocks.some((block) => !block.closed || !block.content.trim()) ||
|
|
628
|
+
inline.blocks.length > 1
|
|
629
|
+
) {
|
|
630
|
+
diagnostics.push(
|
|
631
|
+
diagnostic(
|
|
632
|
+
"invalid_inline_computation",
|
|
633
|
+
"body.# Computation",
|
|
634
|
+
"Inline computation requires one # Computation section containing exactly one closed fenced code block.",
|
|
635
|
+
),
|
|
636
|
+
);
|
|
466
637
|
}
|
|
467
638
|
if (hasFileField && inline.blocks.length > 0) {
|
|
468
|
-
diagnostics.push(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
639
|
+
diagnostics.push(
|
|
640
|
+
diagnostic(
|
|
641
|
+
"conflicting_computation_sources",
|
|
642
|
+
"computation",
|
|
643
|
+
"Use either computation file path or an inline fenced computation, not both.",
|
|
644
|
+
),
|
|
645
|
+
);
|
|
473
646
|
}
|
|
474
647
|
|
|
475
648
|
let computation = null;
|
|
476
649
|
if (filePath && inline.blocks.length === 0) {
|
|
477
650
|
computation = { mode: "file", path: filePath };
|
|
478
|
-
} else if (
|
|
651
|
+
} else if (
|
|
652
|
+
!hasFileField &&
|
|
653
|
+
inline.sectionCount === 1 &&
|
|
654
|
+
inline.blocks.length === 1 &&
|
|
655
|
+
inline.blocks[0].closed
|
|
656
|
+
) {
|
|
479
657
|
computation = Object.assign({ mode: "inline" }, inline.blocks[0]);
|
|
480
658
|
} else if (!hasFileField && inline.blocks.length === 0) {
|
|
481
|
-
diagnostics.push(
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
659
|
+
diagnostics.push(
|
|
660
|
+
diagnostic(
|
|
661
|
+
"missing_computation",
|
|
662
|
+
"body.# Computation",
|
|
663
|
+
"Provide computation as a file path or one fenced block under # Computation.",
|
|
664
|
+
),
|
|
665
|
+
);
|
|
486
666
|
}
|
|
487
667
|
|
|
488
668
|
const executor = normalizeExecutor(frontmatter.executor, diagnostics);
|
|
@@ -501,9 +681,13 @@ function normalizeAttestedComputation(frontmatter, body, diagnostics) {
|
|
|
501
681
|
function normalizeV02Signals(documentOrFrontmatter, options) {
|
|
502
682
|
const input = documentOrFrontmatter || {};
|
|
503
683
|
const document = isPlainObject(input) && isPlainObject(input.frontmatter) ? input : null;
|
|
504
|
-
const frontmatter = document ? input.frontmatter :
|
|
684
|
+
const frontmatter = document ? input.frontmatter : isPlainObject(input) ? input : {};
|
|
505
685
|
const config = options || {};
|
|
506
|
-
const body = hasOwn(config, "body")
|
|
686
|
+
const body = hasOwn(config, "body")
|
|
687
|
+
? config.body
|
|
688
|
+
: document && hasOwn(document, "body")
|
|
689
|
+
? document.body
|
|
690
|
+
: "";
|
|
507
691
|
const asOf = normalizeAsOf(config.asOf);
|
|
508
692
|
const diagnostics = [];
|
|
509
693
|
|
|
@@ -512,14 +696,26 @@ function normalizeV02Signals(documentOrFrontmatter, options) {
|
|
|
512
696
|
if (nonEmptyString(frontmatter.resource)) {
|
|
513
697
|
resource = frontmatter.resource;
|
|
514
698
|
} else {
|
|
515
|
-
diagnostics.push(
|
|
699
|
+
diagnostics.push(
|
|
700
|
+
diagnostic(
|
|
701
|
+
"invalid_resource",
|
|
702
|
+
"resource",
|
|
703
|
+
"resource must be a non-empty path or URI when present.",
|
|
704
|
+
),
|
|
705
|
+
);
|
|
516
706
|
}
|
|
517
707
|
}
|
|
518
708
|
const provenance = normalizeSources(frontmatter, body, diagnostics);
|
|
519
709
|
const generation = normalizeGenerated(frontmatter, diagnostics);
|
|
520
|
-
const verification = normalizeVerified(
|
|
710
|
+
const verification = normalizeVerified(
|
|
711
|
+
frontmatter.verified,
|
|
712
|
+
hasOwn(frontmatter, "verified"),
|
|
713
|
+
diagnostics,
|
|
714
|
+
);
|
|
521
715
|
const lifecycle = normalizeLifecycle(frontmatter, asOf, diagnostics);
|
|
522
|
-
|
|
716
|
+
// Where the document lives, for messages that must point an operator at it.
|
|
717
|
+
const location = document && typeof document.path === "string" ? document.path : null;
|
|
718
|
+
const computation = normalizeAttestedComputation(frontmatter, body, diagnostics, location);
|
|
523
719
|
|
|
524
720
|
return {
|
|
525
721
|
raw: frontmatter,
|