Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/giant-buckets-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Introduces AI contribution tracking so users can better understand agentic coding impact
27 changes: 27 additions & 0 deletions src/core/tools/ApplyDiffTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { computeDiffStats, sanitizeUnifiedDiff } from "../diff/stats"
import { BaseTool, ToolCallbacks } from "./BaseTool"
import type { ToolUse } from "../../shared/tools"
import { trackContribution } from "../../services/contribution-tracking/ContributionTrackingService" // kilocode_change

interface ApplyDiffParams {
path: string
Expand Down Expand Up @@ -175,6 +176,19 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {

const didApprove = await askApproval("tool", completeMessage, toolProgressStatus, isWriteProtected)

// kilocode_change start
// Track contribution (fire-and-forget, never blocks user workflow)
Comment thread
jrf0110 marked this conversation as resolved.
trackContribution({
cwd: task.cwd,
filePath: relPath,
unifiedDiff: unifiedPatch,
status: didApprove ? "accepted" : "rejected",
taskId: task.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
})
// kilocode_change end

Comment thread
jrf0110 marked this conversation as resolved.
if (!didApprove) {
return
}
Expand Down Expand Up @@ -219,6 +233,19 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {

const didApprove = await askApproval("tool", completeMessage, toolProgressStatus, isWriteProtected)

// kilocode_change start
// Track contribution (fire-and-forget, never blocks user workflow)
Comment thread
jrf0110 marked this conversation as resolved.
trackContribution({
cwd: task.cwd,
filePath: relPath,
unifiedDiff: unifiedPatch,
status: didApprove ? "accepted" : "rejected",
taskId: task.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
})
// kilocode_change end

Comment thread
jrf0110 marked this conversation as resolved.
if (!didApprove) {
await task.diffViewProvider.revertChanges()
task.processQueuedMessages()
Expand Down
29 changes: 29 additions & 0 deletions src/core/tools/MultiApplyDiffTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { applyDiffTool as applyDiffToolClass } from "./ApplyDiffTool"
import { computeDiffStats, sanitizeUnifiedDiff } from "../diff/stats"
import { isNativeProtocol } from "@roo-code/types"
import { resolveToolProtocol } from "../../utils/resolveToolProtocol"
import { trackContribution } from "../../services/contribution-tracking/ContributionTrackingService" // kilocode_change

export interface DiffOperation {
path: string
Expand Down Expand Up @@ -638,6 +639,19 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
const isWriteProtected = cline.rooProtectedController?.isWriteProtected(relPath) || false
didApprove = await askApproval("tool", operationMessage, toolProgressStatus, isWriteProtected)

// kilocode_change start
// Track contribution for single file operation (fire-and-forget)
Comment thread
jrf0110 marked this conversation as resolved.
trackContribution({
cwd: cline.cwd,
filePath: relPath,
unifiedDiff: unifiedPatch,
status: didApprove ? "accepted" : "rejected",
taskId: cline.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
Comment thread
jrf0110 marked this conversation as resolved.
})
// kilocode_change end

Comment thread
jrf0110 marked this conversation as resolved.
if (!didApprove) {
// Revert changes if diff view was shown
if (!isPreventFocusDisruptionEnabled) {
Expand All @@ -663,6 +677,21 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
}
} else {
// Batch operations - already approved above
// kilocode_change start
// Track contribution for batch file operation (fire-and-forget)
const unifiedPatchRaw = formatResponse.createPrettyPatch(relPath, beforeContent!, originalContent!)
const unifiedPatch = sanitizeUnifiedDiff(unifiedPatchRaw)
trackContribution({
cwd: cline.cwd,
filePath: relPath,
unifiedDiff: unifiedPatch,
status: "accepted", // Batch operations are already approved at this point
taskId: cline.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
})
// kilocode_change end

if (isPreventFocusDisruptionEnabled) {
// Direct file write without diff view or opening the file
cline.diffViewProvider.editType = "modify"
Expand Down
27 changes: 27 additions & 0 deletions src/core/tools/WriteToFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
import { convertNewFileToUnifiedDiff, computeDiffStats, sanitizeUnifiedDiff } from "../diff/stats"
import { BaseTool, ToolCallbacks } from "./BaseTool"
import type { ToolUse } from "../../shared/tools"
import { trackContribution } from "../../services/contribution-tracking/ContributionTrackingService" // kilocode_change

interface WriteToFileParams {
path: string
Expand Down Expand Up @@ -142,6 +143,19 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {

const didApprove = await askApproval("tool", completeMessage, undefined, isWriteProtected)

// kilocode_change start
// Track contribution (fire-and-forget, never blocks user workflow)
Comment thread
jrf0110 marked this conversation as resolved.
trackContribution({
cwd: task.cwd,
filePath: relPath,
unifiedDiff: unified,
status: didApprove ? "accepted" : "rejected",
taskId: task.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
})
// kilocode_change end

Comment thread
jrf0110 marked this conversation as resolved.
if (!didApprove) {
return
}
Expand Down Expand Up @@ -174,6 +188,19 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {

const didApprove = await askApproval("tool", completeMessage, undefined, isWriteProtected)

// kilocode_change start
// Track contribution (fire-and-forget, never blocks user workflow)
Comment thread
jrf0110 marked this conversation as resolved.
trackContribution({
cwd: task.cwd,
filePath: relPath,
unifiedDiff: unified,
status: didApprove ? "accepted" : "rejected",
taskId: task.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
})
// kilocode_change end

Comment thread
jrf0110 marked this conversation as resolved.
if (!didApprove) {
await task.diffViewProvider.revertChanges()
return
Expand Down
17 changes: 17 additions & 0 deletions src/core/tools/kilocode/editFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { TelemetryService } from "@roo-code/telemetry"
import { type ClineProviderState } from "../../webview/ClineProvider"
import { ClineSayTool } from "../../../shared/ExtensionMessage"
import { X_KILOCODE_ORGANIZATIONID, X_KILOCODE_TASKID, X_KILOCODE_TESTER } from "../../../shared/kilocode/headers"
import { trackContribution } from "../../../services/contribution-tracking/ContributionTrackingService"
import { sanitizeUnifiedDiff } from "../../diff/stats"
Comment thread
jrf0110 marked this conversation as resolved.

const FAST_APPLY_MODEL_PRICING = {
"morph-v3-fast": {
Expand Down Expand Up @@ -179,6 +181,21 @@ export async function editFileTool(
cline.rooProtectedController?.isWriteProtected(relPath) || false,
)

// Track contribution (fire-and-forget, never blocks user workflow)
const provider = cline.providerRef.deref()
const state = await provider?.getState()
const unifiedPatchRaw = formatResponse.createPrettyPatch(relPath, originalContent, newContent)
const unifiedPatch = sanitizeUnifiedDiff(unifiedPatchRaw)
trackContribution({
cwd: cline.cwd,
filePath: relPath,
unifiedDiff: unifiedPatch,
status: approved ? "accepted" : "rejected",
taskId: cline.taskId,
organizationId: state?.apiConfiguration?.kilocodeOrganizationId,
kilocodeToken: state?.apiConfiguration?.kilocodeToken || "",
Comment thread
jrf0110 marked this conversation as resolved.
})

if (!approved) {
await cline.diffViewProvider.revertChanges()
return
Expand Down
Loading