Skip to content

Sync the vault both ways with NOTE - #1

Merged
kualta merged 16 commits into
mainfrom
sync-plugin
Nov 9, 2026
Merged

kualta merged 16 commits into
mainfrom
sync-plugin

Conversation

@kualta

@kualta kualta commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

FLOW NOTE Sync (plugin id flow-note) links an Obsidian vault once through note.flow.talk/link, then syncs its notes and attachments both ways with the person's end-to-end encrypted NOTE notepad, through the device client in @flow-industries/seal.

  • Linking (src/controller.ts, src/obsidian/modals.ts, src/account.ts):
    • It shows the user code and the 12-digit device code, and opens the link page only on https://note.flow.talk.
    • It names the linked account by its DID, plus the handle when that checks out both ways (HTTPS, or DNS asked over DNS-over-HTTPS). The vouching domain is shown apart, so a lookalike handle reads as its real domain.
    • Nothing syncs in either direction until the person confirms the account.
    • A vault that is still linked can't be linked again. A stopped vault offers Retry and Unlink, never Link, and Unlink shows whenever anything of a link is stored.
  • Custody (src/custody.ts, src/obsidian/vault.ts): the seed, tokens, pin and confirmed account live only in Obsidian's secret storage, under a per-vault namespace. The plugin writes no data.json.
  • One transport per store: SyncController owns the only open device vault. A Web Lock keeps a second window out, and a closed device keeps the lock until its stop() settles (running work, a token refresh included, finishes first), so a reopen never races a refresh. An open still in flight when the vault closes keeps the lock too, until it settles and stops. Unlink and removal delete the device's databases only after that.
  • Sync (src/plan.ts, src/engine.ts):
    • A three-way plan over notes and attachments (up to 32 MB), against an index kept per linked device.
    • Every write to NOTE is compare-and-swap, so an edit that reaches NOTE mid-round is never replaced or trashed. Local writes are conditional, so typing during a sync is never overwritten.
    • Conflicts: NOTE's version keeps the path, and the local version becomes a copy beside it, named the way NOTE names its own.
    • Renames carry both ways, including swaps and rotations, which converge through a temporary name only when they form a cycle. A parked rename is saved at once, so a quit mid-cycle still finishes it.
    • Links: NOTE's link repair follows what Obsidian did.
      • A rename Obsidian saw, with "Automatically update internal links" on (recorded per entry when the rename event arrives): moves pass repairLinks: (path) => !path.endsWith(".md"). NOTE then repairs only notes Obsidian doesn't index, such as .mdx, since a second repair of Obsidian's own edits would re-target links in chains and swaps.
      • Any other rename (made outside Obsidian, while it was closed, or with that setting off): NOTE repairs the links.
      • Known limits, in the README: with the setting off, Obsidian asks before updating links, so a fast chain of renames after "Update" can still re-target links; settings suggest turning the setting on. A plugin that moves files without updating links, while the setting is on, leaves .md links as they are.
    • Deletions: an edit beats a deletion. Mass deletions (over fifty, or over ten that are also over a tenth of the vault) wait for confirmation.
    • Excluded: .obsidian/, hidden files, scripts other plugins run (.js, .mjs, .cjs, .jsx, .ts, .mts, .cts, .tsx, .py, .sh), names NOTE can't store, case variants and attachments over 32 MB.
  • Readiness: rounds start only once a sync() since the vault opened reports read: true, meaning it read and applied the notepad from the PDS. While it hasn't, the plugin makes no syncs of its own: it follows the device client's schedule and backoff, and asks once more after one of those syncs publishes a status it reaches only after a read (synced, or an upload refused for quota or size). A new link never plans against a notepad it hasn't read.
  • Unlink, removal and every stop:
    • Unlink and removal (under Access, or a revocation at Flow ID) wipe the keys, every sync index this vault holds, and the device's local database.
    • A stopped engine never writes its index again.
    • Each stop and removal shows a persistent notice, once per reason, since mobile has no status bar.
  • Note content never runs. Nothing is evaluated, and nothing is written into Obsidian's config folder.
  • Repo:
    • Obsidian's sample-plugin layout with Bun, TypeScript and Biome, plus eslint-plugin-obsidianmd (bun run lint:obsidian), the rules Obsidian's review runs.
    • CI and the release workflow pin their actions by commit SHA.
    • The release workflow checks the tag, builds, attests, and drafts a release.
    • MIT licensed.

Blocked on

package.json depends on @flow-industries/seal through a local link: while seal is unpublished. CI's bun install --frozen-lockfile fails until it moves to the published version.

Testing

All of these ran locally with Bun 1.4.2, against a clean local build of seal's latest commit.

  • Checks: bun run lint and bun run typecheck are clean. bun run lint:obsidian lints the whole repo, scripts and tests included, with no errors (also under the plugin's stock recommended config). 13 warnings stay by design: APIs that minAppVersion 1.11.5 still needs (display, setWarning), and timers in modules that also run under bun test.
  • bun test: 94 pass across 9 files.
    • Through the real device client: a third note's links survive a single rename, a chain and a swap with Obsidian's link updates on. NOTE repairs them after a rename Obsidian didn't see, or made with link updates off, and repairs an .mdx note's links after a rename Obsidian made.
    • The lock outlives an open in flight.
    • An unread vault syncs once, then waits on the device's own schedule, and starts once a sync that read it publishes a quota refusal.
    • A quit right after a swap parks one note still ends at the swapped names.
    • A link whose device key went missing stops with Unlink as the way out.
    • Handles verify over DNS-over-HTTPS, with exactly one did= record.
    • Regression tests for linking again over a stopped link, and after the secret store lost the link. Both now keep every edit and trash nothing.
    • An unlink during a round's write leaves no index behind.
    • Every stop and removal shows a notice, and a reopen waits for a token refresh in flight.
    • A rate-limited status doesn't count as a read, and an emptied note deleted in NOTE is deleted here.
    • Two-way and three-way swaps converge, and chains of renames never use a temporary name.
    • The mass-deletion ceiling, DNS handle verification, the vouching domain, and per-device index naming.
    • Each of these fails on the previous head.
  • End to end: tests/e2e.test.ts drives the real device client on @flow-industries/seal/testing, with two vaults linked as two devices. It covers linking and confirmation, two-way sync of notes, MDX and a PNG, a passkey-signed note from NOTE, renames, conflicts, revocation, removal under Access mid-sync, a NOTE edit landing mid-round, and unlink.
  • Build: bun run build gives 1034 KiB. bun run smoke loads main.js requiring only obsidian and @lezer/*.
  • Real Obsidian 1.15.0 (macOS), before the rename: it loads, links against production Flow ID up to the passkey step, cancels, and writes no data.json.
  • Not run yet: a full passkey approval, mobile, and a restart of a linked vault.

Simplify

Ran the simplify pass on each change. It finished a half-done compare-and-swap adoption, ordered each item's own write before its conflict copy, and shared one stale-write predicate.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T17:14:43.921738Z d2b0d9a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2b0d9a2e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread package.json Outdated
"fake-indexeddb": "6.2.4"
},
"dependencies": {
"@flow-industries/seal": "link:@flow-industries/seal"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace the local-only seal dependency

The link: specifier depends on a developer-local package link rather than a registry or repository artifact. Both checked workflows perform a fresh checkout followed directly by bun install --frozen-lockfile, with no step that registers this link, so clean CI and release runners cannot install @flow-industries/seal and stop before tests or builds. Pin a source that fresh public checkouts can resolve.

AGENTS.md reference: AGENTS.md:L3-L3

Useful? React with 👍 / 👎.

Comment thread src/engine.ts Outdated
this.remoteChanged();
hash = local?.hash ?? "";
} else if (remote && remote.path !== path) {
await vault.rename(id, path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stage rename cycles through a temporary path

When two existing notes exchange paths—for example A.md → tmp.md, B.md → A.md, then tmp.md → B.md—the planner emits two direct renames, but each destination remains occupied by the other note. The remote vault rejects both operations as path collisions, and every retry produces the same plan, so the swap can never sync. Rename cycles need to be detected and staged through a free temporary path.

Useful? React with 👍 / 👎.

@kualta
kualta merged commit 7d1ec6d into main Nov 9, 2026
1 check passed
@kualta
kualta deleted the sync-plugin branch November 9, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant