closed-loop-cli 1.0.2 → 1.0.3
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.
Potentially problematic release.
This version of closed-loop-cli might be problematic. Click here for more details.
- package/dist/index.js +44 -0
- package/package.json +1 -1
- package/src/index.ts +52 -0
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const readline = __importStar(require("readline"));
|
|
40
40
|
const dotenv = __importStar(require("dotenv"));
|
|
41
|
+
const os = __importStar(require("os"));
|
|
41
42
|
const autogenesis_1 = require("./orchestrator/autogenesis");
|
|
42
43
|
const server_1 = require("./dashboard/server");
|
|
43
44
|
const telegram_bot_1 = require("./orchestrator/telegram-bot");
|
|
@@ -253,7 +254,50 @@ function setupLogRedirection() {
|
|
|
253
254
|
logFile.write('ERROR: ' + args.join(' ') + '\n');
|
|
254
255
|
};
|
|
255
256
|
}
|
|
257
|
+
async function checkAndPromptAPIKey() {
|
|
258
|
+
if (process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN) {
|
|
259
|
+
return process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN || '';
|
|
260
|
+
}
|
|
261
|
+
const configPath = path.join(os.homedir(), '.closed-loop.json');
|
|
262
|
+
if (fs.existsSync(configPath)) {
|
|
263
|
+
try {
|
|
264
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
265
|
+
if (config.apiKey) {
|
|
266
|
+
process.env.ANTHROPIC_API_KEY = config.apiKey;
|
|
267
|
+
return config.apiKey;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (e) { }
|
|
271
|
+
}
|
|
272
|
+
console.log('\n\x1b[33m🔑 Anthropic API key not found in environment or local .env file.\x1b[0m');
|
|
273
|
+
console.log('To run this assistant, please configure your API key below.');
|
|
274
|
+
const rl = readline.createInterface({
|
|
275
|
+
input: process.stdin,
|
|
276
|
+
output: process.stdout
|
|
277
|
+
});
|
|
278
|
+
const question = (query) => {
|
|
279
|
+
return new Promise(resolve => rl.question(query, resolve));
|
|
280
|
+
};
|
|
281
|
+
const key = await question('\x1b[35mEnter your Anthropic API Key:\x1b[0m ');
|
|
282
|
+
rl.close();
|
|
283
|
+
const trimmedKey = key.trim();
|
|
284
|
+
if (!trimmedKey) {
|
|
285
|
+
console.error('\x1b[31mError: API Key cannot be empty.\x1b[0m');
|
|
286
|
+
process.exit(1);
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
fs.writeFileSync(configPath, JSON.stringify({ apiKey: trimmedKey }, null, 2), 'utf8');
|
|
290
|
+
console.log(`\x1b[32m✔ Saved API key to ${configPath}\x1b[0m\n`);
|
|
291
|
+
}
|
|
292
|
+
catch (err) {
|
|
293
|
+
console.warn(`\x1b[33mWarning: Could not save API key to config: ${err.message}\x1b[0m`);
|
|
294
|
+
}
|
|
295
|
+
process.env.ANTHROPIC_API_KEY = trimmedKey;
|
|
296
|
+
return trimmedKey;
|
|
297
|
+
}
|
|
256
298
|
async function main() {
|
|
299
|
+
// Ensure API Key is configured before running any agent logic
|
|
300
|
+
await checkAndPromptAPIKey();
|
|
257
301
|
const args = process.argv.slice(2);
|
|
258
302
|
// Parse codeact option
|
|
259
303
|
let codeactMode = false;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as fs from 'fs';
|
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import * as readline from 'readline';
|
|
5
5
|
import * as dotenv from 'dotenv';
|
|
6
|
+
import * as os from 'os';
|
|
6
7
|
import { AutogenesisEngine } from './orchestrator/autogenesis';
|
|
7
8
|
import { startDashboardServer } from './dashboard/server';
|
|
8
9
|
import { startTelegramBot } from './orchestrator/telegram-bot';
|
|
@@ -257,7 +258,58 @@ function setupLogRedirection() {
|
|
|
257
258
|
};
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
async function checkAndPromptAPIKey(): Promise<string> {
|
|
262
|
+
if (process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN) {
|
|
263
|
+
return process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN || '';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const configPath = path.join(os.homedir(), '.closed-loop.json');
|
|
267
|
+
if (fs.existsSync(configPath)) {
|
|
268
|
+
try {
|
|
269
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
270
|
+
if (config.apiKey) {
|
|
271
|
+
process.env.ANTHROPIC_API_KEY = config.apiKey;
|
|
272
|
+
return config.apiKey;
|
|
273
|
+
}
|
|
274
|
+
} catch (e) {}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
console.log('\n\x1b[33m🔑 Anthropic API key not found in environment or local .env file.\x1b[0m');
|
|
278
|
+
console.log('To run this assistant, please configure your API key below.');
|
|
279
|
+
|
|
280
|
+
const rl = readline.createInterface({
|
|
281
|
+
input: process.stdin,
|
|
282
|
+
output: process.stdout
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const question = (query: string): Promise<string> => {
|
|
286
|
+
return new Promise(resolve => rl.question(query, resolve));
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const key = await question('\x1b[35mEnter your Anthropic API Key:\x1b[0m ');
|
|
290
|
+
rl.close();
|
|
291
|
+
|
|
292
|
+
const trimmedKey = key.trim();
|
|
293
|
+
if (!trimmedKey) {
|
|
294
|
+
console.error('\x1b[31mError: API Key cannot be empty.\x1b[0m');
|
|
295
|
+
process.exit(1);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
fs.writeFileSync(configPath, JSON.stringify({ apiKey: trimmedKey }, null, 2), 'utf8');
|
|
300
|
+
console.log(`\x1b[32m✔ Saved API key to ${configPath}\x1b[0m\n`);
|
|
301
|
+
} catch (err: any) {
|
|
302
|
+
console.warn(`\x1b[33mWarning: Could not save API key to config: ${err.message}\x1b[0m`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
process.env.ANTHROPIC_API_KEY = trimmedKey;
|
|
306
|
+
return trimmedKey;
|
|
307
|
+
}
|
|
308
|
+
|
|
260
309
|
async function main() {
|
|
310
|
+
// Ensure API Key is configured before running any agent logic
|
|
311
|
+
await checkAndPromptAPIKey();
|
|
312
|
+
|
|
261
313
|
const args = process.argv.slice(2);
|
|
262
314
|
|
|
263
315
|
// Parse codeact option
|