Skip to content

Commit f46903c

Browse files
t3dotggclaude
andcommitted
feat(web): skip the star toast when the server's GitHub account already starred
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 10bb948 commit f46903c

13 files changed

Lines changed: 160 additions & 17 deletions

File tree

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const RPC_REQUIRED_SCOPES = {
141141
[WS_METHODS.pullRequestsLabelCandidates]: AuthOrchestrationReadScope,
142142
[WS_METHODS.sourceControlLookupRepository]: AuthOrchestrationReadScope,
143143
[WS_METHODS.sourceControlAppAccess]: AuthOrchestrationReadScope,
144+
[WS_METHODS.sourceControlStarred]: AuthOrchestrationReadScope,
144145
[WS_METHODS.subscribeProjectClones]: AuthOrchestrationReadScope,
145146
[WS_METHODS.projectsListEntries]: AuthFilesystemReadScope,
146147
[WS_METHODS.projectsListIgnoredFiles]: AuthFilesystemReadScope,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const RPC_AGGREGATES = {
140140
[WS_METHODS.sourceControlSignInWait]: "source-control",
141141
[WS_METHODS.sourceControlSignInCancel]: "source-control",
142142
[WS_METHODS.sourceControlAppAccess]: "source-control",
143+
[WS_METHODS.sourceControlStarred]: "source-control",
143144
[WS_METHODS.projectCloneStart]: "source-control",
144145
[WS_METHODS.projectCloneCancel]: "source-control",
145146
[WS_METHODS.projectCloneRetry]: "source-control",

‎apps/server/src/sourceControl/SourceControlSignIn.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {
55
type SourceControlSignInInput,
66
type SourceControlSignInPrompt,
77
type SourceControlSignInResult,
8+
type SourceControlStarredInput,
89
} from "@t3tools/contracts";
910
import * as Context from "effect/Context";
1011
import * as Effect from "effect/Effect";
1112
import * as Layer from "effect/Layer";
1213

1314
import * as SourceControlBuiltInDrivers from "./builtInDrivers.ts";
1415

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. */
1617
export class SourceControlSignIn extends Context.Service<
1718
SourceControlSignIn,
1819
{
@@ -26,6 +27,7 @@ export class SourceControlSignIn extends Context.Service<
2627
input: SourceControlSignInInput,
2728
) => Effect.Effect<void, SourceControlSignInError>;
2829
readonly access: (input: SourceControlAppAccessInput) => Effect.Effect<SourceControlAppAccess>;
30+
readonly starred: (input: SourceControlStarredInput) => Effect.Effect<boolean>;
2931
}
3032
>()("t3/sourceControl/SourceControlSignIn") {}
3133

@@ -63,6 +65,11 @@ const make = Effect.gen(function* () {
6365
signIn === undefined ? "signed-out" : yield* signIn.access(input.host, input.repository),
6466
} satisfies SourceControlAppAccess;
6567
}),
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+
}),
6673
});
6774
});
6875

‎apps/server/src/ws.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,7 @@ export const layerWsRpc = (
26812681
[WS_METHODS.sourceControlSignInWait]: (input) => sourceControlSignIn.wait(input),
26822682
[WS_METHODS.sourceControlSignInCancel]: (input) => sourceControlSignIn.cancel(input),
26832683
[WS_METHODS.sourceControlAppAccess]: (input) => sourceControlSignIn.access(input),
2684+
[WS_METHODS.sourceControlStarred]: (input) => sourceControlSignIn.starred(input),
26842685
[WS_METHODS.projectCloneStart]: (input) =>
26852686
projectCloneTracker.start(input, {
26862687
createProject: (project) =>

‎apps/web/src/components/GitHubStarPrompt.test.ts‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
import { EnvironmentId } from "@t3tools/contracts";
12
import { describe, expect, it, vi } from "vite-plus/test";
23

34
import type { toastManager } from "./ui/toast";
45

5-
const { add } = vi.hoisted(() => ({ add: vi.fn<typeof toastManager.add>() }));
6+
const { add, starred } = vi.hoisted(() => ({
7+
add: vi.fn<typeof toastManager.add>(),
8+
starred: { value: false },
9+
}));
610
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 () => ({ _tag: "Success", value: starred.value }),
15+
}));
716

8-
function setup({ sent = 0, writable = true } = {}) {
17+
const environmentId = EnvironmentId.make("environment-1");
18+
19+
function setup({ sent = 0, writable = true, alreadyStarred = false } = {}) {
920
add.mockReset();
21+
starred.value = alreadyStarred;
1022
const store = new Map([["t3code:github-star-prompt:sent", String(sent)]]);
1123
vi.stubGlobal("window", {
1224
localStorage: {
@@ -22,35 +34,44 @@ function setup({ sent = 0, writable = true } = {}) {
2234
// A fresh module import stands in for an app reload; storage survives it.
2335
async function startSession() {
2436
vi.resetModules();
25-
return import("./GitHubStarPrompt");
37+
const session = await import("./GitHubStarPrompt");
38+
return { send: () => session.recordPromptSent(environmentId) };
2639
}
2740

2841
describe("recordPromptSent", () => {
2942
it("asks after five prompts, once per session, and never again once closed", async () => {
3043
setup();
3144
let session = await startSession();
32-
for (let sent = 0; sent < 5; sent++) session.recordPromptSent();
45+
for (let sent = 0; sent < 5; sent++) await session.send();
3346
expect(add).not.toHaveBeenCalled();
3447

35-
session.recordPromptSent();
36-
session.recordPromptSent();
48+
await session.send();
49+
await session.send();
3750
expect(add).toHaveBeenCalledOnce();
3851

3952
session = await startSession();
40-
session.recordPromptSent();
53+
await session.send();
4154
expect(add).toHaveBeenCalledTimes(2);
4255

4356
add.mock.lastCall?.[0].onClose?.();
4457
session = await startSession();
45-
for (let sent = 0; sent < 10; sent++) session.recordPromptSent();
58+
for (let sent = 0; sent < 10; sent++) await session.send();
4659
expect(add).toHaveBeenCalledTimes(2);
4760
vi.unstubAllGlobals();
4861
});
4962

5063
it("never asks when a dismissal could not be saved", async () => {
5164
setup({ sent: 5, writable: false });
52-
const session = await startSession();
53-
session.recordPromptSent();
65+
await (await startSession()).send();
66+
expect(add).not.toHaveBeenCalled();
67+
vi.unstubAllGlobals();
68+
});
69+
70+
it("never asks once the environment's GitHub account starred the repo", async () => {
71+
setup({ sent: 5, alreadyStarred: true });
72+
await (await startSession()).send();
73+
starred.value = false;
74+
await (await startSession()).send();
5475
expect(add).not.toHaveBeenCalled();
5576
vi.unstubAllGlobals();
5677
});

‎apps/web/src/components/GitHubStarPrompt.tsx‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import { type EnvironmentId, SourceControlProviderKind } from "@t3tools/contracts";
2+
import { runAtomCommand } from "@t3tools/client-runtime/state/runtime";
13
import * as Schema from "effect/Schema";
24
import { StarIcon } from "lucide-react";
35

46
import { getLocalStorageItem, setLocalStorageItem } from "../hooks/useLocalStorage";
57
import { readLocalApi } from "../localApi";
8+
import { appAtomRegistry } from "../rpc/atomRegistry";
9+
import { sourceControlEnvironment } from "../state/sourceControl";
610
import { toastManager } from "./ui/toast";
711

812
// Separate keys so a count written by another tab can never undo a dismissal.
913
const SENT_KEY = "t3code:github-star-prompt:sent";
1014
const DISMISSED_KEY = "t3code:github-star-prompt:dismissed";
11-
const REPO_URL = "https://github.com/pingdotgg/t3code";
15+
const REPOSITORY = "pingdotgg/t3code";
1216
const PROMPTS_BEFORE_ASKING = 5;
1317

1418
let shownThisSession = false;
@@ -32,7 +36,7 @@ function showStarPrompt() {
3236
onClick: () => {
3337
close();
3438
void readLocalApi()
35-
?.shell.openExternal(REPO_URL)
39+
?.shell.openExternal(`https://github.com/${REPOSITORY}`)
3640
.catch(() => undefined);
3741
},
3842
},
@@ -45,8 +49,29 @@ function showStarPrompt() {
4549
});
4650
}
4751

48-
/** Counts a sent prompt. After more than five, asks once per session for a star until dismissed. */
49-
export function recordPromptSent(): void {
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> {
5075
if (shownThisSession) return;
5176
try {
5277
if (getLocalStorageItem(DISMISSED_KEY, Schema.Boolean)) return;
@@ -58,5 +83,6 @@ export function recordPromptSent(): void {
5883
return;
5984
}
6085
shownThisSession = true;
61-
showStarPrompt();
86+
if (await alreadyStarred(environmentId)) dismiss();
87+
else showStarPrompt();
6288
}

‎apps/web/src/components/chat/useComposerSend.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ export function useComposerSend(input: ComposerSendInput) {
13691369
) {
13701370
handleNewThreadInActiveProject();
13711371
}
1372-
recordPromptSent();
1372+
void recordPromptSent(environmentId);
13731373
}
13741374
}
13751375

‎packages/client-runtime/src/state/sourceControl.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export function createSourceControlEnvironmentAtoms<R, E>(
3030
label: "environment-data:source-control:check-app-access",
3131
tag: WS_METHODS.sourceControlAppAccess,
3232
}),
33+
checkStarred: createEnvironmentRpcCommand(runtime, {
34+
label: "environment-data:source-control:check-starred",
35+
tag: WS_METHODS.sourceControlStarred,
36+
}),
3337
repository: createEnvironmentRpcQueryAtomFamily(runtime, {
3438
label: "environment-data:source-control:repository",
3539
tag: WS_METHODS.sourceControlLookupRepository,

‎packages/contracts/src/rpc.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ import {
395395
SourceControlRepositoryLookupInput,
396396
SourceControlAppAccess,
397397
SourceControlAppAccessInput,
398+
SourceControlStarredInput,
398399
SourceControlSignInError,
399400
SourceControlSignInInput,
400401
SourceControlSignInPrompt,
@@ -592,6 +593,7 @@ export const WS_METHODS = {
592593
sourceControlSignInWait: "sourceControl.signInWait",
593594
sourceControlSignInCancel: "sourceControl.signInCancel",
594595
sourceControlAppAccess: "sourceControl.appAccess",
596+
sourceControlStarred: "sourceControl.starred",
595597
projectCloneStart: "projectClone.start",
596598
projectCloneCancel: "projectClone.cancel",
597599
projectCloneRetry: "projectClone.retry",
@@ -1242,6 +1244,13 @@ const WsSourceControlAppAccessRpc = Rpc.make(WS_METHODS.sourceControlAppAccess,
12421244
error: EnvironmentAuthorizationError,
12431245
});
12441246

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+
12451254
// Returns when the project exists and cloning starts; progress uses the subscription.
12461255
const WsProjectCloneStartRpc = Rpc.make(WS_METHODS.projectCloneStart, {
12471256
payload: ProjectCloneStartInput,
@@ -2070,6 +2079,7 @@ export const WsRpcGroup = RpcGroup.make(
20702079
WsSourceControlSignInWaitRpc,
20712080
WsSourceControlSignInCancelRpc,
20722081
WsSourceControlAppAccessRpc,
2082+
WsSourceControlStarredRpc,
20732083
WsProjectCloneStartRpc,
20742084
WsProjectCloneCancelRpc,
20752085
WsProjectCloneRetryRpc,

‎packages/contracts/src/sourceControl.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ export const SourceControlAppAccess = Schema.Struct({
226226
});
227227
export type SourceControlAppAccess = typeof SourceControlAppAccess.Type;
228228

229+
export const SourceControlStarredInput = Schema.Struct({
230+
provider: SourceControlProviderKind,
231+
host: TrimmedNonEmptyString,
232+
repository: TrimmedNonEmptyString,
233+
});
234+
export type SourceControlStarredInput = typeof SourceControlStarredInput.Type;
235+
229236
export class SourceControlSignInError extends Schema.TaggedError<SourceControlSignInError>()(
230237
"SourceControlSignInError",
231238
{

0 commit comments

Comments
 (0)