code review

This commit is contained in:
Will Li 2025-08-15 01:51:14 -07:00
parent aacc7f99a9
commit ec3721fa2f
5 changed files with 18 additions and 22 deletions

View file

@ -14,7 +14,7 @@ export interface TaskProviderState {
}
export interface InitTaskOptions {
mode_slug?: string
modeSlug?: string
enableDiff?: boolean
enableCheckpoints?: boolean
fuzzyMatchThreshold?: number
@ -95,7 +95,7 @@ export interface TaskLike {
off<K extends keyof TaskEvents>(event: K, listener: (...args: TaskEvents[K]) => void | Promise<void>): this
setMessageResponse(text: string, images?: string[]): void
submitUserMessage(text: string, images?: string[], mode_slug?: string): void
submitUserMessage(text: string, images?: string[], modeSlug?: string): void
}
export type TaskEvents = {

View file

@ -768,7 +768,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
this.askResponseImages = images
}
public submitUserMessage(text: string, images?: string[], mode_slug?: string): void {
public submitUserMessage(text: string, images?: string[], modeSlug?: string): void {
try {
const trimmed = (text ?? "").trim()
const imgs = images ?? []
@ -783,20 +783,20 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
void (async () => {
// If a mode slug is provided, handle the mode switch first (same behavior as initClineWithTask)
try {
const modeSlugValue = (mode_slug ?? "").trim()
const modeSlugValue = (modeSlug ?? "").trim()
if (modeSlugValue.length > 0) {
const customModes = await provider.customModesManager.getCustomModes()
const targetMode = getModeBySlug(modeSlugValue, customModes)
if (targetMode) {
await provider.handleModeSwitch(targetMode.slug)
provider.log(`[Task#submitUserMessage] Applied mode from mode_slug: '${targetMode.slug}'`)
provider.log(`[Task#submitUserMessage] Applied mode from modeSlug: '${targetMode.slug}'`)
} else {
provider.log(`[Task#submitUserMessage] Ignoring invalid mode_slug: '${modeSlugValue}'.`)
provider.log(`[Task#submitUserMessage] Ignoring invalid modeSlug: '${modeSlugValue}'.`)
}
}
} catch (err) {
provider.log(
`[Task#submitUserMessage] Failed to apply mode_slug: ${
`[Task#submitUserMessage] Failed to apply modeSlug: ${
err instanceof Error ? err.message : String(err)
}`,
)
@ -2554,10 +2554,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// Getters
public get cwd() {
if (!this.workspacePath) {
// Return a fallback to prevent crashes
return path.join(os.homedir(), "Desktop")
}
return this.workspacePath
}
}

View file

@ -708,10 +708,10 @@ export class ClineProvider
throw new OrganizationAllowListViolationError(t("common:errors.violated_organization_allowlist"))
}
// Bridge: If a mode_slug is provided by the cloud extension bridge, honor it before creating the task
// Bridge: If a modeSlug is provided by the cloud extension bridge, honor it before creating the task
// This ensures the task initializes with the correct mode and associated provider profile
try {
const modeSlugFromBridge: string | undefined = (options as any)?.mode_slug
const modeSlugFromBridge: string | undefined = (options as any)?.modeSlug
if (typeof modeSlugFromBridge === "string" && modeSlugFromBridge.trim().length > 0) {
const customModes = await this.customModesManager.getCustomModes()
const targetMode = getModeBySlug(modeSlugFromBridge, customModes)
@ -721,13 +721,13 @@ export class ClineProvider
this.log(`[initClineWithTask] Applied mode from bridge: '${targetMode.slug}'`)
} else {
this.log(
`[initClineWithTask] Ignoring invalid mode_slug from bridge: '${modeSlugFromBridge}'. Falling back to current mode.`,
`[initClineWithTask] Ignoring invalid modeSlug from bridge: '${modeSlugFromBridge}'. Falling back to current mode.`,
)
}
}
} catch (err) {
this.log(
`[initClineWithTask] Failed to apply mode_slug from bridge: ${
`[initClineWithTask] Failed to apply modeSlug from bridge: ${
err instanceof Error ? err.message : String(err)
}`,
)

View file

@ -2208,7 +2208,7 @@ describe("ClineProvider", () => {
})
})
})
describe("Bridge mode_slug handling", () => {
describe("Bridge modeSlug handling", () => {
let provider: ClineProvider
let mockContext: vscode.ExtensionContext
let mockOutputChannel: vscode.OutputChannel
@ -2262,7 +2262,7 @@ describe("Bridge mode_slug handling", () => {
provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
})
it("applies mode_slug from bridge options when starting task", async () => {
it("applies modeSlug from bridge options when starting task", async () => {
await provider.resolveWebviewView(mockWebviewView)
// Spy on handleModeSwitch to ensure it's invoked with the bridge-provided mode
@ -2277,10 +2277,10 @@ describe("Bridge mode_slug handling", () => {
groups: ["read", "edit"] as any,
} as any)
// Pass mode_slug through the options object (as provided by the bridge package)
// Pass modeSlug through the options object (as provided by the bridge package)
await provider.initClineWithTask("Started from bridge", undefined, undefined, {
experiments: {},
mode_slug: "architect",
modeSlug: "architect",
} as any)
expect(handleModeSwitchSpy).toHaveBeenCalledWith("architect")

View file

@ -97,13 +97,13 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
text,
images,
newTab,
mode_slug,
modeSlug,
}: {
configuration: RooCodeSettings
text?: string
images?: string[]
newTab?: boolean
mode_slug?: string
modeSlug?: string
}) {
let provider: ClineProvider
@ -152,7 +152,7 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
const cline = await provider.initClineWithTask(text, images, undefined, {
consecutiveMistakeLimit: Number.MAX_SAFE_INTEGER,
mode_slug,
modeSlug,
})
if (!cline) {