@herbertgao/pi-extensions 2026.11.12 → 2026.11.14

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 (176) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +6 -4
  3. package/node_modules/@herbertgao/pi-inline-skill-commands/LICENSE +21 -0
  4. package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +37 -0
  5. package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +53 -0
  6. package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +239 -0
  7. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +10 -0
  8. package/node_modules/@herbertgao/pi-subagents/README.md +37 -7
  9. package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +113 -34
  10. package/node_modules/@herbertgao/pi-subagents/package.json +9 -4
  11. package/node_modules/@herbertgao/pi-subagents/skills/workflow-authoring/SKILL.md +147 -0
  12. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +48 -32
  13. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +16 -8
  14. package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +16 -6
  15. package/node_modules/@herbertgao/pi-subagents/src/index.ts +99 -7
  16. package/node_modules/@herbertgao/pi-subagents/src/mention.ts +5 -7
  17. package/node_modules/@herbertgao/pi-subagents/src/settings.ts +26 -0
  18. package/node_modules/@herbertgao/pi-subagents/src/structured-output.ts +13 -5
  19. package/node_modules/@herbertgao/pi-subagents/src/ui/fleet-list.ts +55 -8
  20. package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-card-redraw.ts +86 -0
  21. package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-card.ts +5 -5
  22. package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-dialog.ts +478 -115
  23. package/node_modules/@herbertgao/pi-subagents/src/ui/workflow-menu.ts +77 -6
  24. package/node_modules/@herbertgao/pi-subagents/src/workflow/agent-detail.ts +148 -0
  25. package/node_modules/@herbertgao/pi-subagents/src/workflow/host.ts +88 -14
  26. package/node_modules/@herbertgao/pi-subagents/src/workflow/journal.ts +8 -0
  27. package/node_modules/@herbertgao/pi-subagents/src/workflow/json-schema.ts +507 -57
  28. package/node_modules/@herbertgao/pi-subagents/src/workflow/progress.ts +41 -11
  29. package/node_modules/@herbertgao/pi-subagents/src/workflow/runtime.ts +106 -34
  30. package/node_modules/@herbertgao/pi-subagents/src/workflow/task.ts +43 -5
  31. package/node_modules/@herbertgao/pi-subagents/src/workflow/tool-description.ts +93 -153
  32. package/node_modules/@herbertgao/pi-subagents/src/workflow/worker-source.ts +283 -71
  33. package/node_modules/@pi-plugins/fast-mode/dist/index.mjs +288 -177
  34. package/node_modules/@pi-plugins/fast-mode/dist/index.mjs.map +1 -1
  35. package/node_modules/@pi-plugins/fast-mode/package.json +7 -7
  36. package/node_modules/pi-lens/CHANGELOG-USER.md +6 -6
  37. package/node_modules/pi-lens/CHANGELOG.md +132 -0
  38. package/node_modules/pi-lens/README.md +2 -0
  39. package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -0
  40. package/node_modules/pi-lens/dist/{chunk-LGH2HHZG.js → chunk-25CAONWT.js} +36 -25
  41. package/node_modules/pi-lens/dist/{chunk-ZQSSO7LO.js → chunk-2DWNYVUN.js} +3 -3
  42. package/node_modules/pi-lens/dist/{chunk-YCR6ZYTE.js → chunk-2RQREVGO.js} +1 -1
  43. package/node_modules/pi-lens/dist/{chunk-VWEBZ2JV.js → chunk-2XALJI2K.js} +40 -40
  44. package/node_modules/pi-lens/dist/{chunk-PQXUZYTQ.js → chunk-2YQ5LI7R.js} +4 -4
  45. package/node_modules/pi-lens/dist/{chunk-VSQT6IHZ.js → chunk-35UJUF27.js} +18 -4
  46. package/node_modules/pi-lens/dist/{chunk-OLWGYBYT.js → chunk-3IWMNN2S.js} +17 -17
  47. package/node_modules/pi-lens/dist/chunk-3UTDLQWO.js +88 -0
  48. package/node_modules/pi-lens/dist/chunk-3Z7Z3B7V.js +27 -0
  49. package/node_modules/pi-lens/dist/{chunk-UNP6Y4JV.js → chunk-4E4OCW3L.js} +16 -16
  50. package/node_modules/pi-lens/dist/{chunk-37IDWT6O.js → chunk-4GLSO2EM.js} +13 -11
  51. package/node_modules/pi-lens/dist/{chunk-QV3JPCMK.js → chunk-5HVDD7IA.js} +1 -1
  52. package/node_modules/pi-lens/dist/{chunk-ZRQMENT4.js → chunk-62PIU4TO.js} +1 -1
  53. package/node_modules/pi-lens/dist/{chunk-3TSMQZG6.js → chunk-6MDWNZ7E.js} +2 -2
  54. package/node_modules/pi-lens/dist/{chunk-WLD6BGON.js → chunk-6MWX2J5H.js} +4 -0
  55. package/node_modules/pi-lens/dist/{chunk-SCU62JLX.js → chunk-6MZLS6CK.js} +7 -7
  56. package/node_modules/pi-lens/dist/{chunk-B42AIWPJ.js → chunk-7BWPQZHE.js} +3 -3
  57. package/node_modules/pi-lens/dist/{chunk-I3NZVAMN.js → chunk-7JMEPY6P.js} +10 -10
  58. package/node_modules/pi-lens/dist/{chunk-7DPXUPRF.js → chunk-7ORBRDFY.js} +2 -2
  59. package/node_modules/pi-lens/dist/{chunk-6E5QLMWI.js → chunk-7WAQ3K26.js} +23 -23
  60. package/node_modules/pi-lens/dist/{chunk-2H5GHZKC.js → chunk-AB26NAHA.js} +7 -7
  61. package/node_modules/pi-lens/dist/{chunk-BBSDJTOV.js → chunk-AFSG6YUB.js} +13 -13
  62. package/node_modules/pi-lens/dist/{chunk-XDNWR7SG.js → chunk-ALTHJUZO.js} +2 -2
  63. package/node_modules/pi-lens/dist/{chunk-UN72ZAJ5.js → chunk-AOEVZXR6.js} +9 -9
  64. package/node_modules/pi-lens/dist/{chunk-HRLF35WL.js → chunk-ARTCVE6I.js} +9 -9
  65. package/node_modules/pi-lens/dist/{chunk-LQQNFCQJ.js → chunk-B2QO7GHY.js} +1 -1
  66. package/node_modules/pi-lens/dist/{chunk-I2FYOZNW.js → chunk-BJGWP4UX.js} +10 -10
  67. package/node_modules/pi-lens/dist/{chunk-G53LBDNU.js → chunk-BKJ6WZKP.js} +6 -6
  68. package/node_modules/pi-lens/dist/{chunk-P5MSLVUW.js → chunk-BQ72NQQM.js} +11 -11
  69. package/node_modules/pi-lens/dist/{chunk-K7O6AHSJ.js → chunk-BWGNVM33.js} +11 -11
  70. package/node_modules/pi-lens/dist/{chunk-ADYQRETD.js → chunk-BYIEU4E4.js} +2 -2
  71. package/node_modules/pi-lens/dist/{chunk-7ZVTFLCC.js → chunk-CDAJQBKJ.js} +11 -11
  72. package/node_modules/pi-lens/dist/{chunk-BKWFDWYM.js → chunk-D3UQWOCB.js} +16 -16
  73. package/node_modules/pi-lens/dist/{chunk-3PAS2ERX.js → chunk-DHFJS2I4.js} +8 -8
  74. package/node_modules/pi-lens/dist/{chunk-KNSOA43J.js → chunk-DKXIUGNA.js} +2 -2
  75. package/node_modules/pi-lens/dist/{chunk-LOEJFTF2.js → chunk-DLGJYQML.js} +2 -2
  76. package/node_modules/pi-lens/dist/{chunk-VGRGW4UL.js → chunk-DNJJVKJZ.js} +31 -31
  77. package/node_modules/pi-lens/dist/{chunk-5HBQL7DH.js → chunk-EBXCYEII.js} +3 -3
  78. package/node_modules/pi-lens/dist/chunk-EH6EHFW2.js +73 -0
  79. package/node_modules/pi-lens/dist/{chunk-W26QZ3OM.js → chunk-EKQDQPX6.js} +10 -10
  80. package/node_modules/pi-lens/dist/{chunk-TWEOJE3D.js → chunk-EXHSWN3P.js} +844 -377
  81. package/node_modules/pi-lens/dist/{chunk-4IZZEN63.js → chunk-F7BFIENK.js} +33 -33
  82. package/node_modules/pi-lens/dist/{chunk-ZI7YHV6I.js → chunk-FD4LJQ6Y.js} +5 -5
  83. package/node_modules/pi-lens/dist/{chunk-RIH3UBK4.js → chunk-GFCPPCNR.js} +11 -11
  84. package/node_modules/pi-lens/dist/{chunk-5JB4WENL.js → chunk-GIK6VUCY.js} +1 -1
  85. package/node_modules/pi-lens/dist/{chunk-PPQHMSPH.js → chunk-GNK2IHVG.js} +15 -15
  86. package/node_modules/pi-lens/dist/{chunk-CXQYK4YT.js → chunk-H6DNTQ4V.js} +2 -2
  87. package/node_modules/pi-lens/dist/{chunk-NGNBJIUO.js → chunk-HERQPNY6.js} +8 -8
  88. package/node_modules/pi-lens/dist/{chunk-INBK3HIT.js → chunk-HFIFEH46.js} +3 -3
  89. package/node_modules/pi-lens/dist/{chunk-J2ZB5MDS.js → chunk-HKRESBMC.js} +20 -20
  90. package/node_modules/pi-lens/dist/{chunk-AZG5UJYY.js → chunk-HMXWZUQW.js} +1 -1
  91. package/node_modules/pi-lens/dist/{chunk-XSC3BCN3.js → chunk-HOWHAKXO.js} +6 -6
  92. package/node_modules/pi-lens/dist/{chunk-7CLWC2UH.js → chunk-HUWW77QY.js} +1 -1
  93. package/node_modules/pi-lens/dist/{chunk-KZ732ZVW.js → chunk-IO6P3NBP.js} +1 -1
  94. package/node_modules/pi-lens/dist/{chunk-7WKVCZI4.js → chunk-J7VNGHLN.js} +2 -2
  95. package/node_modules/pi-lens/dist/{chunk-QE7BJQ6K.js → chunk-JGCBMCCS.js} +8 -8
  96. package/node_modules/pi-lens/dist/{chunk-PFJLYRO3.js → chunk-KIQSNH3F.js} +34 -34
  97. package/node_modules/pi-lens/dist/{chunk-JGUDT5KD.js → chunk-KSQJBGRO.js} +5 -5
  98. package/node_modules/pi-lens/dist/{chunk-RJ3APNIP.js → chunk-KXKM2DFP.js} +4 -4
  99. package/node_modules/pi-lens/dist/chunk-L3Q72QGQ.js +25 -0
  100. package/node_modules/pi-lens/dist/{chunk-6GLMMGCX.js → chunk-LDPY22FS.js} +2 -2
  101. package/node_modules/pi-lens/dist/{chunk-3PO4YYOX.js → chunk-M3QGXGY4.js} +3793 -3814
  102. package/node_modules/pi-lens/dist/{chunk-NNEQOC3U.js → chunk-MET776XM.js} +9 -7
  103. package/node_modules/pi-lens/dist/{chunk-X33QECRJ.js → chunk-MKQFSW2Q.js} +2 -2
  104. package/node_modules/pi-lens/dist/{chunk-7U36VQL6.js → chunk-MKW7ZUTT.js} +3 -3
  105. package/node_modules/pi-lens/dist/{chunk-PQF6YGYB.js → chunk-N2U644ZW.js} +4 -18
  106. package/node_modules/pi-lens/dist/{chunk-DI4AZZNY.js → chunk-NAACKIKT.js} +2 -2
  107. package/node_modules/pi-lens/dist/{chunk-O6LCSHHI.js → chunk-NHHS5T52.js} +1 -1
  108. package/node_modules/pi-lens/dist/{chunk-DCA2MXVQ.js → chunk-NIZKGBOU.js} +51 -27
  109. package/node_modules/pi-lens/dist/{chunk-PKWEBMCA.js → chunk-NNDZ7DOP.js} +194 -111
  110. package/node_modules/pi-lens/dist/{chunk-Q7J3JYJ2.js → chunk-NZ7NSKIW.js} +13 -13
  111. package/node_modules/pi-lens/dist/{chunk-S6MCMD27.js → chunk-OG3UCAHV.js} +3 -3
  112. package/node_modules/pi-lens/dist/{chunk-3QXFUP6T.js → chunk-OHTHVILU.js} +12 -12
  113. package/node_modules/pi-lens/dist/{chunk-NHA5K226.js → chunk-P7EV5ISR.js} +17 -2
  114. package/node_modules/pi-lens/dist/{chunk-L6BDRYUK.js → chunk-PVV27TOX.js} +5 -5
  115. package/node_modules/pi-lens/dist/{chunk-HIRBC72R.js → chunk-Q32RJDYC.js} +4 -4
  116. package/node_modules/pi-lens/dist/{chunk-QE5DJ7MX.js → chunk-Q4UQNTLB.js} +4 -4
  117. package/node_modules/pi-lens/dist/{chunk-SDYLT45T.js → chunk-QQGZY2BR.js} +2 -2
  118. package/node_modules/pi-lens/dist/{chunk-QMWKSYWB.js → chunk-S247BOH2.js} +4 -4
  119. package/node_modules/pi-lens/dist/{chunk-ARTYCUGF.js → chunk-S7KUDW73.js} +121 -18
  120. package/node_modules/pi-lens/dist/{chunk-6CFSDLHE.js → chunk-SJ2SR432.js} +17 -17
  121. package/node_modules/pi-lens/dist/{chunk-CQY2HEH7.js → chunk-SL4G67AP.js} +2 -2
  122. package/node_modules/pi-lens/dist/{chunk-LVLPA32Q.js → chunk-T2D2WWP6.js} +48 -11
  123. package/node_modules/pi-lens/dist/{chunk-HIJ4CHFF.js → chunk-T7KHGEJ5.js} +3 -3
  124. package/node_modules/pi-lens/dist/{chunk-74AMPWNC.js → chunk-TABDCX35.js} +2 -2
  125. package/node_modules/pi-lens/dist/chunk-TFSBHRL2.js +25 -0
  126. package/node_modules/pi-lens/dist/{chunk-KNJH6WJQ.js → chunk-TQKWR5AZ.js} +7 -7
  127. package/node_modules/pi-lens/dist/chunk-TWAQFMLW.js +110 -0
  128. package/node_modules/pi-lens/dist/{chunk-TKOFTLGB.js → chunk-UARVPNAU.js} +33 -33
  129. package/node_modules/pi-lens/dist/chunk-UWBD3JMH.js +56 -0
  130. package/node_modules/pi-lens/dist/{chunk-K4Z7MK6T.js → chunk-VEF3GFOL.js} +15 -15
  131. package/node_modules/pi-lens/dist/{chunk-4DAHGU3V.js → chunk-W2JPGW7Q.js} +27 -25
  132. package/node_modules/pi-lens/dist/{chunk-CZJGAOKL.js → chunk-W2YHHNY3.js} +7 -7
  133. package/node_modules/pi-lens/dist/{chunk-R4L7KZ7R.js → chunk-WA6U2URH.js} +9 -9
  134. package/node_modules/pi-lens/dist/{chunk-OZQQ3AIR.js → chunk-WAK2AXQQ.js} +9 -9
  135. package/node_modules/pi-lens/dist/{chunk-DFKOA74L.js → chunk-WH6O4IFD.js} +10 -10
  136. package/node_modules/pi-lens/dist/{chunk-27JQHK7Y.js → chunk-WJ7GY5WJ.js} +1 -1
  137. package/node_modules/pi-lens/dist/{chunk-KXGTLAUW.js → chunk-WWZLT6AM.js} +2 -2
  138. package/node_modules/pi-lens/dist/{chunk-O2MHF7QM.js → chunk-XRLZ75YY.js} +38 -38
  139. package/node_modules/pi-lens/dist/chunk-XWWFESYZ.js +27 -0
  140. package/node_modules/pi-lens/dist/chunk-XZSXSM4K.js +27 -0
  141. package/node_modules/pi-lens/dist/{chunk-C5PLBTNR.js → chunk-Y2LIOCA7.js} +1 -1
  142. package/node_modules/pi-lens/dist/{chunk-AXAR5ZW2.js → chunk-YIEHUKX2.js} +84 -169
  143. package/node_modules/pi-lens/dist/{chunk-B2OXE4AH.js → chunk-YOMLAKU6.js} +182 -180
  144. package/node_modules/pi-lens/dist/{chunk-MOAVEPC4.js → chunk-YV7XVYSJ.js} +11 -11
  145. package/node_modules/pi-lens/dist/{chunk-ZULZS2I6.js → chunk-ZVQUYCBU.js} +996 -365
  146. package/node_modules/pi-lens/dist/index.js +4911 -2376
  147. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +8 -8
  148. package/node_modules/pi-lens/dist/mcp/cli.js +40 -40
  149. package/node_modules/pi-lens/dist/mcp/server.js +321 -234
  150. package/node_modules/pi-lens/dist/mcp/worker.js +58 -58
  151. package/node_modules/pi-lens/dist/probes/installer.js +21 -21
  152. package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +18 -9
  153. package/node_modules/pi-lens/docs/ci.md +7 -0
  154. package/node_modules/pi-lens/docs/defect-shapes.md +43 -28
  155. package/node_modules/pi-lens/docs/globalconfig.md +1 -0
  156. package/node_modules/pi-lens/docs/invariants/dispatch-runners.md +15 -0
  157. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +3 -3
  158. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +3 -2
  159. package/node_modules/pi-lens/docs/module-report-read-symbol.md +6 -2
  160. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +3 -2
  161. package/node_modules/pi-lens/docs/pi-lens-orchestration.md +2 -1
  162. package/node_modules/pi-lens/docs/pi-lens-subagent.md +2 -1
  163. package/node_modules/pi-lens/docs/servercapabilities.md +1 -1
  164. package/node_modules/pi-lens/docs/settings.md +1 -0
  165. package/node_modules/pi-lens/docs/usage.md +1 -0
  166. package/node_modules/pi-lens/package.json +1 -1
  167. package/package.json +9 -4
  168. package/node_modules/pi-lens/dist/chunk-2H7NFZ4Q.js +0 -25
  169. package/node_modules/pi-lens/dist/chunk-5YJXF2IS.js +0 -56
  170. package/node_modules/pi-lens/dist/chunk-GCSDF5IE.js +0 -27
  171. package/node_modules/pi-lens/dist/chunk-H5API74E.js +0 -67
  172. package/node_modules/pi-lens/dist/chunk-HBX55MWO.js +0 -27
  173. package/node_modules/pi-lens/dist/chunk-JOIKBUQN.js +0 -88
  174. package/node_modules/pi-lens/dist/chunk-M2YMBT5G.js +0 -73
  175. package/node_modules/pi-lens/dist/chunk-MJRGPEQ5.js +0 -25
  176. package/node_modules/pi-lens/dist/chunk-TFKN5EIR.js +0 -27
@@ -68,11 +68,17 @@ A **card in the transcript**, updating as the run goes:
68
68
  ⎿ auditing 6 route files
69
69
  ```
70
70
 
71
- A **`workflow` row in FleetView**, above the agents, carrying its agent counts where a description would go. `⏎` on it opens the inspector rather than a conversation overlay.
71
+ The card redraws when the run reports progress, at most once a second, and once more when it ends. That holds in pi's default fullscreen mode. In regular mode (`tuiMode: "regular"`), redrawing a card that has scrolled off screen clears the terminal's scrollback. So while the run goes, the card shows `⎿ Running in background (ID: …) · /agents → Workflows`, and the tree appears when the run ends. Switching modes mid-run redraws the card for the new mode.
72
+
73
+ The mode is read from the TUI FleetView is drawn into, and falls back to pi's `tuiMode` setting until then. With `--tui-mode regular` on the command line and FleetView turned off, that setting says fullscreen, so the card redraws live anyway.
74
+
75
+ A running row's token and tool-call counts move as the child works: tool calls when each one completes, tokens when pi finalizes an assistant message, so a long response holds the count until it ends. A resumed row counts only its continuation; a retried row keeps the earlier attempt's spend.
76
+
77
+ A **row in FleetView**, above the agents: a `workflow` label, the run's name, and a progress bar of finished agents with their count and the active phases where a description would go (`workflow audit-src ▰▰▰▰▰▱▱▱… 3/7 agents · Reviewing (2/3) 1m12s`). A phase's title reads as an activity there — `phase("Review")` shows as `Reviewing`. `⏎` on it opens the inspector rather than a conversation overlay.
72
78
 
73
79
  Each row names the model the child _actually_ ran on — read back from its session once pi has resolved its defaults, not the string the script asked for — so a fuzzy `model: "haiku"` reads as the model it resolved to, and an `agent()` that named no model still says what it inherited.
74
80
 
75
- The **inspector**, at `/agents → Workflows` — two panes, two levels: phases on the left, that phase's agents on the right, and `⏎` to descend into one agent's prompt, activity and outcome. The detail pane has room for the canonical `provider/model-id` and the thinking level, including a level pi clamped (`thinking: low (asked max)`). The full key table is in [the README](../README.md#commands); the four that change the run rather than the view are:
81
+ The **inspector**, at `/agents → Workflows` — two panes, two levels: phases on the left, that phase's agents on the right, and `⏎` to descend into one agent's prompt, activity and outcome. Activity lists the agent's tool calls (`⏺ Bash(npm test)`) as it makes them. A second `⏎` expands all three sections into the full prompt, the transcript with each call's result, and the full outcome. `↑↓` move between agents; `→` expands the detail and moves focus into it so `↑↓` scroll it (`PgUp`/`PgDn` or `shift+↑`/`shift+↓` page it), and `←` hands focus back and folds it to the compact view. The detail pane has room for the canonical `provider/model-id` and the thinking level, including a level pi clamped (`thinking: low (asked max)`). The full key table is in [the README](../README.md#commands); the four that change the run rather than the view are:
76
82
 
77
83
  | Key | |
78
84
  | --- | ----------------------------------------------------------------------------------- |
@@ -101,7 +107,7 @@ Re-running normally re-pays for every agent. `resumeFromRunId` avoids that:
101
107
 
102
108
  > Its unchanged leading `agent()` calls return their recorded results instantly; the first changed or failed call, and everything after it, runs live.
103
109
 
104
- Every run journals each settled `agent()` call beside its script as `<run id>.workflow.jsonl`, and the resume replays the **unchanged prefix** of that journal. It is a prefix and not a lookup table on purpose: a later call that still matches came from a run whose earlier stages no longer exist, so its recorded answer was produced downstream of work that has changed.
110
+ Every run journals each settled `agent()` call as `<run id>.workflow.jsonl` in the session's tasks directory — beside an inline script, not beside a saved one ([Where files live](#where-files-live)) — and the resume replays the **unchanged prefix** of that journal. It is a prefix and not a lookup table on purpose: a later call that still matches came from a run whose earlier stages no longer exist, so its recorded answer was produced downstream of work that has changed.
105
111
 
106
112
  Four things it will not do:
107
113
 
@@ -228,6 +234,8 @@ The finished script ships as [`examples/workflows/fan-out-audit.js`](../examples
228
234
 
229
235
  Occasionally you will want to write or heavily edit one. The rules are short.
230
236
 
237
+ The model works from the same reference: the bundled `workflow-authoring` skill ([`skills/workflow-authoring/SKILL.md`](../skills/workflow-authoring/SKILL.md)), which is part of the `SubagentWorkflow` tool description by default. pi also lists it among the available skills, and `/skill:workflow-authoring` loads it by hand. Setting `workflowToolExposure` to `"skill"` ([settings](../README.md#persistent-settings)) saves about 4k tokens per session: the description keeps only the opt-in rule, the `meta` rules and one starting pattern, and points at the skill file by path. That pointer works without the skill listing (`--no-skills`, or `pi -e` on a single file), but the model needs a `read` tool and has to choose to use it — a model that skips it writes the script without the reference. Setting it to `"deferred"` declares no `SubagentWorkflow` tool at all until pi's `tool_search` loads it, then gives it the inline reference; that needs `tool_search` active (`"defaultTools": ["+tool_search"]`, off in pi by default), and the extension warns at startup when it is not.
238
+
231
239
  **`meta` must be a pure literal** — no variables, function calls, spreads, or template interpolation. It is read _before_ the script runs, which is what lets the phases appear on screen from the first frame instead of materializing one at a time as agents happen to start. `name` and `description` are required; `phases` and `whenToUse` are optional.
232
240
 
233
241
  ```js
@@ -238,9 +246,9 @@ export const meta = {
238
246
  }
239
247
  ```
240
248
 
241
- **The body is an async function body.** Top-level `await` and a bare top-level `return` are both allowed — the runtime wraps it. (This is also why a workflow script is not valid standalone JavaScript, and why your editor may complain about the `return`.)
249
+ **The body is an async function body, in strict mode.** Top-level `await` and a bare top-level `return` are both allowed — the runtime wraps it. (This is also why a workflow script is not valid standalone JavaScript, and why your editor may complain about the `return`.) Assigning to an undeclared variable throws.
242
250
 
243
- **What you `return` crosses a JSON boundary.** It is checked for cycles, non-finite numbers, sparse arrays, symbol keys and exotic prototypes. Return something useful on its own — the caller sees your return value, not the individual agent outputs.
251
+ **What you `return` is copied.** The copy takes own enumerable keys only and never calls `toJSON`, so a `Date`, `Map`, `Set` or class instance arrives as `{}` plus its own fields — call `.toISOString()` or `Object.fromEntries()` yourself. Functions and `undefined` fields are dropped; a function or hole in an array, `NaN` and `Infinity` become `null`. Only a cycle or a `BigInt` fails the run, as does returning a bare function. Return something useful on its own — the caller sees your return value, not the individual agent outputs.
244
252
 
245
253
  ## Reference
246
254
 
@@ -261,26 +269,66 @@ At least one of `script` / `scriptPath` / `name` is required; `scriptPath` wins
261
269
 
262
270
  Spawns one subagent and resolves to its final text — or, with `schema`, to a validated object.
263
271
 
264
- **Returns `null` if the agent failed terminally _or_ if you skipped it from the inspector**, indistinguishably. Filter with `.filter(Boolean)` when a `null` would break a later stage, and be careful with in-script retry loops: retrying on `null` will re-run something you deliberately skipped.
272
+ **Returns `null` if the agent failed terminally _or_ if you skipped it from the inspector.** [`agentError(label)`](#agenterrorlabel) says which, and why. Filter with `.filter(Boolean)` when a `null` would break a later stage, and be careful with in-script retry loops: retrying on `null` will re-run something you deliberately skipped.
265
273
 
266
- | Option | Type | Notes |
267
- | ----------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
268
- | `label` | string | Display name in the progress tree. Also the handle `resume` addresses |
269
- | `phase` | string | Put this agent in a named group, overriding the ambient `phase()`. **Use it inside `pipeline`/`parallel` stages**, where the ambient phase races |
270
- | `agentType` | string | Which agent definition to use. Defaults to `general-purpose`; built-ins are `general-purpose`, `Explore`, `Plan`, plus your custom agents. The built-in `general-purpose` gets no nested `Agent` tool here; a custom agent with `allowed_subagents` keeps its own |
271
- | `model` | string | `provider/modelId`, or fuzzy like `haiku` |
272
- | `effort` | string | `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. Omitted, the agent definition's own `thinking` decides, then the parent's |
273
- | `isolation` | `"worktree"` | Run in a throwaway git worktree. Only when agents write files in parallel and would collide — it costs setup time and disk per agent. Only this option decides, as in Claude Code — an agent file's `isolation:` does not apply to workflow children |
274
- | `gate` | string | A shell command run after the agent finishes; a non-zero exit fails the agent and its output becomes the error |
275
- | `resume` | string | Continue the child that ran under that label instead of starting fresh |
276
- | `schema` | object | A JSON Schema with an object root. Resolves to the validated object instead of text |
274
+ | Option | Type | Notes |
275
+ | ----------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
276
+ | `label` | string | Display name in the progress tree. Also the handle `resume` addresses |
277
+ | `phase` | string | Put this agent in a named group, overriding the ambient `phase()`. **Use it inside `pipeline`/`parallel` stages**, where the ambient phase races |
278
+ | `agentType` | string | Which agent definition to use. Defaults to `general-purpose`; built-ins are `general-purpose`, `Explore`, `Plan`, plus your custom agents. The built-in `general-purpose` gets no nested `Agent` tool here; a custom agent with `allowed_subagents` keeps its own |
279
+ | `model` | string | `provider/modelId`, or fuzzy like `haiku` |
280
+ | `effort` | string | `minimal`, `low`, `medium`, `high`, `xhigh`, `max`, in any case; `med` means `medium`. Omitted or `""`, the agent definition's own `thinking` decides, then the parent's. Anything else throws at the call |
281
+ | `isolation` | `"worktree"` | Run in a throwaway git worktree. Only when agents write files in parallel and would collide — it costs setup time and disk per agent. Only this option decides, as in Claude Code — an agent file's `isolation:` does not apply to workflow children |
282
+ | `gate` | string | A shell command run after the agent finishes; a non-zero exit fails the agent and its output becomes the error |
283
+ | `resume` | string | Continue the child that ran under that label instead of starting fresh |
284
+ | `schema` | object | A draft-07 JSON Schema with an object root. Resolves to the validated object instead of text. A schema that is invalid (including an unknown keyword or an unresolvable `$ref`) or that no value could satisfy fails the run at the call, before the agent starts — see troubleshooting |
285
+ | `disallowedTools` | string[] | Tools denied to this agent, on top of its definition's own deny list — e.g. `['Bash', 'Write']`, in Claude Code's or pi's spelling. A non-array, or an empty or whitespace-padded entry, throws rather than running the agent un-narrowed; `[]` means none |
277
286
 
278
- Any other key is rejected **by name** at the call. Note that this checks option _keys_, not option _values_ — an `agentType` that names no known agent falls back to `general-purpose` silently.
287
+ Any other key is rejected **by name** at the call. Note that this checks option _keys_, not option _values_ — an `agentType` that names no known agent falls back to the [`fallbackSubagent`](../README.md#persistent-settings) agent (`general-purpose` by default) silently, or, under `fallbackSubagent: none`, fails and `agent()` returns `null`.
279
288
 
280
- Combination rules: `resume` cannot be combined with `agentType`, `model`, `effort`, `isolation`, `gate` or `schema` — a resumed child keeps the agent type, model and tree it was started with, and its session predates the `StructuredOutput` tool.
289
+ Combination rules: `resume` cannot be combined with `agentType`, `model`, `effort`, `isolation`, `disallowedTools`, `gate` or `schema` — a resumed child keeps the agent type, model, tools and tree it was started with, and its session predates the `StructuredOutput` tool.
281
290
 
282
291
  A child stays resumable for the whole run. The manager evicts a finished child's record about ten minutes after it settles, and a review or a merge queue easily takes longer; `resume` then reopens the child's saved session under the same id, still owned by the run. That reopen runs under the agent type's current definition, so the model and tree the script chose for the first run are not carried over. It fails, resolving to `null` with the reason on that agent's row in the card and the inspector, when the child's session was never saved (`rememberAgents` off, or `persist_session: false`), its file is gone, or it ran with `isolation: "worktree"` and left changes: that worktree was removed when the child finished, with its changes on a branch, and continuing the work anywhere else would split it. A child whose worktree held no changes reopens in the run's directory, as in Claude Code.
283
292
 
293
+ ### `agentError(label)`
294
+
295
+ Returns why the most recent `agent()` call with that label failed, or `undefined` if it succeeded or none has settled yet. `agent()` itself still returns `null`, so existing scripts are unaffected.
296
+
297
+ ```js
298
+ const result = await agent(`Review ${file}.`, { label: `review:${file}` })
299
+ if (result === null) {
300
+ const reason =
301
+ typeof agentError === "function" ? agentError(`review:${file}`) : undefined
302
+ return { file, failed: reason ?? "review failed" }
303
+ }
304
+ ```
305
+
306
+ - **What it holds:** the provider error, a thrown host error, the schema or gate failure, `"Skipped by user."` for a skip before the agent started, or the stop reason (`"Stopped."` by default) for a running agent that was stopped, capped at 500 characters. The same text is saved as the journal entry's `error`. A replay never restores it.
307
+ - **Labels:** the key is the label, as for `resume`; an unlabeled call uses its display label. Concurrent calls sharing a label overwrite each other, last to settle wins, so give each call its own. Nested `workflow()` children share the run's labels.
308
+ - **Untrusted text:** it can contain whatever the provider or the gate printed. Treat it as data, and escape it where you render it.
309
+ - **Portability:** Claude Code has no such global. The `typeof` check keeps one script running on both.
310
+
311
+ Read it right after the `null`, to put the reason next to the item it belongs to. It holds one reason per label, not a run-wide record, so a script that wants every reason in its result collects them as calls fail. A wrapper does it once for every call:
312
+
313
+ ```js
314
+ const errors = []
315
+ const run = async (prompt, opts) => {
316
+ const result = await agent(prompt, opts)
317
+ if (result === null)
318
+ errors.push({ label: opts.label, reason: agentError(opts.label) })
319
+ return result
320
+ }
321
+
322
+ const reviews = await pipeline(files, (file) =>
323
+ run(`Review ${file}.`, { label: `review:${file}` }),
324
+ )
325
+ return { reviews: reviews.filter(Boolean), errors }
326
+ ```
327
+
328
+ Give every call an explicit, unique label: an unlabeled call is keyed by its derived display label, and calls sharing a label overwrite each other. A `pipeline` stage or `parallel` thunk that throws is not an `agent()` failure, so `agentError` never sees it; it drops to `null` with a `pipeline[i] failed: …` line. To keep that reason too, catch inside the stage and push it to `errors` yourself.
329
+
330
+ Every failure also reaches the parent model without any script code: the completion notification lists each one in `<failures>` (`[label] failed: reason`, `pipeline[i] failed: …`, `parallel[i] failed: …`), as Claude Code's does. Skips are not listed.
331
+
284
332
  ### `pipeline()` and `parallel()`
285
333
 
286
334
  ```js
@@ -288,26 +336,32 @@ await pipeline(items, ...stages) // no barrier between stages
288
336
  await parallel(thunks) // barrier: waits for all of them
289
337
  ```
290
338
 
291
- **`pipeline` has no barrier.** Item A can be in stage 3 while item B is still in stage 1, so the total time is the slowest single _chain_ rather than the sum of the slowest per stage. Each stage receives `(previousResult, originalItem, index)` — the original item and its index stay available in later stages, so you do not have to thread them through the return value. A stage that throws drops that one item to `null` and skips its remaining stages.
339
+ **`pipeline` has no barrier.** Item A can be in stage 3 while item B is still in stage 1, so the total time is the slowest single _chain_ rather than the sum of the slowest per stage. Each stage receives `(previousResult, originalItem, index)` — the original item and its index stay available in later stages, so you do not have to thread them through the return value. A stage that throws drops that one item to `null` and skips its remaining stages. A stage that _returns_ `null` ends that item's chain too, and so does a `null` item — the next stage never sees it, so a "verify" stage does not spend an agent on nothing. An item that is a promise is awaited before the first stage, which gets the resolved value; `originalItem` stays the promise itself, so `await` it in a later stage that reads it.
292
340
 
293
341
  **`parallel` is a barrier.** It waits for everything before anything moves on, so if five agents run and the slowest takes three times the fastest, four sit finished doing nothing. A thunk that throws becomes `null` without taking its siblings down.
294
342
 
343
+ A thunk or stage that throws leaves a log line — `parallel[1] failed: <message>` or `pipeline[0] failed: <message>` — so a dropped item shows in the progress view rather than vanishing. A stage that returns `null`, or a `null` item, ends its chain without one.
344
+
345
+ In both, a fatal run error is the exception: a cap breach, an unusable `schema`, or a `resume` label no agent has completed under, propagates out of the call and fails the run rather than turning into a `null`.
346
+
295
347
  Prefer `pipeline` unless a stage genuinely needs every prior result _together_ — deduplicating across the whole set, deciding whether to continue at all, or a prompt that compares one result against all the others. Needing to flatten, map or filter is not such a case; do that inside a pipeline stage.
296
348
 
297
349
  ### `workflow(nameOrRef, args?)`
298
350
 
299
- Runs a saved workflow inline and returns its value. Pass a name, or `{ scriptPath }`. `args` becomes the child's `args` global.
351
+ Runs a saved workflow inline and returns a copy of its value, made the same way as a script's own [return value](#writing-the-script-yourself). Pass a name, or `{ scriptPath }`. A copy of `args` becomes the child's `args` global.
300
352
 
301
353
  The child runs in the _same_ worker and vm context under its own globals, so it shares this run's concurrency cap, agent counter, abort signal, journal and budget by construction — its agents are simply this run's agents, controllable from the same inspector. What it does not share is phase state: the child's phases render as their own `▸ <name>` group.
302
354
 
303
355
  **One level only** — `workflow()` inside a child throws saying so. An unknown name, an unreadable path, a child carrying no `meta`, or a child that will not parse all throw into the calling script, so `try`/`catch` if you want to handle them. Capped at 256 nested calls per run.
304
356
 
305
- ### `phase()`, `log()`, `args`, `budget`
357
+ ### `phase()`, `log()`, `console`, `args`, `setTimeout()`, `budget`
306
358
 
307
359
  - **`phase(title)`** — start a new progress group; subsequent `agent()` calls are grouped under it. Inside `pipeline`/`parallel` stages use the `phase` _option_ instead, since the ambient phase races.
308
360
  - **`log(message)`** — a progress line under the tree, for you to read.
309
- - **`args`** — whatever was passed as the tool's `args`, verbatim; `undefined` if none.
310
- - **`budget`** — `{ total, spent(), remaining() }`. **`total` is always `null` here**: it comes from a token-target directive pi does not have. That is deliberate rather than broken — Claude Code scripts guard on it (`while (budget.total && budget.remaining() > 50_000)`), and those guards correctly do not fire instead of throwing on a missing global. `remaining()` is `Infinity` with no target. `spent()` is real, and counts output tokens this run's agents have used.
361
+ - **`console.log/info/warn/error/debug(...values)`** — the same progress line as `log()`, the values joined with spaces, so pasted helper code that logs does not throw.
362
+ - **`args`** — whatever was passed as the tool's `args`, verbatim; `undefined` if none. A nested `workflow(name, args)` child gets a copy, so it cannot mutate the parent's object.
363
+ - **`setTimeout(fn, ms)` / `clearTimeout(id)`** — for a pause between polls. A callback that throws is ignored rather than failing the run.
364
+ - **`budget`** — `{ total, spent(), remaining() }`. **`total` is always `null` here**: it comes from a token-target directive pi does not have. That is deliberate rather than broken — Claude Code scripts guard on it (`while (budget.total && budget.remaining() > 50_000)`), and those guards correctly do not fire instead of throwing on a missing global. `remaining()` is `Infinity` with no target. `spent()` is real, and counts output tokens this run's agents have used, including attempts stopped by a retry.
311
365
 
312
366
  ### Where files live
313
367
 
@@ -335,7 +389,7 @@ Package directories are searched **last**, so a script of yours always wins the
335
389
  | Agents per run, total | 1000 |
336
390
  | Items per `parallel`/`pipeline` **call** | 4096 |
337
391
  | Nested `workflow()` calls per run | 256 |
338
- | Script length | 512 KiB |
392
+ | Script length | 524,288 characters |
339
393
 
340
394
  These are three different things and are easy to conflate: 1000 is a budget for the whole run, the concurrency figure is how many run _simultaneously_, and 4096 is per call rather than per run. Excess items queue rather than melting the machine.
341
395
 
@@ -351,7 +405,7 @@ A run's concurrency limit is its own, independent of the session's `maxConcurren
351
405
 
352
406
  ## Recipes
353
407
 
354
- The orchestration patterns themselves — adversarial verification, judge panels, loop-until-dry — live in exactly one place: the tool description the model reads on every turn. It already knows them. So these are not instructions for writing scripts by hand; they are **what to ask for**, and what the resulting script looks like so you can recognize it in the file.
408
+ The orchestration patterns themselves — adversarial verification, judge panels, loop-until-dry — live in exactly one place: the bundled `workflow-authoring` skill, which by default is part of the tool description the model reads on every turn. It already knows them. So these are not instructions for writing scripts by hand; they are **what to ask for**, and what the resulting script looks like so you can recognize it in the file.
355
409
 
356
410
  ### Fan out over a list you don't have yet
357
411
 
@@ -403,20 +457,41 @@ See [`compose.js`](../examples/workflows/compose.js).
403
457
 
404
458
  ## Troubleshooting
405
459
 
406
- **The run failed with `… is unavailable in workflow scripts (breaks resume)`.**
407
- The script called `Date.now()`, `new Date()` or `Math.random()`. A script that varies run to run cannot be replayed from its journal, so these throw. Use the loop index for ids, pass timestamps in through `args`, or stamp them after the workflow returns. This most often bites pasted-in helper code, and it throws at the line that calls it — _after_ you have already paid for the preceding agents.
460
+ **The run failed with `… unavailable in workflow scripts (breaks resume)`.**
461
+ The script called `Date.now()`, `new Date()`, `Date()` or `Math.random()` — through `globalThis` too. A script that varies run to run cannot be replayed from its journal, so these throw. Use the loop index for ids, pass timestamps in through `args`, or stamp them after the workflow returns. This most often bites pasted-in helper code, and it throws at the line that calls it — _after_ you have already paid for the preceding agents.
408
462
 
409
463
  **`The meta object must be a PURE LITERAL — no variables, function calls, spreads, or template interpolation.`**
410
464
  `meta` is evaluated before the script runs, in an empty context, so it cannot reference anything. Move the dynamic part into the body.
411
465
 
412
466
  **`agent() opts.<key> is not a recognised option.`**
413
- A typo, or an option from a different tool. The supported set is `label`, `phase`, `model`, `agentType`, `isolation`, `gate`, `resume`, `effort`, `schema`.
467
+ A typo, or an option from a different tool. The supported set is `label`, `phase`, `model`, `agentType`, `isolation`, `gate`, `resume`, `effort`, `schema`, `disallowedTools`.
414
468
 
415
469
  **An agent ran as the wrong type and nothing said so.**
416
- An `agentType` that names no known agent falls back to `general-purpose` **silently** — unlike the `Agent` tool, which tells you. Option _keys_ are validated; option _values_ are not. Check the spelling against `/agents`; matching is case-insensitive, and a disabled agent does not count.
470
+ An `agentType` that names no known agent falls back to the [`fallbackSubagent`](../README.md#persistent-settings) agent — `general-purpose` unless you set another — **silently**, unlike the `Agent` tool, which tells you. Set `fallbackSubagent: none` to make it fail instead: the call returns `null`, and the inspector's **Outcome** for that agent lists the available types. Option _keys_ are validated; option _values_ are not. Check the spelling against `/agents`; matching is case-insensitive, and a disabled agent does not count.
417
471
 
418
472
  **`agent()` returned `null`.**
419
- The agent failed terminally, or you skipped it with `s` in the inspector. These are indistinguishable to the script. With `schema`, it also covers a child that never produced a payload matching the schema.
473
+ The agent failed terminally, or you skipped it with `s` in the inspector. With `schema`, it also covers a child that never produced a payload matching the schema. [`agentError(label)`](#agenterrorlabel) returns which and why; the reason is also in the journal entry's `error` and in the completion notification's `<failures>`.
474
+
475
+ **The run failed with `agent({schema}) received an invalid JSON Schema`.**
476
+ The schema is not one the validator can use, and the agent was not started. Schemas and payloads are checked by Ajv, and the message is Ajv's:
477
+
478
+ - not valid draft-07 — `data/properties/a/type must be equal to one of the allowed values`
479
+ - a keyword Ajv does not know, usually a typo — `strict mode: unknown keyword: "minLenght"`
480
+ - a `pattern` that is not a valid regular expression, or a `$ref` that resolves to nothing
481
+ - `$async`, or a schema past 100,000 values or 10,000 levels deep — `schema too large`
482
+
483
+ `format` is never checked, in the schema or in the answer: `format: "email"` documents intent, nothing more.
484
+
485
+ **The run failed with `agent({schema}) received an unusable JSON Schema`.**
486
+ The schema contradicts itself, so no answer could ever pass it, and the agent was not started. The message names the check that failed:
487
+
488
+ - a root without `type: "object"` (a string, not `["object"]`): wrap an array or a primitive in an object property
489
+ - a name in `required` that is missing from `properties` while `additionalProperties` is `false`
490
+ - an `enum` with no value of the declared `type`
491
+ - a `const` of the wrong type, or one outside its `enum`
492
+ - crossed bounds: `minimum` above `maximum` (or equal, if either is exclusive), `minLength` above `maxLength`, `minItems` above `maxItems`, `minProperties` above `maxProperties`, or more `required` names than `maxProperties`
493
+
494
+ The checks follow `properties` and `items` and stop at a `$ref`. A contradiction in an optional property or an array item is refused too, because the child could only succeed by leaving that field out. A `required` name missing from `properties` is fine while `additionalProperties` is not `false`, since the child can still send it — but declare it, so the child knows its type.
420
495
 
421
496
  **A `schema` call came back as `null` even though the agent clearly answered.**
422
497
  `schema` is pressure, not a guarantee. The child gets a `StructuredOutput` tool, `constrainedSampling` set to `strict: "prefer"`, and a validation-and-retry round trip — three soft pressures, where Claude Code has one hard one (it can force the tool call; this cannot, because `toolChoice` is not plumbed through pi's `AgentSession`). Keep schemas small and flat, and `.filter(Boolean)` after every schema stage.
@@ -448,18 +523,22 @@ The sandbox is a determinism and accident boundary, not a defence against a deli
448
523
 
449
524
  ## Coming from Claude Code
450
525
 
451
- This is a port of Claude Code's `Workflow` tool down to its state model, so **a script written for Claude Code runs here unchanged.** `test/workflow-claude-code-compat.test.ts` runs the canonical `review-changes` example from that tool's own description, verbatim.
526
+ This runtime attempts compatibility with Claude Code's `Workflow` tool, down to its state model: a script written for Claude Code runs here with the differences listed below. `test/workflow-claude-code-compat.test.ts` runs the canonical `review-changes` example from that tool's own description, verbatim.
452
527
 
453
- Identical: `agent()`, `pipeline()`, `parallel()`, `workflow()`, `phase()`, `log()`, `args`, `budget`; the `meta` block; `schema` returning a validated object; one-level `workflow()` nesting; the determinism throws.
528
+ The same as Claude Code: `pipeline()` (including the stop on `null`) and `parallel()` (including the `failed:` log lines), `phase()`, `log()`, `args`, `setTimeout`; the `meta` block; `schema` returning a validated object, and which schemas and answers it refuses, with the same messages; one-level `workflow()` nesting; strict mode; the determinism throws and their messages; how the return value is copied; `disallowedTools`; the script reference as a `workflow-authoring` skill the tool description points at.
454
529
 
455
530
  Different:
456
531
 
457
532
  - The tool is **`SubagentWorkflow`**, not `Workflow` — pi's tool registry is flat across extensions, and the winner of a name clash also overwrites the loser's description.
458
533
  - **`budget.total` is always `null`**, because pi has no token-target directive. Claude Code's `budget.total`-guarded patterns therefore run unchanged, just without firing.
459
534
  - **`schema` is pressured, not forced** — see the troubleshooting entry above.
535
+ - **`agentType` matches case-insensitively**, and an unknown one falls back to `fallbackSubagent` — see the troubleshooting entry above. Claude Code matches exactly and throws.
536
+ - **An unknown `effort` throws** at the call. Claude Code ignores it and uses the default effort.
537
+ - **An unknown option key throws** at the call, by name. Claude Code ignores it.
538
+ - **`parallel` and `pipeline` propagate a fatal run error** — a cap breach, an unusable `schema`, or a `resume` label no agent has completed under — instead of folding it into a `null`. Claude Code throws the same schema error at `agent()`, but inside `parallel` or `pipeline` it becomes a `null`.
460
539
  - If both extensions are loaded, this one **stands down** rather than offering the model two orchestrators.
461
540
 
462
- Additions on this side: `gate`, `resume`, `effort`, journal-backed `resumeFromRunId`, and the un-awaited-`agent()` check. All are optional, which is what keeps a Claude Code script portable.
541
+ Additions on this side: `gate`, `resume`, `effort: "minimal"`, `agentError(label)`, the journal entry's `error`, and the un-awaited-`agent()` check. All are optional, which is what keeps a Claude Code script portable.
463
542
 
464
543
  ## Examples
465
544
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herbertgao/pi-subagents",
3
- "version": "0.25.0-local.1",
3
+ "version": "0.26.0-local.1",
4
4
  "description": "Claude Code-style autonomous subagents and workflow orchestration for Pi, with HerbertGao-maintained UI extensions.",
5
5
  "keywords": [
6
6
  "agent",
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "files": [
28
28
  "src/**/*.ts",
29
+ "skills/**/*",
29
30
  "examples/**/*",
30
31
  "docs/**/*.md",
31
32
  "README.md",
@@ -45,6 +46,7 @@
45
46
  "test:coverage": "vitest run --coverage"
46
47
  },
47
48
  "dependencies": {
49
+ "ajv": "^8.20.0",
48
50
  "croner": "^10.0.1",
49
51
  "nanoid": "^5.1.16"
50
52
  },
@@ -64,15 +66,18 @@
64
66
  "extensions": [
65
67
  "./src/index.ts"
66
68
  ],
69
+ "skills": [
70
+ "./skills"
71
+ ],
67
72
  "video": "https://raw.githubusercontent.com/HerbertGao/pi-extensions/master/packages/pi-subagents/media/demo.mp4",
68
73
  "image": "https://raw.githubusercontent.com/HerbertGao/pi-extensions/master/packages/pi-subagents/media/screenshot.png"
69
74
  },
70
75
  "x-upstream": {
71
76
  "package": "@tintinweb/pi-subagents",
72
- "version": "0.25.0",
73
- "reviewedVersion": "0.25.0",
77
+ "version": "0.26.0",
78
+ "reviewedVersion": "0.26.0",
74
79
  "repository": "https://github.com/tintinweb/pi-subagents",
75
- "commit": "b8efc069f05efe50b58a4b74140116c1c9a9dcc1",
80
+ "commit": "dbbd769781847f9c0f74ba2a8545ff33c4b26e7c",
76
81
  "trackVersion": true
77
82
  }
78
83
  }
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: workflow-authoring
3
+ description: Reference for writing a SubagentWorkflow script (script API and gotchas, resume, quality patterns, worked examples). Load before authoring a script for a workflow the user already opted into; it does not itself authorize running one. Applies only when the SubagentWorkflow tool is available.
4
+ ---
5
+
6
+ # Workflow authoring reference
7
+
8
+ A workflow structures work across many agents — to be comprehensive (decompose and cover in parallel), to be confident (independent perspectives and adversarial checks before committing), or to take on scale one context can't hold (migrations, audits, broad sweeps). The script is where you encode that structure: what fans out, what verifies, what synthesizes.
9
+
10
+ When you do call it, the right move is often **hybrid**: scout inline first (list the files, find the channels, scope the diff) to discover the work-list, then call SubagentWorkflow to pipeline over it. You don't need to know the shape before the _task_ — only before the _orchestration step_.
11
+
12
+ Common single-phase workflows you can chain across turns:
13
+
14
+ - **Understand** — parallel readers over relevant subsystems → structured map
15
+ - **Design** — judge panel of N independent approaches → scored synthesis
16
+ - **Review** — dimensions → find → adversarially verify (the review-changes example)
17
+ - **Research** — multi-modal sweep → deep-read → synthesize
18
+ - **Migrate** — discover sites → transform each (worktree isolation) → verify
19
+
20
+ For larger work, run several in sequence — read each result before deciding the next phase. You stay in the loop; each workflow is one well-scoped fan-out.
21
+
22
+ Pass the script inline via `script` — do not Write it to a file first. Every invocation automatically persists its script to a file under the session directory and returns the path in the tool result. To iterate on a workflow, edit that file with Write/Edit and re-invoke SubagentWorkflow with `{scriptPath: "<path>"}` instead of resending the full script. A script you will run more than once belongs in `.pi/workflows/<name>.js` (or `.agents/workflows/`, or `<agent dir>/workflows/` for one that follows the user everywhere); call it with `name: "<name>"` instead of re-sending the source.
23
+
24
+ Every script must begin with `export const meta = {...}`:
25
+ export const meta = {
26
+ name: 'find-flaky-tests',
27
+ description: 'Find flaky tests and propose fixes', // one-line, shown in permission dialog
28
+ phases: [ // one entry per phase() call
29
+ { title: 'Scan', detail: 'grep test logs for retries' },
30
+ { title: 'Fix', detail: 'one agent per flaky test' },
31
+ ],
32
+ }
33
+ // script body starts here — use agent()/parallel()/pipeline()/phase()/log()
34
+ phase('Scan')
35
+ const flaky = await agent('grep CI logs for retry markers', {schema: FLAKY_SCHEMA})
36
+ ...
37
+
38
+ The `meta` object must be a PURE LITERAL — no variables, function calls, spreads, or template interpolation. Required fields: `name`, `description`. Optional: `whenToUse`, `phases`. Use the SAME phase titles in meta.phases as in phase() calls — titles are matched exactly; a phase() call with no matching meta entry just gets its own progress group.
39
+
40
+ Script body hooks:
41
+
42
+ - agent(prompt: string, opts?: {label?: string, phase?: string, schema?: object, model?: string, effort?: string, isolation?: 'worktree', agentType?: string, disallowedTools?: string[], gate?: string, resume?: string}): Promise<any> — spawn a subagent. Without schema, returns its final text as a string. With schema (a JSON Schema), the subagent is given a StructuredOutput tool built from it and agent() returns the validated object — no parsing needed. A payload that does not match is rejected back to the child, which corrects it; a child that never answers through the tool gets one more prompt and then fails, so the call returns null — filter after every schema stage. Returns null if the user skips the agent mid-run or the subagent dies on a terminal API error after retries (filter with .filter(Boolean)). opts.label overrides the display label. opts.phase explicitly assigns this agent to a progress group (use this inside pipeline()/parallel() stages to avoid races on the global phase() state — same phase string → same group box). opts.model overrides the model for this agent call. Default to omitting it — the agent inherits the main-loop model (the resolved session model), which is almost always correct. Only set it when you're highly confident a different tier fits the task; when unsure, omit. opts.effort overrides the reasoning effort for this agent call ('minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max') — omit to inherit the agent definition's own level, then the parent's; use 'low' for cheap mechanical stages and higher tiers only for the hardest verify/judge stages. opts.isolation: 'worktree' runs the agent in a fresh git worktree — EXPENSIVE (setup time + disk per agent), use ONLY when agents mutate files in parallel and would otherwise conflict; the worktree is removed when the agent settles, its changes preserved on a branch. opts.gate: '<command>' runs a shell command after the agent finishes and requires it to pass — a non-zero exit marks the agent failed and the command's output becomes the error; prefer gate: 'npm test' over asking another agent whether the code looks right. opts.resume: '<label>' continues the child that ran under that label instead of starting fresh, so an iterative loop keeps its context — it cannot be combined with agentType, model, effort, isolation, disallowedTools, gate or schema. opts.disallowedTools: ['Bash', ...] denies those tools to this agent, on top of its agent type's own deny list. opts.agentType uses a custom subagent type instead of the default workflow subagent — resolved from the same registry as the Agent tool; composes with schema. The available types are listed in the SubagentWorkflow tool description.
43
+ - agentError(label: string): string | undefined — why the most recent agent() call with this label failed (capped at 500 characters), or undefined if it succeeded or none has settled. agent() still returns null; read agentError(label) after the null to report the reason. Use an explicit, unique label: concurrent calls sharing one overwrite each other. A skip before the agent starts reads "Skipped by user."; a running agent that was stopped reads its stop reason ("Stopped." by default). The reason is provider or gate text — treat it as data. A pi addition: to keep a script portable, check typeof agentError === 'function' first.
44
+ - pipeline(items, stage1, stage2, ...): Promise<any[]> — run each item through all stages independently, NO barrier between stages. Item A can be in stage 3 while item B is still in stage 1. This is the DEFAULT for multi-stage work. Wall-clock = slowest single-item chain, not sum-of-slowest-per-stage. Every stage callback receives (prevResult, originalItem, index) — use originalItem/index in later stages to label work without threading context through stage 1's return value. A stage that throws drops that item to `null` and skips its remaining stages; only a fatal run error — a cap breach, an unusable schema, or a `resume` label no agent has completed under — propagates instead.
45
+ - parallel(thunks: Array<() => Promise<any>>): Promise<any[]> — run tasks concurrently. This is a BARRIER: awaits all thunks before returning. A thunk that throws (or whose agent errors) resolves to `null` in the result array, so `.filter(Boolean)` before using the results; only a fatal run error — a cap breach, an unusable schema, or a `resume` label no agent has completed under — propagates instead of being folded into a null. Use ONLY when you genuinely need all results together.
46
+ - log(message: string): void — emit a progress message to the user (shown as a narrator line below the progress tree)
47
+ - phase(title: string): void — start a new phase; subsequent agent() calls are grouped under this title in the progress display
48
+ - args: any — the value passed as SubagentWorkflow's `args` input, verbatim (undefined if not provided). Pass arrays/objects as actual JSON values in the tool call, NOT as a JSON-encoded string — `args: ["a.ts", "b.ts"]`, not `args: "[\"a.ts\", ...]"` (a stringified list reaches the script as one string, so `args.filter`/`args.map` throw). Use this to parameterize named workflows — e.g. pass a research question, target path, or config object directly instead of via a side-channel file.
49
+ - budget: {total: number|null, spent(): number, remaining(): number} — `budget.total` is always null here: it comes from a token-target directive pi does not have, so guards like `while (budget.total && budget.remaining() > 50_000) { ... }` correctly do not fire rather than throwing on a missing global. `budget.spent()` returns output tokens spent by this run's agents. `budget.remaining()` returns `Infinity` with no target.
50
+ - workflow(nameOrRef: string | {scriptPath: string}, args?: any): Promise<any> — run another workflow inline as a sub-step and return whatever it returns. Pass a name to invoke a saved workflow (same registry as {name: "..."}), or {scriptPath} to run a script file you Wrote earlier. The child shares this run's concurrency cap, agent counter, abort signal, and token budget — its agents appear under a "▸ name" group in /agents → Workflows and its tokens count toward budget.spent(). The args param becomes the child's `args` global. Nesting is one level only: workflow() inside a child throws. Throws on unknown name / unreadable scriptPath / child syntax error; catch to handle gracefully.
51
+
52
+ Any agent() option not listed above is rejected by name at the call.
53
+
54
+ Subagents are told their final text IS the return value (not a human-facing message), so they return raw data. For structured output, use the schema option — validation happens at the tool-call layer so the model retries on mismatch.
55
+ Schemas need {type: 'object', properties: {...}} at root and required ⊆ properties; unsatisfiable ones throw at agent().
56
+
57
+ Scripts are plain JavaScript, NOT TypeScript — type annotations (`: string[]`), interfaces, and generics fail to parse. The script body runs in an async context — use await directly. Standard JS built-ins (JSON, Math, Array, etc.) are available — EXCEPT `Date.now()`/`Math.random()`/argless `new Date()`, which throw (they would break resume); pass timestamps in via `args`, stamp results after the workflow returns, and for randomness vary the agent prompt/label by index. `eval` and `Function(...)` throw. No filesystem or Node.js API access.
58
+
59
+ DEFAULT TO pipeline(). Only reach for a barrier (parallel between stages) when you genuinely need ALL prior-stage results together.
60
+
61
+ A barrier is correct ONLY when stage N needs cross-item context from all of stage N-1:
62
+
63
+ - Dedup/merge across the full result set before expensive downstream work
64
+ - Early-exit if the total count is zero ("0 bugs found → skip verification entirely")
65
+ - Stage N's prompt references "the other findings" for comparison
66
+
67
+ A barrier is NOT justified by:
68
+
69
+ - "I need to flatten/map/filter first" — do it inside a pipeline stage: pipeline(items, stageA, r => transform([r]).flat(), stageB)
70
+ - "The stages are conceptually separate" — that's what pipeline() models. Separate stages ≠ synchronized stages.
71
+ - "It's cleaner code" — barrier latency is real. If 5 finders run and the slowest takes 3× the fastest, a barrier wastes 2/3 of the fast finders' idle time.
72
+
73
+ Smell test: if you wrote
74
+ const a = await parallel(...)
75
+ const b = transform(a) // flatten, map, filter — no cross-item dependency
76
+ const c = await parallel(b.map(...))
77
+ that middle transform doesn't need the barrier. Rewrite as a pipeline with the transform inside a stage. When in doubt: pipeline.
78
+
79
+ Concurrent agent() calls are capped at max(1, min(16, available CPUs - 2)) per workflow (6 on an 8-core machine) — excess calls queue and run as slots free up. You can still pass 100 items to parallel()/pipeline() and they all complete; only that many run at any moment. Total agent count across a workflow's lifetime is capped at 1000 — a runaway-loop backstop set far above any real workflow. A single parallel()/pipeline() call accepts at most 4096 items; passing more is an explicit error, not a silent truncation.
80
+
81
+ When a barrier IS correct — dedup across all findings before expensive verification:
82
+ const all = await parallel(DIMENSIONS.map(d => () => agent(d.prompt, {schema: FINDINGS_SCHEMA})))
83
+ const deduped = dedupeByFileAndLine(all.filter(Boolean).flatMap(r => r.findings)) // <-- genuinely needs ALL at once
84
+ const verified = await parallel(deduped.map(f => () => agent(verifyPrompt(f), {schema: VERDICT_SCHEMA})))
85
+
86
+ Loop-until-count pattern — accumulate to a target:
87
+ const bugs = []
88
+ while (bugs.length < 10) {
89
+ const result = await agent("Find bugs in this codebase.", {schema: BUGS_SCHEMA})
90
+ bugs.push(...result.bugs)
91
+ log(`${bugs.length}/10 found`)
92
+ }
93
+
94
+ Gate-and-retry pattern — verify by running, and keep the agent's context across attempts:
95
+ let fixed = await agent('Find and fix the failing test.', {label: 'fix', gate: 'npm test'})
96
+ if (fixed === null) { // a non-zero exit failed the agent
97
+ // Resume keeps everything the child already learned. It cannot carry the
98
+ // gate, so re-verification needs its own gated call, in the same tree.
99
+ fixed = await agent('`npm test` is still failing. Fix the cause.', {label: 'fix', resume: 'fix'})
100
+ const verified = await agent('Run `npm test` and report the result. Change nothing.',
101
+ {label: 'verify', phase: 'Verify', gate: 'npm test', effort: 'low'})
102
+ return { passed: verified !== null, summary: fixed }
103
+ }
104
+ return { passed: true, summary: fixed }
105
+ // An LLM judging whether a fix works is a weaker signal than the test suite.
106
+
107
+ Composing patterns — exhaustive review (find → dedup vs seen → diverse-lens panel → loop-until-dry):
108
+ const seen = new Set(), confirmed = []
109
+ let dry = 0
110
+ while (dry < 2) { // loop-until-dry
111
+ const found = (await parallel(FINDERS.map(f => () => // barrier: collect all finders this round
112
+ agent(f.prompt, {phase: 'Find', schema: BUGS})))).filter(Boolean).flatMap(r => r.bugs)
113
+ const fresh = found.filter(b => !seen.has(key(b))) // dedup vs ALL seen — plain code, not an agent
114
+ if (!fresh.length) { dry++; continue }
115
+ dry = 0; fresh.forEach(b => seen.add(key(b)))
116
+ const judged = await parallel(fresh.map(b => () => // every fresh bug judged concurrently...
117
+ parallel(['correctness','security','repro'].map(lens => () => // ...each by 3 distinct lenses
118
+ agent(`Judge "${b.desc}" via the ${lens} lens — real?`, {phase: 'Verify', schema: VERDICT})))
119
+ .then(vs => ({ b, real: vs.filter(Boolean).filter(v => v.real).length >= 2 }))))
120
+ confirmed.push(...judged.filter(v => v.real).map(v => v.b))
121
+ }
122
+ return confirmed
123
+ // dedup vs `seen`, NOT `confirmed` — else judge-rejected findings reappear every round and it never converges.
124
+
125
+ Quality patterns — common shapes; pick by task and compose freely:
126
+
127
+ - Adversarial verify: spawn N independent skeptics per finding, each prompted to REFUTE. Kill if ≥majority refute. Prevents plausible-but-wrong findings from surviving.
128
+ const votes = await parallel(Array.from({length: 3}, () => () =>
129
+ agent(`Try to refute: ${claim}. Default to refuted=true if uncertain.`, {schema: VERDICT})))
130
+ const survives = votes.filter(Boolean).filter(v => !v.refuted).length >= 2
131
+ - Verify by running, not by asking: when a claim is testable, `gate` it rather than asking another model whether it holds.
132
+ - Perspective-diverse verify: when a finding can fail in more than one way, give each verifier a distinct lens (correctness, security, perf, does-it-reproduce) instead of N identical refuters — diversity catches failure modes redundancy can't.
133
+ - Judge panel: generate N independent attempts from different angles (e.g. MVP-first, risk-first, user-first), score with parallel judges, synthesize from the winner while grafting the best ideas from runners-up. Beats one-attempt-iterated when the solution space is wide.
134
+ - Loop-until-dry: for unknown-size discovery (bugs, issues, edge cases), keep spawning finders until K consecutive rounds return nothing new. Simple counters (while count < N) miss the tail.
135
+ - Multi-modal sweep: parallel agents each searching a different way (by-container, by-content, by-entity, by-time). Each is blind to what the others surface; useful when one search angle won't find everything.
136
+ - Completeness critic: a final agent that asks "what's missing — modality not run, claim unverified, source unread?" What it finds becomes the next round of work.
137
+ - No silent caps: if a workflow bounds coverage (top-N, no-retry, sampling), `log()` what was dropped — silent truncation reads as "covered everything" when it didn't.
138
+
139
+ Scale to what the user asked for. "find any bugs" → a few finders, single-vote verify. "thoroughly audit this" or "be comprehensive" → larger finder pool, 3–5 vote adversarial pass, synthesis stage. When unsure, lean toward thoroughness for research/review/audit requests and toward brevity for quick checks.
140
+
141
+ These patterns aren't exhaustive — compose novel harnesses when the task calls for it (tournament brackets, self-repair loops, staged escalation, whatever fits).
142
+
143
+ Use this tool for multi-step orchestration where control flow should be deterministic (loops, conditionals, fan-out) rather than model-driven.
144
+
145
+ ## Resume
146
+
147
+ The tool result's `Task ID` is the runId. To resume after a pause, kill, or script edit, relaunch with SubagentWorkflow({scriptPath, resumeFromRunId}) — the longest unchanged prefix of agent() calls returns cached results instantly; the first edited/new call and everything after it runs live. Same script + same args → 100% cache hit, unless the run used `agent({ resume })`: such a run is not replayed at all. It is a prefix and not a lookup: a later call that still matches is not reused once an earlier one has changed. A journaled failure ends the prefix, so resuming a run that died at agent 5 retries exactly agent 5. Same session only, and the run must have finished — stop it from /agents → Workflows first. Before diagnosing why a completed workflow returned an empty or unexpected result, Read the run's `<run id>.workflow.jsonl` in the session's tasks directory (beside an inline script; a `name`/`scriptPath` run's journal is there too, not beside the saved file) — it records each agent's actual return value; do not assume cached results are non-empty. Date.now()/Math.random()/new Date() are unavailable in scripts (they would break this) — stamp results after the workflow returns, or pass timestamps via args.
@@ -290,6 +290,11 @@ interface SpawnOptions {
290
290
  * compiled schema. Set only by the workflow host, for `agent({ schema })`.
291
291
  */
292
292
  structuredOutput?: CompiledSchema
293
+ /**
294
+ * Tools denied to this spawn on top of the agent definition's own list. Set
295
+ * only by the workflow host, for `agent({ disallowedTools })`.
296
+ */
297
+ disallowedTools?: string[]
293
298
  /** Isolation mode — "worktree" creates a temp git worktree for the agent. */
294
299
  isolation?: IsolationMode
295
300
  /**
@@ -989,6 +994,7 @@ export class AgentManager {
989
994
  inheritContext: options.inheritContext,
990
995
  thinkingLevel: options.thinkingLevel,
991
996
  structuredOutput: options.structuredOutput,
997
+ disallowedTools: options.disallowedTools,
992
998
  resumeSessionFile: options.resumeSessionFile,
993
999
  nested: options.parentAgentId !== undefined,
994
1000
  workflow: options.workflowId !== undefined,
@@ -1494,39 +1500,49 @@ export class AgentManager {
1494
1500
  // holds for a resume issued on a call that was cancelled first.
1495
1501
  if (signal?.aborted) this.abort(id)
1496
1502
 
1497
- try {
1498
- this.settleOutcome(
1499
- record,
1500
- await resumeAgent(record.session, prompt, {
1501
- type: record.type,
1502
- maxTurns: options?.maxTurns ?? record.invocation?.maxTurns,
1503
- onTurnEnd: options?.onTurnEnd,
1504
- onToolActivity: (activity) => {
1505
- if (activity.type === "end") record.toolUses++
1506
- options?.onToolActivity?.(activity)
1507
- },
1508
- onAssistantUsage: (usage) => {
1509
- addUsage(record.lifetimeUsage, usage)
1510
- addUsage(record.ownUsage, usage)
1511
- this.onUsage?.(record, usage)
1512
- options?.onAssistantUsage?.(usage)
1513
- },
1514
- onCompaction: (info) => {
1515
- record.compactionCount++
1516
- this.onCompact?.(record, info)
1517
- options?.onCompaction?.(info)
1518
- },
1519
- signal: abortController.signal,
1520
- }),
1521
- )
1522
- } catch (err) {
1523
- this.failResume(record, err)
1524
- }
1525
- this.detachParentAbort(record)
1503
+ // `record.promise` is the in-flight run's, as on every other path: left on
1504
+ // the spawn's settled promise, `waitForAll` spins on it without yielding
1505
+ // and `get_subagent_result` with `wait` returns mid-run. Cleanup runs
1506
+ // before it resolves, so no waiter wakes with the turn's children alive.
1507
+ const session = record.session
1508
+ const run = (async () => {
1509
+ try {
1510
+ this.settleOutcome(
1511
+ record,
1512
+ await resumeAgent(session, prompt, {
1513
+ type: record.type,
1514
+ maxTurns: options?.maxTurns ?? record.invocation?.maxTurns,
1515
+ onTurnEnd: options?.onTurnEnd,
1516
+ onToolActivity: (activity) => {
1517
+ if (activity.type === "end") record.toolUses++
1518
+ options?.onToolActivity?.(activity)
1519
+ },
1520
+ onAssistantUsage: (usage) => {
1521
+ addUsage(record.lifetimeUsage, usage)
1522
+ addUsage(record.ownUsage, usage)
1523
+ this.onUsage?.(record, usage)
1524
+ options?.onAssistantUsage?.(usage)
1525
+ },
1526
+ onCompaction: (info) => {
1527
+ record.compactionCount++
1528
+ this.onCompact?.(record, info)
1529
+ options?.onCompaction?.(info)
1530
+ },
1531
+ signal: abortController.signal,
1532
+ }),
1533
+ )
1534
+ } catch (err) {
1535
+ this.failResume(record, err)
1536
+ }
1537
+ this.detachParentAbort(record)
1526
1538
 
1527
- // Same contract as the spawn settle paths: children spawned during the
1528
- // resumed turn must not outlive it — nothing else can see or reach them.
1529
- this.abortOwnedChildren(id)
1539
+ // Same contract as the spawn settle paths: children spawned during the
1540
+ // resumed turn must not outlive it — nothing else can see or reach them.
1541
+ this.abortOwnedChildren(id)
1542
+ return record.result ?? ""
1543
+ })()
1544
+ record.promise = run
1545
+ await run
1530
1546
 
1531
1547
  return record
1532
1548
  }