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

Function locate_db

atomic-agent/src/transcript/opencode.rs:85–104  ·  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

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

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