MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / init_vault

Method init_vault

atomic-repository/src/repository/vault.rs:73–138  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

71 /// └── scratch/
72 /// ```
73 pub fn init_vault(&self) -> Result<(), RepositoryError> {
74 // Initialize vault tables in redb
75 {
76 let mut txn = self
77 .pristine
78 .write_txn()
79 .map_err(|e| RepositoryError::Database(e.to_string()))?;
80 use atomic_core::pristine::VaultMutTxnT;
81 txn.init_vault()
82 .map_err(|e| RepositoryError::Database(e.to_string()))?;
83 txn.commit()
84 .map_err(|e| RepositoryError::Database(e.to_string()))?;
85 }
86
87 // Create directory structure on disk
88 let vault_dir = self.vault_dir();
89 let subdirs = ["goals", "memory", "skills", "intents", "scratch", "prompts"];
90 for subdir in &subdirs {
91 std::fs::create_dir_all(vault_dir.join(subdir))?;
92 }
93
94 // Initialize knowledge graph tables
95 {
96 let mut txn = self
97 .pristine
98 .write_txn()
99 .map_err(|e| RepositoryError::Database(e.to_string()))?;
100 use atomic_core::pristine::KgMutTxnT;
101 txn.init_kg()
102 .map_err(|e| RepositoryError::Database(e.to_string()))?;
103 txn.commit()
104 .map_err(|e| RepositoryError::Database(e.to_string()))?;
105 }
106
107 // Initialize embeddings table
108 self.init_embeddings()?;
109
110 // Hydrate the tables from an existing on-disk working copy BEFORE
111 // installing defaults: a `.vault/` that arrived with a colocated
112 // Git checkout (or any other source) is user work, and its bytes
113 // are authoritative. The pull/clone path has
114 // `bootstrap_vault_from_working_copy` for this; init on a
115 // pre-existing directory has the same shape.
116 if vault_dir.exists() {
117 let updated = self.vault_record_working_copy()?;
118 if !updated.is_empty() {
119 log::info!(
120 "Hydrated {} vault entries from the existing .vault/ working copy",
121 updated.len()
122 );
123 }
124 }
125
126 // Install default vault content (skills, memory index, system
127 // prompt) — only for paths absent from both the database and disk.
128 self.vault_install_defaults()?;
129
130 // NOTE: The vault files are NOT added+recorded here. The CLI init

Calls 9

write_txnMethod · 0.80
vault_dirMethod · 0.80
commitMethod · 0.45
init_kgMethod · 0.45
init_embeddingsMethod · 0.45
existsMethod · 0.45
is_emptyMethod · 0.45