Skip to content

Commit ff07068

Browse files
committed
Integrated mistral vibe cli
1 parent 4f4680d commit ff07068

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/infra/engines/providers/mistral/auth.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { stat, rm, writeFile, mkdir } from 'node:fs/promises';
22
import * as path from 'node:path';
33
import { homedir } from 'node:os';
4+
import { createInterface } from 'node:readline/promises';
5+
import { stdin as input, stdout as output } from 'node:process';
46

57
import { expandHomeDir } from '../../../../shared/utils/index.js';
68
import { metadata } from './metadata.js';
@@ -77,6 +79,18 @@ export function getCredentialsPath(configDir: string): string {
7779
return path.join(vibeDir, '.env');
7880
}
7981

82+
async function promptForApiKey(): Promise<string | null> {
83+
try {
84+
const rl = createInterface({ input, output });
85+
const answer = await rl.question('Enter MISTRAL_API_KEY: ');
86+
rl.close();
87+
const key = answer.trim();
88+
return key ? key : null;
89+
} catch {
90+
return null;
91+
}
92+
}
93+
8094
/**
8195
* Gets paths to all Mistral-related files that need to be cleaned up
8296
* CodeMachine should not manage Vibe's credentials - it only checks if they exist.
@@ -150,24 +164,31 @@ export async function ensureAuth(options?: MistralAuthOptions): Promise<boolean>
150164
throw new Error(`${metadata.name} CLI is not installed.`);
151165
}
152166

153-
// Mistral Vibe CLI manages its own authentication
154-
// We should not interfere with its credentials file (~/.vibe/.env)
155-
// Instead, guide the user to authenticate via Vibe CLI directly
167+
// CLI is present but no API key - prompt user and persist to ~/.vibe/.env
156168
console.log(`\n────────────────────────────────────────────────────────────`);
157169
console.log(` 🔐 ${metadata.name} Authentication`);
158170
console.log(`────────────────────────────────────────────────────────────`);
159-
console.log(`\n${metadata.name} CLI manages its own authentication.`);
160-
console.log(`\nTo authenticate with ${metadata.name}:\n`);
161-
console.log(`1. Run the Vibe CLI directly to set up your API key:`);
162-
console.log(` vibe\n`);
163-
console.log(`2. When prompted, enter your API key from: https://console.mistral.ai/api-keys`);
164-
console.log(`3. Vibe will store your credentials at ~/.vibe/.env`);
165-
console.log(`4. After authentication, CodeMachine will automatically detect it.\n`);
166-
console.log(`Alternatively, you can set the MISTRAL_API_KEY environment variable:\n`);
167-
console.log(` export MISTRAL_API_KEY=<your-api-key>\n`);
171+
console.log(`\n${metadata.name} CLI requires the MISTRAL_API_KEY.`);
172+
console.log(`You can paste it here and we'll save it to ~/.vibe/.env for you.\n`);
173+
174+
const apiKey = await promptForApiKey();
175+
if (apiKey) {
176+
const vibeDir = path.join(homedir(), '.vibe');
177+
await mkdir(vibeDir, { recursive: true });
178+
const envPath = path.join(vibeDir, '.env');
179+
await writeFile(envPath, `MISTRAL_API_KEY=${apiKey}\n`, { encoding: 'utf8' });
180+
process.env.MISTRAL_API_KEY = apiKey; // make available for this process
181+
console.log(`\nSaved API key to ${envPath}\n`);
182+
return true;
183+
}
184+
185+
console.log(`\nNo API key provided. You can also set it manually:\n`);
186+
console.log(` export MISTRAL_API_KEY=<your-api-key>\n`);
187+
console.log(`or create ~/.vibe/.env with:\n`);
188+
console.log(` MISTRAL_API_KEY=<your-api-key>\n`);
168189
console.log(`────────────────────────────────────────────────────────────\n`);
169190

170-
throw new Error('Authentication incomplete. Please authenticate via Vibe CLI or set MISTRAL_API_KEY environment variable.');
191+
throw new Error('Authentication incomplete. Please set MISTRAL_API_KEY.');
171192
}
172193

173194
/**

src/infra/engines/providers/mistral/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const metadata: EngineMetadata = {
88
cliBinary: 'vibe',
99
installCommand: 'uv tool install mistral-vibe',
1010
defaultModel: 'devstral-2',
11-
order: 4,
11+
order: 0,
1212
experimental: true,
1313
};
1414

0 commit comments

Comments
 (0)