-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.js
More file actions
38 lines (33 loc) · 1.21 KB
/
Copy pathconfig.js
File metadata and controls
38 lines (33 loc) · 1.21 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
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { homedir } from 'node:os';
import { join, dirname } from 'node:path';
const PLACEHOLDER_GATEWAY = 'wss://YOUR-GATEWAY.example.workers.dev/code/ws';
const DEFAULTS = {
gatewayUrl: PLACEHOLDER_GATEWAY,
model: 'qwen/qwen3-coder',
workspace: process.cwd(),
planMode: false,
};
export const CONFIG_PATH = join(homedir(), '.nestcode', 'config.json');
export async function loadConfig() {
let cfg;
try {
const raw = await readFile(CONFIG_PATH, 'utf8');
cfg = { ...DEFAULTS, ...JSON.parse(raw) };
} catch (err) {
if (err.code === 'ENOENT') cfg = { ...DEFAULTS };
else throw err;
}
if (!cfg.gatewayUrl || cfg.gatewayUrl === PLACEHOLDER_GATEWAY) {
throw new Error(
`gatewayUrl is not configured. Edit ${CONFIG_PATH} and set "gatewayUrl" to your NESTcode gateway WebSocket URL, ` +
`or pass --gateway <wss://...> on the command line. Run \`nestcode --init\` to write a starter config.`
);
}
return cfg;
}
export async function writeStarterConfig() {
await mkdir(dirname(CONFIG_PATH), { recursive: true });
await writeFile(CONFIG_PATH, JSON.stringify(DEFAULTS, null, 2) + '\n', 'utf8');
return CONFIG_PATH;
}