Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,8 @@ fn custom_subagents_reach_new_sessions() {
h.settle();
assert!(h.drawn("model-picker-gpt-7"));
assert!(h.drawn("model-picker-gpt-6.1-sol"), "a model switched on that is no longer offered stays listed");
let drawn: Vec<String> = h.rt.elements().into_iter().filter_map(|e| e.text).collect();
assert!(drawn.iter().any(|t| t == "Claudiu:codex-gpt-7"), "each model shows the type Claude Code names it: {drawn:?}");
h.click("model-picker-gpt-6.1-sol");
h.click("model-picker-done");
h.settle();
Expand Down
1 change: 1 addition & 0 deletions src/claude/acp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl Connection {
let program = which::which(program).map_err(|_| missing.to_string())?;
let mut command = Command::new(program);
command.args(args).current_dir(cwd).stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped());
crate::platform::no_window(&mut command);
for (key, value) in env {
command.env(key, value);
}
Expand Down
34 changes: 21 additions & 13 deletions src/claude/subagents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,18 @@ pub struct AgentType {
pub model: String,
}

/// The agent type name of a model: the agent's key and the id, dots and slashes turned into dashes because type names
/// can hold neither (`gpt-6.1-sol` → `codex-gpt-6-1-sol`, `openai/gpt-6.1-sol` → `opencode-openai-gpt-6-1-sol`).
/// None for an id no type name can carry.
/// The agent type name of a model: the agent's key and the id, with every character a type name can't hold (dots,
/// slashes, colons) turned into a dash, cut to the length Claude Code takes (`gpt-6.1-sol` → `codex-gpt-6-1-sol`,
/// `ollama/qwen3:8b` → `opencode-ollama-qwen3-8b`). None for an empty id.
pub fn type_name(agent: Agent, model: &str) -> Option<String> {
let allowed = !model.is_empty() && model.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-' | '/'));
let name = format!("{}-{}", agent.key(), model.replace(['.', '/'], "-"));
(allowed && name.len() <= TYPE_NAME_MAX).then_some(name)
if model.is_empty() {
return None;
}
let id: String = model.chars().map(|c| if c.is_ascii_alphanumeric() || matches!(c, '_' | '-') { c } else { '-' }).collect();
// Every character is ASCII now, so cutting at a byte count can't split one.
let mut name = format!("{}-{id}", agent.key());
name.truncate(TYPE_NAME_MAX);
Some(name)
}

/// The agent types of the models switched on. A model whose type name an earlier one took gives none.
Expand Down Expand Up @@ -242,13 +247,16 @@ mod tests {
}

#[test]
fn ids_no_type_name_can_carry_and_repeats_give_no_type() {
let long = "g".repeat(59); // "codex-" plus 59 is 65 characters
let types = agent_types(Agent::Codex, &ids(&["gpt 5", "gpt-5.5", "gpt-5-5", "", &long, "o3"]));
assert_eq!(types.iter().map(|t| t.name.as_str()).collect::<Vec<_>>(), ["codex-gpt-5-5", "codex-o3"]);
let fits = "g".repeat(55); // "opencode-" plus 55 is 64 characters
let types = agent_types(Agent::OpenCode, &ids(&[&format!("{fits}x"), &fits, "a/b.c", "a.b/c"]));
assert_eq!(types.iter().map(|t| t.name.clone()).collect::<Vec<_>>(), [format!("opencode-{fits}"), "opencode-a-b-c".into()]);
fn every_model_gets_a_type_and_repeats_give_none() {
let types = agent_types(Agent::OpenCode, &ids(&["ollama/qwen3:8b", "openrouter/deepseek/deepseek-r1:free", "a b+c", "", "a/b.c", "a.b/c"]));
let names: Vec<&str> = types.iter().map(|t| t.name.as_str()).collect();
assert_eq!(names, ["opencode-ollama-qwen3-8b", "opencode-openrouter-deepseek-deepseek-r1-free", "opencode-a-b-c"]);
// "a b+c" takes opencode-a-b-c first, so "a/b.c" and "a.b/c" give none.
assert_eq!(types[2].model, "a b+c");
let long = "g".repeat(70);
let types = agent_types(Agent::Codex, &ids(&[&long]));
assert_eq!(types[0].name, format!("codex-{}", "g".repeat(58)), "cut to 64 characters");
assert_eq!(types[0].model, long, "the agent still gets the real id");
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/panels/settings_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ fn model_matches(query: &str, model: &AgentModel) -> bool {

/// A model's switch, keyed `key`, on the page or in the picker; it flips the model in the agent's form.
fn model_switch(key: String, agent: Agent, model: &AgentModel, offered: bool, on: bool) -> Option<El> {
let name = type_name(agent, &model.id)?;
// The mod registers the type, so Claude Code puts its plugin's name before it.
let name = format!("Claudiu:{}", type_name(agent, &model.id)?);
let tag = if offered { name } else { format!("{name} · no longer offered") };
let id = model.id.clone();
Some(switch_row(key, &model.name, Some(&tag), on, move |ws| {
Expand Down
Loading