From 33afafd890cdee4948c09623fcafda152061bfbb Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 6 Jan 2026 15:09:06 -0800 Subject: [PATCH] Use unique Tauri identifier per worktree for app data isolation --- .gitignore | 3 +++ scripts/git-hooks/post-checkout.mjs | 24 ++++++++++++------------ src-tauri/yaak-models/src/lib.rs | 13 ++----------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index d666f106..3511cfe4 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ tmp .zed codebook.toml target + +# Per-worktree Tauri config (generated by post-checkout hook) +src-tauri/tauri.worktree.conf.json diff --git a/scripts/git-hooks/post-checkout.mjs b/scripts/git-hooks/post-checkout.mjs index 1b387076..459c10ad 100644 --- a/scripts/git-hooks/post-checkout.mjs +++ b/scripts/git-hooks/post-checkout.mjs @@ -98,14 +98,22 @@ YAAK_DEV_PORT=${maxDevPort} # MCP Server port (main worktree uses 64343) YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort} - -# Database path prefix for worktree isolation -YAAK_DB_PATH_PREFIX=worktrees/${worktreeName} `; fs.writeFileSync(envLocalPath, envContent, 'utf8'); console.log(`Created .env.local with YAAK_DEV_PORT=${maxDevPort} and YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}`); +// Create tauri.worktree.conf.json with unique app identifier for complete isolation +// This gives each worktree its own app data directory, avoiding the need for DB path prefixes +const tauriWorktreeConfig = { + identifier: `app.yaak.desktop.dev.${worktreeName}`, + productName: `Daak (${worktreeName})` +}; + +const tauriConfigPath = path.join(process.cwd(), 'src-tauri', 'tauri.worktree.conf.json'); +fs.writeFileSync(tauriConfigPath, JSON.stringify(tauriWorktreeConfig, null, 2) + '\n', 'utf8'); +console.log(`Created tauri.worktree.conf.json with identifier: ${tauriWorktreeConfig.identifier}`); + // Copy gitignored editor config folders from main worktree (.zed, .vscode, .claude, etc.) // This ensures your editor settings, tasks, and configurations are available in the new worktree // without needing to manually copy them or commit them to git. @@ -148,12 +156,4 @@ try { // Continue anyway } -// Run npm run init to install dependencies and bootstrap -console.log('\nRunning npm run init to install dependencies and bootstrap...'); -try { - execSync('npm run init', { stdio: 'inherit' }); - console.log('\n✓ Worktree setup complete!'); -} catch (err) { - console.error('\n✗ Failed to run npm run init. You may need to run it manually.'); - process.exit(1); -} +console.log('\n✓ Worktree setup complete! Run `npm run init` to install dependencies.'); diff --git a/src-tauri/yaak-models/src/lib.rs b/src-tauri/yaak-models/src/lib.rs index 2c190159..7af9be14 100644 --- a/src-tauri/yaak-models/src/lib.rs +++ b/src-tauri/yaak-models/src/lib.rs @@ -51,17 +51,8 @@ pub fn init() -> TauriPlugin { let app_path = app_handle.path().app_data_dir().unwrap(); create_dir_all(app_path.clone()).expect("Problem creating App directory!"); - // Support per-worktree databases via YAAK_DB_PATH_PREFIX env var - let db_dir = match std::env::var("YAAK_DB_PATH_PREFIX") { - Ok(prefix) if !prefix.is_empty() => { - let dir = app_path.join(prefix); - create_dir_all(&dir).expect("Problem creating DB directory!"); - dir - } - _ => app_path.clone(), - }; - let db_file_path = db_dir.join("db.sqlite"); - let blob_db_file_path = db_dir.join("blobs.sqlite"); + let db_file_path = app_path.join("db.sqlite"); + let blob_db_file_path = app_path.join("blobs.sqlite"); // Main database pool let manager = SqliteConnectionManager::file(db_file_path);