Skip to content

Commit 0db3980

Browse files
committed
fix: Add WASM embedding, shared database location, and CLI/desktop parity
## WASM Embedding (v0.4.1) - Embed sql-wasm.wasm as base64 for standalone distribution - Extract to temp file at runtime (/tmp/forest-sql-wasm-<pid>.wasm) - Fixes ENOENT errors in distributed binaries - Fallback to development path when running from source ## Shared Database Location (v0.4.2) - CLI and desktop now use same database: ~/Library/Application Support/com.ettio.forest.desktop/ - Platform-specific paths (macOS/Linux/Windows) - Override with FOREST_DB_PATH environment variable - Ensures seamless integration between CLI and GUI ## Embedding Parity (v0.4.3) - CLI now uses same fastembed engine as desktop app - forest-embed Rust helper bundled alongside CLI - Both produce identical 384-dim embeddings (all-MiniLM-L6-v2) - True feature parity between CLI and desktop ## Other Changes - Updated .gitignore to exclude large binaries and build artifacts - Updated documentation with all fixes - Version bump to 0.4.3
1 parent 714dc99 commit 0db3980

18 files changed

Lines changed: 679 additions & 59 deletions

.claude/settings.local.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
"Bash(cargo build:*)",
1313
"WebFetch(domain:v2.tauri.app)",
1414
"WebFetch(domain:edwardtufte.github.io)",
15-
"WebFetch(domain:docs.rs)"
15+
"WebFetch(domain:docs.rs)",
16+
"Bash(bun install)",
17+
"Bash(bun run build:*)",
18+
"WebFetch(domain:docs.brew.sh)"
1619
],
1720
"deny": [],
1821
"ask": []
19-
}
22+
},
23+
"enabledMcpjsonServers": [
24+
"tauri-mcp"
25+
]
2026
}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Thumbs.db
3939
forest-desktop/src-tauri/target/
4040
forest-desktop/src-tauri/binaries/*.dmg
4141
forest-desktop/src-tauri/binaries/*.app
42+
forest-desktop/src-tauri/binaries/*-aarch64-apple-darwin
43+
forest-desktop/src-tauri/binaries/*-x86_64-apple-darwin
44+
forest-desktop/src-tauri/binaries/*-x86_64-pc-windows-msvc.exe
45+
forest-desktop/src-tauri/binaries/*-x86_64-unknown-linux-gnu
4246

4347
# Bun build cache
4448
.*.bun-build
@@ -49,3 +53,10 @@ forest-desktop/dist/
4953
# MCP socket files
5054
*.sock
5155
.mcp.json
56+
57+
# Embedding model cache
58+
.fastembed_cache/
59+
60+
# Local Claude settings
61+
.claude/settings.local.json
62+
forest-desktop/.claude/settings.local.json

CLAUDE.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
Forest is a graph-native knowledge base CLI that captures unstructured ideas and automatically links them using a hybrid scoring algorithm combining semantic embeddings and lexical similarity. All data is stored in a single SQLite database (`forest.db`).
88

9+
**Database Location (as of v0.4.2):**
10+
- **macOS**: `~/Library/Application Support/com.ettio.forest.desktop/forest.db`
11+
- **Linux**: `~/.local/share/com.ettio.forest.desktop/forest.db`
12+
- **Windows**: `%APPDATA%\com.ettio.forest.desktop\forest.db`
13+
- **Override**: Set `FOREST_DB_PATH` environment variable to use a custom location
14+
915
## Agent-First TLDR Standard
1016

1117
Forest implements the **TLDR Standard (v0.1)** for agent ingestion - a minimal, parseable command metadata format designed for AI agents.
@@ -382,7 +388,7 @@ Uses **sql.js** (SQLite compiled to WASM) with in-memory database persisted to d
382388

383389
**Key pattern**: Database is lazily initialized on first access. All mutations set `dirty = true` and persist to disk.
384390

385-
Database path controlled by `FOREST_DB_PATH` env var (default: `forest.db` in cwd).
391+
Database path controlled by `FOREST_DB_PATH` env var (default: app data directory, see above).
386392

387393
**Database Schema:**
388394
```sql
@@ -509,14 +515,24 @@ Then applies a 0.9× penalty if both `tagOverlap` and `titleSimilarity` are zero
509515

510516
**Token downweighting**: Generic technical terms (flow, stream, pipe, branch, terminal) are weighted at 0.4× in token similarity to reduce over-connection of unrelated domains.
511517

512-
### Embeddings (src/lib/embeddings.ts)
518+
### Embeddings
519+
520+
**Desktop App (Rust):** Uses `fastembed` crate with `all-MiniLM-L6-v2` (384-dim) - native, fast, bundled
513521

514-
Three providers via `FOREST_EMBED_PROVIDER`:
515-
1. **local** (default): Uses `@xenova/transformers` with model `Xenova/all-MiniLM-L6-v2` (384-dim)
522+
**CLI (TypeScript):** Three providers via `FOREST_EMBED_PROVIDER`:
523+
1. **local** (default): Uses `forest-embed` Rust helper (same fastembed engine as desktop app!)
524+
- Ensures CLI and desktop app produce identical embeddings
525+
- Binary located next to CLI executable
526+
- Falls back to mock if binary not found
516527
2. **openai**: Calls OpenAI embeddings API (requires `OPENAI_API_KEY`)
517528
3. **mock**: Deterministic hash-based vectors for offline testing
518529
4. **none**: Disables embeddings (pure lexical scoring)
519530

531+
**Architecture (v0.4.3):**
532+
- Desktop app: Direct fastembed integration
533+
- CLI: Shells out to `forest-embed` helper binary
534+
- Both use identical model → identical search results
535+
520536
Embeddings are computed during capture/edit and stored as JSON arrays in the `embedding` column.
521537

522538
### Text Processing (src/lib/text.ts)
@@ -568,7 +584,7 @@ FOREST_EMBED_PROVIDER=openai OPENAI_API_KEY=... forest capture --stdin < test.tx
568584
- `::` - Dual-stack mode, listens on both IPv4 and IPv6
569585
- `0.0.0.0` - IPv4 only
570586
- `localhost` - Localhost only (may prefer IPv4 or IPv6 depending on OS)
571-
- `FOREST_DB_PATH` - Database file path (default: `forest.db` in cwd)
587+
- `FOREST_DB_PATH` - Database file path (default: see Database Location above)
572588
- `FOREST_EMBED_PROVIDER` - Embedding provider (default: `local`)
573589

574590
**Network connectivity:**

forest-desktop/CLI-INTEGRATION.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Forest.app/
2424
The CLI is compiled into a standalone executable using `bun build --compile`:
2525

2626
```bash
27+
# First, embed sql-wasm.wasm as base64 for standalone distribution
28+
bun run scripts/embed-wasm.ts
29+
30+
# Then compile to standalone binary
2731
bun build --compile --minify --sourcemap \
2832
--outfile forest-desktop/src-tauri/binaries/forest-aarch64-apple-darwin \
2933
src/index.ts
@@ -32,8 +36,25 @@ bun build --compile --minify --sourcemap \
3236
This creates a single 65MB binary with:
3337
- Bun runtime embedded
3438
- All dependencies bundled
39+
- **sql.js WASM file embedded as base64** (extracted to temp file at runtime)
40+
- **forest-embed helper bundled** (Rust binary for semantic embeddings)
3541
- No need for external `node_modules`
3642

43+
**WASM Embedding Fix (v0.4.1):**
44+
Previous versions had hardcoded development paths to `sql-wasm.wasm`, causing ENOENT errors in distributed binaries. The fix:
45+
1. `scripts/embed-wasm.ts` converts WASM to base64 string
46+
2. `src/lib/db.ts` extracts to temp file at runtime (`/tmp/forest-sql-wasm-<pid>.wasm`)
47+
3. Temp file is cleaned up on process exit
48+
4. Falls back to development path when running from source
49+
50+
**Embedding Parity (v0.4.3):**
51+
CLI and desktop app now use the same embedding engine for true feature parity:
52+
1. `forest-embed` Rust binary provides semantic embeddings to CLI
53+
2. Uses `fastembed` crate (same as desktop app)
54+
3. Both produce identical 384-dim embeddings (all-MiniLM-L6-v2)
55+
4. CLI shells out to helper binary, falls back to mock if not found
56+
5. Binary bundled alongside CLI in distribution
57+
3758
### 2. Tauri Bundle Configuration (`tauri.conf.json`)
3859

3960
```json
@@ -56,7 +77,25 @@ Provides Tauri commands for:
5677
- `check_cli_in_path()` - Check if CLI is already in PATH
5778
- `auto_install_cli_path(shell)` - Auto-add to shell RC files
5879

59-
### 4. Frontend Integration
80+
### 4. Shared Database Location (v0.4.2)
81+
82+
Both the desktop app and CLI use the same database location for seamless integration:
83+
84+
**Platform-specific locations:**
85+
- **macOS**: `~/Library/Application Support/com.ettio.forest.desktop/forest.db`
86+
- **Linux**: `~/.local/share/com.ettio.forest.desktop/forest.db`
87+
- **Windows**: `%APPDATA%\com.ettio.forest.desktop\forest.db`
88+
89+
**Override:**
90+
Set `FOREST_DB_PATH` environment variable to use a custom location.
91+
92+
This ensures:
93+
- ✅ CLI and desktop app always share the same data
94+
- ✅ Predictable, persistent storage location
95+
- ✅ Data survives app updates and reinstalls
96+
- ✅ No confusion about "where is my database"
97+
98+
### 5. Frontend Integration
6099

61100
**Command Palette** (`src/components/CommandPalette.tsx`):
62101
- Type `/cli-install` to open installation dialog

0 commit comments

Comments
 (0)