Skip to content

Commit 6c708e0

Browse files
fix(desktop): bundle openwrk as sidecar and add --allow-external flag (anomalyco#396)
- Add openwrk to externalBin in tauri.conf.json - Update prepare-sidecar.mjs to build openwrk binary alongside other sidecars - Add --allow-external flag when spawning openwrk daemon to allow custom opencode-bin path Fixes 'Failed to start openwrk: No such file or directory' error when using Openwrk orchestrator mode.
1 parent df3fa24 commit 6c708e0

3 files changed

Lines changed: 83 additions & 1 deletion

File tree

‎packages/desktop/scripts/prepare-sidecar.mjs‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ const owpenbotTargetName = owpenbotTargetTriple
135135
: null;
136136
const owpenbotTargetPath = owpenbotTargetName ? join(sidecarDir, owpenbotTargetName) : null;
137137
const owpenbotDir = resolve(__dirname, "..", "..", "owpenbot");
138+
139+
// openwrk paths
140+
const openwrkBaseName = "openwrk";
141+
const openwrkName = process.platform === "win32" ? `${openwrkBaseName}.exe` : openwrkBaseName;
142+
const openwrkPath = join(sidecarDir, openwrkName);
143+
const openwrkBuildName = bunTarget
144+
? `${openwrkBaseName}-${bunTarget}${bunTarget.includes("windows") ? ".exe" : ""}`
145+
: openwrkName;
146+
const openwrkBuildPath = join(sidecarDir, openwrkBuildName);
147+
const openwrkTargetTriple = resolvedTargetTriple;
148+
const openwrkTargetName = openwrkTargetTriple
149+
? `${openwrkBaseName}-${openwrkTargetTriple}${openwrkTargetTriple.includes("windows") ? ".exe" : ""}`
150+
: null;
151+
const openwrkTargetPath = openwrkTargetName ? join(sidecarDir, openwrkTargetName) : null;
152+
const openwrkDir = resolve(__dirname, "..", "..", "headless");
153+
138154
const readHeader = (filePath, length = 256) => {
139155
const fd = openSync(filePath, "r");
140156
try {
@@ -485,6 +501,57 @@ if (existsSync(owpenbotBuildPath)) {
485501
}
486502
}
487503

504+
// Build openwrk sidecar
505+
const shouldBuildOpenwrk = !existsSync(openwrkBuildPath) || isStubBinary(openwrkBuildPath);
506+
if (shouldBuildOpenwrk) {
507+
mkdirSync(sidecarDir, { recursive: true });
508+
if (existsSync(openwrkBuildPath)) {
509+
try {
510+
unlinkSync(openwrkBuildPath);
511+
} catch {
512+
// ignore
513+
}
514+
}
515+
// openwrk uses bun build --compile directly
516+
const openwrkCliPath = resolve(openwrkDir, "src", "cli.ts");
517+
if (!existsSync(openwrkCliPath)) {
518+
console.error(`Openwrk CLI source not found at ${openwrkCliPath}`);
519+
process.exit(1);
520+
}
521+
const openwrkArgs = ["build", "--compile", openwrkCliPath, "--outfile", openwrkBuildPath];
522+
if (bunTarget) {
523+
openwrkArgs.push("--target", bunTarget);
524+
}
525+
const result = spawnSync("bun", openwrkArgs, { cwd: openwrkDir, stdio: "inherit" });
526+
if (result.status !== 0) {
527+
process.exit(result.status ?? 1);
528+
}
529+
}
530+
531+
if (existsSync(openwrkBuildPath)) {
532+
const shouldCopyCanonical = !existsSync(openwrkPath) || isStubBinary(openwrkPath);
533+
if (shouldCopyCanonical && openwrkBuildPath !== openwrkPath) {
534+
try {
535+
if (existsSync(openwrkPath)) unlinkSync(openwrkPath);
536+
} catch {
537+
// ignore
538+
}
539+
copyFileSync(openwrkBuildPath, openwrkPath);
540+
}
541+
542+
if (openwrkTargetPath) {
543+
const shouldCopyTarget = !existsSync(openwrkTargetPath) || isStubBinary(openwrkTargetPath);
544+
if (shouldCopyTarget && openwrkBuildPath !== openwrkTargetPath) {
545+
try {
546+
if (existsSync(openwrkTargetPath)) unlinkSync(openwrkTargetPath);
547+
} catch {
548+
// ignore
549+
}
550+
copyFileSync(openwrkBuildPath, openwrkTargetPath);
551+
}
552+
}
553+
}
554+
488555
const openworkServerVersion = (() => {
489556
try {
490557
const raw = readFileSync(resolve(openworkServerDir, "package.json"), "utf8");
@@ -494,6 +561,15 @@ const openworkServerVersion = (() => {
494561
}
495562
})();
496563

564+
const openwrkVersion = (() => {
565+
try {
566+
const raw = readFileSync(resolve(openwrkDir, "package.json"), "utf8");
567+
return String(JSON.parse(raw).version ?? "").trim();
568+
} catch {
569+
return null;
570+
}
571+
})();
572+
497573
const versions = {
498574
opencode: {
499575
version: normalizedOpencodeVersion,
@@ -507,6 +583,10 @@ const versions = {
507583
version: expectedOwpenbotVersion,
508584
sha256: existsSync(owpenbotPath) ? sha256File(owpenbotPath) : null,
509585
},
586+
openwrk: {
587+
version: openwrkVersion,
588+
sha256: existsSync(openwrkPath) ? sha256File(openwrkPath) : null,
589+
},
510590
};
511591

512592
const missing = Object.entries(versions)

‎packages/desktop/src-tauri/src/openwrk/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub fn spawn_openwrk_daemon(
162162
options.opencode_host.clone(),
163163
"--opencode-workdir".to_string(),
164164
options.opencode_workdir.clone(),
165+
"--allow-external".to_string(),
165166
];
166167

167168
if let Some(port) = options.opencode_port {

‎packages/desktop/src-tauri/tauri.conf.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"externalBin": [
3838
"sidecars/opencode",
3939
"sidecars/openwork-server",
40-
"sidecars/owpenbot"
40+
"sidecars/owpenbot",
41+
"sidecars/openwrk"
4142
]
4243
},
4344
"plugins": {

0 commit comments

Comments
 (0)