Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai f1ca1fc7a2 feat(vcs): choose the agent, model and effort for Generate Commit Message
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
2026-11-19 19:15:22 +08:00
9 змінених файлів з 287 додано та 11 видалено

No files matched your search

+9
Переглянути файл
@@ -170,6 +170,12 @@ pub struct CommitSettings {
pub double_click_opens_diff: Option<bool>,
/// 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(),
}
}
}
+3
Переглянути файл
@@ -847,6 +847,9 @@ mod tests {
"disabledPluginChecks": [],
"doubleClickOpensDiff": null,
"agentInstructions": "",
"agent": "",
"agentModel": "",
"agentEffort": "",
})
);
}
+6
Переглянути файл
@@ -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 = {
+67
Переглянути файл
@@ -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 });
+62 -9
Переглянути файл
@@ -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<AgentModelCatalog, "config" | "thoughtLevels">;
/**
* 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<AgentTask>,
providers: readonly AgentProvider[],
draft: Draft,
preference?: CommitAgentPreference,
catalogs?: ReadonlyMap<string, ModelCatalog>,
): 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<void> {
return new Promise((resolve, reject) => {
@@ -243,8 +296,9 @@ async function generate(): Promise<void> {
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<void> {
return;
}
const { commit } = workflowSettings().vcs;
const subjects = await recentSubjects(changes.roots[0]);
const prompt = commitMessagePrompt(
changes.patch,
+118
Переглянути файл
@@ -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<AgentProvider[]>([]);
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<AgentModelCatalog, "config" | "thoughtLevels">;
/** 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<typeof setTimeout> | 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<string>[] {
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<string>("vcs.commit.agent");
const [model, setModel] = useSetting<string>("vcs.commit.agentModel");
const [effort, setEffort] = useSetting<string>("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 (
<>
<Row label="Agent" hint="Commit messages are short: a fast model with low effort is usually enough.">
<Select value={agent} options={agentOptions} onChange={pick} aria-label={tx("Agent")} />
</Row>
<Row label="Model" disabled={!agent}>
<Select
value={model}
options={choiceOptions(tx("The agent's current model"), models?.values ?? [], model)}
onChange={(next) => {
setModel(next);
setEffort(AUTOMATIC);
}}
disabled={!agent}
aria-label={tx("Model")}
/>
</Row>
<Row label="Effort" disabled={!agent}>
<Select
value={effort}
options={choiceOptions(tx("The agent's default"), levels?.values ?? [], effort)}
onChange={setEffort}
disabled={!agent}
aria-label={tx("Effort")}
/>
</Row>
</>
);
}
function AgentInstructionsRow() {
const [value, set] = useSetting<string>("vcs.commit.agentInstructions");
const id = useId();
@@ -531,6 +643,12 @@ export const VCS_PAGES: PageSpec[] = [
{
title: "Commit Message Generation",
options: [
{
kind: "custom",
label: "Agent",
keywords: ["agent", "ai", "model", "effort", "thinking", "reasoning", "generate commit message"],
component: CommitAgentRows,
},
{
kind: "custom",
label: "Instructions for Generate Commit Message with Agent",
+5 -1
Переглянути файл
@@ -2648,5 +2648,9 @@
"Cannot export test results": "Cannot export test results",
"Test results exported": "Test results exported",
"Always update snapshots": "Always update snapshots",
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U)."
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).",
"Automatic (the agent of the latest task)": "Automatic (the agent of the latest task)",
"The agent's current model": "The agent's current model",
"The agent's default": "The agent's default",
"Commit messages are short: a fast model with low effort is usually enough.": "Commit messages are short: a fast model with low effort is usually enough."
}
+5 -1
Переглянути файл
@@ -9027,5 +9027,9 @@
"Cannot export test results": "无法导出测试结果",
"Test results exported": "测试结果已导出",
"Always update snapshots": "始终更新快照",
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "每次同步、构建和运行时都检查远程仓库中是否有更新的 SNAPSHOT 依赖(-U)。"
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "每次同步、构建和运行时都检查远程仓库中是否有更新的 SNAPSHOT 依赖(-U)。",
"Automatic (the agent of the latest task)": "自动(最近任务的智能体)",
"The agent's current model": "智能体当前的模型",
"The agent's default": "智能体的默认值",
"Commit messages are short: a fast model with low effort is usually enough.": "提交信息很短,通常用快速模型配低推理强度就够了。"
}
+12
Переглянути файл
@@ -62,6 +62,12 @@ export interface CommitSettingsValid {
doubleClickOpensDiff: boolean | null;
/** Team conventions for Generate Commit Message with Agent, added to its prompt. */
agentInstructions: string;
/** The 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 interface VcsSettingsValid {
@@ -300,6 +306,9 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = {
disabledPluginChecks: [],
doubleClickOpensDiff: null,
agentInstructions: "",
agent: "",
agentModel: "",
agentEffort: "",
},
confirmation: {
onCreate: "ask",
@@ -465,6 +474,9 @@ export function validateVcs(raw: unknown): VcsSettingsValid {
disabledPluginChecks: strings(c.disabledPluginChecks, d.commit.disabledPluginChecks),
doubleClickOpensDiff: tri(c.doubleClickOpensDiff),
agentInstructions: text(c.agentInstructions, d.commit.agentInstructions),
agent: text(c.agent, d.commit.agent),
agentModel: text(c.agentModel, d.commit.agentModel),
agentEffort: text(c.agentEffort, d.commit.agentEffort),
},
confirmation: {
onCreate: oneOf(conf.onCreate, confirm, d.confirmation.onCreate),