imtoagent 0.3.11 → 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.
@@ -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 {
@@ -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 中找不到,继续尝试 npm global bin
64
+ // PATH 中找不到,继续尝试 fallback
64
65
  }
65
66
 
66
- // fallback:直接从 npm global bin 目录运行
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: 通过 PATH 查找
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}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imtoagent",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "description": "IM ↔ Agent 统一网关 — 飞书/Telegram/微信/企业微信对接 Claude Code/Codex/OpenCode",
5
5
  "type": "module",
6
6
  "bin": {