Skip to content

feat: p2p sync#15

Open
Thopiax wants to merge 5 commits intomainfrom
claude/session-011CUZKH6fRvegs3kQKkXWy1
Open

feat: p2p sync#15
Thopiax wants to merge 5 commits intomainfrom
claude/session-011CUZKH6fRvegs3kQKkXWy1

Conversation

@Thopiax
Copy link
Copy Markdown
Owner

@Thopiax Thopiax commented Oct 28, 2025

Add "garden pattern" synchronization where a primary device (desktop) acts as a "garden" hub and portals (laptop/phone) sync via WebRTC P2P when on same network.

Key Features:

  • Yjs CRDT-based sync for conflict-free replication
  • WebRTC P2P connection with BroadcastChannel fallback
  • Legend State <-> Yjs bidirectional sync adapter
  • Zero-server architecture (uses public signaling servers)
  • Optional encryption with shared password
  • Real-time connection status and peer count indicators

Architecture:

  • YjsGardenSync adapter bridges Legend State observables with Yjs shared types
  • Automatic lifecycle management based on settings
  • All 7 entity collections synced: moments, areas, habits, cycles, phase configs, crystallized routines, and metric logs

UI Integration:

  • Garden Sync settings section in SettingsDrawer
  • Enable/disable toggle with device role selector (Garden/Portal)
  • Room name generator and input (6-char code: ABC123)
  • Optional password for encrypted sync
  • Connection status indicator with peer count
  • Debug mode toggle for development

Commands:

  • :garden - Open garden sync settings via Vim command mode
  • Cmd+K -> "Garden Sync Settings" in command palette

Technical Details:

  • Dependencies: yjs@13.6.27, y-webrtc@10.3.0, y-protocols@1.0.6
  • Sync managed in StoreInitializer with useEffect lifecycle
  • Settings persisted to localStorage via Legend State
  • Status and peer count exposed as observables for UI reactivity

🤖 Generated with Claude Code

Description

Brief description of the changes in this PR.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

Related Issues

Closes #(issue number)

Testing

  • Tests pass locally (pnpm test)
  • Lint passes (pnpm lint)
  • Tested manually in browser

Screenshots (if applicable)

Add screenshots or GIFs demonstrating the changes.

Checklist

  • Code follows the project's code style (Biome)
  • Self-review of code completed
  • Comments added for complex logic
  • Documentation updated (if needed)
  • No new warnings introduced
  • Tests added/updated (if applicable)

Philosophy Alignment

How does this change align with Zenborg's principles?

  • Presence over performance
  • Keyboard-first interaction
  • Local-first data
  • Mindful tech

Add "garden pattern" synchronization where a primary device (desktop) acts as a
"garden" hub and portals (laptop/phone) sync via WebRTC P2P when on same network.

Key Features:
- Yjs CRDT-based sync for conflict-free replication
- WebRTC P2P connection with BroadcastChannel fallback
- Legend State <-> Yjs bidirectional sync adapter
- Zero-server architecture (uses public signaling servers)
- Optional encryption with shared password
- Real-time connection status and peer count indicators

Architecture:
- YjsGardenSync adapter bridges Legend State observables with Yjs shared types
- Automatic lifecycle management based on settings
- All 7 entity collections synced: moments, areas, habits, cycles,
  phase configs, crystallized routines, and metric logs

UI Integration:
- Garden Sync settings section in SettingsDrawer
- Enable/disable toggle with device role selector (Garden/Portal)
- Room name generator and input (6-char code: ABC123)
- Optional password for encrypted sync
- Connection status indicator with peer count
- Debug mode toggle for development

Commands:
- :garden - Open garden sync settings via Vim command mode
- Cmd+K -> "Garden Sync Settings" in command palette

Technical Details:
- Dependencies: yjs@13.6.27, y-webrtc@10.3.0, y-protocols@1.0.6
- Sync managed in StoreInitializer with useEffect lifecycle
- Settings persisted to localStorage via Legend State
- Status and peer count exposed as observables for UI reactivity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Oct 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
zenborg Ready Ready Preview Comment Oct 28, 2025 10:01am

WebrtcProvider expects password to be string | undefined, not string | null.
Convert null to undefined using nullish coalescing operator.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Change generic type to any for Legend State observable compatibility
- Fix WebRTC provider event types (status, peers, synced)
- Use object spread instead of assign for observable updates
- Fix peer counting logic

All production code TypeScript errors resolved. Test file errors remain but
are unrelated to garden sync implementation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add dual-mode support to Garden Sync:
- WebRTC mode: P2P sync for web browsers (existing)
- WebSocket mode: Local server sync for Tauri desktop (new)

Changes:
- Auto-detect environment (Tauri vs Web) and choose appropriate mode
- Add y-websocket provider for local server connections
- Create tauri-utils for environment detection
- Update YjsGardenSync to support both WebRTC and WebSocket providers
- Different event handling for each provider type
- Show sync mode in settings UI (WebSocket for Tauri, WebRTC for Web)

WebSocket mode:
- Connects to ws://localhost:8765 by default
- Desktop runs as Garden (server)
- Phone/laptop connects as Portal (client)
- Reliable local network sync without NAT/firewall issues

Next steps for Tauri branch:
- Implement Rust WebSocket server using yrs crate
- Run server on port 8765
- Handle Yjs sync protocol
- Optional: Add mDNS service advertisement

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add detailed guide for implementing WebSocket server in Tauri branch:
- Rust dependencies and setup
- Yjs server implementation with yrs crate
- WebSocket connection handling
- Yjs sync protocol explanation
- mDNS service advertisement (optional)
- Testing instructions
- Simplified Node.js alternative
- Architecture diagrams

This guide explains what needs to be built on the Tauri side to enable
reliable local-network Garden Sync between desktop and mobile devices.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants