Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat(agent): explore/research/review/debug built-ins; model is the user's choice
Akarshan Biswas1c1dc768df2d
diff --git a/docs/src/pages/docs/agent/project-config.mdx b/docs/src/pages/docs/agent/project-config.mdxindex 97024d817..a699d591a 100644--- a/docs/src/pages/docs/agent/project-config.mdx+++ b/docs/src/pages/docs/agent/project-config.mdx@@ -269,6 +269,19 @@ Contributor ids: `assistant_instructions`, `guidelines`, `working_directory`, `rSee [Skills](/docs/agent/skills#controlling-which-are-active).+### `[subagents.<name>]`++Per-project model for a subagent, replacing the one its definition names. `model` is a model id,+`"smol"` (`smol_model` in `~/.jan/config.toml`) or `"inherit"` (the session's model). Works for+built-in, plugin, user and project subagents alike, and is what `/settings > subagents` writes.++```toml+[subagents.review]+model = "smol"+```++See [Subagents](/docs/agent/subagents#choosing-a-subagents-model).+## Updating```bashdiff --git a/docs/src/pages/docs/agent/slash-commands.mdx b/docs/src/pages/docs/agent/slash-commands.mdxindex 61f3ec14c..a9cb9ed5c 100644--- a/docs/src/pages/docs/agent/slash-commands.mdx+++ b/docs/src/pages/docs/agent/slash-commands.mdx@@ -77,7 +77,7 @@ See [Run modes](/docs/agent/run-modes), [Goals and todos](/docs/agent/goals-and-| `/login` | Sign in to Tokamak and save the API key || `/config [what you want]` | View provider config (`~/.jan/config.toml`). With words, it is `/vibe-setting` || `/terminal-setup` | Configure this terminal so <kbd>Shift</kbd>+<kbd>Enter</kbd> inserts a newline and, on macOS, <kbd>Option</kbd>+<kbd>Delete</kbd> deletes a word. Writes the terminal's own config where it can (VS Code, kitty, Ghostty, tmux) and prints the manual step where it cannot. Idempotent |-| `/settings [what you want]` | With words (other than the `max_parallel_subagents N` shortcut), it is `/vibe-setting`. Bare, it opens the menu to edit settings in an interactive menu - the project's `agent.toml` (`[agent]` knobs `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `max_parallel_subagents`, `[budget]` limits, the `[tools]` / `[skills]` toggles) and user-wide `~/.jan/config.toml` keys such as `ask_timeout_secs` in the one list (Enter edits a row, `x` resets to default, Esc cancels, clearing the field unsets). The leading `providers` row opens a manager for OpenAI-compatible providers in `~/.jan/config.toml`: `a` adds, Enter edits, `d` twice deletes. `max_parallel_subagents N` works as a one-shot shortcut. Writes apply on the next session (or after `/reload config` for the `[agent]`/`[budget]` limits) |+| `/settings [what you want]` | With words (other than the `max_parallel_subagents N` shortcut), it is `/vibe-setting`. Bare, it opens the menu to edit settings in an interactive menu - the project's `agent.toml` (`[agent]` knobs `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `max_parallel_subagents`, `[budget]` limits, the `[tools]` / `[skills]` toggles) and user-wide `~/.jan/config.toml` keys such as `ask_timeout_secs` in the one list (Enter edits a row, `x` resets to default, Esc cancels, clearing the field unsets). The leading `providers` row opens a manager for OpenAI-compatible providers in `~/.jan/config.toml`: `a` adds, Enter edits, `d` twice deletes. The `subagents` row lists each subagent with its model; Enter picks one from the model picker (the `smol` and `inherit` roles included) and `x` clears the override. The `smol_model` row opens the model picker too (see [Subagents](/docs/agent/subagents#choosing-a-subagents-model)). `max_parallel_subagents N` works as a one-shot shortcut. Writes apply on the next session (or after `/reload config` for the `[agent]`/`[budget]` limits) || `/vibe-setting <what you want>` | Say what you want in plain words and the agent proposes the settings changes that get it. `/settings <words>` and `/config <words>` do the same. See [below](#vibe-setting) |### `/vibe-setting`diff --git a/docs/src/pages/docs/agent/subagents.mdx b/docs/src/pages/docs/agent/subagents.mdxindex 56dbd5b3a..a6eed961f 100644--- a/docs/src/pages/docs/agent/subagents.mdx+++ b/docs/src/pages/docs/agent/subagents.mdx@@ -160,6 +160,55 @@ Because a subagent's context is separate, a long research task that would have ccosts you only its final answer.</Callout>+## Built-in subagents++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 |+| `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 |+| `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.++A saved subagent with the same name replaces a built-in one (see below), and the model of any of them+can be changed per project.++## Choosing a subagent's model++A subagent definition's `model` is one of:++- `smol`: the cheap model set as `smol_model` in `~/.jan/config.toml`. When `smol_model` is unset,+ the session's model is used.+- `inherit` (or no `model`): the session's model.+- A model id, such as `gpt-5-mini`. This ties the definition to one provider's naming, so prefer a+ role.++To change it without editing the definition, set an override in the project's `agent.toml`:++```toml+[subagents.review]+model = "smol"+```++Or do it from the console. `/settings` has two rows for this:++- **`smol_model`** opens the model picker and sets the cheap model for every `smol` subagent (and for+ `/goal` checks).+- **`subagents`** lists every subagent with the model it runs on. Enter opens the model picker, with+ the `smol` and `inherit` roles at the top. `x` clears the override, so the definition's own model+ applies again.++The model is read each time a subagent is dispatched, so a change applies to the next one without a+restart. A cost ceiling is enforced at the subagent's own model's prices; a model with no published+price 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.+## Reusable subagentsDefinitions are TOML files, merged from two scopes:@@ -170,7 +219,8 @@ Definitions are TOML files, merged from two scopes:```The two are merged, and the project scope shadows the user scope by name - so a project can-override one of your personal subagents without renaming it.+override one of your personal subagents without renaming it. Either scope also shadows a built-in+subagent of the same name.Plugins can also ship subagents as markdown agent files (`agents/*.md` in an installed plugin, theClaude Code convention). They load as a third, read-only scope:@@ -179,16 +229,16 @@ Claude Code convention). They load as a third, read-only scope:same name.- Plugin agents cannot be created or edited through `create_subagent` - they are managed byinstalling or removing the plugin.-- Claude-runtime frontmatter is translated: `model` and `color` are ignored (the agent runs on the- session's model), and `tools` is mapped onto Jan's tool names (`Read` -> `read`, `Glob` -> `glob`,+- Claude-runtime frontmatter is translated: `model: haiku` runs the agent on the `smol` role and any+ other `model` on the session's model, `color` is ignored, and `tools` is mapped onto Jan's tool names (`Read` -> `read`, `Glob` -> `glob`,`Grep` -> `grep`, `WebSearch` -> `web_search`, `WebFetch` -> `web_fetch`, `TodoWrite` -> `todo`).Names with no Jan equivalent are dropped; an agent listing only unknown tools inherits theparent's full tool policy.See [Plugins](/docs/agent/plugins#plugin-agents) for how plugin agents are discovered.-Each definition carries a name, a one-line description, a system prompt, and an optional default-tool allowlist. The agent can write one for you:+Each definition carries a name, a one-line description, a system prompt, an optional default tool+allowlist, and an optional `model` (see above). The agent can write one for you:```Create a subagent called "reviewer" that reviews diffs for correctnessdiff --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 125b1125d..107f418ab 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@@ -39,7 +39,13 @@ Everything else is per-user state under `~/.jan/`, created on first use.`-- subagents/ # reusable agent definitions```-`agent.toml` has `[agent]`, `[provider]`, `[budget]`, `[tools]`, and `[skills]` sections.+`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+the 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 scopeand marks shadowed ones, and `skill_write` with `scope: "user"` writes a user skill. Symlinkeddiff --git a/src-tauri/src/core/agent/builtin_subagents/debug.toml b/src-tauri/src/core/agent/builtin_subagents/debug.tomlnew file mode 100644index 000000000..d751b6457--- /dev/null+++ b/src-tauri/src/core/agent/builtin_subagents/debug.toml@@ -0,0 +1,15 @@+name = "debug"+description = "Debugger on the session's model: reproduces a failure, finds its root cause, makes the smallest fix and proves it with a test run."+model = "inherit"+system_prompt = """+You are "debug". You are given one failure to investigate: a failing test, an error message, a crash or a wrong result in the current project.++1. Reproduce it first with the smallest command that shows it. If you cannot reproduce it, stop and report exactly what you ran and what you saw.+2. Find the root cause. Read the code on the failing path, form a hypothesis, and test it (a targeted log line, a narrower test, a bisect) before changing anything. Do not fix a symptom you have not explained.+3. Make the smallest change that fixes the cause, consistent with the surrounding code. Remove any temporary logging you added.+4. Prove it: rerun the reproduction, then the nearby tests, and report anything that still fails.++Never touch unrelated code, never weaken or delete a test to make it pass, and never commit or push.++Finish with a self-contained report for the agent that dispatched you: the root cause in one or two sentences with `path:line`, the change you made (files and why), and the commands you ran to verify it with their results.+"""diff --git a/src-tauri/src/core/agent/builtin_subagents/explorer.toml b/src-tauri/src/core/agent/builtin_subagents/explore.tomlsimilarity index 82%rename from src-tauri/src/core/agent/builtin_subagents/explorer.tomlrename to src-tauri/src/core/agent/builtin_subagents/explore.tomlindex c87b46328..23a7380ff 100644--- a/src-tauri/src/core/agent/builtin_subagents/explorer.toml+++ b/src-tauri/src/core/agent/builtin_subagents/explore.toml@@ -1,9 +1,9 @@-name = "explorer"+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."model = "smol"allowed_tools = ["read", "shell"]system_prompt = """-You are "explorer", 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, never by changing 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.- Search wide first, then read narrowly: open only the parts of files that bear on the question.diff --git a/src-tauri/src/core/agent/builtin_subagents/researcher.toml b/src-tauri/src/core/agent/builtin_subagents/research.tomlsimilarity index 78%rename from src-tauri/src/core/agent/builtin_subagents/researcher.tomlrename to src-tauri/src/core/agent/builtin_subagents/research.tomlindex aac31df37..acdca92f2 100644--- a/src-tauri/src/core/agent/builtin_subagents/researcher.toml+++ b/src-tauri/src/core/agent/builtin_subagents/research.toml@@ -1,9 +1,9 @@-name = "researcher"+name = "research"description = "Web researcher on the smol model: answers a question from current sources and returns a cited summary."model = "smol"allowed_tools = ["web_search", "web_fetch", "read"]system_prompt = """-You are "researcher". You are given one question that needs current or external information: library and API documentation, versions, error messages, standards, or anything outside the project.+You are "research". You are given one question that needs current or external information: library and API documentation, versions, error messages, standards, or anything outside the project.- Search with specific, descriptive queries, then read the most relevant pages in full with `web_fetch`. Do not rely on search snippets for anything that matters.- Prefer primary sources (official documentation, the project's repository, specifications) over blog posts and forums, and note each source's date when it matters.diff --git a/src-tauri/src/core/agent/builtin_subagents/reviewer.toml b/src-tauri/src/core/agent/builtin_subagents/review.tomlsimilarity index 85%rename from src-tauri/src/core/agent/builtin_subagents/reviewer.tomlrename to src-tauri/src/core/agent/builtin_subagents/review.tomlindex 29972b255..fa49a491f 100644--- a/src-tauri/src/core/agent/builtin_subagents/reviewer.toml+++ b/src-tauri/src/core/agent/builtin_subagents/review.toml@@ -1,9 +1,9 @@-name = "reviewer"+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."model = "inherit"allowed_tools = ["read", "shell"]system_prompt = """-You are "reviewer", a careful code reviewer. You are given a change to review (a diff, a commit range, a branch or a list of files). You never edit files; you report.+You are "review", a careful code reviewer. You are given a change to review (a diff, a commit range, a branch or a list of files). You never edit files; you report.- Get the change yourself with read-only commands (`git diff`, `git show`, `git log`) and read the surrounding code that the change depends on or affects.- Look for real problems first: wrong behaviour, unhandled errors and edge cases, concurrency and resource issues, security, broken contracts with callers, and tests that are missing or do not test what they claim.diff --git a/src-tauri/src/core/agent/subagent.rs b/src-tauri/src/core/agent/subagent.rsindex 12934de4b..6d1ad9dca 100644--- a/src-tauri/src/core/agent/subagent.rs+++ b/src-tauri/src/core/agent/subagent.rs@@ -68,9 +68,10 @@ impl SubagentScope {/// embedded at compile time, so the dispatch description that lists them is/// byte-identical across runs (it sits in the cached prompt prefix).const BUILTIN_SUBAGENTS: &[&str] = &[- include_str!("builtin_subagents/explorer.toml"),- include_str!("builtin_subagents/researcher.toml"),- include_str!("builtin_subagents/reviewer.toml"),+ include_str!("builtin_subagents/debug.toml"),+ include_str!("builtin_subagents/explore.toml"),+ include_str!("builtin_subagents/research.toml"),+ include_str!("builtin_subagents/review.toml"),];/// Parse [`BUILTIN_SUBAGENTS`]. A file that fails to parse is a build defect a@@ -107,6 +108,18 @@ pub struct SubagentDefinition {pub scope: SubagentScope,}+impl SubagentDefinition {+ /// The model as listings show it: the role or id the definition names, or+ /// `inherit` when it names none.+ pub fn model_label(&self) -> &str {+ self.model+ .as_deref()+ .map(str::trim)+ .filter(|m| !m.is_empty())+ .unwrap_or(INHERIT_ROLE)+ }+}+/// On-disk shape of a subagent `.toml`; `scope` is derived from the directory,/// not stored in the file.#[derive(Debug, Clone, Deserialize, Serialize)]@@ -341,9 +354,10 @@ fn apply_model_overrides(project_root: &Path, defs: &mut [SubagentDefinition]) {/// Load subagent definitions shipped by installed plugins as Markdown agent/// files (`<plugin>/agents/**/*.md`, the Claude Code convention). Loaded/// first so user/project TOML definitions shadow them by name. Frontmatter-/// `name` and `description` are used; `model` and `color` are Claude-runtime-/// metadata and ignored (the parent's model runs the child); `tools` maps-/// Claude tool names onto Jan tool names, dropping names with no equivalent.+/// `name` and `description` are used; `model` names a Claude tier and is+/// mapped onto a role (see [`map_claude_model`]); `color` is Claude-runtime+/// metadata and ignored; `tools` maps Claude tool names onto Jan tool names,+/// dropping names with no equivalent.fn load_plugin_agents(project_root: &Path, out: &mut Vec<SubagentDefinition>) {crate::core::agent::skills::for_each_plugin_dir(project_root, |_, path| {scan_agent_dir(&path.join("agents"), out);@@ -375,19 +389,12 @@ fn scan_agent_files(dir: &Path, visit: &mut dyn FnMut(&Path, &str)) {fn scan_agent_dir(dir: &Path, out: &mut Vec<SubagentDefinition>) {scan_agent_files(dir, &mut |path, raw| match parse_plugin_agent(raw) {- Some((name, description, tools, system_prompt)) => {- if validate_name(&name).is_err() {- log::warn!("subagent: skipping plugin agent '{name}' (invalid name)");+ Some(def) => {+ if validate_name(&def.name).is_err() {+ log::warn!("subagent: skipping plugin agent '{}' (invalid name)", def.name);return;}- out.push(SubagentDefinition {- name,- description,- system_prompt,- allowed_tools: tools,- model: None,- scope: SubagentScope::Plugin,- });+ out.push(def);}None => log::warn!("subagent: skipping plugin agent {} (missing frontmatter name)",@@ -404,12 +411,24 @@ struct PluginAgentFrontmatter {description: Option<String>,#[serde(default)]tools: Vec<String>,+ model: Option<String>,+}++/// A Claude Code agent's `model:` tier as a Jan model role. `haiku` is the+/// cheap tier, which is what `smol` means here; any other tier, or none, runs+/// on the session's model. A Claude tier is never passed through as a model+/// id: no Jan provider is guaranteed to serve a model by that name.+fn map_claude_model(model: Option<&str>) -> Option<String> {+ model+ .map(str::trim)+ .filter(|m| m.eq_ignore_ascii_case("haiku"))+ .map(|_| SMOL_ROLE.to_string())}-/// Parse a Claude Code agent markdown file into `(name, description, tools,-/// system_prompt)`. `None` when the file has no `---` frontmatter or no-/// `name` — such files are not dispatchable.-fn parse_plugin_agent(raw: &str) -> Option<(String, String, Option<Vec<String>>, String)> {+/// Parse a Claude Code agent markdown file into a plugin-scope definition.+/// `None` when the file has no `---` frontmatter or no `name`, since such files+/// are not dispatchable. The name is not validated here; the loader does that.+fn parse_plugin_agent(raw: &str) -> Option<SubagentDefinition> {let (yaml, body) = crate::core::agent::skills::split_frontmatter(raw);let yaml = yaml?;let fm: PluginAgentFrontmatter = serde_yaml::from_str(&yaml).unwrap_or_default();@@ -417,8 +436,14 @@ fn parse_plugin_agent(raw: &str) -> Option<(String, String, Option<Vec<String>>,.name.map(|n| n.trim().to_string()).filter(|n| !n.is_empty())?;- let description = fm.description.unwrap_or_default();- Some((name, description, map_claude_tools(&fm.tools), body))+ Some(SubagentDefinition {+ name,+ description: fm.description.unwrap_or_default(),+ system_prompt: body,+ allowed_tools: map_claude_tools(&fm.tools),+ model: map_claude_model(fm.model.as_deref()),+ scope: SubagentScope::Plugin,+ })}/// Claude Code tool names with a Jan equivalent, 1:1 where one exists. Unknown@@ -463,8 +488,8 @@ pub(crate) fn plugin_agent_metas(root: &Path, plugin: &str) -> Vec<(String, Stri};let base = base.join("agents");scan_agent_files(&base, &mut |_, raw| {- if let Some((name, description, _, _)) = parse_plugin_agent(raw) {- out.push((name, description));+ if let Some(def) = parse_plugin_agent(raw) {+ out.push((def.name, def.description));}});out@@ -2667,7 +2692,13 @@ pub fn format_subagent_list(registry: &SubagentRegistry) -> String {}let mut lines = Vec::with_capacity(defs.len());for d in defs {- lines.push(format!("{} [{}]: {}", d.name, d.scope.label(), d.description));+ lines.push(format!(+ "{} [{}, model: {}]: {}",+ d.name,+ d.scope.label(),+ d.model_label(),+ d.description+ ));}lines.join("\n")}@@ -2680,11 +2711,17 @@ pub fn subagent_tool_schemas(max_parallel: u32,) -> Vec<serde_json::Value> {use serde_json::json;- let available: Vec<&str> = {+ // 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+ .into_iter()+ .filter_map(|name| registry.get(name))+ .map(|d| format!("{} ({})", d.name, d.model_label()))+ .collect()};let bg = format!(" Subagents run in the BACKGROUND, concurrently (up to {max_parallel} at once, from max_parallel_subagents in agent.toml; more are queued FIFO). You keep working and get a note the moment each finishes. Each subagent's final answer is written to blackboard/<name>.md in a shared scratch directory the whole plan can read from and write to. Steer a running child with message_subagent, or stop it with stop_subagent, by the name you gave it here.");let phases_desc = " List all the subagents in one call. To PIPELINE them, give a subagent a `phase`: subagents sharing a phase run together, lower phases run first, and each later phase is handed the previous phase's results automatically. Omit `phase` for a plain fan-out (one stage, everyone at once); use it to stage work (e.g. phase 0 researches in parallel, phase 1 synthesizes).";@@ -2912,10 +2949,10 @@ pub fn parse_create_args(description,system_prompt,allowed_tools: optional_tool_list(args),- model: args- .get("model")- .and_then(|v| v.as_str())- .map(String::from),+ // Not read from the call: which model an agent runs on is the+ // user's choice (definition files, `[subagents.<name>]`,+ // `/settings`), so the agent cannot route work to a pricier model.+ model: None,scope,},scope,@@ -3074,7 +3111,7 @@ pub(crate) mod tests {fn the_builtin_catalog_parses_in_a_stable_order() {let defs = builtin_definitions();let names: Vec<&str> = defs.iter().map(|d| d.name.as_str()).collect();- assert_eq!(names, ["explorer", "researcher", "reviewer"]);+ assert_eq!(names, ["debug", "explore", "research", "review"]);for def in &defs {assert_eq!(def.scope, SubagentScope::Builtin);assert!(!def.description.is_empty() && !def.system_prompt.is_empty());@@ -3088,12 +3125,17 @@ pub(crate) mod tests {);}}- let explorer = &defs[0];- assert_eq!(explorer.model.as_deref(), Some(SMOL_ROLE));+ let explore = &defs[1];+ assert_eq!(explore.model.as_deref(), Some(SMOL_ROLE));assert_eq!(- explorer.allowed_tools.as_deref(),+ explore.allowed_tools.as_deref(),Some(&["read".to_string(), "shell".to_string()][..]));+ // `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];+ assert_eq!(debug.model.as_deref(), Some(INHERIT_ROLE));+ assert_eq!(debug.allowed_tools, None);assert_eq!(builtin_definitions(), defs, "deterministic");}@@ -3102,19 +3144,19 @@ pub(crate) mod tests {#[test]fn saved_definitions_shadow_builtins_and_overrides_apply_to_them() {let root = unique_root("builtin_shadow");- write_def(&project_subagents_dir(&root), "reviewer", "model = \"mine\"\n");+ write_def(&project_subagents_dir(&root), "review", "model = \"mine\"\n");let toml = crate::core::agent::project::agent_toml_path(&root);- std::fs::write(&toml, "[subagents.explorer]\nmodel = \"inherit\"\n").unwrap();+ std::fs::write(&toml, "[subagents.explore]\nmodel = \"inherit\"\n").unwrap();let reg = SubagentRegistry::load(&root);- let reviewer = reg.get("reviewer").unwrap();- assert_eq!(reviewer.scope, SubagentScope::Project);- assert_eq!(reviewer.model.as_deref(), Some("mine"));- let explorer = reg.get("explorer").unwrap();- assert_eq!(explorer.scope, SubagentScope::Builtin);- assert_eq!(explorer.model.as_deref(), Some(INHERIT_ROLE));+ let review = reg.get("review").unwrap();+ assert_eq!(review.scope, SubagentScope::Project);+ assert_eq!(review.model.as_deref(), Some("mine"));+ let explore = reg.get("explore").unwrap();+ assert_eq!(explore.scope, SubagentScope::Builtin);+ assert_eq!(explore.model.as_deref(), Some(INHERIT_ROLE));let listed = format_subagent_list(®);- assert!(listed.contains("explorer [builtin]"), "{listed}");+ assert!(listed.contains("explore [builtin, model: inherit]"), "{listed}");let _ = std::fs::remove_dir_all(&root);}@@ -5338,6 +5380,68 @@ pub(crate) mod tests {assert!(dispatch.contains("BACKGROUND"), "explains the background model: {dispatch}");}+ /// Which model an agent runs on is the user's choice (the shipped catalog,+ /// a definition file, `/settings`), never the model's: `create_subagent`+ /// does not offer the field. The dispatch description does name each+ /// agent's model, so the main agent can send cheap work to a cheap agent.+ #[test]+ fn schemas_keep_model_choice_out_of_create_but_name_it_on_dispatch() {+ let mut reg = registry_with("reviewer", None);+ reg.defs[0].model = Some(SMOL_ROLE.to_string());+ reg.defs.push(SubagentDefinition {+ name: "writer".to_string(),+ model: None,+ ..reg.defs[0].clone()+ });+ let schemas = subagent_tool_schemas(®, DEFAULT_MAX_PARALLEL_SUBAGENTS);+ let create = schemas+ .iter()+ .find(|s| s["function"]["name"] == "create_subagent")+ .unwrap();+ assert!(+ create["function"]["parameters"]["properties"].get("model").is_none(),+ "create_subagent must not let the model choose a model"+ );++ let dispatch = schemas[0]["function"]["description"].as_str().unwrap();+ assert!(dispatch.contains("reviewer (smol)"), "{dispatch}");+ assert!(dispatch.contains("writer (inherit)"), "{dispatch}");+ }++ /// `list_subagents` reports the model a name dispatches on next to its+ /// scope, `inherit` when the definition names none.+ #[test]+ fn format_list_reports_each_model() {+ let mut reg = registry_with("reviewer", None);+ assert!(format_subagent_list(®).contains("reviewer [project, model: inherit]: d"));+ reg.defs[0].model = Some("gpt-x".to_string());+ assert!(format_subagent_list(®).contains("reviewer [project, model: gpt-x]: d"));+ }++ /// A Claude Code agent file's `model:` names a Claude tier, not an id any+ /// Jan provider serves. `haiku` is the cheap tier, so it maps to the smol+ /// role; every other value (`sonnet`, `opus`, `inherit`) runs on the+ /// session's model, as before.+ #[test]+ fn plugin_agent_model_maps_haiku_to_smol_and_the_rest_to_inherit() {+ let root = unique_root("plugin-model");+ std::fs::create_dir_all(plugin_agents_dir(&root)).unwrap();+ for (name, model) in [("fast", "haiku"), ("Loud", "HAIKU"), ("big", "opus"), ("none", "")] {+ let line = if model.is_empty() { String::new() } else { format!("model: {model}\n") };+ std::fs::write(+ plugin_agents_dir(&root).join(format!("{name}.md")),+ format!("---\nname: {}\ndescription: d\n{line}---\nGo.", name.to_lowercase()),+ )+ .unwrap();+ }+ let reg = SubagentRegistry::load(&root);+ assert_eq!(reg.get("fast").unwrap().model.as_deref(), Some(SMOL_ROLE));+ assert_eq!(reg.get("loud").unwrap().model.as_deref(), Some(SMOL_ROLE));+ assert_eq!(reg.get("big").unwrap().model, None);+ assert_eq!(reg.get("none").unwrap().model, None);+ let _ = std::fs::remove_dir_all(&root);+ }+#[test]fn parse_await_requires_run_id() {assert_eq!(@@ -5353,7 +5457,21 @@ pub(crate) mod tests {assert!(format_subagent_list(&empty).contains("No subagents"));let reg = registry_with("reviewer", None);let listed = format_subagent_list(®);- assert!(listed.contains("reviewer [project]: d"));+ assert!(listed.contains("reviewer [project, model: inherit]: d"));+ }++ /// A `model` the agent slips into `create_subagent` anyway is dropped: the+ /// saved definition runs on the session's model until the user picks one.+ #[test]+ fn parse_create_ignores_a_model_argument() {+ let (def, _, _) = parse_create_args(&serde_json::json!({+ "name": "helper",+ "description": "d",+ "system_prompt": "sp",+ "model": "most-expensive-model"+ }))+ .unwrap();+ assert_eq!(def.model, None);}#[test]@@ -5418,11 +5536,11 @@ pub(crate) mod tests {let def = reg.get("code-explorer").expect("loaded");assert_eq!(def.description, "Explores code");assert_eq!(def.system_prompt, "You are an explorer.");- // Claude runtime metadata is ignored: the parent model runs the child.+ // `sonnet` is not the cheap tier: the parent model runs the child.assert_eq!(def.model, None);assert_eq!(def.scope, SubagentScope::Plugin);let list = format_subagent_list(®);- assert!(list.contains("code-explorer [plugin]"));+ assert!(list.contains("code-explorer [plugin, model: inherit]"));let _ = std::fs::remove_dir_all(&root);}diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 375f6900b..df11a227e 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -31289,11 +31289,17 @@ mod tests {let picker = app.picker.as_ref().expect("subagents screen open");assert_eq!(picker.kind, PickerKind::SubagentModels);let labels: Vec<_> = picker.items.iter().map(|i| i.value.as_str()).collect();- // The saved explorer and reviewer shadow the built-ins of the same- // name; the built-in researcher is listed beside them.- assert_eq!(labels, ["explorer", "researcher", "reviewer"]);- assert_eq!(picker.items[0].hint.as_deref(), Some("big"));- assert_eq!(picker.items[2].hint.as_deref(), Some("inherit"));+ // The saved explorer and reviewer sit beside the built-in catalog.+ assert_eq!(labels, ["debug", "explore", "explorer", "research", "review", "reviewer"]);+ let hint = |name: &str| {+ let item = picker.items.iter().find(|i| i.value == name).unwrap();+ item.hint.clone().unwrap_or_default()+ };+ assert_eq!(hint("explorer"), "big");+ assert_eq!(hint("reviewer"), "inherit");+ assert_eq!(hint("explore"), "smol");+ let row = picker.items.iter().position(|i| i.value == "explorer").unwrap();+ app.picker.as_mut().unwrap().selected = row;// Enter on explorer: the model picker, aimed at it, offering roles.press(&mut app, KeyCode::Enter, KeyModifiers::NONE).await;@@ -31315,13 +31321,16 @@ mod tests {// Back on the refreshed list, which shows the override and its source.let picker = app.picker.as_ref().expect("returns to the subagents list");assert_eq!(picker.kind, PickerKind::SubagentModels);- assert_eq!(picker.items[0].hint.as_deref(), Some("smol (override; own: big)"));+ let row = &picker.items[picker.selected];+ assert_eq!(row.value, "explorer", "the cursor stays on the edited agent");+ assert_eq!(row.hint.as_deref(), Some("smol (override; own: big)"));// `x` clears the override: the definition's own model applies again.press(&mut app, KeyCode::Char('x'), KeyModifiers::NONE).await;let reg = crate::core::agent::subagent::SubagentRegistry::load(&root);assert_eq!(reg.get("explorer").unwrap().model.as_deref(), Some("big"));- assert_eq!(app.picker.as_ref().unwrap().items[0].hint.as_deref(), Some("big"));+ let picker = app.picker.as_ref().unwrap();+ assert_eq!(picker.items[picker.selected].hint.as_deref(), Some("big"));}/// Enter on the `smol_model` row picks from the configured models rather