Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Authors, reviews and debugs cloudSyncModule.ts files that sync one user-data slice through Ledger Sync, covering contract and invariants.
28% 92%+64 ptsof test cases passed
Passed 23 of 25 test cases with the skill, and 7 of 25 without it.
3 of 3 safety checks passed
13 agent runs
cloudSyncModule.tsA module reconciles LocalState (what the app holds, from Redux) with DistantState (what is
stored encrypted in Cloud Sync). createAggregator composes every module into one blob shared by all
of the user's instances (LWD, LWM, web-tools).
Concepts: 05-wallet-sync-data-manager,
then 06-watch-loop for when each hook fires. Steps and a
video: cookbook. Testing
layers: test-strategy. Contract:
@shared/cloud-sync-module. Copy
account-name (simplest);
accounts for async + injected ctx;
recent-addresses for the
tolerant-list schema only — its .transform() use is a known bug (see below).
| Hook | Sync? | Runs | Must return |
|---|---|---|---|
diffLocalToDistant(local, latest) | sync | every loop tick (~10s) before push | { hasChanges, nextState } — what to push |
resolveIncrementalUpdate(local, latest, incoming) | async | on pull and every tick with incoming === latest | { hasChanges: false } or { hasChanges: true, update } |
applyUpdate(local, update) | sync | only when the above reported changes | the new LocalState (pure, no mutation) |
Live under domain/entity/<name>/src/cloudSyncModule.ts beside schema.ts + slice.ts (see
domain/entity/README.md). Type it
CloudSyncDataManager<LocalState, Update, typeof schema>, with hasChanges: false as const so the
union narrows. A 4th generic DistantState defaults to z.infer<Schema> — pass the raw wire type
explicitly if your schema transforms, since that is what the hooks actually receive.
resolveIncrementalUpdate short-circuits on incoming == null, on incoming === latest, and on
incoming being content-equal to local. The reference check alone only covers
makeLocalIncrementalUpdate, which passes one object as both args every tick; every pull hands you
a freshly decrypted one
(incrementalUpdates.ts,
makeSaveNewUpdate). Without the content check, an unchanged pull dispatches → re-renders → pushes,
forever.diffLocalToDistant(emptyLocal, null) → hasChanges: false, or every user who never touchedNext to this one in the catalogue, plus more from the same author.