Compare commits
9 Commits
07bb207ff3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c661ec06a | |||
| 872df0fd65 | |||
| 505881edef | |||
| c5591f8936 | |||
| b7a73c4b15 | |||
| 4b74fa615a | |||
| dcf190067c | |||
| a816e9cd91 | |||
| afd408a4b8 |
@@ -23,8 +23,8 @@ jobs:
|
|||||||
- name: 拉取代码
|
- name: 拉取代码
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.PAT_WITH_BYPASS }} # 使用具有绕过保护权限的 PAT
|
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
ref: ${{ github.head_ref }}
|
||||||
|
|
||||||
- name: 配置 Git
|
- name: 配置 Git
|
||||||
run: |
|
run: |
|
||||||
@@ -34,35 +34,50 @@ jobs:
|
|||||||
|
|
||||||
# 配置用户信息
|
# 配置用户信息
|
||||||
git config --global user.name "devstar"
|
git config --global user.name "devstar"
|
||||||
git config --global user.email "devstar@noreply.github.com"
|
git config --global user.email "devstar@noreply.devstar.cn"
|
||||||
|
|
||||||
- name: 自动递增版本号
|
- name: Check and bump version
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'pull_request'
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache jq
|
apk add --no-cache jq
|
||||||
CURRENT_VERSION=$(jq -r '.version' package.json)
|
# 获取远程 main 分支版本
|
||||||
echo "当前版本: $CURRENT_VERSION"
|
git fetch origin main
|
||||||
|
MAIN_VERSION=$(git show origin/main:package.json | jq -r '.version')
|
||||||
|
PR_VERSION=$(jq -r '.version' package.json)
|
||||||
|
|
||||||
# 分解版本号(使用 sh 兼容的语法)
|
echo "Main 分支版本: $MAIN_VERSION"
|
||||||
MAJOR=$(echo "$CURRENT_VERSION" | cut -d'.' -f1)
|
echo "当前 PR 版本: $PR_VERSION"
|
||||||
MINOR=$(echo "$CURRENT_VERSION" | cut -d'.' -f2)
|
|
||||||
PATCH=$(echo "$CURRENT_VERSION" | cut -d'.' -f3)
|
|
||||||
|
|
||||||
# 递增补丁版本号
|
# 如果版本号相同,则递增
|
||||||
NEW_PATCH=$((PATCH + 1))
|
if [ "$MAIN_VERSION" = "$PR_VERSION" ]; then
|
||||||
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
|
echo "版本号未变更,开始递增..."
|
||||||
echo "新版本: $NEW_VERSION"
|
|
||||||
|
|
||||||
# 更新 package.json
|
# 分解版本号
|
||||||
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
|
MAJOR=$(echo "$PR_VERSION" | cut -d'.' -f1)
|
||||||
mv package.json.tmp package.json
|
MINOR=$(echo "$PR_VERSION" | cut -d'.' -f2)
|
||||||
|
PATCH=$(echo "$PR_VERSION" | cut -d'.' -f3)
|
||||||
|
|
||||||
# 提交版本变更(包含 [skip ci] 避免触发循环构建)
|
# 递增补丁版本号
|
||||||
git add package.json
|
NEW_PATCH=$((PATCH + 1))
|
||||||
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
|
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
|
||||||
|
echo "新版本: $NEW_VERSION"
|
||||||
|
|
||||||
# 推送到保护分支(需要 PAT_WITH_BYPASS 有绕过保护的权限)
|
# 更新 package.json
|
||||||
git push
|
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
|
||||||
|
mv package.json.tmp package.json
|
||||||
|
|
||||||
|
# 提交版本变更
|
||||||
|
git config user.name "devstar-actions"
|
||||||
|
git config user.email "devstar-actions@devstar.cn"
|
||||||
|
git add package.json
|
||||||
|
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
|
||||||
|
|
||||||
|
# 推送到当前分支
|
||||||
|
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
git push origin $BRANCH_NAME || git push origin HEAD:refs/heads/$BRANCH_NAME
|
||||||
|
else
|
||||||
|
echo "版本号已更新,跳过递增"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: 安装依赖
|
- name: 安装依赖
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "devstar",
|
"name": "devstar",
|
||||||
"displayName": "%displayName%",
|
"displayName": "%displayName%",
|
||||||
"description": "%description%",
|
"description": "%description%",
|
||||||
"version": "0.5.2",
|
"version": "0.5.3",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"publisher": "mengning",
|
"publisher": "mengning",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -379,6 +379,22 @@ export default class RemoteContainer {
|
|||||||
} catch (portError) {
|
} catch (portError) {
|
||||||
vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立');
|
vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动配置本地 VSCode 的 MCP Server
|
||||||
|
try {
|
||||||
|
await this.configureMCPServerLocally();
|
||||||
|
} catch (mcpError) {
|
||||||
|
console.error('[MCP] 本地 MCP 配置失败:', mcpError);
|
||||||
|
// 不阻塞主流程,仅记录错误
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动配置容器内 AI IDE 的 MCP Server
|
||||||
|
try {
|
||||||
|
await this.configureMCPServerInContainer(sshConfig.hostname, port);
|
||||||
|
} catch (mcpError) {
|
||||||
|
console.error('[MCP] 容器内 MCP 配置失败:', mcpError);
|
||||||
|
// 不阻塞主流程,仅记录错误
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用 VSCode Extension API 打开远程连接
|
// 使用 VSCode Extension API 打开远程连接
|
||||||
@@ -478,6 +494,232 @@ export default class RemoteContainer {
|
|||||||
console.log('未找到 forwardPorts 参数,跳过端口映射设置。');
|
console.log('未找到 forwardPorts 参数,跳过端口映射设置。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在容器内配置 AI IDE 的 MCP Server
|
||||||
|
* 支持 Trae IDE 等 AI IDE 的 MCP 自动配置
|
||||||
|
*/
|
||||||
|
private async configureMCPServerInContainer(hostname: string, sshPort: number): Promise<void> {
|
||||||
|
// 获取用户 token
|
||||||
|
const userToken = this.user.getUserTokenFromLocal();
|
||||||
|
if (!userToken) {
|
||||||
|
console.log('[MCP] 用户未登录,跳过 MCP Server 配置');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取 DevStar 域名
|
||||||
|
const devstarDomain = this.user.getDevstarDomain();
|
||||||
|
const mcpUrl = `${devstarDomain}/api/mcp`;
|
||||||
|
|
||||||
|
console.log(`[MCP] 开始配置 MCP Server: ${mcpUrl}`);
|
||||||
|
|
||||||
|
// Trae IDE 的 MCP 配置路径
|
||||||
|
const traeMcpPath = '/root/.trae-server/data/Machine/mcp.json';
|
||||||
|
|
||||||
|
// MCP 配置内容(注意:使用 "mcpServers" 格式)
|
||||||
|
const mcpConfig = {
|
||||||
|
mcpServers: {
|
||||||
|
devstar: {
|
||||||
|
type: 'http',
|
||||||
|
url: mcpUrl,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${userToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const configJson = JSON.stringify(mcpConfig, null, 2);
|
||||||
|
|
||||||
|
// 使用 SSH 连接到容器并配置
|
||||||
|
const ssh = new NodeSSH();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await ssh.connect({
|
||||||
|
host: hostname,
|
||||||
|
username: 'root',
|
||||||
|
port: sshPort,
|
||||||
|
privateKeyPath: this.user.getUserPrivateKeyPath(),
|
||||||
|
readyTimeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('[MCP] SSH 连接成功');
|
||||||
|
|
||||||
|
// 检查现有配置
|
||||||
|
const checkScript = `
|
||||||
|
if [ -f "${traeMcpPath}" ]; then
|
||||||
|
cat "${traeMcpPath}"
|
||||||
|
else
|
||||||
|
echo "FILE_NOT_EXISTS"
|
||||||
|
fi
|
||||||
|
`;
|
||||||
|
|
||||||
|
const checkResult = await ssh.execCommand(checkScript);
|
||||||
|
|
||||||
|
let needUpdate = true;
|
||||||
|
|
||||||
|
if (checkResult.stdout !== 'FILE_NOT_EXISTS') {
|
||||||
|
try {
|
||||||
|
const existingConfig = JSON.parse(checkResult.stdout);
|
||||||
|
const existingDevstar = existingConfig.mcpServers?.devstar;
|
||||||
|
|
||||||
|
if (existingDevstar) {
|
||||||
|
// 检查 URL 和 token 是否匹配
|
||||||
|
const urlMatch = existingDevstar.url === mcpUrl;
|
||||||
|
const tokenMatch = existingDevstar.headers?.Authorization === `Bearer ${userToken}`;
|
||||||
|
|
||||||
|
if (urlMatch && tokenMatch) {
|
||||||
|
console.log('[MCP] DevStar MCP 配置已存在且正确,无需更新');
|
||||||
|
needUpdate = false;
|
||||||
|
} else {
|
||||||
|
console.log(`[MCP] DevStar MCP 配置需要更新 (URL匹配: ${urlMatch}, Token匹配: ${tokenMatch})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (parseError) {
|
||||||
|
console.log('[MCP] 解析现有配置失败,将创建新配置');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('[MCP] 容器内无配置文件,需要创建');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建或更新配置文件
|
||||||
|
if (needUpdate) {
|
||||||
|
const setupScript = `
|
||||||
|
mkdir -p /root/.trae-server/data/Machine && \
|
||||||
|
cat > ${traeMcpPath} << 'EOF'
|
||||||
|
${configJson}
|
||||||
|
EOF
|
||||||
|
echo "MCP 配置已更新"
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await ssh.execCommand(setupScript);
|
||||||
|
|
||||||
|
if (result.code === 0) {
|
||||||
|
console.log('[MCP] DevStar MCP 配置成功');
|
||||||
|
} else {
|
||||||
|
console.error(`[MCP] 配置失败: ${result.stderr}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[MCP] SSH 连接或配置失败:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
await ssh.dispose();
|
||||||
|
} catch (e) {
|
||||||
|
// ignore dispose error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在本地 VSCode 中配置 MCP Server
|
||||||
|
* 支持 GitHub Copilot 等使用本地 MCP 配置
|
||||||
|
*/
|
||||||
|
private async configureMCPServerLocally(): Promise<void> {
|
||||||
|
// 获取用户 token
|
||||||
|
const userToken = this.user.getUserTokenFromLocal();
|
||||||
|
if (!userToken) {
|
||||||
|
console.log('[MCP] 用户未登录,跳过本地 MCP Server 配置');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取 DevStar 域名
|
||||||
|
const devstarDomain = this.user.getDevstarDomain();
|
||||||
|
const mcpUrl = `${devstarDomain}/api/mcp`;
|
||||||
|
|
||||||
|
console.log(`[MCP] 开始配置本地 MCP Server: ${mcpUrl}`);
|
||||||
|
|
||||||
|
// 根据操作系统确定配置文件路径
|
||||||
|
let mcpConfigPath: string;
|
||||||
|
const platform = os.platform();
|
||||||
|
const homedir = os.homedir();
|
||||||
|
|
||||||
|
if (platform === 'darwin') {
|
||||||
|
// macOS
|
||||||
|
mcpConfigPath = path.join(homedir, 'Library/Application Support/Code/User/mcp.json');
|
||||||
|
} else if (platform === 'win32') {
|
||||||
|
// Windows
|
||||||
|
mcpConfigPath = path.join(homedir, 'AppData/Roaming/Code/User/mcp.json');
|
||||||
|
} else {
|
||||||
|
// Linux
|
||||||
|
mcpConfigPath = path.join(homedir, '.config/Code/User/mcp.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[MCP] 配置文件路径: ${mcpConfigPath}`);
|
||||||
|
|
||||||
|
// MCP 配置内容(本地 VSCode 使用 "servers" 格式)
|
||||||
|
const mcpConfig = {
|
||||||
|
servers: {
|
||||||
|
devstar: {
|
||||||
|
type: 'http',
|
||||||
|
url: mcpUrl,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${userToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const configJson = JSON.stringify(mcpConfig, null, 2);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 检查现有配置
|
||||||
|
let existingConfig: any = {};
|
||||||
|
let needUpdate = true;
|
||||||
|
|
||||||
|
if (fs.existsSync(mcpConfigPath)) {
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync(mcpConfigPath, 'utf8');
|
||||||
|
existingConfig = JSON.parse(content);
|
||||||
|
const existingDevstar = existingConfig.servers?.devstar;
|
||||||
|
|
||||||
|
if (existingDevstar) {
|
||||||
|
// 检查 URL 和 token 是否匹配
|
||||||
|
const urlMatch = existingDevstar.url === mcpUrl;
|
||||||
|
const tokenMatch = existingDevstar.headers?.Authorization === `Bearer ${userToken}`;
|
||||||
|
|
||||||
|
if (urlMatch && tokenMatch) {
|
||||||
|
console.log('[MCP] 本地 DevStar MCP 配置已存在且正确,无需更新');
|
||||||
|
needUpdate = false;
|
||||||
|
} else {
|
||||||
|
console.log(`[MCP] 本地 DevStar MCP 配置需要更新 (URL匹配: ${urlMatch}, Token匹配: ${tokenMatch})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (parseError) {
|
||||||
|
console.log('[MCP] 解析现有配置失败,将创建新配置');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('[MCP] 本地无配置文件,需要创建');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建或更新配置文件
|
||||||
|
if (needUpdate) {
|
||||||
|
// 确保目录存在
|
||||||
|
const configDir = path.dirname(mcpConfigPath);
|
||||||
|
if (!fs.existsSync(configDir)) {
|
||||||
|
fs.mkdirSync(configDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 合并现有配置(保留其他 MCP servers)
|
||||||
|
const newConfig = {
|
||||||
|
...existingConfig,
|
||||||
|
servers: {
|
||||||
|
...existingConfig.servers,
|
||||||
|
...mcpConfig.servers
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFileSync(mcpConfigPath, JSON.stringify(newConfig, null, 2), 'utf8');
|
||||||
|
console.log('[MCP] 本地 DevStar MCP 配置成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[MCP] 本地 MCP 配置失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user