The best way to control Claude Code, Codex and more from any computer or phone
feat(web): ask for a GitHub star when idle, and star in one click (#29922)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Nov 2, 2026 at 22:56 UTC
5d3d78ab932bc71535d3155dad7f68fef39c5c16
11 files changed
+231
-36
apps/server/src/observability/RpcInstrumentation.ts
+1
@@ -142,6 +142,7 @@ const RPC_AGGREGATES = {
142
[WS_METHODS.sourceControlSignInCancel]: "source-control",
143
[WS_METHODS.sourceControlAppAccess]: "source-control",
144
[WS_METHODS.sourceControlStarred]: "source-control",
145
+ [WS_METHODS.sourceControlStar]: "source-control",
146
[WS_METHODS.projectCloneStart]: "source-control",
147
[WS_METHODS.projectCloneCancel]: "source-control",
148
[WS_METHODS.projectCloneRetry]: "source-control",
apps/server/src/sourceControl/SourceControlSignIn.ts
+6
@@ -28,6 +28,7 @@ export class SourceControlSignIn extends Context.Service<
28
) => Effect.Effect<void, SourceControlSignInError>;
29
readonly access: (input: SourceControlAppAccessInput) => Effect.Effect<SourceControlAppAccess>;
30
readonly starred: (input: SourceControlStarredInput) => Effect.Effect<boolean>;
31
+ readonly star: (input: SourceControlStarredInput) => Effect.Effect<boolean>;
32
}
33
>()("t3/sourceControl/SourceControlSignIn") {}
34
@@ -70,6 +71,11 @@ const make = Effect.gen(function* () {
71
.isRepositoryStarred;
72
return isStarred === undefined ? false : yield* isStarred(input.host, input.repository);
73
}),
74
+ star: Effect.fn("SourceControlSignIn.star")(function* (input) {
75
+ const star = drivers.find(({ driver }) => driver.kind === input.provider)?.instance
76
+ .starRepository;
77
+ return star === undefined ? false : yield* star(input.host, input.repository);
78
+ }),
79
});
80
});
81
apps/server/src/ws.ts
+1
@@ -2749,6 +2749,7 @@ export const layerWsRpc = (
2749
[WS_METHODS.sourceControlSignInCancel]: (input) => sourceControlSignIn.cancel(input),
2750
[WS_METHODS.sourceControlAppAccess]: (input) => sourceControlSignIn.access(input),
2751
[WS_METHODS.sourceControlStarred]: (input) => sourceControlSignIn.starred(input),
2752
+ [WS_METHODS.sourceControlStar]: (input) => sourceControlSignIn.star(input),
2753
[WS_METHODS.projectCloneStart]: (input) =>
2754
projectCloneTracker.start(input, {
2755
createProject: (project) =>
apps/web/src/components/GitHubStarPrompt.test.ts
+100
-6
@@ -3,29 +3,54 @@ import { describe, expect, it, vi } from "vite-plus/test";
3
4
import type { toastManager } from "./ui/toast";
5
6
-const { add, starred } = vi.hoisted(() => ({
6
+const { add, update, openExternal, commands, starred, page } = vi.hoisted(() => ({
7
add: vi.fn<typeof toastManager.add>(),
8
- starred: { value: false, failed: false, duringCheck: () => {} },
8
+ update: vi.fn<typeof toastManager.update>(),
9
+ openExternal: vi.fn(async (_url: string) => {}),
10
+ commands: { checkStarred: {}, star: {} },
11
+ starred: { value: false, failed: false, starWorks: true, duringCheck: () => {} },
12
+ page: {
13
+ focused: true,
14
+ activeElement: null as { matches: (selector: string) => boolean } | null,
15
+ events: new EventTarget(),
16
+ },
17
}));
10
-vi.mock("./ui/toast", () => ({ toastManager: { add, close: vi.fn() } }));
18
+vi.mock("./ui/toast", () => ({ toastManager: { add, update, close: vi.fn() } }));
19
+vi.mock("../localApi", () => ({ readLocalApi: () => ({ shell: { openExternal } }) }));
20
vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: {} }));
12
-vi.mock("../state/sourceControl", () => ({ sourceControlEnvironment: { checkStarred: {} } }));
21
+vi.mock("../state/sourceControl", () => ({ sourceControlEnvironment: commands }));
22
vi.mock("@t3tools/client-runtime/state/runtime", () => ({
14
- runAtomCommand: async () => {
23
+ runAtomCommand: async (_registry: unknown, command: unknown) => {
24
+ if (command === commands.star) return { _tag: "Success", value: starred.starWorks };
25
starred.duringCheck();
26
return starred.failed ? { _tag: "Failure" } : { _tag: "Success", value: starred.value };
27
},
28
}));
29
30
const environmentId = EnvironmentId.make("environment-1");
31
+const IDLE_MS = 30_000;
32
33
function setup({ sent = 0, writable = true, alreadyStarred = false } = {}) {
34
add.mockReset();
35
+ update.mockReset();
36
+ openExternal.mockClear();
37
starred.value = alreadyStarred;
38
starred.failed = false;
39
+ starred.starWorks = true;
40
starred.duringCheck = () => {};
41
+ page.focused = true;
42
+ page.activeElement = null;
43
+ page.events = new EventTarget();
44
const store = new Map([["t3code:github-star-prompt:sent", String(sent)]]);
45
+ vi.stubGlobal("document", {
46
+ hasFocus: () => page.focused,
47
+ get activeElement() {
48
+ return page.activeElement;
49
+ },
50
+ });
51
vi.stubGlobal("window", {
52
+ addEventListener: page.events.addEventListener.bind(page.events),
53
+ removeEventListener: page.events.removeEventListener.bind(page.events),
54
localStorage: {
55
getItem: (key: string) => store.get(key) ?? null,
56
setItem: (key: string, value: string) => {
@@ -41,10 +66,48 @@ function setup({ sent = 0, writable = true, alreadyStarred = false } = {}) {
66
async function startSession() {
67
vi.resetModules();
68
const session = await import("./GitHubStarPrompt");
44
- return { send: () => session.recordPromptSent(environmentId) };
69
+ return {
70
+ // Sends a prompt, then leaves the page idle long enough to ask.
71
+ send: async () => {
72
+ const sent = session.recordPromptSent(environmentId);
73
+ await vi.advanceTimersByTimeAsync(IDLE_MS);
74
+ await sent;
75
+ },
76
+ sendWithoutWaiting: () => void session.recordPromptSent(environmentId),
77
+ };
78
}
79
80
+// The toast's handlers ignore their click event.
81
+const click = (props: unknown) => (props as { onClick: () => unknown }).onClick();
82
+
83
describe("recordPromptSent", () => {
84
+ vi.useFakeTimers();
85
+
86
+ it("asks only after the focused page is idle", async () => {
87
+ setup({ sent: 5 });
88
+ (await startSession()).sendWithoutWaiting();
89
+ await vi.advanceTimersByTimeAsync(IDLE_MS - 1);
90
+ page.events.dispatchEvent(new Event("keydown"));
91
+ await vi.advanceTimersByTimeAsync(IDLE_MS - 1);
92
+ expect(add).not.toHaveBeenCalled();
93
+
94
+ page.focused = false;
95
+ await vi.advanceTimersByTimeAsync(IDLE_MS);
96
+ expect(add).not.toHaveBeenCalled();
97
+
98
+ page.focused = true;
99
+ page.activeElement = { matches: (selector) => selector.includes("iframe") };
100
+ page.events.dispatchEvent(new Event("focus"));
101
+ await vi.advanceTimersByTimeAsync(IDLE_MS);
102
+ expect(add).not.toHaveBeenCalled();
103
+
104
+ page.activeElement = null;
105
+ page.events.dispatchEvent(new Event("pointerdown"));
106
+ await vi.advanceTimersByTimeAsync(IDLE_MS);
107
+ expect(add).toHaveBeenCalledOnce();
108
+ vi.unstubAllGlobals();
109
+ });
110
+
111
it("asks after five prompts, once per session, and never again once closed", async () => {
112
setup();
113
let session = await startSession();
@@ -101,4 +164,35 @@ describe("recordPromptSent", () => {
164
expect(add).not.toHaveBeenCalled();
165
vi.unstubAllGlobals();
166
});
167
+ it("stars on click, opens GitHub when starring fails, and asks for a click once the click expired", async () => {
168
+ setup({ sent: 5 });
169
+ await (await startSession()).send();
170
+ click(add.mock.lastCall?.[0].actionProps);
171
+ await vi.advanceTimersByTimeAsync(0);
172
+ expect(add.mock.lastCall?.[0].title).toBe("Thanks for the star!");
173
+ expect(openExternal).not.toHaveBeenCalled();
174
+
175
+ setup({ sent: 5 });
176
+ starred.starWorks = false;
177
+ await (await startSession()).send();
178
+ click(add.mock.lastCall?.[0].actionProps);
179
+ await vi.advanceTimersByTimeAsync(0);
180
+ expect(openExternal).toHaveBeenCalledWith("https://github.com/pingdotgg/t3code");
181
+ expect(update.mock.lastCall?.[1]).not.toMatchObject({
182
+ actionProps: { children: "Open GitHub" },
183
+ });
184
+
185
+ setup({ sent: 5 });
186
+ starred.starWorks = false;
187
+ vi.stubGlobal("navigator", { userActivation: { isActive: false } });
188
+ await (await startSession()).send();
189
+ click(add.mock.lastCall?.[0].actionProps);
190
+ await vi.advanceTimersByTimeAsync(0);
191
+ const fallback = update.mock.lastCall?.[1];
192
+ expect(fallback).toMatchObject({ actionProps: { children: "Open GitHub" } });
193
+ expect(openExternal).not.toHaveBeenCalled();
194
+ click(typeof fallback === "object" ? fallback.actionProps : undefined);
195
+ expect(openExternal).toHaveBeenCalledOnce();
196
+ vi.unstubAllGlobals();
197
+ });
198
});
apps/web/src/components/GitHubStarPrompt.tsx
+67
-21
@@ -14,6 +14,9 @@ const SENT_KEY = "t3code:github-star-prompt:sent";
14
const DISMISSED_KEY = "t3code:github-star-prompt:dismissed";
15
const REPOSITORY = "pingdotgg/t3code";
16
const PROMPTS_BEFORE_ASKING = 5;
17
+const IDLE_MS = 30_000;
18
+// User-driven actions (send, navigate, type, scroll) start with one of these; touch fires pointerdown.
19
+const ACTIVITY_EVENTS = ["pointerdown", "keydown", "wheel", "focus"] as const;
20
21
let shownThisSession = false;
22
@@ -24,22 +27,32 @@ function dismiss() {
27
}
28
29
// Every close path, including both buttons, runs `onClose`, which saves the dismissal.
27
-function showStarPrompt() {
30
+function showStarPrompt(environmentId: EnvironmentId) {
31
const close = () => toastManager.close(id);
32
+ const openInBrowser = () => {
33
+ close();
34
+ void readLocalApi()
35
+ ?.shell.openExternal(`https://github.com/${REPOSITORY}`)
36
+ .catch(() => undefined);
37
+ };
38
+ const starInPlace = async () => {
39
+ toastManager.update(id, { actionProps: { children: "Starring…", disabled: true } });
40
+ if (await starRepository(environmentId)) {
41
+ close();
42
+ toastManager.add({ type: "success", title: "Thanks for the star!", timeout: 4_000 });
43
+ return;
44
+ }
45
+ // Browsers block new tabs once the click's activation expires; desktop opens through its bridge.
46
+ if (window.desktopBridge || navigator.userActivation?.isActive !== false)
47
+ return openInBrowser();
48
+ toastManager.update(id, { actionProps: { children: "Open GitHub", onClick: openInBrowser } });
49
+ };
50
const id = toastManager.add({
51
title: "Enjoying T3 Code?",
52
description: "Give us a star on GitHub to let us know!",
53
timeout: 0,
54
onClose: dismiss,
34
- actionProps: {
35
- children: "Star on GitHub",
36
- onClick: () => {
37
- close();
38
- void readLocalApi()
39
- ?.shell.openExternal(`https://github.com/${REPOSITORY}`)
40
- .catch(() => undefined);
41
- },
42
- },
55
+ actionProps: { children: "Star on GitHub", onClick: () => void starInPlace() },
56
data: {
57
actionLayout: "stacked-end",
58
leadingIcon: <StarIcon aria-hidden className="size-4 text-warning-foreground" />,
@@ -49,27 +62,59 @@ function showStarPrompt() {
62
});
63
}
64
65
+// Resolves after IDLE_MS without input while this window has focus.
66
+function waitForIdle() {
67
+ return new Promise<void>((resolve) => {
68
+ let timer: ReturnType<typeof setTimeout> | undefined;
69
+ const restart = () => {
70
+ clearTimeout(timer);
71
+ timer = setTimeout(() => {
72
+ // Input inside another app or an embedded frame never reaches us; the next focus restarts.
73
+ if (!document.hasFocus() || document.activeElement?.matches("iframe, webview")) return;
74
+ for (const type of ACTIVITY_EVENTS) window.removeEventListener(type, restart, true);
75
+ resolve();
76
+ }, IDLE_MS);
77
+ };
78
+ for (const type of ACTIVITY_EVENTS) {
79
+ window.addEventListener(type, restart, { capture: true, passive: true });
80
+ }
81
+ restart();
82
+ });
83
+}
84
+
85
// The server's GitHub account stands in for the user's; it may not be theirs on a shared server.
86
+const starInput = (environmentId: EnvironmentId) => ({
87
+ environmentId,
88
+ input: {
89
+ provider: SourceControlProviderKind.make("github"),
90
+ host: "github.com",
91
+ repository: REPOSITORY,
92
+ },
93
+});
94
+
95
async function alreadyStarred(environmentId: EnvironmentId) {
96
const result = await runAtomCommand(
97
appAtomRegistry,
98
sourceControlEnvironment.checkStarred,
57
- {
58
- environmentId,
59
- input: {
60
- provider: SourceControlProviderKind.make("github"),
61
- host: "github.com",
62
- repository: REPOSITORY,
63
- },
64
- },
99
+ starInput(environmentId),
100
{ label: "check GitHub star", reportFailure: false, reportDefect: false },
101
);
102
return result._tag === "Success" ? result.value : undefined;
103
}
104
105
+async function starRepository(environmentId: EnvironmentId) {
106
+ const result = await runAtomCommand(
107
+ appAtomRegistry,
108
+ sourceControlEnvironment.star,
109
+ starInput(environmentId),
110
+ { label: "star on GitHub", reportFailure: false, reportDefect: false },
111
+ );
112
+ return result._tag === "Success" && result.value;
113
+}
114
+
115
/**
116
* Counts a sent prompt. After more than five, asks once per session for a star until dismissed,
72
- * unless the environment's GitHub account already starred the repo.
117
+ * unless the environment's GitHub account already starred the repo. Waits until the user is idle.
118
*/
119
export async function recordPromptSent(environmentId: EnvironmentId): Promise<void> {
120
if (shownThisSession) return;
@@ -86,11 +131,12 @@ export async function recordPromptSent(environmentId: EnvironmentId): Promise<vo
131
const starred = await alreadyStarred(environmentId);
132
if (starred === undefined) return;
133
if (starred) return dismiss();
134
+ await waitForIdle();
135
try {
90
- // Another tab can dismiss while the check runs.
136
+ // Another tab can dismiss while the check or the idle wait runs.
137
if (getLocalStorageItem(DISMISSED_KEY, Schema.Boolean)) return;
138
} catch {
139
return;
140
}
95
- showStarPrompt();
141
+ showStarPrompt(environmentId);
142
}
packages/client-runtime/src/state/sourceControl.ts
+4
@@ -34,6 +34,10 @@ export function createSourceControlEnvironmentAtoms<R, E>(
34
label: "environment-data:source-control:check-starred",
35
tag: WS_METHODS.sourceControlStarred,
36
}),
37
+ star: createEnvironmentRpcCommand(runtime, {
38
+ label: "environment-data:source-control:star",
39
+ tag: WS_METHODS.sourceControlStar,
40
+ }),
41
repository: createEnvironmentRpcQueryAtomFamily(runtime, {
42
label: "environment-data:source-control:repository",
43
tag: WS_METHODS.sourceControlLookupRepository,
packages/contracts/src/clientRpcPermissions.ts
+1
@@ -36,6 +36,7 @@ export const CLIENT_GUARDED_RPC_SCOPES = {
36
[WS_METHODS.projectsCreateFromThread]: AuthOrchestrationOperateScope,
37
[WS_METHODS.sourceControlCloneRepository]: AuthSourceControlWriteScope,
38
[WS_METHODS.sourceControlPublishRepository]: AuthSourceControlWriteScope,
39
+ [WS_METHODS.sourceControlStar]: AuthSourceControlWriteScope,
40
// Signing in replaces the server's GitHub credential, as saving a token in Settings does.
41
[WS_METHODS.sourceControlSignInStart]: AuthSettingsWriteScope,
42
[WS_METHODS.sourceControlSignInWait]: AuthSettingsWriteScope,
packages/contracts/src/rpc.ts
+9
@@ -595,6 +595,7 @@ export const WS_METHODS = {
595
sourceControlSignInCancel: "sourceControl.signInCancel",
596
sourceControlAppAccess: "sourceControl.appAccess",
597
sourceControlStarred: "sourceControl.starred",
598
+ sourceControlStar: "sourceControl.star",
599
projectCloneStart: "projectClone.start",
600
projectCloneCancel: "projectClone.cancel",
601
projectCloneRetry: "projectClone.retry",
@@ -1252,6 +1253,13 @@ const WsSourceControlStarredRpc = Rpc.make(WS_METHODS.sourceControlStarred, {
1253
error: EnvironmentAuthorizationError,
1254
});
1255
1256
+// Stars the repository as the server's forge account. False when the forge refused or cannot star.
1257
+const WsSourceControlStarRpc = Rpc.make(WS_METHODS.sourceControlStar, {
1258
+ payload: SourceControlStarredInput,
1259
+ success: Schema.Boolean,
1260
+ error: EnvironmentAuthorizationError,
1261
+});
1262
+
1263
// Returns when the project exists and cloning starts; progress uses the subscription.
1264
const WsProjectCloneStartRpc = Rpc.make(WS_METHODS.projectCloneStart, {
1265
payload: ProjectCloneStartInput,
@@ -2090,6 +2098,7 @@ export const WsRpcGroup = RpcGroup.make(
2098
WsSourceControlSignInCancelRpc,
2099
WsSourceControlAppAccessRpc,
2100
WsSourceControlStarredRpc,
2101
+ WsSourceControlStarRpc,
2102
WsProjectCloneStartRpc,
2103
WsProjectCloneCancelRpc,
2104
WsProjectCloneRetryRpc,
packages/source-control-core/src/server/driver.ts
+2
@@ -65,6 +65,8 @@ export interface SourceControlDriverInstance {
65
readonly signIn?: SourceControlSignIn;
66
/** Whether the server's account on `host` starred `repository` (`owner/name`). */
67
readonly isRepositoryStarred?: (host: string, repository: string) => Effect.Effect<boolean>;
68
+ /** Stars `repository` as the server's account on `host`; false when the forge refused. */
69
+ readonly starRepository?: (host: string, repository: string) => Effect.Effect<boolean>;
70
}
71
72
/** What the server gives every driver. A driver builds anything else it needs itself. */
packages/source-control-github/src/server/driver.test.ts
+14
-6
@@ -2,17 +2,17 @@ import { assert, describe, it } from "@effect/vitest";
2
import * as Effect from "effect/Effect";
3
import * as Layer from "effect/Layer";
4
5
-import { makeIsRepositoryStarred } from "./driver.ts";
5
+import { makeIsRepositoryStarred, makeStarRepository } from "./driver.ts";
6
import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts";
7
import * as GitHubRest from "./GitHubRest.ts";
8
9
-describe("makeIsRepositoryStarred", () => {
10
- it.effect("is true only when GitHub answers 204 for the repository", () => {
9
+describe("starred", () => {
10
+ it.effect("checks and stars only a valid repository, true only on 204", () => {
11
const paths: Array<string> = [];
12
const starred = new Set(["user/starred/pingdotgg/t3code"]);
13
const api = Layer.mock(GitHubRest.GitHubRest)({
14
rest: (input) => {
15
- paths.push(input.path);
15
+ paths.push(`${input.method ?? "GET"} ${input.path}`);
16
return starred.has(input.path)
17
? Effect.succeed({
18
status: 204,
@@ -31,12 +31,20 @@ describe("makeIsRepositoryStarred", () => {
31
});
32
return Effect.gen(function* () {
33
const isStarred = yield* makeIsRepositoryStarred;
34
+ const star = yield* makeStarRepository;
35
assert.isTrue(yield* isStarred("github.com", "pingdotgg/t3code"));
36
assert.isFalse(yield* isStarred("github.com", "pingdotgg/uploadthing"));
37
assert.isFalse(yield* isStarred("github.com", "pingdotgg/t3code/../../user"));
38
+ assert.isFalse(yield* isStarred("github.com", "../repos"));
39
+ assert.isTrue(yield* star("github.com", "pingdotgg/t3code"));
40
+ assert.isFalse(yield* star("github.com", "pingdotgg/uploadthing"));
41
+ assert.isFalse(yield* star("github.com", "pingdotgg/t3code/../../user"));
42
+ assert.isFalse(yield* star("github.com", "../repos"));
43
assert.deepStrictEqual(paths, [
38
- "user/starred/pingdotgg/t3code",
39
- "user/starred/pingdotgg/uploadthing",
44
+ "GET user/starred/pingdotgg/t3code",
45
+ "GET user/starred/pingdotgg/uploadthing",
46
+ "PUT user/starred/pingdotgg/t3code",
47
+ "PUT user/starred/pingdotgg/uploadthing",
48
]);
49
}).pipe(Effect.provide(api));
50
});
packages/source-control-github/src/server/driver.ts
+26
-3
@@ -53,17 +53,25 @@ const makeSignIn = Effect.gen(function* () {
53
} satisfies SourceControlSignIn;
54
});
55
56
+const starredPath = (repository: string) => {
57
+ const segments = repository.split("/");
58
+ // "." and ".." survive encoding and would normalize the URL out of user/starred.
59
+ return segments.length === 2 && segments.every((segment) => !["", ".", ".."].includes(segment))
60
+ ? `user/starred/${segments.map(encodeURIComponent).join("/")}`
61
+ : undefined;
62
+};
63
+
64
// Only 204 means starred. Tokens without star access, a missing login, and 404 all read as false.
65
export const makeIsRepositoryStarred = Effect.gen(function* () {
66
const api = yield* GitHubRest.GitHubRest;
67
return Effect.fn("GitHubDriver.isRepositoryStarred")(
68
function* (host: string, repository: string) {
61
- const segments = repository.split("/");
62
- if (segments.length !== 2) return false;
69
+ const path = starredPath(repository);
70
+ if (path === undefined) return false;
71
const response = yield* api.rest({
72
host,
73
operation: "isRepositoryStarred",
66
- path: `user/starred/${segments.map(encodeURIComponent).join("/")}`,
74
+ path,
75
allowReserve: false,
76
});
77
return response.status === 204;
@@ -72,6 +80,20 @@ export const makeIsRepositoryStarred = Effect.gen(function* () {
80
);
81
});
82
83
+// False on any failure, such as a token or app sign-in without permission to star.
84
+export const makeStarRepository = Effect.gen(function* () {
85
+ const api = yield* GitHubRest.GitHubRest;
86
+ return Effect.fn("GitHubDriver.starRepository")(
87
+ function* (host: string, repository: string) {
88
+ const path = starredPath(repository);
89
+ if (path === undefined) return false;
90
+ const response = yield* api.rest({ host, operation: "starRepository", method: "PUT", path });
91
+ return response.status === 204;
92
+ },
93
+ Effect.orElseSucceed(() => false),
94
+ );
95
+});
96
+
97
const makeInstance = Effect.all({
98
sourceControl: GitHubSourceControlProvider.make,
99
discovery: GitHubSourceControlProvider.makeDiscovery,
@@ -79,6 +101,7 @@ const makeInstance = Effect.all({
101
fetchMedia: GitHubMediaFetch.make,
102
signIn: makeSignIn,
103
isRepositoryStarred: makeIsRepositoryStarred,
104
+ starRepository: makeStarRepository,
105
});
106
107
export const driver = defineSourceControlDriver({