//! The one switch the meaning lane turns on, read from the person's own file.//!//! Semantic search is OFF until the owner turns it on, and the decision is the//! OWNER's, not the server's — which is why it is a synced, ejecting column on//! `cotton_ai_access` rather than an underscore table beside the vectors. The//! vectors are a cache the server may rebuild for twenty-four cents; the//! sentence "I chose to send my notes to OpenAI" is not, and it has to travel//! to every device and out through `GET /v1/export` with everything else.//!//! WHY THE COLUMN MAY NOT BE THERE YET, and why this is not a silent fallback.//! The migration that adds `semantic_search` is build-order step 6 of the//! semantic-search spec (D22) and is not in the schema this build reads: grep//! `cotton_ai_access` in `cotton_store::schema::ddl` and the column is//! absent. With no column, no person has ever been shown D13's paragraph,//! nobody has consented, and nobody has turned anything on — so `false` is the//! TRUE answer, the same answer the column itself gives on the day it lands//! with `DEFAULT 0`. What the tolerance buys is that the indexer,//! `GET /v1/search/status` and the meaning lane need no edit when the migration//! lands: the seam simply goes live.//!//! MOVED HERE FROM `mcp/handlers/records_2/search.rs`'s `mod embed_shim`, which//! agent M2 wrote as a shim naming this module as its permanent home. Moved,//! never copied — two readers of "is the switch on" is how the tool and the//! worker would eventually disagree about what a person consented to.use cotton_store::driver::Driver;use rusqlite::types::ValueasSqlValue;/// Where the switch lives (D22) — the workspace's existing one-row AI table.pubconst SEMANTIC_SWITCH_TABLE: &str = "cotton_ai_access";pubconst SEMANTIC_SWITCH_COLUMN: &str = "semantic_search";/// Is the switch column in this file's schema yet?////// Read per call rather than memoised: a long-lived process holds a file handle/// across the deploy that adds the column, and a cached "no" would keep the/// lane dark on every hot workspace until the next restart.pubfn semantic_switch_column_present(db: &Driver) -> bool { db.all(&format!("PRAGMA table_info({SEMANTIC_SWITCH_TABLE})"), &[]) .map(|rows| { rows.iter() .any(|row| row.text("name") == Some(SEMANTIC_SWITCH_COLUMN)) }) .unwrap_or(false)}/// Has the owner of this file turned semantic search on?////// Three ways to be off, and all three are the same answer to the person: the/// column is not in this file's schema yet, `cotton_ai_access` has no row for/// this workspace (nobody has ever made an AI call here), or the column is 0./// Only an explicit 1 is on.pubfn semantic_search_enabled(db: &Driver, workspace_id: &str) -> bool {if !semantic_switch_column_present(db) {returnfalse; } db.get( &format!("SELECT {SEMANTIC_SWITCH_COLUMN} FROM {SEMANTIC_SWITCH_TABLE} WHERE workspace_id = ?" ), &[SqlValue::Text(workspace_id.to_string())], ) .ok() .flatten() .and_then(|row| row.int(SEMANTIC_SWITCH_COLUMN)) .is_some_and(|value| value == 1)}