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.

refactor(agent): stop advertising ls/find/grep; bash covers them

Akarshan Biswas4b5b93dc66bc
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs
index 7591786ad..856314f68 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/schema.rs
@@ -25,57 +25,12 @@ pub fn builtin_tool_schemas() -> Vec<Value> {
}
}
}),
- json!({
- "type": "function",
- "function": {
- "name": "ls",
- "description": "List directory contents sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Truncated to the entry limit or 64KB.",
- "parameters": {
- "type": "object",
- "properties": {
- "path": { "type": "string", "description": "Directory to list (default '.')." },
- "limit": { "type": "integer", "description": "Maximum number of entries to return (default 500)." }
- },
- "required": []
- }
- }
- }),
- json!({
- "type": "function",
- "function": {
- "name": "find",
- "description": "Search for files by glob pattern, e.g. '*.ts', '**/*.json', or 'src/**/*.rs'. Returns paths relative to the search directory. Respects .gitignore.",
- "parameters": {
- "type": "object",
- "properties": {
- "pattern": { "type": "string", "description": "Glob pattern to match files." },
- "path": { "type": "string", "description": "Directory to search in (default '.')." },
- "limit": { "type": "integer", "description": "Maximum number of results (default 1000)." }
- },
- "required": ["pattern"]
- }
- }
- }),
- json!({
- "type": "function",
- "function": {
- "name": "grep",
- "description": "Search file contents for a pattern. Returns matching lines with file paths and line numbers. Respects .gitignore. Truncated to the match limit or 64KB.",
- "parameters": {
- "type": "object",
- "properties": {
- "pattern": { "type": "string", "description": "Search pattern (regex or literal string)." },
- "path": { "type": "string", "description": "Directory or file to search (default '.')." },
- "glob": { "type": "string", "description": "Filter files by glob pattern, e.g. '*.ts' or '**/*.rs'." },
- "ignore_case": { "type": "boolean", "description": "Case-insensitive search (default false)." },
- "literal": { "type": "boolean", "description": "Treat pattern as a literal string instead of regex (default false)." },
- "context": { "type": "integer", "description": "Number of lines to show before and after each match (default 0)." },
- "limit": { "type": "integer", "description": "Maximum number of matches to return (default 100)." }
- },
- "required": ["pattern"]
- }
- }
- }),
+ // ls / find / grep are deliberately NOT advertised: `bash` covers
+ // listing and searching (`ls`, `find`, `grep`/`rg`), so dedicated tools
+ // for them only enlarge the schema a weak model has to handle. They stay
+ // in BUILTIN_TOOLS -- recognized, gated, and executable if named -- so
+ // the change is reversible and the handlers/tests are untouched; they are
+ // just no longer offered to the model.
#[cfg(feature = "tauri")]
json!({
"type": "function",
@@ -262,11 +217,13 @@ mod tests {
use super::*;
use crate::tools::BUILTIN_TOOLS;
+ /// ls/find/grep stay in BUILTIN_TOOLS (recognized + executable) but are not
+ /// advertised -- bash covers listing and searching -- so the offered set is
+ /// BUILTIN_TOOLS minus that trio. Every other builtin must be advertised, in
+ /// the same order, so a new one can't be silently added and never offered.
#[test]
- fn schemas_match_builtin_tools() {
+ fn advertised_schemas_are_the_builtins_minus_the_unadvertised() {
let schemas = builtin_tool_schemas();
- let expected_len = if cfg!(feature = "tauri") { 16 } else { 15 };
- assert_eq!(schemas.len(), expected_len);
for schema in &schemas {
assert_eq!(schema["type"], "function");
}
@@ -274,7 +231,11 @@ mod tests {
.iter()
.map(|s| s["function"]["name"].as_str().unwrap())
.collect();
- let expected: Vec<&str> = BUILTIN_TOOLS.iter().map(|t| t.name).collect();
+ let expected: Vec<&str> = BUILTIN_TOOLS
+ .iter()
+ .map(|t| t.name)
+ .filter(|n| !matches!(*n, "ls" | "find" | "grep"))
+ .collect();
assert_eq!(names, expected);
}
}
diff --git a/src-tauri/src/core/agent/subagent.rs b/src-tauri/src/core/agent/subagent.rs
index a84ea5452..754d9b687 100644
--- a/src-tauri/src/core/agent/subagent.rs
+++ b/src-tauri/src/core/agent/subagent.rs
@@ -361,8 +361,11 @@ fn map_claude_tools(tools: &[String]) -> Option<Vec<String>> {
.filter_map(|t| {
let jan = match t.to_ascii_lowercase().as_str() {
"read" => Some("read"),
- "glob" => Some("glob"),
- "grep" => Some("grep"),
+ // Glob/Grep intentionally unmapped: Jan no longer advertises
+ // list/search tools (bash covers them). Mapping them would
+ // restrict a child to a tool it is never offered -- and a child
+ // scoped to *only* those would be left with none. Dropped instead,
+ // so such an agent inherits the full toolset (bash included).
"bash" => Some("bash"),
"edit" => Some("edit"),
"write" => Some("write"),
@@ -2632,7 +2635,8 @@ mod tests {
)
.unwrap();
// tools is a Claude Code frontmatter list; NotebookRead has no Jan
- // equivalent and must be dropped, not fatal.
+ // equivalent, and Glob/Grep are intentionally unmapped (Jan no longer
+ // advertises list/search tools) -- all three must drop, leaving `read`.
std::fs::write(
plugin_agents_dir(&root).join("scout.md"),
"---\nname: scout\ndescription: Scans\ntools: [Read, Glob, Grep, NotebookRead]\n---\nScan.",
@@ -2641,15 +2645,29 @@ mod tests {
let reg = SubagentRegistry::load(&root);
let def = reg.get("scout").expect("loaded");
- assert_eq!(
- def.allowed_tools.as_deref(),
- Some(&["read".to_string(), "glob".to_string(), "grep".to_string()][..])
- );
+ assert_eq!(def.allowed_tools.as_deref(), Some(&["read".to_string()][..]));
// No tools field: no allowlist at all.
assert_eq!(reg.get("reader").unwrap().allowed_tools, None);
let _ = std::fs::remove_dir_all(&root);
}
+ #[test]
+ fn plugin_agent_scoped_to_only_search_tools_inherits_full_toolset() {
+ // Glob/Grep are unmapped, so an agent listing only those maps to nothing
+ // -> None (inherit), never Some([]) -- otherwise it would be left with no
+ // way to search (bash is what covers it now).
+ let root = unique_root("plugin-search-only");
+ std::fs::create_dir_all(plugin_agents_dir(&root)).unwrap();
+ std::fs::write(
+ plugin_agents_dir(&root).join("finder.md"),
+ "---\nname: finder\ndescription: Finds\ntools: [Glob, Grep]\n---\nFind.",
+ )
+ .unwrap();
+ let reg = SubagentRegistry::load(&root);
+ assert_eq!(reg.get("finder").unwrap().allowed_tools, None);
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
#[test]
fn plugin_agent_with_only_unknown_tools_gets_no_allowlist() {
let root = unique_root("plugin-unknown-tools");