@1agh/maude 2.0.6 → 2.0.8
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/closure.ts +156 -16
- package/apps/studio/access/filters.ts +27 -0
- package/apps/studio/actions/agents.ts +54 -0
- package/apps/studio/actions/ctx.ts +3 -0
- package/apps/studio/actions/defs/sync.ts +13 -0
- package/apps/studio/actions/defs/view.ts +59 -3
- package/apps/studio/actions/keymap.gen.ts +35 -0
- package/apps/studio/actions/menu.ts +2 -0
- package/apps/studio/actions/types.ts +3 -1
- package/apps/studio/actions.manifest.json +136 -1
- package/apps/studio/actions.parity.json +25 -1
- package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
- package/apps/studio/annotations/ui/ride.ts +2 -1
- package/apps/studio/annotations-context-toolbar.tsx +5 -4
- package/apps/studio/annotations-layer.tsx +4 -3
- package/apps/studio/api.ts +383 -128
- package/apps/studio/artboard-activity-overlay.tsx +4 -4
- package/apps/studio/artboard-ai-copies.tsx +4 -4
- package/apps/studio/artboard-freeze.ts +108 -0
- package/apps/studio/artboard-live-gate.tsx +414 -45
- package/apps/studio/artboard-live.ts +526 -31
- package/apps/studio/artboard-placeholder.ts +197 -0
- package/apps/studio/artboard-still-raster.ts +485 -0
- package/apps/studio/artboard-still-warmup.ts +221 -0
- package/apps/studio/artboard-still.ts +1188 -0
- package/apps/studio/artboard-webgl.ts +2 -1
- package/apps/studio/asset-placeholder.tsx +237 -132
- package/apps/studio/asset-upload-bars.tsx +4 -4
- package/apps/studio/bin/_perf-probe-open.mjs +364 -0
- package/apps/studio/bin/_perf-shared.mjs +12 -7
- package/apps/studio/bin/_pw-launch.mjs +26 -1
- package/apps/studio/bin/perf.sh +19 -0
- package/apps/studio/bridge/dgn-protocol.ts +35 -0
- package/apps/studio/canvas-build-sandbox.ts +69 -13
- package/apps/studio/canvas-camera.ts +90 -0
- package/apps/studio/canvas-comment-mount.tsx +9 -9
- package/apps/studio/canvas-lib.tsx +160 -34
- package/apps/studio/canvas-pages-view.tsx +465 -0
- package/apps/studio/canvas-pages.ts +305 -0
- package/apps/studio/canvas-rows.ts +62 -0
- package/apps/studio/canvas-shell.tsx +62 -16
- package/apps/studio/canvas-theme-icons.tsx +41 -0
- package/apps/studio/canvas-theme-pill.tsx +15 -6
- package/apps/studio/canvas-theme.ts +12 -11
- package/apps/studio/client/app.jsx +7 -0
- package/apps/studio/client/canvas-url.js +23 -1
- package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
- package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
- package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
- package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
- package/apps/studio/client/hooks/use-project-data.jsx +11 -2
- package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
- package/apps/studio/client/index-loader.ts +41 -21
- package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
- package/apps/studio/client/shell/viewport.jsx +32 -16
- package/apps/studio/client/tree/tree.jsx +17 -0
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +7 -3
- package/apps/studio/client/v2/code/canvas-imports-words.js +16 -0
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
- package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
- package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
- package/apps/studio/client/v2/code/code-consent.js +67 -0
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
- package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
- package/apps/studio/client/v2/layers/layers-request.js +49 -0
- package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
- package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
- package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
- package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +40 -5
- package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
- package/apps/studio/client/v2/shell/floating-panels.css +37 -1
- package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
- package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
- package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
- package/apps/studio/client/v2/shell/pages-pick.js +49 -0
- package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +3 -1
- package/apps/studio/client/v2/shell/shell-parity.json +8 -0
- package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
- package/apps/studio/comments-overlay.tsx +12 -11
- package/apps/studio/config-reload-wire.ts +4 -1
- package/apps/studio/config.schema.json +6 -0
- package/apps/studio/context.ts +37 -1
- package/apps/studio/dist/client.bundle.js +720 -720
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/board.css +6 -0
- package/apps/studio/ds/board/ds-bar.tsx +21 -3
- package/apps/studio/ds/board/specimen.tsx +6 -3
- package/apps/studio/ds/board/template.ts +39 -19
- package/apps/studio/ds/cli.ts +7 -1
- package/apps/studio/ds/component-list.ts +2 -1
- package/apps/studio/ds/default.ts +6 -1
- package/apps/studio/ds/ds-resolver.ts +58 -8
- package/apps/studio/ds/engine.ts +3 -1
- package/apps/studio/ds/folder-systems.ts +199 -0
- package/apps/studio/ds/pairing-css.ts +2 -1
- package/apps/studio/ds/rename.ts +10 -3
- package/apps/studio/ds/shell-fallbacks.ts +2 -1
- package/apps/studio/ds/upgrade-stage.ts +6 -2
- package/apps/studio/editing/ai-point-ring.tsx +4 -4
- package/apps/studio/editing/ai-scope-outline.tsx +4 -4
- package/apps/studio/editing/align-bar.tsx +4 -4
- package/apps/studio/editing/anchor-report.ts +3 -2
- package/apps/studio/editing/artboard-handles.tsx +4 -4
- package/apps/studio/editing/corner-dots.tsx +4 -4
- package/apps/studio/editing/crop-mode.tsx +4 -4
- package/apps/studio/editing/drop-chip.tsx +4 -4
- package/apps/studio/editing/empty-report.ts +3 -2
- package/apps/studio/editing/focus-model.tsx +4 -4
- package/apps/studio/editing/gap-bands.tsx +3 -3
- package/apps/studio/editing/hold-rings.tsx +4 -4
- package/apps/studio/editing/lock-badge.tsx +3 -3
- package/apps/studio/editing/long-page.ts +23 -1
- package/apps/studio/editing/nudge.tsx +2 -2
- package/apps/studio/editing/page-activity.ts +4 -3
- package/apps/studio/editing/paste-bar.tsx +4 -4
- package/apps/studio/editing/pen/overlay.tsx +4 -3
- package/apps/studio/editing/place-freely.tsx +3 -3
- package/apps/studio/editing/reorder-slot.tsx +3 -3
- package/apps/studio/editing/selection.tsx +4 -4
- package/apps/studio/editing/size-ghost.tsx +4 -4
- package/apps/studio/editing/tab-order.tsx +4 -4
- package/apps/studio/editing/text-in-place.tsx +4 -4
- package/apps/studio/editing/undo-preview.tsx +3 -3
- package/apps/studio/equal-spacing-handles.tsx +3 -3
- package/apps/studio/frame-clock.ts +89 -0
- package/apps/studio/http.ts +66 -32
- package/apps/studio/index/ds-usage.ts +4 -1
- package/apps/studio/index-cache.ts +272 -0
- package/apps/studio/inspect-overlay.tsx +4 -3
- package/apps/studio/inspect.ts +7 -2
- package/apps/studio/link-chip-overlay.tsx +4 -3
- package/apps/studio/measure-overlay.tsx +4 -3
- package/apps/studio/present/pointer-dot.tsx +3 -2
- package/apps/studio/present/present-media.ts +6 -2
- package/apps/studio/present/present-stage.tsx +3 -2
- package/apps/studio/preview/preview-camera.tsx +3 -2
- package/apps/studio/routes/sync.ts +176 -0
- package/apps/studio/safe-zones-overlay.tsx +3 -2
- package/apps/studio/skip-dirs.ts +103 -47
- package/apps/studio/studio-page-host.ts +70 -0
- package/apps/studio/sync/code-module-consent.ts +86 -0
- package/apps/studio/sync/file-ledger.ts +24 -0
- package/apps/studio/sync/file-plane.ts +458 -53
- package/apps/studio/sync/held-deletes.ts +230 -0
- package/apps/studio/sync/hubs-config.ts +59 -2
- package/apps/studio/sync/index.ts +99 -15
- package/apps/studio/sync/seed-progress.ts +92 -2
- package/apps/studio/sync/settings.ts +36 -1
- package/apps/studio/sync/status.ts +15 -1
- package/apps/studio/sync/writer-registry.ts +5 -0
- package/apps/studio/text-caret.ts +5 -3
- package/apps/studio/toolbars/toolbar-rect.ts +3 -2
- package/apps/studio/use-annotation-resize.tsx +4 -3
- package/apps/studio/use-artboard-drag.tsx +3 -2
- package/apps/studio/use-element-resize.tsx +7 -6
- package/apps/studio/use-grid-track-handles.tsx +5 -4
- package/apps/studio/use-selection-set.tsx +64 -4
- package/apps/studio/use-spacing-handles.tsx +7 -6
- package/apps/studio/video-comp.tsx +55 -42
- package/apps/studio/video-play-overlay.tsx +4 -3
- package/apps/studio/whats-new.json +27 -0
- package/cli/commands/design.mjs +5 -2
- package/cli/commands/hub.mjs +10 -1
- package/cli/lib/bash-guard.mjs +14 -0
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-link.mjs +42 -17
- package/cli/lib/hub-purge.mjs +183 -0
- package/package.json +8 -8
- package/plugins/design/templates/_shell.html +164 -1
|
@@ -65,7 +65,7 @@ import { open as openAsync } from 'node:fs/promises';
|
|
|
65
65
|
import path from 'node:path';
|
|
66
66
|
|
|
67
67
|
import { conflictCopyName, decideFile, type FileState } from './decide-file.ts';
|
|
68
|
-
import type { DeliveryState, FileLedger } from './file-ledger.ts';
|
|
68
|
+
import type { DeliveryState, FileLedger, LedgerRow } from './file-ledger.ts';
|
|
69
69
|
import {
|
|
70
70
|
type CanvasGroupLike,
|
|
71
71
|
classifyProjectFile,
|
|
@@ -112,6 +112,9 @@ export const MAX_FILE_BYTES = (() => {
|
|
|
112
112
|
* happens, so it is kept at a size where twice the file does not matter. */
|
|
113
113
|
export const STREAM_DOWNLOAD_ABOVE_BYTES = 1024 * 1024;
|
|
114
114
|
|
|
115
|
+
/** Issue #207 — above this an upload body streams from disk instead of being read into memory. */
|
|
116
|
+
export const STREAM_UPLOAD_ABOVE_BYTES = 1024 * 1024;
|
|
117
|
+
|
|
115
118
|
/** sha256 of a file, read in 1 MiB chunks (T18 — a video is never held whole). */
|
|
116
119
|
export function sha256File(abs: string): string {
|
|
117
120
|
const hash = createHash('sha256');
|
|
@@ -367,6 +370,7 @@ function deliveryRank(state: DeliveryState): number {
|
|
|
367
370
|
case 'refused':
|
|
368
371
|
return 1;
|
|
369
372
|
case 'stuck':
|
|
373
|
+
case 'delete-held':
|
|
370
374
|
return 2;
|
|
371
375
|
case 'referenced-but-unoffered':
|
|
372
376
|
return 3;
|
|
@@ -427,6 +431,12 @@ export interface FilePlaneResult {
|
|
|
427
431
|
requestsExhausted?: true;
|
|
428
432
|
/** The pass stopped because it had moved `MAX_FILES_PER_PASS` files (issue #204). */
|
|
429
433
|
filesCapped?: true;
|
|
434
|
+
/** Issue #207 — uploads cancelled because the file left this Mac after the scan (not failures). */
|
|
435
|
+
gone?: number;
|
|
436
|
+
/** Issue #207 — files on this disk inside a folder the project does not sync (`linkedHub.ignoreFolders`). */
|
|
437
|
+
ignored?: number;
|
|
438
|
+
/** Issue #207 — folders with a long run of pictures still going up (see `largeSequences`). */
|
|
439
|
+
largeSequences?: LargeSequence[];
|
|
430
440
|
/**
|
|
431
441
|
* Issue #204 — files whose bytes the hub is still FETCHING FROM ITS BUCKET (a cold cell's
|
|
432
442
|
* `503 fetching from storage`). Not delivered, not failed, not stuck: each is backed off for the
|
|
@@ -456,8 +466,16 @@ export interface FilePlaneResult {
|
|
|
456
466
|
backedOff?: number;
|
|
457
467
|
/** Files removed this pass — `parked` names the `_trash/` copy when there is one. */
|
|
458
468
|
deleted: { rel: string; parked: string | null }[];
|
|
459
|
-
/**
|
|
460
|
-
|
|
469
|
+
/**
|
|
470
|
+
* A delete burst tripped a breaker; nothing was removed. Outbound, it is every row still waiting
|
|
471
|
+
* for the person's answer (`delete-held`), with the folders they sit in (issue #207, 7b).
|
|
472
|
+
*/
|
|
473
|
+
deleteHeld?: {
|
|
474
|
+
direction: 'out' | 'in';
|
|
475
|
+
count: number;
|
|
476
|
+
paths: string[];
|
|
477
|
+
folders?: HeldDeleteFolder[];
|
|
478
|
+
};
|
|
461
479
|
/** Consecutive `reanchor` answers tripped the storm limit; the pass held. */
|
|
462
480
|
reanchorHeld?: true;
|
|
463
481
|
/**
|
|
@@ -502,8 +520,12 @@ export interface FilePlaneOptions {
|
|
|
502
520
|
* LOCAL state (hubs.json role / loopback pairing) — never from anything the
|
|
503
521
|
* hub said. The hub gates the write side too now, but a gate on one side is
|
|
504
522
|
* half a gate, so both ask.
|
|
523
|
+
*
|
|
524
|
+
* fix/207 — may be a function, read at every gate: the person can say yes (or no) in the app
|
|
525
|
+
* while sync runs (`POST /_api/sync/code-consent/set`), and the very next pass must admit the
|
|
526
|
+
* rows it held — no restart. A boolean keeps the old fixed reading.
|
|
505
527
|
*/
|
|
506
|
-
allowCodeModules: boolean;
|
|
528
|
+
allowCodeModules: boolean | (() => boolean);
|
|
507
529
|
/**
|
|
508
530
|
* Whether this peer may SEND a `code-module` the hub does not hold yet. The
|
|
509
531
|
* hub's file door takes one only from an owner-role token (403 otherwise);
|
|
@@ -515,8 +537,19 @@ export interface FilePlaneOptions {
|
|
|
515
537
|
canUploadCodeModules?: boolean;
|
|
516
538
|
/** Names conflict copies. Same exposure class as `syncMeta.by` (hostname). */
|
|
517
539
|
label: string;
|
|
518
|
-
/**
|
|
519
|
-
|
|
540
|
+
/**
|
|
541
|
+
* Increment 6. Off means a local absence is HELD, never propagated. A getter is read at the
|
|
542
|
+
* start of every pass (issue #207), so turning it off or on in the project config applies at the
|
|
543
|
+
* next pass — Resync — instead of at the next restart.
|
|
544
|
+
*/
|
|
545
|
+
propagateDeletes?: boolean | (() => boolean);
|
|
546
|
+
/**
|
|
547
|
+
* Issue #207 — design-root-relative folders this project does not sync
|
|
548
|
+
* (`linkedHub.ignoreFolders` in the project config). Nothing under them moves either way.
|
|
549
|
+
* A getter is read at the start of every pass, so a folder left out mid-upload stops at the
|
|
550
|
+
* next pass instead of at the next restart.
|
|
551
|
+
*/
|
|
552
|
+
ignoreFolders?: readonly string[] | (() => readonly string[]);
|
|
520
553
|
/**
|
|
521
554
|
* The outbound delete breaker is OFF: a deliberate bulk delete on this
|
|
522
555
|
* machine propagates in one pass. Computed by the caller from LOCAL consent
|
|
@@ -635,18 +668,238 @@ type LocalFile = SyncableLocalFile | OversizedLocalFile;
|
|
|
635
668
|
const sha256 = (bytes: Uint8Array | string): string =>
|
|
636
669
|
createHash('sha256').update(bytes).digest('hex');
|
|
637
670
|
|
|
671
|
+
interface WalkedFile {
|
|
672
|
+
rel: string;
|
|
673
|
+
abs: string;
|
|
674
|
+
size: number;
|
|
675
|
+
mtimeMs: number;
|
|
676
|
+
}
|
|
677
|
+
|
|
638
678
|
/**
|
|
639
|
-
* Walk the design root and hash what the classifier admits.
|
|
679
|
+
* Walk the design root and hash what the classifier admits — synchronously.
|
|
640
680
|
*
|
|
641
681
|
* The stat cache is what makes this cheap: a converged project re-reads
|
|
642
682
|
* nothing, because every file's `(size, mtimeMs)` still matches the ledger.
|
|
683
|
+
* The plane itself scans with `scanLocalFilesAsync` (issue #207); this stays
|
|
684
|
+
* for callers with no event loop to protect.
|
|
643
685
|
*/
|
|
644
686
|
export function scanLocalFiles(
|
|
645
687
|
designRoot: string,
|
|
646
688
|
ledger: FileLedger,
|
|
647
689
|
canvasGroups?: readonly CanvasGroupLike[]
|
|
648
690
|
): Map<string, LocalFile> {
|
|
649
|
-
const
|
|
691
|
+
const out = new Map<string, LocalFile>();
|
|
692
|
+
for (const { f, cls } of walkAndClassify(designRoot, canvasGroups)) {
|
|
693
|
+
if (f.size > MAX_FILE_BYTES) {
|
|
694
|
+
out.set(f.rel, { ...f, cls, hash: null, oversized: true });
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
let hash = ledger.cachedHash(f.rel, f.size, f.mtimeMs);
|
|
698
|
+
if (hash === null) {
|
|
699
|
+
try {
|
|
700
|
+
hash = sha256File(f.abs);
|
|
701
|
+
} catch {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
ledger.noteLocal(f.rel, hash, f.size, f.mtimeMs);
|
|
705
|
+
}
|
|
706
|
+
out.set(f.rel, { rel: f.rel, abs: f.abs, hash, size: f.size, mtimeMs: f.mtimeMs, cls });
|
|
707
|
+
}
|
|
708
|
+
return out;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* The longest stretch of scan work before it yields to the event loop.
|
|
713
|
+
* Issue #207: the scan hashed every uncached file in ONE synchronous run
|
|
714
|
+
* (2 000 new 0.5–3 MB renders held the loop for 7.7 s) and the studio's
|
|
715
|
+
* `/_health` waited for all of it. Hashing now reads through a stream and
|
|
716
|
+
* yields every slice — inside a file as well as between files, because a
|
|
717
|
+
* stream whose chunks are already read ahead resolves on MICROTASKS, which
|
|
718
|
+
* never let a request in — so a request waits one slice at most.
|
|
719
|
+
*/
|
|
720
|
+
export const SCAN_SLICE_MS = 8;
|
|
721
|
+
|
|
722
|
+
/** What the panel says about a file in a folder the project does not sync. */
|
|
723
|
+
export const IGNORED_REASON = 'In a folder this project does not sync';
|
|
724
|
+
|
|
725
|
+
/** Issue #207 (7b) — the ledger reason for a `delete-held` row. */
|
|
726
|
+
export const DELETE_HELD_REASON =
|
|
727
|
+
'deleted on this Mac, as part of a batch too large to delete on the hub without asking';
|
|
728
|
+
/** Issue #207 (7b) — the ledger reason for a `hub-only` row. */
|
|
729
|
+
export const HUB_ONLY_REASON =
|
|
730
|
+
'deleted on this Mac and kept on the hub — it is not downloaded again';
|
|
731
|
+
|
|
732
|
+
/** One folder of held deletes, for the Sync details row. */
|
|
733
|
+
export interface HeldDeleteFolder {
|
|
734
|
+
/** Design-root-relative folder (`''` = the design root itself). */
|
|
735
|
+
folder: string;
|
|
736
|
+
count: number;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** The folder a held row sits in. */
|
|
740
|
+
export function heldDeleteFolderOf(rel: string): string {
|
|
741
|
+
const i = rel.lastIndexOf('/');
|
|
742
|
+
return i < 0 ? '' : rel.slice(0, i);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/** Every `delete-held` row, grouped by folder (largest first) — pure over the ledger's rows. */
|
|
746
|
+
export function summarizeHeldDeletes(rows: Readonly<Record<string, LedgerRow>>): {
|
|
747
|
+
count: number;
|
|
748
|
+
paths: string[];
|
|
749
|
+
folders: HeldDeleteFolder[];
|
|
750
|
+
} {
|
|
751
|
+
const paths: string[] = [];
|
|
752
|
+
const byFolder = new Map<string, number>();
|
|
753
|
+
for (const [rel, row] of Object.entries(rows)) {
|
|
754
|
+
if (row.state !== 'delete-held') continue;
|
|
755
|
+
paths.push(rel);
|
|
756
|
+
const f = heldDeleteFolderOf(rel);
|
|
757
|
+
byFolder.set(f, (byFolder.get(f) ?? 0) + 1);
|
|
758
|
+
}
|
|
759
|
+
paths.sort();
|
|
760
|
+
const folders = [...byFolder.entries()]
|
|
761
|
+
.map(([folder, count]) => ({ folder, count }))
|
|
762
|
+
.sort((a, b) => b.count - a.count || (a.folder < b.folder ? -1 : 1));
|
|
763
|
+
return { count: paths.length, paths, folders };
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/** Does `rel` sit in `folder` (or below it)? `null` folder = every held row. */
|
|
767
|
+
export function inHeldFolder(rel: string, folder: string | null): boolean {
|
|
768
|
+
if (folder === null) return true;
|
|
769
|
+
if (folder === '') return !rel.includes('/');
|
|
770
|
+
return rel.startsWith(`${folder}/`);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* The folders a project does not sync, cleaned: design-root-relative, no
|
|
775
|
+
* leading/trailing slash, contained (a `..` or absolute entry is dropped — the
|
|
776
|
+
* list comes from a committed file a teammate may have written), and never a
|
|
777
|
+
* runtime-state (`_`) top folder, which the plane never walks anyway.
|
|
778
|
+
*/
|
|
779
|
+
export function normalizeIgnoreFolders(raw: unknown): string[] {
|
|
780
|
+
if (!Array.isArray(raw)) return [];
|
|
781
|
+
const out = new Set<string>();
|
|
782
|
+
for (const v of raw) {
|
|
783
|
+
if (typeof v !== 'string') continue;
|
|
784
|
+
const p = path.posix.normalize(v.replace(/\\/g, '/').trim()).replace(/^\/+|\/+$/g, '');
|
|
785
|
+
if (!p || p === '.' || p === '..' || p.startsWith('../') || /^[A-Za-z]:/.test(v)) continue;
|
|
786
|
+
if (v.trim().startsWith('/')) continue;
|
|
787
|
+
out.add(p);
|
|
788
|
+
}
|
|
789
|
+
return [...out];
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/** True when `rel` is one of the folders, or inside one. */
|
|
793
|
+
export function isIgnoredRel(rel: string, folders: readonly string[]): boolean {
|
|
794
|
+
for (const f of folders) if (rel === f || rel.startsWith(`${f}/`)) return true;
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** Issue #207 — a folder whose pictures still going up pass either of these is named in the panel. */
|
|
799
|
+
export const LARGE_SEQUENCE_FILES = 200;
|
|
800
|
+
export const LARGE_SEQUENCE_BYTES = 200 * 1024 * 1024;
|
|
801
|
+
const PICTURE_EXT_RE = /\.(png|jpe?g|webp|avif|gif|tiff?|exr|bmp|heic|tga|dpx|psd)$/i;
|
|
802
|
+
|
|
803
|
+
export interface LargeSequence {
|
|
804
|
+
/** Design-root-relative folder. */
|
|
805
|
+
folder: string;
|
|
806
|
+
files: number;
|
|
807
|
+
bytes: number;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Folders holding a long run of pictures that this pass still has to send up —
|
|
812
|
+
* a render sequence, a frame dump. Only uploads count (what is already on the
|
|
813
|
+
* workspace is not news); at most five folders, largest first.
|
|
814
|
+
*/
|
|
815
|
+
export function largeSequences(
|
|
816
|
+
work: readonly { rel: string; decision: { action: string }; local?: { size: number } }[]
|
|
817
|
+
): LargeSequence[] {
|
|
818
|
+
const byFolder = new Map<string, { files: number; bytes: number }>();
|
|
819
|
+
for (const w of work) {
|
|
820
|
+
if (w.decision.action !== 'push' && w.decision.action !== 'revive') continue;
|
|
821
|
+
if (!PICTURE_EXT_RE.test(w.rel)) continue;
|
|
822
|
+
const folder = path.posix.dirname(w.rel);
|
|
823
|
+
if (folder === '.') continue;
|
|
824
|
+
const s = byFolder.get(folder) ?? { files: 0, bytes: 0 };
|
|
825
|
+
s.files += 1;
|
|
826
|
+
s.bytes += w.local?.size ?? 0;
|
|
827
|
+
byFolder.set(folder, s);
|
|
828
|
+
}
|
|
829
|
+
return [...byFolder]
|
|
830
|
+
.filter(([, s]) => s.files > LARGE_SEQUENCE_FILES || s.bytes > LARGE_SEQUENCE_BYTES)
|
|
831
|
+
.map(([folder, s]) => ({ folder, ...s }))
|
|
832
|
+
.sort((a, b) => b.bytes - a.bytes)
|
|
833
|
+
.slice(0, 5);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/** Hand the event loop a turn (a macrotask: pending I/O and timers run first). */
|
|
837
|
+
export const yieldToLoop = (): Promise<void> => new Promise((r) => setImmediate(r));
|
|
838
|
+
|
|
839
|
+
/** A time-sliced yield: `await slice()` yields once `ms` of work has run since the last turn. */
|
|
840
|
+
export function createSlicer(ms = SCAN_SLICE_MS): () => Promise<void> {
|
|
841
|
+
let start = performance.now();
|
|
842
|
+
return async () => {
|
|
843
|
+
if (performance.now() - start < ms) return;
|
|
844
|
+
await yieldToLoop();
|
|
845
|
+
start = performance.now();
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* sha256 of a file through `Bun.file().stream()` — issue #207. Memory is the
|
|
851
|
+
* stream's read-ahead (~30 MB measured on a 256 MB file, never the file), and
|
|
852
|
+
* it yields to the event loop every slice, so a large file never blocks it.
|
|
853
|
+
*/
|
|
854
|
+
export async function hashFileStreamed(
|
|
855
|
+
abs: string,
|
|
856
|
+
slice: () => Promise<void> = createSlicer()
|
|
857
|
+
): Promise<string> {
|
|
858
|
+
const hasher = new Bun.CryptoHasher('sha256');
|
|
859
|
+
for await (const chunk of Bun.file(abs).stream()) {
|
|
860
|
+
hasher.update(chunk);
|
|
861
|
+
await slice();
|
|
862
|
+
}
|
|
863
|
+
return hasher.digest('hex');
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* The plane's scan: the same answer as `scanLocalFiles`, but hashed through a
|
|
868
|
+
* stream and yielding to the event loop every `SCAN_SLICE_MS` (issue #207).
|
|
869
|
+
*/
|
|
870
|
+
export async function scanLocalFilesAsync(
|
|
871
|
+
designRoot: string,
|
|
872
|
+
ledger: FileLedger,
|
|
873
|
+
canvasGroups?: readonly CanvasGroupLike[]
|
|
874
|
+
): Promise<Map<string, LocalFile>> {
|
|
875
|
+
const slice = createSlicer();
|
|
876
|
+
const out = new Map<string, LocalFile>();
|
|
877
|
+
for (const { f, cls } of walkAndClassify(designRoot, canvasGroups)) {
|
|
878
|
+
await slice();
|
|
879
|
+
if (f.size > MAX_FILE_BYTES) {
|
|
880
|
+
out.set(f.rel, { ...f, cls, hash: null, oversized: true });
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
let hash = ledger.cachedHash(f.rel, f.size, f.mtimeMs);
|
|
884
|
+
if (hash === null) {
|
|
885
|
+
try {
|
|
886
|
+
hash = await hashFileStreamed(f.abs, slice);
|
|
887
|
+
} catch {
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
ledger.noteLocal(f.rel, hash, f.size, f.mtimeMs);
|
|
891
|
+
}
|
|
892
|
+
out.set(f.rel, { rel: f.rel, abs: f.abs, hash, size: f.size, mtimeMs: f.mtimeMs, cls });
|
|
893
|
+
}
|
|
894
|
+
return out;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/** Walk the design root (stat only, no reads) and keep what the classifier admits. */
|
|
898
|
+
function walkAndClassify(
|
|
899
|
+
designRoot: string,
|
|
900
|
+
canvasGroups?: readonly CanvasGroupLike[]
|
|
901
|
+
): { f: WalkedFile; cls: FileClass }[] {
|
|
902
|
+
const found: WalkedFile[] = [];
|
|
650
903
|
|
|
651
904
|
const walk = (dir: string, rel: string, depth: number): void => {
|
|
652
905
|
if (depth > MAX_WALK_DEPTH) return;
|
|
@@ -684,24 +937,10 @@ export function scanLocalFiles(
|
|
|
684
937
|
const names = new Set(found.map((f) => f.rel));
|
|
685
938
|
const opts = { canvasGroups, hasFile: (r: string) => names.has(r) };
|
|
686
939
|
|
|
687
|
-
const out
|
|
940
|
+
const out: { f: WalkedFile; cls: FileClass }[] = [];
|
|
688
941
|
for (const f of found) {
|
|
689
942
|
const cls = classifyProjectFile(f.rel, opts);
|
|
690
|
-
if (
|
|
691
|
-
if (f.size > MAX_FILE_BYTES) {
|
|
692
|
-
out.set(f.rel, { ...f, cls, hash: null, oversized: true });
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
let hash = ledger.cachedHash(f.rel, f.size, f.mtimeMs);
|
|
696
|
-
if (hash === null) {
|
|
697
|
-
try {
|
|
698
|
-
hash = sha256File(f.abs);
|
|
699
|
-
} catch {
|
|
700
|
-
continue;
|
|
701
|
-
}
|
|
702
|
-
ledger.noteLocal(f.rel, hash, f.size, f.mtimeMs);
|
|
703
|
-
}
|
|
704
|
-
out.set(f.rel, { rel: f.rel, abs: f.abs, hash, size: f.size, mtimeMs: f.mtimeMs, cls });
|
|
943
|
+
if (isFilePlaneClass(cls)) out.push({ f, cls });
|
|
705
944
|
}
|
|
706
945
|
return out;
|
|
707
946
|
}
|
|
@@ -736,14 +975,43 @@ export interface FilePlane {
|
|
|
736
975
|
unmeasured: number;
|
|
737
976
|
byClass: Record<string, { files: number; bytes: number }>;
|
|
738
977
|
} | null;
|
|
978
|
+
/** Issue #207 (7b) — the held local deletes, as Sync details shows them. */
|
|
979
|
+
heldDeletes(): ReturnType<typeof summarizeHeldDeletes>;
|
|
980
|
+
/**
|
|
981
|
+
* Issue #207 (7b) — the person's answer to held deletes (`folder` null = all of them). `send`: the
|
|
982
|
+
* next passes delete them through the hub's door, past this Mac's breaker. `purging`: a confirmed
|
|
983
|
+
* owner purge is deleting them on the hub — the plane leaves them alone until `endPurge`. `keep`:
|
|
984
|
+
* kept on the hub, never proposed or downloaded again. Returns the paths the answer covered.
|
|
985
|
+
*/
|
|
986
|
+
answerHeldDeletes(how: 'send' | 'purging' | 'keep', folder: string | null): string[];
|
|
987
|
+
/** The purge for these paths ended (done or not): held again unless the hub deleted them. */
|
|
988
|
+
endPurge(rels: readonly string[]): void;
|
|
739
989
|
}
|
|
740
990
|
|
|
741
991
|
export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
992
|
+
// fix/207 — the receive consent, read live (see `FilePlaneOptions.allowCodeModules`).
|
|
993
|
+
const mayReceiveCode = (): boolean =>
|
|
994
|
+
typeof opts.allowCodeModules === 'function'
|
|
995
|
+
? opts.allowCodeModules() === true
|
|
996
|
+
: opts.allowCodeModules === true;
|
|
997
|
+
const mayUploadCode = (): boolean => opts.canUploadCodeModules ?? mayReceiveCode();
|
|
742
998
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
743
999
|
const log = opts.log ?? console;
|
|
744
1000
|
const now = opts.now ?? Date.now;
|
|
745
1001
|
const base = opts.hubUrl.replace(/\/+$/, '');
|
|
746
1002
|
const { ledger, designRoot } = opts;
|
|
1003
|
+
/** Issue #207 (7b) — held deletes the person said to send through the door (in memory). */
|
|
1004
|
+
const confirmedDeletes = new Set<string>();
|
|
1005
|
+
/** Issue #207 (7b) — held deletes an owner purge is deleting on the hub right now. */
|
|
1006
|
+
const purgingDeletes = new Set<string>();
|
|
1007
|
+
const readPropagateDeletes = (): boolean =>
|
|
1008
|
+
(typeof opts.propagateDeletes === 'function'
|
|
1009
|
+
? opts.propagateDeletes()
|
|
1010
|
+
: opts.propagateDeletes) === true;
|
|
1011
|
+
const readIgnoreFolders = (): string[] =>
|
|
1012
|
+
normalizeIgnoreFolders(
|
|
1013
|
+
typeof opts.ignoreFolders === 'function' ? opts.ignoreFolders() : opts.ignoreFolders
|
|
1014
|
+
);
|
|
747
1015
|
/**
|
|
748
1016
|
* The design root with its own symlinks resolved. Containment is judged
|
|
749
1017
|
* against THIS, not the configured string — otherwise a project reached
|
|
@@ -1519,8 +1787,12 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1519
1787
|
quotaExhausted?: true;
|
|
1520
1788
|
quotaResetsAt?: number;
|
|
1521
1789
|
permanent?: true;
|
|
1790
|
+
/** Issue #207 — the file is no longer on this Mac: cancelled, not failed. */
|
|
1791
|
+
gone?: true;
|
|
1522
1792
|
}
|
|
1523
1793
|
> {
|
|
1794
|
+
// A FILE THAT LEFT THIS MAC is not uploaded, and not retried (issue #207).
|
|
1795
|
+
if (!existsSync(local.abs)) return { ok: false, gone: true, reason: 'no longer on this Mac' };
|
|
1524
1796
|
// PRE-FLIGHT AGAINST THE DOOR'S OWN CEILING, before a byte is read.
|
|
1525
1797
|
//
|
|
1526
1798
|
// `tooLarge` is TERMINAL: the returned reason is stored and the caller
|
|
@@ -1554,10 +1826,28 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1554
1826
|
}
|
|
1555
1827
|
// T18 — past one request: a resumable session, in verified parts.
|
|
1556
1828
|
if (local.size > singlePutCeiling()) return pushSession(local, expect);
|
|
1557
|
-
|
|
1829
|
+
// ISSUE #207 — A LARGE BODY STREAMS FROM DISK. Handing fetch the whole file
|
|
1830
|
+
// as one buffer cost TWICE the file in memory over TLS (measured: 532 MB of
|
|
1831
|
+
// RSS for a 256 MB body; a `Bun.file` body is no better there), copied on
|
|
1832
|
+
// the main thread — the memmove a desktop uploading thousands of renders
|
|
1833
|
+
// spent its time in. A stream costs its read-ahead. The hub hashes what
|
|
1834
|
+
// lands against `x-maude-content-sha256`, so a file that changes mid-flight
|
|
1835
|
+
// is refused there, never stored under the wrong hash.
|
|
1836
|
+
let bytes: Uint8Array | ReadableStream<Uint8Array>;
|
|
1558
1837
|
try {
|
|
1559
|
-
|
|
1838
|
+
if (local.size > STREAM_UPLOAD_ABOVE_BYTES) {
|
|
1839
|
+
const st = statSync(local.abs);
|
|
1840
|
+
if (st.size !== local.size || st.mtimeMs !== local.mtimeMs) {
|
|
1841
|
+
return { ok: false, reason: 'The file changed since it was read — it goes up next pass' };
|
|
1842
|
+
}
|
|
1843
|
+
bytes = Bun.file(local.abs).stream();
|
|
1844
|
+
} else {
|
|
1845
|
+
bytes = readFileSync(local.abs);
|
|
1846
|
+
}
|
|
1560
1847
|
} catch (err) {
|
|
1848
|
+
if ((err as NodeJS.ErrnoException)?.code === 'ENOENT') {
|
|
1849
|
+
return { ok: false, gone: true, reason: 'no longer on this Mac' };
|
|
1850
|
+
}
|
|
1561
1851
|
// A LOCAL DISK READ, not a transfer. Classifying it as a transport
|
|
1562
1852
|
// failure would tell a person the workspace is unreachable when the file
|
|
1563
1853
|
// is simply gone or unreadable — a wrong answer is worse than a vague one.
|
|
@@ -1581,6 +1871,9 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1581
1871
|
'content-type': 'application/octet-stream',
|
|
1582
1872
|
'x-maude-content-sha256': local.hash,
|
|
1583
1873
|
'x-maude-expect-hash': expect ?? 'none',
|
|
1874
|
+
// A stream has no length of its own; the door and every proxy in
|
|
1875
|
+
// front of it see the same one a buffer would have carried.
|
|
1876
|
+
'content-length': String(local.size),
|
|
1584
1877
|
},
|
|
1585
1878
|
body: bytes as unknown as BodyInit,
|
|
1586
1879
|
signal: AbortSignal.timeout(PUT_TIMEOUT_MS),
|
|
@@ -1598,6 +1891,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1598
1891
|
const body = (await res.json().catch(() => ({}))) as { seq?: unknown };
|
|
1599
1892
|
return { ok: true, seq: typeof body?.seq === 'number' ? body.seq : null };
|
|
1600
1893
|
} catch (err) {
|
|
1894
|
+
if (!existsSync(local.abs)) return { ok: false, gone: true, reason: 'no longer on this Mac' };
|
|
1601
1895
|
return { ok: false, reason: transportFailure(err, local.rel, log) };
|
|
1602
1896
|
} finally {
|
|
1603
1897
|
ledger.outboxDone(local.hash);
|
|
@@ -1801,7 +2095,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1801
2095
|
* spent on them. A conflict, a refusal and an unoffered reference are not "on their way".
|
|
1802
2096
|
*/
|
|
1803
2097
|
function waitingHere(): number {
|
|
1804
|
-
const uploadsCode =
|
|
2098
|
+
const uploadsCode = mayUploadCode();
|
|
1805
2099
|
let n = 0;
|
|
1806
2100
|
for (const [rel, r] of Object.entries(ledger.rows())) {
|
|
1807
2101
|
if (r.state === 'stuck' || r.state === 'pushing') n += 1;
|
|
@@ -1829,9 +2123,9 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
1829
2123
|
* the hold can say how much waits. The scan only records observations (`noteLocal`) — no decision, no
|
|
1830
2124
|
* ancestor moves.
|
|
1831
2125
|
*/
|
|
1832
|
-
function holdAtCursor(out: FilePlaneResult): FilePlaneResult {
|
|
2126
|
+
async function holdAtCursor(out: FilePlaneResult): Promise<FilePlaneResult> {
|
|
1833
2127
|
if (hitRateLimit === null) return out;
|
|
1834
|
-
|
|
2128
|
+
await scanLocalFilesAsync(designRoot, ledger, opts.canvasGroups);
|
|
1835
2129
|
return holdIfRateLimited(out, waitingHere());
|
|
1836
2130
|
}
|
|
1837
2131
|
|
|
@@ -2078,7 +2372,9 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2078
2372
|
if (fullRead && !page.truncated) ledger.pruneRemotes(new Set(delta.keys()));
|
|
2079
2373
|
|
|
2080
2374
|
// ── 2. Ours ──────────────────────────────────────────────────────────
|
|
2081
|
-
const
|
|
2375
|
+
const ignoreFolders = readIgnoreFolders();
|
|
2376
|
+
const propagateDeletes = readPropagateDeletes();
|
|
2377
|
+
const local = await scanLocalFilesAsync(designRoot, ledger, opts.canvasGroups);
|
|
2082
2378
|
|
|
2083
2379
|
// ── 3. Decide ────────────────────────────────────────────────────────
|
|
2084
2380
|
let work: {
|
|
@@ -2099,6 +2395,16 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2099
2395
|
for (const rel of paths) {
|
|
2100
2396
|
const row = delta.get(rel);
|
|
2101
2397
|
const here = local.get(rel);
|
|
2398
|
+
// A FOLDER THE PERSON CHOSE NOT TO SYNC (issue #207, `linkedHub.ignoreFolders`). Nothing
|
|
2399
|
+
// moves in either direction — no upload, no download, no delete — and what the workspace
|
|
2400
|
+
// already holds stays there. Reported as `ignored`, never as waiting.
|
|
2401
|
+
if (ignoreFolders.length > 0 && isIgnoredRel(rel, ignoreFolders)) {
|
|
2402
|
+
if (here && ledger.row(rel)?.state !== 'ignored') {
|
|
2403
|
+
ledger.setState(rel, 'ignored', { reason: IGNORED_REASON });
|
|
2404
|
+
}
|
|
2405
|
+
if (here) out.ignored = (out.ignored ?? 0) + 1;
|
|
2406
|
+
continue;
|
|
2407
|
+
}
|
|
2102
2408
|
// HELD, NOT ABSENT. A file this peer cannot move is still a file: no
|
|
2103
2409
|
// decision may read it as deleted here or missing here.
|
|
2104
2410
|
if (here?.oversized) {
|
|
@@ -2164,7 +2470,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2164
2470
|
// recorded (by push, or by agreement) was all `tombstone-agreed` needed
|
|
2165
2471
|
// to quarantine a code module on the word of a hub that may not move
|
|
2166
2472
|
// one. Refuse it here, reported, with the file and its row untouched.
|
|
2167
|
-
if (row?.deleted && here && !
|
|
2473
|
+
if (row?.deleted && here && !mayReceiveCode()) {
|
|
2168
2474
|
const cls = classifyProjectFile(rel, {
|
|
2169
2475
|
canvasGroups: opts.canvasGroups,
|
|
2170
2476
|
hasFile: (r) => local.has(r) || existsSync(path.join(designRoot, r)),
|
|
@@ -2201,7 +2507,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2201
2507
|
drop(out, rel, `classifies '${cls}' here`, ledger);
|
|
2202
2508
|
continue;
|
|
2203
2509
|
}
|
|
2204
|
-
if (cls === 'code-module' && !
|
|
2510
|
+
if (cls === 'code-module' && !mayReceiveCode()) {
|
|
2205
2511
|
// AGREEMENT IS NOT A TRANSFER. The gate refuses to move a code
|
|
2206
2512
|
// module from an unvouched hub (DDR-054); identical bytes on both
|
|
2207
2513
|
// sides move nothing, and reporting them as refused left a
|
|
@@ -2225,10 +2531,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2225
2531
|
// hub moved, or there is no agreed ancestor — still never lands here.
|
|
2226
2532
|
const ancestor = ledger.ancestorOf(rel);
|
|
2227
2533
|
const uploadOnly =
|
|
2228
|
-
here !== undefined &&
|
|
2229
|
-
ancestor !== null &&
|
|
2230
|
-
ancestor === remoteHash &&
|
|
2231
|
-
(opts.canUploadCodeModules ?? opts.allowCodeModules);
|
|
2534
|
+
here !== undefined && ancestor !== null && ancestor === remoteHash && mayUploadCode();
|
|
2232
2535
|
if (!uploadOnly) {
|
|
2233
2536
|
drop(
|
|
2234
2537
|
out,
|
|
@@ -2249,7 +2552,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2249
2552
|
// it (2026-10-02, alligators: five `ui/club-web/_*.ts`, 264 refusals,
|
|
2250
2553
|
// passes stopped with 2 500+ paths still to do). Never ask: report it,
|
|
2251
2554
|
// keep the file, and let the rest of the pass run.
|
|
2252
|
-
if (remoteHash === null && here && !(
|
|
2555
|
+
if (remoteHash === null && here && !mayUploadCode()) {
|
|
2253
2556
|
const cls = classifyProjectFile(rel, {
|
|
2254
2557
|
canvasGroups: opts.canvasGroups,
|
|
2255
2558
|
hasFile: (r) => local.has(r) || existsSync(path.join(designRoot, r)),
|
|
@@ -2303,15 +2606,40 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2303
2606
|
continue;
|
|
2304
2607
|
}
|
|
2305
2608
|
|
|
2609
|
+
// AN ANSWER IS BEING CARRIED OUT, OR WAS GIVEN (issue #207, 7b). A held delete an owner purge
|
|
2610
|
+
// is deleting on the hub is left alone until it ends. A file the person kept on the hub stays
|
|
2611
|
+
// there and does not come back here — while the hub still holds the bytes this Mac last saw.
|
|
2612
|
+
// A new version from a teammate, a tombstone, or the file back on this disk decides as usual.
|
|
2613
|
+
if (!here && purgingDeletes.has(rel) && remoteHash !== null) continue;
|
|
2614
|
+
if (
|
|
2615
|
+
!here &&
|
|
2616
|
+
kept?.state === 'hub-only' &&
|
|
2617
|
+
remoteHash !== null &&
|
|
2618
|
+
remoteHash === (kept.syncedHash ?? kept.lastSeenHash ?? null)
|
|
2619
|
+
) {
|
|
2620
|
+
continue;
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
// GONE FROM HERE, AND THE HUB HOLDS EXACTLY WHAT THIS MAC LAST SAW (issue #207). No recorded
|
|
2624
|
+
// ancestor — the upload landed while its answer was lost (a timeout on a slow link), or the
|
|
2625
|
+
// pass ended before adopting it — so this read as "the hub offers a file this machine has
|
|
2626
|
+
// never had" and the next pass downloaded the moved-out renders again. This Mac DID have
|
|
2627
|
+
// those bytes: it is a local delete, decided (and breaker-held) like any other. Only for
|
|
2628
|
+
// this decision — the ledger's ancestor moves only after bytes land (`adoptAfter`).
|
|
2629
|
+
const ancestor =
|
|
2630
|
+
ledger.ancestorOf(rel) ??
|
|
2631
|
+
(!here && remoteHash !== null && !row?.deleted && kept?.lastSeenHash === remoteHash
|
|
2632
|
+
? remoteHash
|
|
2633
|
+
: null);
|
|
2306
2634
|
const state: FileState = {
|
|
2307
2635
|
path: rel,
|
|
2308
2636
|
local: here?.hash ?? null,
|
|
2309
2637
|
remote: remoteHash,
|
|
2310
|
-
ancestor
|
|
2638
|
+
ancestor,
|
|
2311
2639
|
...(row?.deleted ? { remoteTombstone: true } : {}),
|
|
2312
2640
|
...(degraded ? { epochChanged: true } : {}),
|
|
2313
2641
|
...(remoteHash && ledger.outboxHas(remoteHash) ? { selfInFlight: true } : {}),
|
|
2314
|
-
...(
|
|
2642
|
+
...(propagateDeletes ? { propagateDeletes: true } : {}),
|
|
2315
2643
|
};
|
|
2316
2644
|
const decision = decideFile(state);
|
|
2317
2645
|
// REFUSED FOR GOOD, AND UNCHANGED (issue #175): the door already said no
|
|
@@ -2343,10 +2671,25 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2343
2671
|
state: remoteHash !== null ? 'on-hub' : 'local-only',
|
|
2344
2672
|
});
|
|
2345
2673
|
out.synced += 1;
|
|
2674
|
+
} else if (
|
|
2675
|
+
decision.adoptAncestor &&
|
|
2676
|
+
!here &&
|
|
2677
|
+
(row?.deleted === true || ledger.remoteOf(rel) === null)
|
|
2678
|
+
) {
|
|
2679
|
+
// GONE ON BOTH SIDES (issue #207). Not here, and the hub SAID so — a tombstone on this
|
|
2680
|
+
// page, or a remembered one (a complete full read is the only other writer of `null`).
|
|
2681
|
+
// There is nothing left to move or to agree on, so nothing to track. The row stayed
|
|
2682
|
+
// behind instead, and a row with no state reads `local-only`: every file this Mac
|
|
2683
|
+
// deleted came back in Sync details as "only on this Mac" the pass its own tombstone
|
|
2684
|
+
// arrived (`noteRemote` re-creates a forgotten row). A remote never learned (`undefined`)
|
|
2685
|
+
// is not a statement, so that row keeps its ancestor for the next full read.
|
|
2686
|
+
ledger.forget(rel);
|
|
2687
|
+
purgingDeletes.delete(rel);
|
|
2688
|
+
confirmedDeletes.delete(rel);
|
|
2346
2689
|
} else if (
|
|
2347
2690
|
!here &&
|
|
2348
2691
|
remoteHash !== null &&
|
|
2349
|
-
!
|
|
2692
|
+
!propagateDeletes &&
|
|
2350
2693
|
state.ancestor === remoteHash
|
|
2351
2694
|
) {
|
|
2352
2695
|
// 2.0.5 rule (a) — DELETED HERE, KEPT THERE, AND SAID SO. With delete
|
|
@@ -2395,8 +2738,17 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2395
2738
|
|
|
2396
2739
|
for (const direction of ['out', 'in'] as const) {
|
|
2397
2740
|
const action = direction === 'out' ? 'propagate-delete' : 'quarantine';
|
|
2398
|
-
|
|
2399
|
-
|
|
2741
|
+
// Issue #207 (7b) — a held delete the person confirmed goes through (the hub's door still
|
|
2742
|
+
// gates it). One still waiting for an answer keeps waiting, and a new local delete joins its
|
|
2743
|
+
// question rather than slipping out under the limit beside it.
|
|
2744
|
+
const hits = work.filter(
|
|
2745
|
+
(w) => w.decision.action === action && !(direction === 'out' && confirmedDeletes.has(w.rel))
|
|
2746
|
+
);
|
|
2747
|
+
const asking =
|
|
2748
|
+
direction === 'out' &&
|
|
2749
|
+
opts.unlimitedOutboundDeletes !== true &&
|
|
2750
|
+
hits.some((w) => ledger.row(w.rel)?.state === 'delete-held');
|
|
2751
|
+
if (hits.length === 0 || !(asking || overBreaker(direction, hits.length))) continue;
|
|
2400
2752
|
const paths = hits.map((w) => w.rel).sort();
|
|
2401
2753
|
// ONCE PER DISTINCT HOLD, not once per pass.
|
|
2402
2754
|
//
|
|
@@ -2412,14 +2764,28 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2412
2764
|
? `[sync/files] ${paths.length} of ${tracked} tracked files are gone from this machine — NOT telling the project. If that was a branch switch or a bad restore, nothing is lost; if you meant it, confirm the deletion.`
|
|
2413
2765
|
: `[sync/files] the project wants to remove ${paths.length} of ${tracked} tracked files here — holding. Nothing was deleted.`
|
|
2414
2766
|
);
|
|
2415
|
-
out.deleteHeld = { direction, count: paths.length, paths: paths.slice(0, 200) };
|
|
2416
2767
|
for (const w of hits) {
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
}
|
|
2768
|
+
if (direction === 'out') {
|
|
2769
|
+
// Its own state (7b): `conflict` read as "stuck" and offered no answer.
|
|
2770
|
+
if (ledger.row(w.rel)?.state !== 'delete-held') {
|
|
2771
|
+
ledger.setState(w.rel, 'delete-held', { reason: DELETE_HELD_REASON });
|
|
2772
|
+
}
|
|
2773
|
+
} else {
|
|
2774
|
+
ledger.setState(w.rel, 'conflict', {
|
|
2775
|
+
reason: 'the project wants this removed, as part of a batch too large to apply unasked',
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
if (direction === 'out') {
|
|
2780
|
+
const all = summarizeHeldDeletes(ledger.rows());
|
|
2781
|
+
out.deleteHeld = {
|
|
2782
|
+
direction,
|
|
2783
|
+
count: all.count,
|
|
2784
|
+
paths: all.paths.slice(0, 200),
|
|
2785
|
+
folders: all.folders.slice(0, 20),
|
|
2786
|
+
};
|
|
2787
|
+
} else {
|
|
2788
|
+
out.deleteHeld = { direction, count: paths.length, paths: paths.slice(0, 200) };
|
|
2423
2789
|
}
|
|
2424
2790
|
work = work.filter((w) => !hits.includes(w));
|
|
2425
2791
|
}
|
|
@@ -2459,6 +2825,11 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2459
2825
|
work = work.filter((w) => !firstAnchor.includes(w));
|
|
2460
2826
|
}
|
|
2461
2827
|
|
|
2828
|
+
// A LONG RUN OF PICTURES IN ONE FOLDER (issue #207) — a render sequence, a frame dump. They
|
|
2829
|
+
// sync like everything else; the panel only says so, and offers to leave the folder out.
|
|
2830
|
+
const sequences = largeSequences(work);
|
|
2831
|
+
if (sequences.length > 0) out.largeSequences = sequences;
|
|
2832
|
+
|
|
2462
2833
|
// ── 4. Apply ─────────────────────────────────────────────────────────
|
|
2463
2834
|
//
|
|
2464
2835
|
// The open canvas first (#204): its own files, imports and assets are what a person is looking
|
|
@@ -2967,6 +3338,16 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
2967
3338
|
out.dropped.push({ rel, reason: res.reason });
|
|
2968
3339
|
return true;
|
|
2969
3340
|
}
|
|
3341
|
+
if (res.gone) {
|
|
3342
|
+
// ISSUE #207 — THE FILE LEFT THIS MAC between the scan and its upload (6 555 renders
|
|
3343
|
+
// moved out mid-pass: 951 ENOENT retries every 5 s). Not a failure and not a backoff:
|
|
3344
|
+
// the upload is cancelled and the row leaves the queue. The next pass reads the
|
|
3345
|
+
// absence — nothing if the hub never had it, a delete proposal if it did.
|
|
3346
|
+
ledger.noteAttemptOk(rel);
|
|
3347
|
+
ledger.setState(rel, 'local-only', { reason: 'no longer on this Mac' });
|
|
3348
|
+
out.gone = (out.gone ?? 0) + 1;
|
|
3349
|
+
return false;
|
|
3350
|
+
}
|
|
2970
3351
|
out.failed.push({ rel, reason: res.reason });
|
|
2971
3352
|
ledger.setState(rel, 'stuck', { reason: res.reason });
|
|
2972
3353
|
return false;
|
|
@@ -3015,7 +3396,7 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
3015
3396
|
out.conflicts.push({ rel, copy: copyRel });
|
|
3016
3397
|
// The copy travels too, so BOTH ends see the conflict rather than only
|
|
3017
3398
|
// the machine that happened to lose.
|
|
3018
|
-
const copyLocal = statLocal(copyRel);
|
|
3399
|
+
const copyLocal = await statLocal(copyRel);
|
|
3019
3400
|
if (copyLocal) {
|
|
3020
3401
|
const res = await push(copyLocal, null);
|
|
3021
3402
|
if (res.ok) out.pushed.push(copyRel);
|
|
@@ -3054,8 +3435,11 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
3054
3435
|
// Gone here, and the hub still holds exactly what we last reconciled —
|
|
3055
3436
|
// the Syncthing rule. The CAS carries our ancestor, so an edit that
|
|
3056
3437
|
// landed in between wins and this comes back as a conflict instead.
|
|
3057
|
-
|
|
3438
|
+
// No recorded ancestor (issue #207): the hub hash this Mac last saw here is the CAS — the
|
|
3439
|
+
// decision above only got here because the two were equal.
|
|
3440
|
+
const res = await pushDelete(rel, ledger.ancestorOf(rel) ?? remoteHash);
|
|
3058
3441
|
if (res.ok) {
|
|
3442
|
+
confirmedDeletes.delete(rel);
|
|
3059
3443
|
ledger.forget(rel);
|
|
3060
3444
|
out.deleted.push({ rel, parked: null });
|
|
3061
3445
|
return true;
|
|
@@ -3090,11 +3474,11 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
3090
3474
|
}
|
|
3091
3475
|
}
|
|
3092
3476
|
|
|
3093
|
-
function statLocal(rel: string): SyncableLocalFile | null {
|
|
3477
|
+
async function statLocal(rel: string): Promise<SyncableLocalFile | null> {
|
|
3094
3478
|
const abs = path.join(designRoot, rel);
|
|
3095
3479
|
try {
|
|
3096
3480
|
const st = statSync(abs);
|
|
3097
|
-
const hash =
|
|
3481
|
+
const hash = await hashFileStreamed(abs);
|
|
3098
3482
|
return { rel, abs, hash, size: st.size, mtimeMs: st.mtimeMs, cls: 'inert-media' };
|
|
3099
3483
|
} catch {
|
|
3100
3484
|
return null;
|
|
@@ -3121,6 +3505,27 @@ export function createFilePlane(opts: FilePlaneOptions): FilePlane {
|
|
|
3121
3505
|
dorucekaTotal() {
|
|
3122
3506
|
return Object.keys(ledger.rows()).length;
|
|
3123
3507
|
},
|
|
3508
|
+
heldDeletes() {
|
|
3509
|
+
// What still waits for an answer: an answered row (being sent, or purged) is not asked again.
|
|
3510
|
+
const waiting: Record<string, LedgerRow> = {};
|
|
3511
|
+
for (const [rel, row] of Object.entries(ledger.rows()))
|
|
3512
|
+
if (!purgingDeletes.has(rel) && !confirmedDeletes.has(rel)) waiting[rel] = row;
|
|
3513
|
+
return summarizeHeldDeletes(waiting);
|
|
3514
|
+
},
|
|
3515
|
+
answerHeldDeletes(how, folder) {
|
|
3516
|
+
const rels = summarizeHeldDeletes(ledger.rows()).paths.filter(
|
|
3517
|
+
(r) => inHeldFolder(r, folder) && !purgingDeletes.has(r) && !confirmedDeletes.has(r)
|
|
3518
|
+
);
|
|
3519
|
+
for (const rel of rels) {
|
|
3520
|
+
if (how === 'send') confirmedDeletes.add(rel);
|
|
3521
|
+
else if (how === 'purging') purgingDeletes.add(rel);
|
|
3522
|
+
else ledger.setState(rel, 'hub-only', { reason: HUB_ONLY_REASON });
|
|
3523
|
+
}
|
|
3524
|
+
return rels;
|
|
3525
|
+
},
|
|
3526
|
+
endPurge(rels) {
|
|
3527
|
+
for (const rel of rels) purgingDeletes.delete(rel);
|
|
3528
|
+
},
|
|
3124
3529
|
/**
|
|
3125
3530
|
* HOW MUCH MEDIA IS NOT HERE — plan T29.
|
|
3126
3531
|
*
|