@devries-cameron20 / t3code Mirror · read-only / commits / d92c437baa
Fork 0

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 22, 10:45 UTC

feat(web): ask for a GitHub star once after 5 prompts (#27832)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 30, 2026 at 17:56 UTC d92c437baa19409f99416a44f748f148f4317c65
13 files changed +284 -1
apps/server/src/auth/RpcAuthorization.ts
+1
@@ -141,6 +141,7 @@ export const RPC_REQUIRED_SCOPES = {
141 [WS_METHODS.pullRequestsLabelCandidates]: AuthOrchestrationReadScope,
142 [WS_METHODS.sourceControlLookupRepository]: AuthOrchestrationReadScope,
143 [WS_METHODS.sourceControlAppAccess]: AuthOrchestrationReadScope,
144 + [WS_METHODS.sourceControlStarred]: AuthOrchestrationReadScope,
145 [WS_METHODS.subscribeProjectClones]: AuthOrchestrationReadScope,
146 [WS_METHODS.projectsListEntries]: AuthFilesystemReadScope,
147 [WS_METHODS.projectsListIgnoredFiles]: AuthFilesystemReadScope,
apps/server/src/observability/RpcInstrumentation.ts
+1
@@ -140,6 +140,7 @@ const RPC_AGGREGATES = {
140 [WS_METHODS.sourceControlSignInWait]: "source-control",
141 [WS_METHODS.sourceControlSignInCancel]: "source-control",
142 [WS_METHODS.sourceControlAppAccess]: "source-control",
143 + [WS_METHODS.sourceControlStarred]: "source-control",
144 [WS_METHODS.projectCloneStart]: "source-control",
145 [WS_METHODS.projectCloneCancel]: "source-control",
146 [WS_METHODS.projectCloneRetry]: "source-control",
apps/server/src/sourceControl/SourceControlSignIn.ts
+8 -1
@@ -5,6 +5,7 @@ import {
5 type SourceControlSignInInput,
6 type SourceControlSignInPrompt,
7 type SourceControlSignInResult,
8 + type SourceControlStarredInput,
9 } from "@t3tools/contracts";
10 import * as Context from "effect/Context";
11 import * as Effect from "effect/Effect";
@@ -12,7 +13,7 @@ import * as Layer from "effect/Layer";
13
14 import * as SourceControlBuiltInDrivers from "./builtInDrivers.ts";
15
15 -/** Signs the server in to a forge through the forge's own app, for hosts whose driver offers it. */
16 +/** Signs the server in to a forge through the forge's own app, and reads what its account did. */
17 export class SourceControlSignIn extends Context.Service<
18 SourceControlSignIn,
19 {
@@ -26,6 +27,7 @@ export class SourceControlSignIn extends Context.Service<
27 input: SourceControlSignInInput,
28 ) => Effect.Effect<void, SourceControlSignInError>;
29 readonly access: (input: SourceControlAppAccessInput) => Effect.Effect<SourceControlAppAccess>;
30 + readonly starred: (input: SourceControlStarredInput) => Effect.Effect<boolean>;
31 }
32 >()("t3/sourceControl/SourceControlSignIn") {}
33
@@ -63,6 +65,11 @@ const make = Effect.gen(function* () {
65 signIn === undefined ? "signed-out" : yield* signIn.access(input.host, input.repository),
66 } satisfies SourceControlAppAccess;
67 }),
68 + starred: Effect.fn("SourceControlSignIn.starred")(function* (input) {
69 + const isStarred = drivers.find(({ driver }) => driver.kind === input.provider)?.instance
70 + .isRepositoryStarred;
71 + return isStarred === undefined ? false : yield* isStarred(input.host, input.repository);
72 + }),
73 });
74 });
75
apps/server/src/ws.ts
+1
@@ -2681,6 +2681,7 @@ export const layerWsRpc = (
2681 [WS_METHODS.sourceControlSignInWait]: (input) => sourceControlSignIn.wait(input),
2682 [WS_METHODS.sourceControlSignInCancel]: (input) => sourceControlSignIn.cancel(input),
2683 [WS_METHODS.sourceControlAppAccess]: (input) => sourceControlSignIn.access(input),
2684 + [WS_METHODS.sourceControlStarred]: (input) => sourceControlSignIn.starred(input),
2685 [WS_METHODS.projectCloneStart]: (input) =>
2686 projectCloneTracker.start(input, {
2687 createProject: (project) =>
apps/web/src/components/GitHubStarPrompt.test.ts new
+91
@@ -0,0 +1,91 @@
1 +import { EnvironmentId } from "@t3tools/contracts";
2 +import { describe, expect, it, vi } from "vite-plus/test";
3 +
4 +import type { toastManager } from "./ui/toast";
5 +
6 +const { add, starred } = vi.hoisted(() => ({
7 + add: vi.fn<typeof toastManager.add>(),
8 + starred: { value: false, duringCheck: () => {} },
9 +}));
10 +vi.mock("./ui/toast", () => ({ toastManager: { add, close: vi.fn() } }));
11 +vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: {} }));
12 +vi.mock("../state/sourceControl", () => ({ sourceControlEnvironment: { checkStarred: {} } }));
13 +vi.mock("@t3tools/client-runtime/state/runtime", () => ({
14 + runAtomCommand: async () => {
15 + starred.duringCheck();
16 + return { _tag: "Success", value: starred.value };
17 + },
18 +}));
19 +
20 +const environmentId = EnvironmentId.make("environment-1");
21 +
22 +function setup({ sent = 0, writable = true, alreadyStarred = false } = {}) {
23 + add.mockReset();
24 + starred.value = alreadyStarred;
25 + starred.duringCheck = () => {};
26 + const store = new Map([["t3code:github-star-prompt:sent", String(sent)]]);
27 + vi.stubGlobal("window", {
28 + localStorage: {
29 + getItem: (key: string) => store.get(key) ?? null,
30 + setItem: (key: string, value: string) => {
31 + if (!writable) throw new Error("QuotaExceededError");
32 + store.set(key, value);
33 + },
34 + },
35 + });
36 + return store;
37 +}
38 +
39 +// A fresh module import stands in for an app reload; storage survives it.
40 +async function startSession() {
41 + vi.resetModules();
42 + const session = await import("./GitHubStarPrompt");
43 + return { send: () => session.recordPromptSent(environmentId) };
44 +}
45 +
46 +describe("recordPromptSent", () => {
47 + it("asks after five prompts, once per session, and never again once closed", async () => {
48 + setup();
49 + let session = await startSession();
50 + for (let sent = 0; sent < 5; sent++) await session.send();
51 + expect(add).not.toHaveBeenCalled();
52 +
53 + await session.send();
54 + await session.send();
55 + expect(add).toHaveBeenCalledOnce();
56 +
57 + session = await startSession();
58 + await session.send();
59 + expect(add).toHaveBeenCalledTimes(2);
60 +
61 + add.mock.lastCall?.[0].onClose?.();
62 + session = await startSession();
63 + for (let sent = 0; sent < 10; sent++) await session.send();
64 + expect(add).toHaveBeenCalledTimes(2);
65 + vi.unstubAllGlobals();
66 + });
67 +
68 + it("never asks when a dismissal could not be saved", async () => {
69 + setup({ sent: 5, writable: false });
70 + await (await startSession()).send();
71 + expect(add).not.toHaveBeenCalled();
72 + vi.unstubAllGlobals();
73 + });
74 +
75 + it("never asks once the environment's GitHub account starred the repo", async () => {
76 + setup({ sent: 5, alreadyStarred: true });
77 + await (await startSession()).send();
78 + starred.value = false;
79 + await (await startSession()).send();
80 + expect(add).not.toHaveBeenCalled();
81 + vi.unstubAllGlobals();
82 + });
83 +
84 + it("never asks when another tab dismisses it during the star check", async () => {
85 + const store = setup({ sent: 5 });
86 + starred.duringCheck = () => store.set("t3code:github-star-prompt:dismissed", "true");
87 + await (await startSession()).send();
88 + expect(add).not.toHaveBeenCalled();
89 + vi.unstubAllGlobals();
90 + });
91 +});
apps/web/src/components/GitHubStarPrompt.tsx new
+94
@@ -0,0 +1,94 @@
1 +import { type EnvironmentId, SourceControlProviderKind } from "@t3tools/contracts";
2 +import { runAtomCommand } from "@t3tools/client-runtime/state/runtime";
3 +import * as Schema from "effect/Schema";
4 +import { StarIcon } from "lucide-react";
5 +
6 +import { getLocalStorageItem, setLocalStorageItem } from "../hooks/useLocalStorage";
7 +import { readLocalApi } from "../localApi";
8 +import { appAtomRegistry } from "../rpc/atomRegistry";
9 +import { sourceControlEnvironment } from "../state/sourceControl";
10 +import { toastManager } from "./ui/toast";
11 +
12 +// Separate keys so a count written by another tab can never undo a dismissal.
13 +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 +
18 +let shownThisSession = false;
19 +
20 +function dismiss() {
21 + try {
22 + setLocalStorageItem(DISMISSED_KEY, true, Schema.Boolean);
23 + } catch {}
24 +}
25 +
26 +// Every close path, including both buttons, runs `onClose`, which saves the dismissal.
27 +function showStarPrompt() {
28 + const close = () => toastManager.close(id);
29 + const id = toastManager.add({
30 + title: "Enjoying T3 Code?",
31 + description: "Give us a star on GitHub to let us know!",
32 + timeout: 0,
33 + 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 + },
43 + data: {
44 + actionLayout: "stacked-end",
45 + leadingIcon: <StarIcon aria-hidden className="size-4 text-warning-foreground" />,
46 + secondaryActionProps: { children: "Dismiss", onClick: close },
47 + secondaryActionVariant: "ghost",
48 + },
49 + });
50 +}
51 +
52 +// The server's GitHub account stands in for the user's; it may not be theirs on a shared server.
53 +async function alreadyStarred(environmentId: EnvironmentId) {
54 + const result = await runAtomCommand(
55 + appAtomRegistry,
56 + sourceControlEnvironment.checkStarred,
57 + {
58 + environmentId,
59 + input: {
60 + provider: SourceControlProviderKind.make("github"),
61 + host: "github.com",
62 + repository: REPOSITORY,
63 + },
64 + },
65 + { label: "check GitHub star", reportFailure: false, reportDefect: false },
66 + );
67 + return result._tag === "Success" && result.value;
68 +}
69 +
70 +/**
71 + * 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.
73 + */
74 +export async function recordPromptSent(environmentId: EnvironmentId): Promise<void> {
75 + if (shownThisSession) return;
76 + try {
77 + if (getLocalStorageItem(DISMISSED_KEY, Schema.Boolean)) return;
78 + const sent = (getLocalStorageItem(SENT_KEY, Schema.Number) ?? 0) + 1;
79 + setLocalStorageItem(SENT_KEY, sent, Schema.Number);
80 + if (sent <= PROMPTS_BEFORE_ASKING) return;
81 + } catch {
82 + // Storage that cannot be read or written could not keep a dismissal, so never ask.
83 + return;
84 + }
85 + shownThisSession = true;
86 + if (await alreadyStarred(environmentId)) return dismiss();
87 + try {
88 + // Another tab can dismiss while the check runs.
89 + if (getLocalStorageItem(DISMISSED_KEY, Schema.Boolean)) return;
90 + } catch {
91 + return;
92 + }
93 + showStarPrompt();
94 +}
apps/web/src/components/chat/useComposerSend.ts
+2
@@ -58,6 +58,7 @@ import {
58 } from "../../composer-logic";
59 import { resolvePlanFollowUpSubmission } from "../../proposedPlan";
60 import { type ChatMessage } from "../../types";
61 +import { recordPromptSent } from "../GitHubStarPrompt";
62 import { stackedThreadToast, toastManager } from "../ui/toast";
63 import { newMessageId, newThreadId } from "~/lib/utils";
64 import { useNewThreadHandler } from "../../hooks/useHandleNewThread";
@@ -1368,6 +1369,7 @@ export function useComposerSend(input: ComposerSendInput) {
1369 ) {
1370 handleNewThreadInActiveProject();
1371 }
1372 + void recordPromptSent(environmentId);
1373 }
1374 }
1375
packages/client-runtime/src/state/sourceControl.ts
+4
@@ -30,6 +30,10 @@ export function createSourceControlEnvironmentAtoms<R, E>(
30 label: "environment-data:source-control:check-app-access",
31 tag: WS_METHODS.sourceControlAppAccess,
32 }),
33 + checkStarred: createEnvironmentRpcCommand(runtime, {
34 + label: "environment-data:source-control:check-starred",
35 + tag: WS_METHODS.sourceControlStarred,
36 + }),
37 repository: createEnvironmentRpcQueryAtomFamily(runtime, {
38 label: "environment-data:source-control:repository",
39 tag: WS_METHODS.sourceControlLookupRepository,
packages/contracts/src/rpc.ts
+10
@@ -395,6 +395,7 @@ import {
395 SourceControlRepositoryLookupInput,
396 SourceControlAppAccess,
397 SourceControlAppAccessInput,
398 + SourceControlStarredInput,
399 SourceControlSignInError,
400 SourceControlSignInInput,
401 SourceControlSignInPrompt,
@@ -592,6 +593,7 @@ export const WS_METHODS = {
593 sourceControlSignInWait: "sourceControl.signInWait",
594 sourceControlSignInCancel: "sourceControl.signInCancel",
595 sourceControlAppAccess: "sourceControl.appAccess",
596 + sourceControlStarred: "sourceControl.starred",
597 projectCloneStart: "projectClone.start",
598 projectCloneCancel: "projectClone.cancel",
599 projectCloneRetry: "projectClone.retry",
@@ -1242,6 +1244,13 @@ const WsSourceControlAppAccessRpc = Rpc.make(WS_METHODS.sourceControlAppAccess,
1244 error: EnvironmentAuthorizationError,
1245 });
1246
1247 +// False when the server's forge account has not starred the repository or the forge cannot say.
1248 +const WsSourceControlStarredRpc = Rpc.make(WS_METHODS.sourceControlStarred, {
1249 + payload: SourceControlStarredInput,
1250 + success: Schema.Boolean,
1251 + error: EnvironmentAuthorizationError,
1252 +});
1253 +
1254 // Returns when the project exists and cloning starts; progress uses the subscription.
1255 const WsProjectCloneStartRpc = Rpc.make(WS_METHODS.projectCloneStart, {
1256 payload: ProjectCloneStartInput,
@@ -2070,6 +2079,7 @@ export const WsRpcGroup = RpcGroup.make(
2079 WsSourceControlSignInWaitRpc,
2080 WsSourceControlSignInCancelRpc,
2081 WsSourceControlAppAccessRpc,
2082 + WsSourceControlStarredRpc,
2083 WsProjectCloneStartRpc,
2084 WsProjectCloneCancelRpc,
2085 WsProjectCloneRetryRpc,
packages/contracts/src/sourceControl.ts
+7
@@ -226,6 +226,13 @@ export const SourceControlAppAccess = Schema.Struct({
226 });
227 export type SourceControlAppAccess = typeof SourceControlAppAccess.Type;
228
229 +export const SourceControlStarredInput = Schema.Struct({
230 + provider: SourceControlProviderKind,
231 + host: TrimmedNonEmptyString,
232 + repository: TrimmedNonEmptyString,
233 +});
234 +export type SourceControlStarredInput = typeof SourceControlStarredInput.Type;
235 +
236 export class SourceControlSignInError extends Schema.TaggedError<SourceControlSignInError>()(
237 "SourceControlSignInError",
238 {
packages/source-control-core/src/server/driver.ts
+2
@@ -63,6 +63,8 @@ export interface SourceControlDriverInstance {
63 Scope.Scope
64 >;
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 }
69
70 /** What the server gives every driver. A driver builds anything else it needs itself. */
packages/source-control-github/src/server/driver.test.ts new
+43
@@ -0,0 +1,43 @@
1 +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";
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", () => {
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);
16 + return starred.has(input.path)
17 + ? Effect.succeed({
18 + status: 204,
19 + headers: {},
20 + body: "",
21 + truncated: false,
22 + invalidUtf8: false,
23 + })
24 + : Effect.fail(
25 + new GitHubRequestPolicy.GitHubApiNotFoundError({
26 + host: input.host,
27 + operation: input.operation,
28 + }),
29 + );
30 + },
31 + });
32 + return Effect.gen(function* () {
33 + const isStarred = yield* makeIsRepositoryStarred;
34 + assert.isTrue(yield* isStarred("github.com", "pingdotgg/t3code"));
35 + assert.isFalse(yield* isStarred("github.com", "pingdotgg/uploadthing"));
36 + assert.isFalse(yield* isStarred("github.com", "pingdotgg/t3code/../../user"));
37 + assert.deepStrictEqual(paths, [
38 + "user/starred/pingdotgg/t3code",
39 + "user/starred/pingdotgg/uploadthing",
40 + ]);
41 + }).pipe(Effect.provide(api));
42 + });
43 +});
packages/source-control-github/src/server/driver.ts
+20
@@ -53,12 +53,32 @@ const makeSignIn = Effect.gen(function* () {
53 } satisfies SourceControlSignIn;
54 });
55
56 +// Only 204 means starred. Tokens without star access, a missing login, and 404 all read as false.
57 +export const makeIsRepositoryStarred = Effect.gen(function* () {
58 + const api = yield* GitHubRest.GitHubRest;
59 + return Effect.fn("GitHubDriver.isRepositoryStarred")(
60 + function* (host: string, repository: string) {
61 + const segments = repository.split("/");
62 + if (segments.length !== 2) return false;
63 + const response = yield* api.rest({
64 + host,
65 + operation: "isRepositoryStarred",
66 + path: `user/starred/${segments.map(encodeURIComponent).join("/")}`,
67 + allowReserve: false,
68 + });
69 + return response.status === 204;
70 + },
71 + Effect.orElseSucceed(() => false),
72 + );
73 +});
74 +
75 const makeInstance = Effect.all({
76 sourceControl: GitHubSourceControlProvider.make,
77 discovery: GitHubSourceControlProvider.makeDiscovery,
78 pullRequests: GitHubPullRequestProvider.make,
79 fetchMedia: GitHubMediaFetch.make,
80 signIn: makeSignIn,
81 + isRepositoryStarred: makeIsRepositoryStarred,
82 });
83
84 export const driver = defineSourceControlDriver({