mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
feat: 更新 CLI 工具配置管理,优化配置读取和保存策略
This commit is contained in:
@@ -1,23 +1,26 @@
|
|||||||
# Claude Instructions
|
# Claude Instructions
|
||||||
|
|
||||||
|
|
||||||
- **CLI Tools Usage**: @~/.claude/workflows/cli-tools-usage.md
|
|
||||||
- **Coding Philosophy**: @~/.claude/workflows/coding-philosophy.md
|
- **Coding Philosophy**: @~/.claude/workflows/coding-philosophy.md
|
||||||
- **Context Requirements**: @~/.claude/workflows/context-tools.md
|
|
||||||
- **File Modification**: @~/.claude/workflows/file-modification.md
|
|
||||||
- **CLI Endpoints Config**: @.claude/cli-tools.json
|
|
||||||
|
|
||||||
## CLI Endpoints
|
## CLI Endpoints
|
||||||
|
|
||||||
**Strictly follow the @.claude/cli-tools.json configuration**
|
- **CLI Tools Usage**: @~/.claude/workflows/cli-tools-usage.md
|
||||||
|
- **CLI Endpoints Config**: @~/.claude/cli-tools.json
|
||||||
|
|
||||||
|
**Strictly follow the cli-tools.json configuration**
|
||||||
|
|
||||||
Available CLI endpoints are dynamically defined by the config file:
|
Available CLI endpoints are dynamically defined by the config file:
|
||||||
- Built-in tools and their enable/disable status
|
- Built-in tools and their enable/disable status
|
||||||
- Custom API endpoints registered via the Dashboard
|
- Custom API endpoints registered via the Dashboard
|
||||||
- Managed through the CCW Dashboard Status page
|
- Managed through the CCW Dashboard Status page
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Tool Execution
|
## Tool Execution
|
||||||
|
|
||||||
|
- **Context Requirements**: @~/.claude/workflows/context-tools.md
|
||||||
|
- **File Modification**: @~/.claude/workflows/file-modification.md
|
||||||
|
|
||||||
### Agent Calls
|
### Agent Calls
|
||||||
- **Always use `run_in_background: false`** for Task tool agent calls: `Task({ subagent_type: "xxx", prompt: "...", run_in_background: false })` to ensure synchronous execution and immediate result visibility
|
- **Always use `run_in_background: false`** for Task tool agent calls: `Task({ subagent_type: "xxx", prompt: "...", run_in_background: false })` to ensure synchronous execution and immediate result visibility
|
||||||
- **TaskOutput usage**: Only use `TaskOutput({ task_id: "xxx", block: false })` + sleep loop to poll completion status. NEVER read intermediate output during agent/CLI execution - wait for final result only
|
- **TaskOutput usage**: Only use `TaskOutput({ task_id: "xxx", block: false })` + sleep loop to poll completion status. NEVER read intermediate output during agent/CLI execution - wait for final result only
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* Claude CLI Tools Configuration Manager
|
* Claude CLI Tools Configuration Manager
|
||||||
* Manages .claude/cli-tools.json (tools) and .claude/cli-settings.json (settings)
|
* Manages .claude/cli-tools.json (tools) and .claude/cli-settings.json (settings)
|
||||||
* with fallback:
|
*
|
||||||
* 1. Project workspace: {projectDir}/.claude/ (priority)
|
* Configuration Strategy:
|
||||||
|
* - READ: Project → Global → Default (fallback chain)
|
||||||
|
* - CREATE: Always in ~/.claude/ (global user-level config)
|
||||||
|
* - SAVE: Based on source (project config saves to project, others to global)
|
||||||
|
*
|
||||||
|
* Read priority:
|
||||||
|
* 1. Project workspace: {projectDir}/.claude/ (if exists)
|
||||||
* 2. Global: ~/.claude/ (fallback)
|
* 2. Global: ~/.claude/ (fallback)
|
||||||
*/
|
*/
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
@@ -295,12 +301,12 @@ function migrateConfig(config: any, projectDir: string): ClaudeCliToolsConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure CLI tools configuration file exists
|
* Ensure CLI tools configuration file exists
|
||||||
* Creates default config if missing (auto-rebuild feature)
|
* Creates default config in global ~/.claude directory (user-level config)
|
||||||
* @param projectDir - Project directory path
|
* @param projectDir - Project directory path (used for reading existing project config)
|
||||||
* @param createInProject - If true, create in project dir; if false, create in global dir
|
* @param createInProject - DEPRECATED: Always creates in global dir. Kept for backward compatibility.
|
||||||
* @returns The config that was created/exists
|
* @returns The config that was created/exists
|
||||||
*/
|
*/
|
||||||
export function ensureClaudeCliTools(projectDir: string, createInProject: boolean = true): ClaudeCliToolsConfig & { _source?: string } {
|
export function ensureClaudeCliTools(projectDir: string, createInProject: boolean = false): ClaudeCliToolsConfig & { _source?: string } {
|
||||||
const resolved = resolveConfigPath(projectDir);
|
const resolved = resolveConfigPath(projectDir);
|
||||||
|
|
||||||
if (resolved.source !== 'default') {
|
if (resolved.source !== 'default') {
|
||||||
@@ -308,25 +314,12 @@ export function ensureClaudeCliTools(projectDir: string, createInProject: boolea
|
|||||||
return loadClaudeCliTools(projectDir);
|
return loadClaudeCliTools(projectDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config doesn't exist - create default
|
// Config doesn't exist - create in global directory only
|
||||||
console.log('[claude-cli-tools] Config not found, creating default cli-tools.json');
|
console.log('[claude-cli-tools] Config not found, creating default cli-tools.json in ~/.claude');
|
||||||
|
|
||||||
const defaultConfig: ClaudeCliToolsConfig = { ...DEFAULT_TOOLS_CONFIG };
|
const defaultConfig: ClaudeCliToolsConfig = { ...DEFAULT_TOOLS_CONFIG };
|
||||||
|
|
||||||
if (createInProject) {
|
// Always create in global directory (user-level config)
|
||||||
// Create in project directory
|
|
||||||
ensureClaudeDir(projectDir);
|
|
||||||
const projectPath = getProjectConfigPath(projectDir);
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(projectPath, JSON.stringify(defaultConfig, null, 2), 'utf-8');
|
|
||||||
console.log(`[claude-cli-tools] Created default config at: ${projectPath}`);
|
|
||||||
return { ...defaultConfig, _source: 'project' };
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[claude-cli-tools] Failed to create project config:', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: create in global directory
|
|
||||||
const globalDir = path.join(os.homedir(), '.claude');
|
const globalDir = path.join(os.homedir(), '.claude');
|
||||||
if (!fs.existsSync(globalDir)) {
|
if (!fs.existsSync(globalDir)) {
|
||||||
fs.mkdirSync(globalDir, { recursive: true });
|
fs.mkdirSync(globalDir, { recursive: true });
|
||||||
@@ -405,14 +398,28 @@ export function loadClaudeCliTools(projectDir: string): ClaudeCliToolsConfig & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save CLI tools configuration to project .claude/cli-tools.json
|
* Save CLI tools configuration
|
||||||
|
* - If config was loaded from project, saves to project
|
||||||
|
* - Otherwise saves to global ~/.claude/cli-tools.json
|
||||||
*/
|
*/
|
||||||
export function saveClaudeCliTools(projectDir: string, config: ClaudeCliToolsConfig & { _source?: string }): void {
|
export function saveClaudeCliTools(projectDir: string, config: ClaudeCliToolsConfig & { _source?: string }): void {
|
||||||
ensureClaudeDir(projectDir);
|
|
||||||
const configPath = getProjectConfigPath(projectDir);
|
|
||||||
|
|
||||||
const { _source, ...configToSave } = config;
|
const { _source, ...configToSave } = config;
|
||||||
|
|
||||||
|
// Determine save location based on source
|
||||||
|
let configPath: string;
|
||||||
|
if (_source === 'project') {
|
||||||
|
// Config was loaded from project, save back to project
|
||||||
|
ensureClaudeDir(projectDir);
|
||||||
|
configPath = getProjectConfigPath(projectDir);
|
||||||
|
} else {
|
||||||
|
// Default: save to global directory
|
||||||
|
const globalDir = path.join(os.homedir(), '.claude');
|
||||||
|
if (!fs.existsSync(globalDir)) {
|
||||||
|
fs.mkdirSync(globalDir, { recursive: true });
|
||||||
|
}
|
||||||
|
configPath = getGlobalConfigPath();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(configPath, JSON.stringify(configToSave, null, 2), 'utf-8');
|
fs.writeFileSync(configPath, JSON.stringify(configToSave, null, 2), 'utf-8');
|
||||||
console.log(`[claude-cli-tools] Saved tools config to: ${configPath}`);
|
console.log(`[claude-cli-tools] Saved tools config to: ${configPath}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user