Move rest of state to cache (#5404)

* move rest of state to cacheService

* finish moving state to cache

* remove console logs

* fix types

* don't type cast

* add eslint rule banning use of direct storage apis

* fix types

* move vscode state eslint rule to separate rule since it's error and the others aren't

* fix eslint rules parsing
This commit is contained in:
celestial-vault authored and GitHub committed 2025-08-11 14:46:39 -07:00
1 parent 2aa5156905
commit 669e018b85
52 files changed
+1472 -1096

No files matched your search

@@ -2,10 +2,10 @@ import path from "path"
import fs from "fs/promises"
import { Controller } from ".."
import { DeleteAllTaskHistoryCount } from "@shared/proto/cline/task"
import { getGlobalState, updateGlobalState } from "../../storage/state"
import { fileExistsAtPath } from "../../../utils/fs"
import { ShowMessageRequest, ShowMessageType } from "@/shared/proto/host/window"
import { HostProvider } from "@/hosts/host-provider"
import { HistoryItem } from "@/shared/HistoryItem"
/**
* Deletes all task history, with an option to preserve favorites
@@ -19,7 +19,7 @@ export async function deleteAllTaskHistory(controller: Controller): Promise<Dele
await controller.clearTask()
// Get existing task history
const taskHistory = ((await getGlobalState(controller.context, "taskHistory")) as any[]) || []
const taskHistory = controller.cacheService.getGlobalStateKey("taskHistory")
const totalTasks = taskHistory.length
const userChoice = (
@@ -48,7 +48,7 @@ export async function deleteAllTaskHistory(controller: Controller): Promise<Dele
// If there are favorited tasks, update state
if (favoritedTasks.length > 0) {
await updateGlobalState(controller.context, "taskHistory", favoritedTasks)
controller.cacheService.setGlobalState("taskHistory", favoritedTasks)
// Delete non-favorited task directories
const preserveTaskIds = favoritedTasks.map((task) => task.id)
@@ -88,7 +88,7 @@ export async function deleteAllTaskHistory(controller: Controller): Promise<Dele
}
// Delete everything (not preserving favorites)
await updateGlobalState(controller.context, "taskHistory", undefined)
controller.cacheService.setGlobalState("taskHistory", [])
try {
// Remove all contents of tasks directory
+2 -2
View File
@@ -1,7 +1,7 @@
import { Controller } from ".."
import { GetTaskHistoryRequest, TaskHistoryArray } from "@shared/proto/cline/task"
import { getGlobalState } from "../../storage/state"
import { getWorkspacePath, arePathsEqual } from "../../../utils/path"
import { HistoryItem } from "@/shared/HistoryItem"
/**
* Gets filtered task history
@@ -14,7 +14,7 @@ export async function getTaskHistory(controller: Controller, request: GetTaskHis
const { favoritesOnly, currentWorkspaceOnly, searchQuery, sortBy } = request
// Get task history from global state
const taskHistory = ((await getGlobalState(controller.context, "taskHistory")) as any[]) || []
const taskHistory = controller.cacheService.getGlobalStateKey("taskHistory")
const workspacePath = await getWorkspacePath()
// Apply filters
+2 -1
View File
@@ -2,6 +2,7 @@ import { Controller } from ".."
import { StringRequest } from "@shared/proto/cline/common"
import { TaskResponse } from "@shared/proto/cline/task"
import { sendChatButtonClickedEvent } from "../ui/subscribeToChatButtonClicked"
import { HistoryItem } from "@/shared/HistoryItem"
/**
* Shows a task with the specified ID
@@ -14,7 +15,7 @@ export async function showTaskWithId(controller: Controller, request: StringRequ
const id = request.value
// First check if task exists in global state for faster access
const taskHistory = ((await controller.context.globalState.get("taskHistory")) as any[]) || []
const taskHistory = controller.cacheService.getGlobalStateKey("taskHistory")
const historyItem = taskHistory.find((item) => item.id === id)
// We need to initialize the task before returning data
@@ -1,3 +1,4 @@
import { HistoryItem } from "@/shared/HistoryItem"
import { Controller } from "../"
import { Empty } from "@shared/proto/cline/common"
import { TaskFavoriteRequest } from "@shared/proto/cline/task"
@@ -12,7 +13,7 @@ export async function toggleTaskFavorite(controller: Controller, request: TaskFa
try {
// Update in-memory state only
try {
const history = ((await controller.context.globalState.get("taskHistory")) as any[]) || []
const history = controller.cacheService.getGlobalStateKey("taskHistory")
const taskIndex = history.findIndex((item) => item.id === request.taskId)
@@ -28,7 +29,7 @@ export async function toggleTaskFavorite(controller: Controller, request: TaskFa
// Update global state and wait for it to complete
try {
await controller.context.globalState.update("taskHistory", updatedHistory)
controller.cacheService.setGlobalState("taskHistory", updatedHistory)
} catch (stateErr) {
console.error("Error updating global state:", stateErr)
}