Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions packages/types/src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const historyItemSchema = z.object({
totalCost: z.number(),
size: z.number().optional(),
workspace: z.string().optional(),
mode: z.string().optional(),
})

export type HistoryItem = z.infer<typeof historyItemSchema>
3 changes: 3 additions & 0 deletions src/core/task-persistence/taskMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type TaskMetadataOptions = {
taskNumber: number
globalStoragePath: string
workspace: string
mode?: string
}

export async function taskMetadata({
Expand All @@ -26,6 +27,7 @@ export async function taskMetadata({
taskNumber,
globalStoragePath,
workspace,
mode,
}: TaskMetadataOptions) {
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)

Expand Down Expand Up @@ -92,6 +94,7 @@ export async function taskMetadata({
totalCost: tokenUsage.totalCost,
size: taskDirSize,
workspace,
mode,
}

return { historyItem, tokenUsage }
Expand Down
24 changes: 24 additions & 0 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class Task extends EventEmitter<ClineEvents> {
readonly parentTask: Task | undefined = undefined
readonly taskNumber: number
readonly workspacePath: string
taskMode: string

providerRef: WeakRef<ClineProvider>
private readonly globalStoragePath: string
Expand Down Expand Up @@ -268,12 +269,34 @@ export class Task extends EventEmitter<ClineEvents> {
this.parentTask = parentTask
this.taskNumber = taskNumber

// Store the task's mode when it's created
// For history items, use the stored mode; for new tasks, we'll set it after getting state
this.taskMode = historyItem?.mode || defaultModeSlug

if (historyItem) {
TelemetryService.instance.captureTaskRestarted(this.taskId)
} else {
TelemetryService.instance.captureTaskCreated(this.taskId)
}

// If no historyItem, get the current mode from provider
if (!historyItem && provider.getState) {
const statePromise = provider.getState()
// Check if getState() returns a Promise
if (statePromise && typeof statePromise.then === "function") {
statePromise
.then((state) => {
if (state?.mode) {
this.taskMode = state.mode
}
})
.catch((error) => {
// If there's an error getting state, keep the default mode
console.error("Failed to get mode from provider state:", error)
})
}
}

// Only set up diff strategy if diff is enabled
if (this.diffEnabled) {
// Default to old strategy, will be updated if experiment is enabled
Expand Down Expand Up @@ -411,6 +434,7 @@ export class Task extends EventEmitter<ClineEvents> {
taskNumber: this.taskNumber,
globalStoragePath: this.globalStoragePath,
workspace: this.cwd,
mode: this.taskMode, // Use the task's own mode, not the current provider mode
})

this.emit("taskTokenUsageUpdated", this.taskId, tokenUsage)
Expand Down
Loading