@1agh/maude 2.0.1 → 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/access/filters.ts +24 -2
- package/apps/studio/access/frame.ts +38 -0
- package/apps/studio/access/request.ts +81 -2
- 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/hooks/use-palette-and-panels.jsx +2 -0
- package/apps/studio/client/styles/_index.css +2 -0
- package/apps/studio/client/v2/assets/asset-state-lane.js +170 -5
- package/apps/studio/client/v2/assets/ds-library-view.jsx +263 -0
- package/apps/studio/client/v2/assets/ds-library.css +123 -0
- package/apps/studio/client/v2/assets/ds-library.js +175 -0
- 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/client/v2/left-panel/assets-panel.jsx +60 -1
- package/apps/studio/dist/client.bundle.js +524 -523
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds-assets.ts +407 -0
- package/apps/studio/edit-ops/image-fit.ts +19 -2
- package/apps/studio/edit-ops/types.ts +5 -0
- package/apps/studio/editing/asset-drag.ts +8 -2
- package/apps/studio/editing/ds-asset-ref.ts +66 -0
- package/apps/studio/http.ts +17 -2
- package/apps/studio/materialize-client.ts +11 -0
- package/apps/studio/routes/asset-state.ts +12 -0
- package/apps/studio/routes/ds-assets.ts +78 -0
- package/apps/studio/routes/edit.ts +1 -0
- package/apps/studio/routes/index.ts +4 -0
- package/apps/studio/sync/accepted-link.ts +28 -6
- package/apps/studio/sync/asset-push.ts +8 -1
- package/apps/studio/sync/asset-state.ts +27 -2
- package/apps/studio/sync/availability.ts +5 -0
- package/apps/studio/sync/create-collision.ts +96 -19
- package/apps/studio/sync/file-plane.ts +36 -7
- package/apps/studio/sync/index.ts +10 -2
- package/apps/studio/sync/lfs-pointer.ts +137 -0
- package/apps/studio/sync/project-config-push.ts +8 -1
- package/apps/studio/sync/transaction-client.ts +54 -11
- package/apps/studio/sync/writer-registry.ts +2 -0
- package/apps/studio/whats-new.json +9 -0
- package/package.json +8 -8
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// routes/ds-assets.ts — `GET /_api/ds/assets` (2.0.2): a design system's own asset library, for the Assets tab's
|
|
2
|
+
// "Design system" source.
|
|
3
|
+
//
|
|
4
|
+
// GET /_api/ds/assets?ds=<name>&dir=<folder>&q=<search>&cursor=<c>&limit=<n>
|
|
5
|
+
// 200 { ok: true, ds, root, dir, dirs:[{path,name,count}], files:[{path,name,ext,kind,size,mtimeMs,placeable}],
|
|
6
|
+
// total, next } ds-assets.ts `listDsAssets`: one folder (or a search below it), one page, by name
|
|
7
|
+
// 400 { ok: false, reason: 'bad-dir' } a folder with `..`, a `_`/`.` name or a `\`
|
|
8
|
+
// 404 { ok: false, reason: 'not-found' } no such system, a folder that is not there (or is a symlink), or —
|
|
9
|
+
// for a canvas-only session — one with nothing its canvases show
|
|
10
|
+
//
|
|
11
|
+
// `ds` is a name from the project's config `designSystems` (path per system, which must be `system/<one segment>`);
|
|
12
|
+
// `path` in every row is designRoot-relative (`system/<ds>/assets/photos-cut/x.jpg`) — the shell shows it at
|
|
13
|
+
// `/<designRel>/<path>` and places it as that literal reference (editing/ds-asset-ref.ts).
|
|
14
|
+
//
|
|
15
|
+
// MAIN ORIGIN ONLY, never canvas-safe (a shell panel's read; absent from both canvas allowlists). Reads only, for
|
|
16
|
+
// every role that can read the project. A canvas-only session is answered from its closure alone (`filterAssetListing`'s
|
|
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.
|
|
22
|
+
|
|
23
|
+
import type { Visibility } from '../access/filters.ts';
|
|
24
|
+
import { listDsAssets } from '../ds-assets.ts';
|
|
25
|
+
import { listMaterializable } from '../materialize-client.ts';
|
|
26
|
+
import type { RouteSpec } from './table.ts';
|
|
27
|
+
|
|
28
|
+
const json = (status: number, body: unknown) =>
|
|
29
|
+
Response.json(body, { status, headers: { 'Cache-Control': 'no-store' } });
|
|
30
|
+
|
|
31
|
+
export interface DsAssetsRouteDeps {
|
|
32
|
+
designRoot: string;
|
|
33
|
+
/** The project's design systems (config `designSystems`), read per request. */
|
|
34
|
+
systems: () => ReadonlyArray<{ name: string; path: string }>;
|
|
35
|
+
/** The session's visibility (http.ts `visOf`). */
|
|
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>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createDsAssetsRoutes(deps: DsAssetsRouteDeps): RouteSpec[] {
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
method: 'GET',
|
|
45
|
+
path: '/_api/ds/assets',
|
|
46
|
+
origin: 'main',
|
|
47
|
+
readOnly: 'allowed',
|
|
48
|
+
handle: async (req) => {
|
|
49
|
+
const q = new URL(req.url).searchParams;
|
|
50
|
+
const name = q.get('ds') ?? '';
|
|
51
|
+
const sys =
|
|
52
|
+
name && name.length <= 64 ? deps.systems().find((s) => s.name === name) : undefined;
|
|
53
|
+
if (!sys) return json(404, { ok: false, reason: 'not-found' });
|
|
54
|
+
const vis = deps.visibility(req);
|
|
55
|
+
let candidates: string[] | undefined;
|
|
56
|
+
if (!vis.full) {
|
|
57
|
+
const closure = vis.closure();
|
|
58
|
+
candidates = closure ? [...closure.read].filter((rel) => vis.sees(rel)) : [];
|
|
59
|
+
}
|
|
60
|
+
const page = await listDsAssets({
|
|
61
|
+
designRoot: deps.designRoot,
|
|
62
|
+
systemPath: sys.path,
|
|
63
|
+
dir: q.get('dir'),
|
|
64
|
+
q: q.get('q'),
|
|
65
|
+
cursor: q.get('cursor'),
|
|
66
|
+
limit: q.get('limit'),
|
|
67
|
+
...(candidates ? { candidates } : {}),
|
|
68
|
+
journal: await (deps.journalMedia ?? listMaterializable)(),
|
|
69
|
+
});
|
|
70
|
+
if (!page.ok) return json(page.status, { ok: false, reason: page.reason });
|
|
71
|
+
// a canvas-only session that sees nothing of this library is told it is not there
|
|
72
|
+
if (candidates && !candidates.some((rel) => rel.startsWith(`${page.root}/`)))
|
|
73
|
+
return json(404, { ok: false, reason: 'not-found' });
|
|
74
|
+
return json(200, { ...page, ds: sys.name });
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
@@ -503,6 +503,7 @@ export function createEditRoutes(deps: EditRouteDeps): RouteSpec[] {
|
|
|
503
503
|
dsRev: dsRevOf(rel),
|
|
504
504
|
layout: layoutOf(rel),
|
|
505
505
|
variantsOf: variantsOf(rel),
|
|
506
|
+
designRel: deps.designRel,
|
|
506
507
|
}),
|
|
507
508
|
...(deps.references ? { references: deps.references } : {}),
|
|
508
509
|
...(deps.ops ? { ops: deps.ops } : {}),
|
|
@@ -35,6 +35,7 @@ import { type ConnectionsRouteDeps, createConnectionsRoutes } from './connection
|
|
|
35
35
|
import { createDescribeRoutes, type DescribeRouteDeps } from './describe.ts';
|
|
36
36
|
import { createDiagnosticsRoutes, type DiagnosticsRouteDeps } from './diagnostics.ts';
|
|
37
37
|
import { createDsRoutes, type DsRouteDeps } from './ds.ts';
|
|
38
|
+
import { createDsAssetsRoutes, type DsAssetsRouteDeps } from './ds-assets.ts';
|
|
38
39
|
import { createDsCheckRoutes } from './ds-check.ts';
|
|
39
40
|
import { createEditRoutes, type EditRouteDeps } from './edit.ts';
|
|
40
41
|
import { createElementLinksRoutes, type ElementLinksRouteDeps } from './element-links.ts';
|
|
@@ -150,6 +151,8 @@ export interface RouteDeps {
|
|
|
150
151
|
describe?: DescribeRouteDeps;
|
|
151
152
|
/** S8.21 — `GET /_api/asset-details` and `GET /_api/asset-generated` (main origin, reads): details per kind, the Generated runs */
|
|
152
153
|
assetDetails?: AssetDetailsRouteDeps;
|
|
154
|
+
/** 2.0.2 — `GET /_api/ds/assets`: a design system's own asset library for the Assets tab (main origin, reads) */
|
|
155
|
+
dsAssets?: DsAssetsRouteDeps;
|
|
153
156
|
/** S8.22 — `POST /_api/import-asset` v2 (main origin, Can edit on the project): PSD/HEIC converters, the dedupe answer */
|
|
154
157
|
assetImport?: AssetImportRouteDeps;
|
|
155
158
|
/**
|
|
@@ -270,6 +273,7 @@ export function allSpecs(deps: RouteDeps): RouteSpec[] {
|
|
|
270
273
|
...(deps.figma ? createFigmaRoutes(deps.figma) : []),
|
|
271
274
|
...(deps.describe ? createDescribeRoutes(deps.describe) : []),
|
|
272
275
|
...(deps.assetDetails ? createAssetDetailsRoutes(deps.assetDetails) : []),
|
|
276
|
+
...(deps.dsAssets ? createDsAssetsRoutes(deps.dsAssets) : []),
|
|
273
277
|
...(deps.assetImport ? createAssetImportRoutes(deps.assetImport) : []),
|
|
274
278
|
...importLinkSpecs(deps),
|
|
275
279
|
...(deps.generate ? createGenerateRoutes(deps.generate) : []),
|
|
@@ -459,6 +459,12 @@ export function createAcceptedLink(opts: AcceptedLinkOptions) {
|
|
|
459
459
|
let createNote: { r: Reservation; file: string } | null = null;
|
|
460
460
|
/** doc → the gate a batched create of it holds until settled or re-queued. */
|
|
461
461
|
const createsInFlight = new Map<string, Promise<void>>();
|
|
462
|
+
/**
|
|
463
|
+
* 2.0.2 — a create the transaction client WITHDREW (the project already holds that document:
|
|
464
|
+
* the same file, or a module kept under its name) was not sent: its caller hears `in-project`,
|
|
465
|
+
* and its cold start joins the project's document instead of believing it created it.
|
|
466
|
+
*/
|
|
467
|
+
const IN_PROJECT: ProposalOutcome = { status: 'rejected', code: 'in-project' };
|
|
462
468
|
const proposeCreates = (ops: Operation[], reservation?: Reservation) =>
|
|
463
469
|
client
|
|
464
470
|
.propose({
|
|
@@ -467,7 +473,14 @@ export function createAcceptedLink(opts: AcceptedLinkOptions) {
|
|
|
467
473
|
operations: ops,
|
|
468
474
|
...(reservation ? { reservation } : {}),
|
|
469
475
|
})
|
|
470
|
-
.then(
|
|
476
|
+
.then((r) => ({
|
|
477
|
+
o: outcome(r),
|
|
478
|
+
out: new Set(
|
|
479
|
+
(Array.isArray(r.withdrawn) ? r.withdrawn : [])
|
|
480
|
+
.map((w) => (w as { doc?: unknown })?.doc)
|
|
481
|
+
.filter((d): d is string => typeof d === 'string')
|
|
482
|
+
),
|
|
483
|
+
}));
|
|
471
484
|
/** Note one create on disk before it is answered (fix 5.12d). */
|
|
472
485
|
function noteCreate(op: Operation): void {
|
|
473
486
|
if (!durable) return;
|
|
@@ -518,17 +531,26 @@ export function createAcceptedLink(opts: AcceptedLinkOptions) {
|
|
|
518
531
|
note?.r
|
|
519
532
|
);
|
|
520
533
|
if (note && existsSync(client.entryFile(note.r))) rmSync(note.file, { force: true });
|
|
521
|
-
void sealed.then((o) => {
|
|
522
|
-
|
|
534
|
+
void sealed.then(({ o, out }) => {
|
|
535
|
+
const withdrawn = batch.filter((c) => out.has(c.op.doc as string));
|
|
536
|
+
for (const c of withdrawn) c.resolve(IN_PROJECT);
|
|
537
|
+
const rest = batch.filter((c) => !out.has(c.op.doc as string));
|
|
538
|
+
if (o.status === 'accepted' || rest.length <= 1) {
|
|
523
539
|
release();
|
|
524
|
-
for (const c of
|
|
540
|
+
for (const c of rest) c.resolve(o);
|
|
525
541
|
return;
|
|
526
542
|
}
|
|
527
543
|
// Each create is queued (and so ahead of anything waiting on the gate)
|
|
528
544
|
// before the gate opens.
|
|
529
|
-
const each =
|
|
545
|
+
const each = rest.map((c) => proposeCreates([c.op]));
|
|
530
546
|
release();
|
|
531
|
-
each.forEach(
|
|
547
|
+
each.forEach(
|
|
548
|
+
(answer, i) =>
|
|
549
|
+
void answer.then(
|
|
550
|
+
(a) => rest[i].resolve(a.out.has(rest[i].op.doc as string) ? IN_PROJECT : a.o),
|
|
551
|
+
() => rest[i].resolve(o)
|
|
552
|
+
)
|
|
553
|
+
);
|
|
532
554
|
}, fail);
|
|
533
555
|
}
|
|
534
556
|
function queueCreate(op: Operation): Promise<ProposalOutcome> {
|
|
@@ -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
|
|
|
@@ -160,6 +160,11 @@ export function computeAvailability(input: AvailabilityInput): Availability {
|
|
|
160
160
|
if (path === null) continue;
|
|
161
161
|
}
|
|
162
162
|
if (path !== null && localPaths.has(path)) continue;
|
|
163
|
+
// A `_`-named file or folder is never a canvas (skip-dirs.ts `isCanvasFile`; the index never
|
|
164
|
+
// lists one), but the v2 conversion keeps a document for every `.tsx` in a canvas folder, shared
|
|
165
|
+
// modules included: `_kit` / `_frames` / `_social` drew as ghost canvases that never arrived and
|
|
166
|
+
// failed when clicked (2.0.1, alligators: "94 of 103").
|
|
167
|
+
if (path !== null && path.split('/').some((s) => s.startsWith('_'))) continue;
|
|
163
168
|
pending.push({ path, name: path === null ? null : nameOf(path), state });
|
|
164
169
|
}
|
|
165
170
|
pending.sort((a, b) =>
|
|
@@ -12,7 +12,20 @@
|
|
|
12
12
|
// there and the place is free", so a replay of the same refusal finishes the same rename — the same
|
|
13
13
|
// name, once — instead of starting another. A real content conflict (the same canvas edited on two
|
|
14
14
|
// sides) is not this case: that is a `base-conflict` on a lane, and keeps its own path.
|
|
15
|
+
//
|
|
16
|
+
// 2.0.2 — A COLLISION WITH THE SAME FILE IS NOT A COLLISION (Brno Alligators, 2026-11-03: a cloud
|
|
17
|
+
// cell's 2.0 conversion made a document for every `.tsx` of its checkout, the owner's Mac replayed
|
|
18
|
+
// its queued creates for those same files, and each was renamed — ten duplicate canvases). Before
|
|
19
|
+
// renaming, the project's document for the create is compared with this Mac's canvas: when it
|
|
20
|
+
// holds this Mac's source byte for byte (what the create carries, or the file on disk now — edited
|
|
21
|
+
// after the create), it IS this canvas, and the create is WITHDRAWN: nothing moves, and what queued
|
|
22
|
+
// behind it names the same document and goes as it is. Byte-equal source only: a create carries no
|
|
23
|
+
// base, so "the project's copy is newer from the same base" is not decidable here — that renames,
|
|
24
|
+
// as before. A `_` file is a module (decision maude/v2-p8-lead-underscore-file-is-a-module),
|
|
25
|
+
// imported by its name: it is never renamed — its create is withdrawn and the file stays, and the
|
|
26
|
+
// cold start holds a differing source as any lane conflict (both kept).
|
|
15
27
|
|
|
28
|
+
import { createHash } from 'node:crypto';
|
|
16
29
|
import {
|
|
17
30
|
existsSync,
|
|
18
31
|
mkdirSync,
|
|
@@ -29,9 +42,11 @@ import { canvasArtifacts, relocatedName } from '../canvas-artifacts.ts';
|
|
|
29
42
|
import { nextFreeCanvasName } from '../canvas-create.ts';
|
|
30
43
|
import { canvasSlugFromRel } from '../canvas-slug.ts';
|
|
31
44
|
import type { Paths } from '../context.ts';
|
|
45
|
+
import { isUnderscoreModuleRel } from '../skip-dirs.ts';
|
|
32
46
|
import type {
|
|
33
47
|
CreateConflictAnswer,
|
|
34
48
|
CreateRename,
|
|
49
|
+
CreateWithdrawal,
|
|
35
50
|
Operation,
|
|
36
51
|
ProposalResult,
|
|
37
52
|
} from './transaction-client.ts';
|
|
@@ -55,9 +70,20 @@ interface Journal {
|
|
|
55
70
|
tx: string;
|
|
56
71
|
at: number;
|
|
57
72
|
renames: JournalRename[];
|
|
73
|
+
/** 2.0.2 — creates withdrawn instead of renamed (the same file; a module; a canvas gone). */
|
|
74
|
+
withdrawn?: CreateWithdrawal[];
|
|
58
75
|
told?: boolean;
|
|
59
76
|
}
|
|
60
77
|
|
|
78
|
+
/** One live document of the project, as its bootstrap lists it (`lanes` carries the lane hashes). */
|
|
79
|
+
export interface LiveDoc {
|
|
80
|
+
doc: string;
|
|
81
|
+
path: string | null;
|
|
82
|
+
lanes?: Record<string, { hash: string | null } | undefined>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const sha256 = (s: string) => createHash('sha256').update(s, 'utf8').digest('hex');
|
|
86
|
+
|
|
61
87
|
const TX_FILE = /^tx_[A-Za-z0-9]+\.json$/;
|
|
62
88
|
const nameOf = (rel: string) => path.posix.basename(rel).replace(/\.tsx$/i, '');
|
|
63
89
|
|
|
@@ -122,7 +148,7 @@ export interface CreateCollisionDeps {
|
|
|
122
148
|
paths: Paths;
|
|
123
149
|
docNameFor: (slug: string) => string;
|
|
124
150
|
/** The project's live documents now (asked again), or null when it cannot tell. */
|
|
125
|
-
liveDocs: () => Promise<
|
|
151
|
+
liveDocs: () => Promise<LiveDoc[] | null>;
|
|
126
152
|
/**
|
|
127
153
|
* The runtime's part, before any file moves: the old canvas lets go of its
|
|
128
154
|
* file (the peer's canvas arrives there), the new one will join as its create.
|
|
@@ -162,24 +188,47 @@ export function createCollisionRenamer(deps: CreateCollisionDeps) {
|
|
|
162
188
|
renameSync(tmp, fileOf(j.tx));
|
|
163
189
|
};
|
|
164
190
|
|
|
165
|
-
/**
|
|
166
|
-
|
|
167
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Which of a refused proposal's creates the project already has under its name: the one the
|
|
193
|
+
* refusal names (a scoped session may not be told which), and (2.0.2) every other one the
|
|
194
|
+
* project lists — the kernel refuses at the FIRST taken name, and answering one per round left a
|
|
195
|
+
* batch of them past the round cap.
|
|
196
|
+
*/
|
|
197
|
+
function conflicting(
|
|
198
|
+
creates: Operation[],
|
|
199
|
+
result: ProposalResult,
|
|
200
|
+
live: LiveDoc[] | null
|
|
201
|
+
): Operation[] {
|
|
202
|
+
const docs = new Set((live ?? []).map((d) => d.doc));
|
|
203
|
+
const rels = new Set((live ?? []).map((d) => d.path?.toLowerCase()).filter((p) => !!p));
|
|
204
|
+
return creates.filter(
|
|
168
205
|
(o) =>
|
|
169
206
|
(result.doc !== undefined && o.doc === result.doc) ||
|
|
170
|
-
(result.path !== undefined && o.path === result.path)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// The refusal does not say which (a scoped session may not be told): ask the project.
|
|
174
|
-
const live = await deps.liveDocs();
|
|
175
|
-
if (!live) return [];
|
|
176
|
-
const docs = new Set(live.map((d) => d.doc));
|
|
177
|
-
const rels = new Set(live.map((d) => d.path?.toLowerCase()).filter((p) => !!p));
|
|
178
|
-
return creates.filter(
|
|
179
|
-
(o) => docs.has(o.doc as string) || rels.has(String(o.path).toLowerCase())
|
|
207
|
+
(result.path !== undefined && o.path === result.path) ||
|
|
208
|
+
docs.has(o.doc as string) ||
|
|
209
|
+
rels.has(String(o.path).toLowerCase())
|
|
180
210
|
);
|
|
181
211
|
}
|
|
182
212
|
|
|
213
|
+
/**
|
|
214
|
+
* 2.0.2 — the project's document for this create holds this Mac's source byte for byte: what the
|
|
215
|
+
* create carries, or the file as it is now. Only the same document name counts (the kernel ties a
|
|
216
|
+
* name to its path, so another name at this path is not this canvas).
|
|
217
|
+
*/
|
|
218
|
+
function sameFile(o: Operation, live: LiveDoc[]): boolean {
|
|
219
|
+
const d = live.find((x) => x.doc === o.doc);
|
|
220
|
+
const hash = d?.lanes?.html?.hash;
|
|
221
|
+
if (!d || !hash || String(d.path).toLowerCase() !== String(o.path).toLowerCase()) return false;
|
|
222
|
+
const carried = (o.lanes as Record<string, unknown> | undefined)?.html;
|
|
223
|
+
if (typeof carried === 'string' && carried !== '' && sha256(carried) === hash) return true;
|
|
224
|
+
try {
|
|
225
|
+
const disk = readFileSync(path.join(deps.paths.designRoot, o.path as string), 'utf8');
|
|
226
|
+
return disk !== '' && sha256(disk) === hash;
|
|
227
|
+
} catch {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
183
232
|
async function choose(
|
|
184
233
|
tx: string,
|
|
185
234
|
ops: Operation[],
|
|
@@ -188,18 +237,34 @@ export function createCollisionRenamer(deps: CreateCollisionDeps) {
|
|
|
188
237
|
const creates = ops.filter(
|
|
189
238
|
(o) => o.op === 'doc.create' && typeof o.doc === 'string' && typeof o.path === 'string'
|
|
190
239
|
);
|
|
191
|
-
const
|
|
240
|
+
const listed = await deps.liveDocs();
|
|
241
|
+
const hit = conflicting(creates, result, listed);
|
|
192
242
|
if (!hit.length) return null;
|
|
193
|
-
const live =
|
|
243
|
+
const live = listed ?? [];
|
|
194
244
|
const liveDocs = new Set(live.map((d) => d.doc));
|
|
195
245
|
const liveRels = new Set(live.map((d) => d.path?.toLowerCase()).filter((p) => !!p));
|
|
196
246
|
const chosen = new Set<string>();
|
|
197
247
|
const proposed = new Set(creates.map((o) => String(o.path).toLowerCase()));
|
|
198
248
|
const renames: JournalRename[] = [];
|
|
249
|
+
const withdrawn: CreateWithdrawal[] = [];
|
|
199
250
|
for (const o of hit) {
|
|
200
251
|
const fromRel = o.path as string;
|
|
252
|
+
const doc = o.doc as string;
|
|
253
|
+
// The project already holds this very file: this Mac's canvas IS that document.
|
|
254
|
+
if (sameFile(o, live)) {
|
|
255
|
+
withdrawn.push({ doc, why: 'same' });
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
201
258
|
// A canvas no longer on this Mac has nothing to keep: the refusal stands for it.
|
|
202
|
-
if (!existsSync(path.join(deps.paths.designRoot, fromRel)))
|
|
259
|
+
if (!existsSync(path.join(deps.paths.designRoot, fromRel))) {
|
|
260
|
+
withdrawn.push({ doc, why: 'gone' });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
// A module is imported by its name: a rename would break every canvas that imports it.
|
|
264
|
+
if (isUnderscoreModuleRel(fromRel)) {
|
|
265
|
+
withdrawn.push({ doc, why: 'module' });
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
203
268
|
const toRel = freeCreateRel(fromRel, (candidate) => {
|
|
204
269
|
const lower = candidate.toLowerCase();
|
|
205
270
|
const abs = path.join(deps.paths.designRoot, candidate);
|
|
@@ -220,8 +285,8 @@ export function createCollisionRenamer(deps: CreateCollisionDeps) {
|
|
|
220
285
|
toRel,
|
|
221
286
|
});
|
|
222
287
|
}
|
|
223
|
-
if (!renames.length) return null;
|
|
224
|
-
const j: Journal = { v: 1, tx, at: now(), renames };
|
|
288
|
+
if (!renames.length && !withdrawn.length) return null;
|
|
289
|
+
const j: Journal = { v: 1, tx, at: now(), renames, ...(withdrawn.length ? { withdrawn } : {}) };
|
|
225
290
|
write(j);
|
|
226
291
|
return j;
|
|
227
292
|
}
|
|
@@ -245,6 +310,17 @@ export function createCollisionRenamer(deps: CreateCollisionDeps) {
|
|
|
245
310
|
html: htmlOf(r.fromDoc),
|
|
246
311
|
}));
|
|
247
312
|
const settles = canvases.map((c) => deps.onRenaming(c));
|
|
313
|
+
for (const w of j.withdrawn ?? []) {
|
|
314
|
+
const rel = String(ops.find((x) => x.op === 'doc.create' && x.doc === w.doc)?.path);
|
|
315
|
+
const slug = slugOf(rel);
|
|
316
|
+
log.log(
|
|
317
|
+
w.why === 'same'
|
|
318
|
+
? `[sync/${slug}] the project already has ${rel} as it is on this Mac — joined, not renamed.`
|
|
319
|
+
: w.why === 'module'
|
|
320
|
+
? `[sync/${slug}] the project already has the module ${rel} — it keeps its name.`
|
|
321
|
+
: `[sync/${slug}] the project already has ${rel}, and this Mac no longer does.`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
248
324
|
for (const c of canvases) {
|
|
249
325
|
moveCanvasArtifacts(deps.paths, c.fromRel, c.toRel, deps.fault);
|
|
250
326
|
log.log(
|
|
@@ -260,6 +336,7 @@ export function createCollisionRenamer(deps: CreateCollisionDeps) {
|
|
|
260
336
|
}));
|
|
261
337
|
return {
|
|
262
338
|
renames,
|
|
339
|
+
...(j.withdrawn?.length ? { withdrawn: j.withdrawn } : {}),
|
|
263
340
|
settled: (r) => {
|
|
264
341
|
for (const s of settles) s(r);
|
|
265
342
|
rmSync(fileOf(tx), { force: true });
|
|
@@ -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);
|
|
@@ -3582,6 +3582,9 @@ export function createSyncRuntime(
|
|
|
3582
3582
|
renewalsSinceProgress++;
|
|
3583
3583
|
console.log(`[sync] hub credential renewed for ${linkedHub.url}`);
|
|
3584
3584
|
scheduleRenewal();
|
|
3585
|
+
// The owner's config push that ran on the stale credential (401) goes again on this one —
|
|
3586
|
+
// without it a cell stayed without its config.json until it next restarted (2.0.1 field).
|
|
3587
|
+
if (!outboundPaused()) void projectConfigPusher?.push();
|
|
3585
3588
|
return true;
|
|
3586
3589
|
} catch (err) {
|
|
3587
3590
|
console.warn(`[sync] hub credential renewal failed: ${(err as Error).message}`);
|
|
@@ -3930,9 +3933,14 @@ export function createSyncRuntime(
|
|
|
3930
3933
|
acceptedLink.createDoc(canvas.slug, rel, lanes).then(notOursIfRenamed(docName)),
|
|
3931
3934
|
};
|
|
3932
3935
|
let joined = await acceptedColdStart(coldStart);
|
|
3933
|
-
if (
|
|
3936
|
+
if (
|
|
3937
|
+
joined.kind === 'create-refused' &&
|
|
3938
|
+
(joined.code === 'renamed' || joined.code === 'in-project')
|
|
3939
|
+
) {
|
|
3934
3940
|
// S6.13b — this Mac's canvas moved to a free name while its create
|
|
3935
|
-
// waited; what stays at this path is the peer's canvas.
|
|
3941
|
+
// waited; what stays at this path is the peer's canvas. 2.0.2 — or
|
|
3942
|
+
// its create was withdrawn: the project already holds this document
|
|
3943
|
+
// (the same file, or a module that keeps its name), so it joins it.
|
|
3936
3944
|
joined = await acceptedColdStart({ ...coldStart, inProject: true });
|
|
3937
3945
|
}
|
|
3938
3946
|
renamedAway.delete(docName);
|