0010: Sync, revision tracking, cloud assets and web readiness
Status: proposed, 2026-11-21 (revised after PR #240 review). Builds on 0001 (rendering), 0004 (document packages), 0005 (linked sources), 0006 (template capabilities), 0009 (book format gating), the save ledger (#201) and the web companion exploration (#212). Captures long-term architectural direction and the short-term guardrails it places on persistence, revisions, asset metadata, compatibility and trust. Sync transports, authentication and web editing scope remain deferred.
Problem
ImageFlow is currently single-machine local software: each .imageflow package lives on one Mac's disk, linked sources store canonical absolute paths, and runtime locks and history live inside .imageflow/. Two longer-term needs put pressure on those assumptions:
- Multi-Mac sync, primarily one person switching between a desktop (with large local storage or a Lightroom export folder) and a laptop (with smaller disk space and occasional offline edits). Multi-user collaboration is optional for now.
- A lightweight web companion (#212), starting from shareable read-only proofs and potentially extending to light editing (captions, crops, photo swaps, spread order), alongside eventual support for cloud asset providers (S3/R2, WebDAV, Immich, Lightroom, Apple Photos).
Putting a .imageflow package into iCloud Drive, Dropbox or Syncthing today creates concrete failure modes:
- Machine-local runtime files sit inside
.imageflow/.writer.lockrecords a local PID,/tmpUnix socket endpoint and local(dev, ino)(desktop/persistence.ts,desktop/lock-owner.ts). A second Mac cannot reach that socket and sees a different(dev, ino), so it treats the active lock as stale, moves it towriter-stale-*.jsonand opens the book writable anyway.pending-save.jsonrelies on local hard links and inode checks; file-by-file cloud sync can deliver it out of order withproject.jsonandphotos.jsonand trigger interrupted-save recovery errors..imageflow/history/ledger.jsonlis a single mutable append-only file that produces conflict copies under concurrent sessions. - Torn multi-file sync and placeholder eviction. Sync engines resolve conflicts per file. Even without lock or journal files, iCloud Drive or Dropbox can leave
project.jsonfrom Mac A besidephotos.jsonfrom Mac B, breaking referential consistency. iCloud Drive's Optimize Mac Storage can also evict photos to dataless placeholders, stallingO_NONBLOCKreads and revision hashing (desktop/revisions.ts). - Whole-file manifest conflicts.
project.jsonholds every spread andphotos.jsonholds every photo entry. Non-overlapping edits on two Macs collide at the file level because there is no retained common-ancestor snapshot. - Asset asymmetry and non-portable linked paths. Linked sources store raw absolute paths (
/Users/...), whileSourceStoreapprovals, digests, dimensions and cached previews are keyed by machine-local filesystem identity (volumeUUID-inode-birthtimeNs,desktop/source-identity.ts).photos.jsonstores neither content digests nor dimensions, anddesktop/revisions.tshashes local file availability (state.kind) and photo bytes — so a laptop without originals cannot compute a matching revision or even know photo aspect ratios or capture times. - Mixed app versions. With sync, two ImageFlow versions will inevitably open the same book. Today
projectSchemastrips unknown keys (src/project.ts), andcheckpointRecordSchemais.strict()atversion: 1(desktop/persistence.ts), so unguarded additive fields can be silently dropped or treated as unreadable by an older build.
Principle
Separate book state from asset bytes, separate sync snapshots from the local save ledger, and keep the revision model independent of sync transport and authentication.
A .imageflow package stays a local, human-readable, Git- and MCP-friendly working tree. Sync engines, remote storage backends, cloud asset providers and an eventual web frontend should layer over a portable causal revision model and content-addressed asset/proxy layer — much as Git separates its commit/blob model from local folders, S3 or hosted services — rather than replacing local files or locking books to one cloud vendor.
Architectural direction
1. Split book state from originals, with synced asset facts and proxies
Book state (project.json, photos.json, synced asset facts, texts/, files/, template/) is small (kilobytes to a few megabytes), whereas originals in photos/ can reach tens of gigabytes.
- Synced asset facts enable offline laptops and web. Recording per-source
digest,width,heightand capture metadata in a dedicated derived file (assets-meta.json) — keepingphotos.jsonfocused on user-editable metadata and preserving its read-onlycaptureFieldscontract (src/project.ts) — lets a Mac or browser without originals lay out spreads, crop photos and sort by capture time. - Derived metadata stays outside the save journal and user-edit divergence. Because 0005 computes linked-photo digests lazily in the background after opening,
assets-meta.jsonis not part ofdesktop/persistence.ts's two-manifest atomic save journal (project.json+photos.json) orledger.jsonl, and does not advance the user-authoredbookStateRevision. It is written independently via atomic temp-file rename (missing or stale entries simply regenerate from available originals), never pollutes Undo/Redo orlist_book_checkpoints, and syncs alongside snapshots with a trivial per-asset auto-resolve rule starting in Milestone 1: per asset ID, a replica with an available verified original (or newer verified observation) wins automatically without ever triggering a book-level conflict copy. - Staleness rule for in-place re-exports. Consistent with 0005, an available local original is always authoritative for local editing and print. When a linked photo is re-exported in place (for example from Lightroom) and its new bytes produce a different
digest, the local Mac refreshes its entry inassets-meta.jsonand generates a new content-addressed proxy; the next sync propagates that updated asset fact via the per-asset auto-resolve rule without colliding with unrelated edits on another Mac. - Content-addressed screen proxies. A remote Mac or web light-editor only needs screen-resolution proxies keyed by original content digest and rendition spec; originals remain required for print PDF export.
- Two web tiers (#212). For read-only web proofs, publishing pre-rendered spreads from the Mac avoids Safari text-flow and hyphenation differences and avoids shipping executable template code and licensed fonts to unauthenticated guests. For authenticated light editing,
RenderProject(src/project.ts) already provides a clean web-shaped payload (project,photoswithsrcURLs,texts,files, compiledtemplate) that can drive the React renderer inside a sandboxed iframe using HTTPS proxy URLs, keeping print PDF export on the Mac (or a later headless Chromium worker).
2. Sync snapshot DAG, milestones and merge policy
ImageFlow separates two distinct history mechanisms:
- Local save ledger (
.imageflow/history/ledger.jsonl, #201): records every local save (including Undo and Redo), stores manifest hashes only, is pruned at 4 MB, and serves local inspection and MCP idempotency. It is not a merge base. - Sync snapshots: immutable revision nodes
(bookStateRevision, parents)captured only at sync points, retaining the full small book state (project.json,photos.json,texts/,files/,template/) plusassets-meta.jsonas derived companion facts.
Using an immutable snapshot DAG over plain files — rather than making a CRDT (Automerge/Yjs) the primary format — preserves Git and MCP workflows and lets ImageFlow validate cross-file invariants before committing. Rollout breaks cleanly into two milestones:
- Milestone 1 (fast-forward or keep both): When syncing, derived
assets-meta.jsonentries auto-resolve per asset ID (the replica with a locally available verified original wins, so background digesting on open never causes false divergence). For user-authored book state, if one side's sync node is an ancestor of the other, fast-forward cleanly; if the two sides diverged, preserve both copies and surface the conflict explicitly. This covers almost all solo desktop ↔ laptop switching without needing merge machinery up front.- Implemented (#250):
src/sync-snapshot.tsdefines the immutable commit header and state blob and the decision table;desktop/sync-remote.tsthe transport-agnosticSyncRemote;desktop/sync-engine.tspush, pull and keep-both. A pull downloads and verifies every blob into App Support before it marks itself and touches the book, so an interrupted pull is finished from those staged blobs when the book next opens, without the remote. Linked paths are reduced to file names in snapshots; a pull keeps this Mac's own path for every source still linked here and gives a source newly linked elsewhere an unlocated placeholder path (/imageflow-unlocated/<name>) that Locate Folder… repairs by its synced digest. A pull that changestemplate/makes the next network question ask about newly declared origins even in a trusted book. Every target is checked before a pull is marked; a marked pull that still fails is given up rather than retried at every open, and the next sync keeps both versions. A remote that does not list the commit this Mac last synced counts as still syncing, and records written by a newer version stop sync with a request to update. Linked texts and files have no proxies: on a Mac where they are not located, the book renders without their content until they are. - Implemented (#251):
desktop/sync-store-folder.ts(desktop/sync-remote-folder.tsuntil #278 put it underStoreRemoteas a plain object store, with every blob under its book's prefix; see 0012) is the first transport, a plain sync folder (iCloud Drive, Dropbox, Syncthing, a NAS) with only immutable files: commit headers underbooks/<bookId>/snapshots/and content-addressed blobs, each written through a temporary file and a rename (headers through a hard link, so one is never replaced) and copied withCOPYFILE_FICLONE. Open from Sync Folder lists the books by their tip headers and makes a new, untrusted local package from a tip; File → Sync and the status bar sync manually and show the status (in sync, ahead, behind, diverged, remote still syncing, abandoned). Owned originals never pass through a pull: a pull only copies local bytes to a photo's newphotos/path that nothing references yet, and with the per-Mac Keep originals preference they are downloaded after the sync, beside their target, without failing it. A pull that is given up leaves a trace (target, error, the half-pulled book's revision, the conflict copy) that the status shows and Keep Both reads: while the book is unchanged since, it pulls again without another conflict copy.
- Implemented (#250):
- Milestone 2 (domain-aware 3-way merge): Using the immutable snapshot at the common ancestor (
base), 3-way merge(base, local, remote)by artifact class:- Manifests (
project.json,photos.json): Newly created spreads carry UUIDs (andspreadSchemaalways requires a stable identifier), while boxes, elements, parameters, crops, photos, texts and files are already ID-keyed maps (src/project.ts). Non-overlapping edits merge automatically andproject.spreadsorder merges by spread ID. BecauseprojectSchemavalidates onlyproject.json, every merge runs an explicit cross-file referential check againstphotos.json(for example, if one Mac deletes a photo that the other Mac placed on a spread, retain the referenced photo entry or surface an explicit missing-source diagnostic rather than committing a dangling reference). Same-slot collisions fall back to explicit resolution or a preserved conflict copy. - Markdown and text files (
texts/*.md, textfiles/*): Line-based 3-way text merge, falling back to a conflict copy on overlapping edits. - Executable template code (
template/*): Never silently auto-merge conflicting edits; preserve a conflict copy and require an explicit choice. - Web suggestions (#212): A web editor attaches the
bookStateRevisionit edited from, so the Mac app applies or surfaces conflicts through the same revision check. If real-time co-editing is ever added on the web, live sessions can still commit snapshots into the same DAG.
- Manifests (
3. Two distinct revision hashes
ImageFlow needs two revision concepts with different jobs:
- Local render-input revision (what
desktop/revisions.tsandexpectedRevisionuse today): covers local file availability (state.kind), actual original bytes on disk, template files and local filesystem observations so checks, previews and exports detect any local input change. - Portable book-state revision: hashes a canonical JSON serialization (recursively sorted keys, since JS objects preserve insertion order) of
project.jsonandphotos.json, together with the content digests oftexts/,files/andtemplate/— excluding machine-local absolute linked paths ({ path, linked: true }inphotos.jsonandproject.json), derivedassets-meta.jsonrefreshes, local availability states and raw original bytes. Until namedlocal-rootlocators exist, machine-local absolute linked paths are kept per Mac alongsidesource-accessapprovals and are not overwritten across Macs during sync, so relinking on a laptop neither changes the portable revision nor ping-pongs the desktop's paths. Two Macs (one with originals, one with proxies only) therefore compute the exact same portable book-state revision for the same user-authored book state.
4. Pluggable sync backends and cloud asset providers
Keeping sync snapshots and content-addressed blobs transport-agnostic leaves storage choices open:
- Synced folders (iCloud Drive, Dropbox, Syncthing): Plain working-tree manifests in a synced folder are safe only for strictly sequential single-Mac use because sync daemons resolve conflicts per file and can tear
project.jsonfromphotos.json. Making a synced folder genuinely conflict-safe requires treating immutable snapshot bundles (carrying all manifests and text/template state atomically) plus immutable head/node records as the sync truth, and projecting the winning snapshot into the local working tree. - Git:
docs/mcp.mdexplicitly advises.gitignore-ing.imageflow/, so Git does not transport ImageFlow's internal history. Instead, Git acts as its own commit DAG over the committed working-tree files (project.json,photos.json,texts/,template/). - Optional hosted ImageFlow Cloud or BYO remotes (S3/R2, WebDAV): Most flexible path for multi-Mac sync plus a web frontend, without locking web access to Apple IDs. (CloudKit /
CKSyncEngine+ CloudKit JS remains a candidate if Apple-only personal sync is prioritized, as noted in #212, though Electron provisioning and non-Apple guest access add friction.) - Authentication stays outside the document format. Read-only web proofs can use account-free, revocable capability links; user accounts only enter when adding hosted write-back or managed multi-Mac sync.
- Cloud asset providers and named local roots. 0005 already ensures locations are never IDs.
sourceReferenceSchemaandphotos.jsoncan evolve backward-compatibly fromstring | { path, linked: true }to provider-tagged locators — such as a namedlocal-root(mapped per Mac in local app settings) or cloud providers (s3,webdav,immich,lightroom,apple-photos). Machine-specific paths and provider credentials stay in local app settings, never in book manifests.
5. Trust boundaries
Sync and web access introduce explicit shifts in ImageFlow's security model (0005, 0006) that must remain opt-in and visible:
- Named
local-rootmappings broaden approval from file to root. ADR 0005 approves each linked file individually per Mac. A namedlocal-rootgrants a book read access to accepted file types anywhere inside that explicitly approved directory on this Mac, while remaining strictly confined within the root (no traversal or symlinks out). Users must configure and approve each root explicitly per Mac. - Synced
template/is executable code. A template arriving over sync must obey ADR 0006's book-trust model: only the user's own authenticated replicas may inherit book trust, and untrusted or shared remote template edits must never execute or gain network origins silently. - Web suggestions are command-allowlisted. Remote web edits (#212) must be restricted to an explicit allowlist of safe book commands (captions, crops, photo assignments, spread parameters/order) — never arbitrary filesystem locators,
template/files or declarednetworkorigins.
Short-term guardrails
We do not need to build a sync transport, cloud backend or web frontend yet. However, the design above sets concrete guardrails for near-term work on persistence, revisions and schemas:
- Move machine-local runtime state out of
.imageflow/. Active writer locks (writer.lock,writer-lock-acquire/) and transient save staging (pending-save.json) belong in local app support (keyed by local book identity/path) rather than inside a package directory users may place in iCloud Drive or Dropbox. This immediately removes stale-lock and recovery hazards while keeping local crash recovery and cross-process exclusion. - Ship unknown-field preservation on round-trip now (time-sensitive). Because
projectSchemaandphotoIndexSchemastrip unknown keys today (src/project.ts), unknown-field preservation only protects synced books if it ships in builds released before the first additive field appears. Commit to preserving unknown fields on round-trip inproject.jsonandphotos.jsonnow for harmless additive metadata (such asbookId), and reserveschemaVersionbumps (0009) strictly for structural or semantic additions that older builds must not edit or partially save. Keep sync snapshot metadata in its own versioned files rather than mutating the strict v1 local save ledger (desktop/persistence.ts). - Add a logical lineage
bookId(UUID). Once unknown-field preservation is in place (or gated viaschemaVersionfor earlier builds), store a persistentbookIdinproject.jsonto identify book lineage across replicas, regenerated on Duplicate and Save a Copy. Because a Finder duplicate or AirDropped copy inheritsbookIdand may diverge,bookIdnever replacessourceBookKey(volumeUUID-inode-birthtimeNs) as the local instance and security boundary (0004, 0005). - Use immutable per-commit/content-addressed sync files — never
deviceId-named mutable logs. macOS Migration Assistant and Time Machine restores clone local app support data, including any storeddeviceId, so per-device mutable segment files can collide across cloned Macs. Keying sync snapshot records by commit UUID or content hash eliminates collisions by construction. - Implement the two-hash split, per-Mac linked path exclusion, and derived
assets-meta.json. Keepdesktop/revisions.tsfocused on the local render-input revision. Define the portable book-state revision over canonical JSON (recursively sorted keys) ofproject.jsonandphotos.jsonplus text/file/template digests — explicitly excluding machine-local absolute linked paths (stored per Mac until namedlocal-rootlocators ship) and excluding derivedassets-meta.jsonrefreshes (written outside the two-manifest save journal and auto-resolved per asset ID starting in Milestone 1). - Keep manifests merge-friendly and
src/host-agnostic. Continue preferring ID-keyed maps over positional arrays for independently editable entities (giving long-lived array entries stable IDs if they become independently editable), serialize manifests deterministically, route source access throughsrc/source-locations.tshelpers, and keepsrc/free of Electron, Node and filesystem APIs so the renderer andsrc/project-commands.tsremain reusable on the web. - Key portable proxies by content digest. Retain fast local stamp-based rendition invalidation for local in-place re-exports, while keying shareable proxies by original content SHA-256 and rendition spec so remote Macs and web clients can render and crop without originals.
Deferred
- Choosing and implementing a sync transport (immutable snapshot bundle in a synced folder, BYO S3/WebDAV, optional hosted ImageFlow Cloud or CloudKit).
- Defining the web companion's scope, user/account management and server-side Chromium PDF export (#212).
- Deciding whether portable screen proxies live in a lightweight package cache or exclusively in remote object storage.
- Implementing Milestone 2's 3-way merge engine (after Milestone 1's fast-forward / keep-both flow).
- Implementing cloud asset provider integrations (
s3,immich,lightroom,apple-photos) and namedlocal-rootmappings. - Real-time multi-user co-editing.
Consequences
- Near-term persistence work eliminates the sharpest iCloud/Dropbox failure modes (stale locks and recovery journals) without pretending plain synced folders are safe for concurrent edits.
- Separating the local save ledger from immutable sync snapshots, and separating the local render-input revision from the portable book-state revision, keeps #201 and existing checks intact while giving Milestone 1 (fast-forward / keep both) and Milestone 2 (3-way merge) an actual snapshot base.
- Synced asset facts (
assets-meta.json), content-addressed proxies, explicit mixed-version rules and explicit trust boundaries let multi-Mac sync, cloud asset providers and a web companion (#212) build on one coherent model while keeping local.imageflowpackages inspectable, Git-friendly and MCP-compatible.