From f1ca1fc7a237d9afb6ebbaaafc635f3466ff5f12 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Thu, 19 Nov 2026 19:15:22 +0800 Subject: [PATCH] feat(vcs): choose the agent, model and effort for Generate Commit Message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings › Version Control › Commit › Commit Message Generation gets Agent, Model and Effort dropdowns (vcs.commit.agent / agentModel / agentEffort, global or per project). Automatic keeps the current behaviour: the agent of the latest task on its model. A chosen agent runs on the chosen model and thinking level when it offers them, and the chat's model is no longer involved. The lists come from the agent's model catalog. Closes #4467 --- crates/ide-core/src/workflow_settings.rs | 9 ++ crates/ide-workspace/src/settings.rs | 3 + src/bindings.ts | 6 ++ src/features/agents/commitMessage.test.ts | 67 ++++++++++++ src/features/agents/commitMessage.ts | 71 +++++++++++-- src/features/settings/pages/vcs.tsx | 118 ++++++++++++++++++++++ src/platform/locales/text/en.json | 6 +- src/platform/locales/text/zh.json | 6 +- src/platform/workflowSettings.ts | 12 +++ 9 files changed, 287 insertions(+), 11 deletions(-) diff --git a/crates/ide-core/src/workflow_settings.rs b/crates/ide-core/src/workflow_settings.rs index 06c41a2a3a..816a0281a6 100644 --- a/crates/ide-core/src/workflow_settings.rs +++ b/crates/ide-core/src/workflow_settings.rs @@ -170,6 +170,12 @@ pub struct CommitSettings { pub double_click_opens_diff: Option, /// Team conventions for Generate Commit Message with Agent, added to its prompt. pub agent_instructions: String, + /// The coding agent Generate Commit Message with Agent uses; empty follows the latest task's agent. + pub agent: String, + /// That agent's model for commit messages; empty keeps the model the agent would use. + pub agent_model: String, + /// That model's thinking level for commit messages; empty keeps the agent's. + pub agent_effort: String, } impl Default for CommitSettings { @@ -192,6 +198,9 @@ impl Default for CommitSettings { disabled_plugin_checks: Vec::new(), double_click_opens_diff: None, agent_instructions: String::new(), + agent: String::new(), + agent_model: String::new(), + agent_effort: String::new(), } } } diff --git a/crates/ide-workspace/src/settings.rs b/crates/ide-workspace/src/settings.rs index d6b1526e35..f2e0132435 100644 --- a/crates/ide-workspace/src/settings.rs +++ b/crates/ide-workspace/src/settings.rs @@ -847,6 +847,9 @@ mod tests { "disabledPluginChecks": [], "doubleClickOpensDiff": null, "agentInstructions": "", + "agent": "", + "agentModel": "", + "agentEffort": "", }) ); } diff --git a/src/bindings.ts b/src/bindings.ts index 9e7361bded..1b71849586 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -3745,6 +3745,12 @@ export type CommitSettings = { doubleClickOpensDiff?: boolean | null, /** Team conventions for Generate Commit Message with Agent, added to its prompt. */ agentInstructions?: string, + /** The coding agent Generate Commit Message with Agent uses; empty follows the latest task's agent. */ + agent?: string, + /** That agent's model for commit messages; empty keeps the model the agent would use. */ + agentModel?: string, + /** That model's thinking level for commit messages; empty keeps the agent's. */ + agentEffort?: string, }; export type Commit_Deserialize = { diff --git a/src/features/agents/commitMessage.test.ts b/src/features/agents/commitMessage.test.ts index 8e604e5c6a..5650be3534 100644 --- a/src/features/agents/commitMessage.test.ts +++ b/src/features/agents/commitMessage.test.ts @@ -274,6 +274,73 @@ describe("pickAgent", () => { }); }); +describe("pickAgent with an agent chosen for commit messages", () => { + const effort: AgentConfigOption = { + id: "effort", + name: "Effort", + description: null, + category: "thought_level", + current: "high", + values: ["low", "high"].map((value) => ({ value, name: value, description: null })), + via: "option", + }; + const claude = { ...provider("claude", true, [modelOption("smart")]), thoughtLevels: { fast: [effort] } }; + const tasks = [ + task("a", "claude", { updatedMs: 1, config: [modelOption("smart")] }), + task("b", "codex", { updatedMs: 5 }), + ]; + const prefer = (agent: string, model = "", level = "") => ({ agent, agentModel: model, agentEffort: level }); + + it("uses that agent over the latest task's, on the model of its own latest task", () => { + expect(pickAgent(tasks, [claude, provider("codex")], draft("codex"), prefer("claude"))).toEqual({ + provider: "claude", + config: [{ id: "model", value: "smart" }], + }); + }); + + it("runs the chosen model at the chosen effort", () => { + expect(pickAgent(tasks, [claude, provider("codex")], draft("codex"), prefer("claude", "fast", "low"))).toEqual({ + provider: "claude", + config: [ + { id: "model", value: "fast" }, + { id: "effort", value: "low" }, + ], + }); + }); + + it("reads the models from the agent's refreshed catalog", () => { + const catalog = { + config: [{ ...modelOption("smart"), values: [{ value: "mini", name: "mini", description: null }] }], + thoughtLevels: { mini: [effort] }, + }; + expect( + pickAgent([], [claude], draft("claude"), prefer("claude", "mini", "low"), new Map([["claude", catalog]])), + ).toEqual({ + provider: "claude", + config: [ + { id: "model", value: "mini" }, + { id: "effort", value: "low" }, + ], + }); + }); + + it("keeps the agent's model and effort for values it doesn't offer", () => { + expect(pickAgent([], [claude], draft("claude"), prefer("claude", "gone", "low"))).toEqual({ + provider: "claude", + config: [{ id: "model", value: "smart" }], + }); + }); + + it("follows the latest task when the chosen agent isn't installed", () => { + expect( + pickAgent(tasks, [provider("claude", false), provider("codex")], draft("codex"), prefer("claude", "fast")), + ).toEqual({ + provider: "codex", + config: [], + }); + }); +}); + describe("generateCommitMessage", () => { const changes = { revision: 3, roots: ["/p"], patch: PATCH }; const notified = () => backend.notify.mock.calls.map(([n]) => n as { level: string; title: string; body?: string }); diff --git a/src/features/agents/commitMessage.ts b/src/features/agents/commitMessage.ts index d940e6b4d4..356d2dd70d 100644 --- a/src/features/agents/commitMessage.ts +++ b/src/features/agents/commitMessage.ts @@ -3,7 +3,14 @@ * changes about to be committed and writes their message. It runs as a short task that * is deleted once the message is in the commit field. */ -import type { AgentConfigChoice, AgentConfigOption, AgentEntry, AgentProvider, AgentTask } from "@/bindings"; +import type { + AgentConfigChoice, + AgentConfigOption, + AgentEntry, + AgentModelCatalog, + AgentProvider, + AgentTask, +} from "@/bindings"; import { executeAction } from "@/platform/actions"; import { tx } from "@/platform/i18n"; import { call, commands } from "@/platform/ipc"; @@ -139,28 +146,74 @@ export function askingChoices(options: readonly AgentConfigOption[]): AgentConfi const choicesFor = (options: readonly AgentConfigOption[]) => [...modelChoice(options), ...askingChoices(options)]; +/** Settings › Version Control › Commit: the agent, model and thinking level to generate with; empty follows the agent. */ +export interface CommitAgentPreference { + agent: string; + agentModel: string; + agentEffort: string; +} + +type ModelCatalog = Pick; + /** * The agent that wrote the code: the one of the project's latest task, on the model it - * ran with. Without a task, the one the New Task page has selected. + * ran with. Without a task, the one the New Task page has selected. An agent chosen in + * the settings replaces it, on the model and thinking level chosen there when it offers them. */ export function pickAgent( tasks: Iterable, providers: readonly AgentProvider[], draft: Draft, + preference?: CommitAgentPreference, + catalogs?: ReadonlyMap, ): CommitAgent | null { const installed = providers.filter((p) => p.installed); + const chosen = preference?.agent ? installed.find((p) => p.id === preference.agent) : undefined; + const candidates = chosen ? [chosen] : installed; const latest = [...tasks] - .filter((t) => t.status !== "archived" && installed.some((p) => p.id === t.provider)) + .filter((t) => t.status !== "archived" && candidates.some((p) => p.id === t.provider)) .sort((a, b) => (b.updatedMs ?? 0) - (a.updatedMs ?? 0))[0]; - if (latest) return { provider: latest.provider, config: choicesFor(latest.config) }; - const provider = installed.find((p) => p.id === draft.provider) ?? installed[0]; + const provider = latest + ? installed.find((p) => p.id === latest.provider)! + : (chosen ?? installed.find((p) => p.id === draft.provider) ?? installed[0]); if (!provider) return null; + const options = latest + ? latest.config + : provider.id === draft.provider + ? draftConfig(provider, draft) + : provider.config; + if (!chosen || !preference || (!preference.agentModel && !preference.agentEffort)) { + return { provider: provider.id, config: choicesFor(options) }; + } return { provider: provider.id, - config: choicesFor(provider.id === draft.provider ? draftConfig(provider, draft) : provider.config), + config: [...preferredModel(options, provider, preference, catalogs?.get(provider.id)), ...askingChoices(options)], }; } +/** The model and thinking level of `preference` that the agent offers, else the ones it would run with. */ +function preferredModel( + options: readonly AgentConfigOption[], + provider: AgentProvider, + preference: CommitAgentPreference, + catalog: ModelCatalog | undefined, +): AgentConfigChoice[] { + const offered = (catalog?.config ?? provider.config).find((o) => o.category === "model"); + const fallback = modelChoice(options); + const model = + offered && preference.agentModel && offered.values.some((v) => v.value === preference.agentModel) + ? { id: offered.id, value: preference.agentModel } + : fallback[0]; + if (!model) return []; + const levels = (catalog?.thoughtLevels ?? provider.thoughtLevels)?.[model.value] ?? []; + const level = levels.find((o) => o.category === "thought_level"); + const effort = + level && preference.agentEffort && level.values.some((v) => v.value === preference.agentEffort) + ? [{ id: level.id, value: preference.agentEffort }] + : []; + return [model, ...effort]; +} + /** Resolves when the task's turn ends; rejects when it can't produce an answer. */ function turnEnd(task: string): Promise { return new Promise((resolve, reject) => { @@ -243,8 +296,9 @@ async function generate(): Promise { notify({ level: "info", title: "No changes to describe", body: "Include changes in the commit first." }); return; } - const { tasks, providers, draft } = useAgents.getState(); - const agent = pickAgent(tasks.values(), providers, draft); + const { commit } = workflowSettings().vcs; + const { tasks, providers, draft, modelCatalogs } = useAgents.getState(); + const agent = pickAgent(tasks.values(), providers, draft, commit, modelCatalogs); if (!agent) { notify({ level: "warning", @@ -255,7 +309,6 @@ async function generate(): Promise { return; } - const { commit } = workflowSettings().vcs; const subjects = await recentSubjects(changes.roots[0]); const prompt = commitMessagePrompt( changes.patch, diff --git a/src/features/settings/pages/vcs.tsx b/src/features/settings/pages/vcs.tsx index 4ef1239f87..d27ff8cf8b 100644 --- a/src/features/settings/pages/vcs.tsx +++ b/src/features/settings/pages/vcs.tsx @@ -14,6 +14,7 @@ import { Button, Icon, IconButton, Input, Select, type SelectOption, T } from "@ import { choosePath } from "@/platform/choosePath"; import { Row, SettingSelect } from "../components/Form"; import { useSetting } from "../components/context"; +import type { AgentModelCatalog, AgentProvider } from "@/bindings"; import type { PageSpec } from "./spec"; import { BoundToggle, Grid, Indented, RadioRow, TableEditor, ToggleNumber } from "./workflowControls"; import styles from "./Workflow.module.css"; @@ -378,6 +379,117 @@ function MessageLimits() { ); } +const AUTOMATIC = ""; + +/** The installed coding agents, as the agents feature reports them; empty where agents can't run. */ +function useInstalledAgents(): AgentProvider[] { + const [agents, setAgents] = useState([]); + useEffect(() => { + if (!isTauri()) return; + let live = true; + call(commands.agentProviders()) + .then((all) => live && setAgents(all.filter((p) => p.installed))) + .catch(() => {}); + return () => { + live = false; + }; + }, []); + return agents; +} + +type ModelCatalog = Pick; + +/** The models `agent` offers, from its catalog; asks the agent for it once when it hasn't reported one. */ +function useModelCatalog(agent: AgentProvider | undefined): ModelCatalog | undefined { + const [catalog, setCatalog] = useState<{ provider: string } & ModelCatalog>(); + const id = agent?.id; + useEffect(() => { + if (!id) return; + let live = true; + let timer: ReturnType | undefined; + let polls = 0; + const load = () => + call(commands.agentRefreshModels(id, false, null)) + .then((c) => { + if (!live) return; + setCatalog(c); + if (c.refreshing && ++polls < CATALOG_POLLS) timer = setTimeout(load, CATALOG_POLL_MS); + }) + .catch(() => {}); + void load(); + return () => { + live = false; + clearTimeout(timer); + }; + }, [id]); + if (!agent) return undefined; + const fresh = catalog?.provider === agent.id && catalog.config.some((o) => o.category === "model"); + return fresh ? catalog : { config: agent.config, thoughtLevels: agent.thoughtLevels ?? {} }; +} + +const CATALOG_POLL_MS = 1_500; +const CATALOG_POLLS = 40; + +/** `values` as options after `automatic`, keeping a saved value the agent no longer lists. */ +function choiceOptions( + automatic: string, + values: readonly { value: string; name: string }[], + saved: string, +): SelectOption[] { + const options = [{ value: AUTOMATIC, label: automatic }, ...values.map((v) => ({ value: v.value, label: v.name }))]; + return saved && !values.some((v) => v.value === saved) ? [...options, { value: saved, label: saved }] : options; +} + +function CommitAgentRows() { + const agents = useInstalledAgents(); + const [agent, setAgent] = useSetting("vcs.commit.agent"); + const [model, setModel] = useSetting("vcs.commit.agentModel"); + const [effort, setEffort] = useSetting("vcs.commit.agentEffort"); + const catalog = useModelCatalog(agents.find((p) => p.id === agent)); + const models = catalog?.config.find((o) => o.category === "model"); + const shown = model || models?.current; + const levels = (shown ? catalog?.thoughtLevels[shown] : undefined)?.find((o) => o.category === "thought_level"); + const agentOptions = choiceOptions( + tx("Automatic (the agent of the latest task)"), + agents.map((p) => ({ value: p.id, name: p.name })), + agent, + ); + const pick = (next: string) => { + if (next === agent) return; + setAgent(next); + setModel(AUTOMATIC); + setEffort(AUTOMATIC); + }; + return ( + <> + + { + setModel(next); + setEffort(AUTOMATIC); + }} + disabled={!agent} + aria-label={tx("Model")} + /> + + +