devsplain 2.2.3 → 2.3.0
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/bin/cli.js +73 -54
- package/bin/post-commit.js +0 -17
- package/bin/setup-hook.js +109 -21
- package/lib/config.js +6 -10
- package/lib/llm.js +473 -281
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -4,7 +4,7 @@ const os = require('os');
|
|
|
4
4
|
const readline = require('readline');
|
|
5
5
|
const configPath = path.join(os.homedir(), '.devsplainrc');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/** Prompts the user for sensitive input with hidden characters and raw stdin handling [ds] */
|
|
8
8
|
function askSecret(query) {
|
|
9
9
|
return new Promise((resolve) => {
|
|
10
10
|
const rl = readline.createInterface({
|
|
@@ -22,12 +22,12 @@ function askSecret(query) {
|
|
|
22
22
|
process.stdout.write('\n');
|
|
23
23
|
rl.close();
|
|
24
24
|
resolve(key);
|
|
25
|
-
} else if (char === '\u0008' || char === '\u007f') {
|
|
25
|
+
} else if (char === '\u0008' || char === '\u007f') {
|
|
26
26
|
if (key.length > 0) {
|
|
27
27
|
key = key.slice(0, -1);
|
|
28
28
|
process.stdout.write('\b \b');
|
|
29
29
|
}
|
|
30
|
-
} else if (char === '\u0003') {
|
|
30
|
+
} else if (char === '\u0003') {
|
|
31
31
|
process.stdin.setRawMode(false);
|
|
32
32
|
process.exit(130);
|
|
33
33
|
} else {
|
|
@@ -39,7 +39,7 @@ function askSecret(query) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
/** Migrates legacy single-provider config structure to the new multi-provider format [ds] */
|
|
43
43
|
function migrateConfig(oldConfig) {
|
|
44
44
|
if (oldConfig && typeof oldConfig === 'object' && oldConfig.provider && !oldConfig.providers) {
|
|
45
45
|
return {
|
|
@@ -57,7 +57,7 @@ function migrateConfig(oldConfig) {
|
|
|
57
57
|
return oldConfig;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
/** Resolves config from environment variables, file storage, or interactive wizard setup [ds] */
|
|
61
61
|
async function getConfig(forceWizard = false) {
|
|
62
62
|
if (process.env.DEVSPLAIN_API_KEY || process.env.DEVSPLAIN_PROVIDER) {
|
|
63
63
|
const provider = process.env.DEVSPLAIN_PROVIDER || 'gemini';
|
|
@@ -77,7 +77,6 @@ async function getConfig(forceWizard = false) {
|
|
|
77
77
|
const rawData = fs.readFileSync(configPath, 'utf8');
|
|
78
78
|
fileConfig = migrateConfig(JSON.parse(rawData));
|
|
79
79
|
} catch (e) {
|
|
80
|
-
// Ignored, file might be corrupted
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -104,7 +103,6 @@ async function getConfig(forceWizard = false) {
|
|
|
104
103
|
console.log(`${i + 1}. ${p}${isActive}`);
|
|
105
104
|
});
|
|
106
105
|
console.log(`\n${savedProviders.length + 1}. Add/Configure a different provider`);
|
|
107
|
-
|
|
108
106
|
const c = await askQuestion(`Select (1-${savedProviders.length + 1}): `);
|
|
109
107
|
const idx = parseInt(c) - 1;
|
|
110
108
|
|
|
@@ -185,7 +183,6 @@ async function getConfig(forceWizard = false) {
|
|
|
185
183
|
provider = providerToConfig;
|
|
186
184
|
const old = config.providers[provider];
|
|
187
185
|
baseUrl = old.baseUrl;
|
|
188
|
-
|
|
189
186
|
let defaultModel = old.model;
|
|
190
187
|
const customModel = await askQuestion(`Model name (press Enter for default '${defaultModel}'): `);
|
|
191
188
|
model = customModel.trim() || defaultModel;
|
|
@@ -254,12 +251,11 @@ async function getConfig(forceWizard = false) {
|
|
|
254
251
|
confirmed = true;
|
|
255
252
|
break;
|
|
256
253
|
} else if (confirm === 'n' || confirm === 'no') {
|
|
257
|
-
break;
|
|
254
|
+
break;
|
|
258
255
|
}
|
|
259
256
|
console.log("Invalid choice. Please enter 'y' or 'n'.");
|
|
260
257
|
}
|
|
261
258
|
} else {
|
|
262
|
-
// User just selected an existing provider and didn't want to update it
|
|
263
259
|
config.activeProvider = providerToConfig;
|
|
264
260
|
console.log(`\nSwitched active provider to ${config.activeProvider}.`);
|
|
265
261
|
confirmed = true;
|