sandbox-agent/sdks/gigacode/bin/gigacode
2026-02-06 19:52:47 -08:00

94 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
const { spawn } = require("child_process");
const {
assertExecutable,
formatNonExecutableBinaryMessage,
} = require("@sandbox-agent/cli-shared");
const fs = require("fs");
const path = require("path");
const TRUST_PACKAGES =
"@sandbox-agent/gigacode-linux-x64 @sandbox-agent/gigacode-linux-arm64 @sandbox-agent/gigacode-darwin-arm64 @sandbox-agent/gigacode-darwin-x64 @sandbox-agent/gigacode-win32-x64";
function formatHint(binPath) {
return formatNonExecutableBinaryMessage({
binPath,
binaryName: "gigacode",
trustPackages: TRUST_PACKAGES,
bunInstallBlocks: [
{
label: "Project install",
commands: [
`bun pm trust ${TRUST_PACKAGES}`,
"bun add @sandbox-agent/gigacode",
],
},
{
label: "Global install",
commands: [
`bun pm -g trust ${TRUST_PACKAGES}`,
"bun add -g @sandbox-agent/gigacode",
],
},
],
});
}
const PLATFORMS = {
"darwin-arm64": "@sandbox-agent/gigacode-darwin-arm64",
"darwin-x64": "@sandbox-agent/gigacode-darwin-x64",
"linux-x64": "@sandbox-agent/gigacode-linux-x64",
"linux-arm64": "@sandbox-agent/gigacode-linux-arm64",
"win32-x64": "@sandbox-agent/gigacode-win32-x64",
};
const key = `${process.platform}-${process.arch}`;
const pkg = PLATFORMS[key];
if (!pkg) {
console.error(`Unsupported platform: ${key}`);
process.exit(1);
}
try {
const pkgPath = require.resolve(`${pkg}/package.json`);
const bin = process.platform === "win32" ? "gigacode.exe" : "gigacode";
const binPath = path.join(path.dirname(pkgPath), "bin", bin);
if (!assertExecutable(binPath, fs)) {
console.error(formatHint(binPath));
process.exit(1);
}
const child = spawn(binPath, process.argv.slice(2), {
stdio: "inherit",
});
const forwardSignal = (signal) => {
if (!child.killed) {
child.kill(signal);
}
};
const onSigint = () => forwardSignal("SIGINT");
const onSigterm = () => forwardSignal("SIGTERM");
const onSigquit = () => forwardSignal("SIGQUIT");
process.on("SIGINT", onSigint);
process.on("SIGTERM", onSigterm);
process.on("SIGQUIT", onSigquit);
child.on("exit", (code, signal) => {
process.off("SIGINT", onSigint);
process.off("SIGTERM", onSigterm);
process.off("SIGQUIT", onSigquit);
if (signal) {
process.kill(process.pid, signal);
return;
}
process.exit(code ?? 0);
});
} catch (e) {
if (e.status !== undefined) process.exit(e.status);
throw e;
}