Compare commits

..
Author SHA1 Message Date
l0ng-ai 9658fadd4f fix(format): keep the caret when a language server replaces the whole file
Vue's language server (Volar) answers Reformat Code with a single edit that
replaces the whole document. Applied as is, the caret and the scroll position
jump to the top of the file. Multi-line LSP formatting edits are now reduced to
one edit per changed region (via Document::diff) before they reach the editor,
so the caret and view stay where they were for every server that does this.
2026-11-19 19:05:05 +08:00
9 changed files with 11 additions and 287 deletions

No files matched your search

-9
View File
@@ -170,12 +170,6 @@ 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 {
@@ -198,9 +192,6 @@ 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
View File
@@ -847,9 +847,6 @@ mod tests {
"disabledPluginChecks": [],
"doubleClickOpensDiff": null,
"agentInstructions": "",
"agent": "",
"agentModel": "",
"agentEffort": "",
})
);
}
-6
View File
@@ -3745,12 +3745,6 @@ 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
View File
@@ -274,73 +274,6 @@ 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 });
+9 -62
View File
@@ -3,14 +3,7 @@
* 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,
AgentModelCatalog,
AgentProvider,
AgentTask,
} from "@/bindings";
import type { AgentConfigChoice, AgentConfigOption, AgentEntry, AgentProvider, AgentTask } from "@/bindings";
import { executeAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import { call, commands } from "@/platform/ipc";
@@ -146,74 +139,28 @@ 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. An agent chosen in
* the settings replaces it, on the model and thinking level chosen there when it offers them.
* ran with. Without a task, the one the New Task page has selected.
*/
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" && candidates.some((p) => p.id === t.provider))
.filter((t) => t.status !== "archived" && installed.some((p) => p.id === t.provider))
.sort((a, b) => (b.updatedMs ?? 0) - (a.updatedMs ?? 0))[0];
const provider = latest
? installed.find((p) => p.id === latest.provider)!
: (chosen ?? installed.find((p) => p.id === draft.provider) ?? installed[0]);
if (latest) return { provider: latest.provider, config: choicesFor(latest.config) };
const provider = 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: [...preferredModel(options, provider, preference, catalogs?.get(provider.id)), ...askingChoices(options)],
config: choicesFor(provider.id === draft.provider ? draftConfig(provider, draft) : provider.config),
};
}
/** 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) => {
@@ -296,9 +243,8 @@ async function generate(): Promise<void> {
notify({ level: "info", title: "No changes to describe", body: "Include changes in the commit first." });
return;
}
const { commit } = workflowSettings().vcs;
const { tasks, providers, draft, modelCatalogs } = useAgents.getState();
const agent = pickAgent(tasks.values(), providers, draft, commit, modelCatalogs);
const { tasks, providers, draft } = useAgents.getState();
const agent = pickAgent(tasks.values(), providers, draft);
if (!agent) {
notify({
level: "warning",
@@ -309,6 +255,7 @@ async function generate(): Promise<void> {
return;
}
const { commit } = workflowSettings().vcs;
const subjects = await recentSubjects(changes.roots[0]);
const prompt = commitMessagePrompt(
changes.patch,
-118
View File
@@ -14,7 +14,6 @@ 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";
@@ -379,117 +378,6 @@ 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();
@@ -643,12 +531,6 @@ 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",
+1 -5
View File
@@ -2648,9 +2648,5 @@
"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).",
"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."
"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)."
}
+1 -5
View File
@@ -9027,9 +9027,5 @@
"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)。",
"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.": "提交信息很短,通常用快速模型配低推理强度就够了。"
"Checks remote repositories for newer SNAPSHOT dependencies on every sync, build and run (-U).": "每次同步、构建和运行时都检查远程仓库中是否有更新的 SNAPSHOT 依赖(-U)。"
}
-12
View File
@@ -62,12 +62,6 @@ 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 {
@@ -306,9 +300,6 @@ export const DEFAULT_WORKFLOW: WorkflowSettings = {
disabledPluginChecks: [],
doubleClickOpensDiff: null,
agentInstructions: "",
agent: "",
agentModel: "",
agentEffort: "",
},
confirmation: {
onCreate: "ask",
@@ -474,9 +465,6 @@ 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),