mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
fix: auto-sync CLI tools availability on first config creation (Issue #95)
**问题描述**: 新安装 CCW 后,默认配置中所有 CLI 工具 enabled: true,但实际上用户可能没有安装这些工具,导致执行任务时尝试调用未安装的工具而失败。 **根本原因**: - DEFAULT_TOOLS_CONFIG 中所有工具默认 enabled: true - 首次创建配置时不检测工具实际可用性 - 现有的 syncBuiltinToolsAvailability() 只在用户手动触发时才执行 **修复内容**: 1. 新增 ensureClaudeCliToolsAsync() 异步版本 - 在创建默认配置后自动调用 syncBuiltinToolsAvailability() - 通过 which/where 命令检测工具实际可用性 - 根据检测结果自动调整 enabled 状态 2. 更新两个关键 API 端点使用新函数 - /api/cli/endpoints - 获取 API 端点列表 - /api/cli/tools-config - 获取 CLI 工具配置 **效果**: - 首次安装时自动检测并禁用未安装的工具 - 避免调用不可用工具导致的错误 - 用户可在 Dashboard 中看到准确的工具状态 Fixes #95
This commit is contained in:
@@ -35,6 +35,7 @@ import {
|
||||
import {
|
||||
loadClaudeCliTools,
|
||||
ensureClaudeCliTools,
|
||||
ensureClaudeCliToolsAsync,
|
||||
saveClaudeCliTools,
|
||||
loadClaudeCliSettings,
|
||||
saveClaudeCliSettings,
|
||||
@@ -329,16 +330,18 @@ export async function handleCliRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
|
||||
// API: Get all API endpoints (for --tool custom --model <id>)
|
||||
if (pathname === '/api/cli/endpoints' && req.method === 'GET') {
|
||||
try {
|
||||
// Use ensureClaudeCliTools to auto-create config if missing
|
||||
const config = ensureClaudeCliTools(initialPath);
|
||||
const endpoints = getApiEndpointsFromTools(config);
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ endpoints }));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: (err as Error).message }));
|
||||
}
|
||||
(async () => {
|
||||
try {
|
||||
// Use ensureClaudeCliToolsAsync to auto-create config with availability sync
|
||||
const config = await ensureClaudeCliToolsAsync(initialPath);
|
||||
const endpoints = getApiEndpointsFromTools(config);
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ endpoints }));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: (err as Error).message }));
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -820,21 +823,23 @@ export async function handleCliRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
|
||||
// API: Get CLI Tools Config from .claude/cli-tools.json (with fallback to global)
|
||||
if (pathname === '/api/cli/tools-config' && req.method === 'GET') {
|
||||
try {
|
||||
// Use ensureClaudeCliTools to auto-create config if missing
|
||||
const toolsConfig = ensureClaudeCliTools(initialPath);
|
||||
const settingsConfig = loadClaudeCliSettings(initialPath);
|
||||
const info = getClaudeCliToolsInfo(initialPath);
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
tools: toolsConfig,
|
||||
settings: settingsConfig,
|
||||
_configInfo: info
|
||||
}));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: (err as Error).message }));
|
||||
}
|
||||
(async () => {
|
||||
try {
|
||||
// Use ensureClaudeCliToolsAsync to auto-create config with availability sync
|
||||
const toolsConfig = await ensureClaudeCliToolsAsync(initialPath);
|
||||
const settingsConfig = loadClaudeCliSettings(initialPath);
|
||||
const info = getClaudeCliToolsInfo(initialPath);
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
tools: toolsConfig,
|
||||
settings: settingsConfig,
|
||||
_configInfo: info
|
||||
}));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: (err as Error).message }));
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user