Skip to content

Commit 6c820c5

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-24223
2 parents 38cf023 + 4fc9e5f commit 6c820c5

305 files changed

Lines changed: 2355 additions & 1009 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.

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Architecture and its constraints: `docs/internals/overview.md`. Glossary: `docs/
199199
options, and pass combinators as additional function-builder arguments.
200200
- Inferred types over annotations. `any` is the enemy.
201201
- Default to no comment. Write one only for a constraint, an external quirk, or an invariant the code can't show, in one line where you can and four at most. Don't restate names or signatures, narrate steps, record history, or explain the fix you just made; the PR carries that. `t3code/no-low-value-comments` enforces the length cap and the mechanical cases.
202-
- React effects are for synchronizing with something outside React. Derive in render and act in handlers instead of syncing state, but don't hide real lifecycle work in refs or stores to dodge one. The `t3code/react-effect-budget` lint rule holds each file to its count in `scripts/effect-budget.json`; a new effect states its reason with `// oxlint-disable-next-line t3code/react-effect-budget -- <why>`.
202+
- React effects are for synchronizing with something outside React. Derive in render and act in handlers instead of syncing state, but don't hide real lifecycle work in refs or stores to dodge one. The `t3code/no-unreasoned-state-sync` lint rule reports every effect; one that stays states its reason with `// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- <why>`.
203203
- Our users drive agents all day and notice a dropped frame, a lying spinner, and a stale label. No continuously repainting animations; they peg the GPU on high-refresh displays.
204204
- If a rule here fights the task in front of you, say so loudly and get a human sign-off before breaking it.
205205

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ describe("DesktopClerk", () => {
156156
`setPath:userData:${userData}`,
157157
"requestSingleInstanceLock",
158158
"on:second-instance",
159+
"on:open-url",
159160
"createClerkBridge",
160161
]);
161162
},
@@ -200,14 +201,15 @@ describe("DesktopClerk", () => {
200201
},
201202
);
202203

203-
it.effect("delivers queued startup links and later links once in arrival order", () => {
204+
it.effect("delivers each queued startup link once, before later links", () => {
204205
storageMock.mockReturnValue(storageAdapter);
205206
createClerkBridgeMock.mockReturnValue({ cleanup: vi.fn(), isPrimaryInstance: true });
206207
const listeners = new Map<string, (...args: unknown[]) => void>();
207208
const received: string[] = [];
208209
const first = "t3code://new?prompt=first";
209210
const second = "t3code://threads/env-1/thread-1";
210211
const later = "t3code://new?prompt=later";
212+
const launchPair = "t3code://pair?pairingUrl=https%3A%2F%2Fvps.example.com%2F%23token%3Dabc";
211213
const delivered = Promise.withResolvers<void>();
212214
const electronApp = {
213215
on: (name: string, listener: (...args: unknown[]) => void) =>
@@ -220,13 +222,14 @@ describe("DesktopClerk", () => {
220222
const clerk = yield* DesktopClerk.DesktopClerk;
221223
listeners.get("second-instance")?.({}, ["t3", first]);
222224
listeners.get("second-instance")?.({}, ["t3", second]);
225+
listeners.get("open-url")?.({ preventDefault: () => undefined }, launchPair);
223226
assert.deepEqual(received, []);
224227

225228
yield* clerk.configure;
226229
listeners.get("second-instance")!({}, ["t3", later]);
227230
yield* Effect.promise(() => delivered.promise);
228231

229-
assert.deepEqual(received, [first, second, later]);
232+
assert.deepEqual(received, [launchPair, first, second, later]);
230233
}).pipe(
231234
Effect.scoped,
232235
Effect.provide(layerDesktopClerk(true, [], "darwin", undefined, undefined, listeners)),
@@ -425,6 +428,7 @@ it.effect("hands web and app links to the renderer and leaves other links alone"
425428
}),
426429
} as unknown as ElectronApp.ElectronApp["Service"];
427430
const received: Array<string> = [];
431+
const pairLink = "t3code://pair?pairingUrl=https%3A%2F%2Fvps.example.com%2F%23token%3Dabc";
428432
yield* Effect.gen(function* () {
429433
const clerk = yield* DesktopClerk.DesktopClerk;
430434
yield* clerk.configure;
@@ -437,6 +441,8 @@ it.effect("hands web and app links to the renderer and leaves other links alone"
437441
assert.strictEqual(open("http://localhost:3000/"), 1);
438442
assert.strictEqual(open("t3code://new?prompt=hi"), 1);
439443
assert.strictEqual(open("t3code://threads/env-1/thread-1"), 1);
444+
assert.strictEqual(open(pairLink), 1);
445+
assert.strictEqual(open("t3code://pair"), 0);
440446
assert.strictEqual(open("mailto:[email protected]"), 0);
441447
assert.strictEqual(open("t3code://somewhere-else"), 0);
442448
yield* Effect.yieldNow;
@@ -445,6 +451,7 @@ it.effect("hands web and app links to the renderer and leaves other links alone"
445451
"http://localhost:3000/",
446452
"t3code://new?prompt=hi",
447453
"t3code://threads/env-1/thread-1",
454+
pairLink,
448455
]);
449456
}).pipe(
450457
Effect.provide(layerDesktopClerk(true, [], "darwin", undefined, undefined, listeners)),

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { receiveCodexAuthCallback, CodexAuthCallbackError } from "./CodexAuthCal
1313
import * as ElectronShell from "../electron/ElectronShell.ts";
1414
import { providerAuthReturnUrl } from "@t3tools/shared/providerAuthReturnUrl";
1515
import { promptLinkAppPath } from "@t3tools/shared/promptLinks";
16+
import { readPairingAppLink } from "@t3tools/shared/remote";
1617
import * as HostProcess from "@t3tools/shared/HostProcess";
1718
import { clerkFrontendApiHostnameFromPublishableKey } from "@t3tools/shared/relayAuth";
1819
import * as ElectronApp from "../electron/ElectronApp.ts";
@@ -118,6 +119,15 @@ export const make = Effect.gen(function* () {
118119
yield* electronApp.on("second-instance", (_event: unknown, argv: readonly string[]) => {
119120
handleSecondInstance(argv);
120121
});
122+
// macOS hands a launch link to open-url, which can fire before configure runs.
123+
const pendingOpenUrls: Array<string> = [];
124+
let handleOpenUrl = (url: string) => {
125+
pendingOpenUrls.push(url);
126+
return true;
127+
};
128+
yield* electronApp.on("open-url", (event: { preventDefault: () => void }, url: string) => {
129+
if (handleOpenUrl(url)) event.preventDefault();
130+
});
121131

122132
yield* Effect.acquireRelease(
123133
Effect.try({
@@ -194,7 +204,8 @@ export const make = Effect.gen(function* () {
194204
return true;
195205
};
196206
const openAppLink = (value: string | undefined) => {
197-
if (!value || promptLinkAppPath(value) === null) return false;
207+
if (!value || (promptLinkAppPath(value) === null && readPairingAppLink(value) === null))
208+
return false;
198209
void runPromise(webLinks.receive(value));
199210
return true;
200211
};
@@ -205,15 +216,12 @@ export const make = Effect.gen(function* () {
205216
void runPromise(webLinks.receive(url));
206217
return true;
207218
};
208-
yield* electronApp.on("open-url", (event: { preventDefault: () => void }, url: string) => {
209-
if (
210-
startProviderAuthHandoff(url) ||
211-
resumeProviderAuth(url) ||
212-
openWebLink(url) ||
213-
openAppLink(url)
214-
)
215-
event.preventDefault();
216-
});
219+
handleOpenUrl = (url) =>
220+
startProviderAuthHandoff(url) ||
221+
resumeProviderAuth(url) ||
222+
openWebLink(url) ||
223+
openAppLink(url);
224+
for (const url of pendingOpenUrls.splice(0)) handleOpenUrl(url);
217225
yield* electronApp.on("open-file", (event: { preventDefault: () => void }, path: string) => {
218226
if (!DesktopWebLinks.isWebPageFile(path)) return;
219227
event.preventDefault();

‎apps/mobile/src/App.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ disposeOnFoundationReplace(typeof module === "undefined" ? undefined : module.ho
195195
function SplashScreenCoordinator() {
196196
const { isReady } = useAppearancePreferences();
197197

198+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- hides the native splash screen once appearance preferences have loaded
198199
useEffect(() => {
199200
if (isReady) void SplashScreen.hide();
200201
}, [isReady]);

‎apps/mobile/src/components/ComposerEditor.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function ComposerEditor({
6161
? preferencesResult.value.composerEnterBehavior
6262
: undefined;
6363
const contextHistory = createComposerDraftContextHistory();
64+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- releases the attachment file leases held for native text undo when the history is replaced or unmounts
6465
useEffect(() => () => contextHistory.dispose(), [contextHistory]);
6566
const changeText = (text: string) => {
6667
const restored = contextHistory.restore(

‎apps/mobile/src/components/FilePreview.ios.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function NativeFilePreview(props: {
3434
else Dialog.alert("Could not open preview", "The file could not be loaded. Please try again.");
3535
});
3636

37+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- presents the native file preview and dismisses it on cleanup
3738
useEffect(() => {
3839
let canceled = false;
3940
const presentation =

‎apps/mobile/src/components/FilePreview.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function DocumentPreview(props: {
5555
"A compatible viewer must be installed. Check your connection and try again.",
5656
);
5757
});
58+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- opens the attachment in an external viewer and aborts the open on cleanup
5859
useEffect(() => {
5960
const controller = new AbortController();
6061
const input = {

‎apps/mobile/src/components/FilePreviewModal.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function ResolvedFilePreview(props: {
8686
props.onRequestClose();
8787
});
8888
// Resolves once per presentation and holds local file leases until it closes.
89+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- resolves preview files and holds their local file leases until the preview closes
8990
useEffect(() => {
9091
if (items.every((item) => "uri" in item)) return;
9192
const controller = new AbortController();

‎apps/mobile/src/components/MediaVideoPlayer.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function LoadedMediaVideo(props: {
3333
useMediaVideoPlayback(player, props, playback);
3434
const previousPlaybackRequested = useRef(false);
3535
const onPlaybackStart = useEffectEvent(() => props.onPlaybackStart?.());
36+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to native video player events to keep the shared audio session in step
3637
useEffect(() => {
3738
const subscription = player.addListener("playingChange", ({ isPlaying }) => {
3839
if (isPlaying && !active.current && !fullscreen.current) playback.pause();
@@ -74,6 +75,7 @@ function LoadedMediaVideo(props: {
7475
if (!signal.aborted && props.playRequested) await playIfUninterrupted();
7576
});
7677

78+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- loads the video source into the native player and aborts the load on cleanup
7779
useEffect(() => {
7880
const controller = new AbortController();
7981
// oxlint-disable-next-line react/set-state-in-effect -- Starting a native media load publishes pending before its async result.

‎apps/mobile/src/components/ProjectFavicon.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function ProjectFaviconImage(props: {
165165
);
166166
// Registers with the module-level loader before the Image's native onLoad/onError can fire,
167167
// so stale loads for a superseded URL under the same cacheKey are ignored.
168+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- marks this favicon URL as the current request in the module registry before the native Image reports load or error
168169
useLayoutEffect(() => {
169170
if (faviconRequest === null) return;
170171
return beginProjectFaviconRequest(faviconRequest);

0 commit comments

Comments
 (0)