pi-extensible-workflows 3.3.0 → 3.4.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.
- package/README.md +2 -2
- package/dist/src/agent-execution.d.ts +63 -9
- package/dist/src/agent-execution.js +265 -92
- package/dist/src/cli.js +11 -2
- package/dist/src/doctor-cleanup.js +66 -31
- package/dist/src/execution.d.ts +1 -1
- package/dist/src/execution.js +29 -13
- package/dist/src/host.d.ts +5 -5
- package/dist/src/host.js +160 -76
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/persistence.d.ts +4 -8
- package/dist/src/persistence.js +3 -0
- package/dist/src/registry.d.ts +3 -2
- package/dist/src/registry.js +16 -4
- package/dist/src/session-inspector.js +14 -22
- package/dist/src/types.d.ts +123 -60
- package/dist/src/validation.js +20 -5
- package/dist/src/workflow-artifacts.d.ts +1 -0
- package/dist/src/workflow-artifacts.js +1 -0
- package/package.json +2 -2
- package/skills/pi-extensible-workflows/SKILL.md +13 -5
- package/src/agent-execution.ts +221 -90
- package/src/cli.ts +14 -3
- package/src/doctor-cleanup.ts +36 -3
- package/src/execution.ts +27 -15
- package/src/host.ts +136 -62
- package/src/index.ts +3 -3
- package/src/persistence.ts +5 -3
- package/src/registry.ts +14 -5
- package/src/session-inspector.ts +13 -22
- package/src/types.ts +45 -27
- package/src/validation.ts +13 -4
- package/src/workflow-artifacts.ts +1 -0
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`;
|
|
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;
|
|
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
|
-
|
|
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,
|
|
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:
|
|
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
|
-
|
|
99
|
-
|
|
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
|
|
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
|
|
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
|
|
117
|
-
constructor(root: AgentExecutionRoot,
|
|
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>;
|