imtoagent 0.2.1 → 0.2.2
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/bin/imtoagent +17 -43
- package/package.json +1 -1
package/bin/imtoagent
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
|
|
14
14
|
import * as fs from 'fs';
|
|
15
15
|
import * as path from 'path';
|
|
16
|
-
import * as readline from 'readline';
|
|
17
16
|
import { getDataDir } from '../modules/utils/paths';
|
|
18
17
|
|
|
19
18
|
const PID_FILE = '/tmp/imtoagent.pid';
|
|
@@ -46,13 +45,7 @@ switch (command) {
|
|
|
46
45
|
case 'help':
|
|
47
46
|
case '--help':
|
|
48
47
|
case '-h':
|
|
49
|
-
|
|
50
|
-
if (!command && !fs.existsSync(path.join(getDataDir(), 'config.json'))) {
|
|
51
|
-
console.log('⚠️ 未检测到配置文件,请先完成初始配置\n');
|
|
52
|
-
await cmdSetup();
|
|
53
|
-
} else {
|
|
54
|
-
printHelp();
|
|
55
|
-
}
|
|
48
|
+
printHelp();
|
|
56
49
|
break;
|
|
57
50
|
default:
|
|
58
51
|
console.error(`❌ 未知命令: ${command}`);
|
|
@@ -64,21 +57,30 @@ switch (command) {
|
|
|
64
57
|
// Help
|
|
65
58
|
// ================================================================
|
|
66
59
|
function printHelp() {
|
|
60
|
+
const dataDir = getDataDir();
|
|
61
|
+
const hasConfig = fs.existsSync(path.join(dataDir, 'config.json'));
|
|
62
|
+
|
|
67
63
|
console.log(`
|
|
68
64
|
imtoagent — IM ↔ Agent 统一网关
|
|
69
65
|
|
|
70
66
|
用法:
|
|
71
|
-
imtoagent setup
|
|
67
|
+
imtoagent setup 交互式配置向导(首次使用)
|
|
72
68
|
imtoagent start 后台启动网关
|
|
73
69
|
imtoagent stop 停止网关
|
|
74
70
|
imtoagent status 查看运行状态
|
|
75
71
|
imtoagent restore 热重载恢复
|
|
76
72
|
imtoagent daemon 前台守护模式(自动重启 + 日志,适合 launchd/systemd 托管)
|
|
77
73
|
|
|
78
|
-
数据目录: ${
|
|
74
|
+
数据目录: ${dataDir}
|
|
79
75
|
`);
|
|
76
|
+
|
|
77
|
+
if (!hasConfig) {
|
|
78
|
+
console.log('💡 首次使用,请先运行: imtoagent setup');
|
|
79
|
+
console.log();
|
|
80
|
+
}
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
|
|
82
84
|
// ================================================================
|
|
83
85
|
// setup — 交互式向导
|
|
84
86
|
// ================================================================
|
|
@@ -127,40 +129,12 @@ async function cmdStart() {
|
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
if (missingBackends.length > 0) {
|
|
130
|
-
console.error(`\n⚠️
|
|
131
|
-
for (const
|
|
132
|
-
|
|
133
|
-
console.error(` ❌ ${name} ${b ? `(${b.label})` : ''}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 交互式询问是否自动安装
|
|
137
|
-
const rl = readline.createInterface({
|
|
138
|
-
input: process.stdin,
|
|
139
|
-
output: process.stdout,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const answer = await new Promise<string>((resolve) => {
|
|
143
|
-
rl.question('\n🔧 是否自动安装缺失的后端?[Y/n]: ', resolve);
|
|
144
|
-
});
|
|
145
|
-
rl.close();
|
|
146
|
-
|
|
147
|
-
if (answer.trim().toLowerCase() !== 'n') {
|
|
148
|
-
const { installBackend } = await import('../modules/utils/backend-check');
|
|
149
|
-
let allInstalled = true;
|
|
150
|
-
|
|
151
|
-
for (const name of missingBackends) {
|
|
152
|
-
const ok = await installBackend(name as 'claude' | 'codex' | 'opencode');
|
|
153
|
-
if (!ok) allInstalled = false;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (allInstalled) {
|
|
157
|
-
console.log('\n✅ 所有后端安装完成,正在启动网关...\n');
|
|
158
|
-
} else {
|
|
159
|
-
console.error('\n⚠️ 部分后端安装失败。网关仍可启动,但使用未安装的后端时会报错。\n');
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
console.error('\n跳过安装。网关仍可启动,但使用未安装的后端时会报错。\n');
|
|
132
|
+
console.error(`\n⚠️ 以下后端已配置但未安装,网关启动后发消息会报错:`);
|
|
133
|
+
for (const b of missingBackends) {
|
|
134
|
+
console.error(` ❌ ${b}`);
|
|
163
135
|
}
|
|
136
|
+
console.error(`\n请先安装缺失的后端,或运行 "imtoagent setup" 修改配置。\n`);
|
|
137
|
+
// 不强制退出,允许用户先启动网关再慢慢装后端
|
|
164
138
|
}
|
|
165
139
|
} catch {
|
|
166
140
|
// 检查失败不影响启动
|