@@ -27,6 +27,46 @@ if (command === "usage") {
2727} else if ( command === "version" || command === "--version" || command === "-v" ) {
2828 const pkg = await import ( "../package.json" ) ;
2929 console . log ( pkg . version ) ;
30+ } else if ( command === "update" ) {
31+ const pkg = await import ( "../package.json" ) ;
32+ const currentVersion = pkg . version ;
33+
34+ console . log ( `Current version: ${ currentVersion } ` ) ;
35+ console . log ( "Checking for updates..." ) ;
36+
37+ try {
38+ const response = await fetch ( "https://registry.npmjs.org/agent-limit/latest" ) ;
39+ if ( ! response . ok ) {
40+ throw new Error ( `Failed to fetch: ${ response . status } ` ) ;
41+ }
42+ const data = await response . json ( ) as { version : string } ;
43+ const latestVersion = data . version ;
44+
45+ if ( latestVersion === currentVersion ) {
46+ console . log ( `✓ You're on the latest version (${ currentVersion } )` ) ;
47+ } else {
48+ console . log ( `New version available: ${ latestVersion } ` ) ;
49+ console . log ( "\nUpdating..." ) ;
50+
51+ const proc = Bun . spawn ( [ "npm" , "install" , "-g" , "agent-limit@latest" ] , {
52+ stdout : "inherit" ,
53+ stderr : "inherit" ,
54+ } ) ;
55+
56+ const exitCode = await proc . exited ;
57+
58+ if ( exitCode === 0 ) {
59+ console . log ( `\n✓ Updated to ${ latestVersion } ` ) ;
60+ } else {
61+ console . error ( "\n✗ Update failed. Try running manually:" ) ;
62+ console . error ( " npm install -g agent-limit@latest" ) ;
63+ process . exit ( 1 ) ;
64+ }
65+ }
66+ } catch ( error ) {
67+ console . error ( "Failed to check for updates:" , error instanceof Error ? error . message : error ) ;
68+ process . exit ( 1 ) ;
69+ }
3070} else if ( command === "help" || command === "--help" || command === "-h" || ! command ) {
3171 console . log ( `
3272agent-limit
@@ -41,6 +81,7 @@ Quick Start:
4181
4282CLI:
4383 agent-limit usage Show usage dashboard
84+ agent-limit update Update to latest version
4485 agent-limit version Show version
4586 agent-limit help Show this help message
4687
0 commit comments