feat(task): track task nesting depth with cycle-safe backfill - #10
Merged
Conversation
- Add optional depth (root = 0) to HistoryItem schema, CreateTaskOptions and TaskLike - Derive depth in the Task constructor: persisted value > live parent (+1) > root (0); mark legacy children resumed without their live parent as non-authoritative so a placeholder 0 is never persisted - Persist depth via taskMetadata() only when authoritative - Backfill depth for resumed legacy tasks in createTaskWithHistoryItem by walking the parentTaskId chain through the history store / global state (bounded, cycle-safe)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of the Task Tree plan (issue #9, upstream Zoo-Code-Org#856). PR-1 introduces nesting depth tracking for tasks — the foundation for
maxNestingDepthenforcement and auto-flatten in later PRs.Changes
packages/types/src/history.ts: optionaldepth: z.number().int().min(0)onHistoryItem(root = 0). Optional so legacy records stay valid.packages/types/src/task.ts:CreateTaskOptions.depth?andTaskLike.depth.src/core/task/Task.ts:readonly depth+depthAuthoritative. Constructor precedence: persisted value > live parent (parent.depth + 1) > root (0). A legacy child resumed without its live parent is marked non-authoritative so a placeholder0is never written back to history.src/core/task-persistence/taskMetadata.ts: persistsdepthonly when a valid number is supplied.src/core/webview/ClineProvider.ts:backfillTaskDepth()— oncreateTaskWithHistoryItem, tasks the constructor could not resolve walk theparentTaskIdchain through the in-memory store / global state and persist the computed depth (bounded, cycle-safe).src/core/task/taskDepth.ts(new): purecomputeTaskDepth(taskId, ownDepth, lookup)helper — handles persisted values, ancestor depths, roots, cycles, dangling refs, and over-long chains.Tests
core/task/__tests__/taskDepth.spec.ts(8 cases: persisted value, invalid depth fall-through, root derivation, nearest-ancestor depth, cycle, dangling ref, over-long chain, self-reference).Task.spec.ts: 4 new constructor cases (root=0 authoritative; child = parent+1; persisted beats live parent; legacy child without live parent is non-authoritative).Verification
pnpm run check-types— all 14 packages pass.taskDepth.spec.ts(8/8),Task.spec.ts(96/96),taskMessages.spec.ts(4/4), provider rehydration specsClineProvider.flicker-free-cancel.spec.ts+checkpointRestoreHandler.spec.ts(17/17).Notes