Skip to content

Commit 2c81366

Browse files
author
ShayBC
committed
added connection between task to its parent and root parent + adjusted cline mock in the provider test
1 parent b1dae21 commit 2c81366

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/core/Cline.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ export class Cline {
9292
private isSubTask: boolean = false
9393
// a flag that indicated if this Cline instance is paused (waiting for provider to resume it after subtask completion)
9494
private isPaused: boolean = false
95+
// this is the parent task work mode when it launched the subtask to be used when it is restored (so the last used mode by parent task will also be restored)
9596
private pausedModeSlug: string = defaultModeSlug
97+
// if this is a subtask then this member holds a pointer to the parent task that launched it
98+
private parentTask: Cline | undefined = undefined
99+
// if this is a subtask then this member holds a pointer to the top parent task that launched it
100+
private rootTask: Cline | undefined = undefined
96101
readonly apiConfiguration: ApiConfiguration
97102
api: ApiHandler
98103
private terminalManager: TerminalManager
@@ -218,6 +223,30 @@ export class Cline {
218223
return this.taskNumber
219224
}
220225

226+
// this method returns the cline instance that is the parent task that launched this subtask (assuming this cline is a subtask)
227+
// if undefined is returned, then there is no parent task and this is not a subtask or connection has been severed
228+
getParentTask(): Cline | undefined {
229+
return this.parentTask
230+
}
231+
232+
// this method sets a cline instance that is the parent task that called this task (assuming this cline is a subtask)
233+
// if undefined is set, then the connection is broken and the parent is no longer saved in the subtask member
234+
setParentTask(parentToSet: Cline | undefined) {
235+
this.parentTask = parentToSet
236+
}
237+
238+
// this method returns the cline instance that is the root task (top most parent) that eventually launched this subtask (assuming this cline is a subtask)
239+
// if undefined is returned, then there is no root task and this is not a subtask or connection has been severed
240+
getRootTask(): Cline | undefined {
241+
return this.rootTask
242+
}
243+
244+
// this method sets a cline instance that is the root task (top most patrnt) that called this task (assuming this cline is a subtask)
245+
// if undefined is set, then the connection is broken and the root is no longer saved in the subtask member
246+
setRootTask(rootToSet: Cline | undefined) {
247+
this.rootTask = rootToSet
248+
}
249+
221250
// Add method to update diffStrategy
222251
async updateDiffStrategy(experimentalDiffStrategy?: boolean) {
223252
// If not provided, get from current state

src/core/webview/ClineProvider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ export class ClineProvider implements vscode.WebviewViewProvider {
114114
this.lastTaskNumber = taskNumber
115115
}
116116

117+
// set this cline task parent cline (the task that launched it), and the root cline (the top most task that eventually launched it)
118+
if (this.clineStack.length >= 1) {
119+
cline.setParentTask(this.getCurrentCline())
120+
cline.setRootTask(this.clineStack[0])
121+
}
122+
123+
// add this cline instance into the stack that represents the order of all the called tasks
117124
this.clineStack.push(cline)
118125

119126
// Ensure getState() resolves correctly

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ jest.mock("../../Cline", () => ({
209209
overwriteApiConversationHistory: jest.fn(),
210210
getTaskNumber: jest.fn().mockReturnValue(0),
211211
setTaskNumber: jest.fn(),
212+
setParentTask: jest.fn(),
213+
setRootTask: jest.fn(),
212214
taskId: taskId || "test-task-id",
213215
}),
214216
),

0 commit comments

Comments
 (0)