imtoagent 0.3.10 → 0.3.12
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/modules/cli/setup.ts +11 -0
- package/modules/utils/backend-check.ts +27 -4
- package/package.json +1 -1
package/modules/cli/setup.ts
CHANGED
|
@@ -291,6 +291,17 @@ const IM_FIELDS: Record<string, { key: string; label: string; required: boolean
|
|
|
291
291
|
// ================================================================
|
|
292
292
|
|
|
293
293
|
export async function runSetupWizard(): Promise<void> {
|
|
294
|
+
// Guard: refuse to run in non-TTY environment
|
|
295
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
296
|
+
console.error('');
|
|
297
|
+
console.error('❌ Setup wizard requires an interactive terminal (TTY).');
|
|
298
|
+
console.error(' If you installed via "curl | bash", run these commands manually:');
|
|
299
|
+
console.error('');
|
|
300
|
+
console.error(' imtoagent setup');
|
|
301
|
+
console.error('');
|
|
302
|
+
process.exit(1);
|
|
303
|
+
}
|
|
304
|
+
|
|
294
305
|
const dataDir = getDataDir();
|
|
295
306
|
const configPath = path.join(dataDir, 'config.json');
|
|
296
307
|
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { execSync } from 'child_process';
|
|
6
6
|
import * as fs from 'fs';
|
|
7
|
+
import * as os from 'os';
|
|
7
8
|
import * as path from 'path';
|
|
8
9
|
|
|
9
10
|
export interface BackendInfo {
|
|
@@ -17,7 +18,7 @@ export interface BackendInfo {
|
|
|
17
18
|
const BACKEND_DEFS: Omit<BackendInfo, 'installed' | 'version'>[] = [
|
|
18
19
|
{ type: 'claude', label: 'Claude Code', installHint: 'npm install -g @anthropic-ai/claude-agent-sdk' },
|
|
19
20
|
{ type: 'codex', label: 'Codex', installHint: 'npm install -g @openai/codex' },
|
|
20
|
-
{ type: 'opencode', label: 'OpenCode', installHint: '
|
|
21
|
+
{ type: 'opencode', label: 'OpenCode', installHint: 'curl -fsSL https://opencode.ai/install | bash' },
|
|
21
22
|
];
|
|
22
23
|
|
|
23
24
|
// ================================================================
|
|
@@ -60,10 +61,10 @@ function checkOne(b: Omit<BackendInfo, 'installed' | 'version'>): BackendInfo {
|
|
|
60
61
|
const version = execSync(versionCmd[b.type], { encoding: 'utf-8', timeout: 5000 }).trim();
|
|
61
62
|
return { ...b, installed: true, version };
|
|
62
63
|
} catch {
|
|
63
|
-
// PATH 中找不到,继续尝试
|
|
64
|
+
// PATH 中找不到,继续尝试 fallback
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
// fallback
|
|
67
|
+
// fallback 1: npm global bin
|
|
67
68
|
const npmBin = getNpmGlobalBin();
|
|
68
69
|
if (npmBin) {
|
|
69
70
|
const binPath = path.join(npmBin, b.type);
|
|
@@ -77,6 +78,17 @@ function checkOne(b: Omit<BackendInfo, 'installed' | 'version'>): BackendInfo {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
// fallback 2: OpenCode custom install path
|
|
82
|
+
if (b.type === 'opencode') {
|
|
83
|
+
const opencodePath = path.join(os.homedir(), '.opencode', 'bin', 'opencode');
|
|
84
|
+
try {
|
|
85
|
+
if (fs.existsSync(opencodePath)) {
|
|
86
|
+
const version = execSync(`"${opencodePath}" version`, { encoding: 'utf-8', timeout: 5000 }).trim();
|
|
87
|
+
return { ...b, installed: true, version };
|
|
88
|
+
}
|
|
89
|
+
} catch {}
|
|
90
|
+
}
|
|
91
|
+
|
|
80
92
|
return { ...b, installed: false, version: null };
|
|
81
93
|
}
|
|
82
94
|
|
|
@@ -171,7 +183,18 @@ export async function installBackend(
|
|
|
171
183
|
} catch {}
|
|
172
184
|
}
|
|
173
185
|
|
|
174
|
-
// fallback:
|
|
186
|
+
// fallback 2: check custom install paths
|
|
187
|
+
if (type === 'opencode') {
|
|
188
|
+
const opencodePath = path.join(os.homedir(), '.opencode', 'bin', 'opencode');
|
|
189
|
+
if (fs.existsSync(opencodePath)) {
|
|
190
|
+
const version = execSync(`"${opencodePath}" version`, { encoding: 'utf-8', timeout: 5000 }).trim();
|
|
191
|
+
console.log(`\n✅ ${b.label} installed successfully! Version: ${version}`);
|
|
192
|
+
console.log(` ⚠️ Add to PATH: echo 'export PATH=$HOME/.opencode/bin:$PATH' >> ~/.zshrc`);
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// fallback 3: via PATH
|
|
175
198
|
const info = checkOne(b);
|
|
176
199
|
if (info.installed) {
|
|
177
200
|
console.log(`\n✅ ${b.label} installed successfully! Version: ${info.version}`);
|