pi-extensible-workflows 0.3.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 +72 -0
- package/dist/src/agent-execution.d.ts +213 -0
- package/dist/src/agent-execution.js +537 -0
- package/dist/src/ambient-workflow-evals.d.ts +112 -0
- package/dist/src/ambient-workflow-evals.js +375 -0
- package/dist/src/cli.d.ts +6 -0
- package/dist/src/cli.js +26 -0
- package/dist/src/doctor.d.ts +59 -0
- package/dist/src/doctor.js +269 -0
- package/dist/src/eval-capture-extension.d.ts +5 -0
- package/dist/src/eval-capture-extension.js +48 -0
- package/dist/src/index.d.ts +362 -0
- package/dist/src/index.js +2839 -0
- package/dist/src/persistence.d.ts +90 -0
- package/dist/src/persistence.js +530 -0
- package/dist/src/session-inspector.d.ts +59 -0
- package/dist/src/session-inspector.js +396 -0
- package/dist/src/workflow-evals-child.d.ts +1 -0
- package/dist/src/workflow-evals-child.js +13 -0
- package/dist/src/workflow-evals.d.ts +290 -0
- package/dist/src/workflow-evals.js +1221 -0
- package/evals/cases/custom-model-read.yaml +15 -0
- package/evals/cases/direct-answer.yaml +6 -0
- package/evals/cases/mixed-parallel-pipeline.yaml +18 -0
- package/evals/cases/output-schema.yaml +22 -0
- package/evals/cases/parallel.yaml +15 -0
- package/evals/cases/pipeline.yaml +10 -0
- package/evals/cases/ready-for-agent-parallel-merge.yaml +32 -0
- package/evals/cases/required-role.yaml +14 -0
- package/evals/cases/role-model-mixed.yaml +18 -0
- package/evals/cases/two-agents.yaml +10 -0
- package/package.json +65 -0
- package/skills/pi-extensible-workflows/SKILL.md +109 -0
- package/src/agent-execution.ts +529 -0
- package/src/ambient-workflow-evals.ts +452 -0
- package/src/cli.ts +23 -0
- package/src/doctor.ts +285 -0
- package/src/eval-capture-extension.ts +54 -0
- package/src/index.ts +2519 -0
- package/src/persistence.ts +470 -0
- package/src/session-inspector.ts +370 -0
- package/src/workflow-evals-child.ts +15 -0
- package/src/workflow-evals.ts +876 -0
- package/test/fixtures/ready-for-agent-tasks.md +9 -0
- package/test/fixtures/workflow-eval-roles/developer.md +18 -0
- package/test/fixtures/workflow-eval-roles/reviewer.md +18 -0
- package/test/fixtures/workflow-eval-roles/scout.md +17 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
export { resolveWorkflowSkillPath } from "./eval-capture-extension.js";
|
|
2
|
+
import { type AgentIdentity, type JsonSchema, type JsonValue, type StaticWorkflowCall, type StaticWorkflowExecution, type WorkflowErrorCode } from "./index.js";
|
|
3
|
+
export type SignificantAction = {
|
|
4
|
+
kind: "tool";
|
|
5
|
+
name: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "text";
|
|
8
|
+
} | {
|
|
9
|
+
kind: "thinking";
|
|
10
|
+
};
|
|
11
|
+
export type SequenceExpectation = readonly string[] | {
|
|
12
|
+
equals?: readonly string[];
|
|
13
|
+
startsWith?: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
export type JsonResultType = "null" | "boolean" | "number" | "integer" | "string" | "array" | "object";
|
|
16
|
+
export interface JsonResultShape {
|
|
17
|
+
type?: JsonResultType;
|
|
18
|
+
equals?: JsonValue;
|
|
19
|
+
nonEmpty?: boolean;
|
|
20
|
+
requiredKeys?: readonly string[];
|
|
21
|
+
propertyTypes?: Readonly<Record<string, JsonResultType>>;
|
|
22
|
+
forbiddenProperties?: readonly string[];
|
|
23
|
+
count?: number;
|
|
24
|
+
minCount?: number;
|
|
25
|
+
properties?: Readonly<Record<string, JsonResultShape>>;
|
|
26
|
+
}
|
|
27
|
+
export interface ExpectedReplayResult {
|
|
28
|
+
workflowIndex?: number;
|
|
29
|
+
equals?: JsonValue;
|
|
30
|
+
match?: JsonResultShape;
|
|
31
|
+
}
|
|
32
|
+
export interface OutputSchemaShape {
|
|
33
|
+
type?: string;
|
|
34
|
+
requiredKeys?: readonly string[];
|
|
35
|
+
propertyTypes?: Readonly<Record<string, string>>;
|
|
36
|
+
forbiddenProperties?: readonly string[];
|
|
37
|
+
count?: number;
|
|
38
|
+
minCount?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface AgentPolicyExpectation {
|
|
41
|
+
callIndex: number;
|
|
42
|
+
role?: string;
|
|
43
|
+
model?: string;
|
|
44
|
+
forbidOptions?: readonly ("role" | "model" | "thinking" | "tools" | "retries")[];
|
|
45
|
+
tools?: {
|
|
46
|
+
mode: "omitted" | "empty" | "exact";
|
|
47
|
+
values?: readonly string[];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface AgentStructureExpectation {
|
|
51
|
+
execution: StaticWorkflowExecution;
|
|
52
|
+
operation?: "parallel" | "pipeline";
|
|
53
|
+
agents: readonly AgentOrderExpectation[];
|
|
54
|
+
}
|
|
55
|
+
export interface AgentOrderExpectation {
|
|
56
|
+
role?: string;
|
|
57
|
+
model?: string;
|
|
58
|
+
promptIncludes?: string;
|
|
59
|
+
execution?: StaticWorkflowExecution;
|
|
60
|
+
}
|
|
61
|
+
export interface DataFlowExpectation {
|
|
62
|
+
binding: string;
|
|
63
|
+
toAgentIndex: number;
|
|
64
|
+
}
|
|
65
|
+
export interface ParentAssistantBatch {
|
|
66
|
+
index: number;
|
|
67
|
+
parts: readonly JsonValue[];
|
|
68
|
+
tools: readonly string[];
|
|
69
|
+
usage?: ParentUsage;
|
|
70
|
+
}
|
|
71
|
+
export interface ParentToolResult {
|
|
72
|
+
toolCallId?: string;
|
|
73
|
+
details?: JsonValue;
|
|
74
|
+
isError?: boolean;
|
|
75
|
+
text?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ParentUsage {
|
|
78
|
+
input: number;
|
|
79
|
+
output: number;
|
|
80
|
+
cacheRead: number;
|
|
81
|
+
cacheWrite: number;
|
|
82
|
+
totalTokens: number;
|
|
83
|
+
cost: number;
|
|
84
|
+
models: readonly {
|
|
85
|
+
model: string;
|
|
86
|
+
cost: number;
|
|
87
|
+
}[];
|
|
88
|
+
}
|
|
89
|
+
export interface ParentOracle {
|
|
90
|
+
assistantBatches: readonly ParentAssistantBatch[];
|
|
91
|
+
workflowToolResults: readonly ParentToolResult[];
|
|
92
|
+
skillReads: readonly string[];
|
|
93
|
+
firstSignificantAction?: SignificantAction;
|
|
94
|
+
firstTool?: string;
|
|
95
|
+
firstBatchToolSequence: readonly string[];
|
|
96
|
+
toolsBeforeFirstWorkflow: readonly string[];
|
|
97
|
+
firstWorkflowBatchToolSequence: readonly string[];
|
|
98
|
+
parentToolSequence: readonly string[];
|
|
99
|
+
workflowCallCount: number;
|
|
100
|
+
usage: ParentUsage;
|
|
101
|
+
}
|
|
102
|
+
export interface CapturedWorkflowCall {
|
|
103
|
+
batch: number;
|
|
104
|
+
toolCallId?: string;
|
|
105
|
+
arguments: JsonValue;
|
|
106
|
+
script?: string;
|
|
107
|
+
}
|
|
108
|
+
export interface EvalExpectations {
|
|
109
|
+
firstSignificantAction?: SignificantAction;
|
|
110
|
+
firstTool?: string;
|
|
111
|
+
firstBatchToolSequence?: SequenceExpectation;
|
|
112
|
+
parentToolSequence?: SequenceExpectation;
|
|
113
|
+
workflowCallCount?: number | {
|
|
114
|
+
min?: number;
|
|
115
|
+
max?: number;
|
|
116
|
+
};
|
|
117
|
+
requiredOperations?: readonly StaticWorkflowCall["kind"][];
|
|
118
|
+
forbiddenOperations?: readonly StaticWorkflowCall["kind"][];
|
|
119
|
+
requiredRoles?: readonly string[];
|
|
120
|
+
minimumAgentCalls?: number;
|
|
121
|
+
requireOutputSchema?: OutputSchemaShape | boolean;
|
|
122
|
+
expectedResults?: readonly ExpectedReplayResult[];
|
|
123
|
+
agentPolicies?: readonly AgentPolicyExpectation[];
|
|
124
|
+
requiredAgentOrder?: readonly AgentOrderExpectation[];
|
|
125
|
+
requiredAgentStructures?: readonly AgentStructureExpectation[];
|
|
126
|
+
requiredDataFlow?: readonly DataFlowExpectation[];
|
|
127
|
+
}
|
|
128
|
+
export interface SemanticCriterion {
|
|
129
|
+
id: string;
|
|
130
|
+
description: string;
|
|
131
|
+
}
|
|
132
|
+
export interface WorkflowEvalCase {
|
|
133
|
+
id: string;
|
|
134
|
+
prompt: string;
|
|
135
|
+
timeoutMs?: number;
|
|
136
|
+
maxCost: number;
|
|
137
|
+
expectations: EvalExpectations;
|
|
138
|
+
expectedWorkflowCalls?: number;
|
|
139
|
+
semanticCriteria?: readonly SemanticCriterion[];
|
|
140
|
+
}
|
|
141
|
+
export interface ReplayAgentCall {
|
|
142
|
+
prompt: string;
|
|
143
|
+
options: Readonly<Record<string, JsonValue>>;
|
|
144
|
+
identity: AgentIdentity;
|
|
145
|
+
}
|
|
146
|
+
export interface ReplayTrace {
|
|
147
|
+
agentCalls: readonly ReplayAgentCall[];
|
|
148
|
+
phases: readonly string[];
|
|
149
|
+
logs: readonly string[];
|
|
150
|
+
maxConcurrentAgents: number;
|
|
151
|
+
}
|
|
152
|
+
export interface ReplayReport {
|
|
153
|
+
script: string;
|
|
154
|
+
result?: JsonValue;
|
|
155
|
+
trace?: ReplayTrace;
|
|
156
|
+
error?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface ProductionValidationReport {
|
|
159
|
+
callIndex: number;
|
|
160
|
+
valid: boolean;
|
|
161
|
+
errorCode?: WorkflowErrorCode;
|
|
162
|
+
message?: string;
|
|
163
|
+
}
|
|
164
|
+
export interface CriterionResult {
|
|
165
|
+
id: string;
|
|
166
|
+
pass: boolean;
|
|
167
|
+
evidence: string;
|
|
168
|
+
}
|
|
169
|
+
export interface StaticCandidateReport {
|
|
170
|
+
callIndices: readonly number[];
|
|
171
|
+
criteria: readonly CriterionResult[];
|
|
172
|
+
passed: boolean;
|
|
173
|
+
}
|
|
174
|
+
export interface SemanticJudgeReport {
|
|
175
|
+
criteria: readonly CriterionResult[];
|
|
176
|
+
usage: ParentUsage;
|
|
177
|
+
raw: string;
|
|
178
|
+
}
|
|
179
|
+
export type EvalAccounting = ParentUsage;
|
|
180
|
+
export interface EvalMetrics {
|
|
181
|
+
parentUsageThroughCandidate: ParentUsage | null;
|
|
182
|
+
parentOutputTokensThroughCandidate: number | null;
|
|
183
|
+
nonWorkflowToolSequenceBeforeCandidate: readonly string[];
|
|
184
|
+
nonWorkflowToolCallCountBeforeCandidate: number;
|
|
185
|
+
workflowCallCountBeforeCandidate: number;
|
|
186
|
+
invalidWorkflowCallCount: number;
|
|
187
|
+
productionValidationErrorCodes: readonly string[];
|
|
188
|
+
candidateCallIndices: readonly number[];
|
|
189
|
+
staticCandidates: readonly StaticCandidateReport[];
|
|
190
|
+
semanticCriteria: readonly CriterionResult[];
|
|
191
|
+
anyValidCandidate: boolean;
|
|
192
|
+
requiredWorkflowCallCount: number;
|
|
193
|
+
surplusWorkflowCallCount: number;
|
|
194
|
+
}
|
|
195
|
+
export interface EvalCaseResult {
|
|
196
|
+
id: string;
|
|
197
|
+
status: "passed" | "failed" | "timed_out" | "budget_exceeded" | "skipped";
|
|
198
|
+
limits: {
|
|
199
|
+
timeoutMs?: number;
|
|
200
|
+
maxCost: number;
|
|
201
|
+
};
|
|
202
|
+
oracle?: ParentOracle;
|
|
203
|
+
workflows: readonly CapturedWorkflowCall[];
|
|
204
|
+
productionValidation: readonly ProductionValidationReport[];
|
|
205
|
+
semanticJudge?: SemanticJudgeReport;
|
|
206
|
+
metrics: EvalMetrics;
|
|
207
|
+
accounting: EvalAccounting;
|
|
208
|
+
accountingTrustworthy: boolean;
|
|
209
|
+
diagnostics: readonly string[];
|
|
210
|
+
errors: readonly string[];
|
|
211
|
+
cleanup: {
|
|
212
|
+
processExited: boolean;
|
|
213
|
+
processGroupTerminated: boolean;
|
|
214
|
+
tempRootRemoved: boolean;
|
|
215
|
+
captureIdentityVerified: boolean;
|
|
216
|
+
realWorkflowAgentsLaunched: number | null;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export declare const SAFE_PARENT_EVAL_TOOLS: readonly ["read", "grep", "find", "bash", "workflow"];
|
|
220
|
+
export declare function validateWorkflowEvalCases(values: readonly unknown[], source?: string): readonly WorkflowEvalCase[];
|
|
221
|
+
export declare function loadWorkflowEvalCases(directory?: string): readonly WorkflowEvalCase[];
|
|
222
|
+
export declare const INITIAL_WORKFLOW_EVAL_CASES: readonly WorkflowEvalCase[];
|
|
223
|
+
export declare function matchesJsonResult(shape: JsonResultShape, value: JsonValue): boolean;
|
|
224
|
+
export declare function matchesOutputSchema(shape: OutputSchemaShape, schema: JsonSchema): boolean;
|
|
225
|
+
export declare function extractParentOracle(entries: readonly unknown[]): ParentOracle;
|
|
226
|
+
export declare function extractParentOracleFile(path: string): ParentOracle;
|
|
227
|
+
export declare function extractCapturedWorkflows(oracle: ParentOracle): CapturedWorkflowCall[];
|
|
228
|
+
export declare function captureValidationReports(oracle: ParentOracle, calls: readonly CapturedWorkflowCall[]): {
|
|
229
|
+
reports: ProductionValidationReport[];
|
|
230
|
+
errors: string[];
|
|
231
|
+
verified: boolean;
|
|
232
|
+
};
|
|
233
|
+
export declare function evalExpectationErrors(oracle: ParentOracle, expectations: EvalExpectations): string[];
|
|
234
|
+
export declare function replayExpectationErrors(calls: readonly CapturedWorkflowCall[], reports: readonly ReplayReport[], expectations: EvalExpectations): string[];
|
|
235
|
+
export declare function staticExpectationResults(calls: readonly CapturedWorkflowCall[], expectations: EvalExpectations): CriterionResult[];
|
|
236
|
+
export declare function selectStaticCandidate(calls: readonly CapturedWorkflowCall[], validations: readonly ProductionValidationReport[], expectations: EvalExpectations, requiredCount?: number): {
|
|
237
|
+
callIndices: readonly number[];
|
|
238
|
+
reports: readonly StaticCandidateReport[];
|
|
239
|
+
};
|
|
240
|
+
export declare function assertEvalScriptSafe(script: string): void;
|
|
241
|
+
export declare function matchesJsonSchema(schema: JsonSchema, value: JsonValue): boolean;
|
|
242
|
+
export declare function replayWorkflowScript(script: string, args?: JsonValue, signal?: AbortSignal): Promise<{
|
|
243
|
+
result: JsonValue;
|
|
244
|
+
trace: ReplayTrace;
|
|
245
|
+
}>;
|
|
246
|
+
export interface CaptureCaseInput {
|
|
247
|
+
case: WorkflowEvalCase;
|
|
248
|
+
model: string;
|
|
249
|
+
provider?: string;
|
|
250
|
+
thinking?: string;
|
|
251
|
+
piCommand?: string;
|
|
252
|
+
maxCost: number;
|
|
253
|
+
}
|
|
254
|
+
export declare function parseSemanticJudge(raw: string, criteria: readonly SemanticCriterion[]): CriterionResult[];
|
|
255
|
+
export declare function captureEvalCase(input: CaptureCaseInput): Promise<EvalCaseResult>;
|
|
256
|
+
export interface IsolatedProcessOptions {
|
|
257
|
+
childPath: string;
|
|
258
|
+
timeoutMs?: number;
|
|
259
|
+
env?: NodeJS.ProcessEnv;
|
|
260
|
+
onStderr?: (chunk: string) => void;
|
|
261
|
+
}
|
|
262
|
+
export interface IsolatedProcessResult<T> {
|
|
263
|
+
value?: T;
|
|
264
|
+
timedOut: boolean;
|
|
265
|
+
exitCode: number | null;
|
|
266
|
+
processGroupTerminated: boolean;
|
|
267
|
+
stderr: string;
|
|
268
|
+
error?: string;
|
|
269
|
+
}
|
|
270
|
+
export declare function runIsolatedProcess<T>(payload: unknown, options: IsolatedProcessOptions): Promise<IsolatedProcessResult<T>>;
|
|
271
|
+
export interface WorkflowEvalRunOptions {
|
|
272
|
+
cases?: readonly WorkflowEvalCase[];
|
|
273
|
+
caseIds?: readonly string[];
|
|
274
|
+
model?: string;
|
|
275
|
+
provider?: string;
|
|
276
|
+
thinking?: string;
|
|
277
|
+
piCommand?: string;
|
|
278
|
+
timeoutMs?: number;
|
|
279
|
+
spendCeiling?: number;
|
|
280
|
+
artifactsDir?: string;
|
|
281
|
+
onProgress?: (message: string) => void;
|
|
282
|
+
}
|
|
283
|
+
export interface WorkflowEvalRunResult {
|
|
284
|
+
artifactDir: string;
|
|
285
|
+
cases: readonly EvalCaseResult[];
|
|
286
|
+
spent: number;
|
|
287
|
+
skipped: readonly string[];
|
|
288
|
+
}
|
|
289
|
+
export declare function runWorkflowEvals(options?: WorkflowEvalRunOptions): Promise<WorkflowEvalRunResult>;
|
|
290
|
+
export declare function formatEvalSummary(result: WorkflowEvalRunResult): string;
|