imtoagent 0.3.18 → 0.3.19
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/index.ts +3 -2
- package/modules/agent/opencode-adapter.ts +27 -12
- package/modules/utils/paths.ts +3 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// ============================================================
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
+
import * as os from 'os';
|
|
6
7
|
import * as path from 'path';
|
|
7
8
|
|
|
8
9
|
// ===== 重启信号文件路径(统一固定,不依赖 getDataDir) =====
|
|
@@ -315,7 +316,7 @@ class Bot {
|
|
|
315
316
|
this.backend = cfg.backend;
|
|
316
317
|
this.appId = cfg.appId;
|
|
317
318
|
this.appSecret = cfg.appSecret;
|
|
318
|
-
this.defaultCwd = cfg.cwd || globalConfig.system?.defaultProjectDir || '
|
|
319
|
+
this.defaultCwd = cfg.cwd || globalConfig.system?.defaultProjectDir || path.join(os.homedir(), 'Projects');
|
|
319
320
|
this.config = globalConfig;
|
|
320
321
|
|
|
321
322
|
// Bot 级模型配置
|
|
@@ -874,7 +875,7 @@ async function main() {
|
|
|
874
875
|
process.exit(0);
|
|
875
876
|
}
|
|
876
877
|
|
|
877
|
-
const DEFAULT_PROJECT_DIR = config.system?.defaultProjectDir || '
|
|
878
|
+
const DEFAULT_PROJECT_DIR = config.system?.defaultProjectDir || path.join(os.homedir(), 'Projects');
|
|
878
879
|
|
|
879
880
|
if (config.modelAliases) sharedState.modelAliases = config.modelAliases;
|
|
880
881
|
const { providers: _providers, defaultModel: DEFAULT_MODEL_SPEC } = loadProviders();
|
|
@@ -281,19 +281,34 @@ export async function startOpenCodeServer(): Promise<void> {
|
|
|
281
281
|
|
|
282
282
|
console.log(`[OpenCodeAdapter] Using opencode binary: ${ocBinPath}`);
|
|
283
283
|
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
{
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
284
|
+
const dataDir = getDataDir();
|
|
285
|
+
if (!fs.existsSync(dataDir)) {
|
|
286
|
+
console.log(`[OpenCodeAdapter] Creating data directory: ${dataDir}`);
|
|
287
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
288
|
+
}
|
|
289
|
+
console.log(`[OpenCodeAdapter] Working directory: ${dataDir}`);
|
|
290
|
+
|
|
291
|
+
let child;
|
|
292
|
+
try {
|
|
293
|
+
child = Bun.spawn(
|
|
294
|
+
[ocBinPath, 'serve', '--port', String(OC_PORT), '--hostname', '127.0.0.1'],
|
|
295
|
+
{
|
|
296
|
+
cwd: dataDir,
|
|
297
|
+
env: {
|
|
298
|
+
...process.env,
|
|
299
|
+
// 环形通信无需真实 key,但 OpenCode 的 Anthropic provider 要求此变量存在
|
|
300
|
+
ANTHROPIC_API_KEY: 'imtoagent-local',
|
|
301
|
+
},
|
|
302
|
+
stdout: 'pipe',
|
|
303
|
+
stderr: 'pipe',
|
|
292
304
|
},
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
);
|
|
305
|
+
);
|
|
306
|
+
} catch (err: any) {
|
|
307
|
+
console.error(`[OpenCodeAdapter] Failed to start opencode serve: ${err.message}`);
|
|
308
|
+
console.error(` Binary: ${ocBinPath}`);
|
|
309
|
+
console.error(` Work dir: ${dataDir} (exists: ${fs.existsSync(dataDir)})`);
|
|
310
|
+
throw new Error(`opencode serve failed: ${err.message}`);
|
|
311
|
+
}
|
|
297
312
|
|
|
298
313
|
// 后台收集日志
|
|
299
314
|
(async () => {
|
package/modules/utils/paths.ts
CHANGED
|
@@ -39,8 +39,8 @@ export function getDataDir(): string {
|
|
|
39
39
|
// ====== 第 1 步:查找已有的配置文件 ======
|
|
40
40
|
const candidates: { dir: string; label: string }[] = [];
|
|
41
41
|
|
|
42
|
-
// IMTOAGENT_HOME
|
|
43
|
-
if (envHome && fs.existsSync(path.join(envHome, 'config.json'))) {
|
|
42
|
+
// IMTOAGENT_HOME(优先检查,但不强制;目录不存在则忽略)
|
|
43
|
+
if (envHome && fs.existsSync(envHome) && fs.existsSync(path.join(envHome, 'config.json'))) {
|
|
44
44
|
candidates.push({ dir: envHome, label: 'IMTOAGENT_HOME' });
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -83,7 +83,7 @@ function initDataDir(dotDir: string, envHome: string): string {
|
|
|
83
83
|
let sourceDir: string | null = null;
|
|
84
84
|
let sourceLabel = '';
|
|
85
85
|
|
|
86
|
-
if (envHome && fs.existsSync(path.join(envHome, 'config.json'))) {
|
|
86
|
+
if (envHome && fs.existsSync(envHome) && fs.existsSync(path.join(envHome, 'config.json'))) {
|
|
87
87
|
sourceDir = envHome;
|
|
88
88
|
sourceLabel = 'IMTOAGENT_HOME';
|
|
89
89
|
} else if (fs.existsSync(path.join(process.cwd(), 'config.json'))) {
|