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

Function locate_db

atomic-agent/src/transcript/opencode.rs:89–108  ·  view source on GitHub ↗

Locate the OpenCode database, if present. Checks `$OPENCODE_HOME`, then `$XDG_DATA_HOME/opencode`, then `~/.local/share/opencode` (OpenCode's default data directory on both Linux and macOS), then the platform data dir as a last resort.

()

Source from the content-addressed store, hash-verified

87/// `~/.local/share/opencode` (OpenCode's default data directory on both
88/// Linux and macOS), then the platform data dir as a last resort.
89fn locate_db() -> Option<PathBuf> {
90 let mut candidates: Vec<PathBuf> = Vec::new();
91 if let Some(home) = std::env::var_os("OPENCODE_HOME") {
92 candidates.push(PathBuf::from(home));
93 }
94 if let Some(xdg) = std::env::var_os("XDG_DATA_HOME") {
95 candidates.push(PathBuf::from(xdg).join("opencode"));
96 }
97 if let Some(home) = dirs::home_dir() {
98 candidates.push(home.join(".local").join("share").join("opencode"));
99 }
100 if let Some(data) = dirs::data_dir() {
101 candidates.push(data.join("opencode"));
102 }
103
104 candidates
105 .into_iter()
106 .map(|dir| dir.join(DB_FILENAME))
107 .find(|path| path.is_file())
108}
109
110/// Read the current turn's data for `session_id` from OpenCode's store.
111///

Callers 1

read_turnFunction · 0.85

Calls 3

pushMethod · 0.45
into_iterMethod · 0.45
is_fileMethod · 0.45

Tested by

no test coverage detected