@wichayutdew/pi-workflows 0.3.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +55 -39
  2. package/dist/index.js +5771 -4794
  3. package/examples/mr-comments.workflow.yaml +2 -0
  4. package/package.json +1 -1
  5. package/schemas/workflow.schema.json +10 -1
  6. package/src/command-names.ts +7 -1
  7. package/src/commands.ts +126 -52
  8. package/src/config/catalog.ts +162 -0
  9. package/src/config/ceiling.ts +120 -116
  10. package/src/config/command-conflicts.ts +4 -4
  11. package/src/config/diagnostics.ts +28 -0
  12. package/src/config/load-settings.ts +37 -0
  13. package/src/config/load-types.ts +53 -0
  14. package/src/config/load-workflows.ts +135 -0
  15. package/src/config/load.ts +43 -311
  16. package/src/config/types.ts +150 -137
  17. package/src/config/validate.ts +12 -1261
  18. package/src/config/validation/permissions.ts +312 -0
  19. package/src/config/validation/prompt.ts +21 -0
  20. package/src/config/validation/settings.ts +122 -0
  21. package/src/config/validation/shared.ts +129 -0
  22. package/src/config/validation/shortcut.ts +118 -0
  23. package/src/config/validation/step.ts +228 -0
  24. package/src/config/validation/subagent.ts +288 -0
  25. package/src/config/validation/workflow.ts +156 -0
  26. package/src/config/yaml.ts +29 -0
  27. package/src/digest.ts +38 -6
  28. package/src/engine/checkpoint.ts +13 -9
  29. package/src/engine/create-run.ts +43 -0
  30. package/src/engine/gate-transitions.ts +187 -0
  31. package/src/engine/reconciliation-history.ts +88 -0
  32. package/src/engine/resume.ts +19 -7
  33. package/src/engine/run-advance.ts +122 -0
  34. package/src/engine/run-lifecycle.ts +124 -0
  35. package/src/engine/run-reconciliation.ts +116 -0
  36. package/src/engine/run-validation.ts +129 -0
  37. package/src/engine/state-types.ts +66 -0
  38. package/src/engine/state.ts +10 -193
  39. package/src/engine/transition-helpers.ts +28 -0
  40. package/src/engine/transition-types.ts +8 -0
  41. package/src/engine/transitions.ts +17 -471
  42. package/src/harness/action-context.ts +181 -0
  43. package/src/harness/catalog.ts +45 -0
  44. package/src/harness/context-idle.ts +21 -0
  45. package/src/harness/core-actions.ts +299 -0
  46. package/src/harness/delegation-control-actions.ts +250 -0
  47. package/src/harness/delegation-failure.ts +215 -0
  48. package/src/harness/delegation-plan.ts +219 -0
  49. package/src/harness/delegation-recovery-validation.ts +159 -0
  50. package/src/harness/delegation-response-actions.ts +295 -0
  51. package/src/harness/delegation-retry-policy.ts +118 -0
  52. package/src/harness/dependencies.ts +165 -0
  53. package/src/harness/gate-submission-action.ts +154 -0
  54. package/src/harness/lifecycle-actions.ts +154 -0
  55. package/src/harness/pause-actions.ts +120 -0
  56. package/src/harness/plannotator-result-actions.ts +123 -0
  57. package/src/harness/prompt-gate-actions.ts +270 -0
  58. package/src/harness/resume-action.ts +261 -0
  59. package/src/harness/start-actions.ts +183 -0
  60. package/src/harness/status-actions.ts +191 -0
  61. package/src/harness/step-execution-actions.ts +283 -0
  62. package/src/harness/types.ts +76 -0
  63. package/src/harness.ts +236 -2303
  64. package/src/index.ts +73 -11
  65. package/src/integrations/plannotator-requests.ts +127 -0
  66. package/src/integrations/plannotator-responses.ts +141 -0
  67. package/src/integrations/plannotator-types.ts +44 -0
  68. package/src/integrations/plannotator.ts +16 -235
  69. package/src/integrations/prompt-gate.ts +17 -10
  70. package/src/integrations/subagents/child-policy-envelope.ts +119 -0
  71. package/src/integrations/subagents/child-policy-paths.ts +66 -0
  72. package/src/integrations/subagents/child-policy-sections.ts +186 -0
  73. package/src/integrations/subagents/child-policy-types.ts +32 -0
  74. package/src/integrations/subagents/child-policy-validation.ts +163 -0
  75. package/src/integrations/subagents/child-runtime-completion.ts +56 -0
  76. package/src/integrations/subagents/child-runtime-dependencies.ts +47 -0
  77. package/src/integrations/subagents/child-runtime-files.ts +156 -0
  78. package/src/integrations/subagents/child-runtime-policy.ts +83 -0
  79. package/src/integrations/subagents/child-runtime-types.ts +30 -0
  80. package/src/integrations/subagents/child-runtime.ts +140 -301
  81. package/src/integrations/subagents/client-delegation.ts +181 -0
  82. package/src/integrations/subagents/client-messages.ts +66 -0
  83. package/src/integrations/subagents/client-types.ts +36 -0
  84. package/src/integrations/subagents/client.ts +127 -219
  85. package/src/integrations/subagents/delegated-result.ts +31 -0
  86. package/src/integrations/subagents/diagnostic-format.ts +40 -0
  87. package/src/integrations/subagents/diagnostic-text.ts +114 -0
  88. package/src/integrations/subagents/diagnostic-types.ts +77 -0
  89. package/src/integrations/subagents/diagnostics.ts +24 -977
  90. package/src/integrations/subagents/failure-correlation.ts +235 -0
  91. package/src/integrations/subagents/failure-transcript.ts +192 -0
  92. package/src/integrations/subagents/hidden-bash-failure.ts +98 -0
  93. package/src/integrations/subagents/protocol-events.ts +27 -0
  94. package/src/integrations/subagents/protocol.ts +30 -375
  95. package/src/integrations/subagents/replay-audit.ts +147 -0
  96. package/src/integrations/subagents/replay-safety.ts +82 -0
  97. package/src/integrations/subagents/session-diagnostics.ts +258 -0
  98. package/src/policy/approved-command-extraction.ts +71 -0
  99. package/src/policy/approved-commands.ts +15 -432
  100. package/src/policy/bash-authorization.ts +86 -0
  101. package/src/policy/bash-read-only.ts +161 -0
  102. package/src/policy/bash-types.ts +20 -0
  103. package/src/policy/bash.ts +4 -346
  104. package/src/policy/completion-batch.ts +21 -16
  105. package/src/policy/immutable-input.ts +5 -2
  106. package/src/policy/mcp-authorization.ts +71 -0
  107. package/src/policy/restricted-command.ts +141 -0
  108. package/src/policy/restricted-git.ts +30 -0
  109. package/src/policy/reviewed-artifact.ts +97 -0
  110. package/src/policy/reviewed-command-safety.ts +150 -0
  111. package/src/policy/reviewed-command-shape.ts +49 -0
  112. package/src/policy/reviewed-repository-contract.ts +138 -0
  113. package/src/policy/reviewed-repository-cwd.ts +102 -0
  114. package/src/policy/tool-call-authorization.ts +58 -0
  115. package/src/policy/tool-selection.ts +72 -0
  116. package/src/policy/tool-types.ts +14 -0
  117. package/src/policy/tools.ts +11 -150
  118. package/src/preflight.ts +96 -61
  119. package/src/prompt/main-workflow-notice.ts +41 -0
  120. package/src/prompt/retry-task.ts +83 -0
  121. package/src/prompt/step-contract.ts +101 -0
  122. package/src/prompt/step-sections.ts +75 -0
  123. package/src/prompt/step-task.ts +156 -0
  124. package/src/prompt/template.ts +83 -0
  125. package/src/prompt.ts +10 -254
  126. package/src/runtime/completion-tool.ts +3 -0
  127. package/src/runtime/main-step-completion.ts +78 -0
  128. package/src/runtime/main-step-lifecycle.ts +37 -0
  129. package/src/runtime/main-step-policy.ts +84 -0
  130. package/src/runtime/main-step-runtime-types.ts +64 -0
  131. package/src/runtime/main-step-runtime.ts +129 -200
  132. package/src/runtime/main-step-state.ts +85 -0
  133. package/src/runtime/serial-task-queue.ts +48 -13
  134. package/src/runtime/step-result.ts +48 -27
  135. package/src/workflow-list.ts +15 -6
  136. package/src/workflow-status/format-status.ts +52 -0
  137. package/src/workflow-status/formatting.ts +178 -0
  138. package/src/workflow-status/layout.ts +109 -0
  139. package/src/workflow-status/render-board.ts +101 -0
  140. package/src/workflow-status/render-path.ts +123 -0
  141. package/src/workflow-status/render-summary.ts +144 -0
  142. package/src/workflow-status/types.ts +40 -0
  143. package/src/workflow-status/view.ts +273 -0
  144. package/src/workflow-status.ts +20 -820
package/README.md CHANGED
@@ -248,16 +248,16 @@ configured in `~/.pi/agent/workflows/settings.yaml`.
248
248
 
249
249
  Supported fields:
250
250
 
251
- | Field | Default | Description |
252
- | ------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
253
- | `agent` | `pi-workflows.step` | Actual Pi Subagents profile, such as `scout`, `planner`, `worker`, or `reviewer`. |
254
- | `context` | `fresh` | Always isolated; parent and sibling transcripts are never inherited. |
255
- | `model` | Profile/default model | Optional pi-subagents model override for the selected profile. |
256
- | `timeoutMs` | `900000` | Child deadline, from 1 second through 24 hours. |
257
- | `turnBudget` | pi-subagents default | `{ "maxTurns": n, "graceTurns": n }`. |
258
- | `toolBudget` | pi-subagents default | `{ "soft": n, "hard": n, "block": "*" }`; `block` may instead be a tool-name array. |
259
- | `artifacts` | `false` | Ask pi-subagents to retain its normal run artifacts. |
260
- | `retryToolFailures` | `false` | Authorize one fresh reinforcement retry in allow-list or unrestricted Bash mode; runtime still requires a wholly replay-safe attempt without `edit` or `write`. |
251
+ | Field | Default | Description |
252
+ | ------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
253
+ | `agent` | `pi-workflows.step` | Actual Pi Subagents profile, such as `scout`, `planner`, `worker`, or `reviewer`. |
254
+ | `context` | `fresh` | Always isolated; parent and sibling transcripts are never inherited. |
255
+ | `model` | Profile/default model | Optional pi-subagents model override for the selected profile. |
256
+ | `timeoutMs` | `900000` | Child deadline, from 1 second through 24 hours. |
257
+ | `turnBudget` | pi-subagents default | `{ "maxTurns": n, "graceTurns": n }`. |
258
+ | `toolBudget` | pi-subagents default | `{ "soft": n, "hard": n, "block": "*" }`; `block` may instead be a tool-name array. |
259
+ | `artifacts` | `false` | Ask pi-subagents to retain its normal run artifacts. |
260
+ | `retryToolFailures` | `false` | Authorize the bounded automatic recovery sequence in allow-list or unrestricted Bash mode; every failed attempt still needs a complete audit proving that its actual calls were mutation-safe. |
261
261
 
262
262
  Pi Workflows installs an inert listener in every Pi Subagents child and
263
263
  activates policy only after a valid, single-use workflow capability arrives, so
@@ -398,6 +398,8 @@ Supported sources are:
398
398
  | `verification-worker` | `repositories[].worker[].command` |
399
399
  | `verification-reviewer` | `repositories[].reviewer[].command` |
400
400
  | `remote-actions` | `actions[]` where `toolName` is `bash` and `input.command` is present |
401
+ | `remote-push` | Exact approved non-force `git push` command |
402
+ | `remote-drafts` | Parent-synthesized author-private review drafts |
401
403
 
402
404
  The JSON must be the whole reviewed artifact or appear in a fenced `json`
403
405
  block. The harness copies only exact strings into the correlated step policy.
@@ -590,16 +592,17 @@ blocked. Wait for the terminal event; if the delegation channel has already
590
592
  failed, restart Pi before resuming. This prevents an old writer and a resumed
591
593
  writer from overlapping.
592
594
 
593
- When a delegated child returns `failed` or `structured_output_failed` with a
594
- terminal error or nonzero exit code, the harness audits the retained Pi child
595
- session before deciding whether to launch one fresh reinforcement retry. The
596
- audit accepts only regular, non-symlink session files contained by the current
597
- parent session's child-run root, requires the persisted policy-stripped task and
598
- its per-request binding to match the active delegation, reads a bounded complete
599
- tail, and proves that every recorded call was read-only or rejected by that
600
- step's actual Bash policy before execution. Approved exact Bash commands are
601
- evaluated with the same authorization inputs used by the child. A zero-tool
602
- attempt is also replay-safe when the complete bound transcript proves it.
595
+ When a delegated child returns `failed`, `structured_output_failed`,
596
+ `timed_out`, `turn_budget_exhausted`, or `tool_budget_exhausted`, the harness
597
+ audits the retained Pi child session before deciding whether to launch a fresh
598
+ automatic recovery child. The audit accepts only regular, non-symlink session
599
+ files contained by the current parent session's child-run root, requires the
600
+ persisted policy-stripped task and its per-request binding to match the active
601
+ delegation, reads a bounded complete tail, and proves that every recorded call
602
+ was read-only or rejected by that step's actual Bash policy before execution.
603
+ Approved exact Bash commands are evaluated with the same authorization inputs
604
+ used by the child. A zero-tool attempt is also replay-safe when the complete
605
+ bound transcript proves it.
603
606
 
604
607
  When the terminal error identifies a failed tool, the harness also records the
605
608
  exact correlated call, tool error, subagent exit code, terminal error, and
@@ -611,14 +614,26 @@ correlated result validates. This accepts the same finalized child result; it
611
614
  never replays mutation-capable work.
612
615
 
613
616
  Without a valid finalized result, the next fresh child receives the bounded
614
- terminal evidence in an escaped JSON data boundary and is told to inspect
615
- current state, change its approach, resolve the cause, and finish the original
616
- step. A second failure pauses. Mutation-capable or unknown-effect calls, a
617
- truncated or malformed transcript, a missing active-request binding,
618
- cancellation, interruption, timeout, and budget exhaustion do not trigger an
619
- automatic retry. Local channel failures also wait for confirmed child
617
+ history of distinct terminal evidence in an escaped JSON data boundary and is
618
+ told to inspect current state, change its approach, resolve the cause, and
619
+ finish the original step. The harness launches at most two automatic recovery
620
+ children and stops early when the semantic failure fingerprint repeats.
621
+ Availability of `edit` or `write` is not itself a veto: the complete audit must
622
+ prove that the failed attempt did not actually make or attempt a mutation.
623
+ Mutation-capable or unknown-effect calls, reported file mutation, a truncated or
624
+ malformed transcript, a missing active-request binding, cancellation,
625
+ interruption, detached or stopped execution, and protocol/configuration errors
626
+ remain hard stops. Local channel failures also wait for confirmed child
620
627
  termination instead of risking two live children.
621
628
 
629
+ Temporary delegation-workspace removal is best-effort housekeeping. A cleanup
630
+ error produces a warning but cannot pause an otherwise healthy next step or
631
+ recovery child. Synchronous startup exceptions are contained by the serialized
632
+ failure path. Each recovery uses a new request identity, private result
633
+ capability, and fresh context. The fixed two-attempt bound means a failing step
634
+ can consume at most three times its per-child timeout, turn budget, and tool
635
+ budget.
636
+
622
637
  Inside a live child, recovery is not tied to a list of known error strings. The
623
638
  completion contract requires the agent to inspect the exact error and current
624
639
  state, try a permitted semantically equivalent alternative, and continue the
@@ -806,8 +821,9 @@ ceilings, deterministic transitions, configuration reconciliation, pause/resume
806
821
  state, gate handling, MCP isolation, Bash policy, extension tool selection,
807
822
  main-agent completion, built-in feedback/approval, subagent request correlation
808
823
  and cancellation, child policy enforcement, and dependency preflight,
809
- including reinforcement retry after replay-safe terminal errors and nonzero
810
- exits, reviewed exact-command propagation, and fail-closed legacy checkpoints.
824
+ including bounded automatic recovery after replay-safe terminal errors,
825
+ timeouts, budget exhaustion, and nonzero exits; duplicate-failure stopping;
826
+ reviewed exact-command propagation; and fail-closed legacy checkpoints.
811
827
  `bun run check` also launches real Pi RPC subprocesses, invokes
812
828
  `/work`, and verifies fresh `scout`, `worker`, and `reviewer` children receive
813
829
  only the explicit compact handoff from the immediately preceding step.
@@ -827,17 +843,17 @@ The `pi-package` keyword makes the package discoverable by the Pi package galler
827
843
  The current schema covers the execution harness requested here. Useful future
828
844
  extensions, without hard-coding them into the orchestrator, are:
829
845
 
830
- | Parameter | Why it belongs in configuration |
831
- | --------------------------------- | ------------------------------------------------------------------------------------------- |
832
- | Configurable retry and backoff | Extend the single safe reinforcement retry with per-step transient-failure policy. |
833
- | Acceptance criteria | Give each step machine-checkable completion evidence and verification commands. |
834
- | Working directory or worktree | Isolate mutating steps, monorepo packages, and concurrent branches. |
835
- | Parallel groups and join policy | Run independent steps together and declare fail-fast, quorum, or all-success behavior. |
836
- | Generic gates | Add ticket, CI, chat, or custom approval providers behind the same versioned gate contract. |
837
- | Output schema and named artifacts | Pass structured data between steps instead of relying only on a summary. |
838
- | Cost and token ceilings | Bound model spend independently from turn and tool-call budgets. |
839
- | Environment and secret references | Select named credentials without embedding secret values in workflow files. |
840
- | Logging and retention | Configure progress events, redaction, child artifact retention, and checkpoint history. |
846
+ | Parameter | Why it belongs in configuration |
847
+ | --------------------------------- | -------------------------------------------------------------------------------------------------- |
848
+ | Configurable recovery and backoff | Replace the fixed two-attempt recovery cap with a ceiling-aware per-step transient-failure policy. |
849
+ | Acceptance criteria | Give each step machine-checkable completion evidence and verification commands. |
850
+ | Working directory or worktree | Isolate mutating steps, monorepo packages, and concurrent branches. |
851
+ | Parallel groups and join policy | Run independent steps together and declare fail-fast, quorum, or all-success behavior. |
852
+ | Generic gates | Add ticket, CI, chat, or custom approval providers behind the same versioned gate contract. |
853
+ | Output schema and named artifacts | Pass structured data between steps instead of relying only on a summary. |
854
+ | Cost and token ceilings | Bound model spend independently from turn and tool-call budgets. |
855
+ | Environment and secret references | Select named credentials without embedding secret values in workflow files. |
856
+ | Logging and retention | Configure progress events, redaction, child artifact retention, and checkpoint history. |
841
857
 
842
858
  ## Current limits
843
859