Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/tools/ApplyDiffTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { computeDiffStats, sanitizeUnifiedDiff } from "../diff/stats"
import type { ToolUse } from "../../shared/tools"

import { gitAiBeforeEdit, gitAiAfterEdit } from "../../services/git-ai"

import { BaseTool, ToolCallbacks } from "./BaseTool"

interface ApplyDiffParams {
Expand Down Expand Up @@ -176,15 +178,19 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {
// Save directly without showing diff view or opening the file
task.diffViewProvider.editType = "modify"
task.diffViewProvider.originalContent = originalContent
await gitAiBeforeEdit(task.cwd, [relPath])
await task.diffViewProvider.saveDirectly(
relPath,
diffResult.content,
false,
diagnosticsEnabled,
writeDelayMs,
)
await gitAiAfterEdit(task.cwd, task, [relPath])
} else {
// Original behavior with diff view
await gitAiBeforeEdit(task.cwd, [relPath])

// Show diff view before asking for approval
task.diffViewProvider.editType = "modify"
await task.diffViewProvider.open(relPath)
Expand Down Expand Up @@ -222,6 +228,7 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {

// Call saveChanges to update the DiffViewProvider properties
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
await gitAiAfterEdit(task.cwd, task, [relPath])
}

// Track file edit operation
Expand Down
11 changes: 11 additions & 0 deletions src/core/tools/ApplyPatchTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { RecordSource } from "../context-tracking/FileContextTrackerTypes"
import { fileExistsAtPath } from "../../utils/fs"
import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { sanitizeUnifiedDiff, computeDiffStats } from "../diff/stats"
import { gitAiBeforeEdit, gitAiAfterEdit } from "../../services/git-ai"

import { BaseTool, ToolCallbacks } from "./BaseTool"
import type { ToolUse } from "../../shared/tools"
import { parsePatch, ParseError, processAllHunks } from "./apply-patch"
Expand Down Expand Up @@ -195,6 +197,8 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
diffStats,
} satisfies ClineSayTool)

await gitAiBeforeEdit(task.cwd, [relPath])

// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)
Expand All @@ -219,6 +223,7 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
} else {
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
}
await gitAiAfterEdit(task.cwd, task, [relPath])

// Track file edit operation
await task.fileContextTracker.trackFileContext(relPath, "roo_edited" as RecordSource)
Expand Down Expand Up @@ -273,6 +278,7 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
}

// Delete the file
await gitAiBeforeEdit(task.cwd, [relPath])
try {
await fs.unlink(absolutePath)
} catch (error) {
Expand All @@ -281,6 +287,7 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
pushToolResult(formatResponse.toolError(errorMessage))
return
}
await gitAiAfterEdit(task.cwd, task, [relPath])

task.didEditFile = true
pushToolResult(`Successfully deleted ${relPath}`)
Expand Down Expand Up @@ -352,6 +359,8 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
diffStats,
} satisfies ClineSayTool)

await gitAiBeforeEdit(task.cwd, [relPath])

// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)
Expand Down Expand Up @@ -429,6 +438,7 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
} catch (error) {
console.error(`Failed to delete original file after move: ${error}`)
}
await gitAiAfterEdit(task.cwd, task, [relPath, change.movePath])

await task.fileContextTracker.trackFileContext(change.movePath, "roo_edited" as RecordSource)
} else {
Expand All @@ -438,6 +448,7 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> {
} else {
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
}
await gitAiAfterEdit(task.cwd, task, [relPath])

await task.fileContextTracker.trackFileContext(relPath, "roo_edited" as RecordSource)
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/tools/EditFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { sanitizeUnifiedDiff, computeDiffStats } from "../diff/stats"
import type { ToolUse } from "../../shared/tools"

import { gitAiBeforeEdit, gitAiAfterEdit } from "../../services/git-ai"

import { BaseTool, ToolCallbacks } from "./BaseTool"

interface EditFileParams {
Expand Down Expand Up @@ -415,6 +417,8 @@ export class EditFileTool extends BaseTool<"edit_file"> {
diffStats,
} satisfies ClineSayTool)

await gitAiBeforeEdit(task.cwd, [relPath])

// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)
Expand Down Expand Up @@ -448,6 +452,7 @@ export class EditFileTool extends BaseTool<"edit_file"> {
// Call saveChanges to update the DiffViewProvider properties
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
}
await gitAiAfterEdit(task.cwd, task, [relPath])

// Track file edit operation
if (relPath) {
Expand Down
5 changes: 5 additions & 0 deletions src/core/tools/EditTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { sanitizeUnifiedDiff, computeDiffStats } from "../diff/stats"
import type { ToolUse } from "../../shared/tools"

import { gitAiBeforeEdit, gitAiAfterEdit } from "../../services/git-ai"

import { BaseTool, ToolCallbacks } from "./BaseTool"

interface EditParams {
Expand Down Expand Up @@ -190,6 +192,8 @@ export class EditTool extends BaseTool<"edit"> {
diffStats,
} satisfies ClineSayTool)

await gitAiBeforeEdit(task.cwd, [relPath])

// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)
Expand Down Expand Up @@ -217,6 +221,7 @@ export class EditTool extends BaseTool<"edit"> {
// Call saveChanges to update the DiffViewProvider properties
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
}
await gitAiAfterEdit(task.cwd, task, [relPath])

// Track file edit operation
if (relPath) {
Expand Down
5 changes: 5 additions & 0 deletions src/core/tools/SearchReplaceTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { sanitizeUnifiedDiff, computeDiffStats } from "../diff/stats"
import type { ToolUse } from "../../shared/tools"

import { gitAiBeforeEdit, gitAiAfterEdit } from "../../services/git-ai"

import { BaseTool, ToolCallbacks } from "./BaseTool"

interface SearchReplaceParams {
Expand Down Expand Up @@ -186,6 +188,8 @@ export class SearchReplaceTool extends BaseTool<"search_replace"> {
diffStats,
} satisfies ClineSayTool)

await gitAiBeforeEdit(task.cwd, [relPath])

// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)
Expand Down Expand Up @@ -213,6 +217,7 @@ export class SearchReplaceTool extends BaseTool<"search_replace"> {
// Call saveChanges to update the DiffViewProvider properties
await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
}
await gitAiAfterEdit(task.cwd, task, [relPath])

// Track file edit operation
if (relPath) {
Expand Down
19 changes: 19 additions & 0 deletions src/core/tools/WriteToFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { convertNewFileToUnifiedDiff, computeDiffStats, sanitizeUnifiedDiff } from "../diff/stats"
import type { ToolUse } from "../../shared/tools"

import { gitAiBeforeEdit, gitAiAfterEdit } from "../../services/git-ai"

import { BaseTool, ToolCallbacks } from "./BaseTool"

interface WriteToFileParams {
Expand All @@ -25,6 +27,12 @@ interface WriteToFileParams {

export class WriteToFileTool extends BaseTool<"write_to_file"> {
readonly name = "write_to_file" as const
private didGitAiBeforeEdit = false

override resetPartialState(): void {
super.resetPartialState()
this.didGitAiBeforeEdit = false
}

async execute(params: WriteToFileParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
const { pushToolResult, handleError, askApproval } = callbacks
Expand Down Expand Up @@ -133,8 +141,14 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
return
}

await gitAiBeforeEdit(task.cwd, [relPath])
await task.diffViewProvider.saveDirectly(relPath, newContent, false, diagnosticsEnabled, writeDelayMs)
await gitAiAfterEdit(task.cwd, task, [relPath])
} else {
if (!this.didGitAiBeforeEdit) {
await gitAiBeforeEdit(task.cwd, [relPath])
}

if (!task.diffViewProvider.isEditing) {
const partialMessage = JSON.stringify(sharedMessageProps)
await task.ask("tool", partialMessage, true).catch(() => {})
Expand Down Expand Up @@ -167,6 +181,7 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
}

await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs)
await gitAiAfterEdit(task.cwd, task, [relPath])
}

if (relPath) {
Expand Down Expand Up @@ -246,6 +261,10 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {

if (newContent) {
if (!task.diffViewProvider.isEditing) {
if (!this.didGitAiBeforeEdit) {
await gitAiBeforeEdit(task.cwd, [relPath!])
this.didGitAiBeforeEdit = true
}
await task.diffViewProvider.open(relPath!)
}

Expand Down
Loading
Loading