@@ -570,6 +570,39 @@ fix_npm_permissions() {
570570 echo -e " ${SUCCESS} ✓${NC} npm configured for user installs"
571571}
572572
573+ resolve_clawdbot_bin () {
574+ if command -v clawdbot & > /dev/null; then
575+ command -v clawdbot
576+ return 0
577+ fi
578+ local npm_bin=" "
579+ npm_bin=" $( npm_global_bin_dir || true) "
580+ if [[ -n " $npm_bin " && -x " ${npm_bin} /clawdbot" ]]; then
581+ echo " ${npm_bin} /clawdbot"
582+ return 0
583+ fi
584+ return 1
585+ }
586+
587+ ensure_clawdbot_bin_link () {
588+ local npm_root=" "
589+ npm_root=" $( npm root -g 2> /dev/null || true) "
590+ if [[ -z " $npm_root " || ! -d " $npm_root /clawdbot" ]]; then
591+ return 1
592+ fi
593+ local npm_bin=" "
594+ npm_bin=" $( npm_global_bin_dir || true) "
595+ if [[ -z " $npm_bin " ]]; then
596+ return 1
597+ fi
598+ mkdir -p " $npm_bin "
599+ if [[ ! -x " ${npm_bin} /clawdbot" ]]; then
600+ ln -sf " $npm_root /clawdbot/dist/entry.js" " ${npm_bin} /clawdbot"
601+ echo -e " ${WARN} →${NC} Installed clawdbot bin link at ${INFO}${npm_bin} /clawdbot${NC} "
602+ fi
603+ return 0
604+ }
605+
573606# Check for existing Clawdbot installation
574607check_existing_clawdbot () {
575608 if [[ -n " $( type -P clawdbot 2> /dev/null || true) " ]]; then
@@ -830,16 +863,29 @@ install_clawdbot() {
830863 else
831864 echo -e " ${WARN} →${NC} Installing Clawdbot (${INFO}${CLAWDBOT_VERSION}${NC} )..."
832865 fi
866+ local install_spec=" "
867+ if [[ " ${CLAWDBOT_VERSION} " == " latest" ]]; then
868+ install_spec=" clawdbot@latest"
869+ else
870+ install_spec=" clawdbot@${CLAWDBOT_VERSION} "
871+ fi
872+
873+ if ! install_clawdbot_npm " ${install_spec} " ; then
874+ echo -e " ${WARN} →${NC} npm install failed; cleaning up and retrying..."
875+ cleanup_npm_clawdbot_paths
876+ install_clawdbot_npm " ${install_spec} "
877+ fi
833878
834879 if [[ " ${CLAWDBOT_VERSION} " == " latest" ]]; then
835- if ! install_clawdbot_npm " clawdbot@latest " ; then
880+ if ! resolve_clawdbot_bin & > /dev/null ; then
836881 echo -e " ${WARN} →${NC} npm install clawdbot@latest failed; retrying clawdbot@next"
882+ cleanup_npm_clawdbot_paths
837883 install_clawdbot_npm " clawdbot@next"
838884 fi
839- else
840- install_clawdbot_npm " clawdbot@${CLAWDBOT_VERSION} "
841885 fi
842886
887+ ensure_clawdbot_bin_link || true
888+
843889 echo -e " ${SUCCESS} ✓${NC} Clawdbot installed"
844890}
845891
0 commit comments