11import type { ReplayScriptSourceBundle } from '@agent-device/contracts/replay' ;
22import type { MaestroSourceReader } from '@agent-device/maestro' ;
33import type { DaemonRequest } from '../../daemon/types.ts' ;
4- import { buildReplayScriptSourceBundle } from '../../replay/script-source-bundle.ts' ;
4+ import {
5+ loadReplayScriptSourceBundle ,
6+ readAdScriptSourceBundle ,
7+ } from '../../replay/script-source-bundle.ts' ;
58import { discoverReplaySourcePaths } from '../../replay/source-discovery.ts' ;
69
710/**
8- * Builds a replay script source bundle from a file on disk the way a real
9- * caller does (#1802) — through the client's own builder, so a test never
10- * hand-rolls a bundle shape the CLI would not actually send.
11+ * A native `.ad` script's bundle, built from a file on disk through the client's own reader
12+ * (#1802) so a test never hand-rolls a shape the CLI would not actually send. Synchronous
13+ * because an `.ad` script has no include grammar and needs no engine; use
14+ * `maestroScriptSourceBundleFor` for a flow.
1115 */
12- export function replayScriptSourceBundleFor (
16+ export function replayScriptSourceBundleFor ( filePath : string ) : ReplayScriptSourceBundle {
17+ return readAdScriptSourceBundle ( { inputPath : filePath , cwd : process . cwd ( ) } ) ;
18+ }
19+
20+ /** A Maestro flow's bundle — async because the engine that walks its includes loads on demand. */
21+ export async function maestroScriptSourceBundleFor (
1322 filePath : string ,
14- options : { replayBackend ?: string } = { } ,
15- ) : ReplayScriptSourceBundle {
16- return buildReplayScriptSourceBundle ( {
23+ ) : Promise < ReplayScriptSourceBundle > {
24+ return await loadReplayScriptSourceBundle ( {
1725 inputPath : filePath ,
1826 cwd : process . cwd ( ) ,
19- replayBackend : options . replayBackend ,
27+ replayBackend : 'maestro' ,
2028 } ) ;
2129}
2230
@@ -41,7 +49,7 @@ export const noMaestroIncludeSources: MaestroSourceReader = (resolvedPath) => {
4149 * the CLI boundary (pinned in `cli-client-commands.test.ts`), and a daemon-level harness must
4250 * still deliver the request so the daemon's own response is what the case observes.
4351 */
44- export function withClientReplayScriptSources ( req : DaemonRequest ) : DaemonRequest {
52+ export async function withClientReplayScriptSources ( req : DaemonRequest ) : Promise < DaemonRequest > {
4553 if ( req . command !== 'replay' && req . command !== 'test' ) return req ;
4654 const inputs = req . positionals ?? [ ] ;
4755 const entryPath = inputs [ 0 ] ;
@@ -52,7 +60,7 @@ export function withClientReplayScriptSources(req: DaemonRequest): DaemonRequest
5260 if ( req . command === 'replay' ) {
5361 if ( req . flags ?. replayScriptSource ) return req ;
5462 return withFlags ( req , {
55- replayScriptSource : buildReplayScriptSourceBundle ( {
63+ replayScriptSource : await loadReplayScriptSourceBundle ( {
5664 inputPath : entryPath ,
5765 cwd,
5866 replayBackend,
@@ -61,8 +69,11 @@ export function withClientReplayScriptSources(req: DaemonRequest): DaemonRequest
6169 }
6270 if ( req . flags ?. replayScriptSources ) return req ;
6371 return withFlags ( req , {
64- replayScriptSources : discoverReplaySourcePaths ( { inputs, cwd, replayBackend } ) . map (
65- ( inputPath ) => buildReplayScriptSourceBundle ( { inputPath, cwd, replayBackend } ) ,
72+ replayScriptSources : await Promise . all (
73+ discoverReplaySourcePaths ( { inputs, cwd, replayBackend } ) . map (
74+ async ( inputPath ) =>
75+ await loadReplayScriptSourceBundle ( { inputPath, cwd, replayBackend } ) ,
76+ ) ,
6677 ) ,
6778 } ) ;
6879 } catch {
0 commit comments