11import fs from 'node:fs' ;
22import path from 'node:path' ;
3- import { fileURLToPath } from 'node:url' ;
43import { runCmd } from '@agent-device/host-kit/command' ;
54import { AppError } from '@agent-device/kernel/errors' ;
6- import { buildSwiftToolEnv , compileSwiftSourceFile } from './swift-cache.ts' ;
75import { findProjectRoot } from '@agent-device/host-kit/version' ;
6+ import {
7+ buildSwiftToolEnv ,
8+ compileSwiftSourceFile ,
9+ resolveRecordingScriptPath ,
10+ } from './swift-cache.ts' ;
811import { waitForPlayableVideo , waitForStableFile } from './video.ts' ;
912import {
1013 DEFAULT_RECORDING_EXPORT_QUALITY ,
1114 type RecordingExportQuality ,
1215} from '@agent-device/contracts/recording' ;
1316
14- export function buildRecordingScriptPathCandidates (
15- scriptName : string ,
16- moduleDir : string ,
17- projectRoot : string ,
18- cwd : string ,
19- ) : string [ ] {
20- const sourceScriptPath = `apple/runner/AgentDeviceRunner/RecordingScripts/${ scriptName } ` ;
21- const packagedScriptPath = `dist/${ sourceScriptPath } ` ;
22- return [
23- path . resolve ( moduleDir , scriptName ) ,
24- path . resolve ( projectRoot , sourceScriptPath ) ,
25- path . resolve ( moduleDir , `../${ sourceScriptPath } ` ) ,
26- path . resolve ( moduleDir , `../../${ sourceScriptPath } ` ) ,
27- path . resolve ( moduleDir , `../../../${ sourceScriptPath } ` ) ,
28- path . resolve ( projectRoot , packagedScriptPath ) ,
29- path . resolve ( cwd , sourceScriptPath ) ,
30- ] ;
31- }
32-
33- function resolveRecordingScriptPath ( scriptName : string ) : string {
34- const moduleDir = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
35- const scriptCandidates = buildRecordingScriptPathCandidates (
36- scriptName ,
37- moduleDir ,
38- findProjectRoot ( ) ,
39- process . cwd ( ) ,
40- ) ;
41-
42- for ( const candidate of scriptCandidates ) {
43- if ( fs . existsSync ( candidate ) ) {
44- return candidate ;
45- }
46- }
47-
48- throw new AppError ( 'COMMAND_FAILED' , `Missing recording helper script: ${ scriptName } ` , {
49- hint : 'Ensure apple/runner/AgentDeviceRunner/RecordingScripts is present in this checkout or bundled under dist/apple/runner in the package.' ,
50- scriptName,
51- searchedPaths : scriptCandidates ,
52- } ) ;
53- }
54-
55- let overlayScriptPath : string | undefined ;
56- let exportSupportScriptPath : string | undefined ;
57-
5817export function getRecordingOverlaySupportWarning (
5918 hostPlatform : NodeJS . Platform = process . platform ,
6019) : string | undefined {
@@ -64,13 +23,19 @@ export function getRecordingOverlaySupportWarning(
6423 return 'touch overlay burn-in is only available on macOS hosts; returning raw video plus gesture telemetry' ;
6524}
6625
26+ let overlayScriptPath : string | undefined ;
27+ let exportSupportScriptPath : string | undefined ;
28+
6729function getOverlayScriptPath ( ) : string {
68- overlayScriptPath ??= resolveRecordingScriptPath ( 'recording-overlay.swift' ) ;
30+ overlayScriptPath ??= resolveRecordingScriptPath ( 'recording-overlay.swift' , findProjectRoot ( ) ) ;
6931 return overlayScriptPath ;
7032}
7133
7234function getExportSupportScriptPath ( ) : string {
73- exportSupportScriptPath ??= resolveRecordingScriptPath ( 'RecordingExportSupport.swift' ) ;
35+ exportSupportScriptPath ??= resolveRecordingScriptPath (
36+ 'RecordingExportSupport.swift' ,
37+ findProjectRoot ( ) ,
38+ ) ;
7439 return exportSupportScriptPath ;
7540}
7641
0 commit comments