create-genia-mission-control 1.0.2 → 1.0.3
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/lib/auth.js +54 -47
- package/package.json +1 -1
package/lib/auth.js
CHANGED
|
@@ -1,76 +1,83 @@
|
|
|
1
1
|
import { execa } from 'execa';
|
|
2
2
|
import enquirer from 'enquirer';
|
|
3
|
-
const { prompt } = enquirer;
|
|
4
3
|
import { ui } from './ui.js';
|
|
5
4
|
|
|
5
|
+
const { prompt } = enquirer;
|
|
6
|
+
|
|
6
7
|
export async function authenticate() {
|
|
8
|
+
// Verificar se já está autenticado
|
|
9
|
+
const alreadyAuth = await checkAlreadyAuthenticated();
|
|
10
|
+
|
|
11
|
+
if (alreadyAuth) {
|
|
12
|
+
console.log(ui.ok('Claude Code já autenticado — pulando etapa de login'));
|
|
13
|
+
return { method: 'existing' };
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
ui.nl();
|
|
8
|
-
console.log(ui.
|
|
17
|
+
console.log(ui.warn('Claude Code não autenticado.'));
|
|
9
18
|
ui.nl();
|
|
19
|
+
console.log(ui.gold('Como autenticar:'));
|
|
20
|
+
console.log(ui.dim(' Opção 1 (recomendado): abra outro terminal e rode:'));
|
|
21
|
+
console.log(ui.dim(' claude login'));
|
|
22
|
+
console.log(ui.dim(''));
|
|
23
|
+
console.log(ui.dim(' Opção 2: defina a variável de ambiente:'));
|
|
24
|
+
console.log(ui.dim(' ANTHROPIC_API_KEY=sk-ant-... npx create-genia-mission-control'));
|
|
25
|
+
ui.nl();
|
|
26
|
+
|
|
27
|
+
// Se ANTHROPIC_API_KEY já está no ambiente, usar direto
|
|
28
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
29
|
+
console.log(ui.ok('API key detectada via variável de ambiente'));
|
|
30
|
+
return { method: 'env' };
|
|
31
|
+
}
|
|
10
32
|
|
|
11
|
-
const {
|
|
33
|
+
const { action } = await prompt({
|
|
12
34
|
type: 'select',
|
|
13
|
-
name: '
|
|
14
|
-
message: '
|
|
35
|
+
name: 'action',
|
|
36
|
+
message: 'O que quer fazer?',
|
|
15
37
|
choices: [
|
|
16
|
-
{ name: '
|
|
17
|
-
{ name: 'apikey',
|
|
38
|
+
{ name: 'continue', message: 'Já fiz login em outro terminal — continuar' },
|
|
39
|
+
{ name: 'apikey', message: 'Inserir API key agora' },
|
|
40
|
+
{ name: 'skip', message: 'Pular autenticação por agora' },
|
|
18
41
|
],
|
|
19
42
|
});
|
|
20
43
|
|
|
21
|
-
if (
|
|
22
|
-
return await
|
|
23
|
-
} else {
|
|
24
|
-
return await authAPIKey();
|
|
44
|
+
if (action === 'apikey') {
|
|
45
|
+
return await collectAPIKey();
|
|
25
46
|
}
|
|
47
|
+
|
|
48
|
+
// 'continue' ou 'skip' — prosseguir
|
|
49
|
+
return { method: action };
|
|
26
50
|
}
|
|
27
51
|
|
|
28
|
-
async function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ui.nl();
|
|
52
|
+
async function checkAlreadyAuthenticated() {
|
|
53
|
+
// Checar se ANTHROPIC_API_KEY está no ambiente
|
|
54
|
+
if (process.env.ANTHROPIC_API_KEY) return true;
|
|
32
55
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
56
|
+
// Checar se claude já tem sessão ativa (sem abrir interativo)
|
|
57
|
+
for (const cmd of ['claude', 'claude.cmd']) {
|
|
58
|
+
try {
|
|
59
|
+
const result = await execa(cmd, ['config', 'get', 'apiKey'], {
|
|
60
|
+
stdio: 'pipe',
|
|
61
|
+
timeout: 3000,
|
|
62
|
+
});
|
|
63
|
+
if (result.stdout && result.stdout.trim()) return true;
|
|
64
|
+
} catch {
|
|
65
|
+
// continua
|
|
44
66
|
}
|
|
45
|
-
throw new Error('Claude CLI não encontrado');
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.log(ui.warn('Não foi possível autenticar automaticamente'));
|
|
48
|
-
console.log(ui.dim(' Execute manualmente: claude login'));
|
|
49
|
-
return null;
|
|
50
67
|
}
|
|
68
|
+
|
|
69
|
+
return false;
|
|
51
70
|
}
|
|
52
71
|
|
|
53
|
-
async function
|
|
72
|
+
async function collectAPIKey() {
|
|
54
73
|
const { apiKey } = await prompt({
|
|
55
74
|
type: 'password',
|
|
56
75
|
name: 'apiKey',
|
|
57
|
-
message: 'Cole sua API key da Anthropic:',
|
|
58
|
-
validate: (v) => v.startsWith('sk-ant-') ? true : '
|
|
76
|
+
message: 'Cole sua API key da Anthropic (sk-ant-...):',
|
|
77
|
+
validate: (v) => v.startsWith('sk-ant-') ? true : 'Inválida — deve começar com sk-ant-',
|
|
59
78
|
});
|
|
60
79
|
|
|
61
|
-
// Salvar na variável de ambiente para uso durante a instalação
|
|
62
80
|
process.env.ANTHROPIC_API_KEY = apiKey;
|
|
63
|
-
|
|
64
|
-
// Tentar configurar no claude CLI
|
|
65
|
-
for (const cmd of ['claude', 'claude.cmd']) {
|
|
66
|
-
try {
|
|
67
|
-
await execa(cmd, ['config', 'set', 'apiKey', apiKey], { stdio: 'pipe' });
|
|
68
|
-
break;
|
|
69
|
-
} catch {
|
|
70
|
-
// continua
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
console.log(ui.ok('API key configurada'));
|
|
81
|
+
console.log(ui.ok('API key configurada para esta sessão'));
|
|
75
82
|
return { method: 'apikey', apiKey };
|
|
76
83
|
}
|
package/package.json
CHANGED