Skip to content

Commit b2f7f83

Browse files
authored
Merge branch 'main' into fix/persist-manual-project-order
2 parents fbc1aa2 + c9a0e8a commit b2f7f83

36 files changed

Lines changed: 892 additions & 176 deletions

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ const WSL_FORWARDED_ENV_NAMES = [
118118
"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
119119
"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
120120
"OTEL_EXPORTER_OTLP_LOGS_PROTOCOL",
121+
"OTEL_TRACES_EXPORTER",
122+
"OTEL_METRICS_EXPORTER",
123+
"OTEL_LOGS_EXPORTER",
121124
] as const;
122125

123126
const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { ReactNode } from "react";
2+
import { renderToStaticMarkup } from "react-dom/server";
3+
import { describe, expect, it, vi } from "vite-plus/test";
4+
5+
vi.mock("react-native", () => ({
6+
View: ({ children }: { children: ReactNode }) => <div>{children}</div>,
7+
}));
8+
vi.mock("../../components/AppText", () => ({
9+
AppText: ({
10+
accessibilityElementsHidden,
11+
importantForAccessibility,
12+
children,
13+
}: {
14+
accessibilityElementsHidden?: boolean;
15+
importantForAccessibility?: string;
16+
children: ReactNode;
17+
}) => (
18+
<span
19+
aria-hidden={
20+
accessibilityElementsHidden || importantForAccessibility === "no-hide-descendants"
21+
}
22+
>
23+
{children}
24+
</span>
25+
),
26+
AppTextInput: ({ accessibilityLabel }: { accessibilityLabel?: string }) => (
27+
<input aria-label={accessibilityLabel} />
28+
),
29+
}));
30+
31+
import { ConnectionFormField } from "./ConnectionFormField";
32+
33+
describe("ConnectionFormField accessibility", () => {
34+
it.each(["Host", "Pairing code"])("exposes %s once as the input name", (label) => {
35+
const markup = renderToStaticMarkup(
36+
<ConnectionFormField label={label} placeholder="Not an accessible name" />,
37+
);
38+
39+
expect(markup).toContain(`<span aria-hidden="true">${label}</span>`);
40+
expect(markup).toContain(`<input aria-label="${label}"/>`);
41+
});
42+
});

‎apps/mobile/src/features/connection/ConnectionFormField.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { View } from "react-native";
33
import { AppText, AppTextInput, type AppTextInputProps } from "../../components/AppText";
44
import { cn } from "../../lib/cn";
55

6-
type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
6+
type ConnectionFormFieldProps = Omit<AppTextInputProps, "accessibilityLabel" | "className"> & {
77
readonly label: string;
88
readonly className?: string;
99
};
@@ -12,12 +12,16 @@ type ConnectionFormFieldProps = Omit<AppTextInputProps, "className"> & {
1212
export function ConnectionFormField({ label, className, ...inputProps }: ConnectionFormFieldProps) {
1313
return (
1414
<View collapsable={false} className={cn("gap-1.5", className)}>
15-
<AppText className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted">
15+
<AppText
16+
accessibilityElementsHidden
17+
importantForAccessibility="no-hide-descendants"
18+
className="text-2xs font-t3-bold tracking-[0.8px] uppercase text-foreground-muted"
19+
>
1620
{label}
1721
</AppText>
1822
<AppTextInput
19-
accessibilityLabel={label}
2023
{...inputProps}
24+
accessibilityLabel={label}
2125
className="rounded-[14px] px-4 py-3.5"
2226
/>
2327
</View>

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,27 +1028,25 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
10281028
)}
10291029
{pr ? (
10301030
<View className="flex-row items-center gap-1" accessibilityLabel={pr.accessibilityLabel}>
1031-
{pr.kind === "stack" || pr.others > 0 ? (
1032-
<SymbolView
1033-
name={pr.kind === "stack" ? "square.3.layers.3d" : "arrow.triangle.pull"}
1034-
size={12}
1035-
tintColorClassName={
1036-
pr.state === null || pr.isDraft
1037-
? rowAppearance.mutedIconTintClassName
1038-
: pr.state === "open"
1039-
? "accent-adaptive-emerald-600-400"
1040-
: pr.state === "closed"
1041-
? "accent-adaptive-rose-600-400"
1042-
: "accent-adaptive-violet-600-400"
1043-
}
1044-
/>
1045-
) : null}
1031+
<SymbolView
1032+
name={pr.kind === "stack" ? "square.3.layers.3d" : "arrow.triangle.pull"}
1033+
size={12}
1034+
tintColorClassName={
1035+
pr.state === null || pr.isDraft
1036+
? rowAppearance.mutedIconTintClassName
1037+
: pr.state === "open"
1038+
? "accent-adaptive-emerald-600-400"
1039+
: pr.state === "closed"
1040+
? "accent-adaptive-rose-600-400"
1041+
: "accent-adaptive-violet-600-400"
1042+
}
1043+
/>
10461044
<Text
10471045
accessibilityLabel={pr.accessibilityLabel}
10481046
className={cn("text-xs", pr.textClassName)}
10491047
style={{ fontFamily: MONO_FONT }}
10501048
>
1051-
{pr.kind === "stack" || pr.others > 0 ? pr.label : `#${pr.label}`}
1049+
{pr.label}
10521050
</Text>
10531051
</View>
10541052
) : null}

‎apps/mobile/src/features/usage/UsageRouteScreen.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
22
import { EnvironmentId, USAGE_CONTRACT_VERSION } from "@t3tools/contracts";
33
import { type RouteProp, useIsFocused, useNavigation, useRoute } from "@react-navigation/native";
4+
import { cursorKeychainAccessEnvironments } from "@t3tools/client-runtime/state/usage";
45
import {
56
isCompatibleUsageContractVersion,
67
isModelCostUnknown,
@@ -15,6 +16,7 @@ import {
1516
formatHourShort,
1617
formatPercent,
1718
formatTokens,
19+
formatUsageContractMismatch,
1820
formatUsd,
1921
makeWindow,
2022
} from "@t3tools/shared/usageFormat";
@@ -101,9 +103,7 @@ export function UsageRouteScreen() {
101103
);
102104
const isFocused = useIsFocused();
103105
const limits = useRefreshLimits(selectedEnvironmentIds, isFocused && tab === "limits");
104-
const cursorAccessEnvironments = selectedEnvironments.filter(
105-
(environment) => environment.needsCursorKeychainAccess,
106-
);
106+
const cursorAccessEnvironments = cursorKeychainAccessEnvironments(selectedEnvironments);
107107
const refreshAfterCursorEnable = () => {
108108
void refresh();
109109
void limits.refreshAfterEnable();
@@ -753,7 +753,12 @@ function usageEnvironmentStatus(environment: EnvironmentUsageStatus): string {
753753
environment.summary &&
754754
!isCompatibleUsageContractVersion(environment.summary.contractVersion, USAGE_CONTRACT_VERSION)
755755
) {
756-
return "Older server · excluded from usage totals";
756+
return formatUsageContractMismatch(environment.label, {
757+
direction:
758+
environment.summary.contractVersion < USAGE_CONTRACT_VERSION
759+
? "serverBehind"
760+
: "clientBehind",
761+
});
757762
}
758763
if (!environment.isConnected)
759764
return environment.summary ? "Disconnected · showing saved usage" : "Waiting for connection…";

‎apps/server/src/provider/cursorCredentialStore.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { assert, describe, it } from "@effect/vitest";
22

3-
import { makeCachedCursorAccessTokenReader } from "./cursorCredentialStore.ts";
3+
import {
4+
CursorKeychainTimeoutError,
5+
makeCachedCursorAccessTokenReader,
6+
} from "./cursorCredentialStore.ts";
47

58
describe("Cursor Keychain reader", () => {
69
it("shares concurrent reads and rechecks after the cache expires", async () => {
@@ -19,4 +22,25 @@ describe("Cursor Keychain reader", () => {
1922
time = 5 * 60_000;
2023
assert.strictEqual(await read(), "token-2");
2124
});
25+
26+
it("gives up on an unanswered prompt and reuses it on the next read", async () => {
27+
let reads = 0;
28+
let allow: (token: string) => void = () => {};
29+
const read = makeCachedCursorAccessTokenReader(
30+
() => {
31+
reads++;
32+
return new Promise((resolve) => {
33+
allow = resolve;
34+
});
35+
},
36+
() => 0,
37+
1,
38+
);
39+
const error = await read().catch((cause: unknown) => cause);
40+
assert.instanceOf(error, CursorKeychainTimeoutError);
41+
const retry = read();
42+
allow("token");
43+
assert.strictEqual(await retry, "token");
44+
assert.strictEqual(reads, 1);
45+
});
2246
});

‎apps/server/src/provider/cursorCredentialStore.ts‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,47 @@ const CACHE_MS = 5 * 60_000;
44

55
const requireForKeyring = NodeModule.createRequire(import.meta.url);
66

7-
/** Share one Keychain request across usage history and limits in this server process. */
7+
/** Rejected when nobody answers the macOS Keychain prompt in time. */
8+
export class CursorKeychainTimeoutError extends Error {
9+
constructor() {
10+
super("Timed out waiting for Keychain access.");
11+
}
12+
}
13+
14+
/**
15+
* Share one Keychain request across usage history and limits in this server process.
16+
*
17+
* macOS shows the access prompt on the server's own screen, which a remote
18+
* client cannot answer, so callers give up after `timeoutMs`. The read stays in
19+
* flight: the next call reuses it instead of stacking a second prompt, and picks
20+
* up the token once someone allows access.
21+
*/
822
export function makeCachedCursorAccessTokenReader(
923
read: () => Promise<string | null>,
1024
now: () => number = Date.now,
25+
timeoutMs = 30_000,
1126
): () => Promise<string | null> {
1227
let cached: { token: string; until: number } | null = null;
1328
let pending: Promise<string | null> | null = null;
1429
return () => {
1530
if (cached && cached.until > now()) return Promise.resolve(cached.token);
16-
if (pending) return pending;
17-
pending = read()
31+
pending ??= read()
1832
.then((token) => {
1933
cached = token ? { token, until: now() + CACHE_MS } : null;
2034
return token;
2135
})
2236
.finally(() => {
2337
pending = null;
2438
});
25-
return pending;
39+
const deadline = AbortSignal.timeout(timeoutMs);
40+
return Promise.race([
41+
pending,
42+
new Promise<never>((_, reject) => {
43+
deadline.addEventListener("abort", () => reject(new CursorKeychainTimeoutError()), {
44+
once: true,
45+
});
46+
}),
47+
]);
2648
};
2749
}
2850

‎apps/server/src/usage/UsageService.test.ts‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,46 @@ function totalOutputTokens(summary: { buckets: readonly { totals: { outputTokens
121121
}
122122

123123
describe("UsageService", () => {
124+
it.live("omits Cursor account usage when no file login is saved", () =>
125+
Effect.gen(function* () {
126+
const { settings, home } = yield* setup;
127+
for (const platform of ["linux", "win32", "darwin"] as const) {
128+
const service = yield* UsageService.make.pipe(
129+
Effect.provide(
130+
serviceLayers({
131+
prefix: `usage-service-cursor-no-login-${platform}`,
132+
home,
133+
settings,
134+
platform,
135+
environment: { AGENT_CLI_CREDENTIAL_STORE: "file" },
136+
}),
137+
),
138+
);
139+
const summary = yield* service.readSummary(WINDOW);
140+
assert.isFalse(summary.sources.some((source) => source.fingerprint.provider === "cursor"));
141+
}
142+
}).pipe(Effect.scoped),
143+
);
144+
145+
it.live("keeps Cursor credential errors visible when a saved login cannot be read", () =>
146+
Effect.gen(function* () {
147+
const { settings, home } = yield* setup;
148+
const authPath = NodePath.join(home, "config", "cursor", "auth.json");
149+
yield* Effect.promise(async () => {
150+
await NodeFSP.mkdir(NodePath.dirname(authPath), { recursive: true });
151+
await NodeFSP.writeFile(authPath, "invalid json");
152+
});
153+
const service = yield* UsageService.make.pipe(
154+
Effect.provide(
155+
serviceLayers({ prefix: "usage-service-cursor-invalid-login", home, settings }),
156+
),
157+
);
158+
const summary = yield* service.readSummary(WINDOW);
159+
const cursor = summary.sources.find((source) => source.fingerprint.provider === "cursor");
160+
assert.strictEqual(cursor?.message, "Cursor credentials could not be read.");
161+
}).pipe(Effect.scoped),
162+
);
163+
124164
it.live("does not read the macOS Cursor Keychain before account usage is enabled", () =>
125165
Effect.gen(function* () {
126166
const { settings, home } = yield* setup;
@@ -233,10 +273,7 @@ describe("UsageService", () => {
233273
const summary = yield* service.readSummary(WINDOW);
234274
assert.strictEqual(summary.buckets[0]?.provider, "opencode");
235275
assert.isFalse(summary.buckets.some((bucket) => bucket.provider === "cursor"));
236-
assert.strictEqual(
237-
summary.sources.find((source) => source.fingerprint.provider === "cursor")?.status,
238-
"missing",
239-
);
276+
assert.isFalse(summary.sources.some((source) => source.fingerprint.provider === "cursor"));
240277
assert.strictEqual(
241278
summary.buckets[0]?.sourcePath,
242279
yield* Effect.promise(() => NodeFSP.realpath(root)),
@@ -247,10 +284,6 @@ describe("UsageService", () => {
247284
?.distinctSessions,
248285
1,
249286
);
250-
assert.include(
251-
summary.sources.find((source) => source.fingerprint.provider === "cursor")?.message ?? "",
252-
"Cursor account history needs a Cursor CLI login",
253-
);
254287
}).pipe(Effect.scoped),
255288
);
256289

‎apps/server/src/usage/UsageService.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ export const make = Effect.gen(function* () {
635635
cursorUntilMs,
636636
),
637637
);
638+
// No saved login means there is no account source to report, not a setup error.
639+
if (account.missing && account.error === null) return scanned;
638640
if (account.accountKey !== null && account.error === null && !account.missing) {
639641
// The same account includes CLI and desktop history from every machine.
640642
// A stable remote fingerprint prevents connected environments counting it twice.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { assert, describe, it } from "@effect/vitest";
2+
3+
import { CursorKeychainTimeoutError } from "../provider/cursorCredentialStore.ts";
4+
import { readCursorAccountUsage } from "./cursorUsageReader.ts";
5+
6+
describe("readCursorAccountUsage", () => {
7+
it("asks for Keychain approval when the prompt goes unanswered", async () => {
8+
const result = await readCursorAccountUsage(
9+
{ kind: "keychain" },
10+
0,
11+
1,
12+
() => Promise.reject(new Error("no network expected")),
13+
() => Promise.reject(new CursorKeychainTimeoutError()),
14+
);
15+
assert.deepStrictEqual(result, {
16+
accountKey: null,
17+
records: [],
18+
missing: false,
19+
error: "Allow Keychain access on the Mac running T3 Code, then refresh.",
20+
});
21+
});
22+
});

0 commit comments

Comments
 (0)