Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat(agent): make the explore subagent read-only by default (#9260) (#9261)

Thinh Le18ebc628bbc5
diff --git a/docs/src/pages/docs/agent/subagents.mdx b/docs/src/pages/docs/agent/subagents.mdx
index d2f790691..9eced846f 100644
--- a/docs/src/pages/docs/agent/subagents.mdx
+++ b/docs/src/pages/docs/agent/subagents.mdx
@@ -167,16 +167,17 @@ Jan ships five subagents, ready to dispatch with no setup:
| Name | Model | What it does |
| --- | --- | --- |
-| `explore` | `smol` | Codebase exploration: finds where things are and reports `path:line` evidence. Told to only read |
+| `explore` | `smol` | Codebase exploration: finds where things are and reports `path:line` evidence. Read-only: `read`, `ls`, `find`, `grep` only |
| `research` | `smol` | Answers a question from current web sources, with citations |
| `review` | `inherit` | Reviews a change for correctness, risk and missing tests, and reports instead of editing |
| `debug` | `inherit` | Reproduces a failure, finds the root cause, makes the smallest fix and verifies it |
| `general` | `inherit` | Any task no other agent fits |
-Every built-in has the session's full toolset; its role is its prompt and model. `explore` is
-read-only by instruction, not by construction: on the cheap `smol` model under an auto-approving
-policy it could still write or run commands. To hold it to reading, give it a definition of your own
-(see below) with `allowed_tools = ["read", "ls", "find", "grep"]`.
+`explore` is read-only by construction: it is offered only `read`, `ls`, `find` and `grep`, with no
+shell and no write tools, so even on the cheap `smol` model under an auto-approving policy it cannot
+change anything. Every other built-in has the session's full toolset; its role is its prompt and
+model. To widen or narrow any of them, give it a definition of your own (see below) with the
+`allowed_tools` you want.
Each dispatch entry names an `agent`, one of the predefined agents, and the task. Workers are named
after their agent, numbered when one agent runs more than once (`explore`, `explore-2`); the
diff --git a/src-tauri/src/core/agent/builtin_subagents/explore.toml b/src-tauri/src/core/agent/builtin_subagents/explore.toml
index 49c150bae..62fc97fba 100644
--- a/src-tauri/src/core/agent/builtin_subagents/explore.toml
+++ b/src-tauri/src/core/agent/builtin_subagents/explore.toml
@@ -1,10 +1,11 @@
name = "explore"
-description = "Codebase explorer on the cheap smol model: finds where things are and how they connect, and reports file paths and facts. Told never to change anything, but holds the full toolset like every agent."
+description = "Read-only codebase explorer on the cheap smol model: finds where things are and how they connect, and reports file paths and facts. Has no shell and no write tools."
model = "smol"
+allowed_tools = ["read", "ls", "find", "grep"]
system_prompt = """
-You are "explore", a read-only codebase explorer. You are given one question about the code in the current project. Answer it by reading. Never change anything: no file writes or edits, and only read-only shell commands.
+You are "explore", a read-only codebase explorer. You are given one question about the code in the current project. Answer it by reading. You have no shell and no way to change anything.
-- Search file contents and locate files with read-only shell commands (`rg`/`grep`, `find`, `ls`), and use `read` to open the files that matter.
+- Search file contents with `grep`, locate files with `find` and `ls`, and use `read` to open the files that matter.
- Search wide first, then read narrowly: open only the parts of files that bear on the question.
- Do not guess. When the code does not settle something, say so and name what you checked.
diff --git a/src-tauri/src/core/agent/subagent.rs b/src-tauri/src/core/agent/subagent.rs
index 285e75bb9..a006abad3 100644
--- a/src-tauri/src/core/agent/subagent.rs
+++ b/src-tauri/src/core/agent/subagent.rs
@@ -3321,10 +3321,13 @@ pub(crate) mod tests {
);
}
}
- // Every built-in inherits the dispatching run's full toolset: a role is
- // its prompt and model, never a narrower tool set the model cannot see.
+ // `explore` is read-only by construction, so it is the one built-in with
+ // an allowlist. The rest inherit the dispatching run's full toolset: a
+ // role is its prompt and model.
for def in &defs {
- assert_eq!(def.allowed_tools, None, "{}", def.name);
+ let expected = (def.name == "explore")
+ .then(|| ["read", "ls", "find", "grep"].map(String::from).to_vec());
+ assert_eq!(def.allowed_tools, expected, "{}", def.name);
}
assert_eq!(defs[1].model.as_deref(), Some(SMOL_ROLE));
assert_eq!(defs[0].model.as_deref(), Some(INHERIT_ROLE));
@@ -4103,6 +4106,45 @@ pub(crate) mod tests {
assert!(matches!(err, SubagentError::PermissionDenied(_)));
}
+ /// `explore` is read-only by construction: dispatched with no allowlist of
+ /// its own it is offered the read and search tools and nothing that writes
+ /// or runs a command, a call can narrow that but never widen it, and the
+ /// other built-ins still inherit everything.
+ #[test]
+ fn the_builtin_explore_is_dispatched_read_only() {
+ let reg = SubagentRegistry::load(&unique_root("explore_read_only"));
+ let p = ToolPermissions::allow_all();
+ let offered = resolve_dispatch_plain(&reg, &req("explore", None), &p)
+ .unwrap()
+ .allowed_tools
+ .expect("explore carries an allowlist");
+ for tool in ["read", "ls", "find", "grep"] {
+ assert!(offered.iter().any(|t| t == tool), "{tool} missing: {offered:?}");
+ }
+ for tool in ["shell", "write", "edit"] {
+ assert!(!offered.iter().any(|t| t == tool), "{tool} offered: {offered:?}");
+ }
+ let widened = req("explore", Some(vec!["shell".to_string()]));
+ assert!(matches!(
+ resolve_dispatch_plain(&reg, &widened, &p).unwrap_err(),
+ SubagentError::PermissionDenied(_)
+ ));
+ let narrowed = req("explore", Some(vec!["grep".to_string()]));
+ let narrowed = resolve_dispatch_plain(&reg, &narrowed, &p).unwrap().allowed_tools;
+ assert_eq!(
+ narrowed,
+ Some(vec![
+ "grep".to_string(),
+ "skill_list".to_string(),
+ "skill_read".to_string(),
+ ])
+ );
+ assert_eq!(
+ resolve_dispatch_plain(&reg, &req("general", None), &p).unwrap().allowed_tools,
+ None
+ );
+ }
+
// ── event forwarding + final text ───────────────────────────────────────
#[test]
@@ -5751,7 +5793,10 @@ pub(crate) mod tests {
assert_eq!(second.definition.name, "explore-2", "the worker keeps its own name");
assert_eq!(second.definition.scope, SubagentScope::Builtin);
assert_eq!(second.definition.model.as_deref(), Some(SMOL_ROLE));
- assert_eq!(second.allowed_tools, None, "inherits the full toolset");
+ // A numbered worker keeps its agent's own tools: `explore` stays read-only.
+ let offered = second.allowed_tools.expect("explore carries an allowlist");
+ assert!(offered.iter().all(|t| t != "shell" && t != "write" && t != "edit"), "{offered:?}");
+ assert!(offered.iter().any(|t| t == "grep"), "{offered:?}");
let _ = std::fs::remove_dir_all(&root);
}