-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstart.js
More file actions
executable file
·67 lines (54 loc) · 1.6 KB
/
Copy pathstart.js
File metadata and controls
executable file
·67 lines (54 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const concolor = require('concolor');
const color = concolor({
warn: 'b,yellow',
error: 'b,red',
});
const CONFIG_PATH = path.join(__dirname, 'config.js');
const TEMPLATE_PATH = path.join(__dirname, 'agent', 'config.template.js');
const ensureConfig = () => {
if (fs.existsSync(CONFIG_PATH)) return false;
fs.copyFileSync(TEMPLATE_PATH, CONFIG_PATH);
return true;
};
const createdConfig = ensureConfig();
const { errorText } = require('./agent/agent.js');
const { workspace } = require('./agent/workspace.js');
const { startIde } = require('./ide/ide.js');
const config = require('./config.js');
const DEFAULT_MAX_STEPS = 30;
const USAGE_FILE = path.join(__dirname, 'agent', 'usage.md');
const USAGE = fs.readFileSync(USAGE_FILE, 'utf8').trim();
const resolveApiKey = () => {
const raw = config.API_KEY || '';
return raw.trim();
};
const missingKey = () => {
if (createdConfig) console.log(color.warn('Created config.js\n'));
console.log(color.error('API_KEY is not set.\n'));
console.log(USAGE);
};
const main = async () => {
if (!resolveApiKey()) {
missingKey();
process.exitCode = 1;
return;
}
if (!process.stdin.isTTY || !process.stdout.isTTY) {
console.log(color.error('IDE needs an interactive terminal.'));
process.exitCode = 1;
return;
}
await workspace.init();
await startIde({
maxSteps: DEFAULT_MAX_STEPS,
model: config.MODEL,
});
};
main().catch((error) => {
console.error(color.error(`\nFatal: ${errorText(error)}`));
process.exitCode = 1;
});