feat(ssh,docker): use bundled OpenCode server in SSH remote startup and Docker image

Problem: Desktop SSH managed startup still required a standalone opencode CLI on the remote host even when @openchamber/web bundled OpenCode, and the Dockerfile still installed Debian Node 20 plus the global @opencode/cli binary.

Approach: Probe the remote openchamber installation in ssh-manager.mjs for a runnable bundled OpenCode server (Node 22.15+, non-musl Linux, build/opencode-server/serve.mjs and manifest) and omit OPENCODE_BINARY when present, falling back to the remote opencode CLI lookup for older installations. Update Dockerfile to copy official Node 24 from node:24-slim into the runtime image and drop the global @opencode/cli install.

Testing: Verified with bun test packages/electron/ssh-manager.test.mjs (42 passed, including the new bundled-server case) and node --check packages/electron/ssh-manager.mjs.
This commit is contained in:
Bohdan Triapitsyn committed 2026-11-22 12:02:08 +02:00
1 parent b14ca90868
commit 3281d86afe
4 files changed
+71 -8

No files matched your search

+1 -1
View File
@@ -222,7 +222,7 @@ gap.
`packages/web/package.json` and `packages/electron/package.json` (`@opencode/server` and the packages the
bundled server imports, `packages/web/opencode-server`), the four native wrapper packages in `packages/web/package.json` `dependencies` (`@lydell/node-pty`, `@parcel/watcher`, `@ff-labs/fff-node`, `@opencode/pty`), and
`@opencode/client` / `@opencode/schema` in the root, ui, web and vscode
manifests, plus `@opencode/cli@` in the Dockerfile. They move together,
manifests. They move together,
including `opencode.url` in `flake.nix` (see the bump steps).
## "What's new in OpenCode 2.x?"
+8 -4
View File
@@ -23,17 +23,22 @@ COPY . .
RUN bun run --cwd packages/sdk build
RUN bun run build:web
FROM node:24-slim AS node-runtime
FROM oven/bun:1.4.4 AS runtime
WORKDIR /home/openchamber
COPY --from=node-runtime /usr/local/bin/node /usr/local/bin/node
COPY --from=node-runtime /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
bzip2 \
ca-certificates \
git \
less \
nodejs \
npm \
openssh-client \
python3 \
&& rm -rf /var/lib/apt/lists/*
@@ -52,8 +57,7 @@ ENV NPM_CONFIG_PREFIX=/home/openchamber/.npm-global
ENV PATH=${NPM_CONFIG_PREFIX}/bin:${PATH}
RUN npm config set prefix /home/openchamber/.npm-global && mkdir -p /home/openchamber/.npm-global && \
mkdir -p /home/openchamber/.local /home/openchamber/.config /home/openchamber/.ssh && \
npm install -g @opencode/cli@2.3.2
mkdir -p /home/openchamber/.local /home/openchamber/.config /home/openchamber/.ssh
# cloudflared 2026.3.0 - update digest explicitly when upgrading
COPY --from=cloudflare/cloudflared@sha256:6d91c121b803126f7a5344005d17a9324788fc09d305b6e2560ec6040a7ae283 /usr/local/bin/cloudflared /usr/local/bin/cloudflared
+33 -3
View File
@@ -1221,9 +1221,36 @@ export class ElectronSshManager {
}
}
async remoteHasBundledOpenCode(parsed, controlPath, binPath) {
if (!binPath) return false;
const probeScript = [
`PATH="${REMOTE_PATH_PREFIX}:$PATH"`,
`node -e 'const fs=require("node:fs"),path=require("node:path");`,
`if(process.versions.bun)process.exit(1);`,
`const[maj,min]=(process.versions.node||"").split(".").map(Number);`,
`if(!(maj>22||(maj===22&&min>=15)))process.exit(1);`,
`if(process.platform==="linux"&&!process.report?.getReport?.()?.header?.glibcVersionRuntime)process.exit(1);`,
`const real=fs.realpathSync(process.argv[1]);`,
`const dir=path.resolve(path.dirname(real),"..","opencode-server");`,
`if(!fs.existsSync(path.join(dir,"serve.mjs"))||!fs.existsSync(path.join(dir,"assets","manifest.json")))process.exit(1);`,
`process.stdout.write("bundled\\n");'`,
shellQuote(binPath),
'2>/dev/null || true',
].join(' ');
try {
const output = await this.runRemoteCommand(parsed, controlPath, probeScript);
return output.trim() === 'bundled';
} catch {
return false;
}
}
async startRemoteServerManaged(parsed, controlPath, instance, desiredPort, binPath) {
const opencodePath = await this.resolveRemoteTool(parsed, controlPath, 'opencode', REMOTE_OPENCODE_CANDIDATES);
if (!opencodePath) {
const hasBundledOpenCode = await this.remoteHasBundledOpenCode(parsed, controlPath, binPath);
const opencodePath = hasBundledOpenCode
? null
: await this.resolveRemoteTool(parsed, controlPath, 'opencode', REMOTE_OPENCODE_CANDIDATES);
if (!hasBundledOpenCode && !opencodePath) {
throw new Error('The opencode CLI is not installed on the remote machine. Install it there, then connect again');
}
@@ -1233,7 +1260,10 @@ export class ElectronSshManager {
throw new Error('Exposing the remote server to its network requires a UI password');
}
let envPrefix = `PATH="${REMOTE_PATH_PREFIX}:$PATH" OPENCODE_BINARY=${shellQuote(opencodePath)} OPENCHAMBER_RUNTIME=ssh-remote`;
let envPrefix = `PATH="${REMOTE_PATH_PREFIX}:$PATH" OPENCHAMBER_RUNTIME=ssh-remote`;
if (opencodePath) {
envPrefix += ` OPENCODE_BINARY=${shellQuote(opencodePath)}`;
}
if (secret) {
envPrefix += ` OPENCHAMBER_UI_PASSWORD=${shellQuote(secret)}`;
}
+29
View File
@@ -700,6 +700,35 @@ printf '4321\\n'`);
'/home/pi/.bun/bin/openchamber',
)).rejects.toThrow(/opencode CLI is not installed/);
});
test('starts a remote OpenChamber with a bundled OpenCode server without requiring opencode CLI', async () => {
let started = '';
const manager = new ElectronSshManager({
settingsFilePath: path.join(os.tmpdir(), 'unused-settings.json'),
appVersion: '2.8.0',
emit: () => undefined,
});
manager.resolveRemoteTool = async () => {
throw new Error('should not look up opencode CLI when remote package bundles OpenCode');
};
manager.runRemoteCommand = async (_parsed, _controlPath, script) => {
if (script.includes('opencode-server')) return 'bundled\n';
started = script;
return '4321\n';
};
const port = await manager.startRemoteServerManaged(
{ destination: 'user@example.test', args: [] },
'/tmp/control.sock',
{ id: 'ssh-1', auth: {}, remoteOpenchamber: { mode: 'managed' } },
4321,
'/home/pi/.bun/bin/openchamber',
);
expect(port).toBe(4321);
expect(started).toContain("'/home/pi/.bun/bin/openchamber' serve");
expect(started).not.toContain('OPENCODE_BINARY=');
});
test('prefers a bun that only exists in the home directory over npm', async () => {
const commands = [];
const manager = new ElectronSshManager({