Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent): address jan-reviewer findings on subagent roles
Akarshan Biswas86c44e09aea0
diff --git a/docs/src/pages/docs/agent/subagents.mdx b/docs/src/pages/docs/agent/subagents.mdxindex a6eed961f..74e7930d2 100644--- a/docs/src/pages/docs/agent/subagents.mdx+++ b/docs/src/pages/docs/agent/subagents.mdx@@ -166,13 +166,24 @@ Jan ships four subagents, ready to dispatch with no setup:| Name | Model | Tools | What it does || --- | --- | --- | --- |-| `explore` | `smol` | `read`, `shell` | Read-only codebase exploration: finds where things are and reports `path:line` evidence |+| `explore` | `smol` | `read`, `ls`, `find`, `grep` | Codebase exploration: finds where things are and reports `path:line` evidence. Read-only by construction: it has no shell and no write tools || `research` | `smol` | `web_search`, `web_fetch`, `read` | Answers a question from current web sources, with citations |-| `review` | `inherit` | `read`, `shell` | Read-only review of a change for correctness, risk and missing tests |+| `review` | `inherit` | `read`, `shell` | Reviews a change for correctness, risk and missing tests, and reports instead of editing. It keeps the shell for `git` and the project's checks || `debug` | `inherit` | all | Reproduces a failure, finds the root cause, makes the smallest fix and verifies it |-The main agent sees each name with its model in the `dispatch_subagent` description, so it can send-lookups to `explore` and keep your main model for the work that needs it.+The main agent picks one by setting `agent` on a dispatch entry; `name` stays the worker's own+unique label, so one dispatch can run several workers on the same agent:++```json+{ "subagents": [+ { "name": "explore-api", "agent": "explore", "task": "Where is request auth checked?" },+ { "name": "explore-db", "agent": "explore", "task": "Which tables does the migration touch?" }+] }+```++It sees each agent with its model in the `dispatch_subagent` description, so it can send lookups to+`explore` and keep your main model for the work that needs it. A worker without `agent` is a one-off,+whatever it is named: a worker called `research` does not pick up the built-in.A saved subagent with the same name replaces a built-in one (see below), and the model of any of themcan be changed per project.@@ -206,8 +217,9 @@ The model is read each time a subagent is dispatched, so a change applies to therestart. A cost ceiling is enforced at the subagent's own model's prices; a model with no publishedprice is refused under a ceiling rather than metered at the wrong rate.-The agent cannot pick a model itself: `create_subagent` saves a definition without one, so it runs-on the session's model until you choose otherwise.+The agent cannot pick a model itself: `create_subagent` saves a new definition without one, so it+runs on the session's model until you choose otherwise. When the agent overwrites an existing+definition (to change its prompt, say), the model you set on it is kept.## Reusable subagents@@ -248,7 +260,8 @@ and never edits files.That writes to the project scope by default, so it applies only in this project. Ask for the userscope to use it everywhere.-Once saved, refer to it by name and it picks up its stored prompt and permissions.+Once saved, it is dispatched with `agent` set to its name (or, as before, by a worker `name` equal to+it) and picks up its stored prompt, permissions and model.## One-off subagentsdiff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.md b/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.mdindex 107f418ab..1f14aac68 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.md+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.md@@ -42,9 +42,10 @@ Everything else is per-user state under `~/.jan/`, created on first use.`agent.toml` has `[agent]`, `[provider]`, `[budget]`, `[tools]`, and `[skills]` sections, plus`[subagents.<name>] model = ...` to choose the model a subagent runs on.-Built-in subagents `explore` and `research` run on the cheap `smol` role (`smol_model` in-`config.toml`, else the session's model); `review` and `debug` run on the session's model. A-subagent's `model` is a model id, `smol` or `inherit`. Change it in `/settings > subagents`; set+Built-in subagents `explore` (read-only: `read`/`ls`/`find`/`grep`, no shell) and `research` run on+the cheap `smol` role (`smol_model` in `config.toml`, else the session's model); `review` and+`debug` run on the session's model. A dispatch picks one with `agent: "<name>"`. A subagent's+`model` is a model id, `smol` or `inherit`. Change it in `/settings > subagents`; setthe cheap model with `/settings > smol_model`.A simple skill can be `skills/<name>.md`. Skill precedence is project > user (`~/.jan/skills`) >built-in `jan`. Plugin skills are always named `<plugin>:<name>`. `/skills` lists each skill's scopediff --git a/src-tauri/src/core/agent/builtin_subagents/explore.toml b/src-tauri/src/core/agent/builtin_subagents/explore.tomlindex 23a7380ff..c7fa67a21 100644--- a/src-tauri/src/core/agent/builtin_subagents/explore.toml+++ b/src-tauri/src/core/agent/builtin_subagents/explore.toml@@ -1,11 +1,11 @@name = "explore"-description = "Read-only codebase explorer on the cheap smol model: finds where things are and how they connect, and reports file paths and facts."+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", "shell"]+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 by changing anything.+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 tool that can change anything.-- Use the shell for listing and searching (`ls`, `rg`/`grep`, `find`, `git log`, `git grep`) and `read` to open the files that matter. Never run a command that writes, installs, builds, deletes or touches the network.+- Use `grep` to search file contents, `find` to locate files by name, `ls` to list a directory, and `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/builtin_subagents/review.toml b/src-tauri/src/core/agent/builtin_subagents/review.tomlindex fa49a491f..77f3e6318 100644--- a/src-tauri/src/core/agent/builtin_subagents/review.toml+++ b/src-tauri/src/core/agent/builtin_subagents/review.toml@@ -1,5 +1,5 @@name = "review"-description = "Read-only code reviewer on the session's model: reviews a change or a set of files for correctness, risk and missing tests, and never edits."+description = "Code reviewer on the session's model: reviews a change or a set of files for correctness, risk and missing tests, and reports instead of editing. Has the shell (for git and the project's checks) but no write tools."model = "inherit"allowed_tools = ["read", "shell"]system_prompt = """diff --git a/src-tauri/src/core/agent/context.rs b/src-tauri/src/core/agent/context.rsindex c2ddba6d1..e195d27b4 100644--- a/src-tauri/src/core/agent/context.rs+++ b/src-tauri/src/core/agent/context.rs@@ -240,7 +240,8 @@ user what's wrong.";const SUBAGENT_GUIDE: &str = "# Subagents\n\nYour own context window is limited. For open-ended exploration \that could pull in a lot of file content or tool output (broad codebase search, reading files, many \multi-step research), prefer `dispatch_subagent` over doing it inline: the subagent absorbs that context \-in its own window and returns only the distilled answer. Dispatch independent subagents in parallel when \+in its own window and returns only the distilled answer. For read-only codebase questions set `agent: \"explore\"` \+and for web lookups `agent: \"research\"`: both run on a cheaper model. Dispatch independent subagents in parallel when \their work doesn't depend on each other; each returns in the background and a note carries its answer when \it finishes. Once you delegate a task it belongs to that subagent -- do not do the same work yourself; \spend the wait on other steps, and only `await_subagent` when nothing else is left to do. Do inline work \@@ -939,6 +940,7 @@ mod tests {let root = scratch_project("subagent-handoff");let with = default_prompt(None, &root, None, true).expect("prompt");assert!(with.contains("belongs to that subagent"));+ assert!(with.contains("agent: \"explore\""), "points cheap work at explore");assert!(with.contains("do not do the same work yourself"));assert!(!with.contains("keep working rather than waiting"));let _ = std::fs::remove_dir_all(&root);diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rsindex 848793e6d..a4ba4d342 100644--- a/src-tauri/src/core/agent/loop.rs+++ b/src-tauri/src/core/agent/loop.rs@@ -2772,6 +2772,18 @@ fn advertise_local_tools(}openai_tools.push(schema);}+ // `ls`/`find`/`grep` stay out of the default array (the shell covers+ // them), but a run whose allowlist names them is offered them: a+ // read-only subagent with no shell (the `explore` built-in) has no+ // other way to search. They are Read-capability, so plan mode keeps them.+ if let Some(allow) = allowed_names {+ for schema in tauri_plugin_agent_tools::tools::schema::search_tool_schemas() {+ let name = schema["function"]["name"].as_str().unwrap_or_default();+ if allow.contains(name) && !permissions.is_denied(name) {+ openai_tools.push(schema);+ }+ }+ }// Subagent tools are advertised only when this run may dispatch them// (never for a child run, capping recursion depth at one) and the run// isn't in read-only Plan mode (a dispatched subagent could mutate).@@ -11181,6 +11193,44 @@ mod tests {assert!(!names.iter().any(|n| n == "dispatch_subagent"));}+ /// `ls`/`find`/`grep` are left out of the default array (the shell covers+ /// them), but a run whose allowlist names them -- the read-only `explore`+ /// built-in, which has no shell -- must be offered them, or it could not+ /// search at all. Without an allowlist they stay out.+ #[test]+ fn search_tools_are_advertised_only_when_an_allowlist_names_them() {+ let root = std::env::temp_dir().join(format!("jan-advertise-search-{}", std::process::id()));+ std::fs::create_dir_all(&root).unwrap();+ let advertised = |allowed: Option<&std::collections::HashSet<String>>| {+ let mut tools = Vec::new();+ advertise_local_tools(+ &mut tools,+ allowed,+ &tauri_plugin_agent_tools::permissions::ToolPermissions::allow_all(),+ Some(root.as_path()),+ crate::core::agent::plan::RunMode::Normal,+ false,+ crate::core::agent::subagent::DEFAULT_MAX_PARALLEL_SUBAGENTS,+ false,+ false,+ #[cfg(feature = "cli")]+ &crate::core::agent::host_tools::HostToolSet::new(),+ );+ tools+ .iter()+ .map(|t| t["function"]["name"].as_str().unwrap().to_string())+ .collect::<Vec<_>>()+ };+ let none = advertised(None);+ assert!(!none.iter().any(|n| n == "grep" || n == "ls" || n == "find"), "{none:?}");+ let allow: std::collections::HashSet<String> =+ ["read", "ls", "find", "grep"].iter().map(|s| s.to_string()).collect();+ let mut named = advertised(Some(&allow));+ named.sort();+ assert_eq!(named, ["find", "grep", "ls", "read"]);+ let _ = std::fs::remove_dir_all(&root);+ }+/// Plan mode is read-only: a dispatched child could mutate, so neither the/// dispatch nor the steering tool is advertised.#[test]diff --git a/src-tauri/src/core/agent/subagent.rs b/src-tauri/src/core/agent/subagent.rsindex 6d1ad9dca..c078d71e8 100644--- a/src-tauri/src/core/agent/subagent.rs+++ b/src-tauri/src/core/agent/subagent.rs@@ -248,6 +248,14 @@ impl SubagentRegistry {self.defs.iter().collect()}+ /// Each distinct name, sorted: the values `agent` may take.+ fn dispatchable_names(&self) -> Vec<&str> {+ let mut names: Vec<&str> = self.defs.iter().map(|d| d.name.as_str()).collect();+ names.sort_unstable();+ names.dedup();+ names+ }+/// Write `def` to the directory for `scope`, refusing to clobber an existing/// definition of the same name in that same scope unless `overwrite`. Returns/// `true` when a project-scope write shadows a user-scope definition (so the@@ -303,6 +311,21 @@ impl SubagentRegistry {}std::fs::create_dir_all(dir).map_err(|e| SubagentError::Upstream(format!("failed to create {}: {e}", dir.display())))?;+ let path = dir.join(format!("{}.toml", def.name));+ // An overwrite through `create_subagent` carries no model (the agent may+ // not choose one), so keep the one the replaced file named. Read from+ // the file rather than `self.defs`: those carry agent.toml overrides,+ // which must stay in agent.toml and not be baked into the definition.+ let def = match def.model {+ Some(_) => def,+ None => SubagentDefinition {+ model: std::fs::read_to_string(&path)+ .ok()+ .and_then(|raw| toml::from_str::<SubagentFile>(&raw).ok())+ .and_then(|file| file.model),+ ..def+ },+ };let file = SubagentFile {name: def.name.clone(),description: def.description.clone(),@@ -312,7 +335,6 @@ impl SubagentRegistry {};let body = toml::to_string_pretty(&file).map_err(|e| SubagentError::Upstream(format!("failed to serialize subagent: {e}")))?;- let path = dir.join(format!("{}.toml", def.name));std::fs::write(&path, body).map_err(|e| SubagentError::Upstream(format!("failed to write {}: {e}", path.display())))?;@@ -706,16 +728,21 @@ fn qualify_host_names(tools}-/// One subagent within a phased dispatch. When `name` matches a saved definition-/// that definition's role and tools are used (and `allowed_tools` further narrows-/// it); otherwise the subagent runs as a focused general-purpose agent defined by-/// its `description` (the task) alone. `name` is also the blackboard filename its-/// answer is written to (`blackboard/<name>.md`).+/// One subagent within a phased dispatch. `agent` names the definition to run+/// (any scope, built-ins included); without it, a `name` matching a saved user,+/// project or plugin definition uses that one, as before. Either way the+/// definition's role and tools are used, and `allowed_tools` further narrows+/// them. Otherwise the subagent runs as a focused general-purpose agent defined+/// by its `description` (the task) alone. `name` is the worker's own identity+/// and the blackboard filename its answer is written to+/// (`blackboard/<name>.md`), so it stays unique even when several workers run+/// one definition.#[derive(Debug, Clone)]pub struct SubagentRequest {pub name: String,pub description: String,pub allowed_tools: Option<Vec<String>>,+ pub agent: Option<String>,}/// A group of subagents that run concurrently. The next phase starts only once@@ -756,8 +783,28 @@ fn resolve_dispatch(qualify: impl Fn(Vec<String>) -> Vec<String>,) -> Result<ResolvedDispatch, SubagentError> {let requested = req.allowed_tools.clone().map(&qualify);- match registry.get(&req.name).cloned() {+ // A built-in is reached only through `agent`: matching it by the worker's+ // `name` would hand an ad-hoc worker that happens to be called `research`+ // a prompt and allowlist it never asked for. Saved definitions keep the+ // match by name, which is how they have always been dispatched.+ let definition = match req.agent.as_deref() {+ Some(agent) => Some(registry.get(agent).cloned().ok_or_else(|| {+ SubagentError::Upstream(format!(+ "no subagent definition named '{agent}' for agent; available: {}. Omit \+ agent to run a one-off general-purpose subagent.",+ registry.dispatchable_names().join(", ")+ ))+ })?),+ None => registry+ .get(&req.name)+ .filter(|d| d.scope != SubagentScope::Builtin)+ .cloned(),+ };+ match definition {Some(mut definition) => {+ // The worker keeps its own identity: its run id, blackboard file+ // and transcript rows name the instance, not the definition.+ definition.name = req.name.clone();definition.allowed_tools = definition.allowed_tools.map(&qualify);// Registered definition: the call-site allowlist further narrows it.let allowed_tools = intersect_allowed_tools(@@ -2714,10 +2761,8 @@ pub fn subagent_tool_schemas(// Each name with the model its winning definition dispatches on, so the// agent can send cheap work to a cheap agent without a list call.let available: Vec<String> = {- let mut names: Vec<&str> = registry.list().iter().map(|d| d.name.as_str()).collect();- names.sort_unstable();- names.dedup();- names+ registry+ .dispatchable_names().into_iter().filter_map(|name| registry.get(name)).map(|d| format!("{} ({})", d.name, d.model_label()))@@ -2729,7 +2774,7 @@ pub fn subagent_tool_schemas(format!("Dispatch one or more subagents -- nested, isolated agents -- to do work for you.{phases_desc}{bg} No saved subagents yet; each runs as a focused general-purpose agent defined by its task.")} else {format!(- "Dispatch one or more subagents -- nested, isolated agents -- to do work for you.{phases_desc}{bg} A subagent whose name matches a saved one uses that role and tools; otherwise it runs as a focused general-purpose agent. Saved subagents: {}.",+ "Dispatch one or more subagents -- nested, isolated agents -- to do work for you.{phases_desc}{bg} Set `agent` to run one of these as a subagent, using its role, tools and model (several entries may run the same agent under different names); omit it for a focused general-purpose subagent. Available agents, each with the model it runs on: {}.",available.join(", "))};@@ -2748,7 +2793,8 @@ pub fn subagent_tool_schemas("items": {"type": "object","properties": {- "name": { "type": "string", "description": "Short identity for this subagent, unique across the whole call: letters, digits, '-' and '_' only. It is also the blackboard file its answer is written to (blackboard/<name>.md). If it matches a saved subagent, that role and tools are used; otherwise it runs as a focused general-purpose agent." },+ "name": { "type": "string", "description": "Short identity for this subagent, unique across the whole call: letters, digits, '-' and '_' only. It is also the blackboard file its answer is written to (blackboard/<name>.md)." },+ "agent": { "type": "string", "description": "Optional saved or built-in subagent to run as (one of the names listed in this tool's description); its role, tools and model are used. Several entries may share one agent under different names. Omit it for a focused general-purpose subagent defined by its task." },"task": { "type": "string", "description": "The subagent's sole instruction. Include everything it needs; it does not see this conversation. A subagent in a later phase also receives the previous phase's results automatically, so tell it what to DO with them." },"phase": { "type": "integer", "minimum": 0, "description": "Optional stage (default 0). Subagents with the same phase run concurrently; a phase starts only after every lower phase has finished. Omit it entirely for a plain fan-out." },"allowed_tools": {@@ -2899,10 +2945,17 @@ pub fn parse_dispatch_plan(args: &serde_json::Value) -> Result<DispatchPlan, Sub))})?,};+ let agent = sub+ .get("agent")+ .and_then(|v| v.as_str())+ .map(str::trim)+ .filter(|a| !a.is_empty())+ .map(String::from);by_phase.entry(phase).or_default().push(SubagentRequest {name,description,allowed_tools: optional_tool_list(sub),+ agent,});}let phases = by_phase@@ -3125,12 +3178,26 @@ pub(crate) mod tests {);}}+ // `explore` is read-only by construction: no shell, no write tools,+ // so a cheap model under an auto-approving parent still cannot write.let explore = &defs[1];assert_eq!(explore.model.as_deref(), Some(SMOL_ROLE));- assert_eq!(- explore.allowed_tools.as_deref(),- Some(&["read".to_string(), "shell".to_string()][..])- );+ let tools: Vec<&str> = explore+ .allowed_tools+ .as_deref()+ .unwrap()+ .iter()+ .map(String::as_str)+ .collect();+ assert_eq!(tools, ["read", "ls", "find", "grep"]);+ for tool in &tools {+ let cap = tauri_plugin_agent_tools::tools::lookup(tool).unwrap().capability;+ assert_eq!(cap, tauri_plugin_agent_tools::tools::Capability::Read, "{tool}");+ }+ // `review` keeps the shell for `git diff`, so it must not claim to be+ // read-only; it is told not to edit instead.+ let review = &defs[3];+ assert!(!review.description.contains("read-only"), "{}", review.description);// `debug` has to edit and run tests, so it keeps the full toolset// (narrowed only by the parent's policy) on the session's model.let debug = &defs[0];@@ -3550,6 +3617,7 @@ pub(crate) mod tests {name: name.to_string(),description: "do the thing".to_string(),allowed_tools: allowed,+ agent: None,}}@@ -3765,6 +3833,7 @@ pub(crate) mod tests {name: "one-off".to_string(),description: "task".to_string(),allowed_tools: Some(vec!["read".to_string()]),+ agent: None,};let resolved = resolve_dispatch_plain(®, &request, &p).unwrap();assert_eq!(resolved.definition.name, "one-off");@@ -5474,6 +5543,99 @@ pub(crate) mod tests {assert_eq!(def.model, None);}+ /// Overwriting a saved definition (say, to change its prompt) keeps the+ /// model the user chose for it: `create_subagent` carries no model, so+ /// writing its `None` over the file would move the agent onto the session's+ /// pricier model, which is exactly what the agent must not be able to do.+ #[test]+ fn an_overwrite_keeps_the_existing_definitions_model() {+ let root = unique_root("overwrite_model");+ let dir = project_subagents_dir(&root);+ write_def(&dir, "helper", "model = \"smol\"\n");+ let mut reg = SubagentRegistry::load(&root);+ let (def, scope, _) = parse_create_args(&serde_json::json!({+ "name": "helper", "description": "d", "system_prompt": "new prompt"+ }))+ .unwrap();+ reg.create_in(&dir, def, scope, true).expect("overwrite");+ let reloaded = SubagentRegistry::load_definitions(&root);+ let helper = reloaded.get("helper").unwrap();+ assert_eq!(helper.system_prompt, "new prompt");+ assert_eq!(helper.model.as_deref(), Some(SMOL_ROLE));+ let _ = std::fs::remove_dir_all(&root);+ }++ /// The model kept is the file's own, never a project override: an+ /// override lives in agent.toml and must not be baked into the definition.+ #[test]+ fn an_overwrite_does_not_bake_in_an_agent_toml_override() {+ let root = unique_root("overwrite_override");+ let dir = project_subagents_dir(&root);+ write_def(&dir, "helper", "");+ let toml = crate::core::agent::project::agent_toml_path(&root);+ std::fs::write(&toml, "[subagents.helper]\nmodel = \"smol\"\n").unwrap();+ let mut reg = SubagentRegistry::load(&root);+ let (def, scope, _) = parse_create_args(&serde_json::json!({+ "name": "helper", "description": "d", "system_prompt": "p2"+ }))+ .unwrap();+ reg.create_in(&dir, def, scope, true).expect("overwrite");+ let own = SubagentRegistry::load_definitions(&root);+ assert_eq!(own.get("helper").unwrap().model, None);+ let _ = std::fs::remove_dir_all(&root);+ }++ /// `agent` names the definition a worker runs, separately from the+ /// worker's own `name`, so one plan can fan out several `explore` workers+ /// (names must be unique: each is a blackboard file) and an ad-hoc worker+ /// that happens to be called `research` is not hijacked by the built-in.+ #[test]+ fn agent_names_the_definition_and_name_the_worker() {+ let root = unique_root("agent_field");+ let reg = SubagentRegistry::load(&root);+ let p = ToolPermissions::allow_all();+ let plan = parse_dispatch_plan(&serde_json::json!({ "subagents": [+ { "name": "explore-api", "agent": "explore", "task": "a" },+ { "name": "explore-db", "agent": "explore", "task": "b" },+ { "name": "research", "task": "look into the build", "allowed_tools": ["shell"] }+ ]}))+ .expect("two explore workers in one plan");+ let subs = &plan.phases[0].subagents;+ assert_eq!(subs[0].agent.as_deref(), Some("explore"));++ let api = resolve_dispatch_plain(®, &subs[0], &p).unwrap();+ assert_eq!(api.definition.name, "explore-api", "the worker keeps its own name");+ assert_eq!(api.definition.scope, SubagentScope::Builtin);+ assert_eq!(api.definition.model.as_deref(), Some(SMOL_ROLE));+ assert!(api.definition.system_prompt.contains("read-only"));++ // No `agent`: a one-off, whatever its name, with its own tools.+ let adhoc = resolve_dispatch_plain(®, &subs[2], &p).expect("not hijacked");+ assert_ne!(adhoc.definition.scope, SubagentScope::Builtin);+ assert_eq!(adhoc.definition.model, None);++ // An `agent` that names nothing is an error the model can fix, not a+ // silent fallback to a general-purpose agent on the main model.+ let bad = SubagentRequest { agent: Some("nope".into()), ..req("w", None) };+ let err = resolve_dispatch_plain(®, &bad, &p).unwrap_err().to_string();+ assert!(err.contains("nope") && err.contains("explore"), "{err}");+ let _ = std::fs::remove_dir_all(&root);+ }++ /// The dispatch schema documents `agent` and lists what it may name.+ #[test]+ fn the_dispatch_schema_offers_agent() {+ let reg = SubagentRegistry::load(&unique_root("agent_schema"));+ let schemas = subagent_tool_schemas(®, DEFAULT_MAX_PARALLEL_SUBAGENTS);+ let item = &schemas[0]["function"]["parameters"]["properties"]["subagents"]["items"];+ let agent = &item["properties"]["agent"];+ assert_eq!(agent["type"], "string");+ let required = item["required"].as_array().unwrap();+ assert!(!required.iter().any(|r| r == "agent"));+ let dispatch = schemas[0]["function"]["description"].as_str().unwrap();+ assert!(dispatch.contains("explore (smol)"), "{dispatch}");+ }+#[test]fn parse_create_defaults_scope_to_project() {let (def, scope, overwrite) = parse_create_args(&serde_json::json!({diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 996633c1f..a116acf44 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -917,6 +917,10 @@ enum ModelTarget {/// model picker; also their `provider`, so search matches the word "role".const ROLE_SCOPE: &str = "role";+/// Scope label of a settings picker's current value when no provider lists+/// it, so the picker can still open on (and re-select) it.+const CURRENT_SCOPE: &str = "current";+struct ModelPicker {scopes: Vec<ModelScope>,active_scope: usize,@@ -18631,6 +18635,16 @@ fn open_settings_model_picker(app: &mut App, target: ModelTarget, current: Optio],_ => &[],};+ // A current value no provider lists (a definition's own `model = "big"`,+ // or a hand-edited `smol_model`) gets a row of its own, under the+ // `current` scope, so the picker can open on it. Without one the cursor+ // falls to index 0, and Enter would write a value the user never chose.+ let mut pairs = pairs;+ let listed =+ roles.contains(¤t) || pairs.iter().any(|(_, model)| model.as_str() == current);+ if !current.is_empty() && !listed {+ pairs.push((CURRENT_SCOPE.to_string(), current.to_string()));+ }let picker = ModelPicker::with_roles(pairs, roles, current);match picker {Some(picker) => {@@ -31410,6 +31424,21 @@ mod tests {assert_eq!(mp.current, "inherit");}+ /// A subagent on a model no provider lists (a definition's `model = "big"`)+ /// opens on a row for that model, marked current, rather than on index 0:+ /// that is `smol`, and Enter-Enter would write an override never chosen.+ #[tokio::test]+ async fn the_picker_keeps_an_unlisted_current_model_selectable() {+ let mut app = test_app();+ app_with_subagents(&mut app);+ super::open_subagent_settings(&mut app, Some("explorer"));+ press(&mut app, KeyCode::Enter, KeyModifiers::NONE).await;+ let mp = app.model_picker.as_ref().expect("model picker opened");+ assert_eq!(mp.items[mp.selected].value, "big");+ assert_eq!(mp.current, "big");+ assert!(mp.items.iter().any(|i| i.value == "smol"), "roles still offered");+ }+/// Enter on the `smol_model` row picks from the configured models rather/// than a free-text field, so a typo cannot reach a dispatch.#[test]