增加项目级配置
This commit is contained in:
parent
a3beeb498d
commit
e27bb823c1
1 changed files with 18 additions and 10 deletions
28
src/index.ts
28
src/index.ts
|
|
@ -86,8 +86,9 @@ program
|
||||||
program
|
program
|
||||||
.command('setup')
|
.command('setup')
|
||||||
.description('Run the interactive setup wizard to configure API keys')
|
.description('Run the interactive setup wizard to configure API keys')
|
||||||
.action(async () => {
|
.option('-p, --project', 'Save configuration to project-level (.autoclaw/setting.json)')
|
||||||
await runSetup();
|
.action(async (options) => {
|
||||||
|
await runSetup(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|
@ -100,11 +101,18 @@ program
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
async function runSetup() {
|
async function runSetup(options: any = {}) {
|
||||||
console.log(chalk.bold.cyan("AutoClaw Setup Wizard 🦞\n"));
|
const isProject = options.project;
|
||||||
console.log(chalk.dim(`Config will be saved to: ${GLOBAL_CONFIG_FILE}`));
|
const targetFile = isProject ? LOCAL_CONFIG_FILE : GLOBAL_CONFIG_FILE;
|
||||||
|
const targetDir = isProject ? path.join(process.cwd(), '.autoclaw') : GLOBAL_CONFIG_DIR;
|
||||||
|
|
||||||
const currentConfig = loadJsonConfig(GLOBAL_CONFIG_FILE);
|
console.log(chalk.bold.cyan("AutoClaw Setup Wizard 🦞\n"));
|
||||||
|
console.log(chalk.dim(`Config will be saved to: ${targetFile}`));
|
||||||
|
|
||||||
|
// Load both to show current effective values as defaults
|
||||||
|
const globalConfig = loadJsonConfig(GLOBAL_CONFIG_FILE);
|
||||||
|
const localConfig = loadJsonConfig(LOCAL_CONFIG_FILE);
|
||||||
|
const currentConfig = { ...globalConfig, ...localConfig };
|
||||||
|
|
||||||
function maskSecret(secret?: string): string {
|
function maskSecret(secret?: string): string {
|
||||||
if (!secret || secret.length < 8) return '******';
|
if (!secret || secret.length < 8) return '******';
|
||||||
|
|
@ -282,11 +290,11 @@ async function runSetup() {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(GLOBAL_CONFIG_DIR)) {
|
if (!fs.existsSync(targetDir)) {
|
||||||
fs.mkdirSync(GLOBAL_CONFIG_DIR, { recursive: true });
|
fs.mkdirSync(targetDir, { recursive: true });
|
||||||
}
|
}
|
||||||
fs.writeFileSync(GLOBAL_CONFIG_FILE, JSON.stringify(newConfig, null, 2), { mode: 0o600 });
|
fs.writeFileSync(targetFile, JSON.stringify(newConfig, null, 2), { mode: 0o600 });
|
||||||
console.log(chalk.green(`\n✅ Configuration saved to ${GLOBAL_CONFIG_FILE}`));
|
console.log(chalk.green(`\n✅ Configuration saved to ${targetFile}`));
|
||||||
console.log(chalk.cyan("You can now run 'autoclaw' to start using the agent."));
|
console.log(chalk.cyan("You can now run 'autoclaw' to start using the agent."));
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(chalk.red(`Failed to write config: ${error.message}`));
|
console.error(chalk.red(`Failed to write config: ${error.message}`));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue