@@ -358,12 +358,14 @@ function classifyConfiguredTargetRefs(params: {
358358} ) : {
359359 hasActiveConfiguredRef : boolean ;
360360 hasUnknownConfiguredRef : boolean ;
361+ activeOrUnknownRefPaths : Set < string > ;
361362 diagnostics : string [ ] ;
362363} {
363364 if ( params . configuredTargetRefPaths . size === 0 ) {
364365 return {
365366 hasActiveConfiguredRef : false ,
366367 hasUnknownConfiguredRef : false ,
368+ activeOrUnknownRefPaths : new Set ( ) ,
367369 diagnostics : [ ] ,
368370 } ;
369371 }
@@ -388,6 +390,7 @@ function classifyConfiguredTargetRefs(params: {
388390 const diagnostics = new Set < string > ( ) ;
389391 let hasActiveConfiguredRef = false ;
390392 let hasUnknownConfiguredRef = false ;
393+ const activeOrUnknownRefPaths = new Set < string > ( ) ;
391394
392395 for ( const path of params . configuredTargetRefPaths ) {
393396 if (
@@ -396,6 +399,7 @@ function classifyConfiguredTargetRefs(params: {
396399 params . optionalActivePaths ?. has ( path )
397400 ) {
398401 hasActiveConfiguredRef = true ;
402+ activeOrUnknownRefPaths . add ( path ) ;
399403 continue ;
400404 }
401405 const inactiveWarning = inactiveWarningsByPath . get ( path ) ;
@@ -404,15 +408,37 @@ function classifyConfiguredTargetRefs(params: {
404408 continue ;
405409 }
406410 hasUnknownConfiguredRef = true ;
411+ activeOrUnknownRefPaths . add ( path ) ;
407412 }
408413
409414 return {
410415 hasActiveConfiguredRef,
411416 hasUnknownConfiguredRef,
417+ activeOrUnknownRefPaths,
412418 diagnostics : [ ...diagnostics ] ,
413419 } ;
414420}
415421
422+ function collectExecSecretRefPaths ( params : {
423+ config : OpenClawConfig ;
424+ targetIds : Set < string > ;
425+ paths : ReadonlySet < string > ;
426+ } ) : string [ ] {
427+ const defaults = params . config . secrets ?. defaults ;
428+ return commandSecretGatewayDeps
429+ . discoverConfigSecretTargetsByIds ( params . config , params . targetIds )
430+ . filter ( ( target ) => params . paths . has ( target . path ) )
431+ . filter ( ( target ) => {
432+ const { ref } = resolveSecretInputRef ( {
433+ value : target . value ,
434+ refValue : target . refValue ,
435+ defaults,
436+ } ) ;
437+ return ref ?. source === "exec" ;
438+ } )
439+ . map ( ( target ) => target . path ) ;
440+ }
441+
416442function parseGatewaySecretsResolveResult ( payload : unknown ) : {
417443 assignments : Array < { path ?: string ; pathSegments : string [ ] ; value : unknown } > ;
418444 diagnostics : string [ ] ;
@@ -935,6 +961,82 @@ export async function resolveCommandSecretRefsViaGateway(params: {
935961 hadUnresolvedTargets : false ,
936962 } ;
937963 }
964+ const commandExecSecretRefPaths = resolutionPolicy . allowExecSecretRefs
965+ ? collectExecSecretRefPaths ( {
966+ config : params . config ,
967+ targetIds : params . targetIds ,
968+ paths : preflight . activeOrUnknownRefPaths ,
969+ } )
970+ : [ ] ;
971+ if ( commandExecSecretRefPaths . length > 0 ) {
972+ const execPaths = new Set ( commandExecSecretRefPaths ) ;
973+ const localExec = await resolveCommandSecretRefsLocally ( {
974+ config : params . config ,
975+ commandName : params . commandName ,
976+ targetIds : params . targetIds ,
977+ preflightDiagnostics : preflight . diagnostics ,
978+ mode : "read_only_operational" ,
979+ allowedPaths : execPaths ,
980+ forcedActivePaths : params . forcedActivePaths ,
981+ optionalActivePaths : params . optionalActivePaths ,
982+ resolutionPolicy : {
983+ ...resolutionPolicy ,
984+ scrubUnresolvedSecretRefs : false ,
985+ } ,
986+ } ) ;
987+ const resolvedExecPaths = new Set (
988+ commandExecSecretRefPaths . filter (
989+ ( path ) => localExec . targetStatesByPath [ path ] === "resolved_local" ,
990+ ) ,
991+ ) ;
992+ const remainingPaths = new Set (
993+ [ ...preflight . activeOrUnknownRefPaths ] . filter ( ( path ) => ! resolvedExecPaths . has ( path ) ) ,
994+ ) ;
995+ const remaining =
996+ remainingPaths . size > 0
997+ ? await resolveCommandSecretRefsViaGateway ( {
998+ ...params ,
999+ config : localExec . resolvedConfig ,
1000+ allowedPaths : remainingPaths ,
1001+ allowLocalExecSecretRefs : false ,
1002+ } )
1003+ : undefined ;
1004+ const targetStatesByPath = {
1005+ ...localExec . targetStatesByPath ,
1006+ ...remaining ?. targetStatesByPath ,
1007+ } ;
1008+ const unrecoveredExecDiagnostics = localExec . diagnostics . filter ( ( diagnostic ) =>
1009+ commandExecSecretRefPaths . some (
1010+ ( path ) =>
1011+ targetStatesByPath [ path ] === "unresolved" &&
1012+ diagnostic . startsWith ( `${ params . commandName } : failed to resolve ${ path } locally (` ) ,
1013+ ) ,
1014+ ) ;
1015+ const attemptedExecSkipDiagnostics = new Set (
1016+ commandExecSecretRefPaths . map (
1017+ ( path ) =>
1018+ `${ params . commandName } : skipped local exec SecretRef resolution for ${ path } ; rerun with --allow-exec to execute configured exec providers.` ,
1019+ ) ,
1020+ ) ;
1021+ const remainingDiagnostics = ( remaining ?. diagnostics ?? [ ] ) . filter (
1022+ ( diagnostic ) => ! attemptedExecSkipDiagnostics . has ( diagnostic ) ,
1023+ ) ;
1024+ return {
1025+ resolvedConfig : remaining ?. resolvedConfig ?? localExec . resolvedConfig ,
1026+ diagnostics : dedupeDiagnostics ( [
1027+ ...preflight . diagnostics ,
1028+ ...( resolvedExecPaths . size > 0
1029+ ? [
1030+ `${ params . commandName } : resolved exec SecretRefs locally without gateway secrets.resolve at ${ [ ...resolvedExecPaths ] . join ( ", " ) } .` ,
1031+ ]
1032+ : [ ] ) ,
1033+ ...unrecoveredExecDiagnostics ,
1034+ ...remainingDiagnostics ,
1035+ ] ) ,
1036+ targetStatesByPath,
1037+ hadUnresolvedTargets : Object . values ( targetStatesByPath ) . includes ( "unresolved" ) ,
1038+ } ;
1039+ }
9381040 const gatewayExecSecretRefCredentialPaths = resolutionPolicy . allowExecSecretRefs
9391041 ? [ ]
9401042 : collectActiveGatewayExecSecretRefCredentialPaths ( params . config ) ;
0 commit comments