@iservu-inc/adf-cli 0.5.5 → 0.5.6

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/CHANGELOG.md CHANGED
@@ -5,6 +5,59 @@ All notable changes to `@iservu-inc/adf-cli` will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.5.6] - 2025-10-05
9
+
10
+ ### 🔧 Fixed Invalid .env State Detection
11
+
12
+ **FIX:** Automatically detect and reset invalid configuration where ADF_CURRENT_PROVIDER/ADF_CURRENT_MODEL are set but no API key exists.
13
+
14
+ #### The Problem (Cart Before the Horse)
15
+
16
+ The .env file could end up in an invalid state:
17
+ ```env
18
+ ADF_CURRENT_PROVIDER="openrouter"
19
+ ADF_CURRENT_MODEL="anthropic/claude-sonnet-4-5"
20
+ # But no OPENROUTER_API_KEY present!
21
+ ```
22
+
23
+ This shouldn't be possible - you can't have a "current provider" without an API key for that provider.
24
+
25
+ #### The Fix
26
+
27
+ Now we detect this broken state and automatically reset:
28
+ ```
29
+ ⚠️ Invalid configuration detected:
30
+ ADF_CURRENT_PROVIDER is set to "openrouter" but no API key found
31
+ Resetting provider selection...
32
+ ```
33
+
34
+ The invalid ADF_CURRENT_PROVIDER and ADF_CURRENT_MODEL entries are removed from .env, forcing proper configuration.
35
+
36
+ #### Why This Matters
37
+
38
+ - **Data integrity**: Prevents cart-before-horse situations
39
+ - **Better UX**: Clear feedback about what's wrong
40
+ - **Auto-healing**: Automatically fixes the broken state
41
+ - **Prevents confusion**: Users aren't told they have an active provider when they don't
42
+
43
+ #### How It Can Happen
44
+
45
+ - User manually edited/deleted API key from .env
46
+ - Corrupted .env file
47
+ - Configuration error during setup
48
+
49
+ Now these scenarios are automatically detected and corrected!
50
+
51
+ #### Technical Changes
52
+
53
+ - Modified: `lib/ai/ai-config.js`
54
+ - Added validation after loading .env
55
+ - New `saveEnvFile()` helper function
56
+ - Refactored `saveToEnvFile()` to use `saveEnvFile()`
57
+ - Auto-reset invalid configuration
58
+
59
+ ---
60
+
8
61
  ## [0.5.5] - 2025-10-05
9
62
 
10
63
  ### ✅ Fixed AI Provider Configuration Display
@@ -136,12 +136,9 @@ async function ensureGitignore(projectPath) {
136
136
  }
137
137
 
138
138
  /**
139
- * Save API key to .env file
139
+ * Save entire env object to .env file
140
140
  */
141
- async function saveToEnvFile(envPath, key, value) {
142
- const env = await loadEnvFile(envPath);
143
- env[key] = value;
144
-
141
+ async function saveEnvFile(envPath, env) {
145
142
  const lines = [
146
143
  '# AI Provider Configuration for adf-cli',
147
144
  '# DO NOT commit this file to version control',
@@ -179,6 +176,15 @@ async function saveToEnvFile(envPath, key, value) {
179
176
  await ensureGitignore(projectPath);
180
177
  }
181
178
 
179
+ /**
180
+ * Save API key to .env file
181
+ */
182
+ async function saveToEnvFile(envPath, key, value) {
183
+ const env = await loadEnvFile(envPath);
184
+ env[key] = value;
185
+ await saveEnvFile(envPath, env);
186
+ }
187
+
182
188
  /**
183
189
  * Load .env file into process.env
184
190
  */
@@ -279,8 +285,29 @@ async function configureAIProvider(projectPath = process.cwd()) {
279
285
  }
280
286
 
281
287
  // Get currently active provider and model
282
- const currentProvider = process.env.ADF_CURRENT_PROVIDER || existingEnv.ADF_CURRENT_PROVIDER;
283
- const currentModel = process.env.ADF_CURRENT_MODEL || existingEnv.ADF_CURRENT_MODEL;
288
+ let currentProvider = process.env.ADF_CURRENT_PROVIDER || existingEnv.ADF_CURRENT_PROVIDER;
289
+ let currentModel = process.env.ADF_CURRENT_MODEL || existingEnv.ADF_CURRENT_MODEL;
290
+
291
+ // Validate: If ADF_CURRENT_PROVIDER is set but its API key is missing, reset it
292
+ if (currentProvider) {
293
+ const currentProviderObj = AI_PROVIDERS[currentProvider.toUpperCase()];
294
+ if (currentProviderObj) {
295
+ const currentProviderHasKey = availableProviders.find(p => p.id === currentProvider);
296
+ if (!currentProviderHasKey) {
297
+ console.log(chalk.yellow(`⚠️ Invalid configuration detected:`));
298
+ console.log(chalk.gray(` ADF_CURRENT_PROVIDER is set to "${currentProvider}" but no API key found`));
299
+ console.log(chalk.gray(` Resetting provider selection...\n`));
300
+
301
+ // Clear invalid values from .env file
302
+ delete existingEnv.ADF_CURRENT_PROVIDER;
303
+ delete existingEnv.ADF_CURRENT_MODEL;
304
+ await saveEnvFile(envPath, existingEnv);
305
+
306
+ currentProvider = null;
307
+ currentModel = null;
308
+ }
309
+ }
310
+ }
284
311
 
285
312
  if (availableProviders.length > 0) {
286
313
  console.log(chalk.green('✓ Detected API keys for:'));
@@ -290,7 +317,7 @@ async function configureAIProvider(projectPath = process.cwd()) {
290
317
  console.log('');
291
318
  }
292
319
 
293
- // Show current active configuration if exists
320
+ // Show current active configuration if exists (and is valid)
294
321
  if (currentProvider && currentModel) {
295
322
  const currentProviderObj = AI_PROVIDERS[currentProvider.toUpperCase()];
296
323
  if (currentProviderObj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iservu-inc/adf-cli",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "CLI tool for AgentDevFramework - AI-assisted development framework with multi-provider AI support",
5
5
  "main": "index.js",
6
6
  "bin": {