Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/core/environment/__tests__/getEnvironmentDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,31 @@ describe("getEnvironmentDetails", () => {
const result = await getEnvironmentDetails(mockCline as Task, true)
expect(result).toContain("File listing unavailable: unexpected string rejection")
})

it("should surface task nesting depth for a root task", async () => {
mockCline = { ...mockCline, depth: 0 }

const result = await getEnvironmentDetails(mockCline as Task)

expect(result).toContain("# Task Context")
expect(result).toContain("Nesting depth: 0 (root = 0)")
expect(result).not.toContain("Parent task:")
})

it("should surface nesting depth and parent id for a child task", async () => {
mockCline = { ...mockCline, depth: 2, parentTaskId: "parent-task-id" }

const result = await getEnvironmentDetails(mockCline as Task)

expect(result).toContain("# Task Context")
expect(result).toContain("Nesting depth: 2 (root = 0)")
expect(result).toContain("Parent task: parent-task-id")
})

it("should omit the task context section when depth is unknown", async () => {
const result = await getEnvironmentDetails(mockCline as Task)

expect(result).not.toContain("# Task Context")
expect(result).not.toContain("Nesting depth:")
})
})
12 changes: 12 additions & 0 deletions src/core/environment/getEnvironmentDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
details += `<name>${modeDetails.name}</name>\n`
details += `<model>${modelId}</model>\n`

// Surface this task's position in the delegation tree so a subtask can report
// its own nesting level — depth is never visible to the model anywhere else.
// The parent id is included only for children; resolving the parent's title
// would need a history-store lookup on every environment refresh, which we avoid.
if (typeof cline.depth === "number") {
details += `\n\n# Task Context`
details += `Nesting depth: ${cline.depth} (root = 0)`
if (cline.parentTaskId) {
details += `\nParent task: ${cline.parentTaskId}`
}
}

if (includeFileDetails) {
details += `\n\n# Current Workspace Directory (${cline.cwd.toPosix()}) Files\n`
const isDesktop = arePathsEqual(cline.cwd, path.join(os.homedir(), "Desktop"))
Expand Down
Loading