The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 03:45 UTC
Stage fff native binaries in desktop builds (#3109)
Julius Marminge committed
Jun 16, 2026 at 09:12 UTC
85fe62d4021dfabe14572b7a7ef55e3f4f1144f4
6 files changed
+191
-42
apps/server/package.json
+1
-1
@@ -27,7 +27,7 @@
27
"@effect/platform-node": "catalog:",
28
"@effect/platform-node-shared": "catalog:",
29
"@effect/sql-sqlite-bun": "catalog:",
30
- "@ff-labs/fff-node": "^0.9.4",
30
+ "@ff-labs/fff-node": "0.9.4",
31
"@opencode-ai/sdk": "^1.3.15",
32
"@pierre/diffs": "catalog:",
33
"effect": "catalog:",
patches/@ff-labs__fff-node@0.9.4.patch
new
+37
@@ -0,0 +1,37 @@
1
+diff --git a/dist/src/binary.js b/dist/src/binary.js
2
+index ee181aef5007e4bf34a49479c089ca30f73a320b..327e2c55c83cc4c50d396a3109190ef10af75ca7 100644
3
+--- a/dist/src/binary.js
4
++++ b/dist/src/binary.js
5
+@@ -7,7 +7,7 @@
6
+ */
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { createRequire } from "node:module";
9
+-import { dirname, join } from "node:path";
10
++import { dirname, join, sep } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import { getLibFilename, getNpmPackageName } from "./platform.js";
13
+ /**
14
+@@ -46,6 +46,14 @@ function getPackageDir() {
15
+ // Fallback: assume we're one level deep in src/
16
+ return dirname(currentDir);
17
+ }
18
++function resolveUnpackedAsarPath(binaryPath) {
19
++ const asarSegment = `${sep}app.asar${sep}`;
20
++ if (!binaryPath.includes(asarSegment)) {
21
++ return binaryPath;
22
++ }
23
++ const unpackedPath = binaryPath.replace(asarSegment, `${sep}app.asar.unpacked${sep}`);
24
++ return existsSync(unpackedPath) ? unpackedPath : binaryPath;
25
++}
26
+ /**
27
+ * Check if the binary exists in any known location
28
+ */
29
+@@ -69,7 +77,7 @@ function resolveFromNpmPackage() {
30
+ const packageDir = dirname(packageJsonPath);
31
+ const binaryPath = join(packageDir, getLibFilename());
32
+ if (existsSync(binaryPath)) {
33
+- return binaryPath;
34
++ return resolveUnpackedAsarPath(binaryPath);
35
+ }
36
+ }
37
+ catch {
pnpm-lock.yaml
+6
-3
@@ -66,6 +66,9 @@ patchedDependencies:
66
'@expo/metro-config@56.0.13':
67
hash: 8cb08b5bb7051ed9d2dbe46a2c293c5a1e17f1bd6ddf30de27909e18c921ff46
68
path: patches/@expo%2Fmetro-config@56.0.13.patch
69
+ '@ff-labs/fff-node@0.9.4':
70
+ hash: 2b16019ce7ab61aec6478dd02f79ef468cc1d5c51e9d00764f7d2ab8167210c8
71
+ path: patches/@ff-labs__fff-node@0.9.4.patch
72
'@pierre/diffs@1.3.0-beta.4':
73
hash: f5d41705ce94bbafc731d92e9cb1671db710df046dd135cb894e3e3e9164a75b
74
path: patches/@pierre%2Fdiffs@1.3.0-beta.4.patch
@@ -396,8 +399,8 @@ importers:
399
specifier: 4.0.0-beta.78
400
version: 4.0.0-beta.78(effect@4.0.0-beta.78(patch_hash=883249d8efbb462e928e21fefef96027b66aec50751178cafdce45f08eee3754))
401
'@ff-labs/fff-node':
399
- specifier: ^0.9.4
400
- version: 0.9.4
402
+ specifier: 0.9.4
403
+ version: 0.9.4(patch_hash=2b16019ce7ab61aec6478dd02f79ef468cc1d5c51e9d00764f7d2ab8167210c8)
404
'@opencode-ai/sdk':
405
specifier: ^1.3.15
406
version: 1.15.13
@@ -11854,7 +11857,7 @@ snapshots:
11857
'@ff-labs/fff-bin-win32-x64@0.9.4':
11858
optional: true
11859
11857
- '@ff-labs/fff-node@0.9.4':
11860
+ '@ff-labs/fff-node@0.9.4(patch_hash=2b16019ce7ab61aec6478dd02f79ef468cc1d5c51e9d00764f7d2ab8167210c8)':
11861
dependencies:
11862
ffi-rs: 1.3.2
11863
optionalDependencies:
pnpm-workspace.yaml
+34
-36
@@ -1,22 +1,11 @@
1
packages:
2
- - "apps/*"
3
- - "infra/*"
4
- - "oxlint-plugin-t3code"
5
- - "packages/*"
6
- - "scripts"
7
-
8
-onlyBuiltDependencies:
9
- - electron
10
- - esbuild
11
- - msgpackr-extract
12
- - node-pty
13
- - sharp
14
-
15
-ignoredBuiltDependencies:
16
- - msw
2
+ - apps/*
3
+ - infra/*
4
+ - oxlint-plugin-t3code
5
+ - packages/*
6
+ - scripts
7
8
catalog:
19
- effect: 4.0.0-beta.78
9
"@effect/atom-react": 4.0.0-beta.78
10
"@effect/openapi-generator": 4.0.0-beta.78
11
"@effect/platform-bun": 4.0.0-beta.78
@@ -24,23 +13,33 @@ catalog:
13
"@effect/platform-node-shared": 4.0.0-beta.78
14
"@effect/sql-pg": 4.0.0-beta.78
15
"@effect/sql-sqlite-bun": 4.0.0-beta.78
27
- "@effect/vitest": 4.0.0-beta.78
16
"@effect/tsgo": 0.13.2
17
+ "@effect/vitest": 4.0.0-beta.78
18
"@noble/curves": 1.9.1
19
"@noble/hashes": 1.8.0
20
"@pierre/diffs": 1.3.0-beta.4
32
- "@vitest/runner": 4.1.8
21
"@types/node": 24.12.4
22
"@typescript/native-preview": 7.0.0-dev.20260604.1
23
+ "@vitest/runner": 4.1.8
24
+ effect: 4.0.0-beta.78
25
jose: 6.2.2
26
typescript: ~6.0.3
37
- vitest: npm:@voidzero-dev/vite-plus-test@0.1.24
27
vite: npm:@voidzero-dev/vite-plus-core@0.1.24
28
vite-plus: 0.1.24
29
+ vitest: npm:@voidzero-dev/vite-plus-test@0.1.24
30
yaml: ^2.9.0
31
+
32
+ignoredBuiltDependencies:
33
+ - msw
34
+
35
+onlyBuiltDependencies:
36
+ - electron
37
+ - esbuild
38
+ - msgpackr-extract
39
+ - node-pty
40
+ - sharp
41
+
42
overrides:
42
- # Clerk publishes wallet auth integrations as required dependencies. T3 Code does
43
- # not support wallet auth, so keep that unused dependency tree out of installs.
43
"@clerk/clerk-js>@base-org/account": "-"
44
"@clerk/clerk-js>@coinbase/wallet-sdk": "-"
45
"@clerk/clerk-js>@solana/wallet-adapter-base": "-"
@@ -56,22 +55,13 @@ overrides:
55
"@effect/vitest": "catalog:"
56
"@effect/vitest>@vitest/runner": "-"
57
"@effect/vitest>vitest": "-"
59
- # Pinned to the version the patch in patchedDependencies targets — a fresh
60
- # resolve (e.g. release-smoke regenerating the lockfile) must not drift to a
61
- # newer release and orphan the patch (ERR_PNPM_UNUSED_PATCH).
62
- "@expo/metro-config": "56.0.13"
58
+ "@expo/metro-config": 56.0.13
59
"@types/node": "catalog:"
60
effect: "catalog:"
61
vite: "catalog:"
62
vitest: "catalog:"
63
yaml: "catalog:"
68
-peerDependencyRules:
69
- allowAny:
70
- - vite
71
- - vitest
72
- allowedVersions:
73
- vite: "*"
74
- vitest: "*"
64
+
65
packageExtensions:
66
"@effect/vitest@*":
67
dependencies:
@@ -79,14 +69,22 @@ packageExtensions:
69
peerDependenciesMeta:
70
vitest:
71
optional: true
82
- "vite-plus@*":
72
+ vite-plus@*:
73
dependencies:
74
vite: "catalog:"
75
+
76
patchedDependencies:
86
- # Keep non-browser consumers off the root entrypoint, which eagerly imports
87
- # DOM-dependent renderers. These utility/type subpaths are safe for mobile.
88
- "@pierre/diffs@1.3.0-beta.4": patches/@pierre%2Fdiffs@1.3.0-beta.4.patch
77
"@effect/vitest@4.0.0-beta.78": patches/@effect__vitest@4.0.0-beta.78.patch
78
"@expo/metro-config@56.0.13": patches/@expo%2Fmetro-config@56.0.13.patch
79
+ "@ff-labs/fff-node@0.9.4": patches/@ff-labs__fff-node@0.9.4.patch
80
+ "@pierre/diffs@1.3.0-beta.4": patches/@pierre%2Fdiffs@1.3.0-beta.4.patch
81
effect@4.0.0-beta.78: patches/effect@4.0.0-beta.78.patch
82
react-native-nitro-modules@0.35.9: patches/react-native-nitro-modules@0.35.9.patch
83
+
84
+peerDependencyRules:
85
+ allowAny:
86
+ - vite
87
+ - vitest
88
+ allowedVersions:
89
+ vite: "*"
90
+ vitest: "*"
scripts/build-desktop-artifact.test.ts
+50
@@ -6,8 +6,11 @@ import * as Layer from "effect/Layer";
6
import * as Option from "effect/Option";
7
8
import {
9
+ createStageWorkspaceConfig,
10
createStagePnpmConfig,
11
+ DESKTOP_ASAR_UNPACK,
12
resolveDesktopRuntimeDependencies,
13
+ resolveFffNativeDependencies,
14
resolveBuildOptions,
15
resolveDesktopBuildIconAssets,
16
resolveDesktopProductName,
@@ -15,6 +18,7 @@ import {
18
resolveGitHubPublishConfig,
19
resolveMockUpdateServerPort,
20
resolveMockUpdateServerUrl,
21
+ STAGE_INSTALL_ARGS,
22
} from "./build-desktop-artifact.ts";
23
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
24
import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
@@ -114,17 +118,20 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
118
createStagePnpmConfig(
119
{
120
"@expo/metro-config@56.0.13": "patches/@expo%2Fmetro-config@56.0.13.patch",
121
+ "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch",
122
"@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
123
"alchemy@2.0.0-beta.49": "patches/alchemy@2.0.0-beta.49.patch",
124
"effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
125
},
126
{
127
+ "@ff-labs/fff-node": "0.9.4",
128
"@pierre/diffs": "1.1.20",
129
effect: "4.0.0-beta.73",
130
},
131
),
132
{
133
patchedDependencies: {
134
+ "@ff-labs/fff-node@0.9.4": "patches/@ff-labs__fff-node@0.9.4.patch",
135
"@pierre/diffs@1.1.20": "patches/@pierre%2Fdiffs@1.1.20.patch",
136
"effect@4.0.0-beta.73": "patches/effect@4.0.0-beta.73.patch",
137
},
@@ -142,6 +149,49 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
149
);
150
});
151
152
+ it("installs optional native dependencies for the target desktop architecture", () => {
153
+ assert.deepStrictEqual(STAGE_INSTALL_ARGS, ["install", "--prod"]);
154
+ assert.deepStrictEqual(createStageWorkspaceConfig("mac", "x64"), {
155
+ supportedArchitectures: {
156
+ os: ["darwin"],
157
+ cpu: ["x64"],
158
+ },
159
+ });
160
+ assert.deepStrictEqual(createStageWorkspaceConfig("win", "arm64"), {
161
+ supportedArchitectures: {
162
+ os: ["win32"],
163
+ cpu: ["arm64"],
164
+ },
165
+ });
166
+ assert.deepStrictEqual(createStageWorkspaceConfig("mac", "universal"), {
167
+ supportedArchitectures: {
168
+ os: ["darwin"],
169
+ cpu: ["arm64", "x64"],
170
+ },
171
+ });
172
+ });
173
+
174
+ it("unpacks the fff shared library for filesystem and FFI access", () => {
175
+ assert.deepStrictEqual(DESKTOP_ASAR_UNPACK, ["node_modules/@ff-labs/fff-bin-*/**/*"]);
176
+ });
177
+
178
+ it("promotes target fff binaries to direct staged dependencies", () => {
179
+ assert.deepStrictEqual(resolveFffNativeDependencies("mac", "arm64", "0.9.4"), {
180
+ "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
181
+ });
182
+ assert.deepStrictEqual(resolveFffNativeDependencies("mac", "universal", "0.9.4"), {
183
+ "@ff-labs/fff-bin-darwin-arm64": "0.9.4",
184
+ "@ff-labs/fff-bin-darwin-x64": "0.9.4",
185
+ });
186
+ assert.deepStrictEqual(resolveFffNativeDependencies("win", "x64", "0.9.4"), {
187
+ "@ff-labs/fff-bin-win32-x64": "0.9.4",
188
+ });
189
+ assert.deepStrictEqual(resolveFffNativeDependencies("linux", "arm64", "0.9.4"), {
190
+ "@ff-labs/fff-bin-linux-arm64-gnu": "0.9.4",
191
+ "@ff-labs/fff-bin-linux-arm64-musl": "0.9.4",
192
+ });
193
+ });
194
+
195
it("falls back to the default mock update port when the configured port is blank", () => {
196
assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
197
assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
scripts/build-desktop-artifact.ts
+63
-2
@@ -38,11 +38,19 @@ const WorkspaceConfig = Schema.Struct({
38
});
39
type WorkspaceConfig = typeof WorkspaceConfig.Type;
40
41
+const StageWorkspaceConfig = Schema.Struct({
42
+ supportedArchitectures: Schema.Struct({
43
+ os: Schema.Array(Schema.String),
44
+ cpu: Schema.Array(Schema.String),
45
+ }),
46
+});
47
+
48
const RepoRoot = Effect.service(Path.Path).pipe(
49
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
50
);
51
const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
52
const decodeWorkspaceConfig = Schema.decodeEffect(fromYaml(WorkspaceConfig));
53
+const encodeStageWorkspaceConfig = Schema.encodeEffect(fromYaml(StageWorkspaceConfig));
54
55
const readWorkspaceConfig = Effect.fn("readWorkspaceConfig")(function* () {
56
const fs = yield* FileSystem.FileSystem;
@@ -282,6 +290,47 @@ interface StagePackageJson {
290
};
291
}
292
293
+export const STAGE_INSTALL_ARGS = ["install", "--prod"] as const;
294
+export const DESKTOP_ASAR_UNPACK = ["node_modules/@ff-labs/fff-bin-*/**/*"] as const;
295
+
296
+export function resolveFffNativeDependencies(
297
+ platform: typeof BuildPlatform.Type,
298
+ arch: typeof BuildArch.Type,
299
+ version: string,
300
+): Record<string, string> {
301
+ const architectures = arch === "universal" ? (["arm64", "x64"] as const) : [arch];
302
+
303
+ if (platform === "mac") {
304
+ return Object.fromEntries(
305
+ architectures.map((architecture) => [`@ff-labs/fff-bin-darwin-${architecture}`, version]),
306
+ );
307
+ }
308
+
309
+ if (platform === "win") {
310
+ return Object.fromEntries(
311
+ architectures.map((architecture) => [`@ff-labs/fff-bin-win32-${architecture}`, version]),
312
+ );
313
+ }
314
+
315
+ return Object.fromEntries(
316
+ architectures.flatMap((architecture) =>
317
+ ["gnu", "musl"].map((libc) => [`@ff-labs/fff-bin-linux-${architecture}-${libc}`, version]),
318
+ ),
319
+ );
320
+}
321
+
322
+export function createStageWorkspaceConfig(
323
+ platform: typeof BuildPlatform.Type,
324
+ arch: typeof BuildArch.Type,
325
+): typeof StageWorkspaceConfig.Type {
326
+ return {
327
+ supportedArchitectures: {
328
+ os: [platform === "mac" ? "darwin" : platform === "win" ? "win32" : "linux"],
329
+ cpu: arch === "universal" ? ["arm64", "x64"] : [arch],
330
+ },
331
+ };
332
+}
333
+
334
export function createStagePnpmConfig(
335
patchedDependencies: Record<string, string>,
336
dependencies: Record<string, unknown>,
@@ -702,6 +751,7 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
751
appId: "com.t3tools.t3code",
752
productName: resolveDesktopProductName(version),
753
artifactName: "T3-Code-${version}-${arch}.${ext}",
754
+ asarUnpack: [...DESKTOP_ASAR_UNPACK],
755
directories: {
756
buildResources: "apps/desktop/resources",
757
},
@@ -909,6 +959,11 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
959
const stageDependencies = {
960
...resolvedServerDependencies,
961
...resolvedDesktopRuntimeDependencies,
962
+ ...resolveFffNativeDependencies(
963
+ options.platform,
964
+ options.arch,
965
+ serverPackageJson.dependencies["@ff-labs/fff-node"],
966
+ ),
967
};
968
const stagePnpmConfig = createStagePnpmConfig(workspacePatchedDependencies, stageDependencies);
969
const stagePackageJson: StagePackageJson = {
@@ -939,19 +994,25 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
994
995
const stagePackageJsonString = yield* encodeJsonString(stagePackageJson);
996
yield* fs.writeFileString(path.join(stageAppDir, "package.json"), `${stagePackageJsonString}\n`);
997
+ const stageWorkspaceConfig = createStageWorkspaceConfig(options.platform, options.arch);
998
+ const stageWorkspaceConfigString = yield* encodeStageWorkspaceConfig(stageWorkspaceConfig);
999
+ yield* fs.writeFileString(
1000
+ path.join(stageAppDir, "pnpm-workspace.yaml"),
1001
+ stageWorkspaceConfigString,
1002
+ );
1003
1004
if (Object.keys(workspacePatchedDependencies).length > 0) {
1005
yield* fs.copy(path.join(repoRoot, "patches"), path.join(stageAppDir, "patches"));
1006
}
1007
1008
yield* Effect.log("[desktop-artifact] Installing staged production dependencies...");
948
- const installCommand = yield* resolveSpawnCommand("vp", ["install", "--prod", "--no-optional"]);
1009
+ const installCommand = yield* resolveSpawnCommand("vp", [...STAGE_INSTALL_ARGS]);
1010
yield* runCommand(
1011
ChildProcess.make(installCommand.command, installCommand.args, {
1012
cwd: stageAppDir,
1013
shell: installCommand.shell,
1014
}),
954
- { label: "vp install --prod --no-optional", verbose: options.verbose },
1015
+ { label: "vp install --prod", verbose: options.verbose },
1016
);
1017
1018
// electron-builder treats several set-but-empty variables (e.g. CSC_LINK="")