The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
build(desktop): compile the layered icon to Assets.car on macOS 26 hosts
ethernet26960b1afb1c
diff --git a/.github/workflows/desktop-bundled-release.yml b/.github/workflows/desktop-bundled-release.ymlindex db3f04b6956..3a107bcbe11 100644--- a/.github/workflows/desktop-bundled-release.yml+++ b/.github/workflows/desktop-bundled-release.yml@@ -1014,6 +1014,27 @@ jobs:printf '%s\n' "$APPLE_API_KEY_P8" > "$RUNNER_TEMP/apple-api-key.p8"echo "APPLE_API_KEY=$RUNNER_TEMP/apple-api-key.p8" >> "$GITHUB_ENV"+ - name: Select Xcode 26 for the macOS 26 layered icon+ # electron-builder compiles apps/desktop/assets/icon.icon to Assets.car+ # with actool, which only Xcode >= 26 ships; the runner image keeps an+ # older Xcode selected. Without this the config silently packages the+ # .icns alone (apps/desktop/scripts/mac-icon.cjs), so assert it here.+ shell: bash+ run: |+ xcode="$(ls -d /Applications/Xcode_26*.app 2>/dev/null | sort -V | tail -1)"+ if [ -z "$xcode" ]; then+ echo "::error::no Xcode 26 on this runner; the macOS 26 layered icon cannot be compiled"+ exit 1+ fi+ echo "DEVELOPER_DIR=$xcode/Contents/Developer" >> "$GITHUB_ENV"+ export DEVELOPER_DIR="$xcode/Contents/Developer"+ version="$(actool --version | python3 -c 'import plistlib, sys; print(plistlib.loads(sys.stdin.buffer.read())["com.apple.actool.version"]["short-bundle-version"])')"+ echo "actool $version from $xcode"+ case "$version" in+ 2[6-9].*|[3-9][0-9].*) ;;+ *) echo "::error::actool $version cannot compile .icon packages (need >= 26)"; exit 1 ;;+ esac+- name: Build and packageshell: bashtimeout-minutes: 330diff --git a/apps/desktop/electron-builder.config.cjs b/apps/desktop/electron-builder.config.cjsindex 217667abe1f..8f824f6e661 100644--- a/apps/desktop/electron-builder.config.cjs+++ b/apps/desktop/electron-builder.config.cjs@@ -52,6 +52,7 @@ function mustStoreMsix(value) {// with the .appinstaller generator so the manifest and the App Installer can// never drift (see scripts/msix-shared.mjs).const { OUT_OF_STORE_PUBLISHER, channelBuildRequest, stageChannelManifest } = require('../../scripts/msix-shared.mjs')+const { macIconResource } = require('./scripts/mac-icon.cjs')const channelRequest = channelBuildRequest()/** @typedef {import("app-builder-lib").Configuration} Configuration */@@ -140,6 +141,13 @@ module.exports = {unpack: ['**/*.node', '**/prebuilds/**', 'dist/**']},mac: {+ // macOS 26 masks every icon into its own squircle: the layered Icon+ // Composer package lets the system do that with the ring following the+ // outline, while `assets/icon.icns` stays the artwork for macOS <= 15.+ // electron-builder compiles `.icon` with actool >= 26 only, so hosts+ // without Xcode 26 fall back to the .icns alone (see scripts/mac-icon.cjs);+ // after-pack.mjs restores our full-resolution .icns either way.+ icon: macIconResource(__dirname),// The afterSign hook owns notarization, including keychain-profile builds.notarize: false,// The packaged client reads this generated app-update.yml by default.diff --git a/apps/desktop/scripts/after-pack.mjs b/apps/desktop/scripts/after-pack.mjsindex d274c65635e..bee90396a11 100644--- a/apps/desktop/scripts/after-pack.mjs+++ b/apps/desktop/scripts/after-pack.mjs@@ -13,7 +13,7 @@import path from 'node:path'import fs from 'node:fs'-import { mkdir, readdir } from 'node:fs/promises'+import { copyFile, mkdir, readdir } from 'node:fs/promises'import { runPython } from '../../../scripts/build/python.mjs'import { assertPackagedBackendReadyArtifact, resolvePackagedAsarPath } from './backend-ready-artifact.mjs'@@ -23,6 +23,18 @@ import { resolveSigningIdentity, signNestedChromium } from './sign-nested-chromiimport { signWheelZipMembers } from './sign-wheel-zips.mjs'import { sanitizeTree } from './sanitize-pe-signatures.mjs'+/**+ * Put our full-resolution `assets/icon.icns` back as the bundle's legacy icon.+ * When `mac.icon` is the Icon Composer package, electron-builder replaces the+ * bundled `icon.icns` with actool's 256px fallback; macOS <= 15 shows that+ * file, so it must be the 16→1024 artwork the generator produced.+ * @param {{ appOutDir: string, packager: { appInfo: { productFilename: string } } }} context+ * @param {string} [appDir] the apps/desktop directory+ */+export async function restoreLegacyMacIcon({ appOutDir, packager }, appDir = path.resolve(import.meta.dirname, '..')) {+ await copyFile(path.join(appDir, 'assets', 'icon.icns'), path.join(packager.getResourcesDir(appOutDir), 'icon.icns'))+}+/*** Restore the empty app-level localizations dropped during Electron extraction.* Runs after language filtering and before signing; the markers come from the@@ -66,6 +78,7 @@ export default async function afterPack(context) {path.resolve(import.meta.dirname, '../../../scripts/bundles/payload.py'), 'relocate', payload], { stdio: 'inherit' })}if (platform === 'darwin') {+ await restoreLegacyMacIcon(context)await restoreMacLocaleMarkers(context)if (fs.existsSync(payload)) {const entitlements = path.join(import.meta.dirname, '..', 'electron', 'entitlements.mac.inherit.plist')diff --git a/apps/desktop/scripts/after-pack.test.mjs b/apps/desktop/scripts/after-pack.test.mjsindex 8424c5d918c..ce1d96a65f4 100644--- a/apps/desktop/scripts/after-pack.test.mjs+++ b/apps/desktop/scripts/after-pack.test.mjs@@ -62,6 +62,7 @@ it('restores app localizations from the filtered framework without copying localawait configuredHook(ctx)expect((await readdir(resources)).filter(name => name.endsWith('.lproj')).sort()).toEqual(['en_GB.lproj', 'nb.lproj'])+ expect(await readdir(resources)).toContain('icon.icns')expect(await readdir(path.join(resources, 'nb.lproj'))).toEqual([])expect(await readFile(path.join(framework, 'nb.lproj', 'locale.pak'), 'utf8')).toBe('untouched locale data')} finally {@@ -69,6 +70,26 @@ it('restores app localizations from the filtered framework without copying local}})+it('puts the full-resolution .icns back after electron-builder packaged the layered icon', async () => {+ // With `mac.icon` pointing at the Icon Composer package, electron-builder+ // bundles actool's 256px fallback as icon.icns; macOS <= 15 shows that file.+ const root = await mkdtemp(path.join(os.tmpdir(), 'hermes-mac-icon-'))+ try {+ const ctx = context(root)+ await seedPackagedMain(ctx)+ const resources = ctx.packager.getResourcesDir(root)+ await mkdir(ctx.packager.getMacOsElectronFrameworkResourcesDir(root), { recursive: true })+ await mkdir(resources, { recursive: true })+ await writeFile(path.join(resources, 'icon.icns'), 'actool fallback')+ await configuredHook(ctx)+ const restored = await readFile(path.join(resources, 'icon.icns'))+ expect(restored.equals(await readFile(path.join(desktopRoot, 'assets', 'icon.icns')))).toBe(true)+ expect(restored.subarray(0, 4).toString('latin1')).toBe('icns')+ } finally {+ await rm(root, { recursive: true, force: true })+ }+})+it('leaves Linux alone and reports a missing framework without failing packaging', async () => {const root = await mkdtemp(path.join(os.tmpdir(), 'hermes-locale-pack-'))const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})@@ -83,6 +104,7 @@ it('leaves Linux alone and reports a missing framework without failing packagingawait configuredHook(ctx)expect(warn).toHaveBeenCalledWith(expect.stringContaining('macOS locale markers were not restored'))expect((await readdir(root)).sort()).toEqual(['Hermes Preview.app', 'resources'])+ expect(await readdir(ctx.packager.getResourcesDir(root))).toContain('icon.icns')} finally {warn.mockRestore()await rm(root, { recursive: true, force: true })diff --git a/apps/desktop/scripts/mac-icon.cjs b/apps/desktop/scripts/mac-icon.cjsnew file mode 100644index 00000000000..e57311e4540--- /dev/null+++ b/apps/desktop/scripts/mac-icon.cjs@@ -0,0 +1,86 @@+// Which macOS icon resource electron-builder packages, decided per build host.+//+// `assets/icon.icon` is the Icon Composer package for macOS 26 (the system+// masks its layers itself, so the border ring follows the real outline).+// electron-builder compiles it to `Contents/Resources/Assets.car` with+// actool, which exists only in Xcode >= 26; on any other host it throws and+// the whole build fails. Choosing at config time keeps a dev Mac on Xcode+// 16 building the .icns-only app it always built, while release CI selects+// Xcode 26 (`DEVELOPER_DIR`) and asserts the version before packaging so a+// silent fallback can never ship from there.+//+// Whichever resource is chosen, after-pack.mjs restores `assets/icon.icns`+// as the bundle's legacy icon: electron-builder's own `.icon` path replaces+// it with actool's 256px fallback, and macOS <= 15 shows the .icns.+// @ts-check+'use strict'++const path = require('node:path')+const { spawnSync } = require('node:child_process')++const ICON_COMPOSER = 'assets/icon.icon'+const LEGACY_ICNS = 'assets/icon.icns'++/**+ * The actool short version from `actool --version` plist output, or null+ * when actool is missing or answers with something else.+ * @param {string} output+ * @returns {string | null}+ */+function parseActoolVersion(output) {+ const match = /<key>short-bundle-version<\/key>\s*<string>([^<]+)<\/string>/.exec(output)+ return match ? match[1].trim() : null+}++/**+ * @param {string | null} version+ * @returns {boolean}+ */+function actoolSupportsIconComposer(version) {+ if (!version) return false+ const major = Number.parseInt(version.split('.')[0], 10)+ return Number.isInteger(major) && major >= 26+}++/**+ * @param {(command: string, args: string[]) => { status: number | null, stdout?: string | Buffer | null, stderr?: string | Buffer | null }} run+ * @returns {string | null}+ */+function installedActoolVersion(run = (command, args) => spawnSync(command, args, { encoding: 'utf8' })) {+ try {+ const result = run('actool', ['--version'])+ if (result.status !== 0) return null+ return parseActoolVersion(`${result.stdout ?? ''}${result.stderr ?? ''}`)+ } catch {+ return null+ }+}++/**+ * The `mac.icon` value for this host: the Icon Composer package when actool+ * can compile it, otherwise the legacy .icns alone.+ * @param {string} appDir the apps/desktop directory+ * @param {{ platform?: string, actoolVersion?: string | null, log?: (message: string) => void }} [options]+ * @returns {string}+ */+function macIconResource(appDir, options = {}) {+ const platform = options.platform ?? process.platform+ if (platform !== 'darwin') return LEGACY_ICNS+ const version = options.actoolVersion === undefined ? installedActoolVersion() : options.actoolVersion+ if (actoolSupportsIconComposer(version)) return ICON_COMPOSER+ const log = options.log ?? (message => console.warn(message))+ log(+ `[mac-icon] actool ${version ?? 'not found'}: packaging ${LEGACY_ICNS} only; ` ++ `the macOS 26 layered icon (${path.join(appDir, ICON_COMPOSER)}) needs Xcode 26 or newer`+ )+ return LEGACY_ICNS+}++module.exports = {+ ICON_COMPOSER,+ LEGACY_ICNS,+ actoolSupportsIconComposer,+ installedActoolVersion,+ macIconResource,+ parseActoolVersion+}diff --git a/apps/desktop/scripts/mac-icon.test.mjs b/apps/desktop/scripts/mac-icon.test.mjsnew file mode 100644index 00000000000..a44ff490106--- /dev/null+++ b/apps/desktop/scripts/mac-icon.test.mjs@@ -0,0 +1,55 @@+import { createRequire } from 'node:module'+import path from 'node:path'+import { expect, it, vi } from 'vitest'++const require = createRequire(import.meta.url)+const desktopRoot = path.resolve(import.meta.dirname, '..')+const {+ ICON_COMPOSER,+ LEGACY_ICNS,+ installedActoolVersion,+ macIconResource,+ parseActoolVersion+} = require('./mac-icon.cjs')++// actool answers --version with a plist whose top-level key itself contains dots.+const ACTOOL_PLIST = `<?xml version="1.0" encoding="UTF-8"?>+<plist version="1.0">+<dict>+\t<key>com.apple.actool.version</key>+\t<dict>+\t\t<key>bundle-version</key>+\t\t<string>25098</string>+\t\t<key>short-bundle-version</key>+\t\t<string>27.0</string>+\t</dict>+</dict>+</plist>+`++it('packages the Icon Composer layers only where actool can compile them', () => {+ const log = vi.fn()+ expect(macIconResource(desktopRoot, { platform: 'darwin', actoolVersion: '26.0', log })).toBe(ICON_COMPOSER)+ expect(macIconResource(desktopRoot, { platform: 'darwin', actoolVersion: '27.0', log })).toBe(ICON_COMPOSER)+ expect(log).not.toHaveBeenCalled()+ // Xcode 16's actool throws inside electron-builder; the .icns-only app must still build.+ expect(macIconResource(desktopRoot, { platform: 'darwin', actoolVersion: '16.4', log })).toBe(LEGACY_ICNS)+ expect(macIconResource(desktopRoot, { platform: 'darwin', actoolVersion: null, log })).toBe(LEGACY_ICNS)+ expect(log).toHaveBeenCalledTimes(2)+ expect(log.mock.calls[1][0]).toContain('not found')+ expect(log.mock.calls[0][0]).toContain(path.join(desktopRoot, ICON_COMPOSER))+})++it('never packages the layered icon from a non-mac host', () => {+ for (const platform of ['linux', 'win32']) {+ expect(macIconResource(desktopRoot, { platform })).toBe(LEGACY_ICNS)+ }+})++it('reads the version out of the actool plist and treats any failure as absent', () => {+ expect(parseActoolVersion(ACTOOL_PLIST)).toBe('27.0')+ expect(parseActoolVersion('xcrun: error: unable to find utility "actool"')).toBeNull()+ expect(installedActoolVersion(() => ({ status: 0, stdout: ACTOOL_PLIST }))).toBe('27.0')+ expect(installedActoolVersion(() => ({ status: 72, stdout: '', stderr: 'no developer tools' }))).toBeNull()+ expect(installedActoolVersion(() => { throw new Error('ENOENT') })).toBeNull()+})