Compare commits
4
Commits
d97329e504
...
0b71a33bd2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b71a33bd2 | ||
|
|
464639ef1a | ||
|
|
fbdd2a9dc5 | ||
|
|
877965f913 |
@@ -3,19 +3,23 @@
|
||||
# 复制为 .env 并按需填写
|
||||
# =============================================================
|
||||
|
||||
# ── Claude / Anthropic API ──────────────────────────────────
|
||||
# Anthropic 官方 API Key(从 https://console.anthropic.com 获取)
|
||||
ANTHROPIC_API_KEY=
|
||||
# ── Claude / API 配置 ────────────────────────────────────────
|
||||
# 推荐:灵眸 AI(国内直连,无需代理)https://docs.lmuai.com/docs/tools/claude-code
|
||||
ANTHROPIC_AUTH_TOKEN=sk-你的灵眸API密钥
|
||||
ANTHROPIC_BASE_URL=https://api.lmuai.com
|
||||
|
||||
# API Base URL(默认使用 Anthropic 官方;若使用中转代理请修改)
|
||||
# 示例(DeepSeek 兼容接口):
|
||||
# ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
|
||||
ANTHROPIC_BASE_URL=https://api.anthropic.com
|
||||
# 备选:Anthropic 官方 API Key(海外直连)
|
||||
# ANTHROPIC_API_KEY=
|
||||
# ANTHROPIC_BASE_URL=https://api.anthropic.com
|
||||
|
||||
# 备选:DeepSeek 兼容接口
|
||||
# ANTHROPIC_API_KEY=
|
||||
# ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
|
||||
|
||||
# 默认使用的模型
|
||||
# 可选:claude-opus-4-5 | claude-sonnet-4-5 | claude-haiku-4-5
|
||||
# deepseek-v3-0324(配合 DeepSeek 接口使用)
|
||||
CLAUDE_MODEL=claude-opus-4-5
|
||||
# 灵眸可选:claude-opus-4-7 | claude-sonnet-4-6 | claude-sonnet-4-5 | claude-haiku-4-5
|
||||
# DeepSeek可选:deepseek-v4-pro
|
||||
CLAUDE_MODEL=claude-sonnet-4-6
|
||||
|
||||
# ── WSL2 ────────────────────────────────────────────────────
|
||||
# WSL2 发行版名称(wsl --list 查看已安装发行版)
|
||||
|
||||
+45
-48
@@ -2,7 +2,7 @@
|
||||
|
||||
WSL2 + Claude Code CLI + Unity MCP + Rust Token Killer **全栈一键部署方案**,适用于 Windows 11 开发环境。
|
||||
|
||||
支持 **v2rayN 代理自动检测**、**WSL2 代理透传**、**防火墙自动放行**。
|
||||
支持 **WSL2 镜像网络模式**(`autoProxy=true`),WSL2 自动继承 Windows 代理状态,无需脚本干预。
|
||||
|
||||
## 组件清单
|
||||
|
||||
@@ -43,18 +43,12 @@ WSL2 Ubuntu 首次启动若弹出用户创建提示,可直接跳过或按提
|
||||
# 1. 以管理员身份运行 PowerShell
|
||||
cd path\to\claude-dev-stack
|
||||
|
||||
# 2. 复制配置文件,填写 ANTHROPIC_API_KEY
|
||||
# 2. 复制配置文件,填写灵眸 API Key(推荐)或 Anthropic API Key
|
||||
cp .env.example .env
|
||||
notepad .env
|
||||
|
||||
# 3. 运行部署脚本(自动检测 v2rayN 代理)
|
||||
# 3. 运行部署脚本
|
||||
pwsh .\deploy.ps1
|
||||
|
||||
# 手动指定代理端口
|
||||
pwsh .\deploy.ps1 -ProxyPort 10809
|
||||
|
||||
# 不使用代理(直连)
|
||||
pwsh .\deploy.ps1 -ProxyPort -1
|
||||
```
|
||||
|
||||
首次安装 WSL2 特性后可能需要**重启系统**,重启后重新执行脚本。
|
||||
@@ -71,55 +65,60 @@ pwsh .\deploy.ps1 -SkipWSL
|
||||
# 在 WSL2 Ubuntu 终端中执行
|
||||
cp .env.example .env
|
||||
nano .env
|
||||
# 如需代理(端口由 deploy.ps1 写入 ~/.mcp-proxy.env,或手动指定)
|
||||
PROXY_PORT=10809 bash wsl-setup.sh
|
||||
bash wsl-setup.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 代理说明(v2rayN)
|
||||
## 代理说明
|
||||
|
||||
### 自动检测顺序
|
||||
### WSL2 镜像模式自动继承 Windows 代理
|
||||
|
||||
1. Windows 系统代理注册表(v2rayN「设为系统代理」时写入)
|
||||
2. v2rayN 配置文件(`%APPDATA%\v2rayN\guiNConfig.json`)
|
||||
3. 探测常用端口:`10809, 10808, 7890, 1080, 8080`
|
||||
脚本自动配置 `~/.wslconfig` 启用 WSL2 镜像网络模式:
|
||||
|
||||
### WSL2 代理透传原理
|
||||
|
||||
```
|
||||
WSL2 Ubuntu
|
||||
→ [Windows 主机 vEthernet(WSL) IP]:10809
|
||||
→ v2rayN
|
||||
→ 互联网
|
||||
```ini
|
||||
[wsl2]
|
||||
networkingMode=mirrored
|
||||
autoProxy=true
|
||||
```
|
||||
|
||||
**必须**在 v2rayN 中开启:
|
||||
> 参数设置 → **「允许来自局域网的连接」** ✅
|
||||
|
||||
脚本自动完成:
|
||||
- 写入 WSL2 `~/.mcp-proxy.env`(每次 shell 启动自动生效)
|
||||
- 配置 WSL2 `git` + `npm` 代理
|
||||
- `apt-get` 安装阶段同样走代理
|
||||
|
||||
### 代理覆盖范围
|
||||
|
||||
| 操作 | 是否走代理 |
|
||||
|------|-----------|
|
||||
| Windows `git clone` / `npm install` | ✅ |
|
||||
| WSL2 `apt-get` / `git clone` / `npm install` / `cargo install` | ✅ |
|
||||
| MCP Server ↔ AI 客户端(stdio) | ❌ 本地通信,无需代理 |
|
||||
| MCP Server ↔ Unity Plugin(localhost) | ❌ 本地通信,无需代理 |
|
||||
`autoProxy=true` 下,WSL2 自动继承 Windows 系统代理状态。
|
||||
**是否使用代理由 Windows 侧决定**(例如通过 v2rayN「设为系统代理」),无需脚本干预。
|
||||
|
||||
---
|
||||
|
||||
## 配置说明(`.env`)
|
||||
|
||||
### 推荐:灵眸 AI(国内直连,无需代理)
|
||||
|
||||
| 变量 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `ANTHROPIC_AUTH_TOKEN` | _(必填)_ | 灵眸 API Key,从 [lmuai.com](https://lmuai.com) 获取 |
|
||||
| `ANTHROPIC_BASE_URL` | `https://api.lmuai.com` | 灵眸 API 基础 URL |
|
||||
| `CLAUDE_MODEL` | `claude-sonnet-4-6` | 可选:`claude-sonnet-4-6` / `claude-opus-4-7` / `claude-sonnet-4-5` / `claude-haiku-4-5` |
|
||||
|
||||
> **灵眸模式自动写入 `settings.json` 的 env 参数**:
|
||||
> | 参数 | 值 | 说明 |
|
||||
> |------|----|------|
|
||||
> | `ANTHROPIC_BASE_URL` | `https://api.lmuai.com` | API 端点 |
|
||||
> | `ANTHROPIC_AUTH_TOKEN` | _(你的 Key)_ | 认证凭据 |
|
||||
> | `API_TIMEOUT_MS` | `3000000` | 超时 50 分钟,防止长任务中断 |
|
||||
> | `CLAUDE_CODE_ATTRIBUTION_HEADER` | `0` | 关闭来源标识,提高缓存命中率 |
|
||||
> | `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` | `1` | 关闭遥测/自动更新检查 |
|
||||
>
|
||||
> - Token 写入 `settings.json` 的 `env` 块(不写入 `~/.bashrc`,避免与 `ANTHROPIC_API_KEY` 冲突)
|
||||
> - 旧 `ANTHROPIC_API_KEY` / `ANTHROPIC_BASE_URL` 变量从 `~/.bashrc` 自动清除
|
||||
|
||||
### 备选:Anthropic 官方 API
|
||||
|
||||
| 变量 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `ANTHROPIC_API_KEY` | _(空)_ | Anthropic API Key,从 [console.anthropic.com](https://console.anthropic.com) 获取 |
|
||||
| `ANTHROPIC_BASE_URL` | `https://api.anthropic.com` | API 基础 URL;中转代理可改为 DeepSeek 等兼容接口 |
|
||||
| `CLAUDE_MODEL` | `claude-opus-4-5` | 默认使用的模型 |
|
||||
| `ANTHROPIC_BASE_URL` | `https://api.anthropic.com` | API 基础 URL;DeepSeek 等中转可改为对应 URL |
|
||||
| `CLAUDE_MODEL` | `claude-sonnet-4-6` | 默认使用的模型 |
|
||||
|
||||
| 变量 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `WSL_DISTRO` | `Ubuntu` | WSL2 发行版名称 |
|
||||
| `SKIP_WSL_INSTALL` | `false` | `true` 跳过 WSL2 安装步骤 |
|
||||
|
||||
@@ -341,19 +340,17 @@ wsl -d Ubuntu -- bash -c "cd ~/.mcp-servers/unity-mcp-server && git pull && npm
|
||||
|
||||
**问题:npm install 安装超时(国内网络)**
|
||||
```bash
|
||||
# 方案一:通过 v2rayN 代理(推荐)
|
||||
pwsh .\deploy.ps1 -ProxyPort 10809
|
||||
|
||||
# 方案一:在 Windows 侧开启系统代理(v2rayN「设为系统代理」),WSL2 自动继承
|
||||
# 方案二:WSL2 内配置镜像
|
||||
npm config set registry https://registry.npmmirror.com
|
||||
```
|
||||
|
||||
**问题:WSL2 无法连接 v2rayN 代理**
|
||||
**问题:WSL2 无法访问外网**
|
||||
```
|
||||
解决:
|
||||
1. v2rayN → 参数设置 → 勾选「允许来自局域网的连接」
|
||||
2. 确认防火墙未拦截 v2rayN 监听端口
|
||||
3. WSL2 内测试:curl -I https://github.com --proxy http://$(ip route | grep default | awk '{print $3}'):10809
|
||||
1. 确认 Windows 侧代理已开启系统代理(v2rayN → 参数设置 → 勾选「允许来自局域网的连接」)
|
||||
2. 确认 ~/.wslconfig 包含 networkingMode=mirrored 和 autoProxy=true
|
||||
3. 重启 WSL2:wsl --shutdown,再重新启动
|
||||
```
|
||||
|
||||
**问题:Unity 版本兼容性**
|
||||
|
||||
+50
-165
@@ -4,7 +4,6 @@
|
||||
WSL2 + Claude Code CLI + Unity MCP + Rust Token Killer 全栈一键部署脚本
|
||||
.DESCRIPTION
|
||||
自动完成以下步骤:
|
||||
0. 检测 v2rayN 代理端口,配置 Windows & WSL2 两侧代理
|
||||
1. 启用 WSL2 功能 & 安装 Ubuntu 发行版
|
||||
2. 检测/安装 Windows 本机 Node.js(AI 客户端 MCP 需要)
|
||||
3. WSL2 内安装 Node.js LTS(Claude Code CLI 需要)
|
||||
@@ -13,8 +12,6 @@
|
||||
6. 配置 Windows 防火墙放行 MCP Bridge 端口
|
||||
7. 安装 Rust 工具链 & Token Killer (rtk)
|
||||
8. 写入 PowerShell Profile 快捷命令
|
||||
.PARAMETER ProxyPort
|
||||
v2rayN HTTP 代理端口;0 = 自动检测;-1 = 跳过代理
|
||||
.PARAMETER BridgePort
|
||||
Unity MCP Bridge 端口,默认 7890
|
||||
.PARAMETER InstallDir
|
||||
@@ -30,7 +27,6 @@
|
||||
已有 WSL2 可普通终端运行,加 -SkipWSL 跳过 WSL2 安装检查。
|
||||
#>
|
||||
param(
|
||||
[int] $ProxyPort = 0,
|
||||
[int] $BridgePort = 7890,
|
||||
[string]$InstallDir = "$env:USERPROFILE\unity-mcp-server",
|
||||
[string]$UnityHubPath = "C:\Program Files\Unity Hub\Unity Hub.exe",
|
||||
@@ -78,108 +74,25 @@ if (Test-Path $EnvFile) {
|
||||
}
|
||||
|
||||
$ANTHROPIC_API_KEY = if ($Config["ANTHROPIC_API_KEY"]) { $Config["ANTHROPIC_API_KEY"] } else { "" }
|
||||
$ANTHROPIC_BASE_URL = if ($Config["ANTHROPIC_BASE_URL"]) { $Config["ANTHROPIC_BASE_URL"] } else { "https://api.anthropic.com" }
|
||||
$CLAUDE_MODEL = if ($Config["CLAUDE_MODEL"]) { $Config["CLAUDE_MODEL"] } else { "claude-opus-4-5" }
|
||||
$ANTHROPIC_AUTH_TOKEN = if ($Config["ANTHROPIC_AUTH_TOKEN"]) { $Config["ANTHROPIC_AUTH_TOKEN"] } else { "" }
|
||||
$ANTHROPIC_BASE_URL = if ($Config["ANTHROPIC_BASE_URL"]) { $Config["ANTHROPIC_BASE_URL"] } else { "https://api.lmuai.com" }
|
||||
$CLAUDE_MODEL = if ($Config["CLAUDE_MODEL"]) { $Config["CLAUDE_MODEL"] } else { "claude-sonnet-4-6" }
|
||||
$WSL_DISTRO = if ($Config["WSL_DISTRO"]) { $Config["WSL_DISTRO"] } else { "Ubuntu" }
|
||||
$SKIP_WSL_INSTALL = if ($Config["SKIP_WSL_INSTALL"]) { $Config["SKIP_WSL_INSTALL"] } else { "false" }
|
||||
|
||||
# 判断认证方式:灵眸/中转用 AUTH_TOKEN,官方用 API_KEY
|
||||
$UseLmuAuth = ($ANTHROPIC_AUTH_TOKEN -ne "" -and $ANTHROPIC_BASE_URL -ne "https://api.anthropic.com")
|
||||
|
||||
# ──────────────────────────────────────────────────────────────
|
||||
# Banner
|
||||
# ──────────────────────────────────────────────────────────────
|
||||
Write-Host ""
|
||||
Write-Host "╔══════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
|
||||
Write-Host "║ WSL2 + Claude Code CLI + Unity MCP + RTK 全栈部署 ║" -ForegroundColor Cyan
|
||||
Write-Host "║ AnkleBreaker Unity MCP · v2rayN 代理自动检测 ║" -ForegroundColor Cyan
|
||||
Write-Host "║ AnkleBreaker Unity MCP · WSL2 Mirror Mode ║" -ForegroundColor Cyan
|
||||
Write-Host "╚══════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Step 0: v2rayN 代理检测与配置
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
Write-Step "0/8 v2rayN 代理检测"
|
||||
|
||||
# ── 检测代理端口 ──────────────────────────────────────────────
|
||||
function Get-V2RayNProxyPort {
|
||||
# 1. Windows 系统代理注册表(v2rayN"设为系统代理"时写入)
|
||||
try {
|
||||
$ie = Get-ItemProperty `
|
||||
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" `
|
||||
-ErrorAction SilentlyContinue
|
||||
if ($ie.ProxyEnable -eq 1 -and $ie.ProxyServer -match ":(\d+)") {
|
||||
return [int]$Matches[1]
|
||||
}
|
||||
} catch {}
|
||||
|
||||
# 2. v2rayN 配置文件
|
||||
$cfgPaths = @(
|
||||
"$env:APPDATA\v2rayN\guiNConfig.json",
|
||||
"$env:LOCALAPPDATA\v2rayN\guiNConfig.json"
|
||||
)
|
||||
foreach ($p in $cfgPaths) {
|
||||
if (Test-Path $p) {
|
||||
try {
|
||||
$j = Get-Content $p -Raw | ConvertFrom-Json
|
||||
if ($j.localPort) { return [int]$j.localPort }
|
||||
if ($j.httpPort) { return [int]$j.httpPort }
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
# 3. 探测常用端口
|
||||
foreach ($port in @(10809, 10808, 7890, 1080, 8080)) {
|
||||
try {
|
||||
$tcp = New-Object System.Net.Sockets.TcpClient
|
||||
$ar = $tcp.BeginConnect("127.0.0.1", $port, $null, $null)
|
||||
if ($ar.AsyncWaitHandle.WaitOne(300, $false)) {
|
||||
$tcp.EndConnect($ar); $tcp.Close(); return $port
|
||||
}
|
||||
$tcp.Close()
|
||||
} catch {}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
function Set-WindowsProxy {
|
||||
param([int]$Port)
|
||||
$url = "http://127.0.0.1:$Port"
|
||||
git config --global http.proxy $url 2>$null
|
||||
git config --global https.proxy $url 2>$null
|
||||
& npm config set proxy $url --location global 2>$null
|
||||
& npm config set https-proxy $url --location global 2>$null
|
||||
$env:http_proxy = $url; $env:https_proxy = $url
|
||||
$env:HTTP_PROXY = $url; $env:HTTPS_PROXY = $url
|
||||
Write-OK "Windows git/npm/env 代理 -> $url"
|
||||
}
|
||||
|
||||
function Clear-WindowsProxy {
|
||||
git config --global --unset http.proxy 2>$null
|
||||
git config --global --unset https.proxy 2>$null
|
||||
& npm config delete proxy --location global 2>$null
|
||||
& npm config delete https-proxy --location global 2>$null
|
||||
"http_proxy","https_proxy","HTTP_PROXY","HTTPS_PROXY" |
|
||||
ForEach-Object { Remove-Item "Env:\$_" -ErrorAction SilentlyContinue }
|
||||
}
|
||||
|
||||
$resolvedProxyPort = 0
|
||||
|
||||
if ($ProxyPort -eq -1) {
|
||||
Write-Warn "已跳过代理配置(-ProxyPort -1)"
|
||||
} elseif ($ProxyPort -gt 0) {
|
||||
$resolvedProxyPort = $ProxyPort
|
||||
Set-WindowsProxy -Port $resolvedProxyPort
|
||||
Write-OK "使用指定代理端口: $resolvedProxyPort"
|
||||
} else {
|
||||
$resolvedProxyPort = Get-V2RayNProxyPort
|
||||
if ($resolvedProxyPort -gt 0) {
|
||||
Set-WindowsProxy -Port $resolvedProxyPort
|
||||
Write-OK "自动检测到 v2rayN 代理端口: $resolvedProxyPort"
|
||||
} else {
|
||||
Write-Warn "未检测到活跃代理,将使用直连网络"
|
||||
Write-Warn "如需代理,请指定: pwsh deploy.ps1 -ProxyPort 10809"
|
||||
Write-Warn "⚠ 确保 v2rayN 已开启「允许来自局域网的连接」(WSL2 需要)"
|
||||
}
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Step 1: WSL2 安装
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
@@ -291,39 +204,6 @@ if ($needRestart) {
|
||||
Start-Sleep 3
|
||||
}
|
||||
|
||||
# ── 配置 WSL2 侧代理(持久化到 ~/.bashrc) ───────────────────
|
||||
if ($resolvedProxyPort -gt 0) {
|
||||
Write-Info "配置 WSL2 代理(端口 $resolvedProxyPort)..."
|
||||
|
||||
# mirrored 模式下 127.0.0.1 即 Windows,直接用即可
|
||||
$proxyEnvContent = "# WSL2 mirrored networking: 127.0.0.1 = Windows host`nexport http_proxy=`"http://127.0.0.1:$resolvedProxyPort`"`nexport https_proxy=`"http://127.0.0.1:$resolvedProxyPort`"`nexport HTTP_PROXY=`"http://127.0.0.1:$resolvedProxyPort`"`nexport HTTPS_PROXY=`"http://127.0.0.1:$resolvedProxyPort`"`nexport no_proxy=`"localhost,127.0.0.1,::1`"`n"
|
||||
|
||||
$tmpFile = "$env:TEMP\mcp-proxy.env"
|
||||
$bytes = [System.Text.Encoding]::UTF8.GetBytes($proxyEnvContent)
|
||||
[System.IO.File]::WriteAllBytes($tmpFile, $bytes)
|
||||
Copy-Item $tmpFile "\\wsl.localhost\$WSL_DISTRO\tmp\mcp-proxy-deploy.env" -Force 2>$null
|
||||
|
||||
Invoke-WSL "cp /tmp/mcp-proxy-deploy.env ~/.mcp-proxy.env && chmod 644 ~/.mcp-proxy.env && echo OK" | Out-Null
|
||||
|
||||
# 写入 ~/.bashrc(幂等)
|
||||
Invoke-WSL @'
|
||||
if ! grep -q 'mcp-proxy.env' ~/.bashrc 2>/dev/null; then
|
||||
printf '\n# Unity MCP WSL2 proxy (generated by deploy.ps1)\n[ -f ~/.mcp-proxy.env ] && . ~/.mcp-proxy.env\n' >> ~/.bashrc
|
||||
fi
|
||||
# 立即应用代理并配置 git
|
||||
. ~/.mcp-proxy.env 2>/dev/null || true
|
||||
if [ -n "$http_proxy" ]; then
|
||||
git config --global http.proxy "$http_proxy"
|
||||
git config --global https.proxy "$https_proxy"
|
||||
echo "WSL2 git proxy set: $http_proxy"
|
||||
fi
|
||||
true
|
||||
'@ -IgnoreError | Out-Null
|
||||
|
||||
Write-OK "WSL2 代理已写入 ~/.mcp-proxy.env + ~/.bashrc"
|
||||
Write-Warn "⚠ 请确保 v2rayN 已开启「允许来自局域网的连接」!"
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Step 2: Windows 本机 Node.js 检查(AI 客户端 MCP 需要)
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
@@ -356,13 +236,6 @@ if ($winNode) {
|
||||
}
|
||||
}
|
||||
|
||||
# 对 Windows npm 设置代理
|
||||
if ($resolvedProxyPort -gt 0 -and (Get-Command npm -ErrorAction SilentlyContinue)) {
|
||||
$proxyUrl = "http://127.0.0.1:$resolvedProxyPort"
|
||||
& npm config set proxy $proxyUrl --location global 2>$null
|
||||
& npm config set https-proxy $proxyUrl --location global 2>$null
|
||||
}
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
# Step 3: WSL2 系统依赖 & Node.js
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
@@ -385,7 +258,6 @@ if ($nodeVer -match "v\d+") {
|
||||
} else {
|
||||
Write-Info "安装 WSL2 Node.js LTS (via nvm)..."
|
||||
$installNodeCmd = @'
|
||||
. ~/.mcp-proxy.env 2>/dev/null || true
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
sudo apt-get install -y -qq curl ca-certificates 2>/dev/null
|
||||
# 安装 nvm
|
||||
@@ -437,7 +309,6 @@ if ($claudeVer -notmatch "MISSING") {
|
||||
$installClaudeCmd = @'
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||
. ~/.mcp-proxy.env 2>/dev/null || true
|
||||
npm install -g @anthropic-ai/claude-code --quiet
|
||||
which claude
|
||||
claude --version
|
||||
@@ -510,8 +381,23 @@ $mcpAllowedTools = @(
|
||||
"mcp__unity-mcp__unity_list_instances","mcp__unity-mcp__unity_select_instance",
|
||||
"mcp__unity-mcp__unity_get_project_context"
|
||||
)
|
||||
$claudeSettingsJson = [ordered]@{ model = $CLAUDE_MODEL; allowedTools = $mcpAllowedTools } |
|
||||
ConvertTo-Json -Depth 3
|
||||
$claudeSettingsJson = if ($UseLmuAuth) {
|
||||
# 灵眸 / 中转 API:使用 env.ANTHROPIC_AUTH_TOKEN(避免与 ANTHROPIC_API_KEY 冲突)
|
||||
[ordered]@{
|
||||
env = [ordered]@{
|
||||
ANTHROPIC_BASE_URL = $ANTHROPIC_BASE_URL
|
||||
ANTHROPIC_AUTH_TOKEN = $ANTHROPIC_AUTH_TOKEN
|
||||
API_TIMEOUT_MS = "3000000"
|
||||
CLAUDE_CODE_ATTRIBUTION_HEADER = "0"
|
||||
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"
|
||||
}
|
||||
model = $CLAUDE_MODEL
|
||||
allowedTools = $mcpAllowedTools
|
||||
} | ConvertTo-Json -Depth 4
|
||||
} else {
|
||||
# Anthropic 官方:使用 model + allowedTools,API Key 由环境变量注入
|
||||
[ordered]@{ model = $CLAUDE_MODEL; allowedTools = $mcpAllowedTools } | ConvertTo-Json -Depth 3
|
||||
}
|
||||
$writeClaudeSettingsCmd = @"
|
||||
mkdir -p ~/.claude
|
||||
cat > ~/.claude/settings.json << 'SETTINGS'
|
||||
@@ -522,22 +408,38 @@ true
|
||||
Invoke-WSL $writeClaudeSettingsCmd -IgnoreError | Out-Null
|
||||
|
||||
# 写入 bash 环境变量(WSL2 侧)
|
||||
$profBlock = ""
|
||||
if ($ANTHROPIC_API_KEY) { $profBlock += "export ANTHROPIC_API_KEY='$ANTHROPIC_API_KEY'\n" }
|
||||
if ($ANTHROPIC_BASE_URL) { $profBlock += "export ANTHROPIC_BASE_URL='$ANTHROPIC_BASE_URL'\n" }
|
||||
$profBlock += "export CLAUDE_MODEL='$CLAUDE_MODEL'\n"
|
||||
$addEnvCmd = @"
|
||||
if ! grep -q 'ANTHROPIC_API_KEY' ~/.bashrc 2>/dev/null; then
|
||||
printf '\n# Claude Code CLI\n$profBlock' >> ~/.bashrc
|
||||
fi
|
||||
# 灵眸模式:auth token 已在 settings.json env 块中,清理旧 bashrc 变量避免冲突
|
||||
# 官方模式:写入 ANTHROPIC_API_KEY 到 bashrc
|
||||
$cleanOldVarsCmd = @'
|
||||
sed -i '/ANTHROPIC_API_KEY/d' ~/.bashrc ~/.profile 2>/dev/null || true
|
||||
sed -i '/ANTHROPIC_BASE_URL/d' ~/.bashrc ~/.profile 2>/dev/null || true
|
||||
sed -i '/CLAUDE_MODEL/d' ~/.bashrc ~/.profile 2>/dev/null || true
|
||||
sed -i '/# Claude Code CLI/d' ~/.bashrc ~/.profile 2>/dev/null || true
|
||||
true
|
||||
'@
|
||||
Invoke-WSL $cleanOldVarsCmd -IgnoreError | Out-Null
|
||||
|
||||
if (-not $UseLmuAuth -and $ANTHROPIC_API_KEY) {
|
||||
$profBlock = "export ANTHROPIC_API_KEY='$ANTHROPIC_API_KEY'\n"
|
||||
$profBlock += "export ANTHROPIC_BASE_URL='$ANTHROPIC_BASE_URL'\n"
|
||||
$profBlock += "export CLAUDE_MODEL='$CLAUDE_MODEL'\n"
|
||||
$addEnvCmd = @"
|
||||
printf '\n# Claude Code CLI\n$profBlock' >> ~/.bashrc
|
||||
true
|
||||
"@
|
||||
Invoke-WSL $addEnvCmd -IgnoreError | Out-Null
|
||||
Invoke-WSL $addEnvCmd -IgnoreError | Out-Null
|
||||
}
|
||||
|
||||
# Windows 侧 Claude 配置
|
||||
$claudeDir = "$env:USERPROFILE\.claude"
|
||||
if (-not (Test-Path $claudeDir)) { New-Item -ItemType Directory -Path $claudeDir | Out-Null }
|
||||
$claudeSettingsJson | Set-Content "$claudeDir\settings.json" -Encoding UTF8
|
||||
if ($ANTHROPIC_API_KEY) {
|
||||
if ($UseLmuAuth) {
|
||||
# 灵眸:token 已在 settings.json 中,清除可能冲突的 Windows 用户级变量
|
||||
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $null, "User")
|
||||
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", $null, "User")
|
||||
[System.Environment]::SetEnvironmentVariable("CLAUDE_MODEL", $null, "User")
|
||||
} elseif ($ANTHROPIC_API_KEY) {
|
||||
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $ANTHROPIC_API_KEY, "User")
|
||||
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", $ANTHROPIC_BASE_URL, "User")
|
||||
[System.Environment]::SetEnvironmentVariable("CLAUDE_MODEL", $CLAUDE_MODEL, "User")
|
||||
@@ -577,7 +479,6 @@ $wslMcpDir = "~/.mcp-servers/unity-mcp-server"
|
||||
$wslMcpCmd = @'
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||
. ~/.mcp-proxy.env 2>/dev/null || true
|
||||
mkdir -p $HOME/.mcp-servers
|
||||
if [ -d $HOME/.mcp-servers/unity-mcp-server/.git ]; then
|
||||
git -C $HOME/.mcp-servers/unity-mcp-server pull --quiet 2>/dev/null || true
|
||||
@@ -665,7 +566,6 @@ Merge-McpConfig "$env:APPDATA\Code\User\mcp.json" $mcpEntry
|
||||
$wslMcpCfgCmd = @"
|
||||
export NVM_DIR="`$HOME/.nvm"
|
||||
[ -s "`$NVM_DIR/nvm.sh" ] && . "`$NVM_DIR/nvm.sh"
|
||||
. ~/.mcp-proxy.env 2>/dev/null || true
|
||||
# 先移除旧条目(幂等),再添加
|
||||
claude mcp remove unity-mcp --scope user 2>/dev/null || true
|
||||
claude mcp add --scope user unity-mcp node $wslScript -e UNITY_BRIDGE_PORT=$BridgePort
|
||||
@@ -730,8 +630,6 @@ if ($rustVer -notmatch "MISSING") {
|
||||
Write-Info "安装 Rust 工具链..."
|
||||
$installRustCmd = @"
|
||||
sudo apt-get install -y -qq build-essential pkg-config libssl-dev 2>/dev/null || true
|
||||
# mirrored 模式下直接用 127.0.0.1,rustup 用 env 代理
|
||||
. ~/.mcp-proxy.env 2>/dev/null || true
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh
|
||||
sh /tmp/rustup-init.sh -y --default-toolchain stable --no-modify-path
|
||||
source ~/.cargo/env
|
||||
@@ -750,15 +648,7 @@ if ($rtkVer -notmatch "MISSING") {
|
||||
Write-Info "安装 rtk (Rust Token Killer)..."
|
||||
$installRtkCmd = @"
|
||||
. ~/.cargo/env 2>/dev/null || true
|
||||
# mirrored 模式:CARGO_NET_GIT_FETCH_WITH_CLI 让 cargo 用系统 git(走代理)
|
||||
# 但 git clone 到 github 时用直连(git proxy 不影响 https)
|
||||
_saved_http=`$(git config --global http.proxy 2>/dev/null)
|
||||
_saved_https=`$(git config --global https.proxy 2>/dev/null)
|
||||
git config --global --unset http.proxy 2>/dev/null || true
|
||||
git config --global --unset https.proxy 2>/dev/null || true
|
||||
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo install --git https://github.com/rtk-ai/rtk 2>&1 | tail -5
|
||||
[ -n "`$_saved_http" ] && git config --global http.proxy "`$_saved_http" || true
|
||||
[ -n "`$_saved_https" ] && git config --global https.proxy "`$_saved_https" || true
|
||||
"@
|
||||
Invoke-WSL $installRtkCmd -IgnoreError
|
||||
$rtkCheck = Invoke-WSL ". ~/.cargo/env 2>/dev/null; rtk --version 2>/dev/null || echo FAILED" -IgnoreError
|
||||
@@ -829,11 +719,6 @@ foreach ($it in $items) {
|
||||
Write-Host (" {0,-16} {1}" -f $it[0], $(if ($it[1]) { $it[1] } else { "(未安装)" })) -ForegroundColor White
|
||||
}
|
||||
|
||||
if ($resolvedProxyPort -gt 0) {
|
||||
Write-Host ""
|
||||
Write-Host " v2rayN 代理 127.0.0.1:$resolvedProxyPort (WSL2 通过 Windows 主机 IP 访问)" -ForegroundColor DarkGray
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host " ━━━━ 后续步骤 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Cyan
|
||||
Write-Host " 1) 在 Unity 项目中安装 MCP Plugin(每个项目一次):" -ForegroundColor White
|
||||
|
||||
Reference in New Issue
Block a user