devflow-kit 3.1.0 → 3.3.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 (138) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -2
  3. package/dist/cli/agents-view/render.js +69 -15
  4. package/dist/cli/agents-view/state.js +40 -14
  5. package/dist/cli/commands/agents.js +135 -45
  6. package/dist/cli/commands/init.js +128 -53
  7. package/dist/cli/commands/learning.js +61 -13
  8. package/dist/cli/commands/memory.js +35 -14
  9. package/dist/cli/commands/uninstall.js +163 -39
  10. package/dist/commands/code-review.md +1 -3
  11. package/dist/commands/debug.md +15 -12
  12. package/dist/commands/dynamic-build.md +172 -135
  13. package/dist/commands/dynamic-plan.md +9 -3
  14. package/dist/commands/explore.md +10 -4
  15. package/dist/commands/implement.md +149 -145
  16. package/dist/commands/plan.md +13 -9
  17. package/dist/commands/release.md +8 -2
  18. package/dist/commands/research.md +8 -2
  19. package/dist/commands/resolve.md +28 -19
  20. package/dist/commands/self-review.md +16 -13
  21. package/dist/core/agent-frontmatter.js +25 -0
  22. package/dist/core/agent-models.js +201 -36
  23. package/dist/core/agent-state.js +27 -5
  24. package/dist/core/assets.js +1 -1
  25. package/dist/core/feature-config.js +68 -10
  26. package/dist/core/flags.js +24 -0
  27. package/dist/core/learning-queue-cleanup.js +10 -11
  28. package/dist/core/learning-tuning-config.js +8 -0
  29. package/dist/core/linked-path.js +46 -0
  30. package/dist/core/plugins.js +16 -5
  31. package/dist/core/queue-drain.js +31 -0
  32. package/dist/hud/components/learning-counts.js +54 -8
  33. package/dist/skills/git/references/tracker/github/create-release.md +2 -2
  34. package/dist/skills/git/references/tracker/github/gather-release-evidence.md +1 -1
  35. package/dist/skills/git/references/tracker/jira/create-release.md +2 -2
  36. package/dist/skills/git/references/tracker/jira/gather-release-evidence.md +1 -1
  37. package/dist/skills/git/references/tracker/linear/create-release.md +2 -2
  38. package/dist/skills/git/references/tracker/linear/gather-release-evidence.md +1 -1
  39. package/dist/targets/claude-code/installer.js +36 -9
  40. package/dist/targets/claude-code/post-install.js +128 -38
  41. package/package.json +1 -1
  42. package/src/assets/agents/code.md +85 -35
  43. package/src/assets/agents/design.md +12 -0
  44. package/src/assets/agents/diagnose.md +18 -11
  45. package/src/assets/agents/evaluate.md +17 -24
  46. package/src/assets/agents/knowledge.md +7 -3
  47. package/src/assets/agents/learning.md +4 -6
  48. package/src/assets/agents/research.md +21 -0
  49. package/src/assets/agents/review.md +12 -0
  50. package/src/assets/agents/scrutinize.md +37 -9
  51. package/src/assets/agents/simplify.md +24 -0
  52. package/src/assets/agents/skim.md +6 -2
  53. package/src/assets/agents/synthesize.md +18 -0
  54. package/src/assets/agents/test.md +19 -11
  55. package/src/assets/agents/triage.md +8 -0
  56. package/src/assets/agents/validate.md +20 -11
  57. package/src/assets/commands/_partials/_engine.mds +36 -55
  58. package/src/assets/commands/_partials/_knowledge.mds +1 -3
  59. package/src/assets/commands/_partials/_plan_contract.mds +1 -1
  60. package/src/assets/commands/_partials/_tracker.mds +1 -1
  61. package/src/assets/commands/_partials/_wave.mds +8 -6
  62. package/src/assets/commands/code-review.mds +1 -3
  63. package/src/assets/commands/debug.mds +13 -8
  64. package/src/assets/commands/dynamic-build.mds +126 -72
  65. package/src/assets/commands/dynamic-plan.mds +7 -1
  66. package/src/assets/commands/explore.mds +9 -1
  67. package/src/assets/commands/implement.mds +147 -141
  68. package/src/assets/commands/plan.mds +12 -8
  69. package/src/assets/commands/release.md +8 -2
  70. package/src/assets/commands/research.mds +8 -2
  71. package/src/assets/commands/resolve.mds +27 -16
  72. package/src/assets/commands/self-review.mds +15 -10
  73. package/src/assets/mds/tracker/_common.mds +1 -1
  74. package/src/assets/mds/tracker/_github.mds +2 -2
  75. package/src/assets/mds/tracker/_jira.mds +2 -2
  76. package/src/assets/mds/tracker/_linear.mds +2 -2
  77. package/src/assets/scripts/ci-wait.cjs +636 -0
  78. package/src/assets/scripts/hooks/assets/orchestrator-charter.md +4 -3
  79. package/src/assets/scripts/hooks/background-memory-update +356 -17
  80. package/src/assets/scripts/hooks/capture-prompt +4 -3
  81. package/src/assets/scripts/hooks/capture-question +4 -3
  82. package/src/assets/scripts/hooks/capture-turn +4 -3
  83. package/src/assets/scripts/hooks/ensure-devflow-init +13 -1
  84. package/src/assets/scripts/hooks/ensure-root-gitignore +122 -10
  85. package/src/assets/scripts/hooks/git-marker +71 -0
  86. package/src/assets/scripts/hooks/json-helper.cjs +12 -145
  87. package/src/assets/scripts/hooks/json-parse +24 -129
  88. package/src/assets/scripts/hooks/lib/learning-store.cjs +169 -64
  89. package/src/assets/scripts/hooks/lib/render-decisions.cjs +1 -1
  90. package/src/assets/scripts/hooks/memory-worker +10 -0
  91. package/src/assets/scripts/hooks/pre-compact-memory +66 -14
  92. package/src/assets/scripts/hooks/preamble +9 -1
  93. package/src/assets/scripts/hooks/queue-append +53 -21
  94. package/src/assets/scripts/hooks/session-start-context +108 -29
  95. package/src/assets/scripts/hooks/session-start-memory +33 -11
  96. package/src/assets/scripts/release-trace.cjs +27 -10
  97. package/src/assets/skills/accessibility/SKILL.md +1 -1
  98. package/src/assets/skills/apply-decisions/SKILL.md +12 -82
  99. package/src/assets/skills/apply-feature-knowledge/SKILL.md +8 -42
  100. package/src/assets/skills/architecture/SKILL.md +1 -1
  101. package/src/assets/skills/boundary-validation/SKILL.md +1 -1
  102. package/src/assets/skills/complexity/SKILL.md +1 -1
  103. package/src/assets/skills/compliance/SKILL.md +1 -1
  104. package/src/assets/skills/consistency/SKILL.md +1 -1
  105. package/src/assets/skills/database/SKILL.md +1 -1
  106. package/src/assets/skills/dependencies/SKILL.md +1 -1
  107. package/src/assets/skills/dependency-research/SKILL.md +3 -6
  108. package/src/assets/skills/design-review/SKILL.md +1 -1
  109. package/src/assets/skills/docs-framework/SKILL.md +1 -1
  110. package/src/assets/skills/documentation/SKILL.md +1 -1
  111. package/src/assets/skills/gap-analysis/SKILL.md +1 -1
  112. package/src/assets/skills/git/SKILL.md +1 -1
  113. package/src/assets/skills/go/SKILL.md +1 -1
  114. package/src/assets/skills/java/SKILL.md +1 -1
  115. package/src/assets/skills/patterns/SKILL.md +1 -1
  116. package/src/assets/skills/performance/SKILL.md +1 -1
  117. package/src/assets/skills/python/SKILL.md +1 -1
  118. package/src/assets/skills/qa/SKILL.md +1 -3
  119. package/src/assets/skills/quality-gates/SKILL.md +9 -12
  120. package/src/assets/skills/quality-gates/references/report-template.md +20 -20
  121. package/src/assets/skills/react/SKILL.md +1 -1
  122. package/src/assets/skills/regression/SKILL.md +1 -1
  123. package/src/assets/skills/reliability/SKILL.md +1 -1
  124. package/src/assets/skills/research-codebase/SKILL.md +1 -1
  125. package/src/assets/skills/research-competitor/SKILL.md +1 -1
  126. package/src/assets/skills/research-external/SKILL.md +1 -1
  127. package/src/assets/skills/research-technology/SKILL.md +1 -1
  128. package/src/assets/skills/review-methodology/SKILL.md +1 -1
  129. package/src/assets/skills/rust/SKILL.md +1 -1
  130. package/src/assets/skills/security/SKILL.md +1 -1
  131. package/src/assets/skills/software-design/SKILL.md +1 -1
  132. package/src/assets/skills/test-driven-development/SKILL.md +15 -33
  133. package/src/assets/skills/testing/SKILL.md +1 -1
  134. package/src/assets/skills/typescript/SKILL.md +1 -1
  135. package/src/assets/skills/ui-design/SKILL.md +1 -1
  136. package/src/assets/skills/worktree-support/SKILL.md +3 -55
  137. package/src/assets/skills/worktree-support/references/discovery.md +48 -0
  138. package/src/assets/skills/worktree-support/references/roots.md +2 -2
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: rust
3
- description: This skill should be used when the user works with Rust files (.rs), asks about "ownership", "borrowing", "lifetimes", "Result/Option", "traits", or discusses memory safety and type-driven design. Provides patterns for ownership, error handling, type system usage, and safe concurrency.
3
+ description: This skill should be used when the user works with Rust files (.rs), asks about "ownership", "borrowing", "lifetimes", "traits", or discusses memory safety.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob
6
6
  activation:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: security
3
- description: This skill should be used when reviewing code for injection flaws, auth bypasses, or hardcoded secrets.
3
+ description: This skill should be used when reviewing code for injection, auth or secrets flaws.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: software-design
3
- description: This skill should be used when the user asks to "handle errors", "inject dependencies", "return Result", "make it immutable", "compose with pipes", or implements business logic, error handling, or service composition. Provides Result type patterns, dependency injection, immutability by default, pipe composition, and structured logging for robust application architecture.
3
+ description: This skill should be used when the user asks to "handle errors", "inject dependencies", "return Result", "make it immutable", or implements business logic or error handling.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob, AskUserQuestion
6
6
  ---
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: test-driven-development
3
- description: This skill should be used when implementing new features, fixing bugs, or writing new code. Enforces RED-GREEN-REFACTOR.
3
+ description: This skill should be used when implementing features or fixing bugs. Enforces RED-GREEN-REFACTOR.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob
6
6
  activation:
@@ -34,6 +34,8 @@ Enforce the RED-GREEN-REFACTOR cycle for all implementation work. Tests define t
34
34
 
35
35
  ## The Cycle
36
36
 
37
+ **Affected tests**: the tests that cover the changed files, selected by the runner's related-test option (Jest's `--findRelatedTests`, Vitest's `related`) or, where the runner has none, the package or path that owns them. Every "run the tests" step below means the affected tests; the full suite belongs to Validate.
38
+
37
39
  ### Step 1: RED — Write a Failing Test
38
40
 
39
41
  Write a test that describes the behavior you want. Run it. Watch it fail. The failure message IS your specification.
@@ -56,19 +58,18 @@ Don't write code "you'll need later." Write code the test demands NOW.
56
58
  Don't optimize. Don't refactor. Don't clean up. Just pass the test.
57
59
  ```
58
60
 
59
- **Checkpoint:** All tests pass. If any test fails, fix it before moving on.
61
+ **Checkpoint:** All affected tests pass. If any test fails, fix it before moving on.
60
62
 
61
63
  ### Step 3: REFACTOR — Improve Without Changing Behavior
62
64
 
63
- Now clean up. Extract helpers, rename variables, simplify logic. Tests stay green throughout.
65
+ Now clean up: extract helpers, rename, simplify, apply DRY. Tests stay green throughout.
64
66
 
65
67
  ```
66
- Run tests after every refactoring step.
68
+ Run the affected tests after every refactoring step.
67
69
  If a test breaks during refactor, undo immediately — you changed behavior.
68
- Apply DRY, extract patterns, improve readability.
69
70
  ```
70
71
 
71
- **Checkpoint:** All tests still pass. Code is clean. Repeat from Step 1 for next behavior.
72
+ **Checkpoint:** All affected tests still pass. Code is clean. Repeat from Step 1 for next behavior.
72
73
 
73
74
  ---
74
75
 
@@ -79,7 +80,7 @@ After each RED-GREEN-REFACTOR cycle, ALL must hold:
79
80
  - [ ] Test existed BEFORE production code (not concurrent, not after)
80
81
  - [ ] Test failed for the RIGHT reason (expected behavior absent, not syntax/import error)
81
82
  - [ ] Production code is minimal — no speculative additions beyond what the test demands
82
- - [ ] ALL tests pass, not just the new one
83
+ - [ ] ALL affected tests pass, not just the new one
83
84
  - [ ] Refactoring happened in Step 3 (or code is already clean — state explicitly)
84
85
  - [ ] No untested production code remains
85
86
 
@@ -96,11 +97,10 @@ These are the excuses developers use to skip TDD. Recognize and reject them.
96
97
  | "I'll write tests after" | Need to see the shape first | Tests ARE the shape — they define the interface before implementation exists | Write the test first |
97
98
  | "Too simple to test" | It's just a getter/setter | Getters break, defaults change, edge cases hide in "simple" code | Write it — takes 30 seconds |
98
99
  | "I'll refactor later" | Just get it working now | "Later" never comes; technical debt compounds silently | Refactor now in Step 3 |
99
- | "Test is too hard to write" | Setup is complex, mocking is painful | Hard-to-test code = bad design; the test is telling you the interface is wrong | Simplify the interface first |
100
- | "Need to see the whole picture" | Can't test what I haven't designed yet | TDD IS design; each test reveals the next piece of the interface | Let the test guide the design |
100
+ | "Test is too hard to write" or "the test setup is too complex" | Mocking is painful | Hard-to-test code = bad design, and complex setup = too much coupling; the test is telling you the interface is wrong | Simplify the interface first |
101
+ | "Need to see the whole picture" or "the architecture first" | Can't test what I haven't designed or structured yet | TDD IS design; each test reveals the next piece of the interface, and tests DEFINE the architecture | Let the tests drive the design and structure |
101
102
  | "Tests slow me down" | Faster to just write the code | Faster until the first regression; TDD is faster for anything > 50 lines | Trust the cycle |
102
103
  | "Framework is hard to set up" | Setup is complex | One-time cost vs recurring regression cost; untested code compounds debt | Set up the framework first — that IS the work |
103
- | "Need the architecture first" | Can't test without structure | Tests DEFINE the architecture; they reveal what interfaces are needed | Let tests drive the structure |
104
104
  | "This is infrastructure, not logic" | Plumbing doesn't need tests | Infrastructure carries data; broken plumbing floods everything downstream | Test the contract, not the internals |
105
105
  | "Deadline is tight, no time for tests" | Ship now, test later | Untested code ships bugs; fixing bugs under deadline is slower than TDD | TDD is faster under pressure, not slower |
106
106
 
@@ -108,13 +108,11 @@ See `references/rationalization-prevention.md` for extended examples with code.
108
108
 
109
109
  ### Red Flags — STOP Immediately
110
110
 
111
- The rationalization table above catches excuses you make *before starting*. These red flags catch you *mid-work* — thoughts that signal you are about to skip a step.
111
+ The table above catches excuses *before starting*. These catch you *mid-work*: thoughts that signal you are about to skip a step.
112
112
 
113
113
  | Thought | Correction |
114
114
  |---------|------------|
115
115
  | "Let me write the implementation first, tests after" | Delete the code. Write the test. Watch it fail. Then rewrite. |
116
- | "I need to see the shape before I can test" | The test IS the shape. It defines the interface before implementation. |
117
- | "The test setup is too complex for this" | Complex setup = too much coupling. Simplify the design first. |
118
116
  | "I'll just spike this and add tests later" | Unless the user said "spike" — you're rationalizing, not prototyping. |
119
117
  | "Let me get it working, then lock it with tests" | Those tests verify your implementation, not the requirement. Backwards. |
120
118
  | "I know this works, I've written it before" | Past code passed past tests. This code needs its own failing test. |
@@ -122,20 +120,11 @@ The rationalization table above catches excuses you make *before starting*. Thes
122
120
 
123
121
  ### Test-First vs Code-First
124
122
 
125
- **Code-first** (wrong):
126
- 1. Write `parseConfig()` — split lines, filter comments, build map
127
- 2. Write test: `parseConfig("key=val")` passes
128
- 3. Ship. Undiscovered: empty input, malformed lines, multi-value keys, whitespace
129
- > Test mirrors implementation. Edge cases stay hidden until production.
123
+ **Code-first** (wrong): write `parseConfig()`, then a test that mirrors it (`parseConfig("key=val")` passes). Empty input, malformed lines, multi-value keys and whitespace stay hidden until production.
130
124
 
131
- **Test-first** (correct):
132
- 1. Test: "ignores comment lines" — `parseConfig("# comment\nkey=val")` → `{key: val}`
133
- 2. Test: "handles empty input" — `parseConfig("")` → empty result
134
- 3. Test: "rejects malformed lines" — `parseConfig("no-equals")` → error
135
- 4. Implement `parseConfig()` to satisfy all three
136
- > Tests define the contract. Implementation forced to handle edges from the start.
125
+ **Test-first** (correct): "ignores comment lines", then "handles empty input", then "rejects malformed lines", each failing first and each driving the next slice of `parseConfig()`, so it handles the edges from the start.
137
126
 
138
- The difference: code-first tests verify what you *happened to build*. Test-first tests specify what *should exist*.
127
+ Code-first tests verify what you *happened to build*. Test-first tests specify what *should exist*.
139
128
 
140
129
  ### When Stuck
141
130
 
@@ -151,14 +140,7 @@ The difference: code-first tests verify what you *happened to build*. Test-first
151
140
 
152
141
  ## Process Enforcement
153
142
 
154
- When implementing any feature under ambient IMPLEMENT:
155
-
156
- 1. **Identify the first behavior** — What is the simplest thing this feature must do?
157
- 2. **Write the test** — Describe that behavior as a failing test
158
- 3. **Run the test** — Confirm it fails (RED)
159
- 4. **Write minimum code** — Just enough to pass (GREEN)
160
- 5. **Refactor** — Clean up while tests stay green (REFACTOR)
161
- 6. **Repeat** — Next behavior, next test, next cycle
143
+ When implementing any feature under ambient IMPLEMENT, start from the simplest thing it must do, take that one behavior through RED, GREEN and REFACTOR, then repeat for the next behavior.
162
144
 
163
145
  ### File Organization
164
146
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: testing
3
- description: This skill should be used when the user asks to "write tests", "fix failing tests", "improve test coverage", "add integration tests", "debug a flaky test", or reviews test quality. Provides behavior-focused testing patterns, coverage analysis, and detection of brittle test anti-patterns like implementation coupling and non-deterministic assertions.
3
+ description: This skill should be used when the user asks to "write tests", "fix failing tests", "improve test coverage" or "debug a flaky test", or reviews test quality.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob, AskUserQuestion
6
6
  activation:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: typescript
3
- description: This skill should be used when the user works with TypeScript files (.ts/.tsx), asks about "generics", "type guards", "utility types", "strict typing", "discriminated unions", or discusses type safety and inference. Provides patterns for Result types, exhaustive checks, branded types, and type-safe API contracts.
3
+ description: This skill should be used when the user works with TypeScript files (.ts/.tsx), asks about "generics", "type guards", "utility types", "discriminated unions", or discusses type safety.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob
6
6
  activation:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: ui-design
3
- description: This skill should be used when the user asks to "design a component", "pick colors", "improve typography", "fix spacing", "choose a layout", or discusses visual design, CSS, styling decisions, or responsive interfaces. Provides patterns for typography scales, color systems, spacing, and production-grade UI design.
3
+ description: This skill should be used when the user asks to "design a component", "pick colors", "improve typography", "fix spacing", or discusses visual design and CSS.
4
4
  user-invocable: false
5
5
  allowed-tools: Read, Grep, Glob
6
6
  activation:
@@ -7,8 +7,6 @@ allowed-tools: Bash, Read
7
7
 
8
8
  # Worktree Support
9
9
 
10
- Canonical patterns for worktree-aware agents and multi-worktree discovery in commands.
11
-
12
10
  ## Iron Law
13
11
 
14
12
  > **WORKTREE_PATH IS A PREFIX, NOT A FLAG**
@@ -16,8 +14,6 @@ Canonical patterns for worktree-aware agents and multi-worktree discovery in com
16
14
  > When WORKTREE_PATH is provided, it changes how you resolve ALL paths — git commands,
17
15
  > file reads, .devflow/docs/ paths. It's not a toggle; it's a coordinate system shift.
18
16
 
19
- ---
20
-
21
17
  ## Agent Path Resolution
22
18
 
23
19
  When `WORKTREE_PATH` is provided to an agent:
@@ -31,46 +27,6 @@ When `WORKTREE_PATH` is provided to an agent:
31
27
 
32
28
  If `WORKTREE_PATH` is omitted, behavior is unchanged (use cwd). This is the common case.
33
29
 
34
- ---
35
-
36
- ## Worktree Discovery Algorithm (Commands)
37
-
38
- For commands that auto-discover worktrees (`/code-review`, `/resolve`):
39
-
40
- ### Step 1: List Worktrees
41
-
42
- Run `git worktree list --porcelain`
43
-
44
- ### Step 2: Parse Each Entry
45
-
46
- Extract: `worktree {path}`, `HEAD {sha}`, `branch refs/heads/{name}`
47
-
48
- ### Step 3: Filter
49
-
50
- Exclude:
51
- - **Bare worktrees** (no branch)
52
- - **Detached HEAD** (no named branch; roots and detached HEAD: `references/roots.md`)
53
- - **Protected branches**: `main`, `master`, `develop`, `integration`, `trunk`, `release/*`, `staging`, `production`
54
- - **Mid-rebase or mid-merge**: check `git -C {path} status` for "rebase in progress" or "merging"
55
-
56
- ### Step 4: Check for Work
57
-
58
- Each worktree must have commits ahead of base branch. Skip those that are clean/up-to-date.
59
-
60
- ### Step 5: Deduplicate
61
-
62
- If two worktrees are on the same branch, use only the first worktree's path.
63
-
64
- ### Step 6: Sort
65
-
66
- Sort by last commit date (most recent first).
67
-
68
- ### Step 7: Return
69
-
70
- Return list of reviewable worktrees with path, branch, HEAD SHA.
71
-
72
- ---
73
-
74
30
  ## Protected Branches (Canonical List)
75
31
 
76
32
  `main`, `master`, `develop`, `integration`, `trunk`, `release/*`, `staging`, `production`
@@ -78,15 +34,7 @@ Return list of reviewable worktrees with path, branch, HEAD SHA.
78
34
  All components (agents, commands, skills) must use this exact list when checking for protected branches.
79
35
  The HUD mirrors this list in `TRUNK_BRANCHES`/`TRUNK_BRANCH_PREFIXES`/`isTrunkBranch()` in `src/core/git.ts` — update both together.
80
36
 
81
- ---
82
-
83
- ## Multi-Worktree Mode
37
+ ## Extended References
84
38
 
85
- | Condition | Behavior |
86
- |-----------|----------|
87
- | 0 reviewable worktrees | Error: no reviewable branches found |
88
- | 1 worktree (common case) | Single-worktree flow, zero behavior change |
89
- | 2+ worktrees | Report count, process worktrees **sequentially** (one at a time) |
90
- | 5+ worktrees | Report count and proceed — user manages their worktree count |
91
- | `--path` flag provided | Use only that worktree, skip discovery |
92
- | Same branch in 2 worktrees | Deduplicate — review once using first worktree's path |
39
+ - `references/discovery.md` — the 7-step discovery algorithm and multi-worktree mode
40
+ - `references/roots.md` — project data roots and detached HEAD
@@ -0,0 +1,48 @@
1
+ # Worktree Discovery
2
+
3
+ How commands that auto-discover worktrees (`/code-review`, `/resolve`) find them, and how the count found sets the flow. The protected-branch list lives only in the skill's `## Protected Branches (Canonical List)`; this file points to it and copies none of it.
4
+
5
+ ## Algorithm
6
+
7
+ ### Step 1: List Worktrees
8
+
9
+ Run `git worktree list --porcelain`
10
+
11
+ ### Step 2: Parse Each Entry
12
+
13
+ Extract: `worktree {path}`, `HEAD {sha}`, `branch refs/heads/{name}`
14
+
15
+ ### Step 3: Filter
16
+
17
+ Exclude:
18
+ - **Bare worktrees** (no branch)
19
+ - **Detached HEAD** (no named branch; roots and detached HEAD: `roots.md`)
20
+ - **Protected branches**: every branch in the skill's `## Protected Branches (Canonical List)`
21
+ - **Mid-rebase or mid-merge**: check `git -C {path} status` for "rebase in progress" or "merging"
22
+
23
+ ### Step 4: Check for Work
24
+
25
+ Each worktree must have commits ahead of base branch. Skip those that are clean/up-to-date.
26
+
27
+ ### Step 5: Deduplicate
28
+
29
+ If two worktrees are on the same branch, use only the first worktree's path.
30
+
31
+ ### Step 6: Sort
32
+
33
+ Sort by last commit date (most recent first).
34
+
35
+ ### Step 7: Return
36
+
37
+ Return list of reviewable worktrees with path, branch, HEAD SHA.
38
+
39
+ ## Multi-Worktree Mode
40
+
41
+ | Condition | Behavior |
42
+ |-----------|----------|
43
+ | 0 reviewable worktrees | Error: no reviewable branches found |
44
+ | 1 worktree (common case) | Single-worktree flow, zero behavior change |
45
+ | 2+ worktrees | Report count, process worktrees **sequentially** (one at a time) |
46
+ | 5+ worktrees | Report count and proceed — user manages their worktree count |
47
+ | `--path` flag provided | Use only that worktree, skip discovery |
48
+ | Same branch in 2 worktrees | Deduplicate — review once using first worktree's path |
@@ -1,6 +1,6 @@
1
1
  # Project Roots and Detached HEAD
2
2
 
3
- Where devflow keeps per-project data across checkouts, and what it does on a detached HEAD. Companion to the worktree discovery algorithm in `SKILL.md`.
3
+ Where devflow keeps per-project data across checkouts, and what it does on a detached HEAD. Companion to the worktree discovery algorithm in `discovery.md`.
4
4
 
5
5
  ## Which Root Holds What
6
6
 
@@ -24,6 +24,6 @@ A detached HEAD is a commit checked out without a branch (`git checkout <sha>`,
24
24
  | Surface | Behaviour |
25
25
  |---------|-----------|
26
26
  | Knowledge commit | Skipped: a commit there becomes unreachable once HEAD moves. The Knowledge agent reports `KB_COMMIT: skipped (detached HEAD) — uncommitted: <paths>`, and the calling workflow names those paths to the user |
27
- | Worktree discovery | Excluded from auto-review (discovery Step 3 in `SKILL.md`): there is no branch to review, compare or push |
27
+ | Worktree discovery | Excluded from auto-review (discovery Step 3 in `discovery.md`): there is no branch to review, compare or push |
28
28
  | Memory bootstrap | The first compaction bootstraps `WORKING-MEMORY.md` stamped `branch: (detached)`, keyed on the HEAD commit; an unborn branch has no commit and still skips |
29
29
  | Memory header | Renders `detached @ <short-sha>` instead of `on unknown` |