- Simplified token type assignment in OAuth service. - Removed unused session_lock module and re-exported Session from zesdex_entities. - Cleaned up session entity by removing unnecessary comments and code. - Consolidated session handling in HTTP handlers for better readability. - Improved formatting and readability in OAuth repository tests. - Enhanced session lock repository with clearer match statements. - Streamlined session repository error handling. - Refined RNG tests for better clarity. - Adjusted module visibility and organization in lib.rs. - Updated IPC client and connection code for better error handling and clarity. - Improved frame handling in IPC for better readability. - Organized module imports and added test utilities for IPC. - Enhanced database connection error handling. - Simplified JWT token creation error handling. - Improved password verification error handling. - Cleaned up state management code for better readability. - Refactored middleware for session authentication and rate limiting. - Simplified clipboard utility for better error handling. - Enhanced logging initialization for better error reporting. - Improved pagination utility with clearer method annotations. - Cleaned up sanitization functions for filenames and paths. - Enhanced slug generation functions for better clarity and usability.
66 lines
2.2 KiB
Rust
66 lines
2.2 KiB
Rust
//! `cd` tool: verify and resolve a workspace-relative directory path.
|
|
use super::super::Tool;
|
|
use super::super::ToolCtx;
|
|
use anyhow::Result;
|
|
use serde_json::{json, Value};
|
|
|
|
/// Tool that resolves a workspace-relative path and reports whether it exists and is a dir.
|
|
pub struct Cd;
|
|
|
|
impl Tool for Cd {
|
|
fn name(&self) -> &'static str {
|
|
"cd"
|
|
}
|
|
|
|
fn description(&self) -> &'static str {
|
|
"Check if a directory exists within the workspace and print its resolved path. Use this to verify a directory path before running other commands there."
|
|
}
|
|
|
|
fn parameters(&self) -> Value {
|
|
json!({
|
|
"type": "object",
|
|
"properties": {
|
|
"path": {
|
|
"type": "string",
|
|
"description": "Directory path (relative to workspace root)"
|
|
}
|
|
},
|
|
"required": ["path"]
|
|
})
|
|
}
|
|
|
|
/// Resolve `path` against the workspace roots and report its status.
|
|
///
|
|
/// Flow: extract `path` → `resolve_path` (sandboxed to `ctx.workspaces`) →
|
|
/// check `exists()` and `is_dir()` → canonicalize → return canonical path.
|
|
///
|
|
/// Why: the agent has no persistent cwd between tool calls; "cd" here is purely a
|
|
/// verification + canonicalization helper rather than a state change.
|
|
///
|
|
/// Return: canonical path on success; explicit "does not exist" / "not a directory"
|
|
/// message (still `Ok`) so the model can react without treating it as an error.
|
|
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
|
let rel = crate::tool::arg_str(args, "path")?;
|
|
|
|
let path = super::super::resolve_path(&ctx.workspaces, &rel)?;
|
|
|
|
if !path.exists() {
|
|
return Ok(format!(
|
|
"path '{}' does not exist (resolved to {})",
|
|
rel,
|
|
path.display()
|
|
));
|
|
}
|
|
if !path.is_dir() {
|
|
return Ok(format!(
|
|
"path '{}' is not a directory (resolved to {})",
|
|
rel,
|
|
path.display()
|
|
));
|
|
}
|
|
|
|
let canon = path.canonicalize().unwrap_or(path);
|
|
Ok(format!("{}", canon.display()))
|
|
}
|
|
}
|