@hyperframes/share 0.9.91 → 0.9.93
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/README.md +1 -1
- package/dist/host.d.mts +1 -0
- package/dist/hosts.d.ts +2 -0
- package/dist/reviewShare.d.mts +5 -1
- package/dist/sources/manifest.d.mts +21 -0
- package/dist/sources/pathPolicy.d.mts +9 -4
- package/dist/sources/types.d.ts +6 -1
- package/dist/sources/unicode.d.mts +4 -2
- package/package.json +4 -1
- package/src/host.mjs +2 -0
- package/src/hosts.d.ts +2 -0
- package/src/reviewShare.mjs +30 -4
- package/src/reviewSwitch.mjs +17 -9
- package/src/sources/capture.mjs +8 -0
- package/src/sources/contract/path-policy.json +183 -16
- package/src/sources/manifest.mjs +67 -17
- package/src/sources/pathPolicy.mjs +94 -33
- package/src/sources/store.mjs +5 -8
- package/src/sources/types.d.ts +6 -1
- package/src/sources/unicode.mjs +24 -3
- package/src/sources/upload.mjs +15 -7
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ can use video-only; changed source, conflicts and unexpected upload failures nee
|
|
|
78
78
|
an explicit choice to omit source. The CLI exposes `--video-only` for that choice.
|
|
79
79
|
`filesForExport` only validates already-prepared source; it does not upload.
|
|
80
80
|
|
|
81
|
-
The adapter uses the portable-source-
|
|
81
|
+
The adapter uses the portable-source-v11 capture/manifest rules and
|
|
82
82
|
multipart transport. The pinned policy, Unicode 15.1 registry (with its license),
|
|
83
83
|
and manifest test vectors are checked into this repository. Source is captured through
|
|
84
84
|
verified file handles; upload bytes are streamed and checked against their hash.
|
package/dist/host.d.mts
CHANGED
|
@@ -20,6 +20,7 @@ export function reviewUploadOrigins(): readonly string[];
|
|
|
20
20
|
export const projectFingerprint: ShareHost["projectFingerprint"];
|
|
21
21
|
/** @type {ShareHost["ffBinary"]} */
|
|
22
22
|
export const ffBinary: ShareHost["ffBinary"];
|
|
23
|
+
export function journalKey(): Uint8Array<ArrayBufferLike> | null;
|
|
23
24
|
export function channelSite(): string;
|
|
24
25
|
export function signinSites(): string[];
|
|
25
26
|
export function runFile(file: string, args: string[]): import("node:child_process").PromiseWithChild<{
|
package/dist/hosts.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface ShareHost {
|
|
|
28
28
|
latestExportFile(dir: string): { path: string; fingerprint?: string; id: string } | null;
|
|
29
29
|
/** Trusted video upload origins configured by the host independently of the review API response. */
|
|
30
30
|
reviewUploadOrigins?: readonly string[];
|
|
31
|
+
/** This install's own secret: change-of-space journals are sealed with it; one it did not seal reads as none. */
|
|
32
|
+
journalKey?: Uint8Array;
|
|
31
33
|
/** The project as change detection sees it, as one hash. */
|
|
32
34
|
projectFingerprint(dir: string): Promise<string>;
|
|
33
35
|
/** The path of the host's FFmpeg tool `name`. */
|
package/dist/reviewShare.d.mts
CHANGED
|
@@ -22,7 +22,11 @@ export function reviewProjectId(projectPath: string): Promise<string | null>;
|
|
|
22
22
|
/** Which local project each review project was shared from: review project id to its folder.
|
|
23
23
|
* @param {string[]} paths @returns {Promise<Record<string, string>>} */
|
|
24
24
|
export function localReviewProjects(paths: string[]): Promise<Record<string, string>>;
|
|
25
|
-
/**
|
|
25
|
+
/** A journal as the kernel writes it: sealed when the host gave a key, so another party's journal can't pass for it.
|
|
26
|
+
* @template {object} T @param {string} dir @param {T} change */
|
|
27
|
+
export function sealedSwitch<T extends object>(dir: string, change: T): T;
|
|
28
|
+
/** The change of space waiting in the project; one the host's key did not seal is none.
|
|
29
|
+
* @param {string} dir @returns {Promise<import("./reviewSwitch.mjs").Switch | null>} */
|
|
26
30
|
export function readReviewSwitch(dir: string): Promise<import("./reviewSwitch.mjs").Switch | null>;
|
|
27
31
|
/** Points the record at another review project, keeping every other field the record holds.
|
|
28
32
|
* @param {string} projectPath @param {string} projectId @param {string} spaceId */
|
|
@@ -6,9 +6,24 @@ export function parseManifest(raw: unknown, stored?: boolean): Manifest;
|
|
|
6
6
|
/** Stored manifest bytes, which must already be canonical so their hash is the snapshot's manifest_sha256.
|
|
7
7
|
* @param {Uint8Array} body @returns {Manifest} */
|
|
8
8
|
export function parseCanonicalManifest(body: Uint8Array): Manifest;
|
|
9
|
+
/** Confirmed requests are reconciled by ID; only an unconfirmed Begin can need its manifest again.
|
|
10
|
+
* @param {{manifest?: unknown, manifestSha256?: unknown, uploadId?: unknown, snapshotId?: unknown}} saved
|
|
11
|
+
* @returns {{uploadId: string} | {manifest: Manifest} | null} */
|
|
12
|
+
export function readUploadIntent(saved: {
|
|
13
|
+
manifest?: unknown;
|
|
14
|
+
manifestSha256?: unknown;
|
|
15
|
+
uploadId?: unknown;
|
|
16
|
+
snapshotId?: unknown;
|
|
17
|
+
}): {
|
|
18
|
+
uploadId: string;
|
|
19
|
+
} | {
|
|
20
|
+
manifest: Manifest;
|
|
21
|
+
} | null;
|
|
9
22
|
export const ENTRYPOINT: "index.html";
|
|
10
23
|
/** @typedef {import("./types.js").ManifestFile} ManifestFile @typedef {import("./types.js").Violation} Violation
|
|
11
24
|
* @typedef {import("./types.js").ManifestDocument} ManifestDocument @typedef {import("./types.js").Manifest} Manifest */
|
|
25
|
+
/** @typedef {import("./pathPolicy.mjs").PathMode} PathMode
|
|
26
|
+
* @typedef {{mode: PathMode, pathErrors: Violation[]}} Validation */
|
|
12
27
|
/** Why a manifest was refused; `code` is the first violation's, in the server's order. */
|
|
13
28
|
export class ManifestInvalid extends Error {
|
|
14
29
|
/** @param {Violation[]} violations */
|
|
@@ -17,7 +32,13 @@ export class ManifestInvalid extends Error {
|
|
|
17
32
|
code: string;
|
|
18
33
|
}
|
|
19
34
|
export function parseStoredManifest(raw: unknown): Manifest;
|
|
35
|
+
export function localBaseDigest(raw: unknown): string;
|
|
20
36
|
export type ManifestFile = import("./types.js").ManifestFile;
|
|
21
37
|
export type Violation = import("./types.js").Violation;
|
|
22
38
|
export type ManifestDocument = import("./types.js").ManifestDocument;
|
|
23
39
|
export type Manifest = import("./types.js").Manifest;
|
|
40
|
+
export type PathMode = import("./pathPolicy.mjs").PathMode;
|
|
41
|
+
export type Validation = {
|
|
42
|
+
mode: PathMode;
|
|
43
|
+
pathErrors: Violation[];
|
|
44
|
+
};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/** The first rule matching a path's folded spelling. @param {string} path @returns {PathRule} */
|
|
2
2
|
export function classifyPath(path: string): PathRule;
|
|
3
|
+
/** @typedef {"current" | "stored" | "localV4"} PathMode */
|
|
3
4
|
/** `path` unchanged when every client can store it and the policy lets it travel; throws PathViolation otherwise,
|
|
4
5
|
* naming the first failing check in the registry's order. @param {string} path
|
|
5
|
-
* @param {
|
|
6
|
-
export function validatePath(path: string,
|
|
6
|
+
* @param {PathMode} [mode] */
|
|
7
|
+
export function validatePath(path: string, mode?: PathMode): string;
|
|
7
8
|
/** Refuses duplicates, and any two paths (or a path and a directory prefix) one filesystem would store as one name.
|
|
8
|
-
* Each path must already pass validatePath. @param {readonly string[]} paths */
|
|
9
|
-
export function checkInventoryPaths(paths: readonly string[]): void;
|
|
9
|
+
* Each path must already pass validatePath. @param {readonly string[]} paths @param {(value: string) => string} [keyOf] */
|
|
10
|
+
export function checkInventoryPaths(paths: readonly string[], keyOf?: (value: string) => string): void;
|
|
10
11
|
/** Whether no file under folder `dir` can be listed, so a capture need not open it: its first matching rule
|
|
11
12
|
* excludes the folder and all below it, and no include rule before that one can reach inside. @param {string} dir */
|
|
12
13
|
export function excludedFolder(dir: string): boolean;
|
|
14
|
+
/** A stored manifest may contain paths that are no longer eligible for upload. @param {string} path */
|
|
15
|
+
export function canUploadStoredPath(path: string): boolean;
|
|
13
16
|
/** @typedef {import("./types.js").PathRule} PathRule @typedef {import("./types.js").PolicyDocument} PolicyDocument */
|
|
14
17
|
/** A path the policy refuses: `code` is the golden vectors' shared vocabulary, `rule` the excluding rule's id. */
|
|
15
18
|
export class PathViolation extends Error {
|
|
@@ -21,5 +24,7 @@ export class PathViolation extends Error {
|
|
|
21
24
|
}
|
|
22
25
|
export function prefiltered(name: string): boolean;
|
|
23
26
|
export function skippedSymlink(path: string): boolean;
|
|
27
|
+
export function isPrivateSourcePath(path: string): boolean;
|
|
28
|
+
export type PathMode = "current" | "stored" | "localV4";
|
|
24
29
|
export type PathRule = import("./types.js").PathRule;
|
|
25
30
|
export type PolicyDocument = import("./types.js").PolicyDocument;
|
package/dist/sources/types.d.ts
CHANGED
|
@@ -61,7 +61,10 @@ export interface PathRule {
|
|
|
61
61
|
/** The fields of contract/path-policy.json this client reads. */
|
|
62
62
|
export interface PolicyDocument {
|
|
63
63
|
policy_version: string;
|
|
64
|
-
stored_manifest: {
|
|
64
|
+
stored_manifest: {
|
|
65
|
+
legacy_rule_regexes: Record<string, string>;
|
|
66
|
+
legacy_short_name_alias_names: string[];
|
|
67
|
+
};
|
|
65
68
|
unicode: { version: string };
|
|
66
69
|
rules: PathRule[];
|
|
67
70
|
path: {
|
|
@@ -70,6 +73,8 @@ export interface PolicyDocument {
|
|
|
70
73
|
forbidden_characters: string;
|
|
71
74
|
reserved_segment_regex: string;
|
|
72
75
|
canonical_spelling_roots: string[];
|
|
76
|
+
short_name_alias_names: string[];
|
|
77
|
+
short_name_alias_shape: string;
|
|
73
78
|
};
|
|
74
79
|
client_prefilter: { names: string[] };
|
|
75
80
|
client_symlinks: { skip_prefixes: string[] };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/** Whether every code point is assigned in Unicode 15.1. @param {string} value */
|
|
2
2
|
export function allAssigned(value: string): boolean;
|
|
3
|
-
/** The spelling two names share on a case-insensitive or
|
|
4
|
-
* @param {string} value */
|
|
3
|
+
/** The spelling two names share on a case-insensitive, normalizing or HFS+ filesystem:
|
|
4
|
+
* NFC(casefold(NFC(value))) once the code points HFS+ ignores are removed. @param {string} value */
|
|
5
5
|
export function comparisonKey(value: string): string;
|
|
6
6
|
export const UNICODE_VERSION: "15.1.0";
|
|
7
7
|
export function nfc(value: string): string;
|
|
8
|
+
export function withoutIgnorable(value: string): string;
|
|
9
|
+
export function v4ComparisonKey(value: string): string;
|
|
8
10
|
export type UnicodeTableFile = {
|
|
9
11
|
unicode_version: string;
|
|
10
12
|
casefold: Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/share",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.93",
|
|
4
4
|
"description": "Shared review identity, version upload and sharing state for HyperFrames hosts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -103,6 +103,9 @@
|
|
|
103
103
|
"publishConfig": {
|
|
104
104
|
"access": "public"
|
|
105
105
|
},
|
|
106
|
+
"dependencies": {
|
|
107
|
+
"@hyperframes/parsers": "0.9.93"
|
|
108
|
+
},
|
|
106
109
|
"devDependencies": {
|
|
107
110
|
"@types/node": "^25.0.10",
|
|
108
111
|
"typescript": "^5.0.0"
|
package/src/host.mjs
CHANGED
|
@@ -38,6 +38,8 @@ export const reviewUploadOrigins = () =>
|
|
|
38
38
|
export const projectFingerprint = (dir) => bound("projectFingerprint")(dir);
|
|
39
39
|
/** @type {ShareHost["ffBinary"]} */
|
|
40
40
|
export const ffBinary = (name) => bound("ffBinary")(name);
|
|
41
|
+
/** The key the host seals change-of-space journals with, or null to read them as they are. */
|
|
42
|
+
export const journalKey = () => host.journalKey ?? null;
|
|
41
43
|
export const channelSite = () => bound("channelSite");
|
|
42
44
|
export const signinSites = () => bound("signinSites");
|
|
43
45
|
|
package/src/hosts.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface ShareHost {
|
|
|
28
28
|
latestExportFile(dir: string): { path: string; fingerprint?: string; id: string } | null;
|
|
29
29
|
/** Trusted video upload origins configured by the host independently of the review API response. */
|
|
30
30
|
reviewUploadOrigins?: readonly string[];
|
|
31
|
+
/** This install's own secret: change-of-space journals are sealed with it; one it did not seal reads as none. */
|
|
32
|
+
journalKey?: Uint8Array;
|
|
31
33
|
/** The project as change detection sees it, as one hash. */
|
|
32
34
|
projectFingerprint(dir: string): Promise<string>;
|
|
33
35
|
/** The path of the host's FFmpeg tool `name`. */
|
package/src/reviewShare.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// copies skip .hyperframes, so a duplicate gets its own link, as the backend wants of a fork.
|
|
4
4
|
import { withProjectShareLock } from "./projectLock.mjs";
|
|
5
5
|
import { firstReviewAudience } from "./reviewAudience.mjs";
|
|
6
|
-
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { mkdirInside } from "./storage.mjs";
|
|
9
9
|
import {
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
SharingStateError,
|
|
17
17
|
writeJsonAtomic,
|
|
18
18
|
} from "./storage.mjs";
|
|
19
|
-
import { channelSite, normalize, signinSites } from "./host.mjs";
|
|
19
|
+
import { channelSite, journalKey, normalize, signinSites } from "./host.mjs";
|
|
20
20
|
import { ReviewFailed } from "./reviewClient.mjs";
|
|
21
21
|
import { rename } from "./storage.mjs";
|
|
22
22
|
|
|
@@ -306,10 +306,36 @@ export const reviewRecord = (projectPath) => readRecord(projectPath);
|
|
|
306
306
|
export const reviewSwitchPath = (projectPath) =>
|
|
307
307
|
recordPath(projectPath).replace(/\.json$/, ".switch.json");
|
|
308
308
|
|
|
309
|
-
/**
|
|
309
|
+
/** The host's key over the project's folder and the journal's own text.
|
|
310
|
+
* @param {Uint8Array} key @param {string} dir @param {object} change */
|
|
311
|
+
const sealOf = (key, dir, change) =>
|
|
312
|
+
createHmac("sha256", key)
|
|
313
|
+
.update(`${normalize(dir)}\0${JSON.stringify(change)}`)
|
|
314
|
+
.digest();
|
|
315
|
+
|
|
316
|
+
/** A journal as the kernel writes it: sealed when the host gave a key, so another party's journal can't pass for it.
|
|
317
|
+
* @template {object} T @param {string} dir @param {T} change */
|
|
318
|
+
export function sealedSwitch(dir, change) {
|
|
319
|
+
const key = journalKey();
|
|
320
|
+
return key ? { ...change, seal: sealOf(key, dir, change).toString("hex") } : change;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** With a host key, the journal without its seal when the seal is that key's over this folder, else null.
|
|
324
|
+
* @param {string} dir @param {Record<string, unknown>} read */
|
|
325
|
+
function unsealed(dir, read) {
|
|
326
|
+
const key = journalKey();
|
|
327
|
+
if (!key) return read;
|
|
328
|
+
const { seal, ...change } = read;
|
|
329
|
+
if (typeof seal !== "string" || !/^[0-9a-f]{64}$/.test(seal)) return null;
|
|
330
|
+
return timingSafeEqual(Buffer.from(seal, "hex"), sealOf(key, dir, change)) ? change : null;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** The change of space waiting in the project; one the host's key did not seal is none.
|
|
334
|
+
* @param {string} dir @returns {Promise<import("./reviewSwitch.mjs").Switch | null>} */
|
|
310
335
|
export async function readReviewSwitch(dir) {
|
|
311
336
|
const file = reviewSwitchPath(dir);
|
|
312
|
-
const
|
|
337
|
+
const read = await readJsonRecord(file);
|
|
338
|
+
const change = read && unsealed(dir, read);
|
|
313
339
|
if (!change) return null;
|
|
314
340
|
if (
|
|
315
341
|
!isSavedId(change.from) ||
|
package/src/reviewSwitch.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
readShare,
|
|
17
17
|
rebindRecord,
|
|
18
18
|
reviewRecord,
|
|
19
|
+
sealedSwitch,
|
|
19
20
|
reviewSentence,
|
|
20
21
|
reviewSwitchPath,
|
|
21
22
|
shown,
|
|
@@ -59,7 +60,7 @@ async function startSwitch(dir, change) {
|
|
|
59
60
|
if (record?.removed) throw new ReviewFailed(410, "review_project_removed");
|
|
60
61
|
if (record?.projectId !== change.from) throw new ReviewFailed(409, "switch_cancelled");
|
|
61
62
|
await mkdirInside(dir, ".hyperframes");
|
|
62
|
-
await writeJsonAtomic(switchPath(dir), change);
|
|
63
|
+
await writeJsonAtomic(switchPath(dir), sealedSwitch(dir, change));
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -91,7 +92,7 @@ async function assertCurrent(dir, change) {
|
|
|
91
92
|
|
|
92
93
|
/** @param {string} dir @param {Switch} change */
|
|
93
94
|
async function writeSwitch(dir, change) {
|
|
94
|
-
if (await owns(dir, change)) await writeJsonAtomic(switchPath(dir), change);
|
|
95
|
+
if (await owns(dir, change)) await writeJsonAtomic(switchPath(dir), sealedSwitch(dir, change));
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/** @param {string} dir @param {Switch} change */
|
|
@@ -232,14 +233,12 @@ async function turnOffOld(client, dir, change) {
|
|
|
232
233
|
await dropSwitch(dir, change);
|
|
233
234
|
}
|
|
234
235
|
|
|
235
|
-
/** The switched change whose old link is still to turn off, or null.
|
|
236
|
+
/** The switched change whose old link is still to turn off, or null. Only one marked opened: the kernel marks it before
|
|
237
|
+
* it moves the record, so an unopened change beside a record already on its new project is an older journal written
|
|
238
|
+
* back, and opening its link again would undo what the owner did since. @param {string} dir */
|
|
236
239
|
async function cleanupOf(dir) {
|
|
237
240
|
const change = await readSwitch(dir);
|
|
238
|
-
|
|
239
|
-
const at = (await reviewRecord(dir))?.projectId;
|
|
240
|
-
return change.opened || at === change.projectId
|
|
241
|
-
? { ...change, projectId: change.projectId }
|
|
242
|
-
: null;
|
|
241
|
+
return change?.opened && change.projectId ? { ...change, projectId: change.projectId } : null;
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
/** Each read of the link turns off an old link a change left on, in turn with every other journal step.
|
|
@@ -334,6 +333,15 @@ async function sharedRecord(projectPath) {
|
|
|
334
333
|
return { ...record, projectId: record.projectId };
|
|
335
334
|
}
|
|
336
335
|
|
|
336
|
+
/** The saved change, or null once an unopened one whose new project the record is already on is dropped: that is an
|
|
337
|
+
* earlier journal written back (cleanupOf). @param {string} dir @param {string} from the record's project */
|
|
338
|
+
async function savedChange(dir, from) {
|
|
339
|
+
const saved = await readSwitch(dir);
|
|
340
|
+
if (saved?.projectId !== from || saved.opened) return saved;
|
|
341
|
+
await dropSwitch(dir, saved);
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
|
|
337
345
|
/** Moves a shared project's link to `spaceId`: a new link there, the newest export on it, the old link off. Its own
|
|
338
346
|
* space answers the link as it is. Refuses before any write when the export cannot go up.
|
|
339
347
|
* @param {{ projectPath: string, title: string, client: ReviewClient, spaceId: string, upload: Upload,
|
|
@@ -343,7 +351,7 @@ export const changeSpace = ({ projectPath, title, client, spaceId, upload, canUp
|
|
|
343
351
|
inTurn(projectPath, async () => {
|
|
344
352
|
const record = await sharedRecord(projectPath);
|
|
345
353
|
const from = record.projectId;
|
|
346
|
-
const saved = await
|
|
354
|
+
const saved = await savedChange(projectPath, from);
|
|
347
355
|
if (saved?.projectId === from) await oldLinkFirst(client, projectPath, saved);
|
|
348
356
|
// A change already registered there carries on; one never registered is made again, with the same key.
|
|
349
357
|
if (saved?.from === from && saved.spaceId === spaceId) {
|
package/src/sources/capture.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
checkInventoryPaths,
|
|
16
16
|
classifyPath,
|
|
17
17
|
excludedFolder,
|
|
18
|
+
isPrivateSourcePath,
|
|
18
19
|
prefiltered,
|
|
19
20
|
skippedSymlink,
|
|
20
21
|
validatePath,
|
|
@@ -28,9 +29,16 @@ import { readRenderOutputs, settledState } from "./projectState.mjs";
|
|
|
28
29
|
const INLINE_HASH_BYTES = 4 * 1024 * 1024;
|
|
29
30
|
const HASHING_AT_ONCE = 4;
|
|
30
31
|
|
|
32
|
+
/** Test a child of a directory so a file-only rule does not prune a folder of the same name.
|
|
33
|
+
* @param {string} rel @param {boolean} directory */
|
|
34
|
+
function isPrivateEntry(rel, directory) {
|
|
35
|
+
return isPrivateSourcePath(directory ? `${rel}/x` : rel);
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
/** @param {string} root @param {string} rel @param {import("node:fs").Dirent} entry @param {Walk} walk
|
|
32
39
|
* @param {string[]} dirs */
|
|
33
40
|
async function visit(root, rel, entry, walk, dirs) {
|
|
41
|
+
if (isPrivateEntry(rel, entry.isDirectory())) return;
|
|
34
42
|
if (entry.isDirectory()) {
|
|
35
43
|
if (!excludedFolder(rel)) dirs.push(rel);
|
|
36
44
|
return;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
"policy_version": "portable-source-
|
|
2
|
+
"policy_version": "portable-source-v11",
|
|
3
3
|
"manifest": {
|
|
4
4
|
"format_version": 1,
|
|
5
5
|
"entrypoint": "index.html",
|
|
6
|
-
"fields": [
|
|
7
|
-
|
|
6
|
+
"fields": [
|
|
7
|
+
"format_version",
|
|
8
|
+
"entrypoint",
|
|
9
|
+
"files"
|
|
10
|
+
],
|
|
11
|
+
"file_fields": [
|
|
12
|
+
"path",
|
|
13
|
+
"sha256",
|
|
14
|
+
"size"
|
|
15
|
+
],
|
|
8
16
|
"sha256": "64 lowercase hex characters: the SHA-256 of the file's exact bytes",
|
|
9
17
|
"size": "the file's byte length, an integer from 0 to 9007199254740991 (2^53 - 1, the largest integer every JSON client reads exactly)",
|
|
10
18
|
"same_digest_same_size": "two entries with the same sha256 must have the same size",
|
|
@@ -23,7 +31,26 @@
|
|
|
23
31
|
"table": "unicode-15.1.0.json",
|
|
24
32
|
"assigned_only": "every code point must be assigned in Unicode 15.1; unassigned and future code points are refused",
|
|
25
33
|
"normalization": "every path must already be NFC",
|
|
26
|
-
"
|
|
34
|
+
"ignorable_code_points": [
|
|
35
|
+
[
|
|
36
|
+
"200C",
|
|
37
|
+
"200F"
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
"202A",
|
|
41
|
+
"202E"
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"206A",
|
|
45
|
+
"206F"
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"FEFF",
|
|
49
|
+
"FEFF"
|
|
50
|
+
]
|
|
51
|
+
],
|
|
52
|
+
"ignorable": "code points HFS+ skips when it compares two names (Apple TN1150): zero-width non-joiner and joiner, directional marks, embeddings and overrides, deprecated format controls and the byte order mark, as inclusive [first, last] hex ranges. They stay legal in a path (an emoji ZWJ sequence, a Persian or Indic name with ZWNJ), but a segment's comparison key drops them: .git with U+200C after the g keys as .git, and two names that differ only by them collide",
|
|
53
|
+
"comparison_key": "NFC(full_casefold(NFC(segment with every ignorable_code_points character removed))), with default full case folding (CaseFolding.txt status C and F)"
|
|
27
54
|
},
|
|
28
55
|
"path": {
|
|
29
56
|
"max_path_bytes": 1024,
|
|
@@ -32,7 +59,81 @@
|
|
|
32
59
|
"forbidden_characters": "<>:\"|?*\\",
|
|
33
60
|
"reserved_segment_regex": "(?:con|prn|aux|nul|com[1-9\u00b9\u00b2\u00b3]|lpt[1-9\u00b9\u00b2\u00b3])(?:\\..*)?",
|
|
34
61
|
"reserved_segment_match": "full match against each segment's comparison key, so CON, Con.txt and nul.tar.gz are all reserved",
|
|
35
|
-
"canonical_spelling_roots": [
|
|
62
|
+
"canonical_spelling_roots": [
|
|
63
|
+
".media",
|
|
64
|
+
".hyperframes"
|
|
65
|
+
],
|
|
66
|
+
"short_name_alias_names": [
|
|
67
|
+
".agent",
|
|
68
|
+
".agents",
|
|
69
|
+
".aider.conf.yaml",
|
|
70
|
+
".aider.conf.yml",
|
|
71
|
+
".amazonq",
|
|
72
|
+
".augment",
|
|
73
|
+
".aws",
|
|
74
|
+
".cache",
|
|
75
|
+
".claude",
|
|
76
|
+
".cline",
|
|
77
|
+
".clinerules",
|
|
78
|
+
".codex",
|
|
79
|
+
".continue",
|
|
80
|
+
".continuerc.json",
|
|
81
|
+
".crush",
|
|
82
|
+
".crush.json",
|
|
83
|
+
".cursor",
|
|
84
|
+
".devcontainer",
|
|
85
|
+
".devcontainer.json",
|
|
86
|
+
".ds_store",
|
|
87
|
+
".env",
|
|
88
|
+
".envrc",
|
|
89
|
+
".factory",
|
|
90
|
+
".fleet",
|
|
91
|
+
".gemini",
|
|
92
|
+
".git",
|
|
93
|
+
".git-credentials",
|
|
94
|
+
".gitattributes",
|
|
95
|
+
".github",
|
|
96
|
+
".gitmodules",
|
|
97
|
+
".gitpod.yml",
|
|
98
|
+
".grok",
|
|
99
|
+
".hg",
|
|
100
|
+
".hyperframes",
|
|
101
|
+
".idea",
|
|
102
|
+
".idx",
|
|
103
|
+
".junie",
|
|
104
|
+
".kilocode",
|
|
105
|
+
".kiro",
|
|
106
|
+
".lock",
|
|
107
|
+
".mcp.json",
|
|
108
|
+
".media",
|
|
109
|
+
".netrc",
|
|
110
|
+
".next",
|
|
111
|
+
".npmrc",
|
|
112
|
+
".opencode",
|
|
113
|
+
".openhands",
|
|
114
|
+
".parcel-cache",
|
|
115
|
+
".pypirc",
|
|
116
|
+
".qoder",
|
|
117
|
+
".qwen",
|
|
118
|
+
".roo",
|
|
119
|
+
".ssh",
|
|
120
|
+
".svn",
|
|
121
|
+
".thumbnails",
|
|
122
|
+
".trae",
|
|
123
|
+
".transcode-cache",
|
|
124
|
+
".turbo",
|
|
125
|
+
".viral-clone",
|
|
126
|
+
".vite",
|
|
127
|
+
".vs",
|
|
128
|
+
".vscode",
|
|
129
|
+
".waveform-cache",
|
|
130
|
+
".windsurf",
|
|
131
|
+
".yarnrc",
|
|
132
|
+
".yarnrc.yml",
|
|
133
|
+
".zed"
|
|
134
|
+
],
|
|
135
|
+
"short_name_alias_shape": "([^~]+)~[0-9]+(?:\\.[^.]{1,3})?",
|
|
136
|
+
"short_name_alias_match": "a segment is a Windows 8.3 short name of a listed name when its comparison key full-matches short_name_alias_shape and the captured stem is a prefix of that name without its leading dot, or of that name without its leading dot and without the dots before its extension, at least 2 characters long (the whole name when shorter) and at most 6, so GIT~1, git~12, CLAUDE~1, HYPERF~2 and AIDERC~1.YML (.aider.conf.yml) are refused. The names are the leading-dot names that canonical_spelling_roots and the reject rules spell out, except inside .hyperframes/, where every file not named is refused already, plus .github, whose hooks, copilot and agents folders are refused. Stored reads use stored_manifest.legacy_short_name_alias_names in place of these names. Short names of other names travel (photo~2.jpg, REPORT~1.TXT). Windows' hashed short names (two characters, four hex digits, ~N) are not covered: a Windows install refuses a folder whose name on disk differs from the path's",
|
|
36
137
|
"checks": [
|
|
37
138
|
{
|
|
38
139
|
"code": "path_empty",
|
|
@@ -60,11 +161,11 @@
|
|
|
60
161
|
},
|
|
61
162
|
{
|
|
62
163
|
"code": "path_empty_segment",
|
|
63
|
-
"rule": "no empty segment ('a//b', a trailing '/')"
|
|
164
|
+
"rule": "no empty segment ('a//b', a trailing '/'), and none made only of ignorable_code_points"
|
|
64
165
|
},
|
|
65
166
|
{
|
|
66
167
|
"code": "path_dot_segment",
|
|
67
|
-
"rule": "no '.' or '..' segment"
|
|
168
|
+
"rule": "no '.' or '..' segment, also once its ignorable_code_points are removed"
|
|
68
169
|
},
|
|
69
170
|
{
|
|
70
171
|
"code": "segment_too_long",
|
|
@@ -78,6 +179,10 @@
|
|
|
78
179
|
"code": "reserved_name",
|
|
79
180
|
"rule": "no segment matches reserved_segment_regex"
|
|
80
181
|
},
|
|
182
|
+
{
|
|
183
|
+
"code": "segment_short_name",
|
|
184
|
+
"rule": "no segment is a Windows 8.3 short name of a short_name_alias_names entry (short_name_alias_match)"
|
|
185
|
+
},
|
|
81
186
|
{
|
|
82
187
|
"code": "reserved_path_alias",
|
|
83
188
|
"rule": "a first segment whose comparison key equals a canonical_spelling_roots entry is spelled exactly like it, and an allowed rule that matches the folded path also matches the path as spelled"
|
|
@@ -139,10 +244,10 @@
|
|
|
139
244
|
},
|
|
140
245
|
{
|
|
141
246
|
"id": "agent-client-state",
|
|
142
|
-
"regex": "(?:[^/]+/)*(?:\\.claude|\\.codex|\\.agents|\\.cursor|\\.vscode|\\.idea)(?:/.*)?",
|
|
247
|
+
"regex": "(?:[^/]+/)*(?:\\.claude|\\.codex|\\.agents|\\.agent|_agents|_agent|\\.qoder|\\.opencode|\\.grok|\\.cursor|\\.vscode|\\.idea|\\.gemini|\\.qwen|\\.kiro|\\.windsurf|\\.continue|\\.roo|\\.kilocode|\\.cline|\\.clinerules|\\.zed|\\.amazonq|\\.junie|\\.augment|\\.trae|\\.factory|\\.crush|\\.idx|\\.fleet|\\.openhands|\\.vs)(?:/.*)?",
|
|
143
248
|
"client_action": "exclude",
|
|
144
249
|
"server_action": "reject",
|
|
145
|
-
"basis": "Agent and IDE state at any depth; Desktop vendors .claude/skills into every project and regenerates it"
|
|
250
|
+
"basis": "Agent and IDE state at any depth, which agents and editors load MCP servers, hooks, tasks and settings from (Visual Studio its MCP servers from .vs/mcp.json); Desktop vendors .claude/skills into every project and regenerates it. Antigravity loads hooks and MCP servers from any of .agents, .agent, _agents and _agent"
|
|
146
251
|
},
|
|
147
252
|
{
|
|
148
253
|
"id": "dependencies-and-git",
|
|
@@ -151,6 +256,20 @@
|
|
|
151
256
|
"server_action": "reject",
|
|
152
257
|
"basis": "Version control and installed dependencies at any depth"
|
|
153
258
|
},
|
|
259
|
+
{
|
|
260
|
+
"id": "git-directory-head",
|
|
261
|
+
"regex": "(?:[^/]+/)*head",
|
|
262
|
+
"client_action": "exclude",
|
|
263
|
+
"server_action": "reject",
|
|
264
|
+
"basis": "A file named HEAD at any depth: git treats a folder holding HEAD with objects/ and refs/ (or a commondir file) as a git directory whatever the folder is called, and reads its config, hooks and info/attributes. Without HEAD no folder is one"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"id": "work-tree-config",
|
|
268
|
+
"regex": "(?:[^/]+/)*(?:\\.gitattributes|\\.gitmodules|\\.mcp\\.json|opencode\\.jsonc?|\\.?crush\\.json|\\.aider\\.conf\\.ya?ml|\\.gitpod\\.yml|\\.continuerc\\.json|\\.devcontainer(?:\\.json|/.*)?|\\.github/(?:hooks|copilot|agents)(?:/.*)?)",
|
|
269
|
+
"client_action": "exclude",
|
|
270
|
+
"server_action": "reject",
|
|
271
|
+
"basis": "Files in the work tree that name commands, at any depth: git reads .gitattributes and .gitmodules, an agent starts the servers .mcp.json, opencode.json and crush.json name and the lint and test commands .aider.conf.yml names, an editor runs the lifecycle commands in .devcontainer, Gitpod the tasks in .gitpod.yml and Continue the servers in .continuerc.json, and Copilot runs the hooks under .github/hooks and .github/copilot and the servers its .github/agents profiles name"
|
|
272
|
+
},
|
|
154
273
|
{
|
|
155
274
|
"id": "build-caches",
|
|
156
275
|
"regex": "(?:[^/]+/)*(?:\\.cache|\\.vite|\\.next|\\.turbo|\\.parcel-cache)(?:/.*)?",
|
|
@@ -296,26 +415,74 @@
|
|
|
296
415
|
"project_json": "Root project.json is portable project content and is included. It is not sync identity: the owner workspace, composition, base snapshot, revision and receipts live outside the inventory, never in project.json.",
|
|
297
416
|
"capture_preconditions": "Do not capture while .hyperframes/history-turn.json exists (an agent turn is open) or while .hyperframes/project.lock is held.",
|
|
298
417
|
"render_outputs": "Leave out every path listed in .hyperframes/render-outputs.json: render outputs written outside renders/ are recorded there, and the server cannot know them.",
|
|
299
|
-
"complete_capture": "A file the client cannot read fails the capture; it never becomes a deletion. The exclusions above and the symlinks client_symlinks
|
|
300
|
-
"symlinks": "Symlinks and special files
|
|
418
|
+
"complete_capture": "A file the client cannot read fails the capture; it never becomes a deletion. The exclusions above, and the symlinks and special files client_symlinks leaves out while the base snapshot lists nothing at or below them, are the only files left out.",
|
|
419
|
+
"symlinks": "Symlinks and special files are read as client_symlinks says: the way the HyperFrames CLI's cloud render packs a project.",
|
|
301
420
|
"empty_directories": "Empty directories are not represented. Pull never deletes a local empty directory."
|
|
302
421
|
},
|
|
303
422
|
"client_prefilter": {
|
|
304
|
-
"names": [
|
|
423
|
+
"names": [
|
|
424
|
+
"Icon\r"
|
|
425
|
+
],
|
|
305
426
|
"rule": "skip a file whose last segment is one of these before running any path check; macOS writes 'Icon\\r' for a folder with a custom icon, and the carriage return would otherwise fail the whole capture with path_invalid_character"
|
|
306
427
|
},
|
|
307
428
|
"client_symlinks": {
|
|
308
|
-
"default": "
|
|
309
|
-
"skip_prefixes": [
|
|
429
|
+
"default": "as_cloud_render",
|
|
430
|
+
"skip_prefixes": [
|
|
431
|
+
"assets/podcast/"
|
|
432
|
+
],
|
|
310
433
|
"match": "a symlink whose folded path (each segment replaced by its comparison key, as for rules) starts with a listed prefix, at any depth below it",
|
|
311
|
-
"rule": "skip such a symlink
|
|
434
|
+
"rule": "skip such a symlink, and on Pull leave such a local symlink in place as local state; a regular file under the prefix is captured like any other",
|
|
435
|
+
"as_cloud_render": "every other symlink is read the way the HyperFrames CLI's cloud render packs a project: a link to a regular file is captured as that file, under the link's path, unless the file is outside the project and either in a private location (an env file, Git data, a hidden, system or home app-data folder) or reached by a link the project received from someone else; a link to a folder, a broken link, a link to such a private file and a special file are left out, but only while the base snapshot lists nothing at or below the path: once it does, each fails the capture instead (a broken link as unreadable), so a capture never becomes a deletion. Pull replaces a captured link with the file it receives, never writing through it",
|
|
312
436
|
"basis": "Desktop's podcast intake links the original camera files, which live outside the project, under assets/podcast/, and the page plays the transcodes under .hyperframes/prepared-assets/podcast/; real files there, such as the joins under assets/podcast/joins/, travel normally"
|
|
313
437
|
},
|
|
314
438
|
"stored_manifest": {
|
|
315
439
|
"legacy_rule_regexes": {
|
|
316
440
|
"agent-client-state": "(?:[^/]+/)*(?:\\.claude|\\.agents|\\.cursor|\\.vscode|\\.idea)(?:/.*)?",
|
|
441
|
+
"work-tree-config": "(?!)",
|
|
442
|
+
"git-directory-head": "(?!)",
|
|
317
443
|
"nested-hyperframes-state": "(?!)"
|
|
318
444
|
},
|
|
319
|
-
"
|
|
445
|
+
"legacy_short_name_alias_names": [
|
|
446
|
+
".agent",
|
|
447
|
+
".agents",
|
|
448
|
+
".aws",
|
|
449
|
+
".cache",
|
|
450
|
+
".claude",
|
|
451
|
+
".codex",
|
|
452
|
+
".cursor",
|
|
453
|
+
".ds_store",
|
|
454
|
+
".env",
|
|
455
|
+
".envrc",
|
|
456
|
+
".git",
|
|
457
|
+
".git-credentials",
|
|
458
|
+
".gitattributes",
|
|
459
|
+
".gitmodules",
|
|
460
|
+
".grok",
|
|
461
|
+
".hg",
|
|
462
|
+
".hyperframes",
|
|
463
|
+
".idea",
|
|
464
|
+
".lock",
|
|
465
|
+
".mcp.json",
|
|
466
|
+
".media",
|
|
467
|
+
".netrc",
|
|
468
|
+
".next",
|
|
469
|
+
".npmrc",
|
|
470
|
+
".opencode",
|
|
471
|
+
".parcel-cache",
|
|
472
|
+
".pypirc",
|
|
473
|
+
".qoder",
|
|
474
|
+
".ssh",
|
|
475
|
+
".svn",
|
|
476
|
+
".thumbnails",
|
|
477
|
+
".transcode-cache",
|
|
478
|
+
".turbo",
|
|
479
|
+
".viral-clone",
|
|
480
|
+
".vite",
|
|
481
|
+
".vscode",
|
|
482
|
+
".waveform-cache",
|
|
483
|
+
".yarnrc",
|
|
484
|
+
".yarnrc.yml"
|
|
485
|
+
],
|
|
486
|
+
"rule": "Only stored snapshot reads use each listed rule's regex in place of its current one, and the v10 short_name_alias_names in place of the current ones, to retain immutable manifest digests: agent-client-state its v3 regex, and work-tree-config, added in v7, git-directory-head, added in v9, and nested-hyperframes-state, added in v10, none. New captures and uploads use the current rules and short names. Clients never install, and the server never signs a download URL for, a path a current rule excludes or a segment that is a current short name."
|
|
320
487
|
}
|
|
321
488
|
}
|
package/src/sources/manifest.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// Serialize snapshots to canonical UTF-8 bytes so clients and the server compute the same digest.
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
+
import { v4ComparisonKey } from "./unicode.mjs";
|
|
4
5
|
import { PathViolation, checkInventoryPaths, validatePath } from "./pathPolicy.mjs";
|
|
5
6
|
|
|
6
7
|
const FORMAT_VERSION = 1;
|
|
@@ -11,6 +12,9 @@ const SHA256 = /^[0-9a-f]{64}$/;
|
|
|
11
12
|
/** @typedef {import("./types.js").ManifestFile} ManifestFile @typedef {import("./types.js").Violation} Violation
|
|
12
13
|
* @typedef {import("./types.js").ManifestDocument} ManifestDocument @typedef {import("./types.js").Manifest} Manifest */
|
|
13
14
|
|
|
15
|
+
/** @typedef {import("./pathPolicy.mjs").PathMode} PathMode
|
|
16
|
+
* @typedef {{mode: PathMode, pathErrors: Violation[]}} Validation */
|
|
17
|
+
|
|
14
18
|
/** Why a manifest was refused; `code` is the first violation's, in the server's order. */
|
|
15
19
|
export class ManifestInvalid extends Error {
|
|
16
20
|
/** @param {Violation[]} violations */
|
|
@@ -37,17 +41,17 @@ function unknownFields(value, fields, out) {
|
|
|
37
41
|
if (!fields.includes(key)) out.push({ code: "invalid_schema" });
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
/** @param {unknown} raw @param {Violation[]} out @param {
|
|
41
|
-
function fileOf(raw, out,
|
|
44
|
+
/** @param {unknown} raw @param {Violation[]} out @param {Validation} policy @returns {ManifestFile | null} */
|
|
45
|
+
function fileOf(raw, out, policy) {
|
|
42
46
|
if (!isObject(raw)) return (out.push({ code: "invalid_schema" }), null);
|
|
43
47
|
const before = out.length;
|
|
44
48
|
const { path, sha256, size } = raw;
|
|
45
49
|
if (typeof path !== "string") out.push({ code: "invalid_schema" });
|
|
46
50
|
else {
|
|
47
51
|
try {
|
|
48
|
-
validatePath(path,
|
|
52
|
+
validatePath(path, policy.mode);
|
|
49
53
|
} catch (error) {
|
|
50
|
-
|
|
54
|
+
policy.pathErrors.push(violationOf(error));
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
checkBlob(sha256, size, out);
|
|
@@ -70,8 +74,8 @@ function checkBlob(sha256, size, out) {
|
|
|
70
74
|
const byUtf8 = (a, b) => Buffer.compare(Buffer.from(a.path, "utf8"), Buffer.from(b.path, "utf8"));
|
|
71
75
|
|
|
72
76
|
/** The files in canonical order, or the inventory's first violation. @param {ManifestFile[]} files
|
|
73
|
-
* @param {Violation[]} out */
|
|
74
|
-
function canonicalInventory(files, out) {
|
|
77
|
+
* @param {Violation[]} out @param {Validation} policy */
|
|
78
|
+
function canonicalInventory(files, out, policy) {
|
|
75
79
|
const ordered = [...files].sort(byUtf8);
|
|
76
80
|
/** @type {Map<string, number>} */
|
|
77
81
|
const sizeByDigest = new Map();
|
|
@@ -82,20 +86,23 @@ function canonicalInventory(files, out) {
|
|
|
82
86
|
return (out.push({ code: "inconsistent_digest_size", path: file.path }), null);
|
|
83
87
|
}
|
|
84
88
|
try {
|
|
85
|
-
checkInventoryPaths(
|
|
89
|
+
checkInventoryPaths(
|
|
90
|
+
ordered.map((file) => file.path),
|
|
91
|
+
policy.mode === "localV4" ? v4ComparisonKey : undefined,
|
|
92
|
+
);
|
|
86
93
|
} catch (error) {
|
|
87
|
-
|
|
94
|
+
policy.pathErrors.push(violationOf(error));
|
|
88
95
|
}
|
|
89
96
|
return ordered;
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
/** @param {unknown} raw @param {Violation[]} out @param {
|
|
93
|
-
function filesOf(raw, out,
|
|
99
|
+
/** @param {unknown} raw @param {Violation[]} out @param {Validation} policy */
|
|
100
|
+
function filesOf(raw, out, policy) {
|
|
94
101
|
if (!Array.isArray(raw)) return (out.push({ code: "invalid_schema" }), null);
|
|
95
102
|
const before = out.length;
|
|
96
|
-
const files = raw.map((item) => fileOf(item, out,
|
|
103
|
+
const files = raw.map((item) => fileOf(item, out, policy));
|
|
97
104
|
if (out.length !== before) return null;
|
|
98
|
-
return canonicalInventory(/** @type {ManifestFile[]} */ (files), out);
|
|
105
|
+
return canonicalInventory(/** @type {ManifestFile[]} */ (files), out, policy);
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
/** The canonical bytes of a valid document. @param {ManifestDocument} document */
|
|
@@ -113,16 +120,26 @@ export function canonicalBytes(document) {
|
|
|
113
120
|
/** Validates a manifest document as the server does; throws ManifestInvalid. @param {unknown} raw
|
|
114
121
|
* @param {boolean} [stored] @returns {Manifest} */
|
|
115
122
|
export function parseManifest(raw, stored = false) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
return readManifest(raw, stored ? "stored" : "current");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {Record<string, unknown>} raw @param {Violation[]} out */
|
|
127
|
+
function checkHeader(raw, out) {
|
|
119
128
|
const { format_version: version, entrypoint } = raw;
|
|
120
|
-
if (
|
|
129
|
+
if (typeof version !== "number" || !Number.isInteger(version))
|
|
121
130
|
out.push({ code: "invalid_schema" });
|
|
122
131
|
else if (version !== FORMAT_VERSION) out.push({ code: "unsupported_format_version" });
|
|
123
132
|
if (typeof entrypoint !== "string") out.push({ code: "invalid_schema" });
|
|
124
133
|
else if (entrypoint !== ENTRYPOINT) out.push({ code: "invalid_entrypoint" });
|
|
125
|
-
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** @param {unknown} raw @param {PathMode} mode @param {Violation[]} [obsoletePaths] @returns {Manifest} */
|
|
137
|
+
function readManifest(raw, mode, obsoletePaths) {
|
|
138
|
+
if (!isObject(raw)) throw new ManifestInvalid([{ code: "invalid_schema" }]);
|
|
139
|
+
/** @type {Violation[]} */
|
|
140
|
+
const out = [];
|
|
141
|
+
checkHeader(raw, out);
|
|
142
|
+
const files = filesOf(raw.files, out, { mode, pathErrors: obsoletePaths ?? out });
|
|
126
143
|
unknownFields(raw, ["format_version", "entrypoint", "files"], out);
|
|
127
144
|
if (out.length) throw new ManifestInvalid(out);
|
|
128
145
|
const ordered = /** @type {ManifestFile[]} */ (files);
|
|
@@ -152,3 +169,36 @@ export function parseCanonicalManifest(body) {
|
|
|
152
169
|
/** A published snapshot or local base can retain v3 paths; its bytes and digest remain immutable.
|
|
153
170
|
* @param {unknown} raw @returns {Manifest} */
|
|
154
171
|
export const parseStoredManifest = (raw) => parseManifest(raw, true);
|
|
172
|
+
|
|
173
|
+
/** Verify the local parent snapshot under the filename rules its writer supported. @param {unknown} raw */
|
|
174
|
+
export const localBaseDigest = (raw) => readManifest(raw, "localV4").sha256;
|
|
175
|
+
|
|
176
|
+
/** @param {{uploadId?: unknown, snapshotId?: unknown}} saved */
|
|
177
|
+
function confirmedUploadId(saved) {
|
|
178
|
+
if (saved.uploadId === null && saved.snapshotId === null) return null;
|
|
179
|
+
if (
|
|
180
|
+
typeof saved.uploadId !== "string" ||
|
|
181
|
+
!saved.uploadId ||
|
|
182
|
+
typeof saved.snapshotId !== "string" ||
|
|
183
|
+
!saved.snapshotId
|
|
184
|
+
)
|
|
185
|
+
throw new Error("Incomplete saved source upload identity.");
|
|
186
|
+
return saved.uploadId;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Confirmed requests are reconciled by ID; only an unconfirmed Begin can need its manifest again.
|
|
190
|
+
* @param {{manifest?: unknown, manifestSha256?: unknown, uploadId?: unknown, snapshotId?: unknown}} saved
|
|
191
|
+
* @returns {{uploadId: string} | {manifest: Manifest} | null} */
|
|
192
|
+
export function readUploadIntent(saved) {
|
|
193
|
+
const uploadId = confirmedUploadId(saved);
|
|
194
|
+
/** @type {Violation[]} */
|
|
195
|
+
const obsoletePaths = [];
|
|
196
|
+
const manifest =
|
|
197
|
+
uploadId === null
|
|
198
|
+
? readManifest(saved.manifest, "stored", obsoletePaths)
|
|
199
|
+
: readManifest(saved.manifest, "localV4");
|
|
200
|
+
if (manifest.sha256 !== saved.manifestSha256)
|
|
201
|
+
throw new Error("Saved source upload manifest does not match its checksum.");
|
|
202
|
+
if (uploadId !== null) return { uploadId };
|
|
203
|
+
return obsoletePaths.length ? null : { manifest };
|
|
204
|
+
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// Validate
|
|
2
|
+
// Validate source manifests against the bundled sync contract.
|
|
3
|
+
import { isCredentialOrToolStatePath, isVcsOrSecretPath } from "@hyperframes/parsers/private-path";
|
|
3
4
|
import { readContract } from "./contract.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
UNICODE_VERSION,
|
|
7
|
+
allAssigned,
|
|
8
|
+
comparisonKey,
|
|
9
|
+
v4ComparisonKey,
|
|
10
|
+
nfc,
|
|
11
|
+
withoutIgnorable,
|
|
12
|
+
} from "./unicode.mjs";
|
|
5
13
|
|
|
6
|
-
const PATH_POLICY_VERSION = "portable-source-
|
|
14
|
+
const PATH_POLICY_VERSION = "portable-source-v11";
|
|
7
15
|
|
|
8
16
|
/** @typedef {import("./types.js").PathRule} PathRule @typedef {import("./types.js").PolicyDocument} PolicyDocument */
|
|
9
17
|
|
|
@@ -26,6 +34,25 @@ const whole = (pattern) => new RegExp(`^(?:${pattern})$`, "su");
|
|
|
26
34
|
/** @param {string} text */
|
|
27
35
|
const escaped = (text) => text.replace(/[\\\]^-]/g, "\\$&");
|
|
28
36
|
|
|
37
|
+
/** Every stem of a Windows 8.3 short name of `names`: a prefix of each name, its leading dot dropped, 2 to 6 long
|
|
38
|
+
* (the whole name when shorter), also with the dots before its extension dropped, as Windows shortens
|
|
39
|
+
* the name .aider.conf.yml to AIDERC~1.YML. @param {readonly string[]} names */
|
|
40
|
+
function shortNameStems(names) {
|
|
41
|
+
/** @type {Set<string>} */
|
|
42
|
+
const stems = new Set();
|
|
43
|
+
for (const name of names) {
|
|
44
|
+
const bare = comparisonKey(name).replace(/^\./, "");
|
|
45
|
+
const dot = bare.lastIndexOf(".");
|
|
46
|
+
const base = dot > 0 ? bare.slice(0, dot).replaceAll(".", "") : bare;
|
|
47
|
+
for (const spelled of [bare, base]) {
|
|
48
|
+
const longest = Math.min(6, spelled.length);
|
|
49
|
+
for (let length = Math.min(2, longest); length <= longest; length++)
|
|
50
|
+
stems.add(spelled.slice(0, length));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return stems;
|
|
54
|
+
}
|
|
55
|
+
|
|
29
56
|
/** @param {PolicyDocument} document */
|
|
30
57
|
function compile(document) {
|
|
31
58
|
if (document.policy_version !== PATH_POLICY_VERSION)
|
|
@@ -40,6 +67,15 @@ function compile(document) {
|
|
|
40
67
|
if ((rule.server_action === "allow") !== (rule.client_action === "include"))
|
|
41
68
|
throw new Error(`path rule ${rule.id}: the server allows exactly what clients include`);
|
|
42
69
|
const limits = document.path;
|
|
70
|
+
const legacy = document.stored_manifest.legacy_rule_regexes;
|
|
71
|
+
for (const id of Object.keys(legacy))
|
|
72
|
+
if (!document.rules.some((rule) => rule.id === id))
|
|
73
|
+
throw new Error(`path policy's stored_manifest names no rule ${id}`);
|
|
74
|
+
const currentRules = document.rules.map((rule) => ({ rule, pattern: whole(rule.regex) }));
|
|
75
|
+
const storedRules = document.rules.map((rule) => ({
|
|
76
|
+
rule,
|
|
77
|
+
pattern: whole(legacy[rule.id] ?? rule.regex),
|
|
78
|
+
}));
|
|
43
79
|
return {
|
|
44
80
|
limits,
|
|
45
81
|
invalidCharacter: new RegExp(
|
|
@@ -47,28 +83,24 @@ function compile(document) {
|
|
|
47
83
|
"u",
|
|
48
84
|
),
|
|
49
85
|
reservedSegment: whole(limits.reserved_segment_regex),
|
|
86
|
+
shortNameShape: whole(limits.short_name_alias_shape),
|
|
87
|
+
paths: {
|
|
88
|
+
current: { rules: currentRules, stems: shortNameStems(limits.short_name_alias_names) },
|
|
89
|
+
stored: {
|
|
90
|
+
rules: storedRules,
|
|
91
|
+
stems: shortNameStems(document.stored_manifest.legacy_short_name_alias_names),
|
|
92
|
+
},
|
|
93
|
+
localV4: { rules: storedRules, stems: new Set() },
|
|
94
|
+
},
|
|
50
95
|
canonicalRoots: new Map(
|
|
51
96
|
limits.canonical_spelling_roots.map((root) => [comparisonKey(root), root]),
|
|
52
97
|
),
|
|
53
|
-
rules:
|
|
54
|
-
storedRules: storedRules(document),
|
|
98
|
+
rules: currentRules,
|
|
55
99
|
prefilter: new Set(document.client_prefilter.names),
|
|
56
100
|
symlinkPrefixes: document.client_symlinks.skip_prefixes,
|
|
57
101
|
};
|
|
58
102
|
}
|
|
59
103
|
|
|
60
|
-
/** Each rule the stored manifest section lists matches by its legacy regex in a stored snapshot read.
|
|
61
|
-
* @param {PolicyDocument} document */
|
|
62
|
-
function storedRules(document) {
|
|
63
|
-
const legacy = new Map(Object.entries(document.stored_manifest.legacy_rule_regexes));
|
|
64
|
-
const unknown = [...legacy.keys()].filter((id) => !document.rules.some((rule) => rule.id === id));
|
|
65
|
-
if (unknown.length) throw new Error(`path policy's stored_manifest names no rule ${unknown}`);
|
|
66
|
-
return document.rules.map((rule) => ({
|
|
67
|
-
rule,
|
|
68
|
-
pattern: whole(legacy.get(rule.id) ?? rule.regex),
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
104
|
/** @type {ReturnType<typeof compile> | null} */
|
|
73
105
|
let compiled = null;
|
|
74
106
|
/** The policy, read and compiled when a path is first checked: an app that never syncs never reads it. */
|
|
@@ -85,8 +117,8 @@ export function classifyPath(path) {
|
|
|
85
117
|
return found.rule;
|
|
86
118
|
}
|
|
87
119
|
|
|
88
|
-
/** Checks 1 to 10 of the registry's `path.checks`: the ones about the string itself. @param {string} path */
|
|
89
|
-
function checkSpelling(path) {
|
|
120
|
+
/** Checks 1 to 10 of the registry's `path.checks`: the ones about the string itself. @param {string} path @param {boolean} localV4 */
|
|
121
|
+
function checkSpelling(path, localV4) {
|
|
90
122
|
const { limits, invalidCharacter } = policy();
|
|
91
123
|
if (!path) throw new PathViolation("path_empty", path);
|
|
92
124
|
if (invalidCharacter.test(path)) throw new PathViolation("path_invalid_character", path);
|
|
@@ -96,13 +128,15 @@ function checkSpelling(path) {
|
|
|
96
128
|
if (Buffer.byteLength(path, "utf8") > limits.max_path_bytes)
|
|
97
129
|
throw new PathViolation("path_too_long", path);
|
|
98
130
|
if (path.startsWith("/")) throw new PathViolation("path_not_relative", path);
|
|
99
|
-
return checkSegments(path, limits);
|
|
131
|
+
return checkSegments(path, limits, localV4);
|
|
100
132
|
}
|
|
101
|
-
|
|
102
|
-
|
|
133
|
+
|
|
134
|
+
/** @param {string} path @param {PolicyDocument["path"]} limits @param {boolean} localV4 */
|
|
135
|
+
function checkSegments(path, limits, localV4) {
|
|
103
136
|
const segments = path.split("/");
|
|
104
|
-
|
|
105
|
-
if (
|
|
137
|
+
const bare = localV4 ? segments : segments.map(withoutIgnorable);
|
|
138
|
+
if (bare.some((segment) => !segment)) throw new PathViolation("path_empty_segment", path);
|
|
139
|
+
if (bare.some((segment) => segment === "." || segment === ".."))
|
|
106
140
|
throw new PathViolation("path_dot_segment", path);
|
|
107
141
|
if (segments.some((segment) => Buffer.byteLength(segment, "utf8") > limits.max_segment_bytes))
|
|
108
142
|
throw new PathViolation("segment_too_long", path);
|
|
@@ -111,15 +145,26 @@ function checkSegments(path, limits) {
|
|
|
111
145
|
return segments;
|
|
112
146
|
}
|
|
113
147
|
|
|
148
|
+
/** Whether a segment's comparison key is a Windows 8.3 short name (GIT~1) of a name the policy refuses.
|
|
149
|
+
* @param {string} key @param {ReadonlySet<string>} stems */
|
|
150
|
+
function isShortNameAlias(key, stems) {
|
|
151
|
+
const stem = policy().shortNameShape.exec(key)?.[1];
|
|
152
|
+
return stem !== undefined && stems.has(stem);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** @typedef {"current" | "stored" | "localV4"} PathMode */
|
|
156
|
+
|
|
114
157
|
/** `path` unchanged when every client can store it and the policy lets it travel; throws PathViolation otherwise,
|
|
115
158
|
* naming the first failing check in the registry's order. @param {string} path
|
|
116
|
-
* @param {
|
|
117
|
-
export function validatePath(path,
|
|
118
|
-
const segments = checkSpelling(path);
|
|
119
|
-
const keys = segments.map(comparisonKey);
|
|
159
|
+
* @param {PathMode} [mode] */
|
|
160
|
+
export function validatePath(path, mode = "current") {
|
|
161
|
+
const segments = checkSpelling(path, mode === "localV4");
|
|
162
|
+
const keys = segments.map(mode === "localV4" ? v4ComparisonKey : comparisonKey);
|
|
120
163
|
const { reservedSegment, canonicalRoots } = policy();
|
|
121
|
-
const rules
|
|
164
|
+
const { rules, stems } = policy().paths[mode];
|
|
122
165
|
if (keys.some((key) => reservedSegment.test(key))) throw new PathViolation("reserved_name", path);
|
|
166
|
+
if (keys.some((key) => isShortNameAlias(key, stems)))
|
|
167
|
+
throw new PathViolation("segment_short_name", path);
|
|
123
168
|
const root = canonicalRoots.get(keys[0] ?? "");
|
|
124
169
|
if (root !== undefined && segments[0] !== root)
|
|
125
170
|
throw new PathViolation("reserved_path_alias", path);
|
|
@@ -134,12 +179,12 @@ export function validatePath(path, stored = false) {
|
|
|
134
179
|
}
|
|
135
180
|
|
|
136
181
|
/** Refuses duplicates, and any two paths (or a path and a directory prefix) one filesystem would store as one name.
|
|
137
|
-
* Each path must already pass validatePath. @param {readonly string[]} paths */
|
|
138
|
-
export function checkInventoryPaths(paths) {
|
|
182
|
+
* Each path must already pass validatePath. @param {readonly string[]} paths @param {(value: string) => string} [keyOf] */
|
|
183
|
+
export function checkInventoryPaths(paths, keyOf = comparisonKey) {
|
|
139
184
|
const seen = { spellingByKey: new Map(), fileKeys: new Set(), directoryKeys: new Set() };
|
|
140
185
|
for (const path of paths) {
|
|
141
186
|
const segments = path.split("/");
|
|
142
|
-
const keys = segments.map(
|
|
187
|
+
const keys = segments.map(keyOf);
|
|
143
188
|
for (let depth = 1; depth <= segments.length; depth++)
|
|
144
189
|
notePrefix(seen, path, {
|
|
145
190
|
prefix: segments.slice(0, depth).join("/"),
|
|
@@ -166,7 +211,7 @@ function notePrefix(seen, path, { prefix, key, isFile }) {
|
|
|
166
211
|
/** The registry's `client_prefilter`: a name (macOS's `Icon\r`) skipped before any path check. @param {string} name */
|
|
167
212
|
export const prefiltered = (name) => policy().prefilter.has(name);
|
|
168
213
|
|
|
169
|
-
/** The registry's `client_symlinks`: a link under `assets/podcast/` is skipped
|
|
214
|
+
/** The registry's `client_symlinks.skip_prefixes`: a link under `assets/podcast/` is skipped, never followed.
|
|
170
215
|
* @param {string} path */
|
|
171
216
|
export const skippedSymlink = (path) =>
|
|
172
217
|
policy().symlinkPrefixes.some((prefix) => foldedPath(path).startsWith(prefix));
|
|
@@ -200,3 +245,19 @@ export function excludedFolder(dir) {
|
|
|
200
245
|
return !(prefix.startsWith(`${folded}/`) || `${folded}/`.startsWith(prefix));
|
|
201
246
|
});
|
|
202
247
|
}
|
|
248
|
+
|
|
249
|
+
/** Private names omitted locally even when the wire contract accepts them. @param {string} path */
|
|
250
|
+
export const isPrivateSourcePath = (path) =>
|
|
251
|
+
isVcsOrSecretPath(path) || isCredentialOrToolStatePath(path);
|
|
252
|
+
|
|
253
|
+
/** A stored manifest may contain paths that are no longer eligible for upload. @param {string} path */
|
|
254
|
+
export function canUploadStoredPath(path) {
|
|
255
|
+
if (isPrivateSourcePath(path)) return false;
|
|
256
|
+
try {
|
|
257
|
+
validatePath(path);
|
|
258
|
+
return true;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (error instanceof PathViolation) return false;
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
}
|
package/src/sources/store.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { constants } from "node:fs";
|
|
|
4
4
|
import { lstat, open } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { errorCode, mkdirInside, writeJsonAtomic } from "../storage.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { localBaseDigest, readUploadIntent } from "./manifest.mjs";
|
|
8
8
|
|
|
9
9
|
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
10
10
|
const object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -32,16 +32,13 @@ function checkSnapshots(raw) {
|
|
|
32
32
|
raw.base !== null &&
|
|
33
33
|
(!object(raw.base) ||
|
|
34
34
|
typeof raw.base.snapshotId !== "string" ||
|
|
35
|
-
|
|
35
|
+
localBaseDigest(raw.base.manifest) !== raw.base.manifestSha256)
|
|
36
36
|
)
|
|
37
37
|
throw new Error("Invalid source base snapshot.");
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
(!object(raw.inflight) ||
|
|
41
|
-
typeof raw.inflight.idempotencyKey !== "string" ||
|
|
42
|
-
parseStoredManifest(raw.inflight.manifest).sha256 !== raw.inflight.manifestSha256)
|
|
43
|
-
)
|
|
38
|
+
if (raw.inflight === null) return;
|
|
39
|
+
if (!object(raw.inflight) || typeof raw.inflight.idempotencyKey !== "string")
|
|
44
40
|
throw new Error("Invalid pending source upload.");
|
|
41
|
+
readUploadIntent(raw.inflight);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
/** Project-local state is excluded by the portable source policy. Account/root mismatches fail closed, including copied folders.
|
package/src/sources/types.d.ts
CHANGED
|
@@ -61,7 +61,10 @@ export interface PathRule {
|
|
|
61
61
|
/** The fields of contract/path-policy.json this client reads. */
|
|
62
62
|
export interface PolicyDocument {
|
|
63
63
|
policy_version: string;
|
|
64
|
-
stored_manifest: {
|
|
64
|
+
stored_manifest: {
|
|
65
|
+
legacy_rule_regexes: Record<string, string>;
|
|
66
|
+
legacy_short_name_alias_names: string[];
|
|
67
|
+
};
|
|
65
68
|
unicode: { version: string };
|
|
66
69
|
rules: PathRule[];
|
|
67
70
|
path: {
|
|
@@ -70,6 +73,8 @@ export interface PolicyDocument {
|
|
|
70
73
|
forbidden_characters: string;
|
|
71
74
|
reserved_segment_regex: string;
|
|
72
75
|
canonical_spelling_roots: string[];
|
|
76
|
+
short_name_alias_names: string[];
|
|
77
|
+
short_name_alias_shape: string;
|
|
73
78
|
};
|
|
74
79
|
client_prefilter: { names: string[] };
|
|
75
80
|
client_symlinks: { skip_prefixes: string[] };
|
package/src/sources/unicode.mjs
CHANGED
|
@@ -146,17 +146,38 @@ export function allAssigned(value) {
|
|
|
146
146
|
return true;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/** @type {RegExp | null} */
|
|
150
|
+
let ignorableLoaded = null;
|
|
151
|
+
/** The path policy's `unicode.ignorable_code_points`, inclusive [first, last] hex ranges, as one character class. */
|
|
152
|
+
const ignorable = () =>
|
|
153
|
+
(ignorableLoaded ??= new RegExp(
|
|
154
|
+
`[${readContract("path-policy.json")
|
|
155
|
+
.unicode.ignorable_code_points.map(
|
|
156
|
+
(/** @type {[string, string]} */ [first, last]) => `\\u{${first}}-\\u{${last}}`,
|
|
157
|
+
)
|
|
158
|
+
.join("")}]`,
|
|
159
|
+
"gu",
|
|
160
|
+
));
|
|
161
|
+
|
|
162
|
+
/** `value` without the code points HFS+ skips when it compares names (ZWNJ, ZWJ, bidi controls, BOM).
|
|
163
|
+
* @param {string} value */
|
|
164
|
+
export const withoutIgnorable = (value) =>
|
|
165
|
+
ASCII.test(value) ? value : value.replace(ignorable(), "");
|
|
166
|
+
|
|
149
167
|
/** Directory names repeat across a manifest's paths, and each segment is keyed twice (policy, then collisions). */
|
|
150
168
|
const KEYS_KEPT = 16384;
|
|
151
169
|
/** @type {Map<string, string>} */
|
|
152
170
|
const keys = new Map();
|
|
153
171
|
|
|
154
|
-
/** The
|
|
155
|
-
|
|
172
|
+
/** The v4 inventory kept ignorable characters when comparing filenames. @param {string} value */
|
|
173
|
+
export const v4ComparisonKey = (value) => nfc(fullCasefold(nfc(value)));
|
|
174
|
+
|
|
175
|
+
/** The spelling two names share on a case-insensitive, normalizing or HFS+ filesystem:
|
|
176
|
+
* NFC(casefold(NFC(value))) once the code points HFS+ ignores are removed. @param {string} value */
|
|
156
177
|
export function comparisonKey(value) {
|
|
157
178
|
const known = keys.get(value);
|
|
158
179
|
if (known !== undefined) return known;
|
|
159
|
-
const key =
|
|
180
|
+
const key = v4ComparisonKey(withoutIgnorable(value));
|
|
160
181
|
if (keys.size >= KEYS_KEPT) keys.clear();
|
|
161
182
|
keys.set(value, key);
|
|
162
183
|
return key;
|
package/src/sources/upload.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { NotWritable, uploadNeeded } from "./uploadFiles.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { canUploadStoredPath } from "./pathPolicy.mjs";
|
|
6
|
+
import { readUploadIntent } from "./manifest.mjs";
|
|
6
7
|
import { SyncApiError } from "./errors.mjs";
|
|
7
8
|
|
|
8
9
|
/** @typedef {import("./adapterTypes.js").SourceRun} SourceRun
|
|
@@ -129,12 +130,19 @@ export async function recoverSourceUpload(job) {
|
|
|
129
130
|
const { binding, api } = job;
|
|
130
131
|
const saved = binding.inflight;
|
|
131
132
|
if (!saved) return null;
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
const intent = readUploadIntent(saved);
|
|
134
|
+
if (
|
|
135
|
+
!intent ||
|
|
136
|
+
("manifest" in intent &&
|
|
137
|
+
intent.manifest.document.files.some(({ path }) => !canUploadStoredPath(path)))
|
|
138
|
+
) {
|
|
139
|
+
await clearIntent(job);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
let receipt =
|
|
143
|
+
"uploadId" in intent
|
|
144
|
+
? await api.status(binding.ownerSpaceId, binding.compositionId, intent.uploadId)
|
|
145
|
+
: await begin({ ...job, manifest: intent.manifest });
|
|
138
146
|
assertReceipt(binding, receipt);
|
|
139
147
|
if (receipt.status === "pending") receipt = await cancelPending(job, receipt);
|
|
140
148
|
assertReceipt(binding, receipt);
|