pi-extensible-workflows 3.3.0 → 3.4.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
@@ -20,7 +20,7 @@ For source installs and local development, see the [installation guide](https://
20
20
 
21
21
  ## Capabilities
22
22
 
23
- The default path is a named inline workflow: write a `script` that fans out independent work with `parallel(...)`, awaits the keyed results, passes them into one summarizing `agent(...)`, and returns. Inline launches require a non-empty `name`; registered function launches reject `name` and use their registered function name as the run name. Runs are backgrounded by default; set `foreground: true` when the final value must be returned in the same tool call. If a foreground tool call detaches before its result is accepted by the next event-loop turn, the terminal success or failure is promoted to exactly one follow-up message.
23
+ The default path is a named inline workflow: write a `script` that fans out independent work with `parallel(...)`, awaits the keyed results, passes them into one summarizing `agent(...)`, and returns. Inline and file-backed launches require a non-empty `name`; a reviewed JavaScript file can use `scriptPath` instead of `script`, and its contents are captured in the run at launch. Registered function launches may use `name` as an optional run label and otherwise use their registered function name. Runs are backgrounded by default; set `foreground: true` when the final value must be returned in the same tool call. If a foreground tool call detaches before its result is accepted by the next event-loop turn, the terminal success or failure is promoted to exactly one follow-up message.
24
24
 
25
25
  ```js
26
26
  const reviews = await parallel("review", {
@@ -36,7 +36,7 @@ return await agent(
36
36
 
37
37
  **Advanced capabilities:** Use registered functions, `outputSchema`, budgets, checkpoints, worktrees, retry/resume, CLI export, and `pipeline(...)` when the task requires them. They remain available without complicating the basic inline path. Workflow worktree scopes always use the explicit `withWorktree(name, callback)` form.
38
38
 
39
- The main Pi agent writes these scripts on the fly for each task; extensions can add reusable functions and variables, and completed workflows can resume without rerunning completed work.
39
+ The main Pi agent writes these scripts on the fly for each task; an external review or approval flow can write one to a JavaScript file and launch it with `scriptPath`. Extensions can add reusable functions and variables, and completed workflows can resume without rerunning completed work.
40
40
 
41
41
  Learn more about roles, workflow contracts, and extension APIs in the documentation:
42
42
 
@@ -1,8 +1,56 @@
1
1
  import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
2
  type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
3
- import type { AgentIdentity, AgentResourceExclusions, AgentResourcePolicy, AgentSetupSummary, JsonSchema, JsonValue, ModelSpec, NativeSession, RegisteredAgentSetupHook, SessionFactory, SessionInput, WorkflowRunContext } from "./types.js";
3
+ type AgentMessage = {
4
+ role: string;
5
+ content?: unknown;
6
+ stopReason?: string;
7
+ errorMessage?: string;
8
+ usage?: {
9
+ input: number;
10
+ output: number;
11
+ cacheRead: number;
12
+ cacheWrite: number;
13
+ cost: {
14
+ total: number;
15
+ };
16
+ };
17
+ };
18
+ type PiSession = {
19
+ readonly sessionId: string;
20
+ readonly sessionFile: string | undefined;
21
+ readonly messages: readonly AgentMessage[];
22
+ getSessionStats(): {
23
+ tokens: {
24
+ input: number;
25
+ output: number;
26
+ cacheRead: number;
27
+ cacheWrite: number;
28
+ total: number;
29
+ };
30
+ cost: number;
31
+ };
32
+ readonly systemPrompt?: string;
33
+ readonly model?: {
34
+ provider: string;
35
+ model?: string;
36
+ id?: string;
37
+ };
38
+ readonly agent?: {
39
+ state: {
40
+ tools: readonly {
41
+ name: string;
42
+ }[];
43
+ };
44
+ };
45
+ subscribe?(listener: (event: unknown) => void): () => void;
46
+ prompt(text: string): Promise<void>;
47
+ steer?(text: string): Promise<void>;
48
+ abort?(): Promise<void>;
49
+ dispose(): void;
50
+ };
51
+ import type { AgentIdentity, AgentResourceExclusions, AgentResourcePolicy, AgentSetupSummary, AgentTransport, AgentTransportContext, JsonSchema, JsonValue, ModelSpec, PreparedAgentSession, RegisteredAgentSetupHook, SessionInput, WorkflowAgentSession, WorkflowAgentSessionReference, WorkflowAgentSessionState, WorkflowRunContext } from "./types.js";
4
52
  import type { RunStore } from "./persistence.js";
5
- export type { AgentSetup, AgentSetupContext, AgentSetupHook, NativeSession, RegisteredAgentSetupHook, SessionFactory, SessionInput } from "./types.js";
53
+ export type { AgentSetup, AgentSetupContext, AgentSetupHook, AgentTransport, AgentTransportContext, PreparedAgentSession, RegisteredAgentSetupHook, SessionInput, WorkflowAgentMessage, WorkflowAgentSession, WorkflowAgentSessionEvent, WorkflowAgentSessionReference, WorkflowAgentSessionState, WorkflowAgentSessionStats, WorkflowAgentTurnResult } from "./types.js";
6
54
  export interface AgentBudgetHooks {
7
55
  beforeAttempt(): void;
8
56
  beforeTurn(): void;
@@ -35,7 +83,7 @@ export interface AgentExecutionOptions {
35
83
  model?: string;
36
84
  thinking?: ThinkingLevel;
37
85
  onProgress?: (progress: AgentProgress) => void | Promise<void>;
38
- onAttempt?: (attempt: Pick<AgentAttempt, "attempt" | "sessionId" | "sessionFile" | "setup">) => void | Promise<void>;
86
+ onAttempt?: (attempt: AgentAttempt) => void | Promise<void>;
39
87
  providerErrorRecovery?: (failure: AgentProviderFailure) => Promise<AgentProviderRecovery>;
40
88
  modelOverride?: ModelSpec;
41
89
  tools?: readonly string[];
@@ -89,32 +137,36 @@ export interface AgentActivity {
89
137
  export interface AgentProgress {
90
138
  accounting: AgentAccounting;
91
139
  toolCalls: readonly AgentToolCallProgress[];
140
+ state?: WorkflowAgentSessionState;
92
141
  activity?: AgentActivity;
93
142
  lastEventAt?: number;
94
143
  persist: boolean;
95
144
  }
96
145
  export interface AgentAttempt {
97
146
  attempt: number;
98
- sessionId: string;
99
- sessionFile: string;
147
+ transport: string;
148
+ session?: WorkflowAgentSessionReference;
149
+ liveSession?: WorkflowAgentSession;
100
150
  result?: JsonValue;
101
151
  error?: {
102
152
  code: string;
103
153
  message: string;
104
154
  };
105
155
  accounting: AgentAccounting;
106
- setup?: AgentSetupSummary;
156
+ setup: AgentSetupSummary;
107
157
  }
108
158
  export interface AgentExecutionResult {
109
159
  value: JsonValue;
110
160
  attempts: readonly AgentAttempt[];
111
161
  cwd: string;
112
162
  }
113
- export declare function createNativeAgentSession(input: SessionInput): Promise<NativeSession>;
163
+ export declare function createLocalPiSession(input: SessionInput): Promise<PiSession>;
164
+ export declare function createLocalWorkflowAgentSession(prepared: Readonly<PreparedAgentSession>, context: Readonly<AgentTransportContext>): Promise<WorkflowAgentSession>;
165
+ export declare const localAgentTransport: AgentTransport;
114
166
  export declare class WorkflowAgentExecutor {
115
167
  private readonly root;
116
- private readonly createSession;
117
- constructor(root: AgentExecutionRoot, createSession?: SessionFactory);
168
+ private readonly transport;
169
+ constructor(root: AgentExecutionRoot, transport?: AgentTransport);
118
170
  setRunContext(runContext: Readonly<WorkflowRunContext>): void;
119
171
  resolve(options: AgentExecutionOptions, inheritedTools?: readonly string[]): {
120
172
  model: ModelSpec;
@@ -167,6 +219,7 @@ type ScheduledNode = {
167
219
  id: string;
168
220
  runId: string;
169
221
  parentId?: string;
222
+ prompt?: string;
170
223
  options: Readonly<ScheduledAgentOptions>;
171
224
  children: Set<string>;
172
225
  collected: boolean;
@@ -181,6 +234,7 @@ type ScheduledNode = {
181
234
  export type OwnershipRecord = {
182
235
  id: string;
183
236
  parentId?: string;
237
+ prompt?: string;
184
238
  label: string;
185
239
  state: ScheduledNode["state"];
186
240
  options: Readonly<ScheduledAgentOptions>;