@tianhai/pi-workflow-kit 0.4.1

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 (54) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +509 -0
  3. package/ROADMAP.md +16 -0
  4. package/agents/code-reviewer.md +18 -0
  5. package/agents/config.ts +5 -0
  6. package/agents/implementer.md +26 -0
  7. package/agents/spec-reviewer.md +13 -0
  8. package/agents/worker.md +17 -0
  9. package/banner.jpg +0 -0
  10. package/docs/developer-usage-guide.md +463 -0
  11. package/docs/oversight-model.md +49 -0
  12. package/docs/workflow-phases.md +71 -0
  13. package/extensions/constants.ts +9 -0
  14. package/extensions/lib/logging.ts +138 -0
  15. package/extensions/plan-tracker.ts +496 -0
  16. package/extensions/subagent/agents.ts +144 -0
  17. package/extensions/subagent/concurrency.ts +52 -0
  18. package/extensions/subagent/env.ts +47 -0
  19. package/extensions/subagent/index.ts +1116 -0
  20. package/extensions/subagent/lifecycle.ts +25 -0
  21. package/extensions/subagent/timeout.ts +13 -0
  22. package/extensions/workflow-monitor/debug-monitor.ts +98 -0
  23. package/extensions/workflow-monitor/git.ts +31 -0
  24. package/extensions/workflow-monitor/heuristics.ts +58 -0
  25. package/extensions/workflow-monitor/investigation.ts +52 -0
  26. package/extensions/workflow-monitor/reference-tool.ts +42 -0
  27. package/extensions/workflow-monitor/skip-confirmation.ts +19 -0
  28. package/extensions/workflow-monitor/tdd-monitor.ts +137 -0
  29. package/extensions/workflow-monitor/test-runner.ts +37 -0
  30. package/extensions/workflow-monitor/verification-monitor.ts +61 -0
  31. package/extensions/workflow-monitor/warnings.ts +81 -0
  32. package/extensions/workflow-monitor/workflow-handler.ts +358 -0
  33. package/extensions/workflow-monitor/workflow-tracker.ts +231 -0
  34. package/extensions/workflow-monitor/workflow-transitions.ts +55 -0
  35. package/extensions/workflow-monitor.ts +885 -0
  36. package/package.json +49 -0
  37. package/skills/brainstorming/SKILL.md +70 -0
  38. package/skills/dispatching-parallel-agents/SKILL.md +194 -0
  39. package/skills/executing-tasks/SKILL.md +247 -0
  40. package/skills/receiving-code-review/SKILL.md +196 -0
  41. package/skills/systematic-debugging/SKILL.md +170 -0
  42. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  43. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  44. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  45. package/skills/systematic-debugging/find-polluter.sh +63 -0
  46. package/skills/systematic-debugging/reference/rationalizations.md +61 -0
  47. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  48. package/skills/test-driven-development/SKILL.md +266 -0
  49. package/skills/test-driven-development/reference/examples.md +101 -0
  50. package/skills/test-driven-development/reference/rationalizations.md +67 -0
  51. package/skills/test-driven-development/reference/when-stuck.md +33 -0
  52. package/skills/test-driven-development/testing-anti-patterns.md +299 -0
  53. package/skills/using-git-worktrees/SKILL.md +231 -0
  54. package/skills/writing-plans/SKILL.md +149 -0
@@ -0,0 +1,231 @@
1
+ ---
2
+ name: using-git-worktrees
3
+ description: Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
4
+ ---
5
+
6
+ > **Related skills:** Set up after `/skill:brainstorming`. Execute with `/skill:executing-tasks`. Clean up with `/skill:executing-tasks`.
7
+
8
+ # Using Git Worktrees
9
+
10
+ ## Overview
11
+
12
+ Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
13
+
14
+ **Core principle:** Systematic directory selection + safety verification = reliable isolation.
15
+
16
+ **Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."
17
+
18
+ ## Directory Selection Process
19
+
20
+ Follow this priority order:
21
+
22
+ ### 1. Check Existing Directories
23
+
24
+ ```bash
25
+ # Check in priority order
26
+ ls -d .worktrees 2>/dev/null # Preferred (hidden)
27
+ ls -d worktrees 2>/dev/null # Alternative
28
+ ```
29
+
30
+ **If found:** Use that directory. If both exist, `.worktrees` wins.
31
+
32
+ ### 2. Check Project Configuration
33
+
34
+ ```bash
35
+ grep -i "worktree.*director" README.md .pi/settings.json AGENTS.md 2>/dev/null
36
+ ```
37
+
38
+ **If preference specified:** Use it without asking.
39
+
40
+ ### 3. Ask User
41
+
42
+ If no directory exists and no project configuration preference:
43
+
44
+ ```
45
+ No worktree directory found. Where should I create worktrees?
46
+
47
+ 1. .worktrees/ (project-local, hidden)
48
+ 2. ~/worktrees/<project-name>/ (global location)
49
+
50
+ Which would you prefer?
51
+ ```
52
+
53
+ ## Safety Verification
54
+
55
+ ### For Project-Local Directories (.worktrees or worktrees)
56
+
57
+ **MUST verify directory is ignored before creating worktree:**
58
+
59
+ ```bash
60
+ # Check if directory is ignored (respects local, global, and system gitignore)
61
+ git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
62
+ ```
63
+
64
+ **If NOT ignored:**
65
+
66
+ Fix broken things immediately:
67
+ 1. Add appropriate line to .gitignore
68
+ 2. Commit the change
69
+ 3. Proceed with worktree creation
70
+
71
+ **Why critical:** Prevents accidentally committing worktree contents to repository.
72
+
73
+ ### For Global Directory (~/worktrees)
74
+
75
+ No .gitignore verification needed - outside project entirely.
76
+
77
+ ## Creation Steps
78
+
79
+ ### 1. Detect Project Name
80
+
81
+ ```bash
82
+ project=$(basename "$(git rev-parse --show-toplevel)")
83
+ ```
84
+
85
+ ### 2. Create Worktree
86
+
87
+ ```bash
88
+ # Determine full path
89
+ case $LOCATION in
90
+ .worktrees|worktrees)
91
+ path="$LOCATION/$BRANCH_NAME"
92
+ ;;
93
+ ~/worktrees/*)
94
+ path="~/worktrees/$project/$BRANCH_NAME"
95
+ ;;
96
+ esac
97
+
98
+ # Create worktree with new branch
99
+ git worktree add "$path" -b "$BRANCH_NAME"
100
+ cd "$path"
101
+ ```
102
+
103
+ ### 3. Run Project Setup
104
+
105
+ Auto-detect and run appropriate setup:
106
+
107
+ ```bash
108
+ # Node.js
109
+ if [ -f package.json ]; then npm install; fi
110
+
111
+ # Rust
112
+ if [ -f Cargo.toml ]; then cargo build; fi
113
+
114
+ # Python
115
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
116
+ if [ -f pyproject.toml ]; then poetry install; fi
117
+
118
+ # Go
119
+ if [ -f go.mod ]; then go mod download; fi
120
+ ```
121
+
122
+ ### 4. Verify Clean Baseline
123
+
124
+ Run tests to ensure worktree starts clean:
125
+
126
+ ```bash
127
+ # Examples - use project-appropriate command
128
+ npm test
129
+ cargo test
130
+ pytest
131
+ go test ./...
132
+ ```
133
+
134
+ **If tests fail:** Report failures, ask whether to proceed or investigate.
135
+
136
+ **If tests pass:** Report ready.
137
+
138
+ ### 5. Report Location
139
+
140
+ ```
141
+ Worktree ready at <full-path>
142
+ Tests passing (<N> tests, 0 failures)
143
+ Ready to implement <feature-name>
144
+ ```
145
+
146
+ ## Keeping a Worktree Current
147
+
148
+ For longer-running work, the base branch may advance. If upstream changes cause test failures or you need new code from main:
149
+
150
+ ```bash
151
+ git fetch origin
152
+ git rebase origin/main # or git merge origin/main
153
+ ```
154
+
155
+ Re-run tests after rebasing. Prefer rebase for clean history unless the branch is shared.
156
+
157
+ ## Quick Reference
158
+
159
+ | Situation | Action |
160
+ |-----------|--------|
161
+ | `.worktrees/` exists | Use it (verify ignored) |
162
+ | `worktrees/` exists | Use it (verify ignored) |
163
+ | Both exist | Use `.worktrees/` |
164
+ | Neither exists | Check project config → Ask user |
165
+ | Directory not ignored | Add to .gitignore + commit |
166
+ | Tests fail during baseline | Report failures + ask |
167
+ | No package.json/Cargo.toml | Skip dependency install |
168
+
169
+ ## Common Mistakes
170
+
171
+ ### Skipping ignore verification
172
+
173
+ - **Problem:** Worktree contents get tracked, pollute git status
174
+ - **Fix:** Always use `git check-ignore` before creating project-local worktree
175
+
176
+ ### Assuming directory location
177
+
178
+ - **Problem:** Creates inconsistency, violates project conventions
179
+ - **Fix:** Follow priority: existing > project config > ask
180
+
181
+ ### Proceeding with failing tests
182
+
183
+ - **Problem:** Can't distinguish new bugs from pre-existing issues
184
+ - **Fix:** Report failures, get explicit permission to proceed
185
+
186
+ ### Hardcoding setup commands
187
+
188
+ - **Problem:** Breaks on projects using different tools
189
+ - **Fix:** Auto-detect from project files (package.json, etc.)
190
+
191
+ ## Example Workflow
192
+
193
+ ```
194
+ You: I'm using the using-git-worktrees skill to set up an isolated workspace.
195
+
196
+ [Check .worktrees/ - exists]
197
+ [Verify ignored - git check-ignore confirms .worktrees/ is ignored]
198
+ [Create worktree: git worktree add .worktrees/auth -b feature/auth]
199
+ [Run npm install]
200
+ [Run npm test - 47 passing]
201
+
202
+ Worktree ready at /home/user/myproject/.worktrees/auth
203
+ Tests passing (47 tests, 0 failures)
204
+ Ready to implement auth feature
205
+ ```
206
+
207
+ ## Red Flags
208
+
209
+ **Never:**
210
+ - Create worktree without verifying it's ignored (project-local)
211
+ - Skip baseline test verification
212
+ - Proceed with failing tests without asking
213
+ - Assume directory location when ambiguous
214
+
215
+ **Always:**
216
+ - Follow directory priority: existing > project config > ask
217
+ - Verify directory is ignored for project-local
218
+ - Auto-detect and run project setup
219
+ - Verify clean test baseline
220
+
221
+ ## Integration
222
+
223
+ **Called by:**
224
+ - **`/skill:brainstorming`** - When design is approved and implementation follows
225
+ - **`/skill:executing-tasks`** - Execute tasks in isolated workspace
226
+ - Any skill needing isolated workspace
227
+
228
+ **Note:** For small changes, branching in the current directory is acceptable with human approval. Worktrees are the default for larger work.
229
+
230
+ **Pairs with:**
231
+ - **`/skill:executing-tasks`** - REQUIRED for cleanup after work complete
@@ -0,0 +1,149 @@
1
+ ---
2
+ name: writing-plans
3
+ description: Use when you have a spec or requirements for a multi-step task, before touching code
4
+ ---
5
+
6
+ > **Related skills:** Did you `/skill:brainstorming` first? Ready to implement? Use `/skill:executing-tasks`.
7
+
8
+ # Writing Plans
9
+
10
+ ## Overview
11
+
12
+ Write comprehensive implementation plans assuming the engineer has zero context for our codebase and questionable taste. Document everything they need to know: which files to touch for each task, code, testing, docs they might need to check, how to test it. Give them the whole plan as bite-sized tasks. DRY. YAGNI. TDD. Frequent commits.
13
+
14
+ Assume they are a skilled developer, but know almost nothing about our toolset or problem domain. Assume they don't know good test design very well.
15
+
16
+ **Announce at start:** "I'm using the writing-plans skill to create the implementation plan."
17
+
18
+ **Context:** This should be run in a dedicated worktree (created by brainstorming skill).
19
+
20
+ **Save plans to:** `docs/plans/YYYY-MM-DD-<feature-name>-implementation.md`
21
+
22
+ ## Boundaries
23
+ - Read code and docs: yes
24
+ - Write to docs/plans/: yes
25
+ - Edit or create any other files: no
26
+
27
+ ## Bite-Sized Task Granularity
28
+
29
+ **Each step is one action (2-5 minutes):**
30
+ - "Write the failing test" - step
31
+ - "Run it to make sure it fails" - step
32
+ - "Implement the minimal code to make the test pass" - step
33
+ - "Run the tests and make sure they pass" - step
34
+ - "Commit" - step
35
+
36
+ ## Plan Document Header
37
+
38
+ **Every plan MUST start with this header:**
39
+
40
+ ```markdown
41
+ # [Feature Name] Implementation Plan
42
+
43
+ > **REQUIRED SUB-SKILL:** Use the executing-tasks skill to implement this plan task-by-task.
44
+
45
+ **Goal:** [One sentence describing what this builds]
46
+
47
+ **Architecture:** [2-3 sentences about approach]
48
+
49
+ **Tech Stack:** [Key technologies/libraries]
50
+
51
+ ---
52
+ ```
53
+
54
+ ## Task Structure
55
+
56
+ Every task must declare its type explicitly so `executing-tasks` can initialize `plan_tracker` with the correct metadata.
57
+
58
+ ### Code task template
59
+
60
+ ```markdown
61
+ ### Task N: [Component Name]
62
+
63
+ **Type:** code
64
+ **TDD scenario:** [New feature — full TDD cycle | Modifying tested code — run existing tests first | Trivial change — use judgment]
65
+
66
+ **Files:**
67
+ - Create: `exact/path/to/file.py`
68
+ - Modify: `exact/path/to/existing.py:123-145`
69
+ - Test: `tests/exact/path/to/test.py`
70
+
71
+ **Step 1: Write the failing test**
72
+
73
+ ```python
74
+ def test_specific_behavior():
75
+ result = function(input)
76
+ assert result == expected
77
+ ```
78
+
79
+ **Step 2: Run test to verify it fails**
80
+
81
+ Run: `pytest tests/path/test.py::test_name -v`
82
+ Expected: FAIL with "function not defined"
83
+
84
+ **Step 3: Write minimal implementation**
85
+
86
+ ```python
87
+ def function(input):
88
+ return expected
89
+ ```
90
+
91
+ **Step 4: Run test to verify it passes**
92
+
93
+ Run: `pytest tests/path/test.py::test_name -v`
94
+ Expected: PASS
95
+
96
+ **Step 5: Commit**
97
+
98
+ ```bash
99
+ git add tests/path/test.py src/path/file.py
100
+ git commit -m "feat: add specific feature"
101
+ ```
102
+ ```
103
+
104
+ ### Non-code task template
105
+
106
+ ```markdown
107
+ ### Task N: [Documentation / rollout / analysis task]
108
+
109
+ **Type:** non-code
110
+
111
+ **Files:**
112
+ - Modify: `README.md`
113
+ - Modify: `docs/architecture.md`
114
+
115
+ **Acceptance criteria:**
116
+ - Criterion 1: [Specific, observable outcome]
117
+ - Criterion 2: [Specific, observable outcome]
118
+ - Criterion 3: [Specific, observable outcome]
119
+
120
+ **Implementation notes:**
121
+ - Update the listed files only.
122
+ - Keep terminology consistent with the rest of the repo.
123
+ - Reference the relevant code paths or docs where useful.
124
+
125
+ **Verification:**
126
+ - Review each acceptance criterion one-by-one.
127
+ - Confirm the updated docs match the implemented behavior.
128
+ ```
129
+
130
+ ## Remember
131
+ - Exact file paths always
132
+ - Every task must include `**Type:** code` or `**Type:** non-code`
133
+ - Non-code tasks must include explicit `**Acceptance criteria:**`
134
+ - Complete code in plan (not "add validation")
135
+ - Exact commands with expected output
136
+ - Reference relevant skills
137
+ - DRY, YAGNI, TDD, frequent commits
138
+ - Order tasks so each task's dependencies are completed by earlier tasks
139
+ - If plan exceeds ~8 tasks, consider splitting into phases with a checkpoint between them
140
+
141
+ ## Execution Handoff
142
+
143
+ After saving the plan, the workflow monitor automatically tracks phase transitions when you invoke skills.
144
+
145
+ Then offer execution:
146
+
147
+ **"Plan complete and saved to `docs/plans/<filename>.md`. Ready to execute with `/skill:executing-tasks`."**
148
+
149
+ The executing-tasks skill handles the full per-task lifecycle (define → approve → execute → verify → review → fix) with human gates and bounded retry loops.