feat(ccw): 智能识别运行中的服务器,支持工作空间切换

- ccw view 自动检测服务器是否已运行
- 已运行时切换工作空间并打开浏览器,无需重启服务器
- 新增 /api/switch-path 和 /api/health 端点
- Dashboard 支持 URL path 参数加载指定工作空间

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-08 09:56:35 +08:00
parent 0f469e225b
commit a80953527b
4 changed files with 144 additions and 9 deletions

View File

@@ -126,6 +126,40 @@ export async function startServer(options = {}) {
return;
}
// API: Switch workspace path (for ccw view command)
if (pathname === '/api/switch-path') {
const newPath = url.searchParams.get('path');
if (!newPath) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Path is required' }));
return;
}
const resolved = resolvePath(newPath);
if (!existsSync(resolved)) {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Path does not exist' }));
return;
}
// Track the path and return success
trackRecentPath(resolved);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
success: true,
path: resolved,
recentPaths: getRecentPaths()
}));
return;
}
// API: Health check (for ccw view to detect running server)
if (pathname === '/api/health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ status: 'ok', timestamp: Date.now() }));
return;
}
// API: Remove a recent path
if (pathname === '/api/remove-recent-path' && req.method === 'POST') {
handlePostRequest(req, res, async (body) => {