@wichayutdew/pi-workflows 0.2.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +66 -38
  2. package/dist/index.js +5903 -4782
  3. package/package.json +1 -1
  4. package/src/command-names.ts +7 -1
  5. package/src/commands.ts +126 -52
  6. package/src/config/catalog.ts +162 -0
  7. package/src/config/ceiling.ts +116 -116
  8. package/src/config/command-conflicts.ts +4 -4
  9. package/src/config/diagnostics.ts +28 -0
  10. package/src/config/load-settings.ts +37 -0
  11. package/src/config/load-types.ts +53 -0
  12. package/src/config/load-workflows.ts +135 -0
  13. package/src/config/load.ts +43 -311
  14. package/src/config/types.ts +137 -135
  15. package/src/config/validate.ts +12 -1261
  16. package/src/config/validation/permissions.ts +291 -0
  17. package/src/config/validation/prompt.ts +19 -0
  18. package/src/config/validation/settings.ts +122 -0
  19. package/src/config/validation/shared.ts +129 -0
  20. package/src/config/validation/shortcut.ts +118 -0
  21. package/src/config/validation/step.ts +228 -0
  22. package/src/config/validation/subagent.ts +288 -0
  23. package/src/config/validation/workflow.ts +156 -0
  24. package/src/config/yaml.ts +29 -0
  25. package/src/digest.ts +38 -6
  26. package/src/engine/checkpoint.ts +13 -9
  27. package/src/engine/create-run.ts +42 -0
  28. package/src/engine/gate-transitions.ts +184 -0
  29. package/src/engine/reconciliation-history.ts +88 -0
  30. package/src/engine/resume.ts +19 -7
  31. package/src/engine/run-advance.ts +122 -0
  32. package/src/engine/run-lifecycle.ts +124 -0
  33. package/src/engine/run-reconciliation.ts +116 -0
  34. package/src/engine/run-validation.ts +128 -0
  35. package/src/engine/state-types.ts +64 -0
  36. package/src/engine/state.ts +10 -193
  37. package/src/engine/transition-helpers.ts +28 -0
  38. package/src/engine/transition-types.ts +8 -0
  39. package/src/engine/transitions.ts +17 -471
  40. package/src/harness/action-context.ts +181 -0
  41. package/src/harness/catalog.ts +45 -0
  42. package/src/harness/context-idle.ts +21 -0
  43. package/src/harness/core-actions.ts +299 -0
  44. package/src/harness/delegation-control-actions.ts +250 -0
  45. package/src/harness/delegation-failure.ts +215 -0
  46. package/src/harness/delegation-plan.ts +219 -0
  47. package/src/harness/delegation-recovery-validation.ts +159 -0
  48. package/src/harness/delegation-response-actions.ts +295 -0
  49. package/src/harness/delegation-retry-policy.ts +118 -0
  50. package/src/harness/dependencies.ts +165 -0
  51. package/src/harness/gate-submission-action.ts +154 -0
  52. package/src/harness/lifecycle-actions.ts +154 -0
  53. package/src/harness/pause-actions.ts +120 -0
  54. package/src/harness/plannotator-result-actions.ts +123 -0
  55. package/src/harness/prompt-gate-actions.ts +270 -0
  56. package/src/harness/resume-action.ts +261 -0
  57. package/src/harness/start-actions.ts +183 -0
  58. package/src/harness/status-actions.ts +191 -0
  59. package/src/harness/step-execution-actions.ts +283 -0
  60. package/src/harness/types.ts +76 -0
  61. package/src/harness.ts +237 -2201
  62. package/src/index.ts +73 -11
  63. package/src/integrations/plannotator-requests.ts +127 -0
  64. package/src/integrations/plannotator-responses.ts +141 -0
  65. package/src/integrations/plannotator-types.ts +44 -0
  66. package/src/integrations/plannotator.ts +16 -235
  67. package/src/integrations/prompt-gate.ts +17 -10
  68. package/src/integrations/subagents/child-policy-envelope.ts +119 -0
  69. package/src/integrations/subagents/child-policy-paths.ts +66 -0
  70. package/src/integrations/subagents/child-policy-sections.ts +174 -0
  71. package/src/integrations/subagents/child-policy-types.ts +32 -0
  72. package/src/integrations/subagents/child-policy-validation.ts +163 -0
  73. package/src/integrations/subagents/child-runtime-completion.ts +56 -0
  74. package/src/integrations/subagents/child-runtime-dependencies.ts +47 -0
  75. package/src/integrations/subagents/child-runtime-files.ts +156 -0
  76. package/src/integrations/subagents/child-runtime-policy.ts +83 -0
  77. package/src/integrations/subagents/child-runtime-types.ts +30 -0
  78. package/src/integrations/subagents/child-runtime.ts +140 -301
  79. package/src/integrations/subagents/client-delegation.ts +181 -0
  80. package/src/integrations/subagents/client-messages.ts +66 -0
  81. package/src/integrations/subagents/client-types.ts +36 -0
  82. package/src/integrations/subagents/client.ts +127 -219
  83. package/src/integrations/subagents/delegated-result.ts +31 -0
  84. package/src/integrations/subagents/diagnostic-format.ts +40 -0
  85. package/src/integrations/subagents/diagnostic-text.ts +114 -0
  86. package/src/integrations/subagents/diagnostic-types.ts +77 -0
  87. package/src/integrations/subagents/diagnostics.ts +24 -799
  88. package/src/integrations/subagents/failure-correlation.ts +235 -0
  89. package/src/integrations/subagents/failure-transcript.ts +192 -0
  90. package/src/integrations/subagents/hidden-bash-failure.ts +98 -0
  91. package/src/integrations/subagents/protocol-events.ts +27 -0
  92. package/src/integrations/subagents/protocol.ts +30 -375
  93. package/src/integrations/subagents/replay-audit.ts +147 -0
  94. package/src/integrations/subagents/replay-safety.ts +82 -0
  95. package/src/integrations/subagents/session-diagnostics.ts +258 -0
  96. package/src/policy/approved-command-extraction.ts +71 -0
  97. package/src/policy/approved-commands.ts +15 -432
  98. package/src/policy/bash-authorization.ts +86 -0
  99. package/src/policy/bash-read-only.ts +161 -0
  100. package/src/policy/bash-types.ts +20 -0
  101. package/src/policy/bash.ts +4 -346
  102. package/src/policy/completion-batch.ts +21 -16
  103. package/src/policy/immutable-input.ts +5 -2
  104. package/src/policy/mcp-authorization.ts +71 -0
  105. package/src/policy/restricted-command.ts +141 -0
  106. package/src/policy/restricted-git.ts +30 -0
  107. package/src/policy/reviewed-artifact.ts +97 -0
  108. package/src/policy/reviewed-command-safety.ts +150 -0
  109. package/src/policy/reviewed-command-shape.ts +49 -0
  110. package/src/policy/reviewed-repository-contract.ts +138 -0
  111. package/src/policy/reviewed-repository-cwd.ts +102 -0
  112. package/src/policy/tool-call-authorization.ts +58 -0
  113. package/src/policy/tool-selection.ts +72 -0
  114. package/src/policy/tool-types.ts +14 -0
  115. package/src/policy/tools.ts +11 -150
  116. package/src/preflight.ts +96 -61
  117. package/src/prompt/main-workflow-notice.ts +41 -0
  118. package/src/prompt/retry-task.ts +83 -0
  119. package/src/prompt/step-contract.ts +101 -0
  120. package/src/prompt/step-sections.ts +75 -0
  121. package/src/prompt/step-task.ts +156 -0
  122. package/src/prompt/template.ts +81 -0
  123. package/src/prompt.ts +10 -245
  124. package/src/runtime/completion-tool.ts +3 -0
  125. package/src/runtime/main-step-completion.ts +78 -0
  126. package/src/runtime/main-step-lifecycle.ts +37 -0
  127. package/src/runtime/main-step-policy.ts +84 -0
  128. package/src/runtime/main-step-runtime-types.ts +64 -0
  129. package/src/runtime/main-step-runtime.ts +129 -200
  130. package/src/runtime/main-step-state.ts +85 -0
  131. package/src/runtime/serial-task-queue.ts +48 -13
  132. package/src/runtime/step-result.ts +48 -27
  133. package/src/workflow-list.ts +15 -6
  134. package/src/workflow-status/format-status.ts +52 -0
  135. package/src/workflow-status/formatting.ts +178 -0
  136. package/src/workflow-status/layout.ts +109 -0
  137. package/src/workflow-status/render-board.ts +101 -0
  138. package/src/workflow-status/render-path.ts +123 -0
  139. package/src/workflow-status/render-summary.ts +144 -0
  140. package/src/workflow-status/types.ts +40 -0
  141. package/src/workflow-status/view.ts +273 -0
  142. 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-context retry after a tool failure; only for wholly replay-safe steps 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
@@ -590,21 +590,47 @@ blocked. Wait for the terminal event; if the delegation channel has already
590
590
  failed, restart Pi before resuming. This prevents an old writer and a resumed
591
591
  writer from overlapping.
592
592
 
593
- When a delegated tool fails, the harness correlates the terminal response with
594
- the retained Pi child session and records the exact failed tool call, tool
595
- error, subagent exit code, terminal error, and validated diagnostic session
596
- path. The fallback accepts only regular, non-symlink session files contained
597
- by the current parent session's child-run root, reads a bounded tail, and
598
- requires the tool error to match the terminal failure. If correlation is not
599
- safe, the terminal error is preserved without claiming an exact command. A
600
- failed process status is treated as resolved when the retained session proves
601
- a successful `structured_output` occurred after every failed tool result and
602
- the correlated result validates. This accepts the same finalized child result;
603
- it never replays mutation-capable work. Without a valid finalized result, a
604
- delegated step may receive the actionable detail in one bounded retry prompt
605
- only when a complete trusted transcript proves every recorded call was
606
- read-only or rejected before execution. An unknown-effect Bash call, a
607
- truncated transcript, or missing correlation pauses instead.
593
+ When a delegated child returns `failed`, `structured_output_failed`,
594
+ `timed_out`, `turn_budget_exhausted`, or `tool_budget_exhausted`, the harness
595
+ audits the retained Pi child session before deciding whether to launch a fresh
596
+ automatic recovery child. The audit accepts only regular, non-symlink session
597
+ files contained by the current parent session's child-run root, requires the
598
+ persisted policy-stripped task and its per-request binding to match the active
599
+ delegation, reads a bounded complete tail, and proves that every recorded call
600
+ was read-only or rejected by that step's actual Bash policy before execution.
601
+ Approved exact Bash commands are evaluated with the same authorization inputs
602
+ used by the child. A zero-tool attempt is also replay-safe when the complete
603
+ bound transcript proves it.
604
+
605
+ When the terminal error identifies a failed tool, the harness also records the
606
+ exact correlated call, tool error, subagent exit code, terminal error, and
607
+ validated diagnostic session path. If exact correlation is unavailable, the
608
+ generic terminal evidence is retained without claiming an unrelated command.
609
+ A failed process status is treated as resolved when the transcript proves a
610
+ successful `structured_output` occurred after every failed tool result and the
611
+ correlated result validates. This accepts the same finalized child result; it
612
+ never replays mutation-capable work.
613
+
614
+ Without a valid finalized result, the next fresh child receives the bounded
615
+ history of distinct terminal evidence in an escaped JSON data boundary and is
616
+ told to inspect current state, change its approach, resolve the cause, and
617
+ finish the original step. The harness launches at most two automatic recovery
618
+ children and stops early when the semantic failure fingerprint repeats.
619
+ Availability of `edit` or `write` is not itself a veto: the complete audit must
620
+ prove that the failed attempt did not actually make or attempt a mutation.
621
+ Mutation-capable or unknown-effect calls, reported file mutation, a truncated or
622
+ malformed transcript, a missing active-request binding, cancellation,
623
+ interruption, detached or stopped execution, and protocol/configuration errors
624
+ remain hard stops. Local channel failures also wait for confirmed child
625
+ termination instead of risking two live children.
626
+
627
+ Temporary delegation-workspace removal is best-effort housekeeping. A cleanup
628
+ error produces a warning but cannot pause an otherwise healthy next step or
629
+ recovery child. Synchronous startup exceptions are contained by the serialized
630
+ failure path. Each recovery uses a new request identity, private result
631
+ capability, and fresh context. The fixed two-attempt bound means a failing step
632
+ can consume at most three times its per-child timeout, turn budget, and tool
633
+ budget.
608
634
 
609
635
  Inside a live child, recovery is not tied to a list of known error strings. The
610
636
  completion contract requires the agent to inspect the exact error and current
@@ -793,8 +819,10 @@ ceilings, deterministic transitions, configuration reconciliation, pause/resume
793
819
  state, gate handling, MCP isolation, Bash policy, extension tool selection,
794
820
  main-agent completion, built-in feedback/approval, subagent request correlation
795
821
  and cancellation, child policy enforcement, and dependency preflight,
796
- including reviewed exact-command propagation and fail-closed legacy
797
- checkpoints. `bun run check` also launches real Pi RPC subprocesses, invokes
822
+ including bounded automatic recovery after replay-safe terminal errors,
823
+ timeouts, budget exhaustion, and nonzero exits; duplicate-failure stopping;
824
+ reviewed exact-command propagation; and fail-closed legacy checkpoints.
825
+ `bun run check` also launches real Pi RPC subprocesses, invokes
798
826
  `/work`, and verifies fresh `scout`, `worker`, and `reviewer` children receive
799
827
  only the explicit compact handoff from the immediately preceding step.
800
828
 
@@ -813,17 +841,17 @@ The `pi-package` keyword makes the package discoverable by the Pi package galler
813
841
  The current schema covers the execution harness requested here. Useful future
814
842
  extensions, without hard-coding them into the orchestrator, are:
815
843
 
816
- | Parameter | Why it belongs in configuration |
817
- | --------------------------------- | ------------------------------------------------------------------------------------------- |
818
- | Retry and backoff | Let a step distinguish a transient child failure from a workflow-level pause. |
819
- | Acceptance criteria | Give each step machine-checkable completion evidence and verification commands. |
820
- | Working directory or worktree | Isolate mutating steps, monorepo packages, and concurrent branches. |
821
- | Parallel groups and join policy | Run independent steps together and declare fail-fast, quorum, or all-success behavior. |
822
- | Generic gates | Add ticket, CI, chat, or custom approval providers behind the same versioned gate contract. |
823
- | Output schema and named artifacts | Pass structured data between steps instead of relying only on a summary. |
824
- | Cost and token ceilings | Bound model spend independently from turn and tool-call budgets. |
825
- | Environment and secret references | Select named credentials without embedding secret values in workflow files. |
826
- | Logging and retention | Configure progress events, redaction, child artifact retention, and checkpoint history. |
844
+ | Parameter | Why it belongs in configuration |
845
+ | --------------------------------- | -------------------------------------------------------------------------------------------------- |
846
+ | Configurable recovery and backoff | Replace the fixed two-attempt recovery cap with a ceiling-aware per-step transient-failure policy. |
847
+ | Acceptance criteria | Give each step machine-checkable completion evidence and verification commands. |
848
+ | Working directory or worktree | Isolate mutating steps, monorepo packages, and concurrent branches. |
849
+ | Parallel groups and join policy | Run independent steps together and declare fail-fast, quorum, or all-success behavior. |
850
+ | Generic gates | Add ticket, CI, chat, or custom approval providers behind the same versioned gate contract. |
851
+ | Output schema and named artifacts | Pass structured data between steps instead of relying only on a summary. |
852
+ | Cost and token ceilings | Bound model spend independently from turn and tool-call budgets. |
853
+ | Environment and secret references | Select named credentials without embedding secret values in workflow files. |
854
+ | Logging and retention | Configure progress events, redaction, child artifact retention, and checkpoint history. |
827
855
 
828
856
  ## Current limits
829
857