Initialize the vault in this repository. Creates the vault tables in the pristine database and the `.vault/` directory structure on disk. This is idempotent — calling it on an already-initialized vault is a no-op. When a `.vault/` working copy already exists on disk (a colocated repository that tracks `.vault/` in Git, or a `.vault/` restored from elsewhere), its bytes are user work and authorit
(&self)
| 146 | /// └── scratch/ |
| 147 | /// ``` |
| 148 | pub fn init_vault(&self) -> Result<(), RepositoryError> { |
| 149 | // Initialize vault tables in redb |
| 150 | { |
| 151 | let mut txn = self |
| 152 | .pristine |
| 153 | .write_txn() |
| 154 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 155 | use atomic_core::pristine::VaultMutTxnT; |
| 156 | txn.init_vault() |
| 157 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 158 | txn.commit() |
| 159 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 160 | } |
| 161 | |
| 162 | // Create directory structure on disk |
| 163 | let vault_dir = self.vault_dir(); |
| 164 | let subdirs = ["goals", "memory", "skills", "intents", "scratch", "prompts"]; |
| 165 | for subdir in &subdirs { |
| 166 | std::fs::create_dir_all(vault_dir.join(subdir))?; |
| 167 | } |
| 168 | |
| 169 | // Initialize knowledge graph tables |
| 170 | { |
| 171 | let mut txn = self |
| 172 | .pristine |
| 173 | .write_txn() |
| 174 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 175 | use atomic_core::pristine::KgMutTxnT; |
| 176 | txn.init_kg() |
| 177 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 178 | txn.commit() |
| 179 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 180 | } |
| 181 | |
| 182 | // Initialize embeddings table |
| 183 | self.init_embeddings()?; |
| 184 | |
| 185 | // Hydrate the tables from an existing on-disk working copy BEFORE |
| 186 | // installing defaults: a `.vault/` that arrived with a colocated |
| 187 | // Git checkout (or any other source) is user work, and its bytes |
| 188 | // are authoritative. The pull/clone path has |
| 189 | // `bootstrap_vault_from_working_copy` for this; init on a |
| 190 | // pre-existing directory has the same shape. |
| 191 | if vault_dir.exists() { |
| 192 | let updated = self.vault_record_working_copy()?; |
| 193 | if !updated.is_empty() { |
| 194 | log::info!( |
| 195 | "Hydrated {} vault entries from the existing .vault/ working copy", |
| 196 | updated.len() |
| 197 | ); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Install default vault content (skills, memory index, system |
| 202 | // prompt) — only for paths absent from both the database and disk. |
| 203 | self.vault_install_defaults()?; |
| 204 | |
| 205 | // NOTE: The vault files are NOT added+recorded here. The CLI init |