@@ -10,8 +10,8 @@ import { checkMcpHeader, McpPreflightError } from './cli/check-typescript.js';
1010import { buildMcpProxy , runMcpEffect } from './authored-mcp.js' ;
1111import { AuthoredBudget } from './authored-budget.js' ;
1212import { assertMemoryReachable , authoredMemory , scriptMemoryScope } from './authored-memory.js' ;
13- import { authoredWorkerRunner } from './authored-worker-step.js' ;
14- import { readSuccessfulOutput , isSurfaceRunCompletionReason } from './authored-step-output.js' ;
13+ import { authoredDeterministicRunner , authoredWorkerRunner } from './authored-worker-step.js' ;
14+ import { isSurfaceRunCompletionReason } from './authored-step-output.js' ;
1515import {
1616 type LlmOptions ,
1717 type CloudHelper ,
@@ -23,7 +23,7 @@ import {
2323import type { FlowHandle } from '@relayflows/surface/runtime' ;
2424import { join } from 'node:path' ;
2525import { observeStep , type ProgressEvent } from './progress.js' ;
26- import { compileSpec , toKernelSpec } from './compile.js' ;
26+ import { parseStepTimeout } from './compile.js' ;
2727import { getAuthoredFlowDefinition } from './authored-flow.js' ;
2828import type { GetFlowDefinition } from './authored-flow-loader.js' ;
2929import type { RunLifecycleOptions } from './cli/run.js' ;
@@ -42,7 +42,6 @@ import type {
4242 CompletionReason as ProtocolCompletionReason ,
4343 RunCompletionReason as ProtocolRunCompletionReason ,
4444} from './protocol.js' ;
45- import { SPEC_SCHEMA_VERSION } from './spec.js' ;
4645
4746type Assert < T extends true > = T ;
4847type Equal < A , B > = [ A ] extends [ B ]
@@ -169,19 +168,7 @@ export async function executeAuthoredFlow<Input = undefined>(
169168 let nextStep = 1 ;
170169 let requestedCompletion : SurfaceRunCompletionReason | undefined ;
171170
172- const lowerDeterministic = async (
173- id : string ,
174- command : string ,
175- terminal = false ,
176- ) : Promise < string > => {
177- const spec = toKernelSpec ( compileSpec ( {
178- version : SPEC_SCHEMA_VERSION ,
179- name : `${ definition . name } /${ id } ` ,
180- steps : [ { id, type : 'deterministic' , command } ] ,
181- } ) ) ;
182- if ( terminal ) return readSuccessfulOutput ( journal , await journal . runStart ( spec ) , id , journalSteps ) ;
183- return budget . execute ( journal , spec , outcome => readSuccessfulOutput ( journal , outcome , id , journalSteps ) ) ;
184- } ;
171+ const lowerDeterministic = authoredDeterministicRunner ( definition . name , journal , journalSteps , budget ) ;
185172
186173 const worker = authoredWorkerRunner ( definition , journal , flowPath , journalSteps , waitOptions , localAgentStream , budget , definition . header . budget ) ;
187174
@@ -248,14 +235,15 @@ export async function executeAuthoredFlow<Input = undefined>(
248235 ( ) => assertOperationAllowed ( 'memory' , definition . name , requestedCompletion ) ,
249236 definition . header . memory ?. script !== false ,
250237 ) ,
251- run ( command ) {
238+ run ( command , runOptions ) {
252239 assertOperationAllowed ( 'run' , definition . name , requestedCompletion ) ;
240+ const leaseMs = runOptions ?. timeout === undefined ? undefined : parseStepTimeout ( runOptions . timeout ) ;
253241 const id = `run-${ nextStep ++ } ` ;
254242 return trackStep ( authoredSteps , new AuthoredFlowOperation (
255243 id ,
256244 'run' ,
257245 ( ) => assertOperationAllowed ( 'run' , definition . name , requestedCompletion ) ,
258- ( ) => observeStep ( id , 'deterministic' , ( ) => lowerDeterministic ( id , command ) , options . onProgress ) ,
246+ ( ) => observeStep ( id , 'deterministic' , ( ) => lowerDeterministic ( id , command , false , leaseMs ) , options . onProgress ) ,
259247 lifecycle ,
260248 ) ) ;
261249 } ,
0 commit comments