From 162756ad9b5add98fae45115a0680da957223e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Fri, 13 Mar 2026 15:33:37 +0800 Subject: [PATCH] fix: add remaining missing web mode handlers (check_git, configure_git_https, guardian_status, invalidate_path_cache) --- scripts/dev-api.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/dev-api.js b/scripts/dev-api.js index 0d57434..1ee802e 100644 --- a/scripts/dev-api.js +++ b/scripts/dev-api.js @@ -2339,6 +2339,44 @@ const handlers = { return { installed: fs.existsSync(CONFIG_PATH), path: OPENCLAW_DIR, platform: isMac ? 'macos' : process.platform, inDocker } }, + check_git() { + try { + const ver = execSync('git --version', { encoding: 'utf8', timeout: 5000, windowsHide: true }).trim() + const match = ver.match(/(\d+\.\d+[\.\d]*)/) + return { installed: true, version: match ? match[1] : ver } + } catch { + return { installed: false } + } + }, + + auto_install_git() { + // Web 模式下不自动安装系统软件,返回指引 + throw new Error('Web 部署模式下请手动安装 Git:\n- Ubuntu/Debian: sudo apt install git\n- CentOS/RHEL: sudo yum install git\n- macOS: xcode-select --install') + }, + + configure_git_https() { + try { + const cmds = [ + 'git config --global url."https://github.com/".insteadOf "git@github.com:"', + 'git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"', + 'git config --global url."https://github.com/".insteadOf "git://github.com/"', + ] + for (const cmd of cmds) execSync(cmd, { timeout: 5000, windowsHide: true }) + return '已配置 Git HTTPS 替代 SSH' + } catch (e) { + throw new Error('配置失败: ' + (e.message || e)) + } + }, + + guardian_status() { + // Web 模式没有 Guardian 守护进程 + return { enabled: false, giveUp: false } + }, + + invalidate_path_cache() { + return true + }, + check_node() { try { const ver = execSync('node --version 2>&1', { windowsHide: true }).toString().trim()