@@ -78,7 +78,7 @@ export interface OpenClawPluginAPI {
7878 fs : typeof fs ;
7979 jacs ?: JACSRuntime ;
8080 } ;
81- registerCli : ( opts : any ) => void ;
81+ registerCli : ( registrar : any , opts ? : any ) => void ;
8282 registerCommand : ( opts : any ) => void ;
8383 registerTool : ( opts : any , options ?: { optional ?: boolean } ) => void ;
8484 registerGatewayMethod ?: ( opts : any ) => void ;
@@ -107,7 +107,7 @@ let haiClientPromise: Promise<HaiClient | null> | null = null;
107107/**
108108 * Main plugin registration function called by OpenClaw
109109 */
110- export default function register ( api : OpenClawPluginAPI ) : void {
110+ export function register ( api : OpenClawPluginAPI ) : void {
111111 const config = api . config ;
112112 const logger = api . logger ;
113113
@@ -168,19 +168,60 @@ export default function register(api: OpenClawPluginAPI): void {
168168 logger . info ( "JACS not configured - run 'openclaw haiai init' to set up" ) ;
169169 }
170170
171- // Register CLI commands
172- api . registerCli ( {
173- name : "haiai" ,
174- description : "HAI.AI cryptographic provenance commands" ,
175- subcommands : cliCommands ( api ) ,
176- } ) ;
171+ // Register CLI commands (Commander.js-style registrar)
172+ const commands = cliCommands ( api ) ;
173+ const initHandler = setupCommand ( api ) ;
177174
178- // Register setup/init command
179- api . registerCommand ( {
180- name : "haiai-init" ,
181- description : "Initialize JACS with key generation and agent creation" ,
182- handler : setupCommand ( api ) ,
183- } ) ;
175+ if ( api . registerCli ) {
176+ api . registerCli ( ( program : any ) => {
177+ const haiai = program . command ( "haiai" ) . description ( "HAI.AI cryptographic provenance commands" ) ;
178+
179+ // Register init subcommand
180+ const initCmd = haiai . command ( "init" ) . description (
181+ "Initialize JACS with key generation"
182+ ) ;
183+ initCmd . option ( "--algorithm <algo>" , "Key algorithm" ) ;
184+ initCmd . option ( "--name <name>" , "Agent name" ) ;
185+ initCmd . option ( "--description <description>" , "Agent description" ) ;
186+ initCmd . option ( "--domain <domain>" , "Agent domain" ) ;
187+ initCmd . option ( "--password-file <path>" , "Password file path" ) ;
188+ initCmd . action ( async ( opts : any ) => {
189+ const result = await initHandler ( opts ) ;
190+ if ( result . text ) console . log ( result . text ) ;
191+ } ) ;
192+
193+ // Register all other subcommands from cliCommands
194+ for ( const [ name , cmd ] of Object . entries ( commands ) ) {
195+ const sub = haiai . command ( name ) . description ( cmd . description ) ;
196+ if ( cmd . args ) {
197+ for ( const arg of cmd . args ) {
198+ if ( arg . startsWith ( "[--" ) || arg . startsWith ( "--" ) ) {
199+ const match = arg . match ( / - - ( \S + ) \s * (?: < ( \S + ) > ) ? / ) ;
200+ if ( match ) sub . option ( `--${ match [ 1 ] } ${ match [ 2 ] ? ` <${ match [ 2 ] } >` : "" } ` , "" ) ;
201+ } else {
202+ sub . argument ( arg , "" ) ;
203+ }
204+ }
205+ }
206+ sub . action ( async ( ...actionArgs : any [ ] ) => {
207+ // Commander passes positional args then opts then command
208+ const opts = actionArgs . length > 1 ? actionArgs [ actionArgs . length - 2 ] : { } ;
209+ const positional = actionArgs . length > 2 ? actionArgs . slice ( 0 , - 2 ) : [ ] ;
210+ // Map positional args to named params based on arg definitions
211+ const args : any = { ...opts , _ : positional } ;
212+ if ( cmd . args ) {
213+ const positionalDefs = cmd . args . filter ( a => ! a . startsWith ( "-" ) ) ;
214+ positionalDefs . forEach ( ( def , i ) => {
215+ const paramName = def . replace ( / [ < > \[ \] ] / g, "" ) ;
216+ if ( positional [ i ] !== undefined ) args [ paramName ] = positional [ i ] ;
217+ } ) ;
218+ }
219+ const result = await cmd . handler ( args ) ;
220+ if ( result . text ) console . log ( result . text ) ;
221+ } ) ;
222+ }
223+ } , { commands : [ "haiai" ] } ) ;
224+ }
184225
185226 // Register agent tools for AI use
186227 registerTools ( api ) ;
@@ -241,6 +282,8 @@ export function setAgentInstance(agent: JacsAgent, agentId: string, publicKey: s
241282 isInitialized = true ;
242283}
243284
285+ export default register ;
286+
244287export { setupCommand } from "./setup" ;
245288export { cliCommands } from "./cli" ;
246289export { registerTools } from "./tools" ;
0 commit comments