Skip to content

Commit 23b3793

Browse files
committed
merge: sync main and preserve worktree setup controls
2 parents 64af187 + 6f00d38 commit 23b3793

249 files changed

Lines changed: 14844 additions & 5063 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/release-desktop.yml‎

Lines changed: 528 additions & 0 deletions
Large diffs are not rendered by default.

‎.github/workflows/release.yml‎

Lines changed: 358 additions & 455 deletions
Large diffs are not rendered by default.

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules
55
*.log
66
*.tsbuildinfo
77
apps/*/dist
8+
apps/*/dist-exe
89
infra/*/dist
910
.astro
1011
packages/*/dist

‎.macroscope/check-run-agents/effect-service-conventions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Effect Service Conventions
33
model: gpt-5-6-sol
44
effort: medium
5-
input: full_diff
5+
input: incremental
66
tools:
77
- browse_code
88
- modify_pr

‎.macroscope/check-run-agents/ui-consistency.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: UI Consistency
3-
model: gpt-5-6-terra
3+
model: gpt-5-6-sol
44
effort: medium
5-
input: full_diff
5+
input: incremental
66
tools:
77
- browse_code
88
- modify_pr

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ The most common defect in this repo is a change that works on the path you teste
7979
- `vp i` installs. Worktrees get this from the t3.json setup script; if module resolution looks broken, it probably did not run.
8080
- `vp run dev` starts server and web. In a worktree, state defaults to that worktree's gitignored `.t3`, which deliberately outranks an ambient `T3CODE_HOME` so you cannot land on shared state by accident. An explicit `--home-dir` still wins.
8181
- Ports derive from the worktree path and are stable across restarts, but read the real ones from the `[dev-runner]` line since occupied ports shift.
82-
- Sharing over the tailnet is three steps: run `vp run dev --share` in the background, wait for the `pairingUrl:` line in its output, paste that full URL (token included) in your reply. Do not wire up `tailscale serve` by hand for this, and do not open the URL yourself.
83-
- The web app requires pairing. Hand over the pairing URL, not the bare origin. A URL without its token is useless to whoever you gave it to. If the token got consumed, mint a fresh one with `node apps/server/src/bin.ts pair` — note it carries standard scopes, while the startup URL carries admin scopes (needed for Settings → Connections management).
82+
- Sharing over the tailnet is three steps: run `vp run dev --share` in the background, wait for the `pairingUrl:` line in its output, then give that full URL to an unpaired browser. Do not wire up `tailscale serve` by hand, open the URL yourself, or consume the user's pairing link. A browser with the reusable dev cookie can use the bare origin. If a normal one-time token was consumed, mint a fresh one with `node apps/server/src/bin.ts pair`. It carries standard scopes, while the startup URL carries admin scopes needed for Connections settings.
83+
- To reuse web dev auth across worktrees, configure one fixed `T3CODE_DEV_AUTH_TOKEN` in the main checkout's gitignored `.env`. The `t3.json` setup links that file into worktrees. Never commit or publish the token or a startup URL. See [Reusable dev credential](docs/operations/development.md#reusable-dev-credential).
8484
- Stop what you started, by the PID you tracked. See rule 1.
8585

8686
## Test data

‎apps/desktop/src/app/DesktopApp.ts‎

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,43 @@ export const stopAllPoolInstances = Effect.fn("desktop.app.stopAllPoolInstances"
158158
);
159159

160160
const bootstrap = Effect.gen(function* () {
161-
const pool = yield* DesktopBackendPool.DesktopBackendPool;
162-
const primaryBackend = yield* pool.primary;
163161
const state = yield* DesktopState.DesktopState;
164162
const environment = yield* DesktopEnvironment.DesktopEnvironment;
165163
const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings;
166-
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
167-
const wslBackend = yield* DesktopWslBackend.DesktopWslBackend;
168164
const desktopWindow = yield* DesktopWindow.DesktopWindow;
169165
const snapShot = yield* DesktopSnapShot.DesktopSnapShot;
170166
const appActivation = yield* DesktopAppActivation.DesktopAppActivation;
171167
yield* logBootstrapInfo("bootstrap start");
172168

169+
const settings = yield* desktopSettings.get;
170+
// The renderer is served from the bundled client (or Vite in development)
171+
// rather than through the local backend, so the window can open without one.
172+
const electronProtocol = yield* ElectronProtocol.ElectronProtocol;
173+
yield* electronProtocol.registerDesktopProtocol({
174+
scheme: ElectronProtocol.getDesktopScheme(environment.isDevelopment),
175+
...(environment.isDevelopment
176+
? { targetOrigin: Option.getOrThrow(environment.devServerUrl) }
177+
: { assetDirectory: environment.clientAssetsDir }),
178+
clerkFrontendApiHostname: DesktopClerk.desktopClerkFrontendApiHostname,
179+
});
180+
yield* installDesktopIpcHandlers();
181+
yield* logBootstrapInfo("bootstrap ipc handlers registered");
182+
183+
yield* snapShot.initialize;
184+
185+
if (!settings.localEnvironmentEnabled) {
186+
yield* logBootstrapInfo("bootstrap skipping local environment (disabled in settings)");
187+
if (!(yield* Ref.get(state.quitting))) {
188+
yield* desktopWindow.createMainIfBackendReady;
189+
}
190+
return;
191+
}
192+
193+
const pool = yield* DesktopBackendPool.DesktopBackendPool;
194+
const primaryBackend = yield* pool.primary;
195+
const serverExposure = yield* DesktopServerExposure.DesktopServerExposure;
196+
const wslBackend = yield* DesktopWslBackend.DesktopWslBackend;
197+
173198
if (environment.isDevelopment && Option.isNone(environment.configuredBackendPort)) {
174199
return yield* new DesktopDevelopmentBackendPortRequiredError();
175200
}
@@ -186,24 +211,13 @@ const bootstrap = Effect.gen(function* () {
186211
},
187212
);
188213

189-
const settings = yield* desktopSettings.get;
190214
if (settings.serverExposureMode !== environment.defaultDesktopSettings.serverExposureMode) {
191215
yield* logBootstrapInfo("bootstrap restoring persisted server exposure mode", {
192216
mode: settings.serverExposureMode,
193217
});
194218
}
195219
const serverExposureState = yield* serverExposure.configureFromSettings({ port: backendPort });
196220
const backendConfig = yield* serverExposure.backendConfig;
197-
const electronProtocol = yield* ElectronProtocol.ElectronProtocol;
198-
const rendererTarget = environment.isDevelopment
199-
? Option.getOrThrow(environment.devServerUrl)
200-
: backendConfig.httpBaseUrl;
201-
yield* electronProtocol.registerDesktopProtocol({
202-
scheme: ElectronProtocol.getDesktopScheme(environment.isDevelopment),
203-
targetOrigin: rendererTarget,
204-
backendOrigin: backendConfig.httpBaseUrl,
205-
clerkFrontendApiHostname: DesktopClerk.desktopClerkFrontendApiHostname,
206-
});
207221
yield* logBootstrapInfo("bootstrap resolved backend endpoint", {
208222
baseUrl: backendConfig.httpBaseUrl.href,
209223
});
@@ -219,16 +233,13 @@ const bootstrap = Effect.gen(function* () {
219233
"bootstrap fell back to local-only because no advertised network host was available",
220234
);
221235
}
222-
yield* snapShot.initialize;
223-
224-
yield* installDesktopIpcHandlers();
225-
yield* logBootstrapInfo("bootstrap ipc handlers registered");
226236

227237
if (!(yield* Ref.get(state.quitting))) {
228-
// In wsl-only mode the renderer is served by the WSL backend, which can be
229-
// slow to cold-boot — show a "Connecting to WSL" splash immediately so the
230-
// app feels responsive instead of presenting no window until WSL is ready.
231-
// (Dual mode opens fast off the Windows primary, so no splash there.)
238+
// The main window waits for the primary backend. In wsl-only mode that is
239+
// the WSL backend, which can be slow to cold-boot — show a "Connecting to
240+
// WSL" splash immediately so the app feels responsive instead of presenting
241+
// no window until WSL is ready. (Dual mode opens fast off the Windows
242+
// primary, so no splash there.)
232243
if (settings.wslOnly === true && settings.wslBackendEnabled === true) {
233244
yield* desktopWindow.showConnectingSplash;
234245
}

‎apps/desktop/src/app/DesktopEnvironment.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ describe("DesktopEnvironment", () => {
120120
environment.backendEntryPath,
121121
"/install/resources/server.asar/apps/server/dist/bin.mjs",
122122
);
123+
assert.equal(
124+
environment.clientAssetsDir,
125+
"/install/resources/server.asar/apps/server/dist/client",
126+
);
123127
}),
124128
);
125129

‎apps/desktop/src/app/DesktopEnvironment.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export class DesktopEnvironment extends Context.Service<
6161
// extracts on demand (see DesktopWslServerTree).
6262
readonly serverRoot: string;
6363
readonly backendEntryPath: string;
64+
// Built web client the packaged renderer is served from over t3code://app.
65+
readonly clientAssetsDir: string;
6466
readonly backendCwd: string;
6567
readonly preloadPath: string;
6668
readonly appUpdateYmlPath: string;
@@ -211,6 +213,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
211213
appRoot,
212214
serverRoot,
213215
backendEntryPath: path.join(serverRoot, "apps/server/dist/bin.mjs"),
216+
clientAssetsDir: path.join(serverRoot, "apps/server/dist/client"),
214217
backendCwd: input.isPackaged ? homeDirectory : appRoot,
215218
preloadPath: path.join(input.dirname, "preload.cjs"),
216219
appUpdateYmlPath: input.isPackaged

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 44 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ describe("DesktopBackendConfiguration", () => {
374374
runtimeId: string;
375375
sha256: string;
376376
}> = [];
377-
const observedNodePtyRoots: string[] = [];
377+
const observedProbeRoots: string[] = [];
378378
let legacyCleanupCount = 0;
379379
const linuxAppRoot = "/home/test/.t3/wsl-runtime/1.2.3-x64";
380+
const resolvedPath = "/home/test/.local/bin:/usr/bin:/bin";
380381

381382
return withPackagedWslHarness(
382383
{
@@ -394,9 +395,14 @@ describe("DesktopBackendConfiguration", () => {
394395
});
395396
return { ok: true, linuxAppRoot };
396397
},
397-
ensureNodePty: (_distro, root) => {
398-
observedNodePtyRoots.push(root);
399-
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
398+
probeRuntime: (_distro, root) => {
399+
observedProbeRoots.push(root);
400+
return { ok: true, resolvedPath };
401+
},
402+
// The staged runtime carries its own Node, so the preflight must not
403+
// go looking for one in the distro.
404+
ensureNodePty: () => {
405+
throw new Error("the staged runtime must not probe for Node");
400406
},
401407
}),
402408
},
@@ -413,12 +419,22 @@ describe("DesktopBackendConfiguration", () => {
413419
sha256: archiveHash,
414420
},
415421
]);
416-
assert.deepEqual(observedNodePtyRoots, [linuxAppRoot]);
422+
assert.deepEqual(observedProbeRoots, [linuxAppRoot]);
417423
assert.equal(
418424
config.entryPath,
419425
path.join(baseDir, "server.asar/apps/server/dist/bin.mjs"),
420426
);
421-
assert.include(config.args, `${linuxAppRoot}/apps/server/dist/bin.mjs`);
427+
assert.deepEqual(config.args, [
428+
"-d",
429+
"Ubuntu",
430+
"--exec",
431+
"env",
432+
`PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${resolvedPath}`,
433+
`${linuxAppRoot}/t3`,
434+
"--bootstrap-fd",
435+
"0",
436+
]);
437+
assert.notInclude(config.args, "/usr/bin/node");
422438
assert.equal(config.wslRuntimeId, `sha256-${archiveHash}`);
423439
assert.equal(legacyCleanupCount, 1);
424440
assert.isTrue(Option.isNone(config.preflightFailure));
@@ -457,8 +473,11 @@ describe("DesktopBackendConfiguration", () => {
457473

458474
assert.deepEqual(observedRuntimeIds, [`sha256-${firstHash}`, `sha256-${secondHash}`]);
459475
assert.equal(first.wslRuntimeId, observedRuntimeIds[0]);
476+
assert.include(first.args, `/runtime/sha256-${firstHash}/t3`);
460477
assert.equal(second.wslRuntimeId, observedRuntimeIds[1]);
478+
assert.include(second.args, `/runtime/sha256-${secondHash}/t3`);
461479
assert.isUndefined(invalidIdentity.wslRuntimeId);
480+
assert.include(invalidIdentity.args, "/usr/bin/node");
462481
assert.include(invalidIdentity.args, `${mountedAppRoot}/apps/server/dist/bin.mjs`);
463482
}),
464483
);
@@ -484,16 +503,18 @@ describe("DesktopBackendConfiguration", () => {
484503

485504
assert.deepEqual(observedNodePtyRoots, [mountedAppRoot]);
486505
assert.equal(config.entryPath, mountedEntryPath);
506+
assert.include(config.args, "/usr/bin/node");
487507
assert.include(config.args, `${mountedAppRoot}/apps/server/dist/bin.mjs`);
488508
assert.isUndefined(config.wslRuntimeId);
489509
assert.isTrue(Option.isNone(config.preflightFailure));
490510
}),
491511
);
492512
});
493513

494-
it.effect("resolveWsl retires a staged runtime that cannot load node-pty", () => {
514+
it.effect("resolveWsl retires a staged runtime whose executable does not start", () => {
495515
const archiveHash = "c".repeat(64);
496516
const stagedAppRoot = `/home/test/.t3/wsl-runtime/sha256-${archiveHash}`;
517+
const observedProbeRoots: string[] = [];
497518
const observedNodePtyRoots: string[] = [];
498519
const invalidatedRuntimeIds: string[] = [];
499520
return withPackagedWslHarness(
@@ -505,11 +526,13 @@ describe("DesktopBackendConfiguration", () => {
505526
Effect.sync(() => {
506527
invalidatedRuntimeIds.push(runtimeId);
507528
}),
529+
probeRuntime: (_distro, root) => {
530+
observedProbeRoots.push(root);
531+
return { ok: false, reason: `${root}/t3 --version failed (exit 127)` };
532+
},
508533
ensureNodePty: (_distro, root) => {
509534
observedNodePtyRoots.push(root);
510-
return root === stagedAppRoot
511-
? { ok: false, reason: "pty.node could not be loaded", fatal: true }
512-
: { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
535+
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
513536
},
514537
}),
515538
},
@@ -518,8 +541,11 @@ describe("DesktopBackendConfiguration", () => {
518541
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
519542
const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
520543

521-
assert.deepEqual(observedNodePtyRoots, [stagedAppRoot, mountedAppRoot]);
544+
assert.deepEqual(observedProbeRoots, [stagedAppRoot]);
545+
assert.deepEqual(observedNodePtyRoots, [mountedAppRoot]);
546+
assert.include(config.args, "/usr/bin/node");
522547
assert.include(config.args, `${mountedAppRoot}/apps/server/dist/bin.mjs`);
548+
assert.notInclude(config.args, `${stagedAppRoot}/t3`);
523549
assert.equal(config.entryPath, mountedEntryPath);
524550
assert.isUndefined(config.wslRuntimeId);
525551
assert.isTrue(Option.isNone(config.preflightFailure));
@@ -540,12 +566,13 @@ describe("DesktopBackendConfiguration", () => {
540566
Effect.sync(() => {
541567
invalidatedRuntimeIds.push(runtimeId);
542568
}),
543-
ensureNodePty: (_distro, root) => ({
569+
probeRuntime: () => ({
544570
ok: false,
545-
reason:
546-
root === stagedAppRoot
547-
? "unsupported CPU architecture or incompatible system libraries"
548-
: "mounted tree is broken in some other way",
571+
reason: "unsupported CPU architecture or incompatible system libraries",
572+
}),
573+
ensureNodePty: () => ({
574+
ok: false,
575+
reason: "mounted tree is broken in some other way",
549576
fatal: true,
550577
}),
551578
}),
@@ -575,51 +602,11 @@ describe("DesktopBackendConfiguration", () => {
575602
Effect.sync(() => {
576603
invalidatedRuntimeIds.push(runtimeId);
577604
}),
578-
ensureNodePty: (_distro, root) =>
579-
root === stagedAppRoot
580-
? { ok: false, reason: "pty.node could not be loaded", fatal: true }
581-
: {
582-
ok: false,
583-
reason: "WSL backend preflight timed out while probing for Node.js.",
584-
fatal: false,
585-
},
586-
}),
587-
},
588-
() =>
589-
Effect.gen(function* () {
590-
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
591-
const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
592-
const failure = Option.getOrThrow(config.preflightFailure);
593-
594-
assert.isFalse(failure.fatal);
595-
assert.equal(failure.retryLimit, 12);
596-
assert.include(failure.reason, "timed out");
597-
assert.deepEqual(invalidatedRuntimeIds, []);
598-
}),
599-
);
600-
});
601-
602-
it.effect("resolveWsl retries the staged runtime after a transient probe failure", () => {
603-
const invalidatedRuntimeIds: string[] = [];
604-
return withPackagedWslHarness(
605-
{
606-
archiveHash: "e".repeat(64),
607-
forbidFallback: "A transient probe failure must not extract the fallback",
608-
forbidCleanup: "A transient probe failure must not clean the fallback tree",
609-
wsl: () => ({
610-
prepareRuntime: () => ({
611-
ok: true,
612-
linuxAppRoot: "/home/test/.t3/wsl-runtime/cache",
613-
}),
614-
invalidateRuntime: (_distro, runtimeId) =>
615-
Effect.sync(() => {
616-
invalidatedRuntimeIds.push(runtimeId);
617-
}),
605+
probeRuntime: () => ({ ok: false, reason: "t3 --version failed (exit 1)" }),
618606
ensureNodePty: () => ({
619607
ok: false,
620608
reason: "WSL backend preflight timed out while probing for Node.js.",
621609
fatal: false,
622-
retryLimit: 12,
623610
}),
624611
}),
625612
},

0 commit comments

Comments
 (0)