lattice-knowledge-sharing
Comprehensive guide to sharing your ~/.lattice knowledge base with collaborators using P2P file synchronization.
Use Case
Share your Lattice knowledge base (~/.lattice/docs/ markdown files and lattice.duckdb database) with collaborators without relying on centralized cloud services like Dropbox or Google Drive.
Key Requirements for Lattice
- Bidirectional sync - Both parties can add/edit documents
- Database safety - DuckDB file (
lattice.duckdb) needs special handling - Markdown-friendly - Small text files sync efficiently
- Privacy - No third-party access to knowledge base content
- Offline-first - Work independently, sync when connected
Recommended Solutions
1. Croc (Recommended for One-Time Sharing)
Best for: Quick, one-time file transfer with a simple share code
Croc is a command-line tool that makes sharing files as simple as sharing a code phrase. Perfect for sending research to a collaborator without setting up ongoing sync.
How Croc Works
┌─────────────┐ ┌─────────────┐ ┌─────────────┐│ Sender │◀──────▶│ Relay Server│◀──────▶│ Receiver │└─────────────┘ └─────────────┘ └─────────────┘ │ │ │ 1. Generate code (e.g., 7-actress-plural) │ │ 2. PAKE key exchange (password → key) │ │ 3. Attempt direct P2P connection │ │ 4. Fallback to relay if NAT blocks P2P │ │ 5. End-to-end encrypted transfer │ └─────────────────────────────────────────────┘Key features:
- Code phrase - Human-readable, one-time code (e.g.,
7-actress-plural-pilgrim) - End-to-end encrypted - Uses PAKE (Password Authenticated Key Exchange)
- NAT traversal - Works through firewalls via relay server
- Resume support - Interrupted transfers can be resumed
- Cross-platform - macOS, Linux, Windows, Android
Installation
# macOSbrew install croc
# Linux (Ubuntu/Debian)curl https://getcroc.schollz.com | bash
# Or download binary from https://github.com/schollz/croc/releasesSharing Lattice Research
Sender (you):
# Share a single topic directorycroc send ~/.lattice/docs/duckdb
# Output:# Sending 'duckdb' (5 files, 142 KB)# Code is: 7-actress-plural-pilgrim# On the other computer, run:# croc 7-actress-plural-pilgrimReceiver (collaborator):
# Receive the filescd ~/.lattice/docscroc 7-actress-plural-pilgrim
# Files are downloaded to current directory# Now sync to their local knowledge graphlattice syncSharing Multiple Topics
# Create a temporary archive of selected topicscd ~/.lattice/docstar -czf /tmp/research-share.tar.gz duckdb/ agents/ bun-nestjs/
# Share the archivecroc send /tmp/research-share.tar.gz
# Receiver extracts and syncscd ~/.lattice/docstar -xzf research-share.tar.gzlattice syncAdvanced: Self-Hosted Relay
For maximum privacy, run your own relay:
# On your server (needs ports 9009-9013)croc relay
# Sender uses your relaycroc --relay "yourserver.com:9009" send ~/.lattice/docs/duckdb
# Receiver uses same relaycroc --relay "yourserver.com:9009" 7-actress-plural-pilgrimPros
- ✅ Simplest UX - just share a code
- ✅ No account or setup required
- ✅ Works through NAT/firewalls
- ✅ End-to-end encrypted
- ✅ Resume interrupted transfers
Cons
- ❌ One-time transfer (not ongoing sync)
- ❌ Both parties must be online simultaneously
- ❌ Requires manual
lattice syncafter receiving
Recommendation: Best for sharing research with someone once. For ongoing collaboration, use Syncthing.
2. Syncthing (Recommended for Ongoing Sync)
Best for: Continuous, bidirectional P2P sync with conflict handling
Why Syncthing for Lattice
- Open source - Free, no vendor lock-in
- True P2P - Direct device-to-device sync, no central server
- Conflict versioning - Preserves both versions when conflicts occur
- Selective sync - Can sync only
docs/folder, exclude database if needed - Cross-platform - Works on macOS, Linux, Windows, Android
Setup for Lattice
# Install Syncthingbrew install syncthing # macOS# ORapt install syncthing # Ubuntu/Debian
# Start Syncthingsyncthing
# Access web UI at http://localhost:8384Configuration:
- Add remote device using Device ID exchange
- Create folder sync for
~/.lattice/docs/ - Enable versioning: “Simple File Versioning” or “Staggered File Versioning”
- Important: Consider
.stignoreto exclude database:
lattice.duckdblattice.duckdb.wal.sync-manifest.jsonDatabase Sync Strategy
Option A: Exclude database, sync markdown only
- Safest approach - each user maintains their own
lattice.duckdb - Run
lattice syncafter receiving new markdown files - Embeddings regenerated locally (requires Voyage API key)
Option B: Sync database with caution
- Only works if users never edit simultaneously
- Risk of database corruption if both write at once
- Better: Use LiteSync (see below) for proper database replication
Pros
- ✅ Simple setup and configuration
- ✅ Excellent conflict handling with versioning
- ✅ No ongoing costs or subscriptions
- ✅ Battle-tested and actively maintained
- ✅ Built-in file versioning prevents data loss
Cons
- ❌ Web UI less polished than commercial alternatives
- ❌ Requires both devices online simultaneously for sync (or relay server)
- ❌ No built-in database conflict resolution
Recommendation: Best choice for 90% of use cases. Exclude database, sync markdown only.
2. Resilio Sync
Best for: Users wanting polished UI and faster sync speeds
Why Resilio Sync for Lattice
- Fast - Uses BitTorrent protocol, faster than Syncthing in many cases
- Polished UI - More user-friendly than Syncthing
- Share links - Can share folders via link or QR code
- Selective sync - Fine-grained control over what syncs
- Encrypted - End-to-end encryption for shared folders
Setup for Lattice
# Download from https://www.resilio.com/individuals/# Install and launch
# Generate link or add device manually# Configure .syncignore for database filesSync Strategy: Same as Syncthing - recommend excluding database, syncing markdown only.
Pros
- ✅ Beautiful, intuitive interface
- ✅ Very fast sync performance
- ✅ Easy sharing via links
- ✅ Mobile apps available
Cons
- ❌ Proprietary (free for personal use, paid for advanced features)
- ❌ Free version limited to 10 folders
- ❌ No built-in versioning (uses OS filesystem features)
Recommendation: Good alternative if you prefer polished UI over open source.
3. Git + SSH (Developer-Friendly Approach)
Best for: Developers comfortable with Git workflows
Why Git for Lattice
- Version control - Full history of all changes
- Conflict resolution - Excellent merge tools
- Free hosting - GitHub/GitLab private repos (or self-hosted)
- Gitignore - Easy to exclude database files
- Familiar workflow - If you already use Git daily
Setup for Lattice
cd ~/.lattice/docs/
# Initialize Git repogit initgit add .git commit -m "Initial commit"
# Add remote (GitHub, GitLab, or self-hosted)git remote add origin git@github.com:username/lattice-kb.gitgit push -u origin main
# .gitignoreecho "lattice.duckdb" >> ../.gitignoreecho "lattice.duckdb.wal" >> ../.gitignoreecho ".sync-manifest.json" >> ../.gitignoreCollaborator workflow:
# Clone repogit clone git@github.com:username/lattice-kb.git ~/.lattice/docs/
# Pull updatescd ~/.lattice/docs/git pull
# Push changesgit add .git commit -m "Add new research on topic X"git pushPros
- ✅ Full version control and history
- ✅ Excellent conflict resolution tools
- ✅ Works with existing GitHub/GitLab accounts
- ✅ Can use SSH for secure, P2P-like direct sync
- ✅ Familiar to developers
Cons
- ❌ Manual sync (need to commit/push/pull)
- ❌ Learning curve for non-developers
- ❌ Binary files (database) not handled well
- ❌ Not real-time sync
Recommendation: Best for technical teams already using Git. Can combine with Git hooks for semi-automatic sync.
4. LiteSync (Database-Specific Solution)
Best for: When you need to sync the DuckDB database itself
Why LiteSync for Lattice
- SQLite replication - Designed specifically for SQLite-compatible databases
- CRDT-based - Automatic conflict resolution
- Real-time sync - Changes propagate immediately
- P2P capable - Can sync peer-to-peer without central server
DuckDB Compatibility
Challenge: LiteSync is designed for SQLite, but DuckDB can attach/read SQLite databases.
Possible approach:
- Export Lattice data to SQLite format
- Use LiteSync to sync SQLite database
- Attach SQLite to DuckDB for queries
Reality: This adds complexity. Better to sync markdown only and regenerate embeddings.
Pros
- ✅ Proper database conflict resolution
- ✅ Real-time synchronization
- ✅ Designed for database files
Cons
- ❌ Not natively compatible with DuckDB
- ❌ Requires conversion layer
- ❌ Additional complexity
- ❌ Commercial product (paid)
Recommendation: Only consider if you absolutely must sync the database. Otherwise, sync markdown only.
5. CRDT-Based Solutions (Future-Proof Approach)
Best for: Building true local-first collaborative features
CRDT Libraries
Automerge:
- JSON-based CRDT with Rust core
- Strong consistency guarantees
- Sync protocol included
- “PostgreSQL for local-first apps”
Yjs:
- Optimized for text editing
- Memory-efficient binary encoding
- Works with WebRTC for P2P sync
- Popular in collaborative editors
Application to Lattice
CRDTs excel at collaborative editing but require application-level integration. For Lattice, this would mean:
Potential architecture:
Markdown files → CRDT documents → Automerge/Yjs sync → Peers ↓ DuckDB sync'd separatelyCurrent state: Would require significant Lattice architecture changes.
Future possibility: Lattice could add CRDT support for true Google Docs-style collaboration on knowledge base.
Pros
- ✅ True offline-first collaboration
- ✅ Automatic conflict resolution
- ✅ No central server required
- ✅ Fine-grained sync (per-document, not per-file)
Cons
- ❌ Requires application integration (not just file sync)
- ❌ Complex to implement
- ❌ Overhead for metadata storage
- ❌ Not a drop-in solution
Recommendation: Not practical for current Lattice, but interesting future direction if real-time collaboration becomes a goal.
Comparison Matrix
| Solution | Setup Difficulty | Transfer Type | Best Use Case | Cost |
|---|---|---|---|---|
| Croc | Very Easy | One-time | Share research once with a code | Free |
| Syncthing | Easy | Ongoing sync | Continuous collaboration | Free |
| Resilio Sync | Very Easy | Ongoing sync | UI-focused users | Freemium |
| Git + SSH | Medium | Manual push/pull | Developer teams | Free |
| LiteSync | Hard | Database sync | Full database replication | Paid |
| CRDTs | Very Hard | Real-time | Future collaborative editing | Free (libs) |
Recommended Setup for Lattice
For Individual Collaboration (2-3 people)
Option 1: Syncthing (Recommended)
# 1. Install Syncthingbrew install syncthing
# 2. Start and configuresyncthing
# 3. Share ~/.lattice/docs/ folder# 4. Add .stignore to exclude database# 5. Each person runs `lattice sync` after changesWhy: Simple, reliable, free, works offline.
For Team/Organization
Option 2: Git + Private Repo
# 1. Create private GitHub/GitLab repo# 2. Add ~/.lattice/docs/ to Git# 3. Team clones and syncs via Git# 4. Use pre-commit hooks to run `lattice sync`Why: Audit trail, familiar workflow, scales well.
For Advanced Users
Option 3: Hybrid Approach
- Markdown: Syncthing or Git for file sync
- Database: Each user maintains own, runs
lattice sync - Embeddings: Generated locally (requires API key for each user)
Why: Best of both worlds - real-time file sync + local database ownership.
Database Considerations
Why NOT Sync DuckDB Directly
- Corruption risk - Two users writing simultaneously corrupts database
- No conflict resolution - DuckDB is single-writer by design
- Large file size - Database file is larger than markdown files
- Lock files -
.walfiles complicate sync
Recommended Database Strategy
Each user maintains their own database:
- Sync markdown files only (using Syncthing, Resilio, or Git)
- After receiving new/updated markdown:
Terminal window lattice sync - Lattice regenerates embeddings and updates local database
- Result: Same knowledge base content, independent databases
Cost: Each user needs their own Voyage API key for embeddings.
Alternative (if embeddings are expensive):
Export/import embeddings separately:
# User A exportslattice export-embeddings > embeddings.json
# User B importslattice import-embeddings < embeddings.json(Note: These commands don’t exist yet, but could be added)
Security Considerations
End-to-End Encryption
| Solution | Encryption | Trust Model |
|---|---|---|
| Syncthing | TLS | Device-to-device trust |
| Resilio | Optional | Device-to-device or link-based |
| Git + SSH | SSH | SSH key authentication |
| LiteSync | TLS | Configured per deployment |
Access Control
Syncthing: Device-level - only explicitly added devices sync Resilio: Link-based or device-based Git: Repository permissions (GitHub/GitLab)
Data Leakage Prevention
- ✅ Never commit API keys to Git (use
.envin.gitignore) - ✅ Exclude sensitive documents from sync if needed
- ✅ Use encrypted file systems for local storage
- ✅ Review
.stignore/.gitignorecarefully
Conflict Resolution
Markdown File Conflicts
Syncthing approach:
- Creates
.sync-conflictversions - Both files preserved
- User manually resolves
Git approach:
- Merge conflicts with
<<<<<<<markers - Use
git mergetoolfor resolution - Commit resolved version
Recommendation: Use descriptive commit messages / sync labels to help resolve conflicts.
Database Conflicts
Best practice: Avoid by not syncing database directly.
If you must sync database:
- Coordinate edits (avoid simultaneous work)
- Use “last write wins” strategy
- Keep backups
- Consider LiteSync for proper CRDT-based resolution
Future Improvements for Lattice
Potential Features
- Export/import embeddings - Share computed embeddings without regenerating
- Conflict-free entity merge - CRDT-based entity synchronization
- Built-in sync command -
lattice sync-remote <peer>using libp2p - Collaborative editing - Real-time multi-user document editing
Integration Ideas
- Syncthing plugin - Automatic
lattice syncafter file changes - Git hooks - Pre-commit: validate markdown, Post-pull: run sync
- CRDT documents - Replace markdown files with Automerge documents
Quick Start Guide
30-Second Share (Croc)
Sender:
brew install croc # One-time installcroc send ~/.lattice/docs/duckdb # Share a topic# → Code is: 7-actress-plural-pilgrimReceiver:
brew install croc # One-time installcd ~/.lattice/docscroc 7-actress-plural-pilgrim # Receive fileslattice sync # Add to knowledge graph1-Minute Setup (Syncthing)
# Installbrew install syncthing
# Startsyncthing &
# Open UIopen http://localhost:8384
# Add folder: ~/.lattice/docs/# Share with collaborator's Device ID# Create .stignore with:# lattice.duckdb# *.walFirst Sync
# After receiving files from collaboratorcd ~/.latticelattice sync # Regenerate your local database
# Make changesvim docs/my-topic/new-research.md
# Syncthing auto-syncs in background# Collaborator receives file and runs `lattice sync`Troubleshooting
Syncthing not syncing
- Check both devices are online
- Verify Device IDs are correct
- Check
.stignoreisn’t blocking files - Review sync status in web UI
Database corruption
- Stop all Lattice processes
- Restore from backup (Syncthing versioning)
- Rebuild:
rm lattice.duckdb && lattice sync
Merge conflicts in markdown
Git approach:
git status # See conflicted files# Edit files, remove <<<<<<< markersgit add .git commit -m "Resolved merge conflict"Syncthing approach:
# Find .sync-conflict filesfind ~/.lattice -name "*.sync-conflict*"# Manually merge changes# Delete conflict files when doneSources
- Croc - GitHub
- Syncthing Documentation
- Resilio Sync vs Syncthing Comparison (2025)
- Syncthing or Resilio Sync - Self-Hosted File Syncing
- 5 Self-Hosted Markdown Editors That Sync Without the Cloud
- HedgeDoc - Collaborative Markdown Editor
- LiteSync - SQLite Replication
- Automerge - CRDT Library
- Yjs - Shared Data Types
- Using CRDTs + Sync as a Database
- CRDT Dictionary - Field Guide
- DuckDB Concurrency Documentation
Last Updated: 2025-12-26 Recommended: Syncthing for markdown sync + local database regeneration