pi-pipelines 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.
@@ -0,0 +1,575 @@
1
+ ---
2
+ description: >
3
+ Create, validate, and manage YAML pipeline definitions for the pi-pipelines
4
+ extension. Covers pipeline format, stage types, review gates, dynamic
5
+ expansion, template variables, agent recommendations, best practices, and
6
+ testing. Use this skill when asked to create, modify, explain, or debug
7
+ a pipeline, or to generate YAML definitions.
8
+ ---
9
+
10
+ # Pi Pipelines — Creating Custom Pipelines
11
+
12
+ Complete guide for creating YAML pipelines for the pi-pipelines extension.
13
+
14
+ ---
15
+
16
+ ## 1. Where to create pipelines
17
+
18
+ Pipelines are discovered in three locations, in this order:
19
+
20
+ | Location | Description |
21
+ |---|---|
22
+ | `.pi/pipelines/` | **Project** — pipelines specific to the current project |
23
+ | `~/.pi/pipelines/` | **Global** — pipelines available in every project |
24
+ | `pipelines/` (extension) | **Bundled** — default pipelines shipped with the extension |
25
+
26
+ A project pipeline overrides a global pipeline, and a global pipeline overrides a bundled pipeline.
27
+ You can override any bundled pipeline by creating your own pipeline with the same name in `.pi/pipelines/` or `~/.pi/pipelines/`.
28
+
29
+ On first startup, the extension automatically copies bundled pipelines to `~/.pi/pipelines/` if they do not already exist.
30
+
31
+ ---
32
+
33
+ ## 2. Minimal pipeline — basic format
34
+
35
+ ```yaml
36
+ name: hello-world
37
+ description: "Short description of what the pipeline does"
38
+
39
+ stages:
40
+ - id: explore
41
+ agent: scout
42
+ task: "Explore the project structure for: {task}"
43
+
44
+ - id: plan
45
+ agent: planner
46
+ task: "Create a plan based on: {outputs.explore}"
47
+ ```
48
+
49
+ ### Required and optional pipeline fields
50
+
51
+ | Field | Required | Description |
52
+ |---|---|---|
53
+ | `name` | ✅ | Pipeline name, used as `/pipeline-<name>` |
54
+ | `description` | ✅ | Description shown by `/list-pipelines` |
55
+ | `stages[]` | ✅ | List of stages to execute |
56
+ | `report` | ❌ | Synthesis config — `{ agent, focus }` or `false` to disable |
57
+ | `version` | ❌ | Schema version (reserved for future use) |
58
+
59
+ ### Every stage requires:
60
+
61
+ | Field | Type | Description |
62
+ |---|---|---|
63
+ | `id` | string | Unique stage identifier |
64
+ | `agent` or `parallel` | string/array | Agent to run, or list of parallel agents |
65
+ | `task` | string | Task for the agent; supports template variables |
66
+ | `model` *optional* | string | Model override for this stage |
67
+
68
+ ---
69
+
70
+ ## 3. Template variables
71
+
72
+ Before a task is sent to an agent, the runner resolves template variables:
73
+
74
+ | Variable | Resolves to | Example |
75
+ |---|---|---|
76
+ | `{task}` | Original task passed when the pipeline was launched | `"/pipeline-hello 'do X'"` → `{task}` = `"do X"` |
77
+ | `{outputs.<stageId>}` | Output from a previous stage, including parallel child IDs | `{outputs.analyze}` → output from stage `analyze` |
78
+ | `{lastFeedback}` | Latest feedback from a review gate, inside retry loops | Inserted automatically during gate retries |
79
+ | `{item}` | Whole item from dynamic expansion; JSON for objects, raw value for strings | `{item}` → `{"path":"src/a.ts"}` |
80
+ | `{item.<key>}` | Single field from a dynamic expansion item | `{item.path}` → `src/a.ts` |
81
+
82
+ **Example:**
83
+
84
+ ```yaml
85
+ stages:
86
+ - id: research
87
+ agent: researcher
88
+ task: "Research: {task}"
89
+
90
+ - id: implement
91
+ agent: worker
92
+ task: "Implement based on: {outputs.research}"
93
+ ```
94
+
95
+ **Important:** A stage does **not** automatically see previous stage outputs.
96
+ You must explicitly reference `{outputs.previousStage}` in the task.
97
+ Without that reference, the stage runs in isolation.
98
+
99
+ ---
100
+
101
+ ## 4. Stage types
102
+
103
+ ### 4a. Simple Stage — one agent
104
+
105
+ ```yaml
106
+ - id: analyze
107
+ agent: planner
108
+ task: "Create a plan: {task}"
109
+ # model: "..." # optional: override the model for this stage
110
+ ```
111
+
112
+ ### 4b. Parallel Stage — multiple agents at once
113
+
114
+ ```yaml
115
+ - id: research
116
+ parallel:
117
+ - id: security
118
+ agent: reviewer
119
+ task: "Security analysis: {task}"
120
+ - id: perf
121
+ agent: scout
122
+ task: "Performance analysis: {task}"
123
+ - id: code
124
+ agent: reviewer
125
+ task: "Code review: {task}"
126
+ ```
127
+
128
+ Agents in a `parallel` stage run concurrently.
129
+ The pipeline waits for all agents to finish, then stores the combined result in `outputs.<parallelStageId>`.
130
+ Each child output is also available under its own child ID, for example `{outputs.health}` or `{outputs.security}`.
131
+
132
+ **Example:**
133
+
134
+ ```yaml
135
+ - id: checks
136
+ parallel:
137
+ - id: health
138
+ agent: oracle
139
+ task: "Assess project stability"
140
+ - id: security
141
+ agent: reviewer
142
+ task: "Run a security review"
143
+
144
+ - id: decision
145
+ agent: planner
146
+ task: >
147
+ Health: {outputs.health}
148
+ Security: {outputs.security}
149
+ Decide what to do next.
150
+ ```
151
+
152
+ **Benefits of parallel stages:**
153
+ - Faster execution for I/O-bound work.
154
+ - Multiple perspectives on the same task.
155
+ - Saves time when stages are independent.
156
+
157
+ ### 4c. Review Gate Stage — quality loop
158
+
159
+ ```yaml
160
+ - id: implement
161
+ agent: worker
162
+ task: "Implement: {outputs.analyze}"
163
+ gate:
164
+ type: review-loop # only supported gate type for now
165
+ maxRounds: 3 # max attempts; default: 3
166
+ targetScore: 9 # minimum average score, 0-10
167
+ reviewers:
168
+ - focus: "Does the code cover all required cases?"
169
+ - focus: "Is the code clean and free of duplication?"
170
+ - focus: "Are the tests production-ready?"
171
+ ```
172
+
173
+ **Review gate fields:**
174
+
175
+ | Field | Required | Default | Description |
176
+ |---|---|---|---|
177
+ | `type` | ✅ | — | Must be `"review-loop"` |
178
+ | `maxRounds` | ❌ | `3` | Max worker→review→fix iterations |
179
+ | `targetScore` | ❌ | `8` | Minimum average score (0–10) to pass |
180
+ | `reviewers` | ✅ | — | Array of reviewer configs, each with `focus` string |
181
+ | `judgeModel` | ❌ | Pi's default model | **Advanced.** Override model for reviewers (see section 9b) |
182
+
183
+ **How a review gate works:**
184
+
185
+ ---
186
+
187
+ ### 4d. Expand Stage — dynamic task decomposition
188
+
189
+ An `expand` stage creates N parallel tasks from the output of a previous stage.
190
+ It is ideal when one agent discovers a list of files/topics, and each item should be processed independently.
191
+
192
+ **How it works:**
193
+
194
+ ```
195
+ Source stage (scout): returns a JSON array of items
196
+ → [{"path":"src/a.ts","risk":"high"}, {"path":"src/b.ts","risk":"low"}]
197
+
198
+ Runner parses the output → creates N dynamic stages
199
+
200
+ Stage-1: Worker → "Refactor src/a.ts: high"
201
+ Stage-2: Worker → "Refactor src/b.ts: low"
202
+
203
+ Dynamic stages run in parallel → results are aggregated into outputs
204
+ ```
205
+
206
+ **YAML syntax:**
207
+
208
+ ```yaml
209
+ stages:
210
+ - id: find-files
211
+ agent: scout
212
+ task: >
213
+ Find files to refactor for: {task}.
214
+ Return JSON: [{"path":"...","risk":"..."}, ...]
215
+
216
+ - id: refactor-each
217
+ expand:
218
+ from: find-files # source: output from stage find-files
219
+ maxItems: 5 # optional limit; default: 10
220
+ agent: worker
221
+ task: "Refactor {item.path}: {item.risk}"
222
+ # gate: ... # ❌ not supported in v1
223
+ ```
224
+
225
+ **Template variables for expand:**
226
+
227
+ | Variable | Resolves to |
228
+ |---|---|
229
+ | `{item}` | Whole item; JSON for objects, raw value for strings |
230
+ | `{item.path}` | Value of the `path` field from the item |
231
+ | `{item.name}` | Value of the `name` field from the item |
232
+ | `{item.<key>}` | Any field from an object item |
233
+
234
+ **Source output parsing strategies:**
235
+
236
+ | Strategy | Format | Example |
237
+ |---|---|---|
238
+ | 1. JSON | Array or `{items: [...]}` | `[{"path":"a.ts"}, ...]` |
239
+ | 2. YAML | Sequence | `- path: a.ts` |
240
+ | 3. Markdown | `-`, `*`, or numbered list | `- src/a.ts` |
241
+
242
+ **Use cases:**
243
+
244
+ | Goal | Source stage returns | Dynamic stages |
245
+ |-----|---------------------|-------------------|
246
+ | Refactoring | List of files + risk | Worker refactors each file |
247
+ | Content marketing | List of topics + angles | Worker writes each post |
248
+ | Postmortem | List of events + timestamps | Worker reconstructs each event |
249
+ | Code review | List of modules + focus areas | Reviewer checks each module |
250
+
251
+ **v1 limitations:**
252
+ - Gates on expanded stages are **not** executed. Use a separate review/aggregation stage after expand.
253
+ - All dynamic stages use the same agent from the expand template's `agent` field.
254
+ - The expand stage output is aggregated as one string in `outputs`.
255
+
256
+ ### 4e. Stage Report — compressing output between stages
257
+
258
+ Optionally compress a stage output before passing it to the next stage.
259
+ By default, output is passed through unchanged (`full`).
260
+
261
+ ```yaml
262
+ stages:
263
+ - id: explore
264
+ agent: scout
265
+ task: "Explore the project: {task}"
266
+ report:
267
+ mode: summary # 'full' (default) or 'summary'
268
+ maxLength: 500 # max summary length; default: 500
269
+ instruction: > # optional instruction for the summarizer
270
+ Extract key files and architecture decisions
271
+ ```
272
+
273
+ **When to use `report: summary`:**
274
+ - A scout returned a 50 KB analysis, but the next stage only needs conclusions.
275
+ - You want to reduce token cost in long pipelines.
276
+
277
+ **When not to use it:**
278
+ - The next stage needs full context, for example a code review of the complete codebase.
279
+ - The pipeline has only 1-2 stages; token savings are usually minimal.
280
+
281
+ ### 4f. Pipeline Report — final synthesis
282
+
283
+ After all stages finish, the pipeline automatically starts a synthesis agent that summarizes the whole run.
284
+ You can configure which agent and focus to use:
285
+
286
+ ```yaml
287
+ name: code-review
288
+ # ... description ...
289
+ report:
290
+ agent: planner # synthesis agent; default: "planner"
291
+ focus: "release check" # optional synthesis prompt focus
292
+ ```
293
+
294
+ **Disable synthesis:**
295
+
296
+ ```yaml
297
+ name: hello-world
298
+ report: false # disables the synthesis agent
299
+ ```
300
+
301
+ Synthesis is **best-effort**. If the synthesis agent fails, the pipeline itself is not failed.
302
+ The result will include `synthesisError`.
303
+
304
+ **Where synthesis appears:**
305
+ - In the `run_pipeline` tool output, as a block in `buildPipelineContextMessage`.
306
+ - In `formatPipelineResult`, as a quoted block at the top of the report.
307
+ - In the message injected into the conversation after `/pipeline-*`.
308
+
309
+ ---
310
+
311
+ ## 5. Complete example: code review pipeline
312
+
313
+ ```yaml
314
+ name: code-review
315
+ description: "Full code review pipeline with security and performance checks"
316
+
317
+ stages:
318
+ - id: explore
319
+ agent: scout
320
+ task: >
321
+ Explore the code structure for: {task}.
322
+ List all files that need review.
323
+
324
+ - id: review
325
+ agent: reviewer
326
+ task: >
327
+ Perform a code review based on: {outputs.explore}.
328
+ Check readability, architecture, tests, and error handling.
329
+
330
+ - id: security-check
331
+ agent: oracle
332
+ task: >
333
+ Perform a security review based on: {outputs.explore}.
334
+ Look for injection, auth bypass, unsafe deserialization, and secrets in code.
335
+
336
+ - id: final-report
337
+ agent: planner
338
+ task: >
339
+ Create a final report combining:
340
+ - Code review: {outputs.review}
341
+ - Security: {outputs.security-check}
342
+ Task: {task}
343
+ ```
344
+
345
+ ---
346
+
347
+ ## 6. Complete example: TDD pipeline with gates
348
+
349
+ ```yaml
350
+ name: tdd-cycle
351
+ description: "TDD cycle with gates for tests and code"
352
+
353
+ stages:
354
+ - id: analyze
355
+ agent: planner
356
+ task: >
357
+ Create an implementation plan for: {task}.
358
+ Include acceptance criteria, test cases, and architecture.
359
+
360
+ - id: write-tests
361
+ agent: worker
362
+ task: >
363
+ Write tests based on: {outputs.analyze}.
364
+ Use the existing test framework.
365
+ gate:
366
+ type: review-loop
367
+ maxRounds: 3
368
+ targetScore: 9
369
+ reviewers:
370
+ - focus: "Coverage of all scenarios from the plan"
371
+ - focus: "Are tests production-ready? Include edge cases and error paths."
372
+ - focus: "Are tests readable and maintainable?"
373
+
374
+ - id: implement
375
+ agent: worker
376
+ task: >
377
+ Implement code that passes the tests: {outputs.write-tests}.
378
+ Task: {outputs.analyze}.
379
+ gate:
380
+ type: review-loop
381
+ maxRounds: 3
382
+ targetScore: 8
383
+ reviewers:
384
+ - focus: "Correctness against acceptance criteria"
385
+ - focus: "Code cleanliness, DRY, SOLID"
386
+ - focus: "Error handling and edge cases"
387
+
388
+ - id: verify
389
+ agent: worker
390
+ task: >
391
+ Run all tests and verify whether they pass.
392
+ Report which tests pass/fail and include coverage information.
393
+
394
+ - id: propose-next
395
+ agent: oracle
396
+ task: >
397
+ Based on the work so far: {outputs.verify}
398
+ and the original task: {task}
399
+ propose the next steps.
400
+ ```
401
+
402
+ ---
403
+
404
+ ## 7. Complete example: content-campaign pipeline with expand
405
+
406
+ ```yaml
407
+ name: content-campaign
408
+ description: "Generates a content campaign: research → posts → visuals → quality"
409
+
410
+ report:
411
+ agent: planner
412
+ focus: "content campaign completeness"
413
+
414
+ stages:
415
+ - id: research
416
+ agent: researcher
417
+ task: >
418
+ Research trending topics for: {task}.
419
+ Return JSON: [{"title":"...","angle":"...","keywords":["..."]}, ...]
420
+ Minimum 3 topics.
421
+
422
+ - id: write-posts
423
+ expand:
424
+ from: research
425
+ maxItems: 5
426
+ agent: worker
427
+ task: >
428
+ Write a blog post for: {item.title}
429
+ Angle: {item.angle}
430
+ Keywords: {item.keywords}
431
+ Format: markdown, 800-1500 words.
432
+
433
+ - id: generate-visuals
434
+ expand:
435
+ from: research
436
+ maxItems: 5
437
+ agent: worker
438
+ task: >
439
+ Create visual concept for: {item.title}
440
+ Describe hero image, supporting diagrams, social media card.
441
+
442
+ - id: quality-review
443
+ parallel:
444
+ - agent: reviewer
445
+ task: "Review ALL posts for quality: {outputs.write-posts}"
446
+ - agent: reviewer
447
+ task: "Review ALL visual concepts: {outputs.generate-visuals}"
448
+
449
+ - id: compile-campaign
450
+ agent: planner
451
+ task: >
452
+ Compile the full campaign for: {task}.
453
+ Posts: {outputs.write-posts}
454
+ Visuals: {outputs.generate-visuals}
455
+ Reviews: {outputs.quality-review}
456
+ Output editorial calendar, each post, and promotion plan.
457
+ ```
458
+
459
+ **Step-by-step flow:**
460
+
461
+ ```
462
+ research (researcher) → JSON with 3-5 topics
463
+
464
+ write-posts (expand × N) → each topic = one worker
465
+
466
+ generate-visuals (expand × N) → each topic = one visual concept
467
+ ↓ (both expands run independently)
468
+ quality-review (parallel × 2) → one reviewer for posts, one for visuals
469
+
470
+ compile-campaign (planner) → final report
471
+ ```
472
+
473
+ **Key difference:** The `research` source stage returns data, and `expand`
474
+ creates N stages that process each item independently. The next stage,
475
+ `quality-review`, receives the aggregated output from all expanded stages via
476
+ `{outputs.write-posts}`.
477
+
478
+ ---
479
+
480
+ ## 8. Agent recommendations
481
+
482
+ | Role | Agent | Notes |
483
+ |---|---|---|
484
+ | Code analysis / exploration | `scout` | Cheap, fast, reads files, returns structure |
485
+ | Planning | `planner` | Read-only; good for plans and analysis |
486
+ | Implementation | `worker` | Only agent that edits files. Use one worker at a time |
487
+ | Code review | `reviewer` | Reads code and checks quality; can make small fixes |
488
+ | Second opinion | `oracle` | Read-only; challenges decisions and supports strategic discussion |
489
+ | Research | `researcher` | Searches the web. Requires `pi-web-access` |
490
+ | General delegate | `delegate` | Behaves like the parent session |
491
+
492
+ **Single-worker rule:** only one `worker` should edit files at a time.
493
+ The other agents (`scout`, `planner`, `reviewer`, `oracle`) are read-only.
494
+
495
+ ---
496
+
497
+ ## 9. Good practices
498
+
499
+ ### 9a. Pipeline naming
500
+ - Use short names without spaces: `code-review`, `tdd-cycle`, `release-prep`.
501
+ - The `description` should explain when to use the pipeline.
502
+
503
+ ### 9b. Gate configuration
504
+ - Use `targetScore: 9` for tests because the quality bar is high.
505
+ - Use `targetScore: 8` for code because code can be "good enough" for a first pass.
506
+ - Use `maxRounds: 2-3`; more rounds are usually not worth the time.
507
+ - Use 2-3 reviewers per gate. One reviewer is too little; 4+ is usually overkill.
508
+ - **`judgeModel` — zaawansowane, nie używaj domyślnie.** To pole istnieje dla zaawansowanych użytkowników którzy chcą wymusić inny model dla recenzentów (tzw. cross-model judging). W większości przypadków **nie ustawiaj go** — Pi użyje swojego domyślnego modelu i to jest w porządku. Skup się na `targetScore` i `reviewers`, nie na `judgeModel`.
509
+
510
+ ### 9c. Template variables in tasks
511
+ - Always use `{outputs.previousStage}` when the next agent needs context.
512
+ - Use `{task}` at the start of the first stage and in summary stages.
513
+ - Do not use `{lastFeedback}` manually; review gates insert it automatically.
514
+
515
+ ### 9d. Expand — good practices
516
+ - The source stage should return STRUCTURED data, preferably JSON.
517
+ - Use `maxItems` to avoid accidentally creating hundreds of stages.
518
+ - Nested expand is not supported; use two expand stages one after another.
519
+ - Usually place a review/aggregation stage after expand because expanded stages do not have gates in v1.
520
+ - JSON with an `items` key (`{"items": [...]}`) is the safest format because agents can generate it easily.
521
+
522
+ ### 9e. Models
523
+ - W większości przypadków **nie ustawiaj `model` ani `judgeModel`** — Pi użyje domyślnego modelu, który jest skonfigurowany przez użytkownika.
524
+ - Pole `model` na stage'u istnieje dla zaawansowanych przypadków, gdy konkretny stage wymaga konkretnego modelu.
525
+ - Pole `judgeModel` to jeszcze bardziej zaawansowana opcja — nie przejmuj się nią przy tworzeniu pipeline'ów.
526
+
527
+ ### 9f. Pipeline structure
528
+ - 2-6 stages is a good default.
529
+ - First stage: usually `scout` or `planner` for exploration.
530
+ - Last stage: usually `oracle` or `planner` for synthesis and next steps.
531
+ - Use gates only on critical stages such as tests and implementation.
532
+
533
+ ---
534
+
535
+ ## 10. Testing a new pipeline
536
+
537
+ After creating a file in one of the supported locations:
538
+ - **Project**: `.pi/pipelines/<name>.pipeline.yaml`
539
+ - **Global**: `~/.pi/pipelines/<name>.pipeline.yaml`
540
+
541
+ Check whether Pi sees the pipeline:
542
+
543
+ ```bash
544
+ # 1. Check whether Pi sees the pipeline
545
+ /list-pipelines
546
+ # You should see: /pipeline-<name>
547
+
548
+ # 2. Run a quick smoke test
549
+ /pipeline-<name> "quick test"
550
+
551
+ # 3. If the pipeline has gates, verify that they work
552
+ # Reviewers should end their output with SCORE: N
553
+ ```
554
+
555
+ If the pipeline does not appear:
556
+ - Check whether the file is in `.pi/pipelines/` or `~/.pi/pipelines/`.
557
+ - Check whether the file extension is `.pipeline.yaml`.
558
+ - Check YAML syntax; indentation matters.
559
+ - Restart Pi; commands are registered at startup.
560
+
561
+ ---
562
+
563
+ ## 11. Bundled pipeline examples
564
+
565
+ The extension ships 5 example pipelines, automatically copied to `~/.pi/pipelines/` on first startup:
566
+
567
+ | File | Description | Gates |
568
+ |---|---|---|
569
+ | `hello-world.pipeline.yaml` | Minimal: scout → planner | 0 |
570
+ | `tdd-review.pipeline.yaml` | TDD with test and code gates | 2 |
571
+ | `dev-sprint.pipeline.yaml` | Full development cycle | 2 |
572
+ | `release-check.pipeline.yaml` | Pre-release quality check | 0 |
573
+ | `refactor.pipeline.yaml` | Safe refactoring with a gate | 1 |
574
+
575
+ Use them as starting points for your own pipelines.