Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

perf(desktop): cut macOS signing calls by 81% (#8093)

Theo Browne63eb0429f49f
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c70d38b9f..3dadd8da2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -927,6 +927,9 @@ importers:
'@electron/asar':
specifier: ^3.4.1
version: 3.4.1
+ '@electron/osx-sign':
+ specifier: 2.7.0
+ version: 2.7.0
'@t3tools/contracts':
specifier: workspace:*
version: link:../packages/contracts
@@ -2050,6 +2053,11 @@ packages:
engines: {node: '>=12.0.0'}
hasBin: true
+ '@electron/[email protected]':
+ resolution: {integrity: sha512-9DGhNqKMl6ibkhUoXbN7OHX2gZznfY10L3ZwG0u6r667Kfb6kec4JEfFTXftoqzmOfZ+OzwDbr4p/nKBMHnz0g==}
+ engines: {node: '>=22.12.0'}
+ hasBin: true
+
'@electron/[email protected]':
resolution: {integrity: sha512-Rzc39XPdk/+/wBG8MfwAHohXflep0ITUfulb6Rgz3R0NeSB1noE+E9/M/cb8ftCAiyDD9PPhLuuWgE1GaInbKg==}
engines: {node: '>=22.12.0'}
@@ -11900,6 +11908,15 @@ snapshots:
transitivePeerDependencies:
- supports-color
+ '@electron/[email protected]':
+ dependencies:
+ debug: 4.4.3
+ isbinaryfile: 4.0.10
+ plist: 3.1.1
+ semver: 7.8.5
+ transitivePeerDependencies:
+ - supports-color
+
'@electron/[email protected]':
dependencies:
'@malept/cross-spawn-promise': 2.0.0
diff --git a/scripts/build-desktop-artifact.test.ts b/scripts/build-desktop-artifact.test.ts
index d1c0d5458..1b9e9b434 100644
--- a/scripts/build-desktop-artifact.test.ts
+++ b/scripts/build-desktop-artifact.test.ts
@@ -20,6 +20,7 @@ import {
DESKTOP_ELECTRON_LANGUAGES,
DESKTOP_FILE_EXCLUSIONS,
DESKTOP_EXTRA_RESOURCES,
+ MAC_FILE_EXCLUSIONS,
InvalidMacPasskeyRpDomainError,
InvalidMacPasskeyPublishableKeyError,
InvalidMockUpdateServerPortError,
@@ -33,6 +34,7 @@ import {
resolveClerkPasskeyNativeArtifacts,
resolveMacPasskeySigningConfiguration,
resolveDesktopRuntimeDependencies,
+ resolveMacStageDependencies,
resolveFffNativeDependencies,
resolveBuildOptions,
resolveDesktopBuildIconAssets,
@@ -483,13 +485,52 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
assert.deepStrictEqual((linux.linux as Record<string, unknown>).protocols, [
{ name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
]);
- for (const config of [mac, linux, win]) {
+ assert.deepStrictEqual(mac.files, [...DESKTOP_FILE_EXCLUSIONS, ...MAC_FILE_EXCLUSIONS]);
+ assert.notProperty(mac.mac as Record<string, unknown>, "sign");
+ for (const config of [linux, win]) {
assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES);
assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS);
}
+ assert.deepStrictEqual(mac.electronLanguages, DESKTOP_ELECTRON_LANGUAGES);
}).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
);
+ it("excludes Windows terminal binaries only from macOS packages", () => {
+ assert.deepStrictEqual(MAC_FILE_EXCLUSIONS, [
+ "!**/node_modules/node-pty/prebuilds/win32-*/**/*",
+ "!**/node_modules/node-pty/third_party/conpty/**/*",
+ ]);
+ });
+
+ it("stages only server runtime externals in macOS packages", () => {
+ assert.deepStrictEqual(
+ resolveMacStageDependencies({
+ serverDependencies: {
+ "@anthropic-ai/claude-agent-sdk": "^0.3.170",
+ "@ff-labs/fff-node": "0.9.4",
+ "@opencode-ai/sdk": "^1.3.15",
+ "@pierre/diffs": "1.3.0",
+ "msgpackr-extract": "3.0.4",
+ "node-pty": "1.1.0",
+ },
+ desktopDependencies: {
+ "@clerk/electron": "0.0.34",
+ effect: "4.0.0-beta.103",
+ },
+ arch: "arm64",
+ fffNodeVersion: "0.9.4",
+ }),
+ {
+ "@ff-labs/fff-node": "0.9.4",
+ "msgpackr-extract": "3.0.4",
+ "node-pty": "1.1.0",
+ "@clerk/electron": "0.0.34",
+ effect: "4.0.0-beta.103",
+ "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
+ },
+ );
+ });
+
it("excludes node-pty binaries for the other Windows architecture", () => {
assert.deepStrictEqual(resolveWindowsServerAsarIgnoreGlobs("x64"), [
...WINDOWS_SERVER_ASAR_IGNORE_GLOBS,
@@ -1112,6 +1153,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
assert.equal(config.appId, "com.t3tools.t3code");
assert.equal(mac.entitlements, "/tmp/entitlements.mac.plist");
assert.equal(mac.provisioningProfile, "/tmp/t3code.provisionprofile");
+ assert.match(String(mac.sign), /\/scripts\/sign-macos\.ts$/);
assert.deepStrictEqual(mac.protocols, [
{ name: "T3 Code", schemes: ["t3code", "t3code-dev"] },
]);
diff --git a/scripts/build-desktop-artifact.ts b/scripts/build-desktop-artifact.ts
index 3abe682b5..a9803d2bf 100644
--- a/scripts/build-desktop-artifact.ts
+++ b/scripts/build-desktop-artifact.ts
@@ -796,6 +796,11 @@ export const DESKTOP_FILE_EXCLUSIONS = [
"!apps/desktop/prod-resources/windows-server",
"!apps/desktop/prod-resources/windows-server/**/*",
] as const;
+// Windows terminal helpers cannot run on macOS and slow signing and notarization.
+export const MAC_FILE_EXCLUSIONS = [
+ "!**/node_modules/node-pty/prebuilds/win32-*/**/*",
+ "!**/node_modules/node-pty/third_party/conpty/**/*",
+] as const;
// Windows ships the server tree (bundle + node_modules) as a separate
// resources/server.asar sidecar instead of loose files: the NSIS installer
// then extracts a handful of large archives instead of thousands of small
@@ -1097,6 +1102,19 @@ export function resolveFffNativeDependencies(
);
}
+export function resolveMacStageDependencies(input: {
+ readonly serverDependencies: Record<string, string>;
+ readonly desktopDependencies: Record<string, string>;
+ readonly arch: typeof BuildArch.Type;
+ readonly fffNodeVersion: string;
+}) {
+ return {
+ ...selectCliRuntimeExternalDependencies(input.serverDependencies),
+ ...input.desktopDependencies,
+ ...resolveFffNativeDependencies("mac", input.arch, input.fffNodeVersion),
+ };
+}
+
export interface ClerkPasskeyNativeArtifact {
readonly packageName: string;
readonly binaryFileName: string;
@@ -2061,7 +2079,7 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
productName: resolveDesktopProductName(version),
artifactName: "T3-Code-${version}-${arch}.${ext}",
electronLanguages: [...DESKTOP_ELECTRON_LANGUAGES],
- files: [...DESKTOP_FILE_EXCLUSIONS],
+ files: [...DESKTOP_FILE_EXCLUSIONS, ...(platform === "mac" ? MAC_FILE_EXCLUSIONS : [])],
directories: {
buildResources: "apps/desktop/resources",
},
@@ -2088,6 +2106,8 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
}
if (platform === "mac") {
+ const path = yield* Path.Path;
+ const repoRoot = yield* RepoRoot;
buildConfig.mac = {
target: target === "dmg" ? [target, "zip"] : [target],
icon: "icon.icns",
@@ -2098,6 +2118,7 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
schemes: ["t3code", "t3code-dev"],
},
],
+ ...(signed ? { sign: path.join(repoRoot, "scripts/sign-macos.ts") } : {}),
...(macPasskeySigning
? {
entitlements: macPasskeySigning.entitlementsPath,
@@ -2899,21 +2920,28 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
// Windows splits dependencies per process: app.asar carries only the
// desktop main-process runtime deps, while the server bundle's deps live in
- // the server.asar sidecar (see stageWindowsServerSidecar). macOS and Linux
- // keep the single merged tree — their primary resolves everything from
- // app.asar and there is no second consumer.
+ // the server.asar sidecar (see stageWindowsServerSidecar). macOS adds only
+ // server packages that remain external to its merged app.asar. Linux retains
+ // its existing full dependency tree.
const stageDependencies =
options.platform === "win"
? { ...resolvedDesktopRuntimeDependencies }
- : {
- ...resolvedServerDependencies,
- ...resolvedDesktopRuntimeDependencies,
- ...resolveFffNativeDependencies(
- options.platform,
- options.arch,
- serverPackageJson.dependencies["@ff-labs/fff-node"],
- ),
- };
+ : options.platform === "mac"
+ ? resolveMacStageDependencies({
+ serverDependencies: resolvedServerDependencies,
+ desktopDependencies: resolvedDesktopRuntimeDependencies,
+ arch: options.arch,
+ fffNodeVersion: serverPackageJson.dependencies["@ff-labs/fff-node"],
+ })
+ : {
+ ...resolvedServerDependencies,
+ ...resolvedDesktopRuntimeDependencies,
+ ...resolveFffNativeDependencies(
+ options.platform,
+ options.arch,
+ serverPackageJson.dependencies["@ff-labs/fff-node"],
+ ),
+ };
const stagePatchedDependencies = createStagePatchedDependencies(
workspacePatchedDependencies,
stageDependencies,
@@ -3034,10 +3062,12 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
buildEnv.GYP_MSVS_VERSION = buildEnv.GYP_MSVS_VERSION ?? "2022";
}
if (options.verbose) {
- buildEnv.DEBUG =
- buildEnv.DEBUG === undefined
- ? "electron-builder,electron-builder:*"
- : `${buildEnv.DEBUG},electron-builder,electron-builder:*`;
+ const debugNamespaces = [
+ "electron-builder",
+ "electron-builder:*",
+ ...(options.platform === "mac" ? ["electron-osx-sign*", "electron-notarize*"] : []),
+ ];
+ buildEnv.DEBUG = [buildEnv.DEBUG, ...debugNamespaces].filter(Boolean).join(",");
}
yield* Effect.log(
diff --git a/scripts/package.json b/scripts/package.json
index 14c4ea98e..6e61fb308 100644
--- a/scripts/package.json
+++ b/scripts/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@effect/platform-node": "catalog:",
"@electron/asar": "^3.4.1",
+ "@electron/osx-sign": "2.7.0",
"@t3tools/contracts": "workspace:*",
"@t3tools/shared": "workspace:*",
"@t3tools/tailscale": "workspace:*",
diff --git a/scripts/sign-macos.test.ts b/scripts/sign-macos.test.ts
new file mode 100644
index 000000000..fd8d365c9
--- /dev/null
+++ b/scripts/sign-macos.test.ts
@@ -0,0 +1,26 @@
+import { sign as signApplication, type SignOptions } from "@electron/osx-sign";
+import { expect, it, vi } from "vite-plus/test";
+
+import sign from "./sign-macos.ts";
+
+vi.mock("@electron/osx-sign", () => ({ sign: vi.fn() }));
+
+it("batches codesign calls without changing existing signing options", async () => {
+ const options = {
+ app: "/tmp/T3 Code.app",
+ identity: "Developer ID Application: T3 Tools, Inc.",
+ keychain: "/tmp/t3code.keychain",
+ provisioningProfile: "/tmp/t3code.provisionprofile",
+ optionsForFile: () => ({
+ entitlements: "/tmp/t3code.entitlements.plist",
+ hardenedRuntime: true,
+ }),
+ } satisfies SignOptions;
+
+ await sign(options);
+
+ expect(signApplication).toHaveBeenCalledExactlyOnceWith({
+ ...options,
+ batchCodesignCalls: true,
+ });
+});
diff --git a/scripts/sign-macos.ts b/scripts/sign-macos.ts
new file mode 100644
index 000000000..3686db6aa
--- /dev/null
+++ b/scripts/sign-macos.ts
@@ -0,0 +1,6 @@
+import { sign as signApplication, type SignOptions } from "@electron/osx-sign";
+
+/** Sign files with matching options together instead of spawning codesign for each file. */
+export default async function sign(options: SignOptions): Promise<void> {
+ await signApplication({ ...options, batchCodesignCalls: true });
+}