jbai-cli 1.2.0 → 1.2.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/README.md +1 -1
- package/bin/jbai-claude.js +5 -2
- package/bin/jbai-opencode.js +69 -9
- package/bin/jbai.js +1 -1
- package/lib/config.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ jbai doctor
|
|
|
175
175
|
|------|-----------------|
|
|
176
176
|
| Claude Code | `npm i -g @anthropic-ai/claude-code` |
|
|
177
177
|
| Codex | `npm i -g @openai/codex` |
|
|
178
|
-
| Aider | `pip install aider-chat` |
|
|
178
|
+
| Aider | `python3 -m pip install aider-chat` |
|
|
179
179
|
| OpenCode | `go install github.com/opencode-ai/opencode@latest` |
|
|
180
180
|
|
|
181
181
|
## Token Management
|
package/bin/jbai-claude.js
CHANGED
|
@@ -33,13 +33,16 @@ if (superMode) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Set environment for Claude Code
|
|
36
|
+
// Only set API_KEY (not AUTH_TOKEN) to avoid conflicts
|
|
36
37
|
const env = {
|
|
37
38
|
...process.env,
|
|
38
39
|
ANTHROPIC_BASE_URL: endpoints.anthropic,
|
|
39
|
-
ANTHROPIC_API_KEY: token
|
|
40
|
-
ANTHROPIC_AUTH_TOKEN: token
|
|
40
|
+
ANTHROPIC_API_KEY: token
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
// Remove any existing auth token that might conflict
|
|
44
|
+
delete env.ANTHROPIC_AUTH_TOKEN;
|
|
45
|
+
|
|
43
46
|
const child = spawn('claude', finalArgs, {
|
|
44
47
|
stdio: 'inherit',
|
|
45
48
|
env
|
package/bin/jbai-opencode.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
4
7
|
const config = require('../lib/config');
|
|
5
8
|
|
|
6
9
|
const token = config.getToken();
|
|
@@ -15,6 +18,7 @@ if (config.isTokenExpired(token)) {
|
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
const endpoints = config.getEndpoints();
|
|
21
|
+
const environment = config.getEnvironment();
|
|
18
22
|
let args = process.argv.slice(2);
|
|
19
23
|
|
|
20
24
|
// Check for super mode (--super, --yolo, -s)
|
|
@@ -22,28 +26,84 @@ const superFlags = ['--super', '--yolo', '-s'];
|
|
|
22
26
|
const superMode = args.some(a => superFlags.includes(a));
|
|
23
27
|
args = args.filter(a => !superFlags.includes(a));
|
|
24
28
|
|
|
29
|
+
// Setup OpenCode config with JetBrains provider
|
|
30
|
+
const configDir = path.join(os.homedir(), '.config', 'opencode');
|
|
31
|
+
const configFile = path.join(configDir, 'opencode.json');
|
|
32
|
+
|
|
33
|
+
if (!fs.existsSync(configDir)) {
|
|
34
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Create or update OpenCode config with JetBrains provider
|
|
38
|
+
const providerName = environment === 'staging' ? 'jbai-staging' : 'jbai';
|
|
39
|
+
let opencodeConfig = {};
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync(configFile)) {
|
|
42
|
+
try {
|
|
43
|
+
opencodeConfig = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
|
|
44
|
+
} catch {
|
|
45
|
+
opencodeConfig = {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Ensure provider section exists
|
|
50
|
+
if (!opencodeConfig.provider) {
|
|
51
|
+
opencodeConfig.provider = {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Environment variable name for the token
|
|
55
|
+
const envVarName = environment === 'staging' ? 'GRAZIE_STAGING_TOKEN' : 'GRAZIE_API_TOKEN';
|
|
56
|
+
|
|
57
|
+
// Add/update JetBrains provider with custom header (using env var reference)
|
|
58
|
+
opencodeConfig.provider[providerName] = {
|
|
59
|
+
npm: '@ai-sdk/anthropic',
|
|
60
|
+
name: `JetBrains AI (${environment})`,
|
|
61
|
+
options: {
|
|
62
|
+
baseURL: endpoints.anthropic,
|
|
63
|
+
apiKey: `{env:${envVarName}}`,
|
|
64
|
+
headers: {
|
|
65
|
+
'Grazie-Authenticate-JWT': `{env:${envVarName}}`
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
models: {}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Add Claude models
|
|
72
|
+
config.MODELS.claude.available.forEach(model => {
|
|
73
|
+
opencodeConfig.provider[providerName].models[model] = {
|
|
74
|
+
name: model
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Write config
|
|
79
|
+
fs.writeFileSync(configFile, JSON.stringify(opencodeConfig, null, 2));
|
|
80
|
+
|
|
25
81
|
// Check if model specified
|
|
26
82
|
const hasModel = args.includes('--model') || args.includes('-m');
|
|
27
|
-
let finalArgs =
|
|
83
|
+
let finalArgs = [];
|
|
84
|
+
|
|
85
|
+
if (!hasModel) {
|
|
86
|
+
// Use provider/model format for OpenCode
|
|
87
|
+
finalArgs.push('--model', `${providerName}/${config.MODELS.claude.default}`);
|
|
88
|
+
}
|
|
28
89
|
|
|
29
90
|
// Add super mode flags
|
|
30
91
|
if (superMode) {
|
|
31
|
-
finalArgs
|
|
92
|
+
finalArgs.push('--yes');
|
|
32
93
|
console.log('🚀 Super mode: --yes (auto-confirm) enabled');
|
|
33
94
|
}
|
|
34
95
|
|
|
35
|
-
|
|
36
|
-
|
|
96
|
+
finalArgs.push(...args);
|
|
97
|
+
|
|
98
|
+
// Set the token in environment variable for OpenCode config to reference
|
|
99
|
+
const childEnv = {
|
|
37
100
|
...process.env,
|
|
38
|
-
|
|
39
|
-
ANTHROPIC_API_KEY: token,
|
|
40
|
-
OPENAI_API_BASE: endpoints.openai,
|
|
41
|
-
OPENAI_API_KEY: token
|
|
101
|
+
[envVarName]: token
|
|
42
102
|
};
|
|
43
103
|
|
|
44
104
|
const child = spawn('opencode', finalArgs, {
|
|
45
105
|
stdio: 'inherit',
|
|
46
|
-
env
|
|
106
|
+
env: childEnv
|
|
47
107
|
});
|
|
48
108
|
|
|
49
109
|
child.on('error', (err) => {
|
package/bin/jbai.js
CHANGED
package/lib/config.js
CHANGED