autoclaw 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +48 -22
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -6,13 +6,27 @@ import dotenv from 'dotenv';
6
6
  import { Agent } from './agent.js';
7
7
  import * as fs from 'fs';
8
8
  import * as path from 'path';
9
- // Load env vars
9
+ import * as os from 'os';
10
+ const CONFIG_DIR = path.join(os.homedir(), '.autoclaw');
11
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'setting.json');
12
+ function loadGlobalConfig() {
13
+ if (fs.existsSync(CONFIG_FILE)) {
14
+ try {
15
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'));
16
+ }
17
+ catch (e) {
18
+ console.error(chalk.red("Error reading global config file."));
19
+ }
20
+ }
21
+ return {};
22
+ }
23
+ // Load local env vars
10
24
  dotenv.config();
11
25
  const program = new Command();
12
26
  program
13
27
  .name('autoclaw')
14
28
  .description('A lightweight AI agent CLI tool')
15
- .version('1.0.0');
29
+ .version('1.0.1');
16
30
  program
17
31
  .command('setup')
18
32
  .description('Run the interactive setup wizard to configure API keys')
@@ -29,42 +43,55 @@ program
29
43
  program.parse(process.argv);
30
44
  async function runSetup() {
31
45
  console.log(chalk.bold.cyan("AutoClaw Setup Wizard šŸ¦ž\n"));
46
+ console.log(chalk.dim(`Config will be saved to: ${CONFIG_FILE}`));
47
+ const currentConfig = loadGlobalConfig();
32
48
  const answers = await inquirer.prompt([
33
49
  {
34
50
  type: 'password',
35
51
  name: 'apiKey',
36
52
  message: 'Enter your OpenAI API Key:',
53
+ default: currentConfig.apiKey,
37
54
  mask: '*',
38
55
  validate: (input) => input.length > 0 ? true : 'API Key cannot be empty.'
39
56
  },
40
57
  {
41
58
  type: 'input',
42
59
  name: 'baseUrl',
43
- message: 'Enter API Base URL (optional, press Enter for default):',
44
- default: 'https://api.openai.com/v1'
60
+ message: 'Enter API Base URL:',
61
+ default: currentConfig.baseUrl || 'https://api.openai.com/v1'
45
62
  },
46
63
  {
47
64
  type: 'input',
48
65
  name: 'model',
49
66
  message: 'Enter default Model:',
50
- default: 'gpt-4o'
67
+ default: currentConfig.model || 'gpt-4o'
51
68
  }
52
69
  ]);
53
- const envContent = `OPENAI_API_KEY=${answers.apiKey}
54
- OPENAI_BASE_URL=${answers.baseUrl}
55
- OPENAI_MODEL=${answers.model}
56
- `;
57
- const envPath = path.resolve(process.cwd(), '.env');
58
- fs.writeFileSync(envPath, envContent);
59
- console.log(chalk.green(`\nāœ… Configuration saved to ${envPath}`));
60
- console.log(chalk.cyan("You can now run 'autoclaw' to start using the agent."));
70
+ const newConfig = {
71
+ apiKey: answers.apiKey,
72
+ baseUrl: answers.baseUrl,
73
+ model: answers.model
74
+ };
75
+ try {
76
+ if (!fs.existsSync(CONFIG_DIR)) {
77
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
78
+ }
79
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(newConfig, null, 2), { mode: 0o600 });
80
+ console.log(chalk.green(`\nāœ… Configuration saved to ${CONFIG_FILE}`));
81
+ console.log(chalk.cyan("You can now run 'autoclaw' to start using the agent."));
82
+ }
83
+ catch (error) {
84
+ console.error(chalk.red(`Failed to write config: ${error.message}`));
85
+ }
61
86
  }
62
87
  async function runChat(options) {
63
88
  console.log(chalk.bold.cyan("Welcome to AutoClaw CLI šŸ¦ž"));
64
- let apiKey = process.env.OPENAI_API_KEY;
65
- let baseURL = process.env.OPENAI_BASE_URL;
66
- // Priority: CLI arg > Env var > Default
67
- const model = options.model || process.env.OPENAI_MODEL || 'gpt-4o';
89
+ // 1. Load Global (JSON)
90
+ const globalConfig = loadGlobalConfig();
91
+ // 2. Resolve final values (Priority: CLI > Env > Global JSON > Default)
92
+ let apiKey = process.env.OPENAI_API_KEY || globalConfig.apiKey;
93
+ let baseURL = process.env.OPENAI_BASE_URL || globalConfig.baseUrl;
94
+ let model = options.model || process.env.OPENAI_MODEL || globalConfig.model || 'gpt-4o';
68
95
  if (!apiKey) {
69
96
  console.log(chalk.yellow("API Key not found."));
70
97
  const { doSetup } = await inquirer.prompt([
@@ -77,17 +104,16 @@ async function runChat(options) {
77
104
  ]);
78
105
  if (doSetup) {
79
106
  await runSetup();
80
- // Reload env
81
- dotenv.config({ override: true });
82
- apiKey = process.env.OPENAI_API_KEY;
83
- baseURL = process.env.OPENAI_BASE_URL;
107
+ const newConfig = loadGlobalConfig();
108
+ apiKey = newConfig.apiKey;
109
+ baseURL = newConfig.baseUrl;
110
+ model = options.model || newConfig.model || 'gpt-4o';
84
111
  }
85
112
  else {
86
113
  console.error(chalk.red("API Key is required to proceed."));
87
114
  process.exit(1);
88
115
  }
89
116
  }
90
- // Double check if apiKey is present after potential setup
91
117
  if (!apiKey) {
92
118
  console.error(chalk.red("API Key is still missing. Exiting."));
93
119
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoclaw",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -44,4 +44,4 @@
44
44
  "ts-node": "^10.9.2",
45
45
  "typescript": "^5.9.3"
46
46
  }
47
- }
47
+ }