@@ -18,10 +18,9 @@ import { PluginCommand } from "./cli/cmd/plug"
1818import { DbCommand } from "./cli/cmd/db"
1919import { UI } from "./cli/ui"
2020import { InstallationVersion } from "@opencode-ai/core/installation/version"
21- import { FormatError } from "./cli/error"
2221import { EOL } from "os"
2322import { errorMessage } from "./util/error"
24- import { Heap } from "./cli/heap "
23+ import { lazyCommand } from "./cli/lazy-command "
2524
2625const args = hideBin ( process . argv )
2726
@@ -63,7 +62,10 @@ const cli = yargs(args)
6362 process . env . OPENCODE_PURE = "1"
6463 }
6564
66- Heap . start ( )
65+ if ( process . env . OPENCODE_AUTO_HEAP_SNAPSHOT ) {
66+ const { Heap } = await import ( "./cli/heap" )
67+ Heap . start ( )
68+ }
6769
6870 process . env . AGENT = "1"
6971 process . env . OPENCODE = "1"
@@ -75,22 +77,22 @@ const cli = yargs(args)
7577 } )
7678 . usage ( "" )
7779 . completion ( "completion" , "generate shell completion script" )
78- . command ( McpCommand )
79- . command ( TuiThreadCommand )
80- . command ( AttachCommand )
81- . command ( RunCommand )
82- . command ( GenerateCommand )
83- . command ( DebugCommand )
84- . command ( ProvidersCommand )
85- . command ( AgentCommand )
86- . command ( UpgradeCommand )
87- . command ( UninstallCommand )
88- . command ( ServeCommand )
89- . command ( ModelsCommand )
90- . command ( ExportCommand )
91- . command ( SessionCommand )
92- . command ( PluginCommand )
93- . command ( DbCommand )
80+ . command ( lazyCommand ( McpCommand , ( ) => import ( "./cli/cmd/mcp" ) , "McpCommand" ) )
81+ . command ( lazyCommand ( TuiThreadCommand , ( ) => import ( "./cli/cmd/tui" ) , "TuiThreadCommand" ) )
82+ . command ( lazyCommand ( AttachCommand , ( ) => import ( "./cli/cmd/attach" ) , "AttachCommand" ) )
83+ . command ( lazyCommand ( RunCommand , ( ) => import ( "./cli/cmd/run" ) , "RunCommand" ) )
84+ . command ( lazyCommand ( GenerateCommand , ( ) => import ( "./cli/cmd/generate" ) , "GenerateCommand" ) )
85+ . command ( lazyCommand ( DebugCommand , ( ) => import ( "./cli/cmd/debug" ) , "DebugCommand" ) )
86+ . command ( lazyCommand ( ProvidersCommand , ( ) => import ( "./cli/cmd/providers" ) , "ProvidersCommand" ) )
87+ . command ( lazyCommand ( AgentCommand , ( ) => import ( "./cli/cmd/agent" ) , "AgentCommand" ) )
88+ . command ( lazyCommand ( UpgradeCommand , ( ) => import ( "./cli/cmd/upgrade" ) , "UpgradeCommand" ) )
89+ . command ( lazyCommand ( UninstallCommand , ( ) => import ( "./cli/cmd/uninstall" ) , "UninstallCommand" ) )
90+ . command ( lazyCommand ( ServeCommand , ( ) => import ( "./cli/cmd/serve" ) , "ServeCommand" ) )
91+ . command ( lazyCommand ( ModelsCommand , ( ) => import ( "./cli/cmd/models" ) , "ModelsCommand" ) )
92+ . command ( lazyCommand ( ExportCommand , ( ) => import ( "./cli/cmd/export" ) , "ExportCommand" ) )
93+ . command ( lazyCommand ( SessionCommand , ( ) => import ( "./cli/cmd/session" ) , "SessionCommand" ) )
94+ . command ( lazyCommand ( PluginCommand , ( ) => import ( "./cli/cmd/plug" ) , "PluginCommand" ) )
95+ . command ( lazyCommand ( DbCommand , ( ) => import ( "./cli/cmd/db" ) , "DbCommand" ) )
9496 . fail ( ( msg , err ) => {
9597 if (
9698 msg ?. startsWith ( "Unknown argument" ) ||
@@ -116,6 +118,7 @@ try {
116118 await cli . parse ( )
117119 }
118120} catch ( e ) {
121+ const { FormatError } = await import ( "./cli/error" )
119122 const formatted = FormatError ( e )
120123 if ( formatted ) UI . error ( formatted )
121124 if ( formatted === undefined ) {
0 commit comments