pi-agent-flow 1.1.0 → 1.2.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 +158 -44
- package/agents/audit.md +37 -17
- package/agents/build.md +42 -38
- package/agents/craft.md +33 -17
- package/agents/debug.md +32 -15
- package/agents/ideas.md +33 -11
- package/agents/scout.md +32 -12
- package/package.json +4 -15
- package/{agents.ts → src/agents.ts} +10 -4
- package/src/ambient.d.ts +85 -0
- package/{batch.ts → src/batch.ts} +256 -118
- package/src/cli-args.ts +283 -0
- package/src/config.ts +305 -0
- package/{flow.ts → src/flow.ts} +39 -18
- package/{hooks.ts → src/hooks.ts} +6 -6
- package/{index.ts → src/index.ts} +361 -102
- package/{render-utils.ts → src/render-utils.ts} +2 -2
- package/{render.ts → src/render.ts} +15 -10
- package/src/runner-events.ts +692 -0
- package/{types.ts → src/types.ts} +2 -0
- package/config.ts +0 -102
- package/runner-cli.js +0 -254
- package/runner-events.js +0 -559
- /package/{web-tool.ts → src/web-tool.ts} +0 -0
package/{flow.ts → src/flow.ts}
RENAMED
|
@@ -10,8 +10,8 @@ import * as fs from "node:fs";
|
|
|
10
10
|
import * as os from "node:os";
|
|
11
11
|
import * as path from "node:path";
|
|
12
12
|
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
|
13
|
-
import { type FlowConfig
|
|
14
|
-
import { parseFlowCliArgs } from "./
|
|
13
|
+
import { type FlowConfig } from "./agents.js";
|
|
14
|
+
import { parseFlowCliArgs } from "./cli-args.js";
|
|
15
15
|
import { processFlowJsonLine, drainStreamingText, drainStreamingEstimate, drainCtxEstimate, updateSmoothedTps, drainSmoothedTps } from "./runner-events.js";
|
|
16
16
|
import {
|
|
17
17
|
type SingleResult,
|
|
@@ -52,8 +52,8 @@ function mergeStreamingUsage(
|
|
|
52
52
|
...actual,
|
|
53
53
|
...(estimatedOutputTokens > 0 ? { output: Math.max(actual.output, estimatedOutputTokens) } : {}),
|
|
54
54
|
...(ctxEstimate > 0 ? { contextTokens: Math.max(actual.contextTokens, ctxEstimate) } : {}),
|
|
55
|
-
//
|
|
56
|
-
...(smoothedTps > 0 ? { smoothedTps
|
|
55
|
+
// Show the live EMA value so the dashboard can rise and fall smoothly.
|
|
56
|
+
...(smoothedTps > 0 ? { smoothedTps } : {}),
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -117,7 +117,7 @@ export function getOptimizedTools(
|
|
|
117
117
|
);
|
|
118
118
|
if (!hasLegacyTools) return flowTools;
|
|
119
119
|
const filtered = flowTools.filter(
|
|
120
|
-
(t) => t !== "read" && t !== "write" && t !== "edit" && t !== "batch",
|
|
120
|
+
(t) => t !== "read" && t !== "write" && t !== "edit" && t !== "batch" && t !== "batch_read",
|
|
121
121
|
);
|
|
122
122
|
return filtered.includes("batch")
|
|
123
123
|
? filtered
|
|
@@ -128,7 +128,7 @@ function buildFlowArgs(
|
|
|
128
128
|
flow: FlowConfig,
|
|
129
129
|
intent: string,
|
|
130
130
|
forkSessionPath: string | null,
|
|
131
|
-
|
|
131
|
+
model?: string,
|
|
132
132
|
parentDepth: number = 0,
|
|
133
133
|
maxDepth: number = 0,
|
|
134
134
|
toolOptimize: boolean = false,
|
|
@@ -145,10 +145,21 @@ function buildFlowArgs(
|
|
|
145
145
|
args.push("--session", forkSessionPath);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
148
|
+
if (inheritedCliArgs.flowModelConfig) {
|
|
149
|
+
args.push("--flow-model-config", inheritedCliArgs.flowModelConfig);
|
|
150
|
+
}
|
|
151
|
+
if (inheritedCliArgs.tieredModels?.lite) {
|
|
152
|
+
args.push("--flow-lite-model", inheritedCliArgs.tieredModels.lite);
|
|
153
|
+
}
|
|
154
|
+
if (inheritedCliArgs.tieredModels?.flash) {
|
|
155
|
+
args.push("--flow-flash-model", inheritedCliArgs.tieredModels.flash);
|
|
156
|
+
}
|
|
157
|
+
if (inheritedCliArgs.tieredModels?.full) {
|
|
158
|
+
args.push("--flow-full-model", inheritedCliArgs.tieredModels.full);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const resolvedModel = model ?? flow.model ?? inheritedCliArgs.fallbackModel;
|
|
162
|
+
if (resolvedModel) args.push("--model", resolvedModel);
|
|
152
163
|
|
|
153
164
|
const thinking = flow.thinking ?? inheritedCliArgs.fallbackThinking;
|
|
154
165
|
if (thinking) args.push("--thinking", thinking);
|
|
@@ -245,8 +256,8 @@ export interface RunFlowOptions {
|
|
|
245
256
|
preventCycles: boolean;
|
|
246
257
|
/** Whether to transform tool lists to use batch. */
|
|
247
258
|
toolOptimize?: boolean;
|
|
248
|
-
/**
|
|
249
|
-
|
|
259
|
+
/** Explicit model to use for this flow execution. */
|
|
260
|
+
model?: string;
|
|
250
261
|
/** Abort signal for cancellation. */
|
|
251
262
|
signal?: AbortSignal;
|
|
252
263
|
/** Streaming update callback. */
|
|
@@ -276,6 +287,7 @@ export async function runFlow(opts: RunFlowOptions): Promise<SingleResult> {
|
|
|
276
287
|
maxDepth,
|
|
277
288
|
preventCycles,
|
|
278
289
|
toolOptimize = false,
|
|
290
|
+
model,
|
|
279
291
|
signal,
|
|
280
292
|
onUpdate,
|
|
281
293
|
makeDetails,
|
|
@@ -297,7 +309,7 @@ export async function runFlow(opts: RunFlowOptions): Promise<SingleResult> {
|
|
|
297
309
|
};
|
|
298
310
|
}
|
|
299
311
|
|
|
300
|
-
const resolvedModel = flow.model ?? inheritedCliArgs.fallbackModel;
|
|
312
|
+
const resolvedModel = model ?? flow.model ?? inheritedCliArgs.fallbackModel;
|
|
301
313
|
const result: SingleResult = {
|
|
302
314
|
type: normalizedFlowName,
|
|
303
315
|
agentSource: flow.source,
|
|
@@ -310,21 +322,30 @@ export async function runFlow(opts: RunFlowOptions): Promise<SingleResult> {
|
|
|
310
322
|
model: resolvedModel,
|
|
311
323
|
};
|
|
312
324
|
|
|
325
|
+
let liveStreamingText = "";
|
|
326
|
+
let liveEstimatedOutputTokens = 0;
|
|
327
|
+
let lastActualOutputTokens = result.usage.output;
|
|
313
328
|
const emitUpdate = () => {
|
|
314
|
-
const
|
|
329
|
+
const streamingDelta = drainStreamingText(result);
|
|
330
|
+
if (streamingDelta) liveStreamingText += streamingDelta;
|
|
315
331
|
const estimatedTokens = drainStreamingEstimate(result);
|
|
332
|
+
if (result.usage.output !== lastActualOutputTokens) {
|
|
333
|
+
lastActualOutputTokens = result.usage.output;
|
|
334
|
+
liveEstimatedOutputTokens = result.usage.output;
|
|
335
|
+
}
|
|
336
|
+
liveEstimatedOutputTokens += estimatedTokens;
|
|
316
337
|
const ctxEst = drainCtxEstimate(result);
|
|
317
338
|
updateSmoothedTps(result, estimatedTokens);
|
|
318
339
|
const smoothedTps = drainSmoothedTps(result);
|
|
319
|
-
const mergedUsage = mergeStreamingUsage(result.usage,
|
|
340
|
+
const mergedUsage = mergeStreamingUsage(result.usage, liveEstimatedOutputTokens, ctxEst, smoothedTps);
|
|
320
341
|
onUpdate?.({
|
|
321
342
|
content: [
|
|
322
343
|
{
|
|
323
344
|
type: "text",
|
|
324
|
-
text:
|
|
345
|
+
text: liveStreamingText || getFlowOutput(result.messages) || "(running...)",
|
|
325
346
|
},
|
|
326
347
|
],
|
|
327
|
-
details: makeDetails([{ ...result, usage: mergedUsage }]),
|
|
348
|
+
details: makeDetails([{ ...result, usage: mergedUsage, streamingText: liveStreamingText || undefined }]),
|
|
328
349
|
});
|
|
329
350
|
};
|
|
330
351
|
|
|
@@ -342,7 +363,7 @@ export async function runFlow(opts: RunFlowOptions): Promise<SingleResult> {
|
|
|
342
363
|
flow,
|
|
343
364
|
intent,
|
|
344
365
|
forkSessionTmpPath,
|
|
345
|
-
|
|
366
|
+
model,
|
|
346
367
|
parentDepth,
|
|
347
368
|
maxDepth,
|
|
348
369
|
toolOptimize,
|
|
@@ -104,19 +104,19 @@ registerHook({
|
|
|
104
104
|
},
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
/** Suggest
|
|
107
|
+
/** Suggest scout flow after a successful audit flow. */
|
|
108
108
|
registerHook({
|
|
109
|
-
name: "pi-agent-flow/audit-to-
|
|
109
|
+
name: "pi-agent-flow/audit-to-scout",
|
|
110
110
|
trigger: { flowTypes: ["audit"], onlyOnSuccess: true },
|
|
111
111
|
action: (ctx) => {
|
|
112
|
-
const
|
|
113
|
-
(p) => p.type.toLowerCase() === "
|
|
112
|
+
const scoutWasRequested = ctx.params.some(
|
|
113
|
+
(p) => p.type.toLowerCase() === "scout",
|
|
114
114
|
);
|
|
115
|
-
if (
|
|
115
|
+
if (scoutWasRequested) return null;
|
|
116
116
|
|
|
117
117
|
return {
|
|
118
118
|
content:
|
|
119
|
-
"Audit complete. Consider running
|
|
119
|
+
"Audit complete. Consider running a [scout] flow to trace the audit findings across the codebase.",
|
|
120
120
|
priority: 15,
|
|
121
121
|
};
|
|
122
122
|
},
|