@@ -547,9 +547,9 @@ function renderSourceRootHelpText(
547547 return result . stdout ?? "" ;
548548}
549549
550- function renderSourceBrowserHelpText (
550+ async function renderSourceBrowserHelpText (
551551 renderContext : RootHelpRenderContext = createIsolatedRootHelpRenderContext ( ) ,
552- ) : string {
552+ ) : Promise < string > {
553553 const browserCliUrl = pathToFileURL (
554554 path . join ( rootDir , "extensions/browser/src/cli/browser-cli.ts" ) ,
555555 ) . href ;
@@ -568,30 +568,18 @@ function renderSourceBrowserHelpText(
568568 `browser.outputHelp();` ,
569569 "process.exit(0);" ,
570570 ] . join ( "\n" ) ;
571- const result = spawnSync (
572- process . execPath ,
571+ return await spawnText (
573572 [ "--import" , "tsx" , "--input-type=module" , "--eval" , inlineModule ] ,
574573 {
575574 cwd : rootDir ,
576- encoding : "utf8" ,
577575 env : {
578576 ...renderContext . env ,
579577 OPENCLAW_DISABLE_CLI_STARTUP_HELP_FAST_PATH : "1" ,
580578 } ,
581- timeout : BROWSER_HELP_RENDER_TIMEOUT_MS ,
579+ failureMessage : "Failed to render source browser help" ,
580+ timeoutMs : BROWSER_HELP_RENDER_TIMEOUT_MS ,
582581 } ,
583582 ) ;
584- if ( result . error ) {
585- throw result . error ;
586- }
587- if ( result . status !== 0 ) {
588- const stderr = result . stderr ?. trim ( ) ;
589- throw new Error (
590- "Failed to render source browser help" +
591- ( stderr ? `: ${ stderr } ` : result . signal ? `: terminated by ${ result . signal } ` : "" ) ,
592- ) ;
593- }
594- return result . stdout ?? "" ;
595583}
596584
597585async function renderSourceCommandHelpText (
@@ -657,7 +645,7 @@ export async function writeCliStartupMetadata(options?: {
657645 sourceRootDir ?: string ;
658646 renderBundledRootHelpText ?: typeof renderBundledRootHelpText ;
659647 renderSourceRootHelpText ?: typeof renderSourceRootHelpText ;
660- renderSourceBrowserHelpText ?: typeof renderSourceBrowserHelpText ;
648+ renderSourceBrowserHelpText ?: ( renderContext : RootHelpRenderContext ) => Awaitable < string > ;
661649 renderSourceSecretsHelpText ?: ( renderContext : RootHelpRenderContext ) => Awaitable < string > ;
662650 renderSourceNodesHelpText ?: ( renderContext : RootHelpRenderContext ) => Awaitable < string > ;
663651 renderSourceSubcommandHelpTextRecord ?: (
@@ -726,34 +714,50 @@ export async function writeCliStartupMetadata(options?: {
726714 } catch {
727715 rootHelpText = ( options ?. renderSourceRootHelpText ?? renderSourceRootHelpText ) ( renderContext ) ;
728716 }
729- const browserHelpText = ( options ?. renderSourceBrowserHelpText ?? renderSourceBrowserHelpText ) (
730- renderContext ,
717+ const browserHelpTextPromise = Promise . resolve (
718+ ( options ?. renderSourceBrowserHelpText ?? renderSourceBrowserHelpText ) ( renderContext ) ,
731719 ) ;
732- const commandHelpText =
720+ const hasCustomCommandRenderer =
733721 options ?. renderSourceSecretsHelpText ||
734722 options ?. renderSourceNodesHelpText ||
735- options ?. renderSourceSubcommandHelpTextRecord
736- ? null
737- : await renderSourceCommandHelpTextRecord (
738- [ "secrets" , "nodes" , ...PRECOMPUTED_SUBCOMMAND_HELP_COMMANDS ] ,
739- renderContext ,
740- ) ;
741- const secretsHelpText = commandHelpText
742- ? commandHelpText . secrets
743- : await ( options ?. renderSourceSecretsHelpText ?? renderSourceSecretsHelpText ) ( renderContext ) ;
744- const nodesHelpText = commandHelpText
745- ? commandHelpText . nodes
746- : await ( options ?. renderSourceNodesHelpText ?? renderSourceNodesHelpText ) ( renderContext ) ;
747- const subcommandHelpText = commandHelpText
748- ? ( Object . fromEntries (
749- PRECOMPUTED_SUBCOMMAND_HELP_COMMANDS . map ( ( commandName ) => [
750- commandName ,
751- commandHelpText [ commandName ] ,
752- ] ) ,
753- ) as PrecomputedSubcommandHelpText )
754- : await ( options ?. renderSourceSubcommandHelpTextRecord ?? renderSourceSubcommandHelpTextRecord ) (
723+ options ?. renderSourceSubcommandHelpTextRecord ;
724+ const commandHelpTextPromise = hasCustomCommandRenderer
725+ ? null
726+ : renderSourceCommandHelpTextRecord (
727+ [ "secrets" , "nodes" , ...PRECOMPUTED_SUBCOMMAND_HELP_COMMANDS ] ,
755728 renderContext ,
756729 ) ;
730+ const secretsHelpTextPromise = commandHelpTextPromise
731+ ? commandHelpTextPromise . then ( ( commandHelpText ) => commandHelpText . secrets )
732+ : Promise . resolve (
733+ ( options ?. renderSourceSecretsHelpText ?? renderSourceSecretsHelpText ) ( renderContext ) ,
734+ ) ;
735+ const nodesHelpTextPromise = commandHelpTextPromise
736+ ? commandHelpTextPromise . then ( ( commandHelpText ) => commandHelpText . nodes )
737+ : Promise . resolve (
738+ ( options ?. renderSourceNodesHelpText ?? renderSourceNodesHelpText ) ( renderContext ) ,
739+ ) ;
740+ const subcommandHelpTextPromise = commandHelpTextPromise
741+ ? commandHelpTextPromise . then (
742+ ( commandHelpText ) =>
743+ Object . fromEntries (
744+ PRECOMPUTED_SUBCOMMAND_HELP_COMMANDS . map ( ( commandName ) => [
745+ commandName ,
746+ commandHelpText [ commandName ] ,
747+ ] ) ,
748+ ) as PrecomputedSubcommandHelpText ,
749+ )
750+ : Promise . resolve (
751+ ( options ?. renderSourceSubcommandHelpTextRecord ?? renderSourceSubcommandHelpTextRecord ) (
752+ renderContext ,
753+ ) ,
754+ ) ;
755+ const [ browserHelpText , secretsHelpText , nodesHelpText , subcommandHelpText ] = await Promise . all ( [
756+ browserHelpTextPromise ,
757+ secretsHelpTextPromise ,
758+ nodesHelpTextPromise ,
759+ subcommandHelpTextPromise ,
760+ ] ) ;
757761
758762 mkdirSync ( resolvedDistDir , { recursive : true } ) ;
759763 writeFileSync (
0 commit comments