@benzotti/jedi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +615 -0
  2. package/dist/index.js +10514 -0
  3. package/framework/adapters/generic.yaml +23 -0
  4. package/framework/adapters/laravel.yaml +46 -0
  5. package/framework/adapters/nextjs.yaml +36 -0
  6. package/framework/adapters/node.yaml +29 -0
  7. package/framework/agents/jdi-architect.md +118 -0
  8. package/framework/agents/jdi-backend.md +52 -0
  9. package/framework/agents/jdi-codebase-mapper.md +59 -0
  10. package/framework/agents/jdi-committer.md +83 -0
  11. package/framework/agents/jdi-debugger.md +73 -0
  12. package/framework/agents/jdi-devops.md +46 -0
  13. package/framework/agents/jdi-executor.md +89 -0
  14. package/framework/agents/jdi-feedback-learner.md +92 -0
  15. package/framework/agents/jdi-frontend.md +51 -0
  16. package/framework/agents/jdi-head-engineering.md +30 -0
  17. package/framework/agents/jdi-phase-researcher.md +59 -0
  18. package/framework/agents/jdi-plan-checker.md +80 -0
  19. package/framework/agents/jdi-planner.md +140 -0
  20. package/framework/agents/jdi-pr-feedback.md +118 -0
  21. package/framework/agents/jdi-pr-generator.md +80 -0
  22. package/framework/agents/jdi-product-lead.md +44 -0
  23. package/framework/agents/jdi-quality.md +77 -0
  24. package/framework/agents/jdi-researcher.md +70 -0
  25. package/framework/agents/jdi-ux-designer.md +40 -0
  26. package/framework/agents/jdi-verifier.md +80 -0
  27. package/framework/commands/commit.md +20 -0
  28. package/framework/commands/create-plan.md +32 -0
  29. package/framework/commands/generate-pr.md +19 -0
  30. package/framework/commands/implement-plan.md +34 -0
  31. package/framework/commands/init.md +65 -0
  32. package/framework/commands/pr-feedback.md +20 -0
  33. package/framework/commands/pr-review.md +15 -0
  34. package/framework/commands/quick.md +17 -0
  35. package/framework/commands/status.md +13 -0
  36. package/framework/commands/worktree-remove.md +32 -0
  37. package/framework/commands/worktree.md +52 -0
  38. package/framework/components/execution/CodebaseContext.md +36 -0
  39. package/framework/components/execution/Commit.md +121 -0
  40. package/framework/components/execution/Verify.md +140 -0
  41. package/framework/components/execution/VerifyAdvanced.md +43 -0
  42. package/framework/components/meta/AgentBase.md +108 -0
  43. package/framework/components/meta/AgentTeamsOrchestration.md +71 -0
  44. package/framework/components/meta/ComplexityRouter.md +80 -0
  45. package/framework/components/meta/StateUpdate.md +191 -0
  46. package/framework/components/meta/TeamRouter.md +86 -0
  47. package/framework/components/planning/TaskBreakdown.md +83 -0
  48. package/framework/components/planning/WaveComputation.md +59 -0
  49. package/framework/components/quality/PRReview.md +196 -0
  50. package/framework/components/quality/PRReviewLocal.md +99 -0
  51. package/framework/config/jdi-config.yaml +159 -0
  52. package/framework/config/state.yaml +72 -0
  53. package/framework/config/variables.yaml +43 -0
  54. package/framework/hooks/checkpoint.md +196 -0
  55. package/framework/hooks/jdi-worktree-cleanup.md +123 -0
  56. package/framework/hooks/lint-fix-frontend.md +59 -0
  57. package/framework/hooks/on-pause.md +213 -0
  58. package/framework/hooks/pre-commit.md +143 -0
  59. package/framework/jedi.md +336 -0
  60. package/framework/learnings/backend.md +3 -0
  61. package/framework/learnings/devops.md +3 -0
  62. package/framework/learnings/frontend.md +3 -0
  63. package/framework/learnings/general.md +3 -0
  64. package/framework/learnings/testing.md +3 -0
  65. package/framework/rules/commit-rules.md +24 -0
  66. package/framework/rules/deviation-rules.md +221 -0
  67. package/framework/teams/devops.md +26 -0
  68. package/framework/teams/engineering.md +29 -0
  69. package/framework/teams/micro-management.md +26 -0
  70. package/framework/teams/product-research.md +29 -0
  71. package/framework/teams/quality-assurance.md +27 -0
  72. package/framework/templates/PLAN-TASK.md +28 -0
  73. package/framework/templates/PLAN.md +127 -0
  74. package/framework/templates/PROJECT.md +104 -0
  75. package/framework/templates/PROJECT.yaml +16 -0
  76. package/framework/templates/REQUIREMENTS.md +95 -0
  77. package/framework/templates/REQUIREMENTS.yaml +27 -0
  78. package/framework/templates/ROADMAP.md +116 -0
  79. package/framework/templates/ROADMAP.yaml +24 -0
  80. package/framework/templates/STATE.md +137 -0
  81. package/framework/templates/SUMMARY.md +201 -0
  82. package/framework/workflows/README.md +87 -0
  83. package/package.json +35 -0
@@ -0,0 +1,99 @@
1
+ ---
2
+ name: PRReviewLocal
3
+ category: quality
4
+ description: Local-only review output (no GitHub comments)
5
+ ---
6
+
7
+ # PRReviewLocal
8
+
9
+ When `post="false"` or invoked as `<JDI:PRReview post="false" />`:
10
+
11
+ Skip Steps 9-10 (posting to GitHub).
12
+
13
+ Instead, write the full structured review to a file:
14
+
15
+ ## File Output
16
+
17
+ 1. **Create the directory** if it does not exist:
18
+ ```bash
19
+ mkdir -p .jdi/reviews
20
+ ```
21
+
22
+ 2. **Write the review file** to `.jdi/reviews/PR-{pr_number}-review.md` with the following structure:
23
+
24
+ ```markdown
25
+ ---
26
+ pr: {pr_number}
27
+ title: "{pr_title}"
28
+ author: "{author}"
29
+ branch: "{head_branch} -> {base_branch}"
30
+ url: "{pr_url}"
31
+ reviewed_at: "{ISO timestamp}"
32
+ verdict: "{APPROVE | REQUEST_CHANGES}"
33
+ findings:
34
+ blockers: {N}
35
+ major: {N}
36
+ minor: {N}
37
+ suggestions: {N}
38
+ questions: {N}
39
+ praise: {N}
40
+ ---
41
+
42
+ # PR Review: #{pr_number}
43
+
44
+ **Title:** {pr_title}
45
+ **Author:** {author}
46
+ **Branch:** {head_branch} -> {base_branch}
47
+ **URL:** {pr_url}
48
+ **Files changed:** {count}
49
+ **Lines:** +{additions} / -{deletions}
50
+
51
+ ---
52
+
53
+ ## Summary
54
+
55
+ {1-2 sentence overall assessment}
56
+
57
+ **Verdict:** {APPROVE | REQUEST_CHANGES}
58
+
59
+ ---
60
+
61
+ ## Findings
62
+
63
+ ### {severity emoji} {Severity}: {title}
64
+ **File:** `{path/to/file.ts}:{line}`
65
+
66
+ {Description}
67
+
68
+ **Suggested fix:**
69
+ \`\`\`{language}
70
+ {code}
71
+ \`\`\`
72
+
73
+ ---
74
+
75
+ ## Checklist
76
+
77
+ - [{x or space}] Logic is correct
78
+ - [{x or space}] Edge cases handled
79
+ - [{x or space}] Error handling appropriate
80
+ - [{x or space}] Types are correct
81
+ - [{x or space}] No security issues
82
+ - [{x or space}] Tests cover changes
83
+ - [{x or space}] Follows project patterns
84
+ - [{x or space}] No performance concerns
85
+ ```
86
+
87
+ **IMPORTANT:** Include ALL findings organised by severity (highest to lowest). Only include severity sections that have findings.
88
+
89
+ 3. **Confirm the file was written:**
90
+
91
+ **Output:**
92
+ ```
93
+ Review file written
94
+ - Path: .jdi/reviews/PR-{pr_number}-review.md
95
+ - Findings: {total_count} ({blockers} blockers, {major} major, {minor} minor, {suggestions} suggestions)
96
+ - Verdict: {APPROVE | REQUEST_CHANGES}
97
+ ```
98
+
99
+ Then proceed to Step 11 (return to master).
@@ -0,0 +1,159 @@
1
+ # JDI Global Configuration
2
+ # Edit these settings to customise JDI behaviour
3
+
4
+ version: "1.0.0"
5
+
6
+ # ─────────────────────────────────────────────────────────────────────────────
7
+ # Workflow Settings
8
+ # ─────────────────────────────────────────────────────────────────────────────
9
+ workflow:
10
+ # Mode: yolo (autonomous) | interactive (confirm gates) | strict (all confirmations)
11
+ mode: yolo
12
+
13
+ # Depth: shallow | standard | deep (affects task granularity)
14
+ depth: standard
15
+
16
+ # Enable parallel plan execution within waves
17
+ parallelisation: true
18
+
19
+ # Commit planning docs to git
20
+ commit_docs: true
21
+
22
+ # ─────────────────────────────────────────────────────────────────────────────
23
+ # Agent Toggles
24
+ # ─────────────────────────────────────────────────────────────────────────────
25
+ agents:
26
+ # Run research phase before planning
27
+ research: true
28
+
29
+ # Validate plans before execution
30
+ plan_check: true
31
+
32
+ # Verify outcomes after execution
33
+ verifier: true
34
+
35
+ # ─────────────────────────────────────────────────────────────────────────────
36
+ # Model Routing
37
+ # ─────────────────────────────────────────────────────────────────────────────
38
+ models:
39
+ # Active profile: quality | balanced | budget
40
+ profile: balanced
41
+
42
+ # Profile definitions (agent -> model mapping)
43
+ profiles:
44
+ # Maximum reasoning power, use for critical work (~100% token baseline)
45
+ quality:
46
+ planner: opus
47
+ architect: opus
48
+ executor: opus
49
+ verifier: sonnet
50
+ researcher: sonnet
51
+ phase_researcher: sonnet
52
+ plan_checker: sonnet
53
+ debugger: opus
54
+ quality: sonnet
55
+
56
+ # Smart allocation for typical development (~40% less than quality)
57
+ balanced:
58
+ planner: opus
59
+ architect: opus
60
+ executor: sonnet
61
+ verifier: sonnet
62
+ researcher: sonnet
63
+ phase_researcher: sonnet
64
+ plan_checker: sonnet
65
+ debugger: sonnet
66
+ quality: sonnet
67
+
68
+ # Minimal opus usage, conserve quota (~60% less than quality)
69
+ budget:
70
+ planner: sonnet
71
+ architect: sonnet
72
+ executor: sonnet
73
+ verifier: haiku
74
+ researcher: haiku
75
+ phase_researcher: haiku
76
+ plan_checker: haiku
77
+ debugger: sonnet
78
+ quality: haiku
79
+
80
+ # Override specific agents (null = use profile default)
81
+ overrides:
82
+ planner: null
83
+ executor: null
84
+ verifier: null
85
+ researcher: null
86
+
87
+ # ─────────────────────────────────────────────────────────────────────────────
88
+ # Default Paths and Values
89
+ # ─────────────────────────────────────────────────────────────────────────────
90
+ defaults:
91
+ branch_prefix: "feature/"
92
+ commit_types:
93
+ - feat
94
+ - fix
95
+ - refactor
96
+ - docs
97
+ - test
98
+ - chore
99
+ - perf
100
+ - style
101
+ plan_location: .jdi/plans
102
+ state_location: .jdi
103
+ thoughts_location: .jdi/thoughts
104
+
105
+ # ─────────────────────────────────────────────────────────────────────────────
106
+ # Git Settings
107
+ # ─────────────────────────────────────────────────────────────────────────────
108
+ git:
109
+ # Automatically stage changes before commit
110
+ auto_stage: false
111
+
112
+ # Require clean worktree before operations
113
+ require_clean_worktree: false
114
+
115
+ # Branches that cannot be directly modified
116
+ protected_branches:
117
+ - main
118
+ - master
119
+ - develop
120
+
121
+ # ─────────────────────────────────────────────────────────────────────────────
122
+ # Quality Gates
123
+ # ─────────────────────────────────────────────────────────────────────────────
124
+ quality:
125
+ # Run linter before each commit
126
+ run_lint_before_commit: true
127
+
128
+ # Run tests before creating PR
129
+ run_tests_before_pr: true
130
+
131
+ # Require verification pass before marking complete
132
+ require_verification: true
133
+
134
+ # ─────────────────────────────────────────────────────────────────────────────
135
+ # Context Management
136
+ # ─────────────────────────────────────────────────────────────────────────────
137
+ context:
138
+ # Maximum files to include per task context
139
+ max_files_per_task: 5
140
+
141
+ # Number of tasks before recommending split
142
+ split_threshold_tasks: 3
143
+
144
+ # Context budget thresholds (0.0 - 1.0)
145
+ context_budget_warning: 0.5 # Yellow zone
146
+ context_budget_critical: 0.7 # Red zone
147
+
148
+ # ─────────────────────────────────────────────────────────────────────────────
149
+ # UI Settings
150
+ # ─────────────────────────────────────────────────────────────────────────────
151
+ ui:
152
+ # Show progress banners during execution
153
+ show_progress_banners: true
154
+
155
+ # Enable verbose output
156
+ verbose_mode: false
157
+
158
+ # Use emoji in output (disabled for cleaner logs)
159
+ emoji_enabled: false
@@ -0,0 +1,72 @@
1
+ session:
2
+ id: null
3
+ started_at: null
4
+ last_activity: null
5
+
6
+ project:
7
+ name: null
8
+ root: null
9
+ initialised: false
10
+ initialised_at: null
11
+
12
+ position:
13
+ phase: null
14
+ phase_name: null
15
+ plan: null
16
+ plan_name: null
17
+ task: null
18
+ task_name: null
19
+ status: idle
20
+
21
+ progress:
22
+ phases_total: 0
23
+ phases_completed: 0
24
+ plans_total: 0
25
+ plans_completed: 0
26
+ tasks_total: 0
27
+ tasks_completed: 0
28
+
29
+ current_plan:
30
+ path: null
31
+ tasks: []
32
+ completed_tasks: []
33
+ current_task_index: null
34
+
35
+ current_phase:
36
+ waves:
37
+ computed: false
38
+ total_waves: 0
39
+ current_wave: null
40
+ structure: []
41
+ plans_by_wave: {}
42
+
43
+ worktree:
44
+ active: false
45
+ path: null
46
+ branch: null
47
+ created_at: null
48
+ type: null
49
+
50
+ continuation:
51
+ file: null
52
+ paused_at: null
53
+ resume_action: null
54
+
55
+ commits:
56
+ session_commits: []
57
+ last_commit_hash: null
58
+ last_commit_message: null
59
+
60
+ checkpoints:
61
+ last_checkpoint: null
62
+ checkpoint_type: null
63
+ awaiting_response: false
64
+
65
+ deviations: []
66
+
67
+ blockers: []
68
+
69
+ metadata:
70
+ context_usage_estimate: 0
71
+ agent_spawns: 0
72
+ errors_encountered: 0
@@ -0,0 +1,43 @@
1
+ feature:
2
+ name: null
3
+ description: null
4
+ type: null
5
+ branch: null
6
+ pr_number: null
7
+ pr_url: null
8
+
9
+ context:
10
+ clickup_task_id: null
11
+ clickup_task_url: null
12
+ figma_url: null
13
+ figma_node_id: null
14
+ requirements_source: null
15
+
16
+ implementation:
17
+ approach: null
18
+ key_decisions: []
19
+ files_created: []
20
+ files_modified: []
21
+ dependencies_added: []
22
+
23
+ review:
24
+ reviewer: null
25
+ review_status: null
26
+ comments_total: 0
27
+ comments_resolved: 0
28
+ changes_requested: []
29
+
30
+ testing:
31
+ test_files: []
32
+ coverage_before: null
33
+ coverage_after: null
34
+ tests_added: 0
35
+ tests_passed: null
36
+
37
+ references:
38
+ related_files: []
39
+ related_components: []
40
+ documentation_urls: []
41
+ api_endpoints: []
42
+
43
+ custom: {}
@@ -0,0 +1,196 @@
1
+ ---
2
+ name: checkpoint
3
+ description: Handles checkpoint interactions
4
+ trigger: checkpoint_reached
5
+ ---
6
+
7
+ # Checkpoint Hook
8
+
9
+ Handles pausing execution and managing user interaction at checkpoints.
10
+
11
+ ---
12
+
13
+ ## Trigger
14
+
15
+ Fires when:
16
+ - Task type is `checkpoint:human-verify`
17
+ - Task type is `checkpoint:decision`
18
+ - Task type is `checkpoint:human-action`
19
+ - Auth gate or credential requirement detected
20
+
21
+ ---
22
+
23
+ ## Checkpoint Types
24
+
25
+ ### human-verify
26
+
27
+ User needs to test/verify something.
28
+
29
+ **Flow:**
30
+ 1. Present what was built
31
+ 2. Provide verification steps
32
+ 3. Wait for "approved" or issues
33
+
34
+ **Template:**
35
+ ```
36
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
37
+ JDI ► CHECKPOINT: Verification Required
38
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
39
+
40
+ **Phase:** {phase} | **Plan:** {plan} | **Task:** {n}/{total}
41
+
42
+ ## What Was Built
43
+
44
+ {Summary of completed work}
45
+
46
+ ## Please Verify
47
+
48
+ 1. {Step 1}
49
+ 2. {Step 2}
50
+ 3. {Step 3}
51
+
52
+ ## Expected Behaviour
53
+
54
+ {What you should see}
55
+
56
+ ───────────────────────────────────────────────────────────────
57
+
58
+ Reply "approved" to continue, or describe any issues found.
59
+ ```
60
+
61
+ ### decision
62
+
63
+ User needs to make a choice.
64
+
65
+ **Flow:**
66
+ 1. Present decision context
67
+ 2. Show options with trade-offs
68
+ 3. Record choice and rationale
69
+
70
+ **Template:**
71
+ ```
72
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
73
+ JDI ► CHECKPOINT: Decision Required
74
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
75
+
76
+ **Decision:** {What needs to be decided}
77
+
78
+ ## Context
79
+
80
+ {Why this decision matters}
81
+
82
+ ## Options
83
+
84
+ | Option | Pros | Cons |
85
+ |--------|------|------|
86
+ | A: {option} | {pros} | {cons} |
87
+ | B: {option} | {pros} | {cons} |
88
+ | C: {option} | {pros} | {cons} |
89
+
90
+ ## Recommendation
91
+
92
+ {If applicable, what we recommend and why}
93
+
94
+ ───────────────────────────────────────────────────────────────
95
+
96
+ Reply with your choice (A/B/C) and any additional context.
97
+ ```
98
+
99
+ ### human-action
100
+
101
+ User needs to do something manually.
102
+
103
+ **Flow:**
104
+ 1. Explain what's needed
105
+ 2. Provide steps
106
+ 3. Wait for "done" confirmation
107
+ 4. Verify action worked
108
+
109
+ **Template:**
110
+ ```
111
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
112
+ JDI ► CHECKPOINT: Manual Action Required
113
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
114
+
115
+ **Action:** {What you need to do}
116
+
117
+ ## Why This Can't Be Automated
118
+
119
+ {Reason - credentials, external system, etc.}
120
+
121
+ ## Steps
122
+
123
+ 1. {Step 1}
124
+ 2. {Step 2}
125
+ 3. {Step 3}
126
+
127
+ ## How to Verify
128
+
129
+ {How we'll confirm it worked}
130
+
131
+ ───────────────────────────────────────────────────────────────
132
+
133
+ Reply "done" when complete.
134
+ ```
135
+
136
+ ---
137
+
138
+ ## State Management
139
+
140
+ On checkpoint:
141
+
142
+ ```yaml
143
+ checkpoints:
144
+ last_checkpoint: "{timestamp}"
145
+ checkpoint_type: "{type}"
146
+ checkpoint_task: "{task_id}"
147
+ awaiting_response: true
148
+ ```
149
+
150
+ On response:
151
+
152
+ ```yaml
153
+ checkpoints:
154
+ awaiting_response: false
155
+ last_response: "{user_response}"
156
+ response_at: "{timestamp}"
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Response Handling
162
+
163
+ ### "approved" / "done"
164
+ - Continue to next task
165
+ - Clear awaiting_response
166
+
167
+ ### Issues described
168
+ - Parse user feedback
169
+ - Return to task with feedback context
170
+ - Address issues
171
+ - Re-present checkpoint
172
+
173
+ ### Decision made
174
+ - Record decision
175
+ - Record rationale if provided
176
+ - Apply decision to remaining work
177
+ - Continue execution
178
+
179
+ ---
180
+
181
+ ## Timeout Behaviour
182
+
183
+ If checkpoint awaits response for extended time:
184
+ - State preserved in state.yaml
185
+ - Can resume with `/jdi-implement-plan --resume`
186
+ - Progress is not lost
187
+
188
+ ---
189
+
190
+ ## Outputs
191
+
192
+ | Output | Purpose |
193
+ |--------|---------|
194
+ | Checkpoint display | User interaction |
195
+ | State update | Track checkpoint |
196
+ | Decision record | Document choices |
@@ -0,0 +1,123 @@
1
+ ---
2
+ name: jdi-worktree-cleanup
3
+ description: Clean up git worktree and associated branch after execution
4
+ ---
5
+
6
+ # Worktree Cleanup Hook
7
+
8
+ Clean up the git worktree and associated branch after worktree-based execution completes.
9
+
10
+ ---
11
+
12
+ ## When to Execute
13
+
14
+ This hook is invoked after worktree execution completes, either:
15
+ - After a **merge** (branch was merged into current branch)
16
+ - After a **discard** (changes were discarded)
17
+
18
+ ---
19
+
20
+ ## Cleanup Steps
21
+
22
+ ### 1. Remove the Git Worktree
23
+
24
+ ```bash
25
+ git worktree remove .worktrees/jdi-{plan-id} --force
26
+ ```
27
+
28
+ The `--force` flag is used to handle cases where the worktree has uncommitted changes (which shouldn't happen in normal flow but provides safety).
29
+
30
+ ### 2. Delete the Branch
31
+
32
+ **If branch was merged:**
33
+ ```bash
34
+ git branch -d jdi/{plan-id}
35
+ ```
36
+ Uses `-d` (safe delete) since the branch was already merged.
37
+
38
+ **If branch was NOT merged (discard):**
39
+ ```bash
40
+ git branch -D jdi/{plan-id}
41
+ ```
42
+ Uses `-D` (force delete) since the branch was never merged.
43
+
44
+ ### 3. Remove Empty Worktrees Directory
45
+
46
+ ```bash
47
+ rmdir .worktrees 2>/dev/null
48
+ ```
49
+
50
+ Only removes the directory if it's empty. Silently fails if other worktrees exist.
51
+
52
+ ---
53
+
54
+ ## Error Handling
55
+
56
+ ### Worktree Removal Fails
57
+
58
+ If the worktree removal fails (e.g., uncommitted changes, locked files):
59
+
60
+ ```
61
+ ⚠️ Warning: Could not remove worktree automatically.
62
+
63
+ Manual cleanup commands:
64
+ git worktree remove .worktrees/jdi-{plan-id} --force
65
+ rm -rf .worktrees/jdi-{plan-id}
66
+ ```
67
+
68
+ ### Branch Deletion Fails
69
+
70
+ If the branch deletion fails:
71
+
72
+ ```
73
+ ⚠️ Warning: Could not delete branch automatically.
74
+
75
+ Manual cleanup command:
76
+ git branch -D jdi/{plan-id}
77
+ ```
78
+
79
+ ---
80
+
81
+ ## State Update
82
+
83
+ After cleanup, update `.jdi/config/state.yaml`:
84
+
85
+ 1. Read `.jdi/config/state.yaml`
86
+ 2. Clear any worktree-related state:
87
+ ```yaml
88
+ worktree:
89
+ active: false
90
+ path: null
91
+ branch: null
92
+ ```
93
+ 3. Write the updated YAML back
94
+
95
+ ---
96
+
97
+ ## Full Cleanup Sequence
98
+
99
+ ```bash
100
+ # 1. Remove worktree
101
+ git worktree remove .worktrees/jdi-{plan-id} --force
102
+
103
+ # 2. Delete branch (use -d if merged, -D if not)
104
+ git branch -d jdi/{plan-id} # or -D for discarded
105
+
106
+ # 3. Clean up empty directory
107
+ rmdir .worktrees 2>/dev/null
108
+
109
+ # 4. Update state (handled by Read/Write tools)
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Usage Example
115
+
116
+ Called from `jdi-implement-plan.md` Step 3: Post-Execution:
117
+
118
+ ```
119
+ After user selects "merge" or "discard":
120
+ 1. If merge: git merge jdi/{plan-id}
121
+ 2. Invoke this cleanup hook
122
+ 3. Report cleanup complete
123
+ ```