@@ -682,6 +682,7 @@ run_openclaw() {
682682
683683CLAUDE_MEM_REPO=" https://github.com/thedotmack/claude-mem.git"
684684CLAUDE_MEM_BRANCH=" ${CLI_BRANCH:- main} "
685+ PLUGIN_FRESHLY_INSTALLED=" "
685686
686687install_plugin () {
687688 # Check for git before attempting clone
@@ -796,6 +797,30 @@ install_plugin() {
796797 fi
797798
798799 success " claude-mem plugin installed and enabled"
800+
801+ # ── Copy core plugin files (worker, hooks, scripts) to extension directory ──
802+ # The OpenClaw extension only contains the gateway hook (dist/index.js).
803+ # The actual worker service and Claude Code hooks live in the plugin/ directory
804+ # of the main repo. We copy them so find_claude_mem_install_dir() can locate
805+ # the worker-service.cjs and the worker runs the updated version.
806+ local extension_dir=" ${HOME} /.openclaw/extensions/claude-mem"
807+ local repo_root=" ${build_dir} /claude-mem"
808+
809+ if [[ -d " $extension_dir " && -d " ${repo_root} /plugin" ]]; then
810+ info " Copying core plugin files to ${extension_dir} ..."
811+
812+ # Copy plugin/ directory (worker service, hooks, scripts, skills, UI)
813+ cp -R " ${repo_root} /plugin" " ${extension_dir} /"
814+
815+ # Copy root package.json (contains the canonical version number)
816+ cp " ${repo_root} /package.json" " ${extension_dir} /package.json"
817+
818+ success " Core plugin files updated at ${extension_dir} "
819+ else
820+ warn " Could not copy core plugin files — worker may need manual update"
821+ fi
822+
823+ PLUGIN_FRESHLY_INSTALLED=" true"
799824}
800825
801826# ##############################################################################
@@ -1668,21 +1693,65 @@ main() {
16681693
16691694 local needs_restart=" "
16701695
1696+ # If we just installed fresh plugin files, always restart the worker
1697+ # to pick up the new version — even if the old worker was healthy.
1698+ if [[ " $PLUGIN_FRESHLY_INSTALLED " == " true" ]]; then
1699+ if [[ -n " $WORKER_VERSION " && -n " $expected_version " && " $WORKER_VERSION " != " $expected_version " ]]; then
1700+ info " Upgrading worker from v${WORKER_VERSION} to v${expected_version} ..."
1701+ else
1702+ info " Plugin files updated — restarting worker to load new code..."
1703+ fi
1704+ needs_restart=" true"
1705+ fi
1706+
16711707 # Check if worker version is outdated compared to installed version
1672- if [[ -n " $WORKER_VERSION " && -n " $expected_version " && " $WORKER_VERSION " != " $expected_version " ]]; then
1673- warn " Existing worker is v${WORKER_VERSION} but installed v${expected_version} — restart recommended"
1674- info " Run: curl -X POST http://127.0.0.1:37777/api/admin/restart"
1708+ if [[ " $needs_restart " != " true" && -n " $WORKER_VERSION " && -n " $expected_version " && " $WORKER_VERSION " != " $expected_version " ]]; then
1709+ info " Upgrading worker from v${WORKER_VERSION} to v${expected_version} ..."
16751710 needs_restart=" true"
16761711 fi
16771712
16781713 # Check if AI provider doesn't match current configuration
1679- if [[ -n " $WORKER_AI_PROVIDER " && -n " $AI_PROVIDER " && " $WORKER_AI_PROVIDER " != " $AI_PROVIDER " ]]; then
1680- warn " Worker is using ${WORKER_AI_PROVIDER} but you configured ${AI_PROVIDER} — restart to apply changes "
1714+ if [[ " $needs_restart " != " true " && -n " $WORKER_AI_PROVIDER " && -n " $AI_PROVIDER " && " $WORKER_AI_PROVIDER " != " $AI_PROVIDER " ]]; then
1715+ warn " Worker is using ${WORKER_AI_PROVIDER} but you configured ${AI_PROVIDER} — restarting to apply"
16811716 needs_restart=" true"
16821717 fi
16831718
1684- # If everything is current, show full healthy status
1685- if [[ " $needs_restart " != " true" ]]; then
1719+ # Restart worker if needed: kill old process, start fresh
1720+ if [[ " $needs_restart " == " true" ]]; then
1721+ info " Stopping existing worker..."
1722+ # Try graceful shutdown via API first, fall back to SIGTERM
1723+ curl -s -X POST " http://127.0.0.1:37777/api/admin/shutdown" > /dev/null 2>&1 || true
1724+ sleep 2
1725+
1726+ # If still running, send SIGTERM to known PID
1727+ if check_port_37777; then
1728+ if [[ -n " $WORKER_REPORTED_PID " ]]; then
1729+ kill " $WORKER_REPORTED_PID " 2> /dev/null || true
1730+ sleep 1
1731+ fi
1732+ # Check PID file as fallback
1733+ local pid_file=" ${HOME} /.claude-mem/worker.pid"
1734+ if [[ -f " $pid_file " ]]; then
1735+ local file_pid
1736+ file_pid=" $( INSTALLER_PID_FILE=" $pid_file " node -e "
1737+ try { process.stdout.write(String(JSON.parse(require('fs').readFileSync(process.env.INSTALLER_PID_FILE, 'utf8')).pid || '')); }
1738+ catch(e) {}
1739+ " 2> /dev/null) " || true
1740+ if [[ -n " $file_pid " ]]; then
1741+ kill " $file_pid " 2> /dev/null || true
1742+ sleep 1
1743+ fi
1744+ fi
1745+ fi
1746+
1747+ # Start fresh worker
1748+ if start_worker; then
1749+ verify_health || true
1750+ else
1751+ warn " Worker restart failed — you can start it manually later"
1752+ fi
1753+ else
1754+ # No restart needed — show healthy status
16861755 local uptime_display=" "
16871756 if [[ -n " $WORKER_UPTIME " && " $WORKER_UPTIME " =~ ^[0-9]+$ && " $WORKER_UPTIME " != " 0" ]]; then
16881757 uptime_display=" $( format_uptime_ms " $WORKER_UPTIME " ) "
@@ -1715,7 +1784,7 @@ main() {
17151784 verify_health || true
17161785 else
17171786 warn " Worker startup failed — you can start it manually later"
1718- warn " cd ~/.claude/plugins/marketplaces/thedotmack && bun plugin/scripts/worker-service.cjs"
1787+ warn " cd ~/.openclaw/extensions/claude-mem && bun plugin/scripts/worker-service.cjs"
17191788 fi
17201789 fi
17211790
0 commit comments