autoclaw 1.0.30 ā 1.0.32
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.
- package/dist/index.js +24 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,8 +8,6 @@ import * as fs from 'fs';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import * as os from 'os';
|
|
10
10
|
import { fileURLToPath } from 'url';
|
|
11
|
-
import { createInterface } from 'node:readline/promises';
|
|
12
|
-
import { stdin as input, stdout as output } from 'node:process';
|
|
13
11
|
// Handle Ctrl+C gracefully
|
|
14
12
|
function handleExit() {
|
|
15
13
|
console.log(chalk.cyan("\n\nGoodbye! (Interrupted)"));
|
|
@@ -59,8 +57,9 @@ program
|
|
|
59
57
|
program
|
|
60
58
|
.command('setup')
|
|
61
59
|
.description('Run the interactive setup wizard to configure API keys')
|
|
62
|
-
.
|
|
63
|
-
|
|
60
|
+
.option('-p, --project', 'Save configuration to project-level (.autoclaw/setting.json)')
|
|
61
|
+
.action(async (options) => {
|
|
62
|
+
await runSetup(options);
|
|
64
63
|
});
|
|
65
64
|
program
|
|
66
65
|
.command('chat [query...]', { isDefault: true })
|
|
@@ -70,10 +69,16 @@ program
|
|
|
70
69
|
await runChat(queryParts, options);
|
|
71
70
|
});
|
|
72
71
|
program.parse(process.argv);
|
|
73
|
-
async function runSetup() {
|
|
72
|
+
async function runSetup(options = {}) {
|
|
73
|
+
const isProject = options.project;
|
|
74
|
+
const targetFile = isProject ? LOCAL_CONFIG_FILE : GLOBAL_CONFIG_FILE;
|
|
75
|
+
const targetDir = isProject ? path.join(process.cwd(), '.autoclaw') : GLOBAL_CONFIG_DIR;
|
|
74
76
|
console.log(chalk.bold.cyan("AutoClaw Setup Wizard š¦\n"));
|
|
75
|
-
console.log(chalk.dim(`Config will be saved to: ${
|
|
76
|
-
|
|
77
|
+
console.log(chalk.dim(`Config will be saved to: ${targetFile}`));
|
|
78
|
+
// Load both to show current effective values as defaults
|
|
79
|
+
const globalConfig = loadJsonConfig(GLOBAL_CONFIG_FILE);
|
|
80
|
+
const localConfig = loadJsonConfig(LOCAL_CONFIG_FILE);
|
|
81
|
+
const currentConfig = { ...globalConfig, ...localConfig };
|
|
77
82
|
function maskSecret(secret) {
|
|
78
83
|
if (!secret || secret.length < 8)
|
|
79
84
|
return '******';
|
|
@@ -248,11 +253,11 @@ async function runSetup() {
|
|
|
248
253
|
...notifyConfig
|
|
249
254
|
};
|
|
250
255
|
try {
|
|
251
|
-
if (!fs.existsSync(
|
|
252
|
-
fs.mkdirSync(
|
|
256
|
+
if (!fs.existsSync(targetDir)) {
|
|
257
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
253
258
|
}
|
|
254
|
-
fs.writeFileSync(
|
|
255
|
-
console.log(chalk.green(`\nā
Configuration saved to ${
|
|
259
|
+
fs.writeFileSync(targetFile, JSON.stringify(newConfig, null, 2), { mode: 0o600 });
|
|
260
|
+
console.log(chalk.green(`\nā
Configuration saved to ${targetFile}`));
|
|
256
261
|
console.log(chalk.cyan("You can now run 'autoclaw' to start using the agent."));
|
|
257
262
|
}
|
|
258
263
|
catch (error) {
|
|
@@ -347,20 +352,16 @@ async function runChat(queryParts, options) {
|
|
|
347
352
|
}
|
|
348
353
|
}
|
|
349
354
|
// Main chat loop
|
|
350
|
-
const rl = createInterface({ input, output });
|
|
351
355
|
try {
|
|
352
356
|
while (true) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
console.log(chalk.cyan("\nGoodbye!"));
|
|
360
|
-
break;
|
|
357
|
+
const { userInput } = await inquirer.prompt([
|
|
358
|
+
{
|
|
359
|
+
type: 'input',
|
|
360
|
+
name: 'userInput',
|
|
361
|
+
message: 'You >',
|
|
362
|
+
prefix: chalk.green('?')
|
|
361
363
|
}
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
+
]);
|
|
364
365
|
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
|
365
366
|
console.log(chalk.cyan("Goodbye!"));
|
|
366
367
|
break;
|
|
@@ -371,17 +372,13 @@ async function runChat(queryParts, options) {
|
|
|
371
372
|
}
|
|
372
373
|
}
|
|
373
374
|
catch (err) {
|
|
374
|
-
if (err.
|
|
375
|
-
// Handled inside loop mostly, but just in case
|
|
375
|
+
if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) {
|
|
376
376
|
console.log(chalk.cyan("\nGoodbye!"));
|
|
377
377
|
}
|
|
378
378
|
else {
|
|
379
379
|
console.error(chalk.red("Error in chat loop:"), err);
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
finally {
|
|
383
|
-
rl.close();
|
|
384
|
-
}
|
|
385
382
|
}
|
|
386
383
|
// Global error handler
|
|
387
384
|
main().catch(err => {
|