Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Refuse an agent's own file tools outright in Clean room chats and questions (#574)

Fábio Soares3be1d0b8713d
diff --git a/crates/ai/src/cli_agents/acp.rs b/crates/ai/src/cli_agents/acp.rs
index ec88c2ea..7a379fbf 100644
--- a/crates/ai/src/cli_agents/acp.rs
+++ b/crates/ai/src/cli_agents/acp.rs
@@ -74,6 +74,14 @@ pub enum Out {
/// while the person is asked. True allows it.
pub type Approver = Arc<dyn Fn(&str, &Value) -> bool + Send + Sync>;
+/// The approver for a chat in Clean room (#564): the agent's own reading, writing, commands and
+/// fetching are refused (they'd reach the original), and what's left (planning, our tools, which
+/// our tool server limits itself) is allowed. There is no project to check paths against in a chat,
+/// so nothing of the agent's own is let through.
+pub fn clean_room_chat_approver() -> Approver {
+ Arc::new(|tool, _input| !matches!(tool, "Read" | "Write" | "Bash" | "WebFetch"))
+}
+
/// An ACP tool call in the approval policy's shape.
fn policy_action(call: &Value) -> (String, Value) {
let s = |p: &str| call.pointer(p).and_then(Value::as_str).map(str::to_string);
diff --git a/crates/ai/src/cli_agents/adapters.rs b/crates/ai/src/cli_agents/adapters.rs
index eafb3dc1..e19f4cf8 100644
--- a/crates/ai/src/cli_agents/adapters.rs
+++ b/crates/ai/src/cli_agents/adapters.rs
@@ -214,6 +214,10 @@ pub fn notes_hook_settings(cli: &str, dir: &std::path::Path) -> String {
const CHANGING_TOOLS: &[&str] =
&["Write", "Edit", "MultiEdit", "NotebookEdit", "Bash", "PowerShell", "WebFetch", "WebSearch", "Task", "TodoWrite", "AskUserQuestion"];
+/// Claude Code's tools that read files, refused outright in Clean room (#564): its defaults let it
+/// read in its own folder and refuse elsewhere only until a release or a setting changes that.
+const READING_TOOLS: &[&str] = &["Read", "Glob", "Grep", "LS", "NotebookRead"];
+
/// Claude Code answering a question about a build: the builder's session copied
/// (`--fork-session`) and the copy not kept, no tool server, and only Read, Glob and Grep (none in
/// Clean room).
@@ -233,7 +237,9 @@ fn question_args(mut a: Vec<String>, cx: &ArgsCx) -> Vec<String> {
}
a.extend(["--no-session-persistence".into(), "--strict-mcp-config".into(), "--disallowedTools".into()]);
a.extend(CHANGING_TOOLS.iter().map(|t| t.to_string()));
- if !cx.reads_checked {
+ if cx.reads_checked {
+ a.extend(READING_TOOLS.iter().map(|t| t.to_string()));
+ } else {
a.extend(["--allowedTools", "Read", "Glob", "Grep"].map(String::from));
}
a
@@ -297,6 +303,11 @@ impl AgentAdapter for ClaudeCode {
a.push("TodoWrite".into());
} else if cx.builder {
a.extend(["Read", "Glob", "Grep", "TodoWrite"].map(String::from));
+ } else if cx.reads_checked {
+ // A Clean room chat works only through our tools, which keep the original out of reach.
+ // Refused outright: neither its defaults nor an allow rule added later can open them (#564).
+ a.push("--disallowedTools".into());
+ a.extend(READING_TOOLS.iter().chain(CHANGING_TOOLS).map(|t| t.to_string()));
}
a
}
diff --git a/crates/ai/src/cli_agents/mod.rs b/crates/ai/src/cli_agents/mod.rs
index 3fcbdbdd..e4c46363 100644
--- a/crates/ai/src/cli_agents/mod.rs
+++ b/crates/ai/src/cli_agents/mod.rs
@@ -149,6 +149,10 @@ pub const APPROVAL_TOOL: &str = craft_anything_engine::tools::interaction_tools:
pub enum Access {
/// Only analyse: no edits.
Analyse,
+ /// The same in Clean room (#564): the agent's own file, shell and web tools are refused outright,
+ /// so it works only through our tool server, which keeps the original out of reach. It isn't
+ /// left to the agent's defaults (they allow reads in its folder and may change).
+ CleanRoomAnalyse,
/// Build: read freely, edit through our approval tool (which asks the person when needed).
Build,
/// Build in Clean room: every read and edit goes through our approval tool, which keeps the
@@ -175,10 +179,23 @@ pub fn build_args(
let prompt = if prompt.starts_with('-') { format!(" {prompt}") } else { prompt.to_string() };
let builder = matches!(access, Access::Build | Access::CleanRoomBuild);
let question = matches!(access, Access::Question | Access::CleanRoomQuestion);
- let reads_checked = matches!(access, Access::CleanRoomBuild | Access::CleanRoomQuestion);
+ let reads_checked = matches!(access, Access::CleanRoomBuild | Access::CleanRoomQuestion | Access::CleanRoomAnalyse);
adapter.args(&ArgsCx { options: opts, prompt: &prompt, preamble, mcp, resume, builder, reads_checked, question })
}
+/// What a run may do with files: a question reads only, a builder builds, anything else analyses;
+/// Deep mode or not decides whether the original is in reach (#564).
+fn access_for(builder: bool, deep: bool, question: bool) -> Access {
+ match (builder, deep, question) {
+ (_, true, true) => Access::Question,
+ (_, false, true) => Access::CleanRoomQuestion,
+ (true, true, false) => Access::Build,
+ (true, false, false) => Access::CleanRoomBuild,
+ (false, true, false) => Access::Analyse,
+ (false, false, false) => Access::CleanRoomAnalyse,
+ }
+}
+
/// True when `program`'s help mentions every required flag (10 s limit, stdin closed).
pub fn verify_flags(program: &str, help_args: &[&str], needed: &[&str]) -> bool {
if needed.is_empty() {
@@ -426,6 +443,9 @@ impl CliSpec {
/// agent speaks it (a local, non-building run), else one CLI run per message.
pub fn conversation(spec: CliSpec) -> Box<dyn Conversation> {
match acp_for(&spec).filter(|_| spec.builder.is_none()) {
+ // In Clean room the agent's own file, shell and web requests are refused, not put to the
+ // person as a card they could allow with one click (#564).
+ Some(c) if !spec.deep => Box::new(c.with_approver(acp::clean_room_chat_approver())),
Some(c) => Box::new(c),
None => Box::new(CliConversation::new(spec)),
}
@@ -605,13 +625,7 @@ fn run_cli(spec: &CliSpec, text: &str, tx: &Sender<AgentEvent>, stop: &Stop, sta
});
return nothing_done(&name);
}
- let access = match (&spec.builder, spec.deep, spec.question) {
- (_, true, true) => Access::Question,
- (_, false, true) => Access::CleanRoomQuestion,
- (Some(_), true, false) => Access::Build,
- (Some(_), false, false) => Access::CleanRoomBuild,
- (None, _, false) => Access::Analyse,
- };
+ let access = access_for(spec.builder.is_some(), spec.deep, spec.question);
let args = build_args(adapter.as_ref(), &spec.options, text, &preamble, &mcp, if adapter.resumes() { resume.as_deref() } else { None }, access);
let shown = FailureContext::new(&program, &args, text, remote.as_deref(), spec);
// A builder turn may take hours and sit silent for long stretches: Ghidra's first look at a big
@@ -1364,6 +1378,53 @@ mod tests {
assert!(!McpCommand::local_or_remote(true, None, Some("/p/inbox".into())).args.contains(&"--inbox".to_string()));
}
+ /// #564: in Clean room a chat's reads aren't left to Claude Code's defaults. Its own file, shell
+ /// and web tools are refused outright (a deny rule beats any allow), so only our tool server,
+ /// which keeps the original out of reach, is left; Deep mode is unchanged.
+ #[test]
+ fn a_clean_room_chat_refuses_the_agents_own_file_tools_outright() {
+ let args = |access| build_args(adapter_for("claude-code").as_ref(), &BackendOptions::default(), "q", "PRE", &mcp(), None, access);
+ let clean = args(Access::CleanRoomAnalyse);
+ let denied = &clean[clean.iter().position(|x| x == "--disallowedTools").expect("a deny list") + 1..];
+ for t in ["Read", "Glob", "Grep", "LS", "NotebookRead", "Write", "Edit", "Bash", "PowerShell", "WebFetch", "WebSearch"] {
+ assert!(denied.contains(&t.to_string()), "{t} is refused: {denied:?}");
+ }
+ let allowed = &clean[clean.iter().position(|x| x == "--allowedTools").unwrap() + 1..clean.iter().position(|x| x == "--disallowedTools").unwrap()];
+ assert_eq!(allowed, ["mcp__craft-anything__*"], "only our tools are allowed");
+ let deep = args(Access::Analyse);
+ assert!(!deep.contains(&"--disallowedTools".to_string()), "Deep mode keeps its defaults: {deep:?}");
+ // A Clean room question refuses reading too (it used to leave that to the default).
+ let q = args(Access::CleanRoomQuestion);
+ let denied = &q[q.iter().position(|x| x == "--disallowedTools").unwrap() + 1..];
+ for t in ["Read", "Glob", "Grep", "LS", "NotebookRead", "Write", "Bash"] {
+ assert!(denied.contains(&t.to_string()), "{t} is refused in a Clean room question");
+ }
+ assert!(!q.contains(&"--allowedTools".to_string()));
+ }
+
+ /// #564: chats take their access from the mode, as builds and questions do.
+ #[test]
+ fn a_run_gets_its_access_from_what_it_is_and_the_mode() {
+ assert_eq!(access_for(false, true, false), Access::Analyse);
+ assert_eq!(access_for(false, false, false), Access::CleanRoomAnalyse);
+ assert_eq!(access_for(true, true, false), Access::Build);
+ assert_eq!(access_for(true, false, false), Access::CleanRoomBuild);
+ assert_eq!(access_for(false, true, true), Access::Question);
+ assert_eq!(access_for(false, false, true), Access::CleanRoomQuestion);
+ assert_eq!(access_for(true, false, true), Access::CleanRoomQuestion);
+ }
+
+ /// #564: an ACP chat in Clean room refuses the agent's own reads, writes, commands and fetches
+ /// instead of putting them to the person.
+ #[test]
+ fn a_clean_room_acp_chat_refuses_the_agents_own_actions() {
+ let approve = acp::clean_room_chat_approver();
+ for tool in ["Read", "Write", "Bash", "WebFetch"] {
+ assert!(!approve(tool, &serde_json::json!({"file_path": "/original/secret.txt"})), "{tool}");
+ }
+ assert!(approve("TodoWrite", &serde_json::Value::Null));
+ }
+
#[test]
fn a_question_reads_a_copy_of_the_builders_session_and_changes_nothing() {
let q = build_args(adapter_for("claude-code").as_ref(), &BackendOptions::default(), "where?", "PRE", &mcp(), Some("sess-1"), Access::Question);
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 2a17f5ef..9b15c70b 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -378,8 +378,16 @@ Owner: open · Status: in progress
differs by agent: Claude Code asks our approval tool; OpenCode's builder runs with `--auto`;
Hermes's `-z` turns its approvals off on every run, chats included. Clean room's approval
rule doesn't reach an agent that never asks us
+- [x] Clean room outside builds (#564): a chat or question with Claude Code refuses the agent's own
+ file, shell and web tools outright (`--disallowedTools`), not through its defaults; an ACP chat
+ refuses them through an approver instead of a consent card (`docs/claude-code.md`)
- [ ] Say on each adapter, as typed data, what it can be held to (asks us, its own sandbox,
- nothing), and have runs act on that, once the decision above is made
+ nothing), in a build, a chat and a question, and have runs act on that, once the decision above
+ is made. Today Codex, Gemini CLI, OpenCode, Antigravity, Hermes and Maki are not held to
+ Clean room in a chat (their own sandbox, if any, is not established)
+- [ ] Check live that a Clean room chat with Claude Code can't read a file outside its folder, and
+ that an ACP chat in Clean room still reaches our tools (its permission requests for them are
+ allowed, only its own read/write/command/fetch are refused)
- [ ] Check live what Hermes over ACP asks about: whether its file reads reach our approval policy
- [ ] Maki's plain `maki -p` builder doesn't ask us before commands, and in Clean room its reads
aren't checked (as with every agent that never asks us): say so in the approval decision
diff --git a/docs/claude-code.md b/docs/claude-code.md
index 9fdbda20..afc089b0 100644
--- a/docs/claude-code.md
+++ b/docs/claude-code.md
@@ -30,6 +30,26 @@ integration does, why it is shaped this way, and what remains to confirm.
- Before a build starts, `claude auth status` is checked. If Claude Code isn't signed in, the run
stops with: "Sign in to Claude Code: open a terminal and run `claude auth login`".
+## Chats and questions in Clean room
+
+Outside a build there is no approval tool, so Clean room's rule that nothing inside the original is
+read can't rest on it. It isn't left to Claude Code's defaults either (they let it read in its own
+folder, and a release or an allow rule added later could change them) (#564):
+
+- A **chat** in Clean room starts Claude Code with `--disallowedTools` naming its own file tools
+ (`Read`, `Glob`, `Grep`, `LS`, `NotebookRead`) and its changing and web tools. A deny rule beats
+ any allow, so it works only through our tool server, which keeps the original out of reach
+ (`clean_room.rs`). In Deep mode a chat is unchanged.
+- A **question** about a build in Clean room refuses the same file tools (it already offered none).
+- A chat over **ACP** in Clean room refuses the agent's own read, write, command and fetch
+ requests instead of showing them as a card the person could allow with one click; its other
+ requests (planning, our tools) are allowed.
+- Other agents (Codex, Gemini CLI, OpenCode, Antigravity, Hermes, Maki) are not held to this in a
+ chat: they keep whatever sandbox they have, if any. See the roadmap's R2.2.
+
+Not yet checked live against Claude Code or an ACP agent (the tests cover the flags and the
+approver).
+
## Under Flatpak
The Flatpak build can read the home folder but not write to it, so Claude Code can't save its