imtoagent 0.3.12 → 0.3.13

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.
@@ -111,6 +111,38 @@ export function formatBackendStatus(backends: BackendInfo[]): string {
111
111
  }).join('\n');
112
112
  }
113
113
 
114
+ // ================================================================
115
+ // Shell config helpers — auto-add paths for user
116
+ // ================================================================
117
+
118
+ function getShellConfigFile(): string | null {
119
+ const candidates = ['.zshrc', '.bashrc', '.bash_profile', '.profile'];
120
+ const home = os.homedir();
121
+ for (const name of candidates) {
122
+ const p = path.join(home, name);
123
+ if (fs.existsSync(p)) return p;
124
+ }
125
+ // fallback: create .zshrc on macOS
126
+ if (process.platform === 'darwin') {
127
+ return path.join(home, '.zshrc');
128
+ }
129
+ return null;
130
+ }
131
+
132
+ function ensurePathInConfig(configPath: string, binDir: string): void {
133
+ const exportLine = `export PATH="${binDir}:$PATH"`;
134
+ try {
135
+ if (fs.existsSync(configPath)) {
136
+ const content = fs.readFileSync(configPath, 'utf-8');
137
+ // Skip if already present
138
+ if (content.includes(binDir)) return;
139
+ }
140
+ fs.appendFileSync(configPath, `\n# Added by imtoagent setup\n${exportLine}\n`);
141
+ // Also update current process.env for immediate detection
142
+ process.env.PATH = `${binDir}:${process.env.PATH}`;
143
+ } catch {}
144
+ }
145
+
114
146
  // ================================================================
115
147
  // 自动安装后端 CLI
116
148
  // ================================================================
@@ -171,7 +203,8 @@ export async function installBackend(
171
203
  return false;
172
204
  }
173
205
 
174
- // 安装完成后验证 — 优先用 npm bin 目录直接检查
206
+ // 安装完成后验证 — 按优先级依次检查
207
+ // 1) npm global bin
175
208
  if (npmBinDir) {
176
209
  const binPath = path.join(npmBinDir, b.type);
177
210
  try {
@@ -183,18 +216,25 @@ export async function installBackend(
183
216
  } catch {}
184
217
  }
185
218
 
186
- // fallback 2: check custom install paths
219
+ // 2) OpenCode custom install path
187
220
  if (type === 'opencode') {
188
- const opencodePath = path.join(os.homedir(), '.opencode', 'bin', 'opencode');
221
+ const opencodeBinDir = path.join(os.homedir(), '.opencode', 'bin');
222
+ const opencodePath = path.join(opencodeBinDir, 'opencode');
189
223
  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;
224
+ try {
225
+ const version = execSync(`"${opencodePath}" version`, { encoding: 'utf-8', timeout: 5000 }).trim();
226
+ // 自动配置 PATH(如果 shell 配置文件存在且未包含该行)
227
+ const shellConfig = getShellConfigFile();
228
+ if (shellConfig) {
229
+ ensurePathInConfig(shellConfig, opencodeBinDir);
230
+ }
231
+ console.log(`\n✅ ${b.label} installed successfully! Version: ${version}`);
232
+ return true;
233
+ } catch {}
194
234
  }
195
235
  }
196
236
 
197
- // fallback 3: via PATH
237
+ // 3) via PATH
198
238
  const info = checkOne(b);
199
239
  if (info.installed) {
200
240
  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.12",
3
+ "version": "0.3.13",
4
4
  "description": "IM ↔ Agent 统一网关 — 飞书/Telegram/微信/企业微信对接 Claude Code/Codex/OpenCode",
5
5
  "type": "module",
6
6
  "bin": {