@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/search.js
CHANGED
|
@@ -1,254 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { resolveConcept } = require("./indexer");
|
|
6
|
-
const { normalizeSearchQuery, prepareSearchIndex } = require("./search-index");
|
|
7
|
-
|
|
8
|
-
const MAX_COMPACT_TEXT = 500;
|
|
9
|
-
|
|
10
|
-
function lower(value) {
|
|
11
|
-
return String(value || "").toLowerCase();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function compactText(value) {
|
|
15
|
-
const text = String(value || "");
|
|
16
|
-
return text.length > MAX_COMPACT_TEXT ? `${text.slice(0, MAX_COMPACT_TEXT - 1)}…` : text;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function compactConceptSummary(doc) {
|
|
20
|
-
return {
|
|
21
|
-
uri: doc.uri,
|
|
22
|
-
title: compactText(doc.title),
|
|
23
|
-
type: compactText(doc.type),
|
|
24
|
-
description: compactText(doc.description),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function asArray(value) {
|
|
29
|
-
if (value === undefined || value === null) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
return Array.isArray(value) ? value : [value];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function frontmatterMatches(frontmatter, filters) {
|
|
36
|
-
const entries = Object.entries(filters || {});
|
|
37
|
-
return entries.every(([key, expected]) => {
|
|
38
|
-
const actual = frontmatter[key];
|
|
39
|
-
if (Array.isArray(actual)) {
|
|
40
|
-
return actual.map(String).some((entry) => lower(entry) === lower(expected));
|
|
41
|
-
}
|
|
42
|
-
return lower(actual) === lower(expected);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function docText(doc) {
|
|
47
|
-
return [
|
|
48
|
-
doc.title,
|
|
49
|
-
doc.description,
|
|
50
|
-
doc.type,
|
|
51
|
-
doc.path,
|
|
52
|
-
doc.tags.join(" "),
|
|
53
|
-
doc.aliases.join(" "),
|
|
54
|
-
doc.body,
|
|
55
|
-
].join("\n");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function snippetFor(doc, terms) {
|
|
59
|
-
if (!terms.length) {
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
const text = docText(doc).replace(/\s+/g, " ");
|
|
63
|
-
const normalized = lower(text);
|
|
64
|
-
let idx = -1;
|
|
65
|
-
let matchedLength = 0;
|
|
66
|
-
terms.forEach((term) => {
|
|
67
|
-
const candidate = normalized.indexOf(lower(term));
|
|
68
|
-
if (candidate !== -1 && (idx === -1 || candidate < idx)) {
|
|
69
|
-
idx = candidate;
|
|
70
|
-
matchedLength = String(term).length;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
if (idx === -1) {
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
const start = Math.max(0, idx - 50);
|
|
77
|
-
return text.slice(start, idx + matchedLength + 80).trim();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function linkedSets(index) {
|
|
81
|
-
const outbound = new Map();
|
|
82
|
-
const inbound = new Map();
|
|
83
|
-
index.edges.filter((edge) => !edge.broken).forEach((edge) => {
|
|
84
|
-
if (!outbound.has(edge.source)) {
|
|
85
|
-
outbound.set(edge.source, new Set());
|
|
86
|
-
}
|
|
87
|
-
if (!inbound.has(edge.target)) {
|
|
88
|
-
inbound.set(edge.target, new Set());
|
|
89
|
-
}
|
|
90
|
-
outbound.get(edge.source).add(edge.target);
|
|
91
|
-
inbound.get(edge.target).add(edge.source);
|
|
92
|
-
});
|
|
93
|
-
return { outbound, inbound };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function signalsForDoc(doc, asOf) {
|
|
97
|
-
if (!asOf) {
|
|
98
|
-
return doc.signals || {};
|
|
99
|
-
}
|
|
100
|
-
const signals = normalizeV02Signals(doc, { asOf });
|
|
101
|
-
if (signals.computation && doc.signals && doc.signals.computation) {
|
|
102
|
-
signals.computation.structuralReady = signals.computation.ready;
|
|
103
|
-
signals.computation.assetsReady = doc.signals.computation.assetsReady;
|
|
104
|
-
signals.computation.attestationReady = Boolean(
|
|
105
|
-
signals.computation.structuralReady && signals.computation.assetsReady,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
return signals;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function applyFilters(index, options) {
|
|
112
|
-
const config = options || {};
|
|
113
|
-
const typeFilters = asArray(config.types || config.type).map(lower);
|
|
114
|
-
const tagsAny = asArray(config.tagsAny || config.tag).map(lower);
|
|
115
|
-
const tagsAll = asArray(config.tagsAll).map(lower);
|
|
116
|
-
const statuses = asArray(config.statuses || config.status).map(lower);
|
|
117
|
-
const trustTiers = asArray(config.trustTiers || config.trustTier).map(lower);
|
|
118
|
-
const freshness = asArray(config.freshness).map(lower);
|
|
119
|
-
const linkedToDoc = resolveConcept(index, config.linkedTo);
|
|
120
|
-
const linkedFromDoc = resolveConcept(index, config.linkedFrom);
|
|
121
|
-
const linkedTo = linkedToDoc ? linkedToDoc.uri : config.linkedTo;
|
|
122
|
-
const linkedFrom = linkedFromDoc ? linkedFromDoc.uri : config.linkedFrom;
|
|
123
|
-
const { outbound, inbound } = linkedSets(index);
|
|
124
|
-
return index.concepts.filter((doc) => {
|
|
125
|
-
const signals = signalsForDoc(doc, config.asOf);
|
|
126
|
-
if (config.bundle && doc.bundle !== config.bundle) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
if (config.pathPrefix && !doc.path.startsWith(config.pathPrefix)) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
if (typeFilters.length && !typeFilters.includes(lower(doc.type))) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
const docTags = doc.tags.map(lower);
|
|
136
|
-
if (tagsAny.length && !tagsAny.some((tag) => docTags.includes(tag))) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (tagsAll.length && !tagsAll.every((tag) => docTags.includes(tag))) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (config.frontmatter && !frontmatterMatches(doc.frontmatter, config.frontmatter)) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
if (linkedTo && !(outbound.get(doc.uri) || new Set()).has(linkedTo)) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
if (linkedFrom && !(inbound.get(doc.uri) || new Set()).has(linkedFrom)) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
if (config.orphanOnly && ((outbound.get(doc.uri) || new Set()).size > 0 || (inbound.get(doc.uri) || new Set()).size > 0)) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
if (config.relationType) {
|
|
155
|
-
const hasRelation = index.edges.some((edge) => (
|
|
156
|
-
!edge.broken &&
|
|
157
|
-
edge.source === doc.uri &&
|
|
158
|
-
edge.kind === "relation" &&
|
|
159
|
-
lower(edge.relationType) === lower(config.relationType)
|
|
160
|
-
));
|
|
161
|
-
if (!hasRelation) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (statuses.length && !statuses.includes(lower(signals.status))) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
if (trustTiers.length && !trustTiers.includes(lower(signals.trustTier))) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
if (freshness.length && !freshness.includes(lower(signals.freshness))) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
if (config.hasSources !== undefined && Boolean(signals.sources && signals.sources.length) !== config.hasSources) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
if (config.runtime && lower(signals.computation && signals.computation.runtime) !== lower(config.runtime)) {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
if (config.attestationReady !== undefined
|
|
181
|
-
&& Boolean(signals.computation && signals.computation.attestationReady) !== config.attestationReady) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
if (config.generatedBy && lower(signals.generated && signals.generated.by) !== lower(config.generatedBy)) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if (config.verifiedBy && !(signals.verifiedEvents || []).some((event) => lower(event.by) === lower(config.verifiedBy))) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function compareDocs(left, right) {
|
|
195
|
-
return left.path.localeCompare(right.path) || left.uri.localeCompare(right.uri);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function searchConcepts(index, options) {
|
|
199
|
-
const config = options || {};
|
|
200
|
-
const { query, terms } = normalizeSearchQuery(config.query);
|
|
201
|
-
const limit = Math.max(1, Math.min(Number(config.limit || 25), 250));
|
|
202
|
-
const offset = Math.max(0, Number(config.offset || 0));
|
|
203
|
-
const filteredDocs = applyFilters(index, config);
|
|
204
|
-
let results;
|
|
205
|
-
if (query) {
|
|
206
|
-
if (!terms.length) {
|
|
207
|
-
results = [];
|
|
208
|
-
} else {
|
|
209
|
-
const docsByUri = new Map(filteredDocs.map((doc) => [doc.uri, doc]));
|
|
210
|
-
const allowedUris = new Set(docsByUri.keys());
|
|
211
|
-
results = prepareSearchIndex(index).search(query, {
|
|
212
|
-
filter: (result) => allowedUris.has(String(result.id)),
|
|
213
|
-
}).map((result) => ({
|
|
214
|
-
doc: docsByUri.get(String(result.id)),
|
|
215
|
-
score: result.score,
|
|
216
|
-
})).filter((entry) => Boolean(entry.doc));
|
|
217
|
-
results.sort((a, b) => b.score - a.score || compareDocs(a.doc, b.doc));
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
results = filteredDocs.map((doc) => ({ doc, score: 0 }));
|
|
221
|
-
results.sort((a, b) => compareDocs(a.doc, b.doc));
|
|
222
|
-
}
|
|
223
|
-
const page = results.slice(offset, offset + limit).map((entry) => {
|
|
224
|
-
if (config.detail === "compact") {
|
|
225
|
-
return compactConceptSummary(entry.doc);
|
|
226
|
-
}
|
|
227
|
-
const summary = conceptSummary(entry.doc);
|
|
228
|
-
if (config.asOf) {
|
|
229
|
-
const signals = signalsForDoc(entry.doc, config.asOf);
|
|
230
|
-
summary.signals = Object.assign({}, summary.signals, {
|
|
231
|
-
status: signals.status,
|
|
232
|
-
staleAfter: signals.staleAfter,
|
|
233
|
-
freshness: signals.freshness,
|
|
234
|
-
asOf: signals.asOf,
|
|
235
|
-
trustTier: signals.trustTier,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
return Object.assign(summary, {
|
|
239
|
-
score: entry.score,
|
|
240
|
-
snippet: snippetFor(entry.doc, terms),
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
return {
|
|
244
|
-
total: results.length,
|
|
245
|
-
limit,
|
|
246
|
-
offset,
|
|
247
|
-
results: page,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
module.exports = {
|
|
252
|
-
applyFilters,
|
|
253
|
-
searchConcepts,
|
|
254
|
-
};
|
|
3
|
+
// Kept through 1.0 as a shim (plan section 6); the query layer lives in search/query.js.
|
|
4
|
+
module.exports = require("./search/query");
|
package/src/store.js
CHANGED
|
@@ -61,7 +61,10 @@ function writeJson(filePath, value) {
|
|
|
61
61
|
`.${path.basename(filePath)}.${process.pid}.${crypto.randomBytes(6).toString("hex")}.tmp`,
|
|
62
62
|
);
|
|
63
63
|
try {
|
|
64
|
-
fs.writeFileSync(temporaryPath, JSON.stringify(value, null, 2) + "\n", {
|
|
64
|
+
fs.writeFileSync(temporaryPath, JSON.stringify(value, null, 2) + "\n", {
|
|
65
|
+
encoding: "utf8",
|
|
66
|
+
flag: "wx",
|
|
67
|
+
});
|
|
65
68
|
fs.renameSync(temporaryPath, filePath);
|
|
66
69
|
} finally {
|
|
67
70
|
if (fs.existsSync(temporaryPath)) {
|
|
@@ -108,7 +111,9 @@ function isInside(root, candidate) {
|
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
function normalizeBundleFilePath(value) {
|
|
111
|
-
const raw = String(value || "")
|
|
114
|
+
const raw = String(value || "")
|
|
115
|
+
.trim()
|
|
116
|
+
.replace(/\\/g, "/");
|
|
112
117
|
if (!raw || raw.startsWith("/") || raw.includes("\0")) {
|
|
113
118
|
throw new Error("Bundle file path must be a safe relative path.");
|
|
114
119
|
}
|
|
@@ -134,10 +139,14 @@ function rejectSymlinkTraversal(realRoot, relativePath, label) {
|
|
|
134
139
|
throw error;
|
|
135
140
|
}
|
|
136
141
|
if (stat.isSymbolicLink()) {
|
|
137
|
-
throw new Error(
|
|
142
|
+
throw new Error(
|
|
143
|
+
`${label || "Concept path"} cannot traverse a symbolic link: ${segments.slice(0, index + 1).join("/")}`,
|
|
144
|
+
);
|
|
138
145
|
}
|
|
139
146
|
if (index < segments.length - 1 && !stat.isDirectory()) {
|
|
140
|
-
throw new Error(
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Concept path parent is not a directory: ${segments.slice(0, index + 1).join("/")}`,
|
|
149
|
+
);
|
|
141
150
|
}
|
|
142
151
|
const resolved = fs.realpathSync(current);
|
|
143
152
|
if (!isInside(realRoot, resolved)) {
|
|
@@ -155,17 +164,17 @@ class FileConceptStore {
|
|
|
155
164
|
this.strictLinks = Boolean(options.strictLinks || (this.project && this.project.strictLinks));
|
|
156
165
|
this.projectRoot = this.project ? fs.realpathSync(this.project.root) : null;
|
|
157
166
|
const configuredProposalRoot = options.proposalRoot || ".okf-proposals";
|
|
158
|
-
this.proposalRoot = path.resolve(
|
|
159
|
-
this.projectRoot || process.cwd(),
|
|
160
|
-
configuredProposalRoot,
|
|
161
|
-
);
|
|
167
|
+
this.proposalRoot = path.resolve(this.projectRoot || process.cwd(), configuredProposalRoot);
|
|
162
168
|
if (this.projectRoot) {
|
|
163
169
|
const relative = path.relative(this.projectRoot, this.proposalRoot);
|
|
164
170
|
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
165
171
|
throw new Error("Proposal root must be a dedicated directory inside the project root.");
|
|
166
172
|
}
|
|
167
173
|
rejectSymlinkTraversal(this.projectRoot, relative.replace(/\\/g, "/"), "Proposal root");
|
|
168
|
-
} else if (
|
|
174
|
+
} else if (
|
|
175
|
+
fs.existsSync(this.proposalRoot) &&
|
|
176
|
+
fs.lstatSync(this.proposalRoot).isSymbolicLink()
|
|
177
|
+
) {
|
|
169
178
|
throw new Error("Proposal root cannot be a symbolic link.");
|
|
170
179
|
}
|
|
171
180
|
this.proposalLocks = new Map();
|
|
@@ -175,7 +184,9 @@ class FileConceptStore {
|
|
|
175
184
|
static fromProject(projectPath, options) {
|
|
176
185
|
const project = loadProjectConfig(projectPath);
|
|
177
186
|
if (project.errors.length) {
|
|
178
|
-
throw new Error(
|
|
187
|
+
throw new Error(
|
|
188
|
+
"Cannot configure writable concept storage from an invalid project configuration.",
|
|
189
|
+
);
|
|
179
190
|
}
|
|
180
191
|
return new FileConceptStore({
|
|
181
192
|
project,
|
|
@@ -192,9 +203,10 @@ class FileConceptStore {
|
|
|
192
203
|
if (!fs.statSync(root).isDirectory()) {
|
|
193
204
|
throw new Error("Writable OKF root must be an existing directory.");
|
|
194
205
|
}
|
|
195
|
-
const id =
|
|
196
|
-
.
|
|
197
|
-
|
|
206
|
+
const id =
|
|
207
|
+
String((options && options.id) || path.basename(root) || "bundle")
|
|
208
|
+
.replace(/[^A-Za-z0-9_.-]+/g, "-")
|
|
209
|
+
.replace(/^-+|-+$/g, "") || "bundle";
|
|
198
210
|
const bundles = [{ id, root, include: [], exclude: [] }];
|
|
199
211
|
const project = {
|
|
200
212
|
project: id,
|
|
@@ -370,7 +382,8 @@ class FileConceptStore {
|
|
|
370
382
|
if (!fs.existsSync(root)) {
|
|
371
383
|
return [];
|
|
372
384
|
}
|
|
373
|
-
return fs
|
|
385
|
+
return fs
|
|
386
|
+
.readdirSync(root)
|
|
374
387
|
.filter((name) => name.endsWith(".json"))
|
|
375
388
|
.sort()
|
|
376
389
|
.map((name) => path.join(root, name));
|
|
@@ -396,9 +409,12 @@ class FileConceptStore {
|
|
|
396
409
|
message: input.message || "",
|
|
397
410
|
validation: input.validation || null,
|
|
398
411
|
assetFiles: Array.isArray(input.assetFiles) ? input.assetFiles : [],
|
|
399
|
-
dependencyRevisions: Array.isArray(input.dependencyRevisions)
|
|
412
|
+
dependencyRevisions: Array.isArray(input.dependencyRevisions)
|
|
413
|
+
? input.dependencyRevisions
|
|
414
|
+
: [],
|
|
400
415
|
migrationId: input.migrationId || null,
|
|
401
416
|
prerequisites: Array.isArray(input.prerequisites) ? input.prerequisites : [],
|
|
417
|
+
...(input.proposedBy ? { proposedBy: input.proposedBy } : {}),
|
|
402
418
|
createdAt: timestamp,
|
|
403
419
|
updatedAt: timestamp,
|
|
404
420
|
};
|
|
@@ -408,28 +424,31 @@ class FileConceptStore {
|
|
|
408
424
|
|
|
409
425
|
async listProposals(filters) {
|
|
410
426
|
const options = filters || {};
|
|
411
|
-
return this.listProposalFiles()
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
427
|
+
return this.listProposalFiles()
|
|
428
|
+
.map(readJson)
|
|
429
|
+
.filter((proposal) => {
|
|
430
|
+
if (options.bundle && proposal.bundle !== options.bundle) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
if (options.status && proposal.status !== options.status) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
return true;
|
|
437
|
+
})
|
|
438
|
+
.map((proposal) => ({
|
|
439
|
+
id: proposal.id,
|
|
440
|
+
status: proposal.status,
|
|
441
|
+
op: proposal.op || "create",
|
|
442
|
+
targetUri: proposal.targetUri || null,
|
|
443
|
+
bundle: proposal.bundle,
|
|
444
|
+
path: proposal.path,
|
|
445
|
+
uri: proposal.uri,
|
|
446
|
+
message: proposal.message,
|
|
447
|
+
assetFileCount: Array.isArray(proposal.assetFiles) ? proposal.assetFiles.length : 0,
|
|
448
|
+
migrationId: proposal.migrationId || null,
|
|
449
|
+
createdAt: proposal.createdAt,
|
|
450
|
+
updatedAt: proposal.updatedAt,
|
|
451
|
+
}));
|
|
433
452
|
}
|
|
434
453
|
|
|
435
454
|
async getProposal(id) {
|
|
@@ -456,15 +475,18 @@ class FileConceptStore {
|
|
|
456
475
|
return {
|
|
457
476
|
accepted: false,
|
|
458
477
|
conflict: true,
|
|
459
|
-
message:
|
|
478
|
+
message:
|
|
479
|
+
"The concept changed after this update was proposed. Create a new proposal from the current concept.",
|
|
460
480
|
proposal,
|
|
461
481
|
};
|
|
462
482
|
}
|
|
463
483
|
|
|
464
484
|
async acceptProposal(id, authoringService, options) {
|
|
465
|
-
return this.withWriteLock(() =>
|
|
466
|
-
this.withProposalLock(id, (canonicalId) =>
|
|
467
|
-
|
|
485
|
+
return this.withWriteLock(() =>
|
|
486
|
+
this.withProposalLock(id, (canonicalId) =>
|
|
487
|
+
this.acceptProposalUnlocked(canonicalId, authoringService, options),
|
|
488
|
+
),
|
|
489
|
+
);
|
|
468
490
|
}
|
|
469
491
|
|
|
470
492
|
async acceptProposalUnlocked(id, authoringService, options) {
|
|
@@ -477,13 +499,17 @@ class FileConceptStore {
|
|
|
477
499
|
throw new Error(`Unsupported proposal operation: ${op}`);
|
|
478
500
|
}
|
|
479
501
|
if (op === "create_computation" && !(options && options.allowComputation)) {
|
|
480
|
-
throw new Error(
|
|
502
|
+
throw new Error(
|
|
503
|
+
"Accepting an Attested Computation proposal requires the computation-authoring capability.",
|
|
504
|
+
);
|
|
481
505
|
}
|
|
482
506
|
if (op === "migration_index") {
|
|
483
507
|
for (const prerequisite of proposal.prerequisites || []) {
|
|
484
508
|
const required = await this.getProposal(prerequisite);
|
|
485
509
|
if (required.status !== "accepted") {
|
|
486
|
-
throw new Error(
|
|
510
|
+
throw new Error(
|
|
511
|
+
`Migration index proposal requires accepted child proposal: ${prerequisite}`,
|
|
512
|
+
);
|
|
487
513
|
}
|
|
488
514
|
}
|
|
489
515
|
const target = this.resolveBundleFile(proposal.bundle, proposal.path);
|
|
@@ -534,9 +560,9 @@ class FileConceptStore {
|
|
|
534
560
|
}
|
|
535
561
|
existing = authoringService.resolveConcept(proposal.targetUri);
|
|
536
562
|
if (
|
|
537
|
-
proposal.bundle !== existing.bundle
|
|
538
|
-
|
|
539
|
-
|
|
563
|
+
proposal.bundle !== existing.bundle ||
|
|
564
|
+
proposal.path !== existing.path ||
|
|
565
|
+
proposal.targetPathUri !== existing.pathUri
|
|
540
566
|
) {
|
|
541
567
|
throw new Error("Update proposal target does not match the current concept identity.");
|
|
542
568
|
}
|
|
@@ -547,29 +573,35 @@ class FileConceptStore {
|
|
|
547
573
|
frontmatter: proposal.frontmatter,
|
|
548
574
|
body: proposal.body,
|
|
549
575
|
};
|
|
550
|
-
const validation =
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
576
|
+
const validation =
|
|
577
|
+
op === "update"
|
|
578
|
+
? authoringService.validateUpdateCandidate(candidate, existing)
|
|
579
|
+
: op === "create_computation"
|
|
580
|
+
? authoringService.validateAttestedComputation(candidate, {
|
|
581
|
+
assetFiles: proposal.assetFiles || [],
|
|
582
|
+
accepting: true,
|
|
583
|
+
})
|
|
584
|
+
: authoringService.validateConcept(candidate);
|
|
558
585
|
if (!validation.valid) {
|
|
559
586
|
proposal.validation = validation;
|
|
560
587
|
this.saveExistingProposal(proposal);
|
|
561
588
|
return { accepted: false, proposal, validation };
|
|
562
589
|
}
|
|
563
590
|
if (op === "create_computation") {
|
|
564
|
-
const normalizeDependencies = (entries) =>
|
|
565
|
-
.
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
591
|
+
const normalizeDependencies = (entries) =>
|
|
592
|
+
(Array.isArray(entries) ? entries : [])
|
|
593
|
+
.map((entry) => ({
|
|
594
|
+
field: entry.field,
|
|
595
|
+
bundle: entry.bundle,
|
|
596
|
+
path: entry.path,
|
|
597
|
+
bytes: entry.bytes,
|
|
598
|
+
revision: entry.revision,
|
|
599
|
+
}))
|
|
600
|
+
.sort((left, right) =>
|
|
601
|
+
`${left.field}\u0000${left.bundle}\u0000${left.path}`.localeCompare(
|
|
602
|
+
`${right.field}\u0000${right.bundle}\u0000${right.path}`,
|
|
603
|
+
),
|
|
604
|
+
);
|
|
573
605
|
const expectedDependencies = normalizeDependencies(proposal.dependencyRevisions);
|
|
574
606
|
const actualDependencies = normalizeDependencies(validation.dependencyRevisions);
|
|
575
607
|
if (JSON.stringify(expectedDependencies) !== JSON.stringify(actualDependencies)) {
|
|
@@ -584,7 +616,8 @@ class FileConceptStore {
|
|
|
584
616
|
return {
|
|
585
617
|
accepted: false,
|
|
586
618
|
conflict: true,
|
|
587
|
-
message:
|
|
619
|
+
message:
|
|
620
|
+
"A referenced computation dependency changed after review. Create a new proposal from the current artifacts.",
|
|
588
621
|
proposal,
|
|
589
622
|
validation,
|
|
590
623
|
};
|
|
@@ -598,7 +631,11 @@ class FileConceptStore {
|
|
|
598
631
|
}
|
|
599
632
|
const safeTarget = this.resolveConceptFile(proposal.bundle, proposal.path);
|
|
600
633
|
const originalText = fs.readFileSync(safeTarget.absolutePath, "utf8");
|
|
601
|
-
const write = writeFileAtomic(
|
|
634
|
+
const write = writeFileAtomic(
|
|
635
|
+
safeTarget.absolutePath,
|
|
636
|
+
validation.markdown,
|
|
637
|
+
proposal.baseRevision,
|
|
638
|
+
);
|
|
602
639
|
if (!write.written) {
|
|
603
640
|
return this.markProposalConflict(proposal, write.currentRevision);
|
|
604
641
|
}
|
|
@@ -609,7 +646,9 @@ class FileConceptStore {
|
|
|
609
646
|
revisionFor(validation.markdown),
|
|
610
647
|
);
|
|
611
648
|
if (!rollback.written) {
|
|
612
|
-
throw new Error(
|
|
649
|
+
throw new Error(
|
|
650
|
+
"Could not roll back an update after proposal status persistence failed.",
|
|
651
|
+
);
|
|
613
652
|
}
|
|
614
653
|
};
|
|
615
654
|
} else if (op === "create_computation") {
|
|
@@ -622,7 +661,9 @@ class FileConceptStore {
|
|
|
622
661
|
});
|
|
623
662
|
const staged = [];
|
|
624
663
|
const written = [];
|
|
625
|
-
const allTargets = assetTargets.concat([
|
|
664
|
+
const allTargets = assetTargets.concat([
|
|
665
|
+
{ relativePath, absolutePath, content: validation.markdown },
|
|
666
|
+
]);
|
|
626
667
|
const uniqueTargets = new Set(allTargets.map((target) => path.resolve(target.absolutePath)));
|
|
627
668
|
if (uniqueTargets.size !== allTargets.length) {
|
|
628
669
|
throw new Error("Computation proposal targets must resolve to distinct files.");
|
|
@@ -642,11 +683,14 @@ class FileConceptStore {
|
|
|
642
683
|
written.push(target.absolutePath);
|
|
643
684
|
});
|
|
644
685
|
rollbackAcceptance = () => {
|
|
645
|
-
written
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
686
|
+
written
|
|
687
|
+
.slice()
|
|
688
|
+
.reverse()
|
|
689
|
+
.forEach((target) => {
|
|
690
|
+
if (fs.existsSync(target)) {
|
|
691
|
+
fs.unlinkSync(target);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
650
694
|
};
|
|
651
695
|
} catch (error) {
|
|
652
696
|
staged.forEach((target) => {
|
|
@@ -664,7 +708,10 @@ class FileConceptStore {
|
|
|
664
708
|
} else {
|
|
665
709
|
ensureDir(path.dirname(absolutePath));
|
|
666
710
|
const safeTarget = this.resolveConceptFile(proposal.bundle, proposal.path);
|
|
667
|
-
fs.writeFileSync(safeTarget.absolutePath, validation.markdown, {
|
|
711
|
+
fs.writeFileSync(safeTarget.absolutePath, validation.markdown, {
|
|
712
|
+
encoding: "utf8",
|
|
713
|
+
flag: "wx",
|
|
714
|
+
});
|
|
668
715
|
rollbackAcceptance = () => {
|
|
669
716
|
if (fs.existsSync(safeTarget.absolutePath)) {
|
|
670
717
|
fs.unlinkSync(safeTarget.absolutePath);
|
|
@@ -697,7 +744,9 @@ class FileConceptStore {
|
|
|
697
744
|
}
|
|
698
745
|
|
|
699
746
|
async rejectProposal(id, reason) {
|
|
700
|
-
return this.withProposalLock(id, (canonicalId) =>
|
|
747
|
+
return this.withProposalLock(id, (canonicalId) =>
|
|
748
|
+
this.rejectProposalUnlocked(canonicalId, reason),
|
|
749
|
+
);
|
|
701
750
|
}
|
|
702
751
|
|
|
703
752
|
async rejectProposalUnlocked(id, reason) {
|
|
@@ -715,13 +764,17 @@ class FileConceptStore {
|
|
|
715
764
|
async saveMigrationManifest(input) {
|
|
716
765
|
const id = input.id || proposalId();
|
|
717
766
|
const timestamp = nowIso();
|
|
718
|
-
const manifest = Object.assign(
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
767
|
+
const manifest = Object.assign(
|
|
768
|
+
{
|
|
769
|
+
id,
|
|
770
|
+
status: "proposed",
|
|
771
|
+
kind: "okf-v0.2-stage-a",
|
|
772
|
+
createdAt: timestamp,
|
|
773
|
+
updatedAt: timestamp,
|
|
774
|
+
},
|
|
775
|
+
input,
|
|
776
|
+
{ id },
|
|
777
|
+
);
|
|
725
778
|
writeJson(this.proposalFile(id, "migrations", true), manifest);
|
|
726
779
|
return manifest;
|
|
727
780
|
}
|