Accept task settings in init task (#6342)

* v3.28.5 Release Notes

* changeset version bump

* Updating CHANGELOG.md format

* Update changelog for patch release

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Kevin Bond <kevin@Kevins-MacBook-Pro.local>

* Add task-specific settings caching to StateManager (#6171)

* Add task-specific settings caching to StateManager

Implement per-task settings storage with automatic loading/clearing:
- Add taskStateCache for isolated task settings
- Load task settings on task creation and reinitialize
- Clear task settings cache when tasks end
- Prioritize task cache over global state in getters

* update error wording for taskSettings read failure

* add missing return statement in promise.all

* fix: persist pending task settings before clearing cache

Changed clearTaskSettings to be async and ensure any pending task state
changes are persisted to storage before clearing the in-memory cache.
This prevents potential data loss when a task ends with unpersisted
settings still in the pending state queue.

- Made clearTaskSettings async and added optional taskId parameter
- Added logic to persist pending task state batch before clearing
- Updated controller to await clearTaskSettings and pass taskId

* add ability to set task setting overrides in newtask rpc

* spread proto object keys that don't need to be transformed and filter undefined values

* use most Settings fields in TaskSettings proto and convert fields that do not directly map to the application typescripts type of Settings

* accept taskSettings in newTask RPC and save them to task state

* remove test taskSettings in useMessageHandlers

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Kevin Bond <kevin@Kevins-MacBook-Pro.local>
This commit is contained in:
authored and GitHub committed 2025-10-01 11:00:21 -07:00
1 parent 793db91291
commit b0fa1be2df
7 files changed
+275 -29

No files matched your search

+17 -7
View File
@@ -40,6 +40,7 @@ import {
GlobalFileNames,
} from "../storage/disk"
import { PersistenceErrorEvent, StateManager } from "../storage/StateManager"
import { Settings } from "../storage/state-keys"
import { Task } from "../task"
import { sendMcpMarketplaceCatalogEvent } from "./mcp/subscribeToMcpMarketplaceCatalog"
import { appendClineStealthModels } from "./models/refreshOpenRouterModels"
@@ -187,7 +188,13 @@ export class Controller {
this.stateManager.setGlobalState("userInfo", info)
}
async initTask(task?: string, images?: string[], files?: string[], historyItem?: HistoryItem) {
async initTask(
task?: string,
images?: string[],
files?: string[],
historyItem?: HistoryItem,
taskSettings?: Partial<Settings>,
) {
await this.clearTask() // ensures that an existing task doesn't exist before starting a new one, although this shouldn't be possible since user must clear task before starting a new one
const autoApprovalSettings = this.stateManager.getGlobalSettingsKey("autoApprovalSettings")
@@ -222,6 +229,13 @@ export class Controller {
const cwd = this.workspaceManager?.getPrimaryRoot()?.path || (await getCwd(getDesktopDir()))
const taskId = historyItem?.id || Date.now().toString()
await this.stateManager.loadTaskSettings(taskId)
if (taskSettings) {
this.stateManager.setTaskSettingsBatch(taskId, taskSettings)
}
this.task = new Task({
controller: this,
mcpHub: this.mcpHub,
@@ -240,12 +254,8 @@ export class Controller {
images,
files,
historyItem,
taskId,
})
// Load task settings after task creation
if (this.task.taskId) {
await this.stateManager.loadTaskSettings(this.task.taskId)
}
}
async reinitExistingTaskFromId(taskId: string) {
@@ -803,7 +813,7 @@ export class Controller {
async clearTask() {
if (this.task) {
// Clear task settings cache when task ends
await this.stateManager.clearTaskSettings(this.task.taskId)
await this.stateManager.clearTaskSettings()
}
await this.task?.abortTask()
this.task = undefined // removes reference to it, so once promises end it will be garbage collected
+63 -2
View File
@@ -1,14 +1,75 @@
import { Empty } from "@shared/proto/cline/common"
import { PlanActMode, OpenaiReasoningEffort as ProtoOpenaiReasoningEffort } from "@shared/proto/cline/state"
import { NewTaskRequest } from "@shared/proto/cline/task"
import { Settings } from "@/core/storage/state-keys"
import { convertProtoToApiProvider } from "@/shared/proto-conversions/models/api-configuration-conversion"
import { DEFAULT_BROWSER_SETTINGS } from "../../../shared/BrowserSettings"
import { convertProtoToAutoApprovalSettings } from "../../../shared/proto-conversions/models/auto-approval-settings-conversion"
import { Controller } from ".."
/**
* Creates a new task with the given text and optional images
* @param controller The controller instance
* @param request The new task request containing text and optional images
* @param request The new task request containing text and optional images, and optional task settings
* @returns Empty response
*/
export async function newTask(controller: Controller, request: NewTaskRequest): Promise<Empty> {
await controller.initTask(request.text, request.images, request.files)
const convertOpenaiReasoningEffort = (effort: ProtoOpenaiReasoningEffort): string => {
switch (effort) {
case ProtoOpenaiReasoningEffort.LOW:
return "low"
case ProtoOpenaiReasoningEffort.MEDIUM:
return "medium"
case ProtoOpenaiReasoningEffort.HIGH:
return "high"
case ProtoOpenaiReasoningEffort.MINIMAL:
return "minimal"
default:
return "medium"
}
}
const convertPlanActMode = (mode: PlanActMode): string => {
return mode === PlanActMode.PLAN ? "plan" : "act"
}
const filteredTaskSettings: Partial<Settings> = Object.fromEntries(
Object.entries({
...request.taskSettings,
...(request.taskSettings?.autoApprovalSettings && {
autoApprovalSettings: convertProtoToAutoApprovalSettings({
...request.taskSettings.autoApprovalSettings,
metadata: {},
}),
}),
...(request.taskSettings?.browserSettings && {
browserSettings: {
viewport: request.taskSettings.browserSettings.viewport || DEFAULT_BROWSER_SETTINGS.viewport,
remoteBrowserHost: request.taskSettings.browserSettings.remoteBrowserHost,
remoteBrowserEnabled: request.taskSettings.browserSettings.remoteBrowserEnabled,
chromeExecutablePath: request.taskSettings.browserSettings.chromeExecutablePath,
disableToolUse: request.taskSettings.browserSettings.disableToolUse,
customArgs: request.taskSettings.browserSettings.customArgs,
},
}),
...(request.taskSettings?.openaiReasoningEffort !== undefined && {
openaiReasoningEffort: convertOpenaiReasoningEffort(request.taskSettings.openaiReasoningEffort),
}),
...(request.taskSettings?.mode !== undefined && {
mode: convertPlanActMode(request.taskSettings.mode),
}),
...(request.taskSettings?.customPrompt === "compact" && {
customPrompt: "compact",
}),
...(request.taskSettings?.planModeApiProvider !== undefined && {
planModeApiProvider: convertProtoToApiProvider(request.taskSettings.planModeApiProvider),
}),
...(request.taskSettings?.actModeApiProvider !== undefined && {
actModeApiProvider: convertProtoToApiProvider(request.taskSettings.actModeApiProvider),
}),
}).filter(([_, value]) => value !== undefined),
)
await controller.initTask(request.text, request.images, request.files, undefined, filteredTaskSettings)
return Empty.create()
}