pi-extensible-workflows 0.3.2 → 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.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ![pi-extensible-workflows workflow banner](https://raw.githubusercontent.com/vekexasia/pi-extensible-workflows/main/assets/pi-extensible-workflows-banner.png)
4
4
 
5
+ > There are many workflow extensions but this one is **Yours.**
6
+
5
7
  Turn multi-agent tasks into deterministic jobs that fan out in parallel, pause for approval, and resume without rerunning completed work.
6
8
 
7
9
  [Documentation](https://vekexasia.github.io/pi-extensible-workflows/) | [Developer guide](https://vekexasia.github.io/pi-extensible-workflows/developers.html) | [Agent guide](https://vekexasia.github.io/pi-extensible-workflows/agents.html)
@@ -41,12 +43,19 @@ return summary;
41
43
  Learn more about roles, workflow contracts, and extension APIs in the documentation:
42
44
 
43
45
  - [Workflow tool and invocation API](https://vekexasia.github.io/pi-extensible-workflows/developers.html#tool-api)
46
+ - [Global and project settings](https://vekexasia.github.io/pi-extensible-workflows/developers.html#settings)
47
+ - [Aggregate run budgets](https://vekexasia.github.io/pi-extensible-workflows/developers.html#budgets)
44
48
  - [Workflow DSL and worktrees](https://vekexasia.github.io/pi-extensible-workflows/developers.html#dsl)
45
49
  - [Reusable extension primitives](https://vekexasia.github.io/pi-extensible-workflows/developers.html#extensions)
50
+ - [Run artifacts and lifecycle events](https://vekexasia.github.io/pi-extensible-workflows/developers.html#lifecycle)
46
51
  - [Run inspection and recovery](https://vekexasia.github.io/pi-extensible-workflows/developers.html#operations)
47
52
  - [Agent patterns and model selection](https://vekexasia.github.io/pi-extensible-workflows/agents.html#patterns)
48
53
  - [Checkpoints](https://vekexasia.github.io/pi-extensible-workflows/agents.html#checkpoints)
49
54
 
55
+ ## Configuration
56
+
57
+ Global workflow settings live at `~/.pi/agent/pi-extensible-workflows/settings.json` by default and configure concurrency, model aliases, and workflow-agent skill or extension exclusions. Trusted projects can add resource exclusions at `<project>/.pi/pi-extensible-workflows/settings.json`; they cannot override global aliases or concurrency. See [global and project settings](https://vekexasia.github.io/pi-extensible-workflows/developers.html#settings) for the schema and merge rules.
58
+
50
59
  ## CLI
51
60
 
52
61
  ```sh
@@ -1,8 +1,10 @@
1
- import { type AgentSessionEvent, type ToolDefinition } from "@earendil-works/pi-coding-agent";
1
+ import { type AgentSessionEvent, type InlineExtension, type SessionStats, type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
2
  type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
3
3
  type AgentMessage = {
4
4
  role: string;
5
5
  content?: unknown;
6
+ stopReason?: string;
7
+ errorMessage?: string;
6
8
  usage?: {
7
9
  input: number;
8
10
  output: number;
@@ -13,14 +15,21 @@ type AgentMessage = {
13
15
  };
14
16
  };
15
17
  };
16
- import type { JsonSchema, JsonValue, ModelSpec } from "./index.js";
18
+ import type { AgentIdentity, AgentResourceExclusions, AgentResourcePolicy, AgentSetupSummary, JsonSchema, JsonValue, ModelSpec, WorkflowRunContext } from "./index.js";
17
19
  import type { RunStore } from "./persistence.js";
20
+ export interface AgentBudgetHooks {
21
+ beforeAttempt(): void;
22
+ beforeTurn(): void;
23
+ afterTurn(accounting: AgentAccounting, final: boolean): void;
24
+ instruction(): string | undefined;
25
+ }
18
26
  export interface AgentDefinition {
19
27
  prompt?: string;
20
28
  description?: string;
21
29
  model?: string;
22
30
  thinking?: ThinkingLevel;
23
31
  tools?: readonly string[];
32
+ disabledAgentResources?: AgentResourceExclusions;
24
33
  }
25
34
  export interface AgentExecutionOptions {
26
35
  label: string;
@@ -30,7 +39,7 @@ export interface AgentExecutionOptions {
30
39
  model?: string;
31
40
  thinking?: ThinkingLevel;
32
41
  onProgress?: (progress: AgentProgress) => void | Promise<void>;
33
- onAttempt?: (attempt: Pick<AgentAttempt, "attempt" | "sessionId" | "sessionFile">) => void | Promise<void>;
42
+ onAttempt?: (attempt: Pick<AgentAttempt, "attempt" | "sessionId" | "sessionFile" | "setup">) => void | Promise<void>;
34
43
  tools?: readonly string[];
35
44
  effectiveTools?: readonly string[];
36
45
  role?: string;
@@ -40,6 +49,13 @@ export interface AgentExecutionOptions {
40
49
  retryState?: string;
41
50
  worktreeOwner?: string;
42
51
  cwd?: string;
52
+ budget?: AgentBudgetHooks;
53
+ agentOptions?: Readonly<Record<string, JsonValue>>;
54
+ agentIdentity?: AgentIdentity;
55
+ conversation?: {
56
+ id: string;
57
+ turn: number;
58
+ };
43
59
  }
44
60
  export interface AgentExecutionRoot {
45
61
  cwd: string;
@@ -48,8 +64,16 @@ export interface AgentExecutionRoot {
48
64
  agentDefinitions?: Readonly<Record<string, AgentDefinition>>;
49
65
  agentDir?: string;
50
66
  availableModels?: ReadonlySet<string>;
67
+ knownModels?: ReadonlySet<string>;
68
+ modelAliases?: Readonly<Record<string, string>>;
69
+ blockedAliases?: ReadonlySet<string>;
70
+ blockedAliasTargets?: Readonly<Record<string, string>>;
71
+ settingsPath?: string;
51
72
  runStore?: RunStore;
52
73
  providerPause?: () => Promise<void>;
74
+ agentSetupHooks?: readonly RegisteredAgentSetupHook[];
75
+ agentResourcePolicy?: () => AgentResourcePolicy | Promise<AgentResourcePolicy>;
76
+ runContext?: Readonly<WorkflowRunContext>;
53
77
  }
54
78
  export interface AgentAccounting {
55
79
  input: number;
@@ -83,17 +107,46 @@ export interface AgentAttempt {
83
107
  message: string;
84
108
  };
85
109
  accounting: AgentAccounting;
110
+ setup?: AgentSetupSummary;
86
111
  }
87
112
  export interface AgentExecutionResult {
88
113
  value: JsonValue;
89
114
  attempts: readonly AgentAttempt[];
90
115
  cwd: string;
91
116
  }
117
+ export interface AgentSetup {
118
+ prompt: string;
119
+ options: Record<string, JsonValue>;
120
+ sessionInput: SessionInput;
121
+ createSession: SessionFactory;
122
+ }
123
+ export interface AgentSetupContext {
124
+ readonly run: Readonly<WorkflowRunContext>;
125
+ readonly identity: Readonly<AgentIdentity>;
126
+ readonly attempt: number;
127
+ readonly signal: AbortSignal;
128
+ }
129
+ export interface AgentSetupHook {
130
+ priority?: number;
131
+ setup: (agent: AgentSetup, context: Readonly<AgentSetupContext>) => void | Promise<void>;
132
+ }
133
+ export interface RegisteredAgentSetupHook {
134
+ name: string;
135
+ priority: number;
136
+ setup: AgentSetupHook["setup"];
137
+ }
138
+ type NativeSessionStats = Pick<SessionStats, "tokens" | "cost">;
92
139
  export interface NativeSession {
93
140
  readonly sessionId: string;
94
141
  readonly sessionFile: string | undefined;
95
142
  readonly messages: readonly AgentMessage[];
143
+ getSessionStats(): NativeSessionStats;
96
144
  readonly systemPrompt?: string;
145
+ readonly model?: {
146
+ provider: string;
147
+ model?: string;
148
+ id?: string;
149
+ };
97
150
  readonly agent?: {
98
151
  state: {
99
152
  tools: readonly {
@@ -101,6 +154,8 @@ export interface NativeSession {
101
154
  }[];
102
155
  };
103
156
  };
157
+ getLeafId?: () => string | null;
158
+ getToolDefinitions?: () => unknown;
104
159
  subscribe?(listener: (event: AgentSessionEvent) => void): () => void;
105
160
  prompt(text: string): Promise<void>;
106
161
  steer?(text: string): Promise<void>;
@@ -110,12 +165,20 @@ export interface NativeSession {
110
165
  export interface SessionInput {
111
166
  cwd: string;
112
167
  model: ModelSpec;
113
- tools: readonly string[];
168
+ tools: string[];
114
169
  sessionLabel: string;
115
170
  agentDir?: string;
116
- customTools?: readonly ToolDefinition[];
171
+ customTools?: ToolDefinition[];
117
172
  resultTool?: ToolDefinition;
118
173
  systemPromptAppend?: string;
174
+ extensionFactories?: InlineExtension[];
175
+ resourcePolicy?: AgentResourcePolicy;
176
+ options?: Record<string, JsonValue>;
177
+ continuation?: {
178
+ sessionId: string;
179
+ sessionFile: string;
180
+ leafId: string;
181
+ };
119
182
  }
120
183
  export type SessionFactory = (input: SessionInput) => Promise<NativeSession>;
121
184
  export declare function createNativeAgentSession(input: SessionInput): Promise<NativeSession>;
@@ -123,8 +186,10 @@ export declare class WorkflowAgentExecutor {
123
186
  private readonly root;
124
187
  private readonly createSession;
125
188
  constructor(root: AgentExecutionRoot, createSession?: SessionFactory);
189
+ setRunContext(runContext: Readonly<WorkflowRunContext>): void;
126
190
  resolve(options: AgentExecutionOptions, inheritedTools?: readonly string[]): {
127
191
  model: ModelSpec;
192
+ requestedModel?: string;
128
193
  tools: readonly string[];
129
194
  systemPromptAppend: string;
130
195
  };
@@ -143,6 +208,12 @@ export interface ScheduledAgentOptions {
143
208
  schema?: JsonSchema;
144
209
  retries?: number;
145
210
  timeoutMs?: number | null;
211
+ agentOptions?: Readonly<Record<string, JsonValue>>;
212
+ agentIdentity?: AgentIdentity;
213
+ conversation?: {
214
+ id: string;
215
+ turn: number;
216
+ };
146
217
  }
147
218
  export type ScheduledAgentResult = {
148
219
  id: string;
@@ -173,7 +244,7 @@ type ScheduledNode = {
173
244
  options: Readonly<ScheduledAgentOptions>;
174
245
  children: Set<string>;
175
246
  collected: boolean;
176
- state: "queued" | "running" | "waiting_for_child" | "completed" | "failed" | "cancelled";
247
+ state: "queued" | "running" | "waiting_for_child" | "paused" | "retrying" | "completed" | "failed" | "cancelled";
177
248
  controller: AbortController;
178
249
  promise: Promise<ScheduledAgentResult>;
179
250
  resolve: (result: ScheduledAgentResult) => void;
@@ -195,7 +266,7 @@ export declare class FairAgentScheduler {
195
266
  readonly sessionLimit: number;
196
267
  private readonly writeOwnership?;
197
268
  constructor(runner: ScheduledAgentRunner, sessionLimit?: number, writeOwnership?: OwnershipWriter | undefined);
198
- addRun(runId: string, limit?: number, maxAgentLaunches?: number): void;
269
+ addRun(runId: string, limit?: number, beforeLaunch?: () => void): void;
199
270
  spawn(runId: string, prompt: string, options: ScheduledAgentOptions, parentId?: string): {
200
271
  id: string;
201
272
  result: Promise<ScheduledAgentResult>;
@@ -204,10 +275,12 @@ export declare class FairAgentScheduler {
204
275
  steer(parentId: string, childId: string, message: string): Promise<void>;
205
276
  cancel(id: string): void;
206
277
  cancelChildren(id: string): void;
278
+ retry(id: string): void;
279
+ attemptStarted(id: string): void;
207
280
  cancelRun(runId: string): Promise<void>;
208
281
  toolsFor(parentId: string, resolveTools?: (role: string | undefined, tools: readonly string[] | undefined, model: string | undefined, inheritedTools: readonly string[], thinking: ThinkingLevel | undefined) => readonly string[]): ToolDefinition[];
209
282
  snapshot(): readonly OwnershipRecord[];
210
- restoreRun(runId: string, limit: number, maxAgentLaunches: number, ownership: readonly OwnershipRecord[]): void;
283
+ restoreRun(runId: string, limit: number, ownership: readonly OwnershipRecord[], beforeLaunch?: () => void): void;
211
284
  flush(): Promise<void>;
212
285
  }
213
286
  export {};