Cloud Sync Module logo

Cloud Sync Module

Organization
LedgerHQ
cloud-sync-module

Write, review or debug a `cloudSyncModule.ts` — a `CloudSyncDataManager` that syncs one slice of user data through Ledger Sync (Cloud Sync). Covers the contract, its invariants, the mandatory contract test, the wiring checklist and the data-loss traps. Use for any work on `**/cloudSyncModule.ts`, `createAggregator`, or `@shared/cloud-sync-module`.

Overview

PublisherLedgerHQ
Repositoryledger-live
Skill namecloud-sync-module
Stars
622
Forks
491
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by LedgerHQ on GitHub. Read the source before you install it.

Installation

Install the Cloud Sync Module AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/LedgerHQ/ledger-live/tree/develop/.agents/skills/cloud-sync-module
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/LedgerHQ/ledger-live.git /tmp/ledger-live
mkdir -p .claude/skills
cp -r /tmp/ledger-live/.agents/skills/cloud-sync-module .claude/skills/cloud-sync-module
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Cloud Sync Module in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Cloud Sync Module on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Cloud Sync Module is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Authoring a cloudSyncModule.ts

A 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).

The three hooks

HookSync?RunsMust return
diffLocalToDistant(local, latest)syncevery loop tick (~10s) before push{ hasChanges, nextState } — what to push
resolveIncrementalUpdate(local, latest, incoming)asyncon pull and every tick with incoming === latest{ hasChanges: false } or { hasChanges: true, update }
applyUpdate(local, update)synconly when the above reported changesthe 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.

Invariants — break one and the loop misbehaves

  1. 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.
  2. diffLocalToDistant(emptyLocal, null) → hasChanges: false, or every user who never touched the feature creates Cloud Sync data on first launch.
  3. Stability: re-diffing against your own nextState yields hasChanges: false. No Date.now(), no random ids, no unstable key order.
  4. Round-trip: the comparator must ignore any field applyUpdate cannot reproduce exactly (recent-addresses stores lastUsed but never compares it — comparing it would loop forever).
  5. Convergence: after applyUpdate from an incoming state, diffing against that state reports no changes.
  6. Purity: LocalState comes from Redux and is Immer-frozen. Never mutate — return new objects.

Risks to evaluate before writing a line

  • Wiping every instance's data. Persist LocalState with the same lifetime as walletSyncState.version (exportWalletState / importWalletState, both apps). Otherwise a restart finds the version "up-to-date", never pulls, and diffLocalToDistant(empty, latest) pushes an empty state that deletes the data everywhere.
  • A too-strict schema kills sync, or overwrites data. CloudSyncSDK parses the whole aggregate on every pull and push, so one module rejecting another version's payload stops sync for accounts, names, everything. On the persisted path parseDistantState (walletSyncComposition.ts) safeParses and returns null instead — which the loop reads as "no distant state" and pushes over. Stay permissive: optional fields, z.unknown() + safeParse-and-filter for lists, never .strict().
  • A .transform()'s output is discarded in production. Both call sites above do parse — the transform executes — then pass the raw JSON on, to preserve unknown fields. Hooks therefore get un-normalised data typed as the transform's output, a lie TypeScript will not catch; normalise in the hooks instead. The contract suite won't catch it either: it only ever replays states your own diffLocalToDistant produced (the idempotence case runs one back through schema.parse()), never the legacy payload an older version actually wrote.
  • No migrations, ever. The wire format is permanent and shared across app versions: add optional fields only, never rename, repurpose or require a key. Rebuilding nextState from scratch (account-name, recent-addresses) is safe only while your subtree is a total function of LocalState — once it can carry a field you don't own, apply your diff on top of latest as accounts does, or you silently delete the other version's data. recent-addresses already violates this: it drops the ensName its own schema declares.
  • Payload and privacy. One blob holds every module: store the minimum needed to restore the state (descriptors, ids), nothing refetchable, no raw device/user ids (client-ids).
  • Async blocks the loop. resolveIncrementalUpdate runs inside the pull's atomic lock. Network work must be batched and recoverable — see accounts' nonImportedAccountInfos + backoff queue.
  • Injected dependencies? The interface has no ctx: export a bindCtx(ctx) factory, as accounts does.

Tests

describeCloudSyncModuleContract is mandatory, but a floor rather than a proof. It covers invariants 1-3 and 5, JSON serialisability, a 1MB ceiling, and a 5ms average over 100 calls — for diffLocalToDistant and applyUpdate only. It skips invariant 4 and resolveIncrementalUpdate's cost, and wraps its convergence and applyUpdate cases in if (result.hasChanges), so a module that always answers hasChanges: false passes them silently.

ts
// src/__tests__/cloudSyncModule.test.ts
import { describeCloudSyncModuleContract } from "@shared/cloud-sync-module/moduleRequirements";

describeCloudSyncModuleContract("<name>SyncModule contract", <name>SyncModule, {
  emptyLocalState,
  nonEmptyLocalState,
  matchingDistantState, // optional — always provide it, it unlocks 2 extra checks
});

Then add module-specific cases:

TargetCover
schemavalid payload · garbage/unknown entries tolerated, not thrown · fields written by a future version survive
diffLocalToDistantnull latest · exact match · added · modified · removed · fields it must ignore (invariant 4)
resolveIncrementalUpdatenull incoming · same reference · same content, different reference · real change · the raw payload rather than schema.parse()'s output (the only way to catch the transform trap)
applyUpdateexpected state · does not mutate localData · is reached at all — assert hasChanges: true explicitly instead of trusting the contract suite

Run pnpm --filter @domain/entity-<name> test; copy a sibling entity package's jest config (testEnvironment: "node", roots: ["<rootDir>/src"]).

Wiring checklist

Registration is where the module becomes real — and where the persistence risk above lives.

  1. walletSyncComposition.ts — add the key to createAggregator({...}) and to the hand-maintained walletSyncSchema (they are duplicated; miss the second and your key silently vanishes from WalletSyncDistantState).
  2. Reducers — LWD wallet.core.ts, LWM wallet.ts: reducer, ExportedWalletState, exportWalletState, walletStateExportShouldDiffer, importWalletState.
  3. useWatchWalletSync.ts — LWD, LWM: add the key to localStateSelector and dispatch it in save.
  4. AppAccountsSync.tsx — a third full registration site (its own createAggregator, AggLocalState, localStateSelector). It is also the only place to verify by hand, with several web-tools tabs as separate instances.
  5. Changeset (create-changeset) and a line in scenarios.md.

Frequently asked questions

What does the Cloud Sync Module AI skill do?

Write, review or debug a `cloudSyncModule.ts` — a `CloudSyncDataManager` that syncs one slice of user data through Ledger Sync (Cloud Sync). Covers the contract, its invariants, the mandatory contract test, the wiring checklist and the data-loss traps. Use for any work on `**/cloudSyncModule.ts`, `createAggregator`, or `@shared/cloud-sync-module`.

Why use Cloud Sync Module on TypingMind?

Because you install it once and use it with any model. Cloud Sync Module is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Cloud Sync Module in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/LedgerHQ/ledger-live/tree/develop/.agents/skills/cloud-sync-module. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Cloud Sync Module?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Cloud Sync Module?

As many as you like. As long as a model supports skills, you can use Cloud Sync Module with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Cloud Sync Module AI skill free?

Yes. It is published on GitHub by LedgerHQ under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇