Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(desktop): check Windows packages match their architecture
leepokaic9422eed913c
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.ymlindex e258efda..ac0137f3 100644--- a/.github/workflows/release-desktop.yml+++ b/.github/workflows/release-desktop.yml@@ -60,7 +60,6 @@ jobs:cache: npmcache-dependency-path: apps/desktop/package-lock.json- run: npm ci- - run: node --test tools/windows-update-feed.test.mjs- name: Version matches the host# The host's minApp is compared with this app's version (docs/reference/compatibility.md).run: |@@ -231,7 +230,7 @@ jobs:npm run dist:win:main -- --${{ matrix.arch }} --publish nevercd distsha256sum codync-windows-${{ matrix.arch }}.exe > codync-windows-${{ matrix.arch }}.exe.sha256- - name: Install and verify native executables+ - name: Installshell: powershellrun: |$ErrorActionPreference = 'Stop'@@ -239,14 +238,12 @@ jobs:$installation = Join-Path $env:LOCALAPPDATA 'Programs\codync-desktop'$process = Start-Process -FilePath $installer -ArgumentList '/S','/currentuser',('/D='+$installation) -Wait -PassThruif ($process.ExitCode -ne 0) { throw "Installer failed: $($process.ExitCode)" }- $expectedMachine = if ('${{ matrix.arch }}' -eq 'arm64') { 0xaa64 } else { 0x8664 }- foreach ($name in @('Codync.exe','resources\codync-host.exe','resources\codync-hostw.exe')) {- $bytes = [IO.File]::ReadAllBytes((Join-Path $installation $name))- $offset = [BitConverter]::ToInt32($bytes,60)- $machine = [BitConverter]::ToUInt16($bytes,$offset+4)- if ($machine -ne $expectedMachine) { throw "Wrong installed architecture: $name" }- }"CODYNC_INSTALLED_RESOURCES=$installation\resources" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8+ - name: Check the installed executables' architecture+ working-directory: ${{ env.CODYNC_INSTALLED_RESOURCES }}+ run: |+ node -e "const { peArch } = require(process.argv[1]); for (const exe of process.argv.slice(2)) if (peArch(exe) !== '${{ matrix.arch }}') throw new Error('Wrong installed architecture: ' + exe)" \+ "$GITHUB_WORKSPACE/apps/desktop/tools/verify-build.cjs" ../Codync.exe codync-host.exe codync-hostw.exe- name: Smoke test the bundled hostworking-directory: ${{ env.CODYNC_INSTALLED_RESOURCES }}run: |diff --git a/apps/desktop/src/shared/packaging-symbols.test.ts b/apps/desktop/src/shared/verify-build.test.tssimilarity index 55%rename from apps/desktop/src/shared/packaging-symbols.test.tsrename to apps/desktop/src/shared/verify-build.test.tsindex 09f77cff..c63b93dc 100644--- a/apps/desktop/src/shared/packaging-symbols.test.ts+++ b/apps/desktop/src/shared/verify-build.test.ts@@ -5,14 +5,27 @@ import { tmpdir } from 'node:os'import { join } from 'node:path'import { test, type TestContext } from 'node:test'-const verifyBuild = createRequire(import.meta.url)('../../tools/verify-build.cjs')+const require = createRequire(import.meta.url)+const verifyBuild = require('../../tools/verify-build.cjs')+const { Arch } = require('electron-builder')-function fixture(t: TestContext, platform = 'darwin') {- const projectDir = mkdtempSync(join(tmpdir(), 'codync-symbol-check-'))+function fixture(t: TestContext, platform = 'darwin', arch = Arch.x64) {+ const projectDir = mkdtempSync(join(tmpdir(), 'codync-verify-build-'))t.after(() => rmSync(projectDir, { recursive: true, force: true }))mkdirSync(join(projectDir, 'resources'))writeFileSync(join(projectDir, 'resources/account-config.json'), JSON.stringify({ environment: 'dev' }))- return { electronPlatformName: platform, packager: { projectDir, appInfo: { id: 'com.pokai.Codync.dev' } } }+ if (platform === 'win32') writeHost(projectDir, 0x8664)+ return { electronPlatformName: platform, arch, packager: { projectDir, appInfo: { id: 'com.pokai.Codync.dev' } } }+}++/** A bundled Windows host with only the PE header fields the check reads. */+function writeHost(projectDir: string, machine: number) {+ const exe = Buffer.alloc(0x100)+ exe.writeUInt32LE(0x80, 0x3c)+ exe.write('PE\0\0', 0x80, 'latin1')+ exe.writeUInt16LE(machine, 0x84)+ mkdirSync(join(projectDir, 'build/native'), { recursive: true })+ writeFileSync(join(projectDir, 'build/native/codync-host.exe'), exe)}test('macOS packaging requires the Apple logo manifest entry and every rendered weight', async (t) => {@@ -35,3 +48,10 @@ test('Linux and Windows packaging does not require Apple-only SF Symbols', asyncawait assert.doesNotReject(verifyBuild(fixture(t, platform)))}})++test('Windows packaging refuses a host built for the other architecture', async (t) => {+ const arm = fixture(t, 'win32', Arch.arm64)+ await assert.rejects(verifyBuild(arm), /Windows arm64 app with a host built for x64/)+ writeHost(arm.packager.projectDir, 0xaa64)+ await assert.doesNotReject(verifyBuild(arm))+})diff --git a/apps/desktop/tools/windows-update-feed.test.mjs b/apps/desktop/src/shared/windows-update-feed.test.tssimilarity index 77%rename from apps/desktop/tools/windows-update-feed.test.mjsrename to apps/desktop/src/shared/windows-update-feed.test.tsindex 5be56a78..b8c6768f 100644--- a/apps/desktop/tools/windows-update-feed.test.mjs+++ b/apps/desktop/src/shared/windows-update-feed.test.ts@@ -1,15 +1,18 @@import assert from 'node:assert/strict'import { execFileSync } from 'node:child_process'import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { createRequire } from 'node:module'import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'import { fileURLToPath } from 'node:url'-import { findFile } from 'electron-updater/out/providers/Provider.js'import { parse, stringify } from 'yaml'-import { mergeWindowsUpdateFeeds } from './windows-update-feed.mjs'-const feed = (arch, version = '2.33.0') => ({+const require = createRequire(import.meta.url)+const { mergeWindowsUpdateFeeds } = require('../../tools/windows-update-feed.mjs')+const { findFile } = require('electron-updater/out/providers/Provider.js')++const feed = (arch: string, version = '2.33.0') => ({version,files: [{ url: `codync-windows-${arch}.exe`, sha512: `${arch}-hash`, size: 123 }],path: `codync-windows-${arch}.exe`,@@ -25,11 +28,11 @@ test('one Windows feed keeps both installers and legacy x64 metadata', () => {assert.equal(x64.files.length, 1)})-for (const arch of ['x64', 'arm64']) {+for (const arch of ['x64', 'arm64'] as const) {test(`electron-updater selects the ${arch} installer from the combined feed`, (context) => {context.mock.property(process, 'arch', arch)const merged = mergeWindowsUpdateFeeds(feed('x64'), feed('arm64'))- const resolved = merged.files.map((info) => ({ info, url: new URL(info.url, 'https://example.com/') }))+ const resolved = merged.files.map((info: { url: string }) => ({ info, url: new URL(info.url, 'https://example.com/') }))assert.equal(findFile(resolved, 'exe').info.url, `codync-windows-${arch}.exe`)})}@@ -38,8 +41,7 @@ test('rejects different versions and missing, swapped or unhashed installers', (assert.throws(() => mergeWindowsUpdateFeeds(feed('x64'), feed('arm64', '2.32.0')), /versions must match/)assert.throws(() => mergeWindowsUpdateFeeds(feed('x64'), { ...feed('arm64'), files: [] }), /must describe/)assert.throws(() => mergeWindowsUpdateFeeds(feed('arm64'), feed('x64')), /must describe/)- const unhashed = feed('arm64')- delete unhashed.files[0].sha512+ const unhashed = { ...feed('arm64'), files: [{ url: 'codync-windows-arm64.exe', size: 123 }] }assert.throws(() => mergeWindowsUpdateFeeds(feed('x64'), unhashed), /SHA-512/)})@@ -51,7 +53,7 @@ test('the workflow command merges YAML feeds on disk', (context) => {const output = join(dir, 'latest.yml')writeFileSync(x64, stringify(feed('x64')))writeFileSync(arm64, stringify(feed('arm64')))- const script = fileURLToPath(new URL('./windows-update-feed.mjs', import.meta.url))+ const script = fileURLToPath(new URL('../../tools/windows-update-feed.mjs', import.meta.url))execFileSync(process.execPath, [script, x64, arm64, output])const merged = parse(readFileSync(output, 'utf8'))assert.deepEqual(merged, mergeWindowsUpdateFeeds(feed('x64'), feed('arm64')))diff --git a/apps/desktop/tools/verify-build.cjs b/apps/desktop/tools/verify-build.cjsindex 5654a26d..abb06772 100644--- a/apps/desktop/tools/verify-build.cjs+++ b/apps/desktop/tools/verify-build.cjs@@ -1,7 +1,25 @@-// Fail before packaging if a stale account-config.json belongs to the other app variant.+// Fail before packaging if a stale account-config.json belongs to the other app variant, or if+// the bundled Windows host was built for another architecture than the installer.const { accessSync, readFileSync } = require('node:fs')const { join } = require('node:path')+const { Arch } = require('electron-builder')++const PE_MACHINES = { 0x8664: 'x64', 0xaa64: 'arm64' }++/** The architecture a Windows executable is built for, from its PE header. */+function peArch(file) {+ const bytes = readFileSync(file)+ const header = bytes.readUInt32LE(0x3c)+ return PE_MACHINES[bytes.readUInt16LE(header + 4)] ?? 'unknown'+}+module.exports = async (context) => {+ if (context.electronPlatformName === 'win32') {+ // tools/native-host.mjs builds the host for the machine it runs on, which a cross-arch package wouldn't match.+ const host = peArch(join(context.packager.projectDir, 'build/native/codync-host.exe'))+ const target = Arch[context.arch]+ if (host !== target) throw new Error(`Packaging the Windows ${target} app with a host built for ${host}; package it on Windows ${target}.`)+ }const expected = context.packager.appInfo.id === 'com.pokai.Codync.dev' ? 'dev' : 'main'const config = JSON.parse(readFileSync(join(context.packager.projectDir, 'resources/account-config.json'), 'utf8'))if (config.environment !== expected) throw new Error(`Packaging ${expected} with ${config.environment} account config; run the matching dist script.`)@@ -14,3 +32,5 @@ module.exports = async (context) => {}}}++module.exports.peArch = peArchdiff --git a/docs/guides/updates.md b/docs/guides/updates.mdindex 9610d3ac..a85521ec 100644--- a/docs/guides/updates.md+++ b/docs/guides/updates.md@@ -145,6 +145,9 @@ after the app archives they point at. Installs read the release GitHub marks *lawhich only the release gate sets: once every feed is up and the App Store has an iPhoneapp the release serves([holding releases](../reference/compatibility.md#holding-releases-for-the-app-store)).+`latest.yml` lists both Windows installers (x64 and ARM64), and electron-updater picks the+one matching the installed app; it is published only after both Windows builds succeed, so a+failed ARM64 build holds the whole release until it is re-run.macOS build versions follow the marketing version; the iOS build counter is independent.Installs of the SwiftUI Mac app that preceded the desktop app still read the Sparkleappcast; the release workflow generates one for the desktop zip, so those installs movediff --git a/docs/guides/windows-testing.md b/docs/guides/windows-testing.mdindex 6d6e013e..4123572e 100644--- a/docs/guides/windows-testing.md+++ b/docs/guides/windows-testing.md@@ -16,7 +16,8 @@ each installed host after running the installer and checking the native app/hostInstallers, checksums and blockmaps use `codync-windows-<arch>.exe` names.Both builds contribute to one `latest.yml` update feed, uploaded only after both installers;electron-updater selects the file matching the installed app's architecture. The pinned computer-use-driver and UI Automation helper remain x64 and run through Prism on ARM64 Windows 11.+driver and UI Automation helper remain x64 and run through Prism on ARM64 Windows 11, as do+registry agents that ship only a `windows-x86_64` build (the ARM64 host downloads that one instead).Windows packaging forces the supported BCJ archive filter: the bundled NSIS decoder silently skipsexecutables compressed with modern 7z ARM64 filters, even when the installer reports success.For a manual CI check, dispatch **Release desktop** with `windows_only` enabled to build bothdiff --git a/host/src/agent/registry.rs b/host/src/agent/registry.rsindex fc60f9d5..71640c49 100644--- a/host/src/agent/registry.rs+++ b/host/src/agent/registry.rs@@ -90,12 +90,21 @@ pub fn platform() -> Option<&'static str> {})}+/// This machine's build in a registry `distribution`.+fn binary(distribution: &Value) -> Option<&Value> {+ binary_for(distribution, platform()?)+}++/// Windows on ARM falls back to the x64 build, which Windows 11 runs through Prism.+fn binary_for<'a>(distribution: &'a Value, platform: &str) -> Option<&'a Value> {+ let prism = (platform == "windows-aarch64").then_some("windows-x86_64");+ std::iter::once(platform).chain(prism).map(|p| &distribution["binary"][p]).find(|target| target.is_object())+}+pub fn launch_kind(agent: &Value) -> Option<Launch> {let d = &agent["distribution"];let on_path = crate::agent::backends::on_path;- if let Some(p) = platform()- && d["binary"][p].is_object()- {+ if binary(d).is_some() {return Some(Launch::Download);}if d["npx"].is_object() && on_path("npx") {@@ -110,7 +119,7 @@ pub fn launch_kind(agent: &Value) -> Option<Launch> {/// The agent runs through `npx` here (no build of its own for this platform).pub fn needs_node(agent: &Value) -> bool {let d = &agent["distribution"];- d["npx"].is_object() && !platform().is_some_and(|p| d["binary"][p].is_object())+ d["npx"].is_object() && binary(d).is_none()}fn args_of(v: &Value) -> String {@@ -180,8 +189,7 @@ pub async fn command(agent: &Value, progress: impl Fn(&str)) -> Result<Cmd> {let d = &agent["distribution"];match launch_kind(agent) {Some(Launch::Download) => {- let platform = platform().ok_or_else(|| anyhow!("no download for this platform"))?;- let target = &d["binary"][platform];+ let target = binary(d).ok_or_else(|| anyhow!("no download for this platform"))?;let cmd =target["cmd"].as_str().and_then(contained).ok_or_else(|| anyhow!("registry entry has a bad cmd"))?;let dir = install_binary(agent, target, cmd, &progress).await?;@@ -452,6 +460,15 @@ mod tests {std::fs::remove_dir_all(&dir).unwrap();}+ #[test]+ fn windows_on_arm_falls_back_to_the_x64_binary() {+ let x64 = json!({"binary": {"windows-x86_64": {"cmd": "./x64.exe"}}});+ assert_eq!(binary_for(&x64, "windows-aarch64"), Some(&x64["binary"]["windows-x86_64"]));+ assert_eq!(binary_for(&x64, "linux-aarch64"), None);+ let both = json!({"binary": {"windows-x86_64": {"cmd": "./x64.exe"}, "windows-aarch64": {"cmd": "./arm.exe"}}});+ assert_eq!(binary_for(&both, "windows-aarch64"), Some(&both["binary"]["windows-aarch64"]));+ }+#[test]fn registry_paths_cannot_escape_the_agents_dir() {assert_eq!(safe_component("cursor"), Some("cursor"));