@1agh/maude 2.0.2 → 2.0.3
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/apps/studio/asset-placeholder.tsx +157 -62
- package/apps/studio/bridge/dgn-protocol.ts +34 -4
- package/apps/studio/client/app.jsx +3 -0
- package/apps/studio/client/v2/assets/asset-state-lane.js +170 -5
- package/apps/studio/client/v2/assets/missing-frame.jsx +8 -4
- package/apps/studio/client/v2/export/native-save.js +44 -0
- package/apps/studio/dist/client.bundle.js +744 -743
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/ds-assets.ts +138 -48
- package/apps/studio/routes/asset-state.ts +12 -0
- package/apps/studio/routes/ds-assets.ts +8 -0
- package/apps/studio/sync/asset-push.ts +8 -1
- package/apps/studio/sync/asset-state.ts +27 -2
- package/apps/studio/sync/file-plane.ts +36 -7
- package/apps/studio/sync/lfs-pointer.ts +137 -0
- package/apps/studio/whats-new.json +9 -0
- package/package.json +8 -8
package/apps/studio/ds-assets.ts
CHANGED
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
// nor shifts a page); `limit` defaults to 200 and is capped at 500.
|
|
20
20
|
// - `candidates` (a canvas-only session): the listing is built from THOSE paths only (the session's closure), never
|
|
21
21
|
// from the disk — such a session learns nothing about a file its canvases do not show.
|
|
22
|
+
// - `journal` (2.0.3, a materializing cell): on a cell the disk is a cache (DDR-243) — a system's media lives in the
|
|
23
|
+
// bucket and is served from a hub-owned cache outside the design root, never at its checkout path, so a disk-only
|
|
24
|
+
// listing showed every folder with 0 files. The hub's inert-media listing (`listMaterializable`, the source the file
|
|
25
|
+
// tree and the closure's `withJournalMedia` read) joins the disk: its paths under the library count, list, search and
|
|
26
|
+
// page like files on disk (size/mtime 0 — the hub hands out paths only). It only ADDS names: a disk entry at the same
|
|
27
|
+
// path (a symlink included) is judged as before, and a folder that is a symlink on disk stays refused.
|
|
22
28
|
|
|
23
29
|
import type { Dirent } from 'node:fs';
|
|
24
30
|
import { lstat, readdir } from 'node:fs/promises';
|
|
@@ -120,19 +126,37 @@ function clampLimit(raw: unknown): number {
|
|
|
120
126
|
return Math.min(Math.trunc(n), DS_ASSETS_LIMIT_MAX);
|
|
121
127
|
}
|
|
122
128
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The folders from the designRoot down to `rel`: `real` when every one is a real folder, `bad` when one is a symlink or
|
|
131
|
+
* not a folder, `absent` when the chain stops at a name that is not there (only the journal can hold files below it).
|
|
132
|
+
*/
|
|
133
|
+
async function dirChain(designRoot: string, rel: string): Promise<'real' | 'absent' | 'bad'> {
|
|
125
134
|
let cur = designRoot;
|
|
126
135
|
for (const seg of rel.split('/')) {
|
|
127
136
|
cur = path.join(cur, seg);
|
|
128
137
|
try {
|
|
129
138
|
const st = await lstat(cur);
|
|
130
|
-
if (!st.isDirectory()) return
|
|
131
|
-
} catch {
|
|
132
|
-
return
|
|
139
|
+
if (!st.isDirectory()) return 'bad';
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return (err as NodeJS.ErrnoException)?.code === 'ENOENT' ? 'absent' : 'bad';
|
|
133
142
|
}
|
|
134
143
|
}
|
|
135
|
-
return
|
|
144
|
+
return 'real';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The journal's media below `base` (designRoot-relative), shape-checked: no empty / `..` / `_` / `.` segment. */
|
|
148
|
+
function journalUnder(base: string, journal: Iterable<string> | null | undefined): Set<string> {
|
|
149
|
+
const out = new Set<string>();
|
|
150
|
+
if (!journal) return out;
|
|
151
|
+
const under = `${base}/`;
|
|
152
|
+
for (const rel of journal) {
|
|
153
|
+
if (typeof rel !== 'string' || !rel.startsWith(under) || rel.length > 1024) continue;
|
|
154
|
+
const segs = rel.slice(under.length).split('/');
|
|
155
|
+
if (segs.some((s) => !s || s === '..' || hiddenName(s) || s.includes('\\') || s.includes('\0')))
|
|
156
|
+
continue;
|
|
157
|
+
if (dsAssetKindOf(rel)) out.add(rel);
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
136
160
|
}
|
|
137
161
|
|
|
138
162
|
async function dirents(abs: string): Promise<Dirent[]> {
|
|
@@ -143,16 +167,16 @@ async function dirents(abs: string): Promise<Dirent[]> {
|
|
|
143
167
|
}
|
|
144
168
|
}
|
|
145
169
|
|
|
146
|
-
/** Media files directly inside, and whether a folder is inside (a folder with neither is not one to open). */
|
|
147
|
-
async function shallowCount(abs: string): Promise<{
|
|
148
|
-
|
|
170
|
+
/** Media files directly inside (by name), and whether a folder is inside (a folder with neither is not one to open). */
|
|
171
|
+
async function shallowCount(abs: string): Promise<{ names: Set<string>; dirs: boolean }> {
|
|
172
|
+
const names = new Set<string>();
|
|
149
173
|
let dirs = false;
|
|
150
174
|
for (const e of await dirents(abs)) {
|
|
151
175
|
if (hiddenName(e.name)) continue;
|
|
152
176
|
if (e.isDirectory()) dirs = true;
|
|
153
|
-
else if (e.isFile() && dsAssetKindOf(e.name))
|
|
177
|
+
else if (e.isFile() && dsAssetKindOf(e.name)) names.add(e.name);
|
|
154
178
|
}
|
|
155
|
-
return {
|
|
179
|
+
return { names, dirs };
|
|
156
180
|
}
|
|
157
181
|
|
|
158
182
|
/** Media files under `startRel` (designRoot-relative), readdir only. */
|
|
@@ -174,23 +198,30 @@ async function walkMedia(designRoot: string, startRel: string): Promise<string[]
|
|
|
174
198
|
return out;
|
|
175
199
|
}
|
|
176
200
|
|
|
177
|
-
async function rowOf(
|
|
201
|
+
async function rowOf(
|
|
202
|
+
designRoot: string,
|
|
203
|
+
rel: string,
|
|
204
|
+
journal: ReadonlySet<string>
|
|
205
|
+
): Promise<DsAssetFile | null> {
|
|
178
206
|
const name = rel.slice(rel.lastIndexOf('/') + 1);
|
|
179
207
|
const kind = dsAssetKindOf(name);
|
|
180
208
|
if (!kind) return null;
|
|
209
|
+
const row = (size: number, mtimeMs: number): DsAssetFile => ({
|
|
210
|
+
path: rel,
|
|
211
|
+
name,
|
|
212
|
+
ext: path.extname(name).slice(1).toLowerCase(),
|
|
213
|
+
kind,
|
|
214
|
+
size,
|
|
215
|
+
mtimeMs,
|
|
216
|
+
placeable: kind !== 'audio' && dsAssetRel(rel) !== null,
|
|
217
|
+
});
|
|
181
218
|
try {
|
|
182
219
|
const st = await lstat(path.join(designRoot, rel));
|
|
183
220
|
if (!st.isFile()) return null;
|
|
184
|
-
return
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
kind,
|
|
189
|
-
size: st.size,
|
|
190
|
-
mtimeMs: st.mtimeMs,
|
|
191
|
-
placeable: kind !== 'audio' && dsAssetRel(rel) !== null,
|
|
192
|
-
};
|
|
193
|
-
} catch {
|
|
221
|
+
return row(st.size, st.mtimeMs);
|
|
222
|
+
} catch (err) {
|
|
223
|
+
// not on this disk: a materializing cell's journal names it (the hub serves it from its cache)
|
|
224
|
+
if ((err as NodeJS.ErrnoException)?.code === 'ENOENT' && journal.has(rel)) return row(0, 0);
|
|
194
225
|
return null;
|
|
195
226
|
}
|
|
196
227
|
}
|
|
@@ -205,6 +236,8 @@ export interface ListDsAssetsInput {
|
|
|
205
236
|
limit?: unknown;
|
|
206
237
|
/** a canvas-only session: the designRoot-relative paths it may see (its closure); the disk is not walked */
|
|
207
238
|
candidates?: Iterable<string>;
|
|
239
|
+
/** a materializing cell: inert media the hub serves although the checkout does not hold it (designRoot-relative) */
|
|
240
|
+
journal?: Iterable<string> | null;
|
|
208
241
|
}
|
|
209
242
|
|
|
210
243
|
export async function listDsAssets(
|
|
@@ -219,6 +252,23 @@ export async function listDsAssets(
|
|
|
219
252
|
const words = searchWords(input.q);
|
|
220
253
|
const limit = clampLimit(input.limit);
|
|
221
254
|
const cursor = typeof input.cursor === 'string' && input.cursor ? input.cursor : null;
|
|
255
|
+
const journal = journalUnder(base, input.journal);
|
|
256
|
+
// one lstat chain per folder, shared by every path below it
|
|
257
|
+
const chains = new Map<string, Promise<'real' | 'absent' | 'bad'>>();
|
|
258
|
+
const chainOf = (d: string) => {
|
|
259
|
+
let p = chains.get(d);
|
|
260
|
+
if (!p) {
|
|
261
|
+
p = dirChain(designRoot, d);
|
|
262
|
+
chains.set(d, p);
|
|
263
|
+
}
|
|
264
|
+
return p;
|
|
265
|
+
};
|
|
266
|
+
const parentOf = (rel: string) => rel.slice(0, rel.lastIndexOf('/'));
|
|
267
|
+
/** journal paths, minus any whose folder on the way is a symlink (or not a folder) on this disk */
|
|
268
|
+
const journalOk = async (rels: string[]) => {
|
|
269
|
+
const ok = await Promise.all(rels.map(async (r) => (await chainOf(parentOf(r))) !== 'bad'));
|
|
270
|
+
return rels.filter((_, i) => ok[i]);
|
|
271
|
+
};
|
|
222
272
|
|
|
223
273
|
// The candidate files (designRoot-relative) and the folders directly below `base`.
|
|
224
274
|
let files: string[];
|
|
@@ -247,42 +297,82 @@ export async function listDsAssets(
|
|
|
247
297
|
// listed file is a real one (a symlinked folder is not walked in a project listing either)
|
|
248
298
|
if (dir && !files.length && !dirCounts.size)
|
|
249
299
|
return { ok: false, status: 404, reason: 'not-found' };
|
|
250
|
-
|
|
251
|
-
const
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return
|
|
300
|
+
// on a cell a closure path may be the journal's only, in a folder this disk does not hold at all
|
|
301
|
+
const journalBelow = (d: string) => {
|
|
302
|
+
for (const r of journal) if (r.startsWith(`${d}/`)) return true;
|
|
303
|
+
return false;
|
|
304
|
+
};
|
|
305
|
+
const fileOk = async (rel: string) => {
|
|
306
|
+
const c = await chainOf(parentOf(rel));
|
|
307
|
+
return c === 'real' || (c === 'absent' && journal.has(rel));
|
|
258
308
|
};
|
|
259
|
-
const ok = await Promise.all(files.map(
|
|
309
|
+
const ok = await Promise.all(files.map(fileOk));
|
|
260
310
|
files = files.filter((_, i) => ok[i]);
|
|
261
|
-
for (const d of [...dirCounts.keys()])
|
|
262
|
-
|
|
311
|
+
for (const d of [...dirCounts.keys()]) {
|
|
312
|
+
const c = await chainOf(d);
|
|
313
|
+
if (!(c === 'real' || (c === 'absent' && journalBelow(d)))) dirCounts.delete(d);
|
|
314
|
+
}
|
|
263
315
|
} else {
|
|
264
|
-
|
|
316
|
+
const baseChain = await chainOf(base);
|
|
317
|
+
if (baseChain === 'bad' || (baseChain === 'absent' && !journal.size)) {
|
|
265
318
|
// no library yet is an empty one; a folder that is not there (or a symlink) is not found
|
|
266
|
-
if (!dir &&
|
|
319
|
+
if (!dir && (await chainOf(root)) === 'absent')
|
|
267
320
|
return { ok: true, root, dir, dirs: [], files: [], total: 0, next: null };
|
|
268
321
|
return { ok: false, status: 404, reason: 'not-found' };
|
|
269
322
|
}
|
|
323
|
+
const onDisk = baseChain === 'real';
|
|
270
324
|
if (words.length) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
);
|
|
325
|
+
const all = new Set(onDisk ? await walkMedia(designRoot, base) : []);
|
|
326
|
+
for (const r of await journalOk([...journal].filter((r) => !all.has(r)))) all.add(r);
|
|
327
|
+
files = [...all].filter((rel) => matches(rel.slice(rel.lastIndexOf('/') + 1), words));
|
|
274
328
|
} else {
|
|
275
|
-
|
|
276
|
-
const subdirs
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
329
|
+
const here = new Set<string>();
|
|
330
|
+
const subdirs = new Set<string>();
|
|
331
|
+
if (onDisk)
|
|
332
|
+
for (const e of await dirents(path.join(designRoot, base))) {
|
|
333
|
+
if (hiddenName(e.name)) continue;
|
|
334
|
+
if (e.isDirectory()) subdirs.add(`${base}/${e.name}`);
|
|
335
|
+
else if (e.isFile() && dsAssetKindOf(e.name)) here.add(`${base}/${e.name}`);
|
|
336
|
+
}
|
|
337
|
+
// the journal's: files directly in this folder, and the folders below it (by their first segment)
|
|
338
|
+
const direct: string[] = [];
|
|
339
|
+
const below = new Map<string, string[]>();
|
|
340
|
+
for (const r of journal) {
|
|
341
|
+
const rest = r.slice(base.length + 1);
|
|
342
|
+
const slash = rest.indexOf('/');
|
|
343
|
+
if (slash < 0) {
|
|
344
|
+
if (!here.has(r)) direct.push(r);
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const d = `${base}/${rest.slice(0, slash)}`;
|
|
348
|
+
const list = below.get(d);
|
|
349
|
+
if (list) list.push(r);
|
|
350
|
+
else below.set(d, [r]);
|
|
281
351
|
}
|
|
352
|
+
for (const r of await journalOk(direct)) here.add(r);
|
|
353
|
+
files = [...here];
|
|
282
354
|
if (!cursor) {
|
|
283
|
-
subdirs.
|
|
284
|
-
const shown =
|
|
285
|
-
const
|
|
355
|
+
for (const d of below.keys()) subdirs.add(d);
|
|
356
|
+
const shown: string[] = [];
|
|
357
|
+
for (const d of [...subdirs].sort(byPath)) {
|
|
358
|
+
if (shown.length >= DIRS_MAX) break;
|
|
359
|
+
// a journal folder whose name is a symlink (or a file) on this disk is not one to open
|
|
360
|
+
if ((await chainOf(d)) !== 'bad') shown.push(d);
|
|
361
|
+
}
|
|
362
|
+
const counts = await Promise.all(
|
|
363
|
+
shown.map(async (d) => {
|
|
364
|
+
const c =
|
|
365
|
+
(await chainOf(d)) === 'real' ? await shallowCount(path.join(designRoot, d)) : null;
|
|
366
|
+
const names = c?.names ?? new Set<string>();
|
|
367
|
+
let dirs = c?.dirs ?? false;
|
|
368
|
+
for (const r of below.get(d) ?? []) {
|
|
369
|
+
const rest = r.slice(d.length + 1);
|
|
370
|
+
if (rest.includes('/')) dirs = true;
|
|
371
|
+
else names.add(rest);
|
|
372
|
+
}
|
|
373
|
+
return { count: names.size, dirs };
|
|
374
|
+
})
|
|
375
|
+
);
|
|
286
376
|
shown.forEach((d, i) => {
|
|
287
377
|
const c = counts[i] as { count: number; dirs: boolean };
|
|
288
378
|
if (c.count || c.dirs) dirCounts.set(d, c.count);
|
|
@@ -295,7 +385,7 @@ export async function listDsAssets(
|
|
|
295
385
|
const total = files.length;
|
|
296
386
|
const from = cursor ? files.findIndex((f) => byPath(f, cursor) > 0) : 0;
|
|
297
387
|
const slice = from < 0 ? [] : files.slice(from, from + limit);
|
|
298
|
-
const rows = (await Promise.all(slice.map((rel) => rowOf(designRoot, rel)))).filter(
|
|
388
|
+
const rows = (await Promise.all(slice.map((rel) => rowOf(designRoot, rel, journal)))).filter(
|
|
299
389
|
(r): r is DsAssetFile => r !== null
|
|
300
390
|
);
|
|
301
391
|
const more = from >= 0 && from + limit < files.length;
|
|
@@ -67,6 +67,9 @@ export function assetStateDepsFor(opts: {
|
|
|
67
67
|
const inCell = (opts.env ?? process.env).MAUDE_WORKSPACE_MODE === '1';
|
|
68
68
|
const service = createAssetStateService({
|
|
69
69
|
designRoot: opts.designRoot,
|
|
70
|
+
// The project root is designRoot minus designRel (`.design`): where the Git LFS store is looked
|
|
71
|
+
// for. The server's own paths, never a request's.
|
|
72
|
+
projectRoot: projectRootOf(opts.designRoot, opts.designRel),
|
|
70
73
|
hub: () => opts.runtime()?.assetPresenceAsker?.() ?? null,
|
|
71
74
|
uploading: () => opts.runtime()?.assetUploading?.() ?? null,
|
|
72
75
|
});
|
|
@@ -78,6 +81,15 @@ export function assetStateDepsFor(opts: {
|
|
|
78
81
|
};
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
/** `<repo>/.design` + `.design` → `<repo>`. */
|
|
85
|
+
export function projectRootOf(designRoot: string, designRel: string): string {
|
|
86
|
+
const ups = designRel
|
|
87
|
+
.split(/[\\/]+/)
|
|
88
|
+
.filter((s) => s && s !== '.')
|
|
89
|
+
.map(() => '..');
|
|
90
|
+
return path.resolve(designRoot, ...ups);
|
|
91
|
+
}
|
|
92
|
+
|
|
81
93
|
function canvasRels(deps: AssetStateRouteDeps, file: string): string[] | null {
|
|
82
94
|
if (!deps.designRoot || deps.designRel === undefined) return null;
|
|
83
95
|
const rel = resolveCanvasRel(deps.designRoot, deps.designRel, file);
|
|
@@ -15,9 +15,14 @@
|
|
|
15
15
|
// MAIN ORIGIN ONLY, never canvas-safe (a shell panel's read; absent from both canvas allowlists). Reads only, for
|
|
16
16
|
// every role that can read the project. A canvas-only session is answered from its closure alone (`filterAssetListing`'s
|
|
17
17
|
// rule for `/_api/assets`): the files its canvases' closure reads, and no folder without one.
|
|
18
|
+
//
|
|
19
|
+
// ON A MATERIALIZING CELL (2.0.3) the system's media is in the hub's journal, not on the checkout (DDR-243): the hub's
|
|
20
|
+
// inert-media listing (`listMaterializable` — the file tree's and the closure's source) joins the disk, so the folders
|
|
21
|
+
// carry their counts and files again. Off a cell it answers `null` at once and the disk alone is listed, as before.
|
|
18
22
|
|
|
19
23
|
import type { Visibility } from '../access/filters.ts';
|
|
20
24
|
import { listDsAssets } from '../ds-assets.ts';
|
|
25
|
+
import { listMaterializable } from '../materialize-client.ts';
|
|
21
26
|
import type { RouteSpec } from './table.ts';
|
|
22
27
|
|
|
23
28
|
const json = (status: number, body: unknown) =>
|
|
@@ -29,6 +34,8 @@ export interface DsAssetsRouteDeps {
|
|
|
29
34
|
systems: () => ReadonlyArray<{ name: string; path: string }>;
|
|
30
35
|
/** The session's visibility (http.ts `visOf`). */
|
|
31
36
|
visibility: (req: Request) => Visibility;
|
|
37
|
+
/** A materializing cell's journal media (designRoot-relative); `null` off a cell. Default `listMaterializable`. */
|
|
38
|
+
journalMedia?: () => Promise<readonly string[] | null>;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
export function createDsAssetsRoutes(deps: DsAssetsRouteDeps): RouteSpec[] {
|
|
@@ -58,6 +65,7 @@ export function createDsAssetsRoutes(deps: DsAssetsRouteDeps): RouteSpec[] {
|
|
|
58
65
|
cursor: q.get('cursor'),
|
|
59
66
|
limit: q.get('limit'),
|
|
60
67
|
...(candidates ? { candidates } : {}),
|
|
68
|
+
journal: await (deps.journalMedia ?? listMaterializable)(),
|
|
61
69
|
});
|
|
62
70
|
if (!page.ok) return json(page.status, { ok: false, reason: page.reason });
|
|
63
71
|
// a canvas-only session that sees nothing of this library is told it is not there
|
|
@@ -45,6 +45,7 @@ import { type Dirent, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
|
45
45
|
import path from 'node:path';
|
|
46
46
|
|
|
47
47
|
import { type CanvasGroupLike, classifyProjectFile, isFilePlaneClass } from './file-membership.ts';
|
|
48
|
+
import { readLfsPointer } from './lfs-pointer.ts';
|
|
48
49
|
import { failureReason, retryAfterMs } from './retry-after.ts';
|
|
49
50
|
|
|
50
51
|
/** Max designRoot-relative depth (matches the classifier's 8-segment cap). */
|
|
@@ -437,10 +438,16 @@ export async function pushAssets(opts: {
|
|
|
437
438
|
const base = hubUrl.replace(/\/+$/, '');
|
|
438
439
|
const out: AssetPushResult = { pushed: [], skipped: 0, failed: [] };
|
|
439
440
|
|
|
440
|
-
const
|
|
441
|
+
const listed = listPushableAssets(designRoot, {
|
|
441
442
|
canvasGroups: opts.canvasGroups,
|
|
442
443
|
syncFiles: opts.syncFiles,
|
|
443
444
|
});
|
|
445
|
+
// 2.0.3 — a Git LFS pointer (a clone without `git lfs pull`) is not the media: never pushed as it.
|
|
446
|
+
const assets = listed.filter((rel) => readLfsPointer(path.join(designRoot, rel)) === null);
|
|
447
|
+
if (assets.length < listed.length)
|
|
448
|
+
log.warn(
|
|
449
|
+
`[asset-push] ${listed.length - assets.length} Git LFS placeholder(s) not uploaded — run git lfs pull`
|
|
450
|
+
);
|
|
444
451
|
// -Infinity seeds the throttle open, so the first emit always passes.
|
|
445
452
|
let lastEmit = -Infinity;
|
|
446
453
|
const emitProgress = (active: string | null, finished: boolean, force = false): void => {
|
|
@@ -27,6 +27,7 @@ import path from 'node:path';
|
|
|
27
27
|
|
|
28
28
|
import { listPushableAssets } from './asset-push.ts';
|
|
29
29
|
import { type CanvasGroupLike, classifyProjectFile } from './file-membership.ts';
|
|
30
|
+
import { hasLfsObject, lfsObjectsDir, readLfsPointer } from './lfs-pointer.ts';
|
|
30
31
|
|
|
31
32
|
export interface AssetWho {
|
|
32
33
|
name: string | null;
|
|
@@ -40,7 +41,12 @@ export type AssetState =
|
|
|
40
41
|
| { state: 'uploading'; progress?: number }
|
|
41
42
|
/** `syncing`: the hub has the bytes, this Mac has not pulled them yet ("Syncing…"). */
|
|
42
43
|
| { state: 'waiting'; who?: AssetWho; syncing?: true }
|
|
43
|
-
| { state: 'missing' }
|
|
44
|
+
| { state: 'missing' }
|
|
45
|
+
/**
|
|
46
|
+
* 2.0.3: the file IS on this disk, but it is a Git LFS pointer (the project was cloned without
|
|
47
|
+
* `git lfs pull`). `localObject`: the real bytes are already in this repo's `.git/lfs/objects`.
|
|
48
|
+
*/
|
|
49
|
+
| { state: 'lfs-pointer'; localObject: boolean };
|
|
44
50
|
|
|
45
51
|
export type HubPresenceState = 'here' | 'waiting' | 'missing' | 'unknown';
|
|
46
52
|
export interface HubPresenceItem {
|
|
@@ -79,11 +85,15 @@ export function isAssetStateRel(rel: unknown): rel is string {
|
|
|
79
85
|
*/
|
|
80
86
|
export function combineAssetState(input: {
|
|
81
87
|
onDisk: boolean;
|
|
88
|
+
/** The file on disk is a Git LFS pointer (wins over `uploading`: those bytes are not the media). */
|
|
89
|
+
lfsPointer?: { localObject: boolean } | null;
|
|
82
90
|
uploading?: { progress?: number } | null;
|
|
83
91
|
linked: boolean;
|
|
84
92
|
hub: HubPresenceItem | null;
|
|
85
93
|
}): AssetState {
|
|
86
94
|
if (input.onDisk) {
|
|
95
|
+
if (input.lfsPointer)
|
|
96
|
+
return { state: 'lfs-pointer', localObject: input.lfsPointer.localObject };
|
|
87
97
|
if (input.uploading) {
|
|
88
98
|
return input.uploading.progress === undefined
|
|
89
99
|
? { state: 'uploading' }
|
|
@@ -234,6 +244,8 @@ export interface AssetStateService {
|
|
|
234
244
|
*/
|
|
235
245
|
export function createAssetStateService(deps: {
|
|
236
246
|
designRoot: string;
|
|
247
|
+
/** The project root, for the Git LFS object store (`lfs-pointer` → `localObject`). Absent: never local. */
|
|
248
|
+
projectRoot?: string;
|
|
237
249
|
hub: () => AssetPresenceAsker | null;
|
|
238
250
|
uploading?: () => ReadonlyMap<string, { progress?: number }> | null;
|
|
239
251
|
now?: () => number;
|
|
@@ -242,6 +254,13 @@ export function createAssetStateService(deps: {
|
|
|
242
254
|
const now = deps.now ?? Date.now;
|
|
243
255
|
const ttl = deps.ttlMs ?? ASSET_STATE_TTL_MS;
|
|
244
256
|
const cache = new Map<string, { at: number; item: HubPresenceItem | null }>();
|
|
257
|
+
// The server's own project root, resolved once (never from a request).
|
|
258
|
+
let objectsDir: string | null | undefined;
|
|
259
|
+
const store = () => {
|
|
260
|
+
if (objectsDir === undefined)
|
|
261
|
+
objectsDir = deps.projectRoot ? lfsObjectsDir(deps.projectRoot) : null;
|
|
262
|
+
return objectsDir;
|
|
263
|
+
};
|
|
245
264
|
|
|
246
265
|
return {
|
|
247
266
|
invalidate: () => cache.clear(),
|
|
@@ -271,8 +290,11 @@ export function createAssetStateService(deps: {
|
|
|
271
290
|
}
|
|
272
291
|
const out: Record<string, AssetState> = {};
|
|
273
292
|
for (const r of wanted) {
|
|
293
|
+
// ≤ 1 KB read, and only of a small file that is here (readLfsPointer stats first).
|
|
294
|
+
const ptr = onDisk.get(r) ? readLfsPointer(path.join(deps.designRoot, r)) : null;
|
|
274
295
|
out[r] = combineAssetState({
|
|
275
296
|
onDisk: onDisk.get(r) === true,
|
|
297
|
+
lfsPointer: ptr ? { localObject: hasLfsObject(store(), ptr.oid) } : null,
|
|
276
298
|
uploading: queue?.get(r) ?? null,
|
|
277
299
|
linked: hub !== null,
|
|
278
300
|
hub: hub ? (cache.get(r)?.item ?? null) : null,
|
|
@@ -340,7 +362,10 @@ export function heldMediaRels(
|
|
|
340
362
|
canvasGroups: opts.canvasGroups,
|
|
341
363
|
syncFiles: true,
|
|
342
364
|
}).filter(
|
|
343
|
-
(rel) =>
|
|
365
|
+
(rel) =>
|
|
366
|
+
classifyProjectFile(rel, { canvasGroups: opts.canvasGroups }) === 'inert-media' &&
|
|
367
|
+
// a Git LFS pointer is not the picture: this Mac does not hold it (2.0.3)
|
|
368
|
+
readLfsPointer(path.join(designRoot, rel)) === null
|
|
344
369
|
);
|
|
345
370
|
}
|
|
346
371
|
|
|
@@ -79,6 +79,7 @@ import {
|
|
|
79
79
|
type JournalEntry,
|
|
80
80
|
type JournalPage,
|
|
81
81
|
} from './journal-client.ts';
|
|
82
|
+
import { LFS_POINTER_REASON, readLfsPointer } from './lfs-pointer.ts';
|
|
82
83
|
import { createPullBudget } from './pull-budget.ts';
|
|
83
84
|
import { failureReason, isBackpressure, refusalWords, retryAfterMs } from './retry-after.ts';
|
|
84
85
|
import { classifyTransportError } from './transport-error.ts';
|
|
@@ -1994,13 +1995,28 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1994
1995
|
out.synced += 1;
|
|
1995
1996
|
continue;
|
|
1996
1997
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
)
|
|
2003
|
-
|
|
1998
|
+
// NOR IS AN UPLOAD A LANDING (2.0.3). The hub still holds exactly what
|
|
1999
|
+
// we last agreed on, so the only thing that moved is OUR copy: this is
|
|
2000
|
+
// the upward half, which the upload gate below decides (the door then
|
|
2001
|
+
// enforces the owner role). Refusing it here meant an owner without
|
|
2002
|
+
// receive consent uploaded each code module once and never again — the
|
|
2003
|
+
// cell kept the first version (alligators, 2.0.2). Anything else — the
|
|
2004
|
+
// hub moved, or there is no agreed ancestor — still never lands here.
|
|
2005
|
+
const ancestor = ledger.ancestorOf(rel);
|
|
2006
|
+
const uploadOnly =
|
|
2007
|
+
here !== undefined &&
|
|
2008
|
+
ancestor !== null &&
|
|
2009
|
+
ancestor === remoteHash &&
|
|
2010
|
+
(opts.canUploadCodeModules ?? opts.allowCodeModules);
|
|
2011
|
+
if (!uploadOnly) {
|
|
2012
|
+
drop(
|
|
2013
|
+
out,
|
|
2014
|
+
rel,
|
|
2015
|
+
'code modules replicate only from an owner-vouched or loopback hub',
|
|
2016
|
+
ledger
|
|
2017
|
+
);
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2004
2020
|
}
|
|
2005
2021
|
}
|
|
2006
2022
|
|
|
@@ -2469,6 +2485,19 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2469
2485
|
out.heldForFormat = (out.heldForFormat ?? 0) + 1;
|
|
2470
2486
|
return false;
|
|
2471
2487
|
}
|
|
2488
|
+
// 2.0.3 — a Git LFS pointer (a clone without `git lfs pull`) is not the file: never send it
|
|
2489
|
+
// up as if it were. Held like a door's refusal of exactly these bytes (`refusedHash`), so it is
|
|
2490
|
+
// said once and goes up by itself once the real file is restored (the hash changes).
|
|
2491
|
+
if (readLfsPointer(here.abs)) {
|
|
2492
|
+
ledger.setState(rel, 'refused', {
|
|
2493
|
+
reason: LFS_POINTER_REASON,
|
|
2494
|
+
blockedClass: 'refused',
|
|
2495
|
+
refusedHash: here.hash,
|
|
2496
|
+
});
|
|
2497
|
+
out.dropped.push({ rel, reason: LFS_POINTER_REASON });
|
|
2498
|
+
log.warn(`[file-plane] ${rel}: a Git LFS placeholder, not the file — not uploaded`);
|
|
2499
|
+
return true;
|
|
2500
|
+
}
|
|
2472
2501
|
ledger.setState(rel, 'pushing');
|
|
2473
2502
|
const expect = decision.action === 'revive' ? null : remoteHash;
|
|
2474
2503
|
const res = await push(here, expect);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// A Git LFS pointer file standing where a picture or clip should be (2.0.3).
|
|
2
|
+
//
|
|
3
|
+
// A project committed with Git LFS but cloned without `git lfs pull` keeps a ~130-byte text file in
|
|
4
|
+
// place of each media file:
|
|
5
|
+
//
|
|
6
|
+
// version https://git-lfs.github.com/spec/v1
|
|
7
|
+
// oid sha256:<64 hex>
|
|
8
|
+
// size <n>
|
|
9
|
+
//
|
|
10
|
+
// The canvas cannot draw it, and the sync must not send it up as if it were the media. This module
|
|
11
|
+
// only RECOGNISES one: a regular file of at most 1 KB whose first line is exactly the spec line. It
|
|
12
|
+
// never reads more than the first 1 KB and never reads a bigger file at all.
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
closeSync,
|
|
16
|
+
existsSync,
|
|
17
|
+
lstatSync,
|
|
18
|
+
openSync,
|
|
19
|
+
readFileSync,
|
|
20
|
+
readSync,
|
|
21
|
+
statSync,
|
|
22
|
+
} from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
|
|
25
|
+
/** What the sync says about a pointer it will not upload (the Sync panel shows it). */
|
|
26
|
+
export const LFS_POINTER_REASON =
|
|
27
|
+
'A Git LFS placeholder, not the file. Run git lfs pull (or Fix with AI on the picture).';
|
|
28
|
+
|
|
29
|
+
/** The pointer spec allows ≤ 1024 bytes; anything bigger is the real file. */
|
|
30
|
+
export const LFS_POINTER_MAX_BYTES = 1024;
|
|
31
|
+
export const LFS_SPEC_LINE = 'version https://git-lfs.github.com/spec/v1';
|
|
32
|
+
|
|
33
|
+
export interface LfsPointer {
|
|
34
|
+
/** The sha256 of the real file, when the pointer carries a well-formed one. */
|
|
35
|
+
oid: string | null;
|
|
36
|
+
/** The real file's size in bytes, when the pointer says it. */
|
|
37
|
+
size: number | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Parse pointer TEXT (pure). Null when it is not a pointer. */
|
|
41
|
+
export function parseLfsPointer(text: string): LfsPointer | null {
|
|
42
|
+
if (text.length > LFS_POINTER_MAX_BYTES) return null;
|
|
43
|
+
const nl = text.indexOf('\n');
|
|
44
|
+
const first = (nl === -1 ? text : text.slice(0, nl)).replace(/\r$/, '');
|
|
45
|
+
if (first !== LFS_SPEC_LINE) return null;
|
|
46
|
+
const oid = /^oid sha256:([0-9a-f]{64})\r?$/m.exec(text)?.[1] ?? null;
|
|
47
|
+
const sizeRaw = /^size (\d{1,15})\r?$/m.exec(text)?.[1];
|
|
48
|
+
return { oid, size: sizeRaw === undefined ? null : Number(sizeRaw) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Read a file and say whether it is a pointer. A symlink, a directory, a missing file or anything
|
|
53
|
+
* over 1 KB is not one (and is never opened).
|
|
54
|
+
*/
|
|
55
|
+
export function readLfsPointer(abs: string): LfsPointer | null {
|
|
56
|
+
let fd: number | null = null;
|
|
57
|
+
try {
|
|
58
|
+
const st = lstatSync(abs);
|
|
59
|
+
if (!st.isFile() || st.size > LFS_POINTER_MAX_BYTES || st.size < LFS_SPEC_LINE.length)
|
|
60
|
+
return null;
|
|
61
|
+
fd = openSync(abs, 'r');
|
|
62
|
+
const buf = Buffer.alloc(LFS_POINTER_MAX_BYTES);
|
|
63
|
+
const n = readSync(fd, buf, 0, LFS_POINTER_MAX_BYTES, 0);
|
|
64
|
+
return parseLfsPointer(buf.subarray(0, n).toString('utf8'));
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
} finally {
|
|
68
|
+
if (fd !== null) {
|
|
69
|
+
try {
|
|
70
|
+
closeSync(fd);
|
|
71
|
+
} catch {
|
|
72
|
+
/* already gone */
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** True when the bytes already in hand (≤ 1 KB) are a pointer. */
|
|
79
|
+
export function isLfsPointerBytes(bytes: Uint8Array): boolean {
|
|
80
|
+
if (bytes.byteLength > LFS_POINTER_MAX_BYTES) return false;
|
|
81
|
+
return parseLfsPointer(Buffer.from(bytes).toString('utf8')) !== null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The LFS object store of the git repository that holds `projectRoot`: `<git common dir>/lfs/objects`.
|
|
86
|
+
* Walks UP from the server's own project root (never from a request) at most `maxUp` levels to the
|
|
87
|
+
* first `.git`; a `.git` FILE (a worktree, a submodule) is followed to its `gitdir:` and that dir's
|
|
88
|
+
* `commondir`. Null when there is no repository or no LFS store.
|
|
89
|
+
*/
|
|
90
|
+
export function lfsObjectsDir(projectRoot: string, maxUp = 8): string | null {
|
|
91
|
+
let dir = path.resolve(projectRoot);
|
|
92
|
+
for (let i = 0; i <= maxUp; i++) {
|
|
93
|
+
const dotGit = path.join(dir, '.git');
|
|
94
|
+
const gitDir = resolveGitDir(dotGit);
|
|
95
|
+
if (gitDir) {
|
|
96
|
+
const store = path.join(gitDir, 'lfs', 'objects');
|
|
97
|
+
try {
|
|
98
|
+
return statSync(store).isDirectory() ? store : null;
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const up = path.dirname(dir);
|
|
104
|
+
if (up === dir) break;
|
|
105
|
+
dir = up;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function resolveGitDir(dotGit: string): string | null {
|
|
111
|
+
try {
|
|
112
|
+
const st = lstatSync(dotGit);
|
|
113
|
+
if (st.isDirectory()) return dotGit;
|
|
114
|
+
if (!st.isFile() || st.size > 4096) return null;
|
|
115
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync(dotGit, 'utf8'));
|
|
116
|
+
if (!m?.[1]) return null;
|
|
117
|
+
const gitDir = path.resolve(path.dirname(dotGit), m[1]);
|
|
118
|
+
const commonFile = path.join(gitDir, 'commondir');
|
|
119
|
+
if (existsSync(commonFile)) {
|
|
120
|
+
const common = readFileSync(commonFile, 'utf8').trim();
|
|
121
|
+
if (common) return path.resolve(gitDir, common);
|
|
122
|
+
}
|
|
123
|
+
return gitDir;
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Does the store hold the object for `oid`? The oid must be 64 lowercase hex, or the answer is false. */
|
|
130
|
+
export function hasLfsObject(objectsDir: string | null, oid: string | null): boolean {
|
|
131
|
+
if (!objectsDir || !oid || !/^[0-9a-f]{64}$/.test(oid)) return false;
|
|
132
|
+
try {
|
|
133
|
+
return statSync(path.join(objectsDir, oid.slice(0, 2), oid.slice(2, 4), oid)).isFile();
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./whats-new.schema.json",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"id": "lfs-placeholder-fix",
|
|
6
|
+
"version": "2.0.3",
|
|
7
|
+
"date": "2026-11-04",
|
|
8
|
+
"kind": "fix",
|
|
9
|
+
"title": "Pictures that were never downloaded say so",
|
|
10
|
+
"summary": "A picture or video that is still a Git LFS placeholder now says \"Not downloaded — Git LFS placeholder\" instead of \"not found\". In the desktop app, Fix with AI puts a restore prompt in the chat, and Copy prompt copies it. Sync no longer uploads the placeholder as if it were the picture.",
|
|
11
|
+
"surface": "design-ui"
|
|
12
|
+
},
|
|
4
13
|
{
|
|
5
14
|
"id": "maude-v2-canvas-window",
|
|
6
15
|
"version": "2.0.0",
|