fix: Use absolute paths and git add -u in post-completion commit resume
Prevents two bugs in the resumeForCommit flow: 1. Agent navigated to main repo instead of worktree due to relative paths in commit prompt — now uses absolute paths from getDirtyWorktreePaths 2. git add -A staged unrelated files (screenshots, other agents' work) — now uses git add -u to only stage tracked modified files
This commit is contained in:
@@ -222,7 +222,7 @@ export class CleanupManager {
|
||||
* Get the relative subdirectory names of dirty worktrees for an agent.
|
||||
* Returns an empty array if all worktrees are clean or the workdir doesn't exist.
|
||||
*/
|
||||
async getDirtyWorktreePaths(alias: string, initiativeId: string | null): Promise<string[]> {
|
||||
async getDirtyWorktreePaths(alias: string, initiativeId: string | null): Promise<{ name: string; absPath: string }[]> {
|
||||
const agentWorkdir = this.getAgentWorkdir(alias);
|
||||
|
||||
try {
|
||||
@@ -242,13 +242,13 @@ export class CleanupManager {
|
||||
worktreePaths.push({ absPath: join(agentWorkdir, 'workspace'), name: 'workspace' });
|
||||
}
|
||||
|
||||
const dirty: string[] = [];
|
||||
const dirty: { name: string; absPath: string }[] = [];
|
||||
for (const { absPath, name } of worktreePaths) {
|
||||
try {
|
||||
const { stdout } = await execFileAsync('git', ['status', '--porcelain'], { cwd: absPath });
|
||||
if (stdout.trim().length > 0) dirty.push(name);
|
||||
if (stdout.trim().length > 0) dirty.push({ name, absPath });
|
||||
} catch {
|
||||
dirty.push(name);
|
||||
dirty.push({ name, absPath });
|
||||
}
|
||||
}
|
||||
return dirty;
|
||||
|
||||
@@ -453,12 +453,16 @@ export class MultiProviderAgentManager implements AgentManager {
|
||||
const dirtyPaths = await this.cleanupManager.getDirtyWorktreePaths(agent.name, agent.initiativeId);
|
||||
if (dirtyPaths.length === 0) return false;
|
||||
|
||||
const dirtyList = dirtyPaths.map(p => `- \`${p}/\``).join('\n');
|
||||
// Use absolute paths so the agent can't accidentally commit in the main repo
|
||||
// Use `git add -u` (tracked files only) instead of `git add -A` to avoid staging unrelated files
|
||||
const dirtyList = dirtyPaths.map(p => `- \`${p.absPath}\``).join('\n');
|
||||
const commitPrompt =
|
||||
'You have uncommitted changes in the following project directories:\n' +
|
||||
'You have uncommitted changes in the following directories:\n' +
|
||||
dirtyList + '\n\n' +
|
||||
'For each directory listed above, `cd` into it, then run `git add -A && git commit -m "<message>"` ' +
|
||||
'with an appropriate commit message describing the work. Do not make any other changes.';
|
||||
'For each directory listed above, `cd` into the EXACT absolute path shown, then run:\n' +
|
||||
'1. `git add -u` to stage only tracked modified files\n' +
|
||||
'2. `git commit -m "<message>"` with a message describing the work\n' +
|
||||
'Do not use `git add -A` or `git add .`. Do not stage untracked files. Do not make any other changes.';
|
||||
|
||||
await this.repository.update(agentId, { status: 'running', pendingQuestions: null, result: null });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user