@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
|
@@ -4,7 +4,7 @@ const crypto = require("node:crypto");
|
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
6
|
|
|
7
|
-
const { splitFrontmatter } = require("./parser");
|
|
7
|
+
const { isReservedPath, splitFrontmatter } = require("./parser");
|
|
8
8
|
|
|
9
9
|
const MANIFEST_NAME = ".okf-producer.json";
|
|
10
10
|
|
|
@@ -28,7 +28,8 @@ function canonical(value) {
|
|
|
28
28
|
return encoded === undefined ? "null" : encoded;
|
|
29
29
|
}
|
|
30
30
|
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
31
|
-
return `{${Object.keys(value)
|
|
31
|
+
return `{${Object.keys(value)
|
|
32
|
+
.sort()
|
|
32
33
|
.map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`)
|
|
33
34
|
.join(",")}}`;
|
|
34
35
|
}
|
|
@@ -54,9 +55,7 @@ function stableDigest(content) {
|
|
|
54
55
|
const parsed = generatedMapping(content);
|
|
55
56
|
if (!parsed || parsed.generated.at === undefined) return sha256(content);
|
|
56
57
|
const stable = Object.assign({}, parsed.split.frontmatter, {
|
|
57
|
-
generated: Object.fromEntries(
|
|
58
|
-
Object.entries(parsed.generated).filter(([key]) => key !== "at"),
|
|
59
|
-
),
|
|
58
|
+
generated: Object.fromEntries(Object.entries(parsed.generated).filter(([key]) => key !== "at")),
|
|
60
59
|
});
|
|
61
60
|
return sha256(`${canonical(stable)}\u0000${parsed.split.body}`);
|
|
62
61
|
}
|
|
@@ -66,7 +65,9 @@ function stableDigest(content) {
|
|
|
66
65
|
// manifest lists stays on disk.
|
|
67
66
|
function hasGeneratedProvenance(content) {
|
|
68
67
|
const parsed = generatedMapping(content);
|
|
69
|
-
return Boolean(
|
|
68
|
+
return Boolean(
|
|
69
|
+
parsed && (parsed.generated.by !== undefined || parsed.generated.at !== undefined),
|
|
70
|
+
);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function isInside(root, target) {
|
|
@@ -75,40 +76,72 @@ function isInside(root, target) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
function normalizeProducedPath(value) {
|
|
78
|
-
const raw = String(value || "")
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const raw = String(value || "")
|
|
80
|
+
.trim()
|
|
81
|
+
.replace(/\\/g, "/");
|
|
82
|
+
if (
|
|
83
|
+
!raw ||
|
|
84
|
+
raw.startsWith("/") ||
|
|
85
|
+
/^[A-Za-z]:\//.test(raw) ||
|
|
86
|
+
/[\u0000-\u001f\u007f]/.test(raw)
|
|
87
|
+
) {
|
|
88
|
+
throw new ProducerPublicationError(
|
|
89
|
+
"Producer paths must be safe bundle-relative Markdown paths.",
|
|
90
|
+
"invalid_producer_path",
|
|
91
|
+
);
|
|
81
92
|
}
|
|
82
93
|
const parts = raw.split("/");
|
|
83
94
|
if (parts.some((part) => !part || part === "." || part === ".." || part.startsWith("."))) {
|
|
84
|
-
throw new ProducerPublicationError(
|
|
95
|
+
throw new ProducerPublicationError(
|
|
96
|
+
"Producer paths cannot contain empty, hidden, dot, or parent segments.",
|
|
97
|
+
"invalid_producer_path",
|
|
98
|
+
);
|
|
85
99
|
}
|
|
86
100
|
const normalized = path.posix.normalize(raw);
|
|
87
101
|
if (!normalized.toLowerCase().endsWith(".md")) {
|
|
88
|
-
throw new ProducerPublicationError(
|
|
102
|
+
throw new ProducerPublicationError(
|
|
103
|
+
"Producer output files must be Markdown documents.",
|
|
104
|
+
"invalid_producer_path",
|
|
105
|
+
);
|
|
89
106
|
}
|
|
90
107
|
return normalized;
|
|
91
108
|
}
|
|
92
109
|
|
|
93
110
|
function normalizeProducedFiles(files) {
|
|
94
111
|
if (!Array.isArray(files) || files.length === 0) {
|
|
95
|
-
throw new ProducerPublicationError(
|
|
112
|
+
throw new ProducerPublicationError(
|
|
113
|
+
"Producer generate() must return a non-empty files array.",
|
|
114
|
+
"invalid_producer_output",
|
|
115
|
+
);
|
|
96
116
|
}
|
|
97
117
|
const seen = new Set();
|
|
98
|
-
return files
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
return files
|
|
119
|
+
.map((file) => {
|
|
120
|
+
if (!file || typeof file !== "object" || Array.isArray(file)) {
|
|
121
|
+
throw new ProducerPublicationError(
|
|
122
|
+
"Each producer file must be an object.",
|
|
123
|
+
"invalid_producer_output",
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const relativePath = normalizeProducedPath(file.path);
|
|
127
|
+
if (seen.has(relativePath)) {
|
|
128
|
+
throw new ProducerPublicationError(
|
|
129
|
+
"Producer output paths must be unique.",
|
|
130
|
+
"duplicate_producer_path",
|
|
131
|
+
{ path: relativePath },
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
seen.add(relativePath);
|
|
135
|
+
if (typeof file.content !== "string") {
|
|
136
|
+
throw new ProducerPublicationError(
|
|
137
|
+
"Producer file content must be a string.",
|
|
138
|
+
"invalid_producer_content",
|
|
139
|
+
{ path: relativePath },
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return { path: relativePath, content: file.content, sha256: sha256(file.content) };
|
|
143
|
+
})
|
|
144
|
+
.sort((left, right) => left.path.localeCompare(right.path));
|
|
112
145
|
}
|
|
113
146
|
|
|
114
147
|
function assertRegularPath(root, relativePath) {
|
|
@@ -124,13 +157,25 @@ function assertRegularPath(root, relativePath) {
|
|
|
124
157
|
throw error;
|
|
125
158
|
}
|
|
126
159
|
if (stat.isSymbolicLink()) {
|
|
127
|
-
throw new ProducerPublicationError(
|
|
160
|
+
throw new ProducerPublicationError(
|
|
161
|
+
"Producer-managed paths cannot traverse symbolic links.",
|
|
162
|
+
"producer_path_symlink",
|
|
163
|
+
{ path: parts.slice(0, index + 1).join("/") },
|
|
164
|
+
);
|
|
128
165
|
}
|
|
129
166
|
if (index < parts.length - 1 && !stat.isDirectory()) {
|
|
130
|
-
throw new ProducerPublicationError(
|
|
167
|
+
throw new ProducerPublicationError(
|
|
168
|
+
"A producer-managed path parent is not a directory.",
|
|
169
|
+
"producer_path_parent_not_directory",
|
|
170
|
+
{ path: parts.slice(0, index + 1).join("/") },
|
|
171
|
+
);
|
|
131
172
|
}
|
|
132
173
|
if (index === parts.length - 1 && !stat.isFile()) {
|
|
133
|
-
throw new ProducerPublicationError(
|
|
174
|
+
throw new ProducerPublicationError(
|
|
175
|
+
"Producer-managed files must be regular files.",
|
|
176
|
+
"producer_path_not_file",
|
|
177
|
+
{ path: relativePath },
|
|
178
|
+
);
|
|
134
179
|
}
|
|
135
180
|
});
|
|
136
181
|
}
|
|
@@ -145,17 +190,35 @@ function readManifest(root, producer) {
|
|
|
145
190
|
content = fs.readFileSync(manifestPath);
|
|
146
191
|
manifest = JSON.parse(content.toString("utf8"));
|
|
147
192
|
} catch {
|
|
148
|
-
throw new ProducerPublicationError(
|
|
193
|
+
throw new ProducerPublicationError(
|
|
194
|
+
"The producer ownership manifest is invalid.",
|
|
195
|
+
"invalid_producer_manifest",
|
|
196
|
+
);
|
|
149
197
|
}
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
198
|
+
if (
|
|
199
|
+
!manifest ||
|
|
200
|
+
manifest.version !== 1 ||
|
|
201
|
+
manifest.producer !== producer.type ||
|
|
202
|
+
manifest.bundle !== producer.bundle ||
|
|
203
|
+
!Array.isArray(manifest.files)
|
|
204
|
+
) {
|
|
205
|
+
throw new ProducerPublicationError(
|
|
206
|
+
"The producer ownership manifest does not match this configured producer.",
|
|
207
|
+
"invalid_producer_manifest",
|
|
208
|
+
);
|
|
153
209
|
}
|
|
154
210
|
const owned = new Map();
|
|
155
211
|
manifest.files.forEach((entry) => {
|
|
156
212
|
const relativePath = normalizeProducedPath(entry && entry.path);
|
|
157
|
-
if (
|
|
158
|
-
|
|
213
|
+
if (
|
|
214
|
+
owned.has(relativePath) ||
|
|
215
|
+
!entry ||
|
|
216
|
+
!/^sha256:[a-f0-9]{64}$/.test(String(entry.sha256 || ""))
|
|
217
|
+
) {
|
|
218
|
+
throw new ProducerPublicationError(
|
|
219
|
+
"The producer ownership manifest contains an invalid file entry.",
|
|
220
|
+
"invalid_producer_manifest",
|
|
221
|
+
);
|
|
159
222
|
}
|
|
160
223
|
owned.set(relativePath, String(entry.sha256));
|
|
161
224
|
});
|
|
@@ -168,11 +231,19 @@ function verifyOwnedFiles(root, owned) {
|
|
|
168
231
|
assertRegularPath(root, relativePath);
|
|
169
232
|
const absolutePath = path.join(root, ...relativePath.split("/"));
|
|
170
233
|
if (!fs.existsSync(absolutePath)) {
|
|
171
|
-
throw new ProducerPublicationError(
|
|
234
|
+
throw new ProducerPublicationError(
|
|
235
|
+
"A producer-owned file changed outside the producer.",
|
|
236
|
+
"producer_owned_file_modified",
|
|
237
|
+
{ path: relativePath },
|
|
238
|
+
);
|
|
172
239
|
}
|
|
173
240
|
const content = fs.readFileSync(absolutePath);
|
|
174
241
|
if (sha256(content) !== expected) {
|
|
175
|
-
throw new ProducerPublicationError(
|
|
242
|
+
throw new ProducerPublicationError(
|
|
243
|
+
"A producer-owned file changed outside the producer.",
|
|
244
|
+
"producer_owned_file_modified",
|
|
245
|
+
{ path: relativePath },
|
|
246
|
+
);
|
|
176
247
|
}
|
|
177
248
|
contents.set(relativePath, content);
|
|
178
249
|
});
|
|
@@ -192,7 +263,11 @@ function inspectPublication(root, producer, files) {
|
|
|
192
263
|
assertRegularPath(root, file.path);
|
|
193
264
|
const absolutePath = path.join(root, ...file.path.split("/"));
|
|
194
265
|
if (fs.existsSync(absolutePath) && !owned.has(file.path)) {
|
|
195
|
-
throw new ProducerPublicationError(
|
|
266
|
+
throw new ProducerPublicationError(
|
|
267
|
+
"Producer output collides with an unowned file.",
|
|
268
|
+
"producer_unowned_collision",
|
|
269
|
+
{ path: file.path },
|
|
270
|
+
);
|
|
196
271
|
}
|
|
197
272
|
if (!owned.has(file.path)) {
|
|
198
273
|
changes.create.push(file.path);
|
|
@@ -202,7 +277,11 @@ function inspectPublication(root, producer, files) {
|
|
|
202
277
|
const current = ownedContents.get(file.path);
|
|
203
278
|
if (owned.get(file.path) === file.sha256) {
|
|
204
279
|
changes.unchanged.push(file.path);
|
|
205
|
-
effective.set(file.path, {
|
|
280
|
+
effective.set(file.path, {
|
|
281
|
+
path: file.path,
|
|
282
|
+
sha256: owned.get(file.path),
|
|
283
|
+
content: file.content,
|
|
284
|
+
});
|
|
206
285
|
return;
|
|
207
286
|
}
|
|
208
287
|
if (current && stableDigest(current.toString("utf8")) === stableDigest(file.content)) {
|
|
@@ -220,8 +299,14 @@ function inspectPublication(root, producer, files) {
|
|
|
220
299
|
owned.forEach((_digest, relativePath) => {
|
|
221
300
|
if (!generated.has(relativePath)) changes.delete.push(relativePath);
|
|
222
301
|
});
|
|
302
|
+
// Every file rewritten or removed must have been written by a producer.
|
|
303
|
+
// verifyOwnedFiles has already proven each owned file unedited since the
|
|
304
|
+
// last publish (its bytes match the manifest digest); a concept must also
|
|
305
|
+
// carry generation provenance, but a reserved index.md or log.md cannot
|
|
306
|
+
// (OKF allows it no such frontmatter), so for those the digest is the proof.
|
|
223
307
|
changes.update.concat(changes.delete).forEach((relativePath) => {
|
|
224
308
|
const current = ownedContents.get(relativePath);
|
|
309
|
+
if (current && isReservedPath(relativePath)) return;
|
|
225
310
|
if (!current || !hasGeneratedProvenance(current.toString("utf8"))) {
|
|
226
311
|
throw new ProducerPublicationError(
|
|
227
312
|
"The ownership manifest claims a file that carries no generation provenance.",
|
|
@@ -254,7 +339,10 @@ function snapshotFile(absolutePath) {
|
|
|
254
339
|
if (!fs.existsSync(absolutePath)) return { exists: false };
|
|
255
340
|
const stat = fs.lstatSync(absolutePath);
|
|
256
341
|
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
257
|
-
throw new ProducerPublicationError(
|
|
342
|
+
throw new ProducerPublicationError(
|
|
343
|
+
"Producer-managed files must be regular files.",
|
|
344
|
+
"producer_path_not_file",
|
|
345
|
+
);
|
|
258
346
|
}
|
|
259
347
|
return { exists: true, content: fs.readFileSync(absolutePath), mode: stat.mode & 0o777 };
|
|
260
348
|
}
|
|
@@ -282,20 +370,29 @@ function assertSnapshotMatches(absolutePath, expected, relativePath) {
|
|
|
282
370
|
function ensureParent(root, absolutePath, createdDirectories) {
|
|
283
371
|
const relative = path.relative(root, path.dirname(absolutePath));
|
|
284
372
|
let current = root;
|
|
285
|
-
relative
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
373
|
+
relative
|
|
374
|
+
.split(path.sep)
|
|
375
|
+
.filter(Boolean)
|
|
376
|
+
.forEach((part) => {
|
|
377
|
+
current = path.join(current, part);
|
|
378
|
+
if (!fs.existsSync(current)) {
|
|
379
|
+
fs.mkdirSync(current);
|
|
380
|
+
createdDirectories.push(current);
|
|
381
|
+
} else if (fs.lstatSync(current).isSymbolicLink() || !fs.statSync(current).isDirectory()) {
|
|
382
|
+
throw new ProducerPublicationError(
|
|
383
|
+
"Producer output parents must be ordinary directories.",
|
|
384
|
+
"producer_path_parent_not_directory",
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
294
388
|
}
|
|
295
389
|
|
|
296
390
|
function atomicWrite(root, absolutePath, content, createdDirectories) {
|
|
297
391
|
ensureParent(root, absolutePath, createdDirectories);
|
|
298
|
-
const temporaryPath = path.join(
|
|
392
|
+
const temporaryPath = path.join(
|
|
393
|
+
path.dirname(absolutePath),
|
|
394
|
+
`.${path.basename(absolutePath)}.${process.pid}.${crypto.randomBytes(6).toString("hex")}.tmp`,
|
|
395
|
+
);
|
|
299
396
|
try {
|
|
300
397
|
fs.writeFileSync(temporaryPath, content, { flag: "wx" });
|
|
301
398
|
fs.renameSync(temporaryPath, absolutePath);
|
|
@@ -306,19 +403,21 @@ function atomicWrite(root, absolutePath, content, createdDirectories) {
|
|
|
306
403
|
|
|
307
404
|
function restoreFiles(root, snapshots, published, createdDirectories) {
|
|
308
405
|
const conflicts = [];
|
|
309
|
-
Array.from(published.entries())
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
406
|
+
Array.from(published.entries())
|
|
407
|
+
.reverse()
|
|
408
|
+
.forEach(([absolutePath, expected]) => {
|
|
409
|
+
const snapshot = snapshots.get(absolutePath);
|
|
410
|
+
if (!snapshotMatches(absolutePath, expected)) {
|
|
411
|
+
conflicts.push(path.relative(root, absolutePath).replace(/\\/g, "/"));
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (snapshot.exists) {
|
|
415
|
+
atomicWrite(root, absolutePath, snapshot.content, []);
|
|
416
|
+
fs.chmodSync(absolutePath, snapshot.mode);
|
|
417
|
+
} else if (fs.existsSync(absolutePath) && fs.lstatSync(absolutePath).isFile()) {
|
|
418
|
+
fs.unlinkSync(absolutePath);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
322
421
|
createdDirectories.reverse().forEach((directory) => {
|
|
323
422
|
try {
|
|
324
423
|
fs.rmdirSync(directory);
|
|
@@ -339,9 +438,11 @@ function pruneEmptyDirectories(root, relativePaths) {
|
|
|
339
438
|
const visited = new Set();
|
|
340
439
|
relativePaths.forEach((relativePath) => {
|
|
341
440
|
let current = path.dirname(path.join(root, ...relativePath.split("/")));
|
|
342
|
-
while (
|
|
343
|
-
|
|
344
|
-
|
|
441
|
+
while (
|
|
442
|
+
isInside(root, current) &&
|
|
443
|
+
path.resolve(current) !== path.resolve(root) &&
|
|
444
|
+
!visited.has(current)
|
|
445
|
+
) {
|
|
345
446
|
visited.add(current);
|
|
346
447
|
try {
|
|
347
448
|
if (fs.readdirSync(current).length > 0) break;
|
|
@@ -362,7 +463,11 @@ class ProducerPublisher {
|
|
|
362
463
|
|
|
363
464
|
bundleRoot(bundleId) {
|
|
364
465
|
const bundle = this.project.bundles.find((entry) => entry.id === bundleId && !entry.remote);
|
|
365
|
-
if (!bundle)
|
|
466
|
+
if (!bundle)
|
|
467
|
+
throw new ProducerPublicationError(
|
|
468
|
+
"Configured producer bundle is unavailable.",
|
|
469
|
+
"unknown_producer_bundle",
|
|
470
|
+
);
|
|
366
471
|
return this.store.resolveWritableBundleRoot(bundle);
|
|
367
472
|
}
|
|
368
473
|
|
|
@@ -376,18 +481,25 @@ class ProducerPublisher {
|
|
|
376
481
|
const root = inspection.root;
|
|
377
482
|
const manifestPath = path.join(root, MANIFEST_NAME);
|
|
378
483
|
const manifestContent = `${JSON.stringify(manifestFor(producer, inspection.effective), null, 2)}\n`;
|
|
379
|
-
const changedPaths = inspection.changes.create
|
|
380
|
-
|
|
381
|
-
|
|
484
|
+
const changedPaths = inspection.changes.create.concat(
|
|
485
|
+
inspection.changes.update,
|
|
486
|
+
inspection.changes.delete,
|
|
487
|
+
);
|
|
488
|
+
if (
|
|
489
|
+
changedPaths.length === 0 &&
|
|
490
|
+
inspection.previousManifestSha256 === sha256(manifestContent)
|
|
491
|
+
) {
|
|
382
492
|
if (validatePersisted) await validatePersisted();
|
|
383
493
|
return inspection.changes;
|
|
384
494
|
}
|
|
385
495
|
const touched = new Set(changedPaths.concat(MANIFEST_NAME));
|
|
386
496
|
const snapshots = new Map();
|
|
387
|
-
touched.forEach((relativePath) =>
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
497
|
+
touched.forEach((relativePath) =>
|
|
498
|
+
snapshots.set(
|
|
499
|
+
path.join(root, ...relativePath.split("/")),
|
|
500
|
+
snapshotFile(path.join(root, ...relativePath.split("/"))),
|
|
501
|
+
),
|
|
502
|
+
);
|
|
391
503
|
inspection.changes.create.forEach((relativePath) => {
|
|
392
504
|
assertSnapshotMatches(
|
|
393
505
|
path.join(root, ...relativePath.split("/")),
|
|
@@ -408,11 +520,20 @@ class ProducerPublisher {
|
|
|
408
520
|
});
|
|
409
521
|
const manifestSnapshot = snapshots.get(manifestPath);
|
|
410
522
|
if (inspection.previousManifestSha256) {
|
|
411
|
-
if (
|
|
412
|
-
|
|
523
|
+
if (
|
|
524
|
+
!manifestSnapshot.exists ||
|
|
525
|
+
sha256(manifestSnapshot.content) !== inspection.previousManifestSha256
|
|
526
|
+
) {
|
|
527
|
+
throw new ProducerPublicationError(
|
|
528
|
+
"The producer ownership manifest changed during publication.",
|
|
529
|
+
"producer_publication_conflict",
|
|
530
|
+
);
|
|
413
531
|
}
|
|
414
532
|
} else if (manifestSnapshot.exists) {
|
|
415
|
-
throw new ProducerPublicationError(
|
|
533
|
+
throw new ProducerPublicationError(
|
|
534
|
+
"The producer ownership manifest changed during publication.",
|
|
535
|
+
"producer_publication_conflict",
|
|
536
|
+
);
|
|
416
537
|
}
|
|
417
538
|
const createdDirectories = [];
|
|
418
539
|
const published = new Map();
|
|
@@ -442,7 +563,10 @@ class ProducerPublisher {
|
|
|
442
563
|
restoreFiles(root, snapshots, published, createdDirectories);
|
|
443
564
|
} catch (rollbackError) {
|
|
444
565
|
if (rollbackError instanceof ProducerPublicationError) throw rollbackError;
|
|
445
|
-
throw new ProducerPublicationError(
|
|
566
|
+
throw new ProducerPublicationError(
|
|
567
|
+
"Producer publication failed and rollback could not be completed.",
|
|
568
|
+
"producer_rollback_failed",
|
|
569
|
+
);
|
|
446
570
|
}
|
|
447
571
|
throw error;
|
|
448
572
|
}
|