opencode-cursor-agent/README.md

144 lines
4.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Cursor API Proxy
[English](./README.md) | 繁體中文
一個讓你可以透過標準 OpenAI/Anthropic API 格式存取 Cursor AI 編輯器的代理伺服器。
## 功能特色
- **API 相容**:支援 OpenAI 格式和 Anthropic 格式的 API 呼叫
- **多帳號管理**:支援新增、移除、切換多個 Cursor 帳號
- **Tailscale 支援**:可綁定到 `0.0.0.0` 供區域網路存取
- **HWID 重置**:內建反偵測功能,可重置機器識別碼
- **連線池**:最佳化的連線管理
## 安裝
```bash
git clone https://github.com/your-repo/cursor-api-proxy-go.git
cd cursor-api-proxy-go
go build -o cursor-api-proxy .
```
## 使用方式
### 啟動伺服器
```bash
./cursor-api-proxy
```
預設監聽 `127.0.0.1:8080`
### 登入帳號
```bash
# 登入帳號
./cursor-api-proxy login myaccount
# 使用代理登入
./cursor-api-proxy login myaccount --proxy=http://127.0.0.1:7890
```
### 列出帳號
```bash
./cursor-api-proxy accounts
```
### 登出帳號
```bash
./cursor-api-proxy logout myaccount
```
### 重置 HWID反BAN
```bash
# 基本重置
./cursor-api-proxy reset-hwid
# 深度清理(清除 session 和 cookies
./cursor-api-proxy reset-hwid --deep-clean
```
### 其他選項
| 選項 | 說明 |
|------|------|
| `--tailscale` | 綁定到 `0.0.0.0` 供區域網路存取 |
| `-h, --help` | 顯示說明 |
## API 端點
| 端點 | 方法 | 說明 |
|------|------|------|
| `http://127.0.0.1:8080/v1/chat/completions` | POST | OpenAI 格式聊天完成 |
| `http://127.0.0.1:8080/v1/models` | GET | 列出可用模型 |
| `http://127.0.0.1:8080/v1/chat/messages` | POST | Anthropic 格式聊天 |
| `http://127.0.0.1:8080/health` | GET | 健康檢查 |
## 環境變數
### 伺服器設定
| 變數 | 預設值 | 說明 |
|------|--------|------|
| `CURSOR_BRIDGE_HOST` | `127.0.0.1` | 監聽位址(設為 `0.0.0.0` 可供區域網路存取) |
| `CURSOR_BRIDGE_PORT` | `8765` | 監聽連接埠 |
| `CURSOR_BRIDGE_API_KEY` | _(無)_ | API 鑑別金鑰,設定後所有請求需帶此金鑰 |
| `CURSOR_BRIDGE_TIMEOUT_MS` | `300000` | 請求逾時毫秒數(預設 5 分鐘) |
| `CURSOR_BRIDGE_MULTI_PORT` | `false` | 啟用多連接埠模式 |
| `CURSOR_BRIDGE_VERBOSE` | `false` | 啟用詳細日誌輸出 |
### Agent / 模型設定
| 變數 | 預設值 | 說明 |
|------|--------|------|
| `CURSOR_AGENT_BIN` / `CURSOR_CLI_BIN` / `CURSOR_CLI_PATH` | `agent` | Cursor CLI 二進位檔路徑 |
| `CURSOR_AGENT_NODE` | _(無)_ | Node.js 執行檔路徑Windows 使用) |
| `CURSOR_AGENT_SCRIPT` | _(無)_ | Agent 腳本路徑Windows 使用) |
| `CURSOR_BRIDGE_DEFAULT_MODEL` | `auto` | 預設使用的模型 ID |
| `CURSOR_BRIDGE_STRICT_MODEL` | `true` | 嚴格模式:禁止使用不在清單中的模型 |
| `CURSOR_BRIDGE_MAX_MODE` | `false` | 啟用 Max Mode消耗更多額度 |
| `CURSOR_BRIDGE_FORCE` | `false` | 強制執行,不詢問確認 |
| `CURSOR_BRIDGE_APPROVE_MCPS` | `false` | 自動核准 MCP 工具呼叫 |
### 工作區與帳號
| 變數 | 預設值 | 說明 |
|------|--------|------|
| `CURSOR_BRIDGE_WORKSPACE` | _(目前目錄)_ | 工作目錄路徑 |
| `CURSOR_BRIDGE_CHAT_ONLY_WORKSPACE` | `true` | 限制 agent 只能存取工作目錄 |
| `CURSOR_CONFIG_DIRS` / `CURSOR_ACCOUNT_DIRS` | _(自動探索)_ | 帳號設定目錄,多個用逗號分隔 |
### TLS / HTTPS
| 變數 | 預設值 | 說明 |
|------|--------|------|
| `CURSOR_BRIDGE_TLS_CERT` | _(無)_ | TLS 憑證檔路徑(啟用 HTTPS |
| `CURSOR_BRIDGE_TLS_KEY` | _(無)_ | TLS 私鑰檔路徑(啟用 HTTPS |
### 記錄與 Windows 特定
| 變數 | 預設值 | 說明 |
|------|--------|------|
| `CURSOR_BRIDGE_SESSIONS_LOG` | `~/.cursor-api-proxy/sessions.log` | Session 記錄檔路徑 |
| `CURSOR_BRIDGE_WIN_CMDLINE_MAX` | `30000` | Windows 命令列最大長度409632700 |
| `COMSPEC` | `cmd.exe` | Windows 命令直譯器路徑 |
## 常見問題
**Q: 為什麼需要登入帳號?**
A: Cursor API 需要驗證才能使用,請先登入你的 Cursor 帳號。
**Q: 如何處理被BAN的問題**
A: 使用 `reset-hwid` 命令重置機器識別碼,加上 `--deep-clean` 進行更徹底的清理。
**Q: 可以在其他設備上使用嗎?**
A: 可以,使用 `--tailscale` 選項啟動伺服器,然後透過區域網路 IP 存取。
## 授權
MIT License