@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,463 @@
1
+ # Developer Usage Guide
2
+
3
+ This guide explains how to install and use `pi-workflow-kit` as a developer building features with the Pi coding agent.
4
+
5
+ ## What this package gives you
6
+
7
+ `pi-workflow-kit` combines:
8
+
9
+ - **Skills** — markdown instructions the agent can invoke with `/skill:<name>`
10
+ - **Extensions** — runtime behavior that tracks workflow state, warns about process mistakes, and adds tools such as `plan_tracker` and `subagent`
11
+
12
+ The intended workflow is:
13
+
14
+ ```text
15
+ brainstorm → plan → execute → finalize
16
+ ```
17
+
18
+ Inside **execute**, each task follows this lifecycle:
19
+
20
+ ```text
21
+ define → approve → execute → verify → review → fix
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ ### Option 1: Install from npm
27
+
28
+ ```bash
29
+ pi install npm:@tianhai/pi-workflow-kit
30
+ ```
31
+
32
+ Use this if you want the published package as-is.
33
+
34
+ ### Option 2: Install from the maintained git repo
35
+
36
+ ```bash
37
+ pi install git:github.com/yinloo-ola/pi-workflow-kit.git
38
+ ```
39
+
40
+ Use this if you want the repo version directly.
41
+
42
+ ### Option 3: Install from **your own maintained repo or fork**
43
+
44
+ If you are maintaining your own repo, install from that repo directly:
45
+
46
+ ```bash
47
+ pi install git:github.com/yinloo-ola/pi-workflow-kit.git
48
+ ```
49
+
50
+ For a different fork/repo, use:
51
+
52
+ ```bash
53
+ pi install git:github.com/<your-user>/<your-repo>.git
54
+ ```
55
+
56
+ Examples:
57
+
58
+ ```bash
59
+ pi install git:github.com/acme/pi-workflow-kit.git
60
+ pi install git:github.com/yinloo-ola/pi-workflow-kit.git
61
+ ```
62
+
63
+ This is the best option when:
64
+ - you have customized the skills or extensions
65
+ - you want full control over updates
66
+ - you do not plan to track upstream releases closely
67
+
68
+ ### Option 4: Add your repo to Pi config
69
+
70
+ Project-level `.pi/settings.json` or global `~/.pi/agent/config.json`:
71
+
72
+ ```json
73
+ {
74
+ "packages": ["git:github.com/yinloo-ola/pi-workflow-kit.git"]
75
+ }
76
+ ```
77
+
78
+ If you prefer npm instead, you can still use:
79
+
80
+ ```json
81
+ {
82
+ "packages": ["npm:@tianhai/pi-workflow-kit"]
83
+ }
84
+ ```
85
+
86
+ After installation, Pi will load the package from whichever source you chose. If you installed from your own repo, future updates come from **your repo**, not the upstream package.
87
+
88
+ ## What activates automatically
89
+
90
+ After installation, Pi loads:
91
+
92
+ ### Skills
93
+ - `brainstorming`
94
+ - `writing-plans`
95
+ - `executing-tasks`
96
+ - `test-driven-development`
97
+ - `systematic-debugging`
98
+ - `using-git-worktrees`
99
+ - `dispatching-parallel-agents`
100
+ - `receiving-code-review`
101
+
102
+ ### Extensions
103
+ - **workflow-monitor**
104
+ - **plan-tracker**
105
+ - **subagent**
106
+
107
+ You do not need to enable these manually.
108
+
109
+ ## Core commands and tools
110
+
111
+ ### Skill invocation
112
+
113
+ Invoke skills directly in the Pi session:
114
+
115
+ ```text
116
+ /skill:brainstorming
117
+ /skill:writing-plans
118
+ /skill:executing-tasks
119
+ ```
120
+
121
+ ### Workflow handoff
122
+
123
+ Start a fresh session for the next phase:
124
+
125
+ ```text
126
+ /workflow-next brainstorm
127
+ /workflow-next plan docs/plans/2026-04-09-feature-design.md
128
+ /workflow-next execute docs/plans/2026-04-09-feature-implementation.md
129
+ /workflow-next finalize docs/plans/2026-04-09-feature-implementation.md
130
+ ```
131
+
132
+ ### Plan tracking
133
+
134
+ Track execution progress:
135
+
136
+ ```ts
137
+ plan_tracker({
138
+ action: "init",
139
+ tasks: [
140
+ { name: "Implement endpoint", type: "code" },
141
+ { name: "Update README", type: "non-code" },
142
+ ],
143
+ })
144
+
145
+ plan_tracker({ action: "update", index: 0, phase: "define" })
146
+ plan_tracker({ action: "update", index: 0, phase: "approve" })
147
+ plan_tracker({ action: "update", index: 0, phase: "execute", attempts: 1 })
148
+ plan_tracker({ action: "update", index: 0, phase: "verify" })
149
+ plan_tracker({ action: "update", index: 0, phase: "review" })
150
+ plan_tracker({ action: "update", index: 0, status: "complete" })
151
+ ```
152
+
153
+ ### Subagent dispatch
154
+
155
+ Use bundled agents through the `subagent` tool.
156
+
157
+ Bundled agents require:
158
+
159
+ ```ts
160
+ agentScope: "both"
161
+ ```
162
+
163
+ Example:
164
+
165
+ ```ts
166
+ subagent({
167
+ agent: "code-reviewer",
168
+ task: "Review Task 2 implementation against the plan and tests",
169
+ agentScope: "both",
170
+ })
171
+ ```
172
+
173
+ ## Recommended developer workflow
174
+
175
+ ## 1. Brainstorm
176
+
177
+ Use this when you have an idea, request, or rough spec.
178
+
179
+ ```text
180
+ /skill:brainstorming
181
+ ```
182
+
183
+ Expected outcome:
184
+ - a clarified design
185
+ - a design artifact in `docs/plans/`
186
+ - optional worktree/branch setup
187
+
188
+ Good time to use:
189
+ - `/skill:using-git-worktrees` for larger changes or isolated work
190
+
191
+ ## 2. Write the implementation plan
192
+
193
+ Use:
194
+
195
+ ```text
196
+ /skill:writing-plans
197
+ ```
198
+
199
+ The implementation plan should be saved under:
200
+
201
+ ```text
202
+ docs/plans/YYYY-MM-DD-<feature>-implementation.md
203
+ ```
204
+
205
+ ### Plan authoring rules
206
+
207
+ Each task should include:
208
+ - a task title
209
+ - `**Type:** code` or `**Type:** non-code`
210
+ - exact file paths
211
+ - concrete implementation steps
212
+ - for code tasks: TDD steps and test commands
213
+ - for non-code tasks: explicit acceptance criteria
214
+
215
+ ### Example task shapes
216
+
217
+ Code task:
218
+
219
+ ```md
220
+ ### Task 1: Add retry logic
221
+
222
+ **Type:** code
223
+ **TDD scenario:** New feature — full TDD cycle
224
+
225
+ **Files:**
226
+ - Modify: `src/retry.ts`
227
+ - Test: `tests/retry.test.ts`
228
+ ```
229
+
230
+ Non-code task:
231
+
232
+ ```md
233
+ ### Task 2: Update docs
234
+
235
+ **Type:** non-code
236
+
237
+ **Files:**
238
+ - Modify: `README.md`
239
+ - Modify: `docs/architecture.md`
240
+
241
+ **Acceptance criteria:**
242
+ - README describes the new API accurately
243
+ - Architecture doc reflects the new flow
244
+ - Terminology matches the codebase
245
+ ```
246
+
247
+ ## 3. Execute the plan
248
+
249
+ Use:
250
+
251
+ ```text
252
+ /skill:executing-tasks
253
+ ```
254
+
255
+ At the start of execution, the agent should:
256
+ 1. read the plan
257
+ 2. extract tasks and task types
258
+ 3. initialize `plan_tracker`
259
+
260
+ Example:
261
+
262
+ ```ts
263
+ plan_tracker({
264
+ action: "init",
265
+ tasks: [
266
+ { name: "Add retry logic", type: "code" },
267
+ { name: "Update docs", type: "non-code" },
268
+ ],
269
+ })
270
+ ```
271
+
272
+ ## Per-task lifecycle during execution
273
+
274
+ For each task:
275
+
276
+ 1. **define**
277
+ - code task: define/write tests
278
+ - non-code task: define/refine acceptance criteria
279
+ 2. **approve**
280
+ - human approves tests or acceptance criteria
281
+ 3. **execute**
282
+ - implement the task
283
+ - bounded retries
284
+ 4. **verify**
285
+ - rerun checks and report pass/fail
286
+ 5. **review**
287
+ - subagent review + human sign-off
288
+ 6. **fix**
289
+ - address review issues and re-enter verify/review
290
+
291
+ ### Important behavior
292
+
293
+ - **Code tasks** follow TDD guidance
294
+ - **Non-code tasks** use acceptance criteria instead of TDD
295
+ - The plan tracker widget shows task progress in the TUI
296
+ - When all tasks reach a terminal state, the workflow can move into **finalize**
297
+
298
+ ## 4. Finalize
299
+
300
+ Use:
301
+
302
+ ```text
303
+ /skill:executing-tasks
304
+ ```
305
+
306
+ or start a fresh finalize session with:
307
+
308
+ ```text
309
+ /workflow-next finalize docs/plans/2026-04-09-feature-implementation.md
310
+ ```
311
+
312
+ Finalize typically includes:
313
+ - holistic review
314
+ - PR preparation
315
+ - doc updates
316
+ - archive planning docs
317
+ - cleanup of worktree/branch if needed
318
+
319
+ ## What the extensions do while you work
320
+
321
+ ### Workflow Monitor
322
+
323
+ The workflow monitor runs in the background and helps keep the agent aligned.
324
+
325
+ It can:
326
+ - track the current global phase
327
+ - prompt at workflow boundaries
328
+ - warn when source is written before tests
329
+ - warn when fixing starts without investigation after failures
330
+ - warn on commit/push/PR creation without recent passing verification
331
+ - remind the agent to confirm branch/worktree before the first write
332
+
333
+ ### Task Tracker
334
+
335
+ The plan tracker stores execution state outside the prompt and shows it in the TUI.
336
+
337
+ It tracks:
338
+ - task name
339
+ - task type
340
+ - task status
341
+ - task phase
342
+ - execute attempts
343
+ - fix attempts
344
+
345
+ ### Subagent
346
+
347
+ The subagent extension lets the main agent delegate focused work to isolated helper agents.
348
+
349
+ Bundled agents include:
350
+ - `implementer`
351
+ - `worker`
352
+ - `code-reviewer`
353
+ - `spec-reviewer`
354
+
355
+ ## Practical examples
356
+
357
+ ### Example: Start a new feature
358
+
359
+ ```text
360
+ /skill:brainstorming
361
+ ```
362
+
363
+ Then:
364
+
365
+ ```text
366
+ /skill:writing-plans
367
+ ```
368
+
369
+ Then:
370
+
371
+ ```text
372
+ /skill:executing-tasks
373
+ ```
374
+
375
+ ### Example: Ask for code review during execution
376
+
377
+ ```ts
378
+ subagent({
379
+ agent: "code-reviewer",
380
+ task: "Review Task 3 implementation for correctness, edge cases, and test coverage",
381
+ agentScope: "both",
382
+ })
383
+ ```
384
+
385
+ ### Example: Move to a fresh execute session
386
+
387
+ ```text
388
+ /workflow-next execute docs/plans/2026-04-09-my-feature-implementation.md
389
+ ```
390
+
391
+ ### Example: Move to a fresh finalize session
392
+
393
+ ```text
394
+ /workflow-next finalize docs/plans/2026-04-09-my-feature-implementation.md
395
+ ```
396
+
397
+ ## Publishing your maintained package
398
+
399
+ If you publish the maintained fork to npm, the package name is:
400
+
401
+ ```text
402
+ @tianhai/pi-workflow-kit
403
+ ```
404
+
405
+ Typical release flow:
406
+
407
+ ```bash
408
+ npm run check
409
+ npm version patch
410
+ git push origin main --follow-tags
411
+ ```
412
+
413
+ Then users install with:
414
+
415
+ ```bash
416
+ pi install npm:@tianhai/pi-workflow-kit
417
+ ```
418
+
419
+ ## Best practices for developers
420
+
421
+ - Start with `brainstorming` for anything non-trivial
422
+ - Use `writing-plans` before touching code for multi-step work
423
+ - Put all plan artifacts under `docs/plans/`
424
+ - Always include task `Type:` in implementation plans
425
+ - Use `code` for implementation/test work and `non-code` for docs/process tasks
426
+ - Let `plan_tracker` reflect the real lifecycle instead of keeping state only in chat
427
+ - Use `subagent(..., agentScope: "both")` when you want bundled agents
428
+ - Treat workflow monitor warnings as signals to correct process, not as noise
429
+ - Use `/workflow-next` when handing off between large phases or sessions
430
+
431
+ ## Common mistakes to avoid
432
+
433
+ - Starting execution without an implementation plan
434
+ - Initializing `plan_tracker` with task names only when your plan contains non-code tasks
435
+ - Forgetting `agentScope: "both"` for bundled subagents
436
+ - Treating verify/review as global phases instead of per-task steps inside execute
437
+ - Writing files outside `docs/plans/` during brainstorm/plan unless you intentionally advance phases
438
+ - Claiming work is done without running verification checks
439
+
440
+ ## Migration note
441
+
442
+ If you previously installed `@yinlootan/pi-superpowers-plus`, replace it with:
443
+
444
+ ```json
445
+ {
446
+ "packages": ["npm:@tianhai/pi-workflow-kit"]
447
+ }
448
+ ```
449
+
450
+ The rebrand keeps runtime names stable, so existing usage still centers on:
451
+ - `plan_tracker`
452
+ - `workflow_reference`
453
+ - `/workflow-next`
454
+ - `/workflow-reset`
455
+ - the existing skill names
456
+
457
+ ## Where to look next
458
+
459
+ - `README.md`
460
+ - `docs/oversight-model.md`
461
+ - `docs/workflow-phases.md`
462
+ - `skills/writing-plans/SKILL.md`
463
+ - `skills/executing-tasks/SKILL.md`
@@ -0,0 +1,49 @@
1
+ # Oversight Model
2
+
3
+ `pi-workflow-kit` combines **skills** and **extensions**.
4
+
5
+ ## Skills
6
+
7
+ Skills teach the agent the intended workflow:
8
+
9
+ - `brainstorming`
10
+ - `writing-plans`
11
+ - `executing-tasks`
12
+ - supporting skills such as TDD, debugging, worktrees, and review handling
13
+
14
+ They explain *what* to do and *when* to do it.
15
+
16
+ ## Extensions
17
+
18
+ Extensions observe runtime behavior and add lightweight enforcement:
19
+
20
+ - **workflow-monitor** tracks workflow phase, injects TDD/debug/verification warnings, and prompts at phase boundaries
21
+ - **plan-tracker** stores per-task execution state, including task type, phase, and attempt counts
22
+ - **subagent** runs isolated helper agents for implementation and review work
23
+
24
+ ## Enforcement style
25
+
26
+ The package is intentionally **warning-first**.
27
+
28
+ - TDD violations are injected into tool results as warnings
29
+ - Debug guardrails escalate after repeated failing cycles
30
+ - Verification checks warn on `git commit`, `git push`, and `gh pr create` when passing tests have not been run recently
31
+ - During brainstorm and plan, writes outside `docs/plans/` trigger process warnings and may escalate to an interactive stop in the TUI
32
+
33
+ In interactive sessions, repeated violations can trigger a human decision prompt.
34
+
35
+ ## Workflow model
36
+
37
+ Global workflow phases:
38
+
39
+ ```text
40
+ brainstorm → plan → execute → finalize
41
+ ```
42
+
43
+ Inside **execute**, each task follows the per-task lifecycle tracked by `plan_tracker`:
44
+
45
+ ```text
46
+ define → approve → execute → verify → review → fix
47
+ ```
48
+
49
+ This keeps global workflow tracking simple while still reflecting the real per-task feedback loop.
@@ -0,0 +1,71 @@
1
+ # Workflow Phases
2
+
3
+ `pi-workflow-kit` tracks four global phases:
4
+
5
+ ```text
6
+ brainstorm → plan → execute → finalize
7
+ ```
8
+
9
+ ## brainstorm
10
+
11
+ Primary skill: `/skill:brainstorming`
12
+
13
+ Purpose:
14
+ - explore requirements
15
+ - shape the design
16
+ - produce a design artifact under `docs/plans/`
17
+
18
+ Write boundary:
19
+ - allowed: `docs/plans/`
20
+ - discouraged elsewhere; runtime warnings may be injected
21
+
22
+ ## plan
23
+
24
+ Primary skill: `/skill:writing-plans`
25
+
26
+ Purpose:
27
+ - turn the design into a concrete implementation plan
28
+ - define task type (`code` or `non-code`)
29
+ - define code-task steps or non-code acceptance criteria
30
+
31
+ Write boundary:
32
+ - allowed: `docs/plans/`
33
+ - discouraged elsewhere; runtime warnings may be injected
34
+
35
+ ## execute
36
+
37
+ Primary skill: `/skill:executing-tasks`
38
+
39
+ Purpose:
40
+ - initialize `plan_tracker`
41
+ - execute tasks one at a time
42
+ - track per-task phase and attempt counts
43
+
44
+ Per-task phases:
45
+ - `define`
46
+ - `approve`
47
+ - `execute`
48
+ - `verify`
49
+ - `review`
50
+ - `fix`
51
+ - terminal states: `complete`, `blocked`
52
+
53
+ ## finalize
54
+
55
+ Primary skill: `/skill:executing-tasks`
56
+
57
+ Purpose:
58
+ - perform holistic review
59
+ - prepare PR / push / cleanup
60
+ - archive planning docs
61
+ - update README / CHANGELOG / other documentation when needed
62
+
63
+ ## Detection signals
64
+
65
+ The workflow monitor uses a few practical signals:
66
+
67
+ - skill invocations such as `/skill:brainstorming` or `/skill:writing-plans`
68
+ - writes to `docs/plans/*-design.md` and `docs/plans/*-implementation.md`
69
+ - `plan_tracker` initialization to enter execute
70
+ - all tracked tasks reaching terminal state to mark execute complete
71
+ - boundary-prompt acceptance to enter finalize
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared constants for pi-workflow-kit extensions.
3
+ *
4
+ * PLAN_TRACKER_TOOL_NAME is the stable integration contract between plan-tracker
5
+ * and workflow-monitor: when plan-tracker receives an "init" action,
6
+ * workflow-monitor observes it to advance the workflow phase to "execute".
7
+ * This tool id intentionally remains unchanged across the rebrand.
8
+ */
9
+ export const PLAN_TRACKER_TOOL_NAME = "plan_tracker";