mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 16:01:05 +00:00
refactor: consolidate executable check into assertExecutable helper
- Add assertExecutable() to cli-shared that checks and attempts chmod - Simplify CLI and SDK spawn code to use the shared helper - Fix cli-shared package.json exports (.js not .mjs) - Add global install instructions to SDK error message
This commit is contained in:
parent
048dcc5693
commit
7f07428621
4 changed files with 95 additions and 77 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import type { ChildProcess } from "node:child_process";
|
||||
import type { AddressInfo } from "node:net";
|
||||
import {
|
||||
assertExecutable,
|
||||
formatNonExecutableBinaryMessage,
|
||||
isPermissionError,
|
||||
} from "@sandbox-agent/cli-shared";
|
||||
|
||||
export type SandboxAgentSpawnLogMode = "inherit" | "pipe" | "silent";
|
||||
|
|
@ -73,29 +73,29 @@ export async function spawnSandboxAgent(
|
|||
throw new Error("sandbox-agent binary not found. Install @sandbox-agent/cli or set SANDBOX_AGENT_BIN.");
|
||||
}
|
||||
|
||||
if (process.platform !== "win32") {
|
||||
try {
|
||||
fs.accessSync(binaryPath, fs.constants.X_OK);
|
||||
} catch (error) {
|
||||
if (isPermissionError(error)) {
|
||||
throw new Error(
|
||||
formatNonExecutableBinaryMessage({
|
||||
binPath: binaryPath,
|
||||
trustPackages: TRUST_PACKAGES,
|
||||
bunInstallBlocks: [
|
||||
{
|
||||
label: "Project install",
|
||||
commands: [
|
||||
`bun pm trust ${TRUST_PACKAGES}`,
|
||||
"bun add sandbox-agent",
|
||||
],
|
||||
},
|
||||
if (!assertExecutable(binaryPath, fs)) {
|
||||
throw new Error(
|
||||
formatNonExecutableBinaryMessage({
|
||||
binPath: binaryPath,
|
||||
trustPackages: TRUST_PACKAGES,
|
||||
bunInstallBlocks: [
|
||||
{
|
||||
label: "Project install",
|
||||
commands: [
|
||||
`bun pm trust ${TRUST_PACKAGES}`,
|
||||
"bun add sandbox-agent",
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "Global install",
|
||||
commands: [
|
||||
`bun pm -g trust ${TRUST_PACKAGES}`,
|
||||
"bun add -g sandbox-agent",
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const stdio = logMode === "inherit" ? "inherit" : logMode === "silent" ? "ignore" : "pipe";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue