Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

- **Installing OpenCode V2 on Windows stops failing at `tar exited 128`.** The
installer asked PATH for `tar`, and an editor started from a Git Bash shell
hands its extension host a PATH where GNU tar comes first: it read the
staging path `C:\…\download.zip` as `host:path` and died. It now names
System32's `tar.exe` — bsdtar, which reads `.zip` and takes Windows paths —
and a tool that won't start reports the path it tried.

## 0.90.4 — 2026-11-15

Bug fixes: local-file links in agent answers open in the editor, picker rows
Expand Down
34 changes: 28 additions & 6 deletions src/orchestrator/stores/binary-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,35 @@ export function isBinaryInstalled(
return pathExists(resolvedBinaryPath(cacheRoot, distribution, version, cmd));
}

/** Shells out to the system `tar` — GNU tar (Linux) / bsdtar (macOS, and
* Windows 10 1803+ ships tar.exe as bsdtar too, which also reads .zip) —
* rather than adding a zip/tar dependency for a format set every platform
* this extension targets already covers natively. */
/** Which archive tool to run, rather than adding a zip/tar dependency for a
* format set every platform this extension targets covers natively: GNU tar
* on Linux, bsdtar on macOS.
*
* On Windows the bare name is not enough — it resolves to whichever tar the
* process that started the editor happened to put first on PATH. A shell
* like Git Bash puts its own GNU tar there, and GNU tar reads a Windows
* path's drive letter as a remote host (`Cannot connect to C: resolve
* failed`, exit 128) and cannot open a .zip at all, which is the format the
* Windows runtime archives are served as (runtime-resolver.ts). System32's
* tar is bsdtar — it reads .zip and .tar.gz and takes Windows paths — and
* Windows 10 1803+ ships it, so name it outright.
*
* Built with backslashes, not `join`: this names a Windows path whatever
* host runs the code that asks. */
export function tarCommand(
platform: NodeJS.Platform = process.platform,
env: Readonly<Record<string, string | undefined>> = process.env,
): string {
if (platform !== "win32") return "tar";
const root = (env.SystemRoot ?? `${env.SystemDrive ?? "C:"}\\Windows`).replace(/[\\/]+$/, "");
return `${root}\\System32\\tar.exe`;
}

/** Extracts into the staging dir with `tarCommand`'s tool. */
async function extractArchive(archivePath: string, destDir: string): Promise<void> {
const answer = await runToExit("tar", ["-xf", archivePath, "-C", destDir], { env: process.env });
if (answer === null) throw new Error("tar could not be run");
const tar = tarCommand();
const answer = await runToExit(tar, ["-xf", archivePath, "-C", destDir], { env: process.env });
if (answer === null) throw new Error(`${tar} could not be run`);
if (answer.code !== 0) throw new Error(`tar exited ${answer.code}: ${answer.stderr.trim()}`);
}

Expand Down
37 changes: 37 additions & 0 deletions test/binary-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
ChecksumMismatch,
installBinary,
parseSha256,
tarCommand,
type BinaryInstallSpec,
} from "../src/orchestrator/stores/binary-installer";
import { runToExit } from "../src/orchestrator/process-tree";

const BYTES = Buffer.from("#!/bin/sh\necho agent\n");
const DIGEST = createHash("sha256").update(BYTES).digest("hex");
Expand Down Expand Up @@ -52,6 +54,41 @@ describe("parseSha256", () => {
});
});

describe("tarCommand — which tar the extract runs", () => {
// What this pins: an editor started from a shell that put its own GNU tar
// (Git Bash) ahead of System32 extracted nothing at all. GNU tar reads a
// Windows path's drive letter as a remote host — `Cannot connect to C:
// resolve failed`, exit 128 — and cannot open the .zip a Windows runtime
// archive is served as.
it("on Windows it is System32's tar, named outright so PATH cannot beat it", () => {
expect(tarCommand("win32", { SystemRoot: "C:\\Windows" })).toBe("C:\\Windows\\System32\\tar.exe");
});

it("it follows the Windows root the environment names, never a hardcoded C:", () => {
expect(tarCommand("win32", { SystemRoot: "D:\\win" })).toBe("D:\\win\\System32\\tar.exe");
expect(tarCommand("win32", { SystemDrive: "E:" })).toBe("E:\\Windows\\System32\\tar.exe");
expect(tarCommand("win32", {})).toBe("C:\\Windows\\System32\\tar.exe");
});

it("a root that already ends in a separator does not double it", () => {
expect(tarCommand("win32", { SystemRoot: "C:\\Windows\\" })).toBe("C:\\Windows\\System32\\tar.exe");
});

it("elsewhere the bare name is enough — there is one tar per platform", () => {
for (const platform of ["linux", "darwin", "freebsd"] as const) {
expect(tarCommand(platform, {})).toBe("tar");
}
});

it.runIf(process.platform === "win32")(
"what this host resolves really is bsdtar — the tool that reads .zip",
async () => {
const answer = await runToExit(tarCommand(), ["--version"], { env: process.env });
expect(answer?.stdout).toMatch(/bsdtar/);
},
);
});

describe("installBinary — the published digest", () => {
it("a download matching its digest installs", async () => {
const installed = await installBinary(root, spec("match", DIGEST));
Expand Down