imtoagent 0.3.13 → 0.3.14
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.
|
@@ -10,6 +10,10 @@ import type { AgentAdapter, AgentInput, AgentOutput } from '../core/types';
|
|
|
10
10
|
import { buildAttachmentHint } from '../core/types';
|
|
11
11
|
import { buildSystemPrompt } from '../prompt-builder';
|
|
12
12
|
import { getDataDir } from '../utils/paths';
|
|
13
|
+
import { getNpmGlobalBin } from '../utils/backend-check';
|
|
14
|
+
import * as fs from 'fs';
|
|
15
|
+
import * as os from 'os';
|
|
16
|
+
import * as path from 'path';
|
|
13
17
|
|
|
14
18
|
// ================================================================
|
|
15
19
|
// OpenCodeAdapter 上下文
|
|
@@ -248,8 +252,21 @@ export async function startOpenCodeServer(): Promise<void> {
|
|
|
248
252
|
} catch {}
|
|
249
253
|
|
|
250
254
|
console.log('[OpenCodeAdapter] starting opencode serve...');
|
|
255
|
+
|
|
256
|
+
// Resolve opencode binary with fallbacks (matches checkOne() logic)
|
|
257
|
+
const home = os.homedir();
|
|
258
|
+
const customPath = path.join(home, '.opencode', 'bin', 'opencode');
|
|
259
|
+
const npmBin = getNpmGlobalBin();
|
|
260
|
+
const npmBinPath = npmBin ? path.join(npmBin, 'opencode') : null;
|
|
261
|
+
const ocBinPath =
|
|
262
|
+
(npmBinPath && fs.existsSync(npmBinPath)) ? npmBinPath :
|
|
263
|
+
fs.existsSync(customPath) ? customPath :
|
|
264
|
+
'opencode'; // fallback to PATH lookup
|
|
265
|
+
|
|
266
|
+
console.log(`[OpenCodeAdapter] Using opencode binary: ${ocBinPath}`);
|
|
267
|
+
|
|
251
268
|
const child = Bun.spawn(
|
|
252
|
-
[
|
|
269
|
+
[ocBinPath, 'serve', '--port', String(OC_PORT), '--hostname', '127.0.0.1'],
|
|
253
270
|
{
|
|
254
271
|
cwd: getDataDir(),
|
|
255
272
|
env: {
|
|
@@ -28,7 +28,7 @@ const BACKEND_DEFS: Omit<BackendInfo, 'installed' | 'version'>[] = [
|
|
|
28
28
|
|
|
29
29
|
let _cachedNpmBin: string | null | undefined = undefined;
|
|
30
30
|
|
|
31
|
-
function getNpmGlobalBin(): string | null {
|
|
31
|
+
export function getNpmGlobalBin(): string | null {
|
|
32
32
|
if (_cachedNpmBin !== undefined) return _cachedNpmBin;
|
|
33
33
|
try {
|
|
34
34
|
const prefix = execSync('npm get prefix', { encoding: 'utf-8', timeout: 5000 }).trim();
|