This commit is contained in:
@@ -35,7 +35,7 @@ pub struct SandboxConfig {
|
||||
pub struct Sandbox {
|
||||
// Owns the temporary directory; dropping it cleans up the clone.
|
||||
_workspace: TempDir,
|
||||
/// Path of the clone, as bind-mounted into the container.
|
||||
/// Path of the clone, as copied into the container.
|
||||
repo_dir: PathBuf,
|
||||
container: Container,
|
||||
}
|
||||
@@ -72,17 +72,20 @@ impl Sandbox {
|
||||
container,
|
||||
};
|
||||
|
||||
sandbox.check_workspace().await?;
|
||||
if let Err(err) = sandbox.check_workspace().await {
|
||||
let _ = sandbox.container.remove().await;
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
Ok(sandbox)
|
||||
}
|
||||
|
||||
/// Vérifie que le clone est bien visible dans le container.
|
||||
///
|
||||
/// Sans ce contrôle, un montage vide — le daemon ne voit pas le clone, par
|
||||
/// exemple quand Herald est dans un container sur une autre machine — fait
|
||||
/// échouer chaque outil ; le modèle enchaîne alors les appels ratés jusqu'au
|
||||
/// budget d'itérations, sans jamais pouvoir reviewer quoi que ce soit.
|
||||
/// Sans ce contrôle, un workspace vide — par exemple un daemon qui n'a pas pu
|
||||
/// recevoir le clone — fait échouer chaque outil ; le modèle enchaîne alors les
|
||||
/// appels ratés jusqu'au budget d'itérations, sans jamais pouvoir reviewer quoi
|
||||
/// que ce soit.
|
||||
async fn check_workspace(&self) -> anyhow::Result<()> {
|
||||
let workspace_folder = self.workspace_folder();
|
||||
let probe = self
|
||||
|
||||
@@ -41,6 +41,19 @@ fn review_tools() -> Vec<Tool> {
|
||||
}
|
||||
}),
|
||||
),
|
||||
Tool::new(
|
||||
"file_size",
|
||||
"Get the size of a file inside the repository in bytes.",
|
||||
json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "File path relative to the repository root."
|
||||
}
|
||||
}
|
||||
}),
|
||||
),
|
||||
Tool::new(
|
||||
"read_file",
|
||||
"Read the content of a text file inside the repository. Every line is \
|
||||
@@ -111,12 +124,19 @@ pub async fn dispatch(sandbox: &Sandbox, name: &str, args: &Value) -> anyhow::Re
|
||||
match name {
|
||||
"ls" => ls(sandbox, args).await,
|
||||
"read_file" => read_file(sandbox, args).await,
|
||||
"file_size" => file_size(sandbox, args).await,
|
||||
"grep" => grep(sandbox, args).await,
|
||||
"find" => find(sandbox, args).await,
|
||||
other => bail!("unknown tool `{other}`"),
|
||||
}
|
||||
}
|
||||
|
||||
async fn file_size(sandbox: &Sandbox, args: &Value) -> anyhow::Result<String> {
|
||||
let path = resolve(sandbox, required_str(args, "path")?)?;
|
||||
let size = sandbox.exec(&["du", "-b", "--", &path]).await?;
|
||||
into_stdout(size)
|
||||
}
|
||||
|
||||
async fn ls(sandbox: &Sandbox, args: &Value) -> anyhow::Result<String> {
|
||||
let path = resolve(sandbox, optional_str(args, "path").unwrap_or("."))?;
|
||||
let output = sandbox.exec(&["ls", "-la", "--", &path]).await?;
|
||||
|
||||
Reference in New Issue
Block a user