@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
@@ -7,193 +7,195 @@ export const SUBAGENT_RUNTIME_NAME_PATTERN =
7
7
 
8
8
  export const TERMINAL_TARGETS = ['$done', '$pause'] as const;
9
9
  export type TerminalTarget = (typeof TERMINAL_TARGETS)[number];
10
- export type StepTarget = string | TerminalTarget;
10
+ export type StepTarget = string;
11
11
 
12
12
  export type BashMode = 'deny' | 'read-only' | 'allow-list' | 'unrestricted';
13
13
  export type BashApprovalSource =
14
14
  'verification-worker' | 'verification-reviewer' | 'remote-actions';
15
15
 
16
- export interface BashRule {
17
- executable: string;
18
- argsPrefix: string[];
19
- }
16
+ export type BashRule = {
17
+ readonly executable: string;
18
+ readonly argsPrefix: ReadonlyArray<string>;
19
+ };
20
20
 
21
- export interface BashPermission {
22
- mode: BashMode;
23
- allow: BashRule[];
21
+ export type BashPermission = {
22
+ readonly mode: BashMode;
23
+ readonly allow: ReadonlyArray<BashRule>;
24
24
  /**
25
25
  * Exact commands extracted from the most recent human-approved artifact.
26
26
  * They supplement `allow` only inside the correlated step execution.
27
27
  */
28
- approvedSources?: BashApprovalSource[];
29
- }
28
+ readonly approvedSources?: ReadonlyArray<BashApprovalSource>;
29
+ };
30
30
 
31
- export interface StepPermissions {
31
+ export type StepPermissions = {
32
32
  /** Exact Pi tool names, including direct MCP tools. */
33
- tools: string[];
33
+ readonly tools: ReadonlyArray<string>;
34
34
  /** MCP proxy selectors in `server` or `server/tool` form. */
35
- mcp: string[];
35
+ readonly mcp: ReadonlyArray<string>;
36
36
  /** Source-name/path fragments whose registered tools may be used. */
37
- extensions: string[];
37
+ readonly extensions: ReadonlyArray<string>;
38
38
  /** Skills the step prompt is allowed to use. */
39
- skills: string[];
40
- bash: BashPermission;
41
- }
39
+ readonly skills: ReadonlyArray<string>;
40
+ readonly bash: BashPermission;
41
+ };
42
42
 
43
- export interface StepRequirements {
44
- tools: string[];
45
- extensions: string[];
46
- skills: string[];
47
- }
43
+ export type StepRequirements = {
44
+ readonly tools: ReadonlyArray<string>;
45
+ readonly extensions: ReadonlyArray<string>;
46
+ readonly skills: ReadonlyArray<string>;
47
+ };
48
48
 
49
49
  export type SubagentContext = 'fresh';
50
50
 
51
- export interface SubagentTurnBudget {
52
- maxTurns: number;
53
- graceTurns?: number;
54
- }
51
+ export type SubagentTurnBudget = {
52
+ readonly maxTurns: number;
53
+ readonly graceTurns?: number;
54
+ };
55
55
 
56
- export interface SubagentToolBudget {
57
- hard: number;
58
- soft?: number;
59
- block?: string[] | '*';
60
- }
56
+ export type SubagentToolBudget = {
57
+ readonly hard: number;
58
+ readonly soft?: number;
59
+ readonly block?: ReadonlyArray<string> | '*';
60
+ };
61
61
 
62
- export interface StepSubagent {
62
+ export type StepSubagent = {
63
63
  /** Pi Subagents agent profile launched for this isolated step. */
64
- agent: string;
64
+ readonly agent: string;
65
65
  /** Workflow steps always use a fresh context. */
66
- context: SubagentContext;
67
- model?: string;
68
- timeoutMs: number;
69
- turnBudget?: SubagentTurnBudget;
70
- toolBudget?: SubagentToolBudget;
71
- artifacts: boolean;
66
+ readonly context: SubagentContext;
67
+ readonly model?: string;
68
+ readonly timeoutMs: number;
69
+ readonly turnBudget?: SubagentTurnBudget;
70
+ readonly toolBudget?: SubagentToolBudget;
71
+ readonly artifacts: boolean;
72
72
  /**
73
- * Authorizes one fresh-context continuation after a tool failure when the
74
- * trusted complete transcript proves every recorded call was replay-safe.
73
+ * Authorizes the bounded automatic recovery sequence in Bash modes broader
74
+ * than read-only. Every failed attempt must still have a complete,
75
+ * mutation-safe replay audit.
75
76
  */
76
- retryToolFailures: boolean;
77
- }
77
+ readonly retryToolFailures: boolean;
78
+ };
78
79
 
79
- export type PromptSpec = { inline: string } | { file: string };
80
+ export type PromptSpec =
81
+ { readonly inline: string } | { readonly file: string };
80
82
 
81
- interface GateDefinition {
82
- submitOutcome: string;
83
- approvedOutcome: string;
84
- rejectedOutcome: string;
85
- }
83
+ type GateDefinition = {
84
+ readonly submitOutcome: string;
85
+ readonly approvedOutcome: string;
86
+ readonly rejectedOutcome: string;
87
+ };
86
88
 
87
- export interface PromptGate extends GateDefinition {
88
- provider: 'prompt';
89
- }
89
+ export type PromptGate = GateDefinition & {
90
+ readonly provider: 'prompt';
91
+ };
90
92
 
91
- export interface PlannotatorGate extends GateDefinition {
92
- provider: 'plannotator';
93
- timeoutMs: number;
94
- }
93
+ export type PlannotatorGate = GateDefinition & {
94
+ readonly provider: 'plannotator';
95
+ readonly timeoutMs: number;
96
+ };
95
97
 
96
98
  export type WorkflowGate = PromptGate | PlannotatorGate;
97
99
 
98
- export interface WorkflowStep {
99
- title: string;
100
- prompt: PromptSpec;
100
+ export type WorkflowStep = {
101
+ readonly title: string;
102
+ readonly prompt: PromptSpec;
101
103
  /** Omit to execute this step in the main Pi agent. */
102
- subagent?: StepSubagent;
103
- permissions: StepPermissions;
104
- requires: StepRequirements;
105
- transitions: Record<string, StepTarget>;
106
- gate?: WorkflowGate;
107
- }
108
-
109
- export interface WorkflowDefinition {
110
- version: typeof WORKFLOW_SCHEMA_VERSION;
111
- id: string;
112
- command: string;
113
- description: string;
114
- start: string;
115
- maxStepVisits: number;
116
- summaryMaxChars: number;
117
- steps: Record<string, WorkflowStep>;
118
- }
104
+ readonly subagent?: StepSubagent;
105
+ readonly permissions: StepPermissions;
106
+ readonly requires: StepRequirements;
107
+ readonly transitions: Readonly<Record<string, StepTarget>>;
108
+ readonly gate?: WorkflowGate;
109
+ };
110
+
111
+ export type WorkflowDefinition = {
112
+ readonly version: typeof WORKFLOW_SCHEMA_VERSION;
113
+ readonly id: string;
114
+ readonly command: string;
115
+ readonly description: string;
116
+ readonly start: string;
117
+ readonly maxStepVisits: number;
118
+ readonly summaryMaxChars: number;
119
+ readonly steps: Readonly<Record<string, WorkflowStep>>;
120
+ };
119
121
 
120
122
  export type WorkflowSourceKind = 'user' | 'project';
121
123
 
122
- export interface LoadedWorkflow {
123
- definition: WorkflowDefinition;
124
- prompts: Record<string, string>;
125
- digest: string;
126
- stepDigests: Record<string, string>;
127
- sourcePath: string;
128
- sourceKind: WorkflowSourceKind;
129
- }
130
-
131
- export interface PermissionCeiling {
132
- tools: string[];
133
- mcp: string[];
134
- extensions: string[];
135
- skills: string[];
136
- bash: BashPermission;
137
- subagent?: SubagentPermissionCeiling;
138
- }
139
-
140
- export interface SubagentPermissionCeiling {
141
- agents: string[];
142
- contexts: SubagentContext[];
143
- models: string[];
144
- maxTimeoutMs: number;
145
- maxTurns: number;
146
- maxGraceTurns: number;
147
- maxToolCalls: number;
148
- artifacts: boolean;
149
- retryToolFailures: boolean;
150
- }
151
-
152
- export interface WorkflowSettings {
153
- version: typeof WORKFLOW_SCHEMA_VERSION;
154
- allowProjectWorkflows: boolean;
155
- statusShortcut: KeyId;
156
- permissionCeiling?: PermissionCeiling;
157
- }
158
-
159
- export interface ConfigDiagnostic {
160
- level: 'warning' | 'error';
161
- path: string;
162
- message: string;
163
- }
164
-
165
- export interface WorkflowCatalog {
166
- workflows: Map<string, LoadedWorkflow>;
167
- settings: WorkflowSettings;
168
- diagnostics: ConfigDiagnostic[];
169
- userDirectory: string;
170
- projectDirectory?: string;
171
- }
172
-
173
- export const EMPTY_PERMISSIONS: StepPermissions = {
124
+ export type LoadedWorkflow = {
125
+ readonly definition: WorkflowDefinition;
126
+ readonly prompts: Readonly<Record<string, string>>;
127
+ readonly digest: string;
128
+ readonly stepDigests: Readonly<Record<string, string>>;
129
+ readonly sourcePath: string;
130
+ readonly sourceKind: WorkflowSourceKind;
131
+ };
132
+
133
+ export type PermissionCeiling = {
134
+ readonly tools: ReadonlyArray<string>;
135
+ readonly mcp: ReadonlyArray<string>;
136
+ readonly extensions: ReadonlyArray<string>;
137
+ readonly skills: ReadonlyArray<string>;
138
+ readonly bash: BashPermission;
139
+ readonly subagent?: SubagentPermissionCeiling;
140
+ };
141
+
142
+ export type SubagentPermissionCeiling = {
143
+ readonly agents: ReadonlyArray<string>;
144
+ readonly contexts: ReadonlyArray<SubagentContext>;
145
+ readonly models: ReadonlyArray<string>;
146
+ readonly maxTimeoutMs: number;
147
+ readonly maxTurns: number;
148
+ readonly maxGraceTurns: number;
149
+ readonly maxToolCalls: number;
150
+ readonly artifacts: boolean;
151
+ readonly retryToolFailures: boolean;
152
+ };
153
+
154
+ export type WorkflowSettings = {
155
+ readonly version: typeof WORKFLOW_SCHEMA_VERSION;
156
+ readonly allowProjectWorkflows: boolean;
157
+ readonly statusShortcut: KeyId;
158
+ readonly permissionCeiling?: PermissionCeiling;
159
+ };
160
+
161
+ export type ConfigDiagnostic = {
162
+ readonly level: 'warning' | 'error';
163
+ readonly path: string;
164
+ readonly message: string;
165
+ };
166
+
167
+ export type WorkflowCatalog = {
168
+ readonly workflows: ReadonlyMap<string, LoadedWorkflow>;
169
+ readonly settings: WorkflowSettings;
170
+ readonly diagnostics: ReadonlyArray<ConfigDiagnostic>;
171
+ readonly userDirectory: string;
172
+ readonly projectDirectory?: string;
173
+ };
174
+
175
+ export const EMPTY_PERMISSIONS = {
174
176
  tools: [],
175
177
  mcp: [],
176
178
  extensions: [],
177
179
  skills: [],
178
180
  bash: { mode: 'deny', allow: [] },
179
- };
181
+ } as const satisfies StepPermissions;
180
182
 
181
- export const EMPTY_REQUIREMENTS: StepRequirements = {
183
+ export const EMPTY_REQUIREMENTS = {
182
184
  tools: [],
183
185
  extensions: [],
184
186
  skills: [],
185
- };
187
+ } as const satisfies StepRequirements;
186
188
 
187
- export const DEFAULT_STEP_SUBAGENT: StepSubagent = {
189
+ export const DEFAULT_STEP_SUBAGENT = {
188
190
  agent: 'pi-workflows.step',
189
191
  context: 'fresh',
190
192
  timeoutMs: 900_000,
191
193
  artifacts: false,
192
194
  retryToolFailures: false,
193
- };
195
+ } as const satisfies StepSubagent;
194
196
 
195
- export const DEFAULT_SETTINGS: WorkflowSettings = {
197
+ export const DEFAULT_SETTINGS = {
196
198
  version: WORKFLOW_SCHEMA_VERSION,
197
199
  allowProjectWorkflows: false,
198
200
  statusShortcut: DEFAULT_STATUS_SHORTCUT,
199
- };
201
+ } as const satisfies WorkflowSettings;