Skip to content

Commit 2e4e456

Browse files
committed
feat: creator mode state management in roo
1 parent 28b7ef2 commit 2e4e456

11 files changed

Lines changed: 86 additions & 28 deletions

File tree

src/core/Cline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class Cline extends EventEmitter<ClineEvents> {
260260
this.diffViewProvider = new DiffViewProvider(this.cwd)
261261
this.enableCheckpoints = enableCheckpoints
262262

263-
this.creatorModeConfig = creatorModeConfig ?? { creatorMode: false }
263+
this.creatorModeConfig = creatorModeConfig ?? historyItem?.creatorModeConfig ?? { creatorMode: false }
264264

265265
this.rootTask = rootTask
266266
this.parentTask = parentTask
@@ -376,6 +376,7 @@ export class Cline extends EventEmitter<ClineEvents> {
376376
taskNumber: this.taskNumber,
377377
globalStoragePath: this.globalStoragePath,
378378
workspace: this.cwd,
379+
creatorModeConfig: this.creatorModeConfig,
379380
})
380381

381382
this.emit("taskTokenUsageUpdated", this.taskId, tokenUsage)

src/core/task-persistence/taskMetadata.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export type TaskMetadataOptions = {
1717
taskNumber: number
1818
globalStoragePath: string
1919
workspace: string
20+
creatorModeConfig?: {
21+
creatorMode?: boolean
22+
newProjectType?: string
23+
newProjectPath?: string
24+
}
2025
}
2126

2227
export async function taskMetadata({
@@ -25,6 +30,7 @@ export async function taskMetadata({
2530
taskNumber,
2631
globalStoragePath,
2732
workspace,
33+
creatorModeConfig,
2834
}: TaskMetadataOptions) {
2935
const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId)
3036
const taskMessage = messages[0] // First message is always the task say.
@@ -57,6 +63,7 @@ export async function taskMetadata({
5763
totalCost: tokenUsage.totalCost,
5864
size: taskDirSize,
5965
workspace,
66+
creatorModeConfig,
6067
}
6168

6269
return { historyItem, tokenUsage }

src/core/webview/ClineProvider.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
540540
return cline
541541
}
542542

543-
public async initClineWithHistoryItem(historyItem: HistoryItem & { rootTask?: Cline; parentTask?: Cline }) {
543+
public async initClineWithHistoryItem(
544+
historyItem: HistoryItem & { rootTask?: Cline; parentTask?: Cline },
545+
options?: { creatorModeConfig?: CreatorModeConfig }
546+
) {
544547
await this.removeClineFromStack()
545548

546549
const {
@@ -571,6 +574,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
571574
parentTask: historyItem.parentTask,
572575
taskNumber: historyItem.number,
573576
onCreated: (cline) => this.emit("clineCreated", cline),
577+
creatorModeConfig: options?.creatorModeConfig,
574578
})
575579

576580
await this.addClineToStack(cline)
@@ -886,6 +890,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
886890
// Preserve parent and root task information for history item.
887891
const rootTask = cline.rootTask
888892
const parentTask = cline.parentTask
893+
const creatorModeConfig = cline.creatorModeConfig
889894

890895
cline.abortTask()
891896

@@ -913,7 +918,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
913918
}
914919

915920
// Clears task again, so we need to abortTask manually above.
916-
await this.initClineWithHistoryItem({ ...historyItem, rootTask, parentTask })
921+
await this.initClineWithHistoryItem({ ...historyItem, rootTask, parentTask }, { creatorModeConfig })
917922
}
918923

919924
async updateCustomInstructions(instructions?: string) {
@@ -1101,7 +1106,8 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
11011106
if (id !== this.getCurrentCline()?.taskId) {
11021107
// Non-current task.
11031108
const { historyItem } = await this.getTaskWithId(id)
1104-
await this.initClineWithHistoryItem(historyItem) // Clears existing task.
1109+
const creatorModeConfig = this.getCurrentCline()?.creatorModeConfig
1110+
await this.initClineWithHistoryItem(historyItem, { creatorModeConfig }) // Clears existing task.
11051111
}
11061112

11071113
await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
@@ -1243,10 +1249,9 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12431249
historyPreviewCollapsed,
12441250
} = await this.getState()
12451251

1246-
// Construct API configuration with creator mode
1252+
const creatorModeConfig = currentCline?.creatorModeConfig;
12471253
const apiConfiguration = {
1248-
...baseApiConfiguration,
1249-
creatorModeConfig: currentCline?.creatorModeConfig,
1254+
...baseApiConfiguration
12501255
}
12511256

12521257
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1334,6 +1339,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13341339
terminalCompressProgressBar: terminalCompressProgressBar ?? true,
13351340
hasSystemPromptOverride,
13361341
historyPreviewCollapsed: historyPreviewCollapsed ?? false,
1342+
creatorModeConfig,
13371343
}
13381344
}
13391345

src/core/webview/webviewMessageHandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
137137
// Could also do this in extension .ts
138138
//provider.postMessageToWebview({ type: "text", text: `Extension: ${Date.now()}` })
139139
// initializing new instance of Cline will make sure that any agentically running promises in old instance don't affect our new task. this essentially creates a fresh slate for the new task
140-
await provider.initClineWithTask(message.text, message.images)
140+
const existingCline = provider.getCurrentCline()
141+
const creatorModeConfig = existingCline?.creatorModeConfig
142+
143+
await provider.initClineWithTask(message.text, message.images, undefined, {}, creatorModeConfig)
141144
break
142145
case "apiConfiguration":
143146
if (message.apiConfiguration) {

src/exports/roo-code.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ type GlobalSettings = {
262262
totalCost: number
263263
size?: number | undefined
264264
workspace?: string | undefined
265+
creatorModeConfig?:
266+
| {
267+
creatorMode?: boolean | undefined
268+
newProjectType?: string | undefined
269+
newProjectPath?: string | undefined
270+
}
271+
| undefined
265272
}[]
266273
| undefined
267274
autoApprovalEnabled?: boolean | undefined

src/exports/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ type GlobalSettings = {
265265
totalCost: number
266266
size?: number | undefined
267267
workspace?: string | undefined
268+
creatorModeConfig?:
269+
| {
270+
creatorMode?: boolean | undefined
271+
newProjectType?: string | undefined
272+
newProjectPath?: string | undefined
273+
}
274+
| undefined
268275
}[]
269276
| undefined
270277
autoApprovalEnabled?: boolean | undefined

src/schemas/index.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,6 @@ export type ApiConfigMeta = z.infer<typeof apiConfigMetaSchema>
149149
* HistoryItem
150150
*/
151151

152-
export const historyItemSchema = z.object({
153-
id: z.string(),
154-
number: z.number(),
155-
ts: z.number(),
156-
task: z.string(),
157-
tokensIn: z.number(),
158-
tokensOut: z.number(),
159-
cacheWrites: z.number().optional(),
160-
cacheReads: z.number().optional(),
161-
totalCost: z.number(),
162-
size: z.number().optional(),
163-
workspace: z.string().optional(),
164-
})
165-
166-
export type HistoryItem = z.infer<typeof historyItemSchema>
167-
168152
/**
169153
* GroupOptions
170154
*/
@@ -347,6 +331,27 @@ export const creatorModeConfigSchema = z.object({
347331

348332
export type CreatorModeConfig = z.infer<typeof creatorModeConfigSchema>
349333

334+
/**
335+
* HistoryItem
336+
*/
337+
338+
export const historyItemSchema = z.object({
339+
id: z.string(),
340+
number: z.number(),
341+
ts: z.number(),
342+
task: z.string(),
343+
tokensIn: z.number(),
344+
tokensOut: z.number(),
345+
cacheWrites: z.number().optional(),
346+
cacheReads: z.number().optional(),
347+
totalCost: z.number(),
348+
size: z.number().optional(),
349+
workspace: z.string().optional(),
350+
creatorModeConfig: creatorModeConfigSchema.optional(),
351+
})
352+
353+
export type HistoryItem = z.infer<typeof historyItemSchema>
354+
350355
/**
351356
* ProviderSettings
352357
*/

src/shared/ExtensionMessage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ export type ExtensionState = Pick<
203203
renderContext: "sidebar" | "editor"
204204
settingsImportedAt?: number
205205
historyPreviewCollapsed?: boolean
206+
creatorModeConfig?: {
207+
creatorMode?: boolean
208+
newProjectType?: string
209+
newProjectPath?: string
210+
}
206211
}
207212

208213
export type { ClineMessage, ClineAsk, ClineSay }

src/shared/modes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ export const modes: readonly ModeConfig[] = [
5656
{
5757
slug: "creator",
5858
name: "Creator",
59+
// TODO: CHANGE ME TO ACTUALLY BE LIKE THE CREATOR MODE WE WANT
5960
roleDefinition:
6061
"You are PearAI Agent (Powered by Roo Code / Cline), a creative and systematic software architect focused on turning high-level ideas into actionable plans. Your primary goal is to help users transform their ideas into structured action plans.",
61-
groups: ["read", ["edit", { fileRegex: "\\.md$", description: "Markdown files only" }], "browser", "mcp"],
62+
groups: ["read", "edit", "browser", "command", "mcp"],
6263
},
6364
{
6465
slug: "code",

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
9797
customModes,
9898
telemetrySetting,
9999
hasSystemPromptOverride,
100-
historyPreviewCollapsed, // Added historyPreviewCollapsed
100+
historyPreviewCollapsed,
101+
creatorModeConfig,
101102
} = useExtensionState()
102103

103104
const { tasks } = useTaskSearch()
@@ -1238,7 +1239,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
12381239
flexDirection: "column",
12391240
overflow: "hidden",
12401241
}}>
1241-
{apiConfiguration?.creatorModeConfig?.creatorMode === true && (
1242+
{creatorModeConfig?.creatorMode === true && (
12421243
<PlanningBar
12431244
requestedPlan={task?.text || ""}
12441245
isGenerating={isStreaming}

0 commit comments

Comments
 (0)