imtoagent 0.2.3 → 0.2.5

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.
@@ -41,18 +41,31 @@ switch (command) {
41
41
  case 'daemon':
42
42
  await cmdDaemon();
43
43
  break;
44
- case undefined:
45
- case 'help':
46
- case '--help':
47
- case '-h':
48
- // 无命令 + 无配置 → 自动引导进入 setup
49
- if (!command && !fs.existsSync(path.join(getDataDir(), 'config.json'))) {
50
- console.log('⚠️ 未检测到配置文件,请先完成初始配置\n');
44
+ case undefined: {
45
+ // 无命令 → 没完成 setup 自动进向导,已完成显示帮助
46
+ const dataDir = getDataDir();
47
+ const configPath = path.join(dataDir, 'config.json');
48
+ let needsSetup = !fs.existsSync(configPath);
49
+ if (!needsSetup) {
50
+ try {
51
+ const raw = fs.readFileSync(configPath, 'utf-8');
52
+ // 如果配置里还有 YOUR_ 占位符,说明还没完成 setup
53
+ needsSetup = /YOUR_[A-Z_]+/.test(raw);
54
+ } catch { needsSetup = true; }
55
+ }
56
+ if (needsSetup) {
57
+ console.log('👋 欢迎使用 imtoagent,请先完成初始配置\n');
51
58
  await cmdSetup();
52
59
  } else {
53
60
  printHelp();
54
61
  }
55
62
  break;
63
+ }
64
+ case 'help':
65
+ case '--help':
66
+ case '-h':
67
+ printHelp();
68
+ break;
56
69
  default:
57
70
  console.error(`❌ 未知命令: ${command}`);
58
71
  printHelp();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "imtoagent",
3
- "version": "0.2.3",
4
- "description": "IM Agent 统一网关 飞书/Telegram/微信/企业微信对接 Claude Code/Codex/OpenCode",
3
+ "version": "0.2.5",
4
+ "description": "IM \u2194 Agent \u7edf\u4e00\u7f51\u5173 \u2014 \u98de\u4e66/Telegram/\u5fae\u4fe1/\u4f01\u4e1a\u5fae\u4fe1\u5bf9\u63a5 Claude Code/Codex/OpenCode",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "imtoagent": "./bin/imtoagent.cjs"
@@ -53,4 +53,4 @@
53
53
  "url": "https://github.com/YOUR_USERNAME/imtoagent/issues"
54
54
  },
55
55
  "homepage": "https://github.com/YOUR_USERNAME/imtoagent#readme"
56
- }
56
+ }
@@ -1,90 +1,44 @@
1
1
  #!/usr/bin/env node
2
2
  // ================================================================
3
- // postinstall.js — npm 安装后引导脚本
3
+ // postinstall.cjs — npm 安装后引导
4
4
  // ================================================================
5
- // Node.js 运行(不依赖 bun),兼容所有安装环境
5
+ // 参考 OpenClaw 的设计:postinstall 只做技术性维护,不做交互。
6
+ // 交互式配置由用户运行 `imtoagent setup` 或 `imtoagent` 触发。
6
7
  // ================================================================
7
8
 
8
- const fs = require('fs');
9
- const path = require('path');
10
- const { execSync } = require('child_process');
9
+ "use strict";
11
10
 
12
- const HOME = process.env.HOME || process.env.USERPROFILE || '';
13
- const DATA_DIR = path.join(HOME, '.imtoagent');
11
+ const fs = require("fs");
12
+ const path = require("path");
14
13
 
15
- // 检测 bun 路径
16
- function findBun() {
17
- // 1. PATH 中有 bun
18
- try {
19
- const r = execSync('which bun', { encoding: 'utf-8', timeout: 3000 }).trim();
20
- if (r) return r;
21
- } catch {}
22
- // 2. 常见安装路径
23
- const candidates = [
24
- path.join(HOME, '.bun', 'bin', 'bun'),
25
- '/usr/local/bin/bun',
26
- '/opt/homebrew/bin/bun',
27
- ];
28
- for (const p of candidates) {
29
- if (fs.existsSync(p)) return p;
30
- }
31
- return null;
32
- }
14
+ const HOME = process.env.HOME || process.env.USERPROFILE || "";
15
+ const DATA_DIR = path.join(HOME, ".imtoagent");
33
16
 
34
17
  try {
35
- const configExists = fs.existsSync(path.join(DATA_DIR, 'config.json'));
18
+ const configExists = fs.existsSync(path.join(DATA_DIR, "config.json"));
36
19
 
37
20
  if (configExists) {
38
- console.log(`
39
- imtoagent 升级成功!
40
- 数据目录: ${DATA_DIR}
41
- 配置文件保持不变,无需重新配置。
42
- 运行 "imtoagent start" 启动网关。
43
- `);
21
+ console.log("");
22
+ console.log(" imtoagent 升级成功!");
23
+ console.log("");
24
+ console.log(" 数据目录: " + DATA_DIR);
25
+ console.log(" 配置文件保持不变,无需重新配置。");
26
+ console.log(' 运行 "imtoagent start" 启动网关。');
27
+ console.log("");
44
28
  } else {
45
- console.log(`
46
- +----------------------------------------------------------+
47
- | |
48
- | 🎉 imtoagent 安装成功! |
49
- | |
50
- | 首次使用需要配置 IM 凭证和模型供应商 |
51
- | |
52
- +----------------------------------------------------------+
53
- `);
54
-
55
- if (process.stdin.isTTY) {
56
- const readline = require('readline');
57
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
58
-
59
- rl.question('是否立即运行配置向导?[Y/n]: ', (answer) => {
60
- rl.close();
61
- const yes = (answer || '').trim().toLowerCase();
62
- if (yes === '' || yes === 'y' || yes === 'yes') {
63
- const bunPath = findBun();
64
- if (!bunPath) {
65
- console.error('\n⚠️ bun 未安装,请先安装: https://bun.sh');
66
- console.error(' 安装后运行: imtoagent setup\n');
67
- process.exit(0);
68
- }
69
- console.log('\n🚀 启动配置向导...\n');
70
- const pkgDir = path.resolve(__dirname, '..');
71
- execSync(`${bunPath} bin/imtoagent setup`, {
72
- cwd: pkgDir,
73
- stdio: 'inherit',
74
- env: { ...process.env },
75
- });
76
- } else {
77
- console.log('\n稍后运行 "imtoagent setup" 即可开始配置。');
78
- }
79
- });
80
- } else {
81
- console.log(' 运行 "imtoagent setup" 开始配置');
82
- console.log(' 然后运行 "imtoagent start" 启动网关\n');
83
- }
29
+ console.log("");
30
+ console.log("🎉 imtoagent 安装成功!");
31
+ console.log("");
32
+ console.log(" 首次使用,请运行以下命令完成初始化配置:");
33
+ console.log("");
34
+ console.log(' imtoagent setup # 交互式配置向导');
35
+ console.log(' imtoagent # 无命令时自动检测,未配置也会进入向导');
36
+ console.log("");
37
+ console.log(" 配置完成后启动网关:");
38
+ console.log("");
39
+ console.log(" imtoagent start");
40
+ console.log("");
84
41
  }
85
42
  } catch (e) {
86
43
  // 静默失败,不影响安装
87
- if (e.message && !e.message.includes('readline')) {
88
- console.error(`[postinstall] 提示失败: ${e.message}`);
89
- }
90
44
  }