fix(agents): the generated commit message describes exactly what would be committed

The diff sent to the agent was every included file's whole working-tree change. With the staging area, or blocks left out of a partial commit, it also held changes the commit leaves out. It is now made the way Commit makes the commit (the index with the selection applied, partial files' chosen blocks only), through the new `vcs_pending_patch` command.

Before filling in the message, the changes are read again: a file edited and saved while the agent worked, which changes neither the message nor the inclusion, no longer gets a message written for its earlier content.
This commit is contained in:
l0ng-ai
2026-11-17 09:57:58 +08:00
parent dfbe87161b
commit 0cd7d9c30e
11 changed files with 84 additions and 27 deletions
+9 -1
View File
@@ -273,7 +273,15 @@ async function generate(): Promise<void> {
await turnEnd(created.id);
const message = commitMessageOf(replyOf(await call(commands.agentEntries(created.id, null))));
if (!message) throw new Error(tx("The agent did not reply with a commit message"));
if (!service.setMessage(changes.revision, message)) {
// The files may have been edited since without touching the draft: the message must
// still describe what would be committed.
const unchanged = async () => {
if (service.revision() !== changes.revision) return null;
const now = await service.changes().catch(() => null);
return now && now.patch === changes.patch ? now.revision : null;
};
const at = await unchanged();
if (at === null || !service.setMessage(at, message)) {
notify({
level: "info",
title: "Commit message not replaced",