pi-extensible-workflows 2.0.0 → 3.1.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 +18 -11
- package/dist/src/agent-execution.d.ts +4 -94
- package/dist/src/agent-execution.js +34 -208
- package/dist/src/budget.d.ts +38 -0
- package/dist/src/budget.js +160 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +60 -8
- package/dist/src/doctor-cleanup.d.ts +41 -0
- package/dist/src/doctor-cleanup.js +597 -0
- package/dist/src/doctor.d.ts +7 -2
- package/dist/src/doctor.js +127 -22
- package/dist/src/execution.d.ts +17 -0
- package/dist/src/execution.js +630 -0
- package/dist/src/host.d.ts +101 -0
- package/dist/src/host.js +3084 -0
- package/dist/src/index.d.ts +13 -634
- package/dist/src/index.js +10 -4432
- package/dist/src/persistence.d.ts +9 -19
- package/dist/src/persistence.js +175 -61
- package/dist/src/registry.d.ts +43 -0
- package/dist/src/registry.js +279 -0
- package/dist/src/session-inspector.js +5 -3
- package/dist/src/types.d.ts +692 -0
- package/dist/src/types.js +27 -0
- package/dist/src/utils.d.ts +32 -0
- package/dist/src/utils.js +168 -0
- package/dist/src/validation.d.ts +28 -0
- package/dist/src/validation.js +832 -0
- package/package.json +3 -2
- package/skills/pi-extensible-workflows/SKILL.md +69 -34
- package/src/agent-execution.ts +37 -189
- package/src/budget.ts +75 -0
- package/src/cli.ts +47 -7
- package/src/doctor-cleanup.ts +337 -0
- package/src/doctor.ts +117 -24
- package/src/execution.ts +540 -0
- package/src/host.ts +2598 -0
- package/src/index.ts +14 -3856
- package/src/persistence.ts +122 -37
- package/src/registry.ts +240 -0
- package/src/session-inspector.ts +5 -3
- package/src/types.ts +158 -0
- package/src/utils.ts +142 -0
- package/src/validation.ts +688 -0
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
import type { AgentSessionEvent, CreateAgentSessionOptions, InlineExtension, SessionStats, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
export declare const RUN_STATES: readonly ["queued", "running", "pausing", "paused", "awaiting_input", "completed", "failed", "stopped", "interrupted", "budget_exhausted"];
|
|
3
|
+
export declare const AGENT_STATES: readonly ["queued", "running", "waiting_for_child", "paused", "retrying", "completed", "failed", "cancelled"];
|
|
4
|
+
export declare const WORKFLOW_CALL_KINDS: readonly ["agent", "parallel", "pipeline", "checkpoint", "phase", "withWorktree", "shell"];
|
|
5
|
+
export type WorkflowCallKind = (typeof WORKFLOW_CALL_KINDS)[number];
|
|
6
|
+
export declare const WORKFLOW_RUN_STARTED_EVENT = "workflow:run-started";
|
|
7
|
+
export declare const WORKFLOW_RUN_RESUMED_EVENT = "workflow:run-resumed";
|
|
8
|
+
export declare const WORKFLOW_RUN_STATE_CHANGED_EVENT = "workflow:run-state-changed";
|
|
9
|
+
export declare const WORKFLOW_RUN_COMPLETED_EVENT = "workflow:run-completed";
|
|
10
|
+
export declare const WORKFLOW_RUN_FAILED_EVENT = "workflow:run-failed";
|
|
11
|
+
export declare const WORKFLOW_AGENT_STATE_CHANGED_EVENT = "workflow:agent-state-changed";
|
|
12
|
+
export declare const WORKFLOW_PHASE_CHANGED_EVENT = "workflow:phase-changed";
|
|
13
|
+
export declare const WORKFLOW_CHECKPOINT_STATE_CHANGED_EVENT = "workflow:checkpoint-state-changed";
|
|
14
|
+
export declare const WORKFLOW_BUDGET_EVENT = "workflow:budget-event";
|
|
15
|
+
export declare const WORKFLOW_WORKTREE_CREATED_EVENT = "workflow:worktree-created";
|
|
16
|
+
export declare const ERROR_CODES: readonly ["CONFIG_ERROR", "INVALID_SETTINGS", "INVALID_SYNTAX", "INVALID_METADATA", "DUPLICATE_NAME", "INVALID_SCHEMA", "UNKNOWN_MODEL", "UNKNOWN_TOOL", "UNKNOWN_AGENT_TYPE", "RUN_OWNED", "REGISTRY_FROZEN", "GLOBAL_COLLISION", "MISSING_WORKFLOW", "RPC_LIMIT_EXCEEDED", "SHELL_FAILED", "AGENT_TIMEOUT", "AGENT_FAILED", "RESULT_INVALID", "CANCELLED", "WORKER_UNRESPONSIVE", "WORKTREE_FAILED", "RESUME_INCOMPATIBLE", "BUDGET_EXHAUSTED", "INTERNAL_ERROR"];
|
|
17
|
+
export type RunState = (typeof RUN_STATES)[number];
|
|
18
|
+
export type AgentState = (typeof AGENT_STATES)[number];
|
|
19
|
+
export type WorkflowErrorCode = (typeof ERROR_CODES)[number];
|
|
20
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
21
|
+
[key: string]: JsonValue;
|
|
22
|
+
};
|
|
23
|
+
export type JsonSchema = {
|
|
24
|
+
[key: string]: JsonValue;
|
|
25
|
+
};
|
|
26
|
+
export interface AgentOptions {
|
|
27
|
+
label?: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
thinking?: NonNullable<ModelSpec["thinking"]>;
|
|
30
|
+
tools?: string[];
|
|
31
|
+
role?: string;
|
|
32
|
+
outputSchema?: JsonSchema;
|
|
33
|
+
retries?: number;
|
|
34
|
+
timeoutMs?: number | null;
|
|
35
|
+
[key: string]: JsonValue;
|
|
36
|
+
}
|
|
37
|
+
export interface ShellOptions {
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
export interface ShellResult {
|
|
42
|
+
exitCode: number | null;
|
|
43
|
+
stdout: string;
|
|
44
|
+
stderr: string;
|
|
45
|
+
}
|
|
46
|
+
export type BudgetDimension = "tokens" | "costUsd" | "durationMs" | "agentLaunches";
|
|
47
|
+
export interface BudgetLimits {
|
|
48
|
+
soft?: number;
|
|
49
|
+
hard?: number;
|
|
50
|
+
}
|
|
51
|
+
export type WorkflowBudget = Partial<Record<BudgetDimension, BudgetLimits>>;
|
|
52
|
+
export type WorkflowBudgetPatch = Partial<Record<BudgetDimension, BudgetLimits | {
|
|
53
|
+
soft?: number | null;
|
|
54
|
+
hard?: number | null;
|
|
55
|
+
} | null>>;
|
|
56
|
+
export interface WorkflowBudgetUsage {
|
|
57
|
+
tokens: number;
|
|
58
|
+
costUsd: number;
|
|
59
|
+
durationMs: number;
|
|
60
|
+
agentLaunches: number;
|
|
61
|
+
}
|
|
62
|
+
export type BudgetEventType = "soft_crossed" | "hard_overrun" | "hard_exhausted" | "adjustment_requested" | "adjustment_approved" | "adjustment_rejected";
|
|
63
|
+
export interface BudgetEvent {
|
|
64
|
+
type: BudgetEventType;
|
|
65
|
+
budgetVersion: number;
|
|
66
|
+
dimensions: readonly BudgetDimension[];
|
|
67
|
+
usage: WorkflowBudgetUsage;
|
|
68
|
+
limits: WorkflowBudget;
|
|
69
|
+
at: number;
|
|
70
|
+
proposalId?: string;
|
|
71
|
+
previous?: WorkflowBudget;
|
|
72
|
+
proposed?: WorkflowBudget;
|
|
73
|
+
}
|
|
74
|
+
export interface BudgetApprovalRequest {
|
|
75
|
+
kind: "budget";
|
|
76
|
+
proposalId: string;
|
|
77
|
+
runId: string;
|
|
78
|
+
consumed: WorkflowBudgetUsage;
|
|
79
|
+
previous: WorkflowBudget;
|
|
80
|
+
proposed: WorkflowBudget;
|
|
81
|
+
budgetVersion: number;
|
|
82
|
+
}
|
|
83
|
+
export interface WorkflowErrorShape {
|
|
84
|
+
code: WorkflowErrorCode;
|
|
85
|
+
message: string;
|
|
86
|
+
}
|
|
87
|
+
export interface WorkflowEventBase {
|
|
88
|
+
runId: string;
|
|
89
|
+
sessionId: string;
|
|
90
|
+
workflowName: string;
|
|
91
|
+
cwd: string;
|
|
92
|
+
runDirectory: string;
|
|
93
|
+
timestamp: number;
|
|
94
|
+
}
|
|
95
|
+
export type WorkflowRunStartedEvent = WorkflowEventBase;
|
|
96
|
+
export type WorkflowRunResumedEvent = WorkflowEventBase;
|
|
97
|
+
export interface WorkflowRunStateChangedEvent extends WorkflowEventBase {
|
|
98
|
+
previousState: RunState;
|
|
99
|
+
state: RunState;
|
|
100
|
+
reason?: string;
|
|
101
|
+
errorCode?: WorkflowErrorCode;
|
|
102
|
+
}
|
|
103
|
+
export interface WorkflowRunCompletedEvent extends WorkflowEventBase {
|
|
104
|
+
resultPath: string;
|
|
105
|
+
}
|
|
106
|
+
export interface WorkflowRunFailedEvent extends WorkflowEventBase {
|
|
107
|
+
error: WorkflowErrorShape;
|
|
108
|
+
}
|
|
109
|
+
export interface WorkflowAgentStateChangedEvent extends WorkflowEventBase {
|
|
110
|
+
agentId: string;
|
|
111
|
+
displayLabel: string;
|
|
112
|
+
role?: string;
|
|
113
|
+
structuralPath: readonly string[];
|
|
114
|
+
parentId?: string;
|
|
115
|
+
parentBreadcrumb?: string;
|
|
116
|
+
worktreeOwner?: string;
|
|
117
|
+
previousState?: AgentState;
|
|
118
|
+
state: AgentState;
|
|
119
|
+
attempt: number;
|
|
120
|
+
}
|
|
121
|
+
export interface WorkflowPhaseChangedEvent extends WorkflowEventBase {
|
|
122
|
+
previousPhase?: string;
|
|
123
|
+
phase: string;
|
|
124
|
+
}
|
|
125
|
+
export type WorkflowCheckpointState = "awaiting" | "approved" | "rejected";
|
|
126
|
+
export interface WorkflowCheckpointStateChangedEvent extends WorkflowEventBase {
|
|
127
|
+
name: string;
|
|
128
|
+
state: WorkflowCheckpointState;
|
|
129
|
+
}
|
|
130
|
+
export interface WorkflowBudgetEvent extends WorkflowEventBase {
|
|
131
|
+
type: BudgetEventType;
|
|
132
|
+
budgetVersion: number;
|
|
133
|
+
dimensions: readonly BudgetDimension[];
|
|
134
|
+
usage: WorkflowBudgetUsage;
|
|
135
|
+
limits: WorkflowBudget;
|
|
136
|
+
proposalId?: string;
|
|
137
|
+
previous?: WorkflowBudget;
|
|
138
|
+
proposed?: WorkflowBudget;
|
|
139
|
+
}
|
|
140
|
+
export interface ModelSpec {
|
|
141
|
+
provider: string;
|
|
142
|
+
model: string;
|
|
143
|
+
thinking?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
144
|
+
}
|
|
145
|
+
export interface WorkflowModelAliasResolverContext {
|
|
146
|
+
cwd: string;
|
|
147
|
+
projectTrusted: boolean;
|
|
148
|
+
rootModel: ModelSpec;
|
|
149
|
+
knownModels: ReadonlySet<string>;
|
|
150
|
+
availableModels: ReadonlySet<string>;
|
|
151
|
+
signal: AbortSignal;
|
|
152
|
+
}
|
|
153
|
+
export interface WorkflowModelAlias {
|
|
154
|
+
resolve: (context: Readonly<WorkflowModelAliasResolverContext>) => string | Promise<string>;
|
|
155
|
+
}
|
|
156
|
+
export interface WorkflowMetadata {
|
|
157
|
+
name: string;
|
|
158
|
+
description?: string;
|
|
159
|
+
}
|
|
160
|
+
export interface WorkflowSettings {
|
|
161
|
+
concurrency: number;
|
|
162
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
163
|
+
disabledAgentResources?: Readonly<AgentResourceExclusions>;
|
|
164
|
+
}
|
|
165
|
+
export interface WorkflowSettingsOverrides {
|
|
166
|
+
concurrency?: number;
|
|
167
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
168
|
+
disabledAgentResources?: Readonly<AgentResourceExclusions>;
|
|
169
|
+
}
|
|
170
|
+
export interface WorkflowSettingsSources {
|
|
171
|
+
concurrency: string;
|
|
172
|
+
modelAliases: string;
|
|
173
|
+
disabledAgentResources: string;
|
|
174
|
+
}
|
|
175
|
+
export interface WorkflowSettingsResolution {
|
|
176
|
+
globalSettingsPath: string;
|
|
177
|
+
projectSettingsPath: string;
|
|
178
|
+
projectTrusted: boolean;
|
|
179
|
+
global: Readonly<WorkflowSettings>;
|
|
180
|
+
project: Readonly<WorkflowSettingsOverrides>;
|
|
181
|
+
effective: Readonly<WorkflowSettings>;
|
|
182
|
+
sources: Readonly<WorkflowSettingsSources>;
|
|
183
|
+
}
|
|
184
|
+
export interface AgentResourceExclusions {
|
|
185
|
+
skills: readonly string[];
|
|
186
|
+
extensions: readonly string[];
|
|
187
|
+
}
|
|
188
|
+
export interface AgentResourcePolicy {
|
|
189
|
+
globalSettingsPath: string;
|
|
190
|
+
projectSettingsPath: string;
|
|
191
|
+
projectTrusted: boolean;
|
|
192
|
+
global: AgentResourceExclusions;
|
|
193
|
+
project: AgentResourceExclusions;
|
|
194
|
+
effective: AgentResourceExclusions;
|
|
195
|
+
unmatchedSkills: string[];
|
|
196
|
+
unmatchedExtensions: string[];
|
|
197
|
+
excludedSkills?: string[];
|
|
198
|
+
excludedExtensions?: string[];
|
|
199
|
+
}
|
|
200
|
+
export interface AgentActivity {
|
|
201
|
+
kind: "reasoning" | "tool" | "text";
|
|
202
|
+
text: string;
|
|
203
|
+
}
|
|
204
|
+
export interface AgentAccounting {
|
|
205
|
+
input: number;
|
|
206
|
+
output: number;
|
|
207
|
+
cacheRead: number;
|
|
208
|
+
cacheWrite: number;
|
|
209
|
+
cost: number;
|
|
210
|
+
}
|
|
211
|
+
export interface AgentSetupSummary {
|
|
212
|
+
hookNames: readonly string[];
|
|
213
|
+
model: ModelSpec;
|
|
214
|
+
tools: readonly string[];
|
|
215
|
+
cwd: string;
|
|
216
|
+
disabledAgentResources?: {
|
|
217
|
+
skills: readonly string[];
|
|
218
|
+
extensions: readonly string[];
|
|
219
|
+
excludedSkills?: readonly string[];
|
|
220
|
+
excludedExtensions?: readonly string[];
|
|
221
|
+
unmatchedSkills: readonly string[];
|
|
222
|
+
unmatchedExtensions: readonly string[];
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export interface AgentAttemptSummary {
|
|
226
|
+
attempt: number;
|
|
227
|
+
sessionId: string;
|
|
228
|
+
sessionFile: string;
|
|
229
|
+
error?: {
|
|
230
|
+
code: string;
|
|
231
|
+
message: string;
|
|
232
|
+
};
|
|
233
|
+
accounting: {
|
|
234
|
+
input: number;
|
|
235
|
+
output: number;
|
|
236
|
+
cacheRead: number;
|
|
237
|
+
cacheWrite: number;
|
|
238
|
+
cost: number;
|
|
239
|
+
};
|
|
240
|
+
setup?: AgentSetupSummary;
|
|
241
|
+
}
|
|
242
|
+
export interface WorkflowWorktreeCreatedEvent extends WorkflowEventBase {
|
|
243
|
+
owner: string;
|
|
244
|
+
branch: string;
|
|
245
|
+
path: string;
|
|
246
|
+
base: string;
|
|
247
|
+
}
|
|
248
|
+
export interface WorkflowWorktreeReference {
|
|
249
|
+
readonly path: string;
|
|
250
|
+
readonly branch: string;
|
|
251
|
+
}
|
|
252
|
+
export interface AgentRecord {
|
|
253
|
+
id: string;
|
|
254
|
+
name: string;
|
|
255
|
+
label?: string;
|
|
256
|
+
path: string;
|
|
257
|
+
state: AgentState;
|
|
258
|
+
parentId?: string;
|
|
259
|
+
structuralPath?: readonly string[];
|
|
260
|
+
parentBreadcrumb?: string;
|
|
261
|
+
worktreeOwner?: string;
|
|
262
|
+
role?: string;
|
|
263
|
+
requestedModel?: string;
|
|
264
|
+
model: ModelSpec;
|
|
265
|
+
tools: readonly string[];
|
|
266
|
+
attempts: number;
|
|
267
|
+
attemptDetails?: readonly AgentAttemptSummary[];
|
|
268
|
+
accounting?: {
|
|
269
|
+
input: number;
|
|
270
|
+
output: number;
|
|
271
|
+
cacheRead: number;
|
|
272
|
+
cacheWrite: number;
|
|
273
|
+
cost: number;
|
|
274
|
+
};
|
|
275
|
+
toolCalls?: readonly {
|
|
276
|
+
id: string;
|
|
277
|
+
name: string;
|
|
278
|
+
state: "running" | "completed" | "failed";
|
|
279
|
+
}[];
|
|
280
|
+
activity?: AgentActivity | undefined;
|
|
281
|
+
}
|
|
282
|
+
export interface WorkflowRunEvent {
|
|
283
|
+
type: string;
|
|
284
|
+
message: string;
|
|
285
|
+
}
|
|
286
|
+
export interface WorkflowRetryProvenance {
|
|
287
|
+
sourceRunId: string;
|
|
288
|
+
lineageRootRunId: string;
|
|
289
|
+
completedPaths: readonly string[];
|
|
290
|
+
incompletePaths: readonly string[];
|
|
291
|
+
namedWorktrees: readonly string[];
|
|
292
|
+
}
|
|
293
|
+
export interface WorkflowPhaseRecord {
|
|
294
|
+
phase: string;
|
|
295
|
+
afterAgent: number;
|
|
296
|
+
}
|
|
297
|
+
export interface RunRecord {
|
|
298
|
+
id: string;
|
|
299
|
+
workflowName: string;
|
|
300
|
+
cwd: string;
|
|
301
|
+
sessionId: string;
|
|
302
|
+
state: RunState;
|
|
303
|
+
parentRunId?: string;
|
|
304
|
+
retry?: WorkflowRetryProvenance;
|
|
305
|
+
phase?: string;
|
|
306
|
+
phaseHistory?: readonly WorkflowPhaseRecord[];
|
|
307
|
+
agents: readonly AgentRecord[];
|
|
308
|
+
error?: WorkflowErrorShape;
|
|
309
|
+
budget?: WorkflowBudget;
|
|
310
|
+
budgetVersion?: number;
|
|
311
|
+
usage?: WorkflowBudgetUsage;
|
|
312
|
+
budgetEvents?: readonly BudgetEvent[];
|
|
313
|
+
events?: readonly WorkflowRunEvent[];
|
|
314
|
+
}
|
|
315
|
+
export declare const LAUNCH_SNAPSHOT_IDENTITY_VERSION = 5;
|
|
316
|
+
export interface AgentDefinition {
|
|
317
|
+
prompt?: string;
|
|
318
|
+
description?: string;
|
|
319
|
+
model?: string;
|
|
320
|
+
thinking?: NonNullable<ModelSpec["thinking"]>;
|
|
321
|
+
tools?: readonly string[];
|
|
322
|
+
disabledAgentResources?: AgentResourceExclusions;
|
|
323
|
+
}
|
|
324
|
+
export interface LaunchSnapshot {
|
|
325
|
+
identityVersion?: number;
|
|
326
|
+
launchKind?: "inline" | "function";
|
|
327
|
+
functionName?: string;
|
|
328
|
+
script: string;
|
|
329
|
+
args: JsonValue;
|
|
330
|
+
metadata: WorkflowMetadata;
|
|
331
|
+
settings: WorkflowSettings;
|
|
332
|
+
settingsSources?: WorkflowSettingsSources;
|
|
333
|
+
budget?: WorkflowBudget;
|
|
334
|
+
settingsPath?: string;
|
|
335
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
336
|
+
phases?: readonly string[];
|
|
337
|
+
models: readonly string[];
|
|
338
|
+
tools: readonly string[];
|
|
339
|
+
agentTypes: readonly string[];
|
|
340
|
+
roles?: Readonly<Record<string, AgentDefinition>>;
|
|
341
|
+
projectRoles?: readonly string[];
|
|
342
|
+
schemas: readonly JsonSchema[];
|
|
343
|
+
}
|
|
344
|
+
export interface PreflightCapabilities {
|
|
345
|
+
models: ReadonlySet<string>;
|
|
346
|
+
tools: ReadonlySet<string>;
|
|
347
|
+
agentTypes: ReadonlySet<string>;
|
|
348
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
349
|
+
knownModels?: ReadonlySet<string>;
|
|
350
|
+
settingsPath?: string;
|
|
351
|
+
skipModelAvailability?: boolean;
|
|
352
|
+
}
|
|
353
|
+
export interface PreflightResult {
|
|
354
|
+
metadata: WorkflowMetadata;
|
|
355
|
+
referenced: {
|
|
356
|
+
phases: readonly string[];
|
|
357
|
+
models: readonly string[];
|
|
358
|
+
tools: readonly string[];
|
|
359
|
+
agentTypes: readonly string[];
|
|
360
|
+
};
|
|
361
|
+
schemas: readonly JsonSchema[];
|
|
362
|
+
dynamicAgentRoles: boolean;
|
|
363
|
+
}
|
|
364
|
+
export interface WorkflowOrchestrationContext {
|
|
365
|
+
agent: (prompt: string, options?: Readonly<AgentOptions>) => Promise<JsonValue>;
|
|
366
|
+
shell: (command: string, options?: ShellOptions) => Promise<ShellResult>;
|
|
367
|
+
prompt: (template: string, values: Readonly<Record<string, JsonValue>>) => string;
|
|
368
|
+
parallel: (...args: readonly unknown[]) => Promise<JsonValue>;
|
|
369
|
+
pipeline: (...args: readonly unknown[]) => Promise<JsonValue>;
|
|
370
|
+
withWorktree: (name: string, callback: WorkflowWorktreeCallback) => Promise<JsonValue>;
|
|
371
|
+
checkpoint: (...args: readonly unknown[]) => Promise<boolean>;
|
|
372
|
+
phase: (name: string) => void;
|
|
373
|
+
log: (message: string) => void;
|
|
374
|
+
}
|
|
375
|
+
export interface WorkflowRunContext {
|
|
376
|
+
cwd: string;
|
|
377
|
+
sessionId: string;
|
|
378
|
+
runId: string;
|
|
379
|
+
workflow: Readonly<WorkflowMetadata>;
|
|
380
|
+
args: JsonValue;
|
|
381
|
+
signal: AbortSignal;
|
|
382
|
+
}
|
|
383
|
+
export interface WorkflowFunctionContext extends WorkflowOrchestrationContext {
|
|
384
|
+
run: Readonly<WorkflowRunContext>;
|
|
385
|
+
invoke: (name: string, input: Readonly<Record<string, JsonValue>>) => Promise<JsonValue>;
|
|
386
|
+
}
|
|
387
|
+
export type WorkflowWorktreeCallback = (reference: Readonly<WorkflowWorktreeReference>) => JsonValue | Promise<JsonValue>;
|
|
388
|
+
export interface WorkflowFunction {
|
|
389
|
+
description: string;
|
|
390
|
+
input: JsonSchema;
|
|
391
|
+
output: JsonSchema;
|
|
392
|
+
run: (input: Readonly<Record<string, JsonValue>>, context: Readonly<WorkflowFunctionContext>) => Promise<JsonValue> | JsonValue;
|
|
393
|
+
}
|
|
394
|
+
export interface WorkflowVariable {
|
|
395
|
+
description: string;
|
|
396
|
+
schema: JsonSchema;
|
|
397
|
+
resolve: (run: Readonly<WorkflowRunContext>) => Promise<JsonValue> | JsonValue;
|
|
398
|
+
}
|
|
399
|
+
type NativeAgentMessage = {
|
|
400
|
+
role: string;
|
|
401
|
+
content?: unknown;
|
|
402
|
+
stopReason?: string;
|
|
403
|
+
errorMessage?: string;
|
|
404
|
+
usage?: {
|
|
405
|
+
input: number;
|
|
406
|
+
output: number;
|
|
407
|
+
cacheRead: number;
|
|
408
|
+
cacheWrite: number;
|
|
409
|
+
cost: {
|
|
410
|
+
total: number;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
type NativeSessionStats = Pick<SessionStats, "tokens" | "cost">;
|
|
415
|
+
export interface NativeSession {
|
|
416
|
+
readonly sessionId: string;
|
|
417
|
+
readonly sessionFile: string | undefined;
|
|
418
|
+
readonly messages: readonly NativeAgentMessage[];
|
|
419
|
+
getSessionStats(): NativeSessionStats;
|
|
420
|
+
readonly systemPrompt?: string;
|
|
421
|
+
readonly model?: {
|
|
422
|
+
provider: string;
|
|
423
|
+
model?: string;
|
|
424
|
+
id?: string;
|
|
425
|
+
};
|
|
426
|
+
readonly agent?: {
|
|
427
|
+
state: {
|
|
428
|
+
tools: readonly {
|
|
429
|
+
name: string;
|
|
430
|
+
}[];
|
|
431
|
+
};
|
|
432
|
+
};
|
|
433
|
+
getLeafId?: () => string | null;
|
|
434
|
+
getToolDefinitions?: () => unknown;
|
|
435
|
+
subscribe?(listener: (event: AgentSessionEvent) => void): () => void;
|
|
436
|
+
prompt(text: string): Promise<void>;
|
|
437
|
+
steer?(text: string): Promise<void>;
|
|
438
|
+
abort?(): Promise<void>;
|
|
439
|
+
dispose(): void;
|
|
440
|
+
}
|
|
441
|
+
type SessionTools = NonNullable<CreateAgentSessionOptions["tools"]>;
|
|
442
|
+
type SessionCustomTools = NonNullable<CreateAgentSessionOptions["customTools"]>;
|
|
443
|
+
export interface SessionInput {
|
|
444
|
+
cwd: string;
|
|
445
|
+
model: ModelSpec;
|
|
446
|
+
tools: SessionTools;
|
|
447
|
+
sessionLabel: string;
|
|
448
|
+
agentDir?: string;
|
|
449
|
+
customTools?: SessionCustomTools;
|
|
450
|
+
resultTool?: ToolDefinition;
|
|
451
|
+
systemPromptAppend?: string;
|
|
452
|
+
extensionFactories?: InlineExtension[];
|
|
453
|
+
resourcePolicy?: AgentResourcePolicy;
|
|
454
|
+
options?: AgentOptions;
|
|
455
|
+
}
|
|
456
|
+
export type SessionFactory = (input: SessionInput) => Promise<NativeSession>;
|
|
457
|
+
export interface AgentSetup {
|
|
458
|
+
prompt: string;
|
|
459
|
+
options: AgentOptions;
|
|
460
|
+
sessionInput: SessionInput;
|
|
461
|
+
createSession: SessionFactory;
|
|
462
|
+
}
|
|
463
|
+
export interface AgentSetupContext {
|
|
464
|
+
readonly run: Readonly<WorkflowRunContext>;
|
|
465
|
+
readonly identity: Readonly<AgentIdentity>;
|
|
466
|
+
readonly attempt: number;
|
|
467
|
+
readonly signal: AbortSignal;
|
|
468
|
+
}
|
|
469
|
+
export interface AgentSetupHook {
|
|
470
|
+
priority?: number;
|
|
471
|
+
setup: (agent: AgentSetup, context: Readonly<AgentSetupContext>) => void | Promise<void>;
|
|
472
|
+
}
|
|
473
|
+
export interface RegisteredAgentSetupHook {
|
|
474
|
+
name: string;
|
|
475
|
+
priority: number;
|
|
476
|
+
setup: AgentSetupHook["setup"];
|
|
477
|
+
}
|
|
478
|
+
export interface WorkflowExtensionMetadata {
|
|
479
|
+
version: string;
|
|
480
|
+
headline: string;
|
|
481
|
+
description: string;
|
|
482
|
+
}
|
|
483
|
+
export interface WorkflowRoleDirectoryRegistration {
|
|
484
|
+
path: string;
|
|
485
|
+
extension: WorkflowExtensionMetadata;
|
|
486
|
+
}
|
|
487
|
+
export interface WorkflowExtension extends WorkflowExtensionMetadata {
|
|
488
|
+
functions?: Readonly<Record<string, WorkflowFunction>>;
|
|
489
|
+
variables?: Readonly<Record<string, WorkflowVariable>>;
|
|
490
|
+
modelAliases?: Readonly<Record<string, WorkflowModelAlias>>;
|
|
491
|
+
agentSetupHooks?: Readonly<Record<string, AgentSetupHook>>;
|
|
492
|
+
roleDirectories?: readonly (string | URL)[];
|
|
493
|
+
}
|
|
494
|
+
export interface WorkflowJournal {
|
|
495
|
+
get(path: string): JsonValue | undefined;
|
|
496
|
+
put(path: string, value: JsonValue): void;
|
|
497
|
+
}
|
|
498
|
+
export declare class WorkflowError extends Error {
|
|
499
|
+
readonly code: WorkflowErrorCode;
|
|
500
|
+
constructor(code: WorkflowErrorCode, message: string);
|
|
501
|
+
}
|
|
502
|
+
export interface WorkflowFailureAgent {
|
|
503
|
+
id: string;
|
|
504
|
+
label?: string;
|
|
505
|
+
role?: string;
|
|
506
|
+
structuralPath: readonly string[];
|
|
507
|
+
attempt: number;
|
|
508
|
+
sessionId?: string;
|
|
509
|
+
sessionFile?: string;
|
|
510
|
+
}
|
|
511
|
+
export interface WorkflowSiblingAgent {
|
|
512
|
+
id: string;
|
|
513
|
+
label?: string;
|
|
514
|
+
role?: string;
|
|
515
|
+
structuralPath: readonly string[];
|
|
516
|
+
}
|
|
517
|
+
export interface WorkflowFailureDiagnostics {
|
|
518
|
+
runId: string;
|
|
519
|
+
workflowName: string;
|
|
520
|
+
state: RunState;
|
|
521
|
+
failedAt: string | null;
|
|
522
|
+
error: WorkflowErrorShape;
|
|
523
|
+
failedAgent?: WorkflowFailureAgent;
|
|
524
|
+
completedSiblingAgents?: readonly WorkflowSiblingAgent[];
|
|
525
|
+
completedSiblingPaths: readonly (readonly string[])[];
|
|
526
|
+
retry?: {
|
|
527
|
+
sourceRunId: string;
|
|
528
|
+
action: string;
|
|
529
|
+
completedPaths: readonly string[];
|
|
530
|
+
incompletePaths: readonly string[];
|
|
531
|
+
namedWorktrees: readonly string[];
|
|
532
|
+
warning: string;
|
|
533
|
+
};
|
|
534
|
+
artifacts: {
|
|
535
|
+
runDirectory: string;
|
|
536
|
+
statePath: string;
|
|
537
|
+
journalPath: string;
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
export interface CheckpointInput {
|
|
541
|
+
name: string;
|
|
542
|
+
prompt: string;
|
|
543
|
+
context: JsonValue;
|
|
544
|
+
}
|
|
545
|
+
export interface AgentIdentity {
|
|
546
|
+
structuralPath: readonly string[];
|
|
547
|
+
callSite: string;
|
|
548
|
+
occurrence: number;
|
|
549
|
+
parentBreadcrumb?: string;
|
|
550
|
+
worktreeOwner?: string;
|
|
551
|
+
}
|
|
552
|
+
export interface ShellIdentity {
|
|
553
|
+
structuralPath: readonly string[];
|
|
554
|
+
callSite: string;
|
|
555
|
+
occurrence: number;
|
|
556
|
+
worktreeOwner?: string;
|
|
557
|
+
}
|
|
558
|
+
export interface WorkflowBridge {
|
|
559
|
+
agent?: (prompt: string, options: Readonly<Record<string, JsonValue>>, signal: AbortSignal, identity: AgentIdentity) => Promise<JsonValue>;
|
|
560
|
+
shell?: (command: string, options: ShellOptions, signal: AbortSignal, identity: ShellIdentity) => Promise<ShellResult>;
|
|
561
|
+
checkpoint?: (input: Readonly<Record<string, JsonValue>>, signal: AbortSignal) => boolean | Promise<boolean>;
|
|
562
|
+
function?: (name: string, input: Readonly<Record<string, JsonValue>>, path: string, signal: AbortSignal, worktreeOwner?: string, structuralPath?: readonly string[]) => Promise<JsonValue>;
|
|
563
|
+
worktree?: (owner: string, signal: AbortSignal) => Promise<Readonly<WorkflowWorktreeReference>>;
|
|
564
|
+
functions?: Readonly<Record<string, {
|
|
565
|
+
name: string;
|
|
566
|
+
}>>;
|
|
567
|
+
variables?: Readonly<Record<string, JsonValue>>;
|
|
568
|
+
phase?: (name: string) => void | Promise<void>;
|
|
569
|
+
log?: (message: string) => void | Promise<void>;
|
|
570
|
+
}
|
|
571
|
+
export interface WorkflowExecution {
|
|
572
|
+
result: Promise<JsonValue>;
|
|
573
|
+
cancel: () => void;
|
|
574
|
+
}
|
|
575
|
+
export interface StaticWorkflowScope {
|
|
576
|
+
kind: "parallel" | "pipeline";
|
|
577
|
+
name: string | null;
|
|
578
|
+
key: string | null;
|
|
579
|
+
}
|
|
580
|
+
export type StaticWorkflowExecution = "parallel" | "sequential";
|
|
581
|
+
export interface StaticWorkflowCall {
|
|
582
|
+
kind: WorkflowCallKind;
|
|
583
|
+
start: number;
|
|
584
|
+
end: number;
|
|
585
|
+
name: string | null;
|
|
586
|
+
prompt: string | null;
|
|
587
|
+
model: string | null;
|
|
588
|
+
label?: string | null;
|
|
589
|
+
role: string | null;
|
|
590
|
+
retries?: number | null;
|
|
591
|
+
outputSchema?: JsonSchema | null;
|
|
592
|
+
options?: Readonly<Record<string, JsonValue>> | null;
|
|
593
|
+
optionKeys?: readonly string[];
|
|
594
|
+
execution?: StaticWorkflowExecution;
|
|
595
|
+
structure?: readonly StaticWorkflowScope[];
|
|
596
|
+
}
|
|
597
|
+
export interface WorkflowCatalogFunction {
|
|
598
|
+
name: string;
|
|
599
|
+
version: string;
|
|
600
|
+
headline: string;
|
|
601
|
+
extensionDescription: string;
|
|
602
|
+
description: string;
|
|
603
|
+
input: JsonSchema;
|
|
604
|
+
output: JsonSchema;
|
|
605
|
+
}
|
|
606
|
+
export interface WorkflowCatalogVariable {
|
|
607
|
+
name: string;
|
|
608
|
+
version: string;
|
|
609
|
+
headline: string;
|
|
610
|
+
extensionDescription: string;
|
|
611
|
+
description: string;
|
|
612
|
+
schema: JsonSchema;
|
|
613
|
+
}
|
|
614
|
+
export interface WorkflowCatalogModelAlias {
|
|
615
|
+
name: string;
|
|
616
|
+
kind: "static" | "dynamic";
|
|
617
|
+
provenance: string;
|
|
618
|
+
version?: string;
|
|
619
|
+
headline?: string;
|
|
620
|
+
extensionDescription?: string;
|
|
621
|
+
}
|
|
622
|
+
export interface WorkflowCatalogSettings {
|
|
623
|
+
concurrency: number;
|
|
624
|
+
modelAliases: Readonly<Record<string, string>>;
|
|
625
|
+
disabledAgentResources: AgentResourceExclusions;
|
|
626
|
+
globalSettingsPath: string;
|
|
627
|
+
projectSettingsPath: string;
|
|
628
|
+
projectTrusted: boolean;
|
|
629
|
+
sources: WorkflowSettingsSources;
|
|
630
|
+
}
|
|
631
|
+
export interface WorkflowCatalogContext {
|
|
632
|
+
cwd: string;
|
|
633
|
+
projectTrusted: boolean;
|
|
634
|
+
globalSettingsPath?: string;
|
|
635
|
+
}
|
|
636
|
+
export interface WorkflowCatalog {
|
|
637
|
+
functions: readonly WorkflowCatalogFunction[];
|
|
638
|
+
variables: readonly WorkflowCatalogVariable[];
|
|
639
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
640
|
+
modelAliasEntries?: readonly WorkflowCatalogModelAlias[];
|
|
641
|
+
settings?: WorkflowCatalogSettings;
|
|
642
|
+
}
|
|
643
|
+
export interface WorkflowCatalogIndexFunction {
|
|
644
|
+
name: string;
|
|
645
|
+
description: string;
|
|
646
|
+
input: JsonSchema;
|
|
647
|
+
}
|
|
648
|
+
export interface WorkflowCatalogIndexVariable {
|
|
649
|
+
name: string;
|
|
650
|
+
description: string;
|
|
651
|
+
schema: JsonSchema;
|
|
652
|
+
}
|
|
653
|
+
export interface WorkflowCatalogIndex {
|
|
654
|
+
functions: readonly WorkflowCatalogIndexFunction[];
|
|
655
|
+
variables: readonly WorkflowCatalogIndexVariable[];
|
|
656
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
657
|
+
modelAliasEntries?: readonly WorkflowCatalogModelAlias[];
|
|
658
|
+
settings?: WorkflowCatalogSettings;
|
|
659
|
+
}
|
|
660
|
+
export interface WorkflowCatalogError {
|
|
661
|
+
error: {
|
|
662
|
+
code: "NOT_FOUND";
|
|
663
|
+
name: string;
|
|
664
|
+
message: string;
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
export interface WorkflowValidationParameters {
|
|
668
|
+
name?: string;
|
|
669
|
+
description?: string;
|
|
670
|
+
script?: string;
|
|
671
|
+
workflow?: string;
|
|
672
|
+
args?: unknown;
|
|
673
|
+
}
|
|
674
|
+
export interface WorkflowValidationContext {
|
|
675
|
+
cwd: string;
|
|
676
|
+
projectTrusted: boolean;
|
|
677
|
+
availableModels: ReadonlySet<string>;
|
|
678
|
+
rootTools: ReadonlySet<string>;
|
|
679
|
+
modelAliases?: Readonly<Record<string, string>>;
|
|
680
|
+
knownModels?: ReadonlySet<string>;
|
|
681
|
+
settingsPath?: string;
|
|
682
|
+
agentDir?: string;
|
|
683
|
+
}
|
|
684
|
+
export interface ValidatedWorkflowLaunch {
|
|
685
|
+
script: string;
|
|
686
|
+
checked: PreflightResult;
|
|
687
|
+
agentDefinitions: Readonly<Record<string, AgentDefinition>>;
|
|
688
|
+
projectAgentDefinitions: Readonly<Record<string, AgentDefinition>>;
|
|
689
|
+
roleNames: readonly string[];
|
|
690
|
+
functionName?: string;
|
|
691
|
+
}
|
|
692
|
+
export {};
|