Skip to content

An agent-managed museum exhibit, built in Rust with Gajae-Code / LazyCodex — developed and maintained with no human intervention.

Rust

fix(dead-code): remove stale constants + dead function; add workspace_sessions_dir tests

YeonGyu-Kimcae11413dd3a
diff --git a/rust/crates/runtime/src/config.rs b/rust/crates/runtime/src/config.rs
index c4e1b6b4..1aad012a 100644
--- a/rust/crates/runtime/src/config.rs
+++ b/rust/crates/runtime/src/config.rs
@@ -9,27 +9,6 @@ use crate::sandbox::{FilesystemIsolationMode, SandboxConfig};
/// Schema name advertised by generated settings files.
pub const CLAW_SETTINGS_SCHEMA_NAME: &str = "SettingsSchema";
-/// Top-level settings keys recognized by the runtime configuration loader.
-const KNOWN_TOP_LEVEL_KEYS: &[&str] = &[
- "$schema",
- "enabledPlugins",
- "env",
- "hooks",
- "mcpServers",
- "model",
- "oauth",
- "permissionMode",
- "permissions",
- "plugins",
- "sandbox",
-];
-
-/// Deprecated top-level keys mapped to their replacement guidance.
-const DEPRECATED_TOP_LEVEL_KEYS: &[(&str, &str)] = &[
- ("allowedTools", "permissions.allow"),
- ("ignorePatterns", "permissions.deny"),
-];
-
/// Origin of a loaded settings file in the configuration precedence chain.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ConfigSource {
diff --git a/rust/crates/runtime/src/prompt.rs b/rust/crates/runtime/src/prompt.rs
index 060ca441..ad85d0b9 100644
--- a/rust/crates/runtime/src/prompt.rs
+++ b/rust/crates/runtime/src/prompt.rs
@@ -253,30 +253,6 @@ fn read_git_status(cwd: &Path) -> Option<String> {
}
}
-fn read_git_recent_commits(cwd: &Path) -> Option<String> {
- let output = Command::new("git")
- .args([
- "--no-optional-locks",
- "log",
- "--oneline",
- "--no-decorate",
- "-n",
- "5",
- ])
- .current_dir(cwd)
- .output()
- .ok()?;
- if !output.status.success() {
- return None;
- }
- let stdout = String::from_utf8(output.stdout).ok()?;
- let trimmed = stdout.trim();
- if trimmed.is_empty() {
- None
- } else {
- Some(trimmed.to_string())
- }
-}
fn read_git_diff(cwd: &Path) -> Option<String> {
let mut sections = Vec::new();
diff --git a/rust/crates/runtime/src/session.rs b/rust/crates/runtime/src/session.rs
index d7f4a549..b7b7a5c3 100644
--- a/rust/crates/runtime/src/session.rs
+++ b/rust/crates/runtime/src/session.rs
@@ -1438,8 +1438,52 @@ mod tests {
/// Per-worktree session isolation: returns a session directory namespaced
/// by the workspace fingerprint of the given working directory.
/// This prevents parallel `opencode serve` instances from colliding.
+/// Called by external consumers (e.g. clawhip) to enumerate sessions for a CWD.
+#[allow(dead_code)]
pub fn workspace_sessions_dir(cwd: &std::path::Path) -> Result<std::path::PathBuf, SessionError> {
let store = crate::session_control::SessionStore::from_cwd(cwd)
.map_err(|e| SessionError::Io(std::io::Error::new(std::io::ErrorKind::Other, e.to_string())))?;
Ok(store.sessions_dir().to_path_buf())
}
+
+#[cfg(test)]
+mod workspace_sessions_dir_tests {
+ use super::*;
+ use std::fs;
+
+ #[test]
+ fn workspace_sessions_dir_returns_fingerprinted_path_for_valid_cwd() {
+ let tmp = std::env::temp_dir().join("claw-session-dir-test");
+ fs::create_dir_all(&tmp).expect("create temp dir");
+
+ let result = workspace_sessions_dir(&tmp);
+ assert!(
+ result.is_ok(),
+ "workspace_sessions_dir should succeed for a valid CWD, got: {:?}",
+ result
+ );
+ let dir = result.unwrap();
+ // The returned path should be non-empty and end with a hash component
+ assert!(!dir.as_os_str().is_empty());
+ // Two calls with the same CWD should produce identical paths (deterministic)
+ let result2 = workspace_sessions_dir(&tmp).unwrap();
+ assert_eq!(dir, result2, "workspace_sessions_dir must be deterministic");
+
+ fs::remove_dir_all(&tmp).ok();
+ }
+
+ #[test]
+ fn workspace_sessions_dir_differs_for_different_cwds() {
+ let tmp_a = std::env::temp_dir().join("claw-session-dir-a");
+ let tmp_b = std::env::temp_dir().join("claw-session-dir-b");
+ fs::create_dir_all(&tmp_a).expect("create dir a");
+ fs::create_dir_all(&tmp_b).expect("create dir b");
+
+ let dir_a = workspace_sessions_dir(&tmp_a).expect("dir a");
+ let dir_b = workspace_sessions_dir(&tmp_b).expect("dir b");
+ assert_ne!(dir_a, dir_b, "different CWDs must produce different session dirs");
+
+ fs::remove_dir_all(&tmp_a).ok();
+ fs::remove_dir_all(&tmp_b).ok();
+ }
+}