@claude-vector/cli
Version:
CLI for Claude-integrated vector search
152 lines (127 loc) • 3.7 kB
JavaScript
/**
* Config command - Manage configuration
*/
import chalk from 'chalk';
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';
import { spawn } from 'child_process';
export async function configCommand(options) {
const configPath = join(process.cwd(), '.claude-search.config.js');
try {
if (options.show) {
await showConfig(configPath);
} else if (options.edit) {
await editConfig(configPath);
} else if (options.reset) {
await resetConfig(configPath);
} else if (options.set) {
await setConfigValue(configPath, options.set);
} else {
// Default: show config
await showConfig(configPath);
}
// 正常終了
process.exit(0);
} catch (error) {
console.error(chalk.red(`Error: ${error.message}`));
process.exit(1);
}
}
async function showConfig(configPath) {
console.log(chalk.bold('\n⚙️ Configuration\n'));
if (!existsSync(configPath)) {
console.log(chalk.yellow('No configuration file found'));
console.log(chalk.gray('Run'), chalk.cyan('claude-search init'), chalk.gray('to create one'));
return;
}
try {
const content = readFileSync(configPath, 'utf-8');
console.log(content);
} catch (error) {
console.error(chalk.red('Error reading configuration'));
}
}
async function editConfig(configPath) {
if (!existsSync(configPath)) {
console.log(chalk.yellow('No configuration file found'));
console.log(chalk.gray('Run'), chalk.cyan('claude-search init'), chalk.gray('to create one'));
return;
}
// Try to open in editor
const editor = process.env.EDITOR || 'nano';
console.log(chalk.gray(`Opening config in ${editor}...`));
const child = spawn(editor, [configPath], {
stdio: 'inherit'
});
child.on('exit', (code) => {
if (code === 0) {
console.log(chalk.green('✓ Configuration updated'));
} else {
console.log(chalk.yellow('Editor exited with error'));
}
});
}
async function resetConfig(configPath) {
console.log(chalk.yellow('⚠️ This will reset configuration to defaults'));
// Create default config
const defaultConfig = `/**
* Claude Vector Search Configuration
* Generated: ${new Date().toISOString()}
*/
export default {
// File patterns
patterns: {
include: [
'**/*.{js,jsx,ts,tsx}',
'**/*.{md,mdx}',
'**/*.json'
],
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/.next/**',
'**/coverage/**',
'**/.git/**'
]
},
// Embedding settings
embeddings: {
model: 'text-embedding-3-small',
batchSize: 100
},
// Chunk processing
chunks: {
maxSize: 1000,
minSize: 100,
overlap: 200
},
// Search settings
search: {
threshold: 0.7,
maxResults: 10
},
// Features
features: {
autoIndex: true,
cache: true,
persistence: true,
errorAnalysis: true,
workflow: true
}
};
`;
writeFileSync(configPath, defaultConfig);
console.log(chalk.green('✓ Configuration reset to defaults'));
}
async function setConfigValue(configPath, keyValue) {
const [key, value] = keyValue.split('=');
if (!key || value === undefined) {
console.error(chalk.red('Invalid format. Use: --set key=value'));
return;
}
console.log(chalk.gray(`Setting ${key} = ${value}`));
// This is a simplified version - in production, you'd parse and modify the JS file properly
console.log(chalk.yellow('Note: Manual config editing is recommended for complex changes'));
console.log(chalk.gray('Use'), chalk.cyan('claude-search config --edit'), chalk.gray('to edit manually'));
}