Skip to content

Commit 0c1a22b

Browse files
committed
merge: reconcile main notification updates with background reports
2 parents b9bd375 + ac5e48c commit 0c1a22b

139 files changed

Lines changed: 6572 additions & 819 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/mobile-eas-production.yml‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ jobs:
230230
git config user.name "${APP_SLUG}[bot]"
231231
git config user.email "${user_id}+${APP_SLUG}[bot]@users.noreply.github.com"
232232
git add apps/mobile/app.config.ts
233-
git commit --no-verify \
234-
-m "chore(mobile): bump app version to $RELEASE_VERSION" \
235-
-m "Co-authored-by: codex <[email protected]>"
233+
git commit --no-verify -m "chore(mobile): bump app version to $RELEASE_VERSION"
236234
git push origin "HEAD:refs/heads/${GITHUB_REF_NAME}"
237235
238236
- name: Summarize manual build version
@@ -504,8 +502,21 @@ jobs:
504502
with:
505503
ref: ${{ needs.production.outputs.android_sha }}
506504
fetch-depth: 0
507-
# Dependency scripts and the build run in this job; only Record build gets a token.
508-
persist-credentials: false
505+
506+
# Dependency scripts and the build run in this job; only Record build gets a token.
507+
# persist-credentials: false would clean up via `git submodule foreach`, which fails on .repos gitlinks.
508+
- name: Drop checkout credentials
509+
run: |
510+
git config --local --unset-all http.https://github.com/.extraheader || true
511+
{ git config --local --name-only --get-regexp '^includeif\.' || true; } | while read -r key; do
512+
path=$(git config --local --get "$key")
513+
git config --local --unset-all "$key"
514+
case "$path" in "$RUNNER_TEMP"/*) rm -f "$path" ;; esac
515+
done
516+
if git config --local --get-regexp '^(http\..*\.extraheader|includeif\.)'; then
517+
echo "::error::Checkout credentials are still configured"
518+
exit 1
519+
fi
509520
510521
# A queued run can follow a build of the same fingerprint; manual runs always build.
511522
- id: record
@@ -628,6 +639,16 @@ jobs:
628639
exit 1
629640
fi
630641
642+
# A --path submission doesn't keep its archive on EAS; this is the only downloadable copy.
643+
- name: Keep the AAB
644+
if: steps.record.outputs.built != 'true'
645+
uses: actions/upload-artifact@v7
646+
with:
647+
name: android-store-aab-${{ github.run_id }}-${{ github.run_attempt }}
648+
path: ${{ runner.temp }}/t3code.aab
649+
retention-days: 14
650+
if-no-files-found: error
651+
631652
- name: Submit to Google Play
632653
if: steps.record.outputs.built != 'true'
633654
working-directory: apps/mobile
@@ -687,8 +708,21 @@ jobs:
687708
with:
688709
ref: ${{ needs.production.outputs.ios_sha }}
689710
fetch-depth: 0
690-
# Dependency scripts and the build run in this job; only Record build gets a token.
691-
persist-credentials: false
711+
712+
# Dependency scripts and the build run in this job; only Record build gets a token.
713+
# persist-credentials: false would clean up via `git submodule foreach`, which fails on .repos gitlinks.
714+
- name: Drop checkout credentials
715+
run: |
716+
git config --local --unset-all http.https://github.com/.extraheader || true
717+
{ git config --local --name-only --get-regexp '^includeif\.' || true; } | while read -r key; do
718+
path=$(git config --local --get "$key")
719+
git config --local --unset-all "$key"
720+
case "$path" in "$RUNNER_TEMP"/*) rm -f "$path" ;; esac
721+
done
722+
if git config --local --get-regexp '^(http\..*\.extraheader|includeif\.)'; then
723+
echo "::error::Checkout credentials are still configured"
724+
exit 1
725+
fi
692726
693727
# A queued run can follow a build of the same fingerprint; manual runs always build.
694728
- id: record

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ describe("ElectronShell", () => {
5454
}).pipe(Effect.provide(ElectronShell.layer)),
5555
);
5656

57+
it.effect("opens only the bare Grok Bot launch link", () =>
58+
Effect.gen(function* () {
59+
openExternalMock.mockResolvedValue(undefined);
60+
61+
const electronShell = yield* ElectronShell.ElectronShell;
62+
const results = yield* Effect.forEach(
63+
["grokbot://app", "grokbot://app/v1/prompt?id=bot&text=hi", "grokbot://"],
64+
(url) => electronShell.openExternal(url),
65+
);
66+
67+
assert.deepEqual(results, [true, false, false]);
68+
assert.deepEqual(openExternalMock.mock.calls, [["grokbot://app"]]);
69+
}).pipe(Effect.provide(ElectronShell.layer)),
70+
);
71+
5772
it.effect("opens local editor file deep links", () =>
5873
Effect.gen(function* () {
5974
openExternalMock.mockResolvedValue(undefined);

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
2121
}),
2222
);
2323

24+
// "Use T3 Code in another app" opens these apps (apps/web/src/components/mcp/mcpApps.ts). List
25+
// each exact link shape the wizard sends, never a whole scheme.
26+
const APP_LAUNCH_URLS = new Set(["grokbot://app"]);
27+
2428
// Zed embeds [user@]host in the path; reject passwords and ports there.
2529
const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/;
2630

@@ -46,6 +50,7 @@ export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
4650
try {
4751
const url = new URL(rawUrl);
4852
return SAFE_WEB_PROTOCOLS.has(url.protocol) ||
53+
APP_LAUNCH_URLS.has(url.href) ||
4954
isRemoteEditorUrl(url) ||
5055
isLocalEditorFileUrl(url)
5156
? Option.some(url.href)

‎apps/desktop/src/preview/DesktopBrowserHost.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const command = (
3434
const makeDebuggee = (
3535
options: {
3636
readonly deferFocus?: boolean;
37+
/** The guest is still loading its first page. */
38+
readonly loading?: boolean;
3739
readonly refuse?: (method: string, sessionId: string | undefined) => boolean;
3840
} = {},
3941
) => {
@@ -69,10 +71,13 @@ const makeDebuggee = (
6971
sendWaiters.shift()?.();
7072
}),
7173
});
74+
let destroyed = false;
7275
const webContents = Object.assign(new NodeEvents.EventEmitter(), {
7376
getURL: () => "http://localhost/",
7477
getTitle: () => "Page",
7578
getUserAgent: () => "Electron",
79+
isLoadingMainFrame: () => options.loading === true,
80+
isDestroyed: () => destroyed,
7681
});
7782
return {
7883
tab: {
@@ -81,6 +86,12 @@ const makeDebuggee = (
8186
},
8287
emit: (method: string, params: unknown) => emitter.emit("message", {}, method, params, ""),
8388
navigate: () => webContents.emit("did-navigate"),
89+
domReady: () => webContents.emit("dom-ready"),
90+
destroy: () => {
91+
destroyed = true;
92+
},
93+
failLoad: (code: number) =>
94+
webContents.emit("did-fail-load", {}, code, "Failed", "http://localhost/", true),
8495
/** Ids of the commands the debugger received, in order. */
8596
sent,
8697
focusEmulation,
@@ -144,6 +155,71 @@ describe("DesktopBrowserHost", () => {
144155
}),
145156
);
146157

158+
it.effect("announces a guest still loading its first page only once that page is up", () =>
159+
Effect.gen(function* () {
160+
const host = yield* DesktopBrowserHost.make;
161+
const loading = makeDebuggee({ loading: true });
162+
const other = { ...key, tabId: "tab-2" };
163+
const reader = yield* takeEvents(host, 3).pipe(Effect.forkScoped);
164+
165+
yield* Effect.yieldNow;
166+
host.attach(key, loading.tab);
167+
host.setShown(key, true);
168+
host.attach(other, makeDebuggee().tab);
169+
loading.domReady();
170+
171+
expect(yield* Fiber.join(reader)).toEqual([
172+
{ type: "attached", ...other },
173+
{ type: "attached", ...key },
174+
{ type: "shown", ...key, shown: true },
175+
]);
176+
}),
177+
);
178+
179+
it.effect(
180+
"keeps a loading guest unannounced across a replaced navigation and a new backend",
181+
() =>
182+
Effect.gen(function* () {
183+
const host = yield* DesktopBrowserHost.make;
184+
const loading = makeDebuggee({ loading: true });
185+
const other = { ...key, tabId: "tab-2" };
186+
host.attach(key, loading.tab);
187+
loading.failLoad(-3);
188+
const reader = yield* takeEvents(host, 2).pipe(Effect.forkScoped);
189+
190+
yield* Effect.yieldNow;
191+
host.attach(other, makeDebuggee().tab);
192+
loading.domReady();
193+
194+
expect(yield* Fiber.join(reader)).toEqual([
195+
{ type: "attached", ...other },
196+
{ type: "attached", ...key },
197+
]);
198+
}),
199+
);
200+
201+
it.effect(
202+
"announces a first page that never comes up, but never a tab closed or destroyed first",
203+
() =>
204+
Effect.gen(function* () {
205+
const host = yield* DesktopBrowserHost.make;
206+
const closed = { ...key, tabId: "tab-2" };
207+
const destroyed = { ...key, tabId: "tab-3" };
208+
const destroyedGuest = makeDebuggee({ loading: true });
209+
const reader = yield* takeEvents(host, 1).pipe(Effect.forkScoped);
210+
211+
yield* Effect.yieldNow;
212+
host.attach(closed, makeDebuggee({ loading: true }).tab);
213+
host.detach(closed);
214+
host.attach(destroyed, destroyedGuest.tab);
215+
destroyedGuest.destroy();
216+
host.attach(key, makeDebuggee({ loading: true }).tab);
217+
yield* TestClock.adjust("5 seconds");
218+
219+
expect(yield* Fiber.join(reader)).toEqual([{ type: "attached", ...key }]);
220+
}),
221+
);
222+
147223
it.effect("re-sends shown to a backend that starts later and when a tab attaches again", () =>
148224
Effect.gen(function* () {
149225
const host = yield* DesktopBrowserHost.make;

‎apps/desktop/src/preview/DesktopBrowserHost.ts‎

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import * as Context from "effect/Context";
99
import * as NodePath from "node:path";
1010
import * as Effect from "effect/Effect";
11+
import * as Fiber from "effect/Fiber";
1112
import * as Layer from "effect/Layer";
1213
import * as Option from "effect/Option";
1314
import * as PubSub from "effect/PubSub";
@@ -26,6 +27,9 @@ const AGENT_INPUT_COMMAND =
2627
const AGENT_INPUT_METHOD = /^(?:Input\.|Page\.navigate$|Runtime\.(?:evaluate|callFunctionOn)$)/;
2728
const AGENT_DOWNLOAD_WINDOW_MS = 5_000;
2829
const FOCUS_IDLE = "5 seconds";
30+
/** Well inside the server's 10 s DESKTOP_ATTACH_TIMEOUT, for a first page that never reports it is up. */
31+
const FIRST_PAGE_TIMEOUT = "5 seconds";
32+
const ERR_ABORTED = -3;
2933

3034
export interface DesktopBrowserTabKey {
3135
readonly threadId: string;
@@ -78,6 +82,8 @@ interface AttachedTab {
7882
sessionId: string,
7983
) => void;
8084
readonly onNewDocument: () => void;
85+
/** Stops waiting for the first page; set until the tab is announced. */
86+
stopWaiting: (() => void) | null;
8187
}
8288

8389
export class DesktopBrowserHost extends Context.Service<
@@ -413,11 +419,13 @@ export const make = Effect.gen(function* () {
413419
const tab = tabs.get(id);
414420
if (!tab) return;
415421
tabs.delete(id);
422+
const announced = tab.stopWaiting === null;
423+
tab.stopWaiting?.();
416424
tab.relay = null;
417425
tab.debuggee.debugger.off("message", tab.onMessage);
418426
tab.debuggee.webContents.off("did-navigate", tab.onNewDocument);
419427
syncPainting(tab);
420-
emit({ type: "detached", ...key });
428+
if (announced) emit({ type: "detached", ...key });
421429
};
422430

423431
const attach = (key: DesktopBrowserTabKey, debuggee: DesktopBrowserTabDebugger) => {
@@ -455,13 +463,53 @@ export const make = Effect.gen(function* () {
455463
dropFocusHolds(tab);
456464
if (tab.screenshotTurn !== null) nextScreenshot(tab);
457465
},
466+
stopWaiting: null,
458467
};
459468
tabs.set(id, tab);
460469
debuggee.debugger.on("message", tab.onMessage);
461470
debuggee.webContents.on("did-navigate", tab.onNewDocument);
462-
emit({ type: "attached", ...key });
463-
const shown = shownTabs.get(id);
464-
if (shown !== undefined) emit({ type: "shown", ...key, shown });
471+
const announce = () => {
472+
emit({ type: "attached", ...key });
473+
const shown = shownTabs.get(id);
474+
if (shown !== undefined) emit({ type: "shown", ...key, shown });
475+
};
476+
if (!debuggee.webContents.isLoadingMainFrame()) {
477+
announce();
478+
return;
479+
}
480+
// Electron does not pause a guest for the debugger, so Playwright connecting during its first
481+
// commit builds its utility world in the discarded document and every wait on it hangs.
482+
const { webContents } = debuggee;
483+
// ERR_ABORTED is a newer navigation replacing this one, whose commit is still to come.
484+
const onFailLoad = (
485+
_event: Electron.Event,
486+
code: number,
487+
_description: string,
488+
_url: string,
489+
isMainFrame: boolean,
490+
) => {
491+
if (isMainFrame && code !== ERR_ABORTED) ready();
492+
};
493+
const ready = () => {
494+
if (tab.stopWaiting === null) return;
495+
// The manager's cleanup for a destroyed guest can still be queued behind another tab's attach.
496+
if (webContents.isDestroyed()) return detach(key);
497+
tab.stopWaiting();
498+
announce();
499+
};
500+
const timeout = runFork(
501+
Effect.sleep(FIRST_PAGE_TIMEOUT).pipe(Effect.andThen(Effect.sync(ready))),
502+
);
503+
tab.stopWaiting = () => {
504+
tab.stopWaiting = null;
505+
webContents.off("dom-ready", ready);
506+
webContents.off("did-stop-loading", ready);
507+
webContents.off("did-fail-load", onFailLoad);
508+
runFork(Fiber.interrupt(timeout));
509+
};
510+
webContents.on("dom-ready", ready);
511+
webContents.on("did-stop-loading", ready);
512+
webContents.on("did-fail-load", onFailLoad);
465513
};
466514

467515
const setShown = (key: DesktopBrowserTabKey, shown: boolean | undefined) => {
@@ -472,7 +520,7 @@ export const make = Effect.gen(function* () {
472520
}
473521
if (shownTabs.get(id) === shown) return;
474522
shownTabs.set(id, shown);
475-
if (tabs.has(id)) emit({ type: "shown", ...key, shown });
523+
if (tabs.get(id)?.stopWaiting === null) emit({ type: "shown", ...key, shown });
476524
};
477525

478526
const handleCommandLine = (line: string) =>
@@ -511,6 +559,8 @@ export const make = Effect.gen(function* () {
511559
[...tabs.values()],
512560
(tab) => {
513561
dropRelay(tab);
562+
// Announced once its first page is up.
563+
if (tab.stopWaiting !== null) return Effect.void;
514564
const shown = shownTabs.get(keyOf(tab.key));
515565
return PubSub.publish(outbox, { type: "attached", ...tab.key }).pipe(
516566
Effect.andThen(

0 commit comments

Comments
 (0)