@different-ai/opencode-browser 4.2.5 → 4.2.6
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/cli.js +38 -4
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ import { join, dirname } from "path";
|
|
|
26
26
|
import { fileURLToPath } from "url";
|
|
27
27
|
import { createInterface } from "readline";
|
|
28
28
|
import { createConnection } from "net";
|
|
29
|
+
import { execSync } from "child_process";
|
|
29
30
|
|
|
30
31
|
const __filename = fileURLToPath(import.meta.url);
|
|
31
32
|
const __dirname = dirname(__filename);
|
|
@@ -35,6 +36,7 @@ const BASE_DIR = join(homedir(), ".opencode-browser");
|
|
|
35
36
|
const EXTENSION_DIR = join(BASE_DIR, "extension");
|
|
36
37
|
const BROKER_DST = join(BASE_DIR, "broker.cjs");
|
|
37
38
|
const NATIVE_HOST_DST = join(BASE_DIR, "native-host.cjs");
|
|
39
|
+
const NATIVE_HOST_WRAPPER = join(BASE_DIR, "host-wrapper.sh");
|
|
38
40
|
const CONFIG_DST = join(BASE_DIR, "config.json");
|
|
39
41
|
const BROKER_SOCKET = join(BASE_DIR, "broker.sock");
|
|
40
42
|
|
|
@@ -94,6 +96,26 @@ function ensureDir(p) {
|
|
|
94
96
|
mkdirSync(p, { recursive: true });
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
function resolveNodePath() {
|
|
100
|
+
if (process.env.OPENCODE_BROWSER_NODE) return process.env.OPENCODE_BROWSER_NODE;
|
|
101
|
+
if (process.execPath && /node(\.exe)?$/.test(process.execPath)) return process.execPath;
|
|
102
|
+
try {
|
|
103
|
+
const output = execSync("which node", { stdio: ["ignore", "pipe", "ignore"] })
|
|
104
|
+
.toString("utf8")
|
|
105
|
+
.trim();
|
|
106
|
+
if (output) return output;
|
|
107
|
+
} catch {}
|
|
108
|
+
return process.execPath;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function writeHostWrapper(nodePath) {
|
|
112
|
+
ensureDir(BASE_DIR);
|
|
113
|
+
const script = `#!/bin/sh\n"${nodePath}" "${NATIVE_HOST_DST}"\n`;
|
|
114
|
+
writeFileSync(NATIVE_HOST_WRAPPER, script, { mode: 0o755 });
|
|
115
|
+
chmodSync(NATIVE_HOST_WRAPPER, 0o755);
|
|
116
|
+
return NATIVE_HOST_WRAPPER;
|
|
117
|
+
}
|
|
118
|
+
|
|
97
119
|
function createJsonLineParser(onMessage) {
|
|
98
120
|
let buffer = "";
|
|
99
121
|
return (chunk) => {
|
|
@@ -196,13 +218,13 @@ function nativeHostManifestPath(dir) {
|
|
|
196
218
|
return join(dir, `${NATIVE_HOST_NAME}.json`);
|
|
197
219
|
}
|
|
198
220
|
|
|
199
|
-
function writeNativeHostManifest(dir, extensionId) {
|
|
221
|
+
function writeNativeHostManifest(dir, extensionId, hostPath) {
|
|
200
222
|
ensureDir(dir);
|
|
201
223
|
|
|
202
224
|
const manifest = {
|
|
203
225
|
name: NATIVE_HOST_NAME,
|
|
204
226
|
description: "OpenCode Browser native messaging host",
|
|
205
|
-
path: NATIVE_HOST_DST,
|
|
227
|
+
path: hostPath || NATIVE_HOST_DST,
|
|
206
228
|
type: "stdio",
|
|
207
229
|
allowed_origins: [`chrome-extension://${extensionId}/`],
|
|
208
230
|
};
|
|
@@ -323,14 +345,21 @@ Find it at ${color("cyan", "chrome://extensions")}:
|
|
|
323
345
|
success(`Installed broker: ${BROKER_DST}`);
|
|
324
346
|
success(`Installed native host: ${NATIVE_HOST_DST}`);
|
|
325
347
|
|
|
326
|
-
|
|
348
|
+
const nodePath = resolveNodePath();
|
|
349
|
+
if (!/node(\.exe)?$/.test(nodePath)) {
|
|
350
|
+
warn(`Node not detected; using ${nodePath}. Set OPENCODE_BROWSER_NODE if needed.`);
|
|
351
|
+
}
|
|
352
|
+
const hostPath = writeHostWrapper(nodePath);
|
|
353
|
+
success(`Installed host wrapper: ${hostPath}`);
|
|
354
|
+
|
|
355
|
+
saveConfig({ extensionId, installedAt: new Date().toISOString(), nodePath });
|
|
327
356
|
|
|
328
357
|
header("Step 6: Register Native Messaging Host");
|
|
329
358
|
|
|
330
359
|
const hostDirs = getNativeHostDirs(osName);
|
|
331
360
|
for (const dir of hostDirs) {
|
|
332
361
|
try {
|
|
333
|
-
writeNativeHostManifest(dir, extensionId);
|
|
362
|
+
writeNativeHostManifest(dir, extensionId, hostPath);
|
|
334
363
|
success(`Wrote native host manifest: ${nativeHostManifestPath(dir)}`);
|
|
335
364
|
} catch (e) {
|
|
336
365
|
warn(`Could not write native host manifest to: ${dir}`);
|
|
@@ -520,6 +549,7 @@ async function status() {
|
|
|
520
549
|
success(`Extension dir present: ${existsSync(EXTENSION_DIR)}`);
|
|
521
550
|
success(`Broker installed: ${existsSync(BROKER_DST)}`);
|
|
522
551
|
success(`Native host installed: ${existsSync(NATIVE_HOST_DST)}`);
|
|
552
|
+
success(`Host wrapper installed: ${existsSync(NATIVE_HOST_WRAPPER)}`);
|
|
523
553
|
|
|
524
554
|
const cfg = loadConfig();
|
|
525
555
|
if (cfg?.extensionId) {
|
|
@@ -528,6 +558,10 @@ async function status() {
|
|
|
528
558
|
warn("No config.json found (run install)");
|
|
529
559
|
}
|
|
530
560
|
|
|
561
|
+
if (cfg?.nodePath) {
|
|
562
|
+
success(`Node path: ${cfg.nodePath}`);
|
|
563
|
+
}
|
|
564
|
+
|
|
531
565
|
const osName = platform();
|
|
532
566
|
const hostDirs = getNativeHostDirs(osName);
|
|
533
567
|
let foundAny = false;
|
package/extension/manifest.json
CHANGED