11import type { Command } from "commander" ;
2- import { agentCliCommand } from "../../commands/agent-via-gateway.js" ;
3- import {
4- agentsAddCommand ,
5- agentsBindingsCommand ,
6- agentsBindCommand ,
7- agentsDeleteCommand ,
8- agentsListCommand ,
9- agentsSetIdentityCommand ,
10- agentsUnbindCommand ,
11- } from "../../commands/agents.js" ;
12- import { setVerbose } from "../../globals.js" ;
132import { defaultRuntime } from "../../runtime.js" ;
143import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js" ;
154import { formatDocsLink } from "../../terminal/links.js" ;
165import { theme } from "../../terminal/theme.js" ;
176import { runCommandWithRuntime } from "../cli-utils.js" ;
187import { hasExplicitOptions } from "../command-options.js" ;
19- import { createDefaultDeps } from "../deps.js" ;
208import { formatHelpExamples } from "../help-format.js" ;
219import { collectOption } from "./helpers.js" ;
2210
23- export function registerAgentCommands ( program : Command , args : { agentChannelOptions : string } ) {
11+ type AgentViaGatewayModule = typeof import ( "../../commands/agent-via-gateway.js" ) ;
12+ type AgentsAddModule = typeof import ( "../../commands/agents.commands.add.js" ) ;
13+ type AgentsBindModule = typeof import ( "../../commands/agents.commands.bind.js" ) ;
14+ type AgentsDeleteModule = typeof import ( "../../commands/agents.commands.delete.js" ) ;
15+ type AgentsIdentityModule = typeof import ( "../../commands/agents.commands.identity.js" ) ;
16+ type AgentsListModule = typeof import ( "../../commands/agents.commands.list.js" ) ;
17+ type CliDepsModule = typeof import ( "../deps.js" ) ;
18+ type GlobalStateModule = typeof import ( "../../global-state.js" ) ;
19+
20+ async function loadAgentCliCommand ( ) : Promise < AgentViaGatewayModule [ "agentCliCommand" ] > {
21+ return ( await import ( "../../commands/agent-via-gateway.js" ) ) . agentCliCommand ;
22+ }
23+
24+ async function loadAgentsAddCommand ( ) : Promise < AgentsAddModule [ "agentsAddCommand" ] > {
25+ return ( await import ( "../../commands/agents.commands.add.js" ) ) . agentsAddCommand ;
26+ }
27+
28+ async function loadAgentsBindCommand ( ) : Promise < AgentsBindModule [ "agentsBindCommand" ] > {
29+ return ( await import ( "../../commands/agents.commands.bind.js" ) ) . agentsBindCommand ;
30+ }
31+
32+ async function loadAgentsBindingsCommand ( ) : Promise < AgentsBindModule [ "agentsBindingsCommand" ] > {
33+ return ( await import ( "../../commands/agents.commands.bind.js" ) ) . agentsBindingsCommand ;
34+ }
35+
36+ async function loadAgentsUnbindCommand ( ) : Promise < AgentsBindModule [ "agentsUnbindCommand" ] > {
37+ return ( await import ( "../../commands/agents.commands.bind.js" ) ) . agentsUnbindCommand ;
38+ }
39+
40+ async function loadAgentsDeleteCommand ( ) : Promise < AgentsDeleteModule [ "agentsDeleteCommand" ] > {
41+ return ( await import ( "../../commands/agents.commands.delete.js" ) ) . agentsDeleteCommand ;
42+ }
43+
44+ async function loadAgentsSetIdentityCommand ( ) : Promise <
45+ AgentsIdentityModule [ "agentsSetIdentityCommand" ]
46+ > {
47+ return ( await import ( "../../commands/agents.commands.identity.js" ) ) . agentsSetIdentityCommand ;
48+ }
49+
50+ async function loadAgentsListCommand ( ) : Promise < AgentsListModule [ "agentsListCommand" ] > {
51+ return ( await import ( "../../commands/agents.commands.list.js" ) ) . agentsListCommand ;
52+ }
53+
54+ async function loadCreateDefaultDeps ( ) : Promise < CliDepsModule [ "createDefaultDeps" ] > {
55+ return ( await import ( "../deps.js" ) ) . createDefaultDeps ;
56+ }
57+
58+ async function loadSetVerbose ( ) : Promise < GlobalStateModule [ "setVerbose" ] > {
59+ return ( await import ( "../../global-state.js" ) ) . setVerbose ;
60+ }
61+
62+ export function registerAgentCommands (
63+ program : Command ,
64+ args : { agentChannelOptions : string } ,
65+ ) : void {
2466 program
2567 . command ( "agent" )
2668 . description ( "Run an agent turn via the Gateway (use --local for embedded)" )
@@ -77,13 +119,16 @@ ${formatHelpExamples([
77119
78120${ theme . muted ( "Docs:" ) } ${ formatDocsLink ( "/cli/agent" , "docs.openclaw.ai/cli/agent" ) } `,
79121 )
80- . action ( async ( opts ) => {
122+ . action ( async ( opts ) : Promise < void > => {
81123 const verboseLevel =
82124 typeof opts . verbose === "string" ? normalizeLowercaseStringOrEmpty ( opts . verbose ) : "" ;
83- setVerbose ( verboseLevel === "on" ) ;
84- // Build default deps (keeps parity with other commands; future-proofing).
85- const deps = createDefaultDeps ( ) ;
86125 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
126+ const setVerbose = await loadSetVerbose ( ) ;
127+ setVerbose ( verboseLevel === "on" ) ;
128+ // Build default deps (keeps parity with other commands; future-proofing).
129+ const createDefaultDeps = await loadCreateDefaultDeps ( ) ;
130+ const deps = createDefaultDeps ( ) ;
131+ const agentCliCommand = await loadAgentCliCommand ( ) ;
87132 await agentCliCommand ( opts , defaultRuntime , deps ) ;
88133 } ) ;
89134 } ) ;
@@ -102,8 +147,9 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
102147 . description ( "List configured agents" )
103148 . option ( "--json" , "Output JSON instead of text" , false )
104149 . option ( "--bindings" , "Include routing bindings" , false )
105- . action ( async ( opts ) => {
150+ . action ( async ( opts ) : Promise < void > => {
106151 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
152+ const agentsListCommand = await loadAgentsListCommand ( ) ;
107153 await agentsListCommand (
108154 { json : Boolean ( opts . json ) , bindings : Boolean ( opts . bindings ) } ,
109155 defaultRuntime ,
@@ -116,8 +162,9 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
116162 . description ( "List routing bindings" )
117163 . option ( "--agent <id>" , "Filter by agent id" )
118164 . option ( "--json" , "Output JSON instead of text" , false )
119- . action ( async ( opts ) => {
165+ . action ( async ( opts ) : Promise < void > => {
120166 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
167+ const agentsBindingsCommand = await loadAgentsBindingsCommand ( ) ;
121168 await agentsBindingsCommand (
122169 {
123170 agent : opts . agent as string | undefined ,
@@ -139,8 +186,9 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
139186 [ ] ,
140187 )
141188 . option ( "--json" , "Output JSON summary" , false )
142- . action ( async ( opts ) => {
189+ . action ( async ( opts ) : Promise < void > => {
143190 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
191+ const agentsBindCommand = await loadAgentsBindCommand ( ) ;
144192 await agentsBindCommand (
145193 {
146194 agent : opts . agent as string | undefined ,
@@ -159,8 +207,9 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
159207 . option ( "--bind <channel[:accountId]>" , "Binding to remove (repeatable)" , collectOption , [ ] )
160208 . option ( "--all" , "Remove all bindings for this agent" , false )
161209 . option ( "--json" , "Output JSON summary" , false )
162- . action ( async ( opts ) => {
210+ . action ( async ( opts ) : Promise < void > => {
163211 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
212+ const agentsUnbindCommand = await loadAgentsUnbindCommand ( ) ;
164213 await agentsUnbindCommand (
165214 {
166215 agent : opts . agent as string | undefined ,
@@ -182,7 +231,7 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
182231 . option ( "--bind <channel[:accountId]>" , "Route channel binding (repeatable)" , collectOption , [ ] )
183232 . option ( "--non-interactive" , "Disable prompts; requires --workspace" , false )
184233 . option ( "--json" , "Output JSON summary" , false )
185- . action ( async ( name , opts , command ) => {
234+ . action ( async ( name , opts , command ) : Promise < void > => {
186235 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
187236 const hasFlags = hasExplicitOptions ( command , [
188237 "workspace" ,
@@ -191,6 +240,7 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
191240 "bind" ,
192241 "nonInteractive" ,
193242 ] ) ;
243+ const agentsAddCommand = await loadAgentsAddCommand ( ) ;
194244 await agentsAddCommand (
195245 {
196246 name : typeof name === "string" ? name : undefined ,
@@ -238,8 +288,9 @@ ${formatHelpExamples([
238288] ) }
239289` ,
240290 )
241- . action ( async ( opts ) => {
291+ . action ( async ( opts ) : Promise < void > => {
242292 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
293+ const agentsSetIdentityCommand = await loadAgentsSetIdentityCommand ( ) ;
243294 await agentsSetIdentityCommand (
244295 {
245296 agent : opts . agent as string | undefined ,
@@ -262,8 +313,9 @@ ${formatHelpExamples([
262313 . description ( "Delete an agent and prune workspace/state" )
263314 . option ( "--force" , "Skip confirmation" , false )
264315 . option ( "--json" , "Output JSON summary" , false )
265- . action ( async ( id , opts ) => {
316+ . action ( async ( id , opts ) : Promise < void > => {
266317 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
318+ const agentsDeleteCommand = await loadAgentsDeleteCommand ( ) ;
267319 await agentsDeleteCommand (
268320 {
269321 id : String ( id ) ,
@@ -275,8 +327,9 @@ ${formatHelpExamples([
275327 } ) ;
276328 } ) ;
277329
278- agents . action ( async ( ) => {
330+ agents . action ( async ( ) : Promise < void > => {
279331 await runCommandWithRuntime ( defaultRuntime , async ( ) => {
332+ const agentsListCommand = await loadAgentsListCommand ( ) ;
280333 await agentsListCommand ( { } , defaultRuntime ) ;
281334 } ) ;
282335 } ) ;
0 commit comments