//! Shared tool context: the database handle and the fixed desktop user. //! //! go-mcp is a peer writer against the same `goingson.db` the desktop app uses. //! Every write flows through the normal repository layer, so the 33 SQL sync //! triggers fire and a running GoingsOn picks the changes up. There is no back //! door around the changelog. use std::path::PathBuf; use goingson_core::UserId; use goingson_db_sqlite::{SqliteProjectRepository, SqliteTaskRepository}; use sqlx::SqlitePool; use uuid::Uuid; /// Fixed single-user desktop id. Must match `DESKTOP_USER_ID` in the GoingsOn /// Tauri app (`src-tauri/src/state.rs`); tasks are keyed on it, so a mismatch /// would write rows the app never shows. pub const DESKTOP_USER_ID: UserId = UserId::from_uuid(Uuid::from_u128(1)); /// Everything a tool needs to reach the database. Cheap to clone (the pool is /// an `Arc` internally); tools hold it behind an `Arc` anyway. pub struct Ctx { pub pool: SqlitePool, pub user_id: UserId, } impl Ctx { pub fn new(pool: SqlitePool) -> Self { Self { pool, user_id: DESKTOP_USER_ID, } } pub fn tasks(&self) -> SqliteTaskRepository { SqliteTaskRepository::new(self.pool.clone()) } pub fn projects(&self) -> SqliteProjectRepository { SqliteProjectRepository::new(self.pool.clone()) } } /// Default location of `goingson.db`, matching Tauri's `app_data_dir` for the /// `com.goingson.app` bundle. Resolves the same path the desktop app opens so /// `go-mcp` with no `--db` flag targets the real database. pub fn default_db_path() -> Option { let home = std::env::var_os("HOME")?; let home = PathBuf::from(home); #[cfg(target_os = "macos")] let base = home.join("Library/Application Support"); #[cfg(not(target_os = "macos"))] let base = std::env::var_os("XDG_DATA_HOME") .map(PathBuf::from) .unwrap_or_else(|| home.join(".local/share")); Some(base.join("com.goingson.app").join("goingson.db")) }