Skip to content

Commit f2f9d96

Browse files
committed
chore: consolidate thread workspace branches
Preserve the reviewed tab/grid history while making the Discussion branch resolve to the complete drag-and-drop implementation from PR #11.
2 parents 747d812 + 987467f commit f2f9d96

82 files changed

Lines changed: 8241 additions & 789 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.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Full docs live in [docs/](./docs). There's no docs site yet.
8282
- [Remote access from a phone or another machine](./docs/user/remote-access.md)
8383
- [Keeping app and server in sync](./docs/user/updating.md)
8484
- [Source control integrations](./docs/user/source-control.md)
85+
- [Track plan limits](./docs/user/plan-limits.md)
8586
- Multiple accounts: [Codex](./docs/user/providers-codex.md) · [Claude](./docs/user/providers-claude.md)
8687
- Linux: [run T3 Code as a background service](./docs/user/background-service.md)
8788

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ const clientSettings: ClientSettings = {
4747
sidebarProjectSortOrder: "manual",
4848
sidebarThreadSortOrder: "created_at",
4949
sidebarThreadPreviewCount: 6,
50+
sidebarThreadPrimaryGrouping: "environment",
51+
sidebarThreadSecondaryGrouping: "project",
52+
sidebarThreadProviderFilter: "codex",
53+
sidebarThreadCollapsedGroups: ["environment:environment-1"],
54+
sidebarSectionOrderMode: "manual",
55+
sidebarSectionOrder: ["environment:environment-2", "environment:environment-1"],
5056
legacySidebarEnabled: false,
5157
timestampFormat: "24-hour",
5258
wordWrap: true,

‎apps/mobile/src/features/settings/components/SettingsSection.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import { AppText as Text } from "../../../components/AppText";
66
export function SettingsSection(props: {
77
readonly title: string;
88
readonly children: ReactNode;
9+
readonly headerAction?: ReactNode;
910
/** Force the grouped card background; Android otherwise lists options flat. */
1011
readonly card?: boolean;
1112
}) {
1213
return (
1314
<View className="gap-2">
14-
<Text className="px-2 text-sm font-t3-medium text-foreground-muted">{props.title}</Text>
15+
<View className="flex-row items-center justify-between gap-3 px-2">
16+
<Text className="text-sm font-t3-medium text-foreground-muted">{props.title}</Text>
17+
{props.headerAction}
18+
</View>
1519
<View
1620
className={
1721
props.card

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

Lines changed: 210 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { useNavigation } from "@react-navigation/native";
2+
import { useAtomValue } from "@effect/atom-react";
23
import type { DailyTotals, MergedUsage } from "@t3tools/shared/usageMerge";
4+
import {
5+
buildProviderRateLimitsView,
6+
type ProviderRateLimitsView,
7+
type RateLimitWindowView,
8+
} from "@t3tools/shared/providerRateLimits";
39
import {
410
enumerateDays,
511
enumerateHourStarts,
@@ -11,13 +17,22 @@ import {
1117
formatUsd,
1218
makeWindow,
1319
} from "@t3tools/shared/usageFormat";
14-
import { useMemo, useState } from "react";
15-
import { Platform, Pressable, RefreshControl, ScrollView, View } from "react-native";
20+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
21+
import {
22+
ActivityIndicator,
23+
Platform,
24+
Pressable,
25+
RefreshControl,
26+
ScrollView,
27+
View,
28+
} from "react-native";
1629
import { useSafeAreaInsets } from "react-native-safe-area-context";
1730

1831
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
1932
import { AppText as Text } from "../../components/AppText";
2033
import { NativeStackScreenOptions } from "../../native/StackHeader";
34+
import { environmentServerConfigsAtom, serverEnvironment } from "../../state/server";
35+
import { useAtomCommand } from "../../state/use-atom-command";
2136
import { useUsage, type EnvironmentUsageStatus } from "../../state/usage";
2237
import { SettingsSection } from "../settings/components/SettingsSection";
2338
import { UsageDailyChart } from "./UsageDailyChart";
@@ -44,6 +59,62 @@ export function UsageRouteScreen() {
4459
const { days: windowDays, window } = windowSelection;
4560
const isPast24Hours = windowDays === 1;
4661
const { merged, environments, isPending, isPartial, refresh } = useUsage(window);
62+
const serverConfigs = useAtomValue(environmentServerConfigsAtom);
63+
const refreshProviderRateLimits = useAtomCommand(serverEnvironment.refreshProviderRateLimits, {
64+
reportFailure: false,
65+
});
66+
const refreshingPlanLimitsRef = useRef(false);
67+
const [isRefreshingPlanLimits, setIsRefreshingPlanLimits] = useState(false);
68+
const [planLimitsRefreshFailed, setPlanLimitsRefreshFailed] = useState(false);
69+
const rateLimitEnvironments = useMemo(
70+
() =>
71+
environments.map((environment) => ({
72+
environmentId: environment.environmentId,
73+
label: environment.label,
74+
providers: serverConfigs.get(environment.environmentId)?.providers ?? [],
75+
})),
76+
[environments, serverConfigs],
77+
);
78+
const hasRateLimitSnapshots = rateLimitEnvironments.some((environment) =>
79+
environment.providers.some((provider) => (provider.rateLimits?.windows.length ?? 0) > 0),
80+
);
81+
const [rateLimitsNowMs, setRateLimitsNowMs] = useState(() => Date.now());
82+
useEffect(() => {
83+
if (!hasRateLimitSnapshots) {
84+
return;
85+
}
86+
setRateLimitsNowMs(Date.now());
87+
const intervalId = setInterval(() => setRateLimitsNowMs(Date.now()), 60_000);
88+
return () => clearInterval(intervalId);
89+
}, [hasRateLimitSnapshots]);
90+
const planLimits = useMemo(
91+
() =>
92+
buildProviderRateLimitsView({
93+
environments: rateLimitEnvironments,
94+
nowMs: rateLimitsNowMs,
95+
}),
96+
[rateLimitEnvironments, rateLimitsNowMs],
97+
);
98+
const refreshPlanLimits = useCallback(() => {
99+
if (refreshingPlanLimitsRef.current || planLimits.refreshTargets.length === 0) {
100+
return;
101+
}
102+
refreshingPlanLimitsRef.current = true;
103+
setIsRefreshingPlanLimits(true);
104+
setPlanLimitsRefreshFailed(false);
105+
void Promise.all(
106+
planLimits.refreshTargets.map((target) =>
107+
refreshProviderRateLimits({
108+
environmentId: target.environmentId,
109+
input: { instanceId: target.instanceId },
110+
}),
111+
),
112+
).then((results) => {
113+
refreshingPlanLimitsRef.current = false;
114+
setIsRefreshingPlanLimits(false);
115+
setPlanLimitsRefreshFailed(results.some((result) => result._tag === "Failure"));
116+
});
117+
}, [planLimits.refreshTargets, refreshProviderRateLimits]);
47118

48119
const days = useMemo(
49120
() => enumerateDays(window.sinceDay, window.untilDay),
@@ -117,6 +188,13 @@ export function UsageRouteScreen() {
117188

118189
<UsageCoverageNotice environments={environments} merged={merged} isPartial={isPartial} />
119190

191+
<PlanLimitsSection
192+
isRefreshing={isRefreshingPlanLimits}
193+
refreshFailed={planLimitsRefreshFailed}
194+
view={planLimits}
195+
onRefresh={refreshPlanLimits}
196+
/>
197+
120198
{isPending ? (
121199
<Text className="py-16 text-center text-base text-foreground-muted">
122200
Scanning provider transcripts…
@@ -148,6 +226,136 @@ export function UsageRouteScreen() {
148226
);
149227
}
150228

229+
function PlanLimitsSection(props: {
230+
readonly view: ProviderRateLimitsView;
231+
readonly isRefreshing: boolean;
232+
readonly refreshFailed: boolean;
233+
readonly onRefresh: () => void;
234+
}) {
235+
if (props.view.providers.length === 0 && props.view.refreshTargets.length === 0) {
236+
return null;
237+
}
238+
239+
return (
240+
<SettingsSection
241+
title="Plan limits"
242+
card
243+
headerAction={
244+
props.view.refreshTargets.length > 0 ? (
245+
<Pressable
246+
accessibilityLabel="Refresh plan limits"
247+
accessibilityRole="button"
248+
className="min-h-8 min-w-16 flex-row items-center justify-center gap-2 rounded-full px-2 active:bg-subtle"
249+
disabled={props.isRefreshing}
250+
onPress={props.onRefresh}
251+
>
252+
{props.isRefreshing ? <ActivityIndicator size="small" /> : null}
253+
<Text className="text-sm font-t3-medium text-foreground-muted">
254+
{props.isRefreshing ? "Refreshing" : "Refresh"}
255+
</Text>
256+
</Pressable>
257+
) : null
258+
}
259+
>
260+
{props.refreshFailed ? (
261+
<Text className="border-b border-border-subtle px-4 py-3 text-sm text-danger-foreground">
262+
Some accounts could not refresh. Start a provider session and try again.
263+
</Text>
264+
) : null}
265+
{props.view.providers.length === 0 ? (
266+
<Text className="px-4 py-4 text-sm text-foreground-muted">
267+
No plan limits reported yet. Start a provider session, then refresh.
268+
</Text>
269+
) : null}
270+
{props.view.providers.map((provider, index) => (
271+
<View
272+
key={provider.key}
273+
className={index === 0 ? "gap-3 p-4" : "gap-3 border-t border-border-subtle p-4"}
274+
>
275+
<View className="flex-row items-baseline justify-between gap-3">
276+
<View className="min-w-0 flex-1">
277+
<Text className="text-base font-t3-medium text-foreground" numberOfLines={1}>
278+
{provider.displayName}
279+
{provider.planLabel ? ` · ${provider.planLabel}` : ""}
280+
</Text>
281+
{provider.environmentLabel ? (
282+
<Text className="text-xs text-foreground-tertiary" numberOfLines={1}>
283+
{provider.environmentLabel}
284+
</Text>
285+
) : null}
286+
</View>
287+
</View>
288+
289+
{provider.windows.map((window) => (
290+
<PlanLimitWindowRow
291+
key={window.id}
292+
accentColor={provider.accentColor}
293+
window={window}
294+
/>
295+
))}
296+
297+
{provider.notice ? (
298+
<Text className="text-sm text-danger-foreground">{provider.notice}</Text>
299+
) : null}
300+
</View>
301+
))}
302+
</SettingsSection>
303+
);
304+
}
305+
306+
function PlanLimitWindowRow(props: {
307+
readonly window: RateLimitWindowView;
308+
readonly accentColor: string | undefined;
309+
}) {
310+
const { window } = props;
311+
const percentLabel = window.isReset ? "reset" : `${Math.round(window.usedPercent)}%`;
312+
313+
return (
314+
<View className="gap-1.5">
315+
<View className="flex-row items-baseline justify-between gap-3">
316+
<Text className="text-sm text-foreground-muted">{window.label}</Text>
317+
<Text
318+
className={
319+
window.status === "exhausted"
320+
? "text-sm font-t3-medium tabular-nums text-danger-foreground"
321+
: "text-sm tabular-nums text-foreground-muted"
322+
}
323+
>
324+
{percentLabel}
325+
{!window.isReset && window.resetsInLabel ? ` · ${window.resetsInLabel} left` : ""}
326+
</Text>
327+
</View>
328+
<View
329+
accessibilityLabel={`${window.label} usage`}
330+
accessibilityRole="progressbar"
331+
accessibilityValue={{
332+
min: 0,
333+
max: 100,
334+
now: Math.round(window.usedPercent),
335+
}}
336+
className="h-1.5 overflow-hidden rounded-full bg-subtle-strong"
337+
>
338+
<View
339+
className={
340+
window.status === "exhausted"
341+
? "h-full rounded-full bg-danger-foreground"
342+
: "h-full rounded-full bg-foreground-muted"
343+
}
344+
style={{
345+
width: `${window.usedPercent}%`,
346+
...(props.accentColor && window.status === "ok"
347+
? { backgroundColor: props.accentColor }
348+
: {}),
349+
}}
350+
/>
351+
</View>
352+
{window.detail ? (
353+
<Text className="text-xs text-foreground-tertiary">{window.detail}</Text>
354+
) : null}
355+
</View>
356+
);
357+
}
358+
151359
function SegmentedControl<Value extends number | string>(props: {
152360
readonly options: readonly { readonly value: Value; readonly label: string }[];
153361
readonly selected: Value;

‎apps/server/integration/OrchestrationEngineHarness.integration.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import * as ThreadPlanProgress from "../src/orchestration/ThreadPlanProgress.ts"
5656
import { RuntimeReceiptBusTest } from "../src/orchestration/Layers/RuntimeReceiptBus.ts";
5757
import { OrchestrationReactorLive } from "../src/orchestration/Layers/OrchestrationReactor.ts";
5858
import { ProviderCommandReactorLive } from "../src/orchestration/Layers/ProviderCommandReactor.ts";
59+
import { ProviderRateLimitsReactor } from "../src/orchestration/Services/ProviderRateLimitsReactor.ts";
5960
import { ProviderRuntimeIngestionLive } from "../src/orchestration/Layers/ProviderRuntimeIngestion.ts";
6061
import { CheckpointReactor } from "../src/orchestration/Services/CheckpointReactor.ts";
6162
import { ProviderRuntimeIngestionService } from "../src/orchestration/Services/ProviderRuntimeIngestion.ts";
@@ -369,6 +370,12 @@ export const makeOrchestrationIntegrationHarness = (
369370
const orchestrationReactorLayer = OrchestrationReactorLive.pipe(
370371
Layer.provideMerge(runtimeIngestionLayer),
371372
Layer.provideMerge(providerCommandReactorLayer),
373+
Layer.provideMerge(
374+
Layer.succeed(ProviderRateLimitsReactor, {
375+
start: () => Effect.void,
376+
drain: Effect.void,
377+
}),
378+
),
372379
Layer.provideMerge(checkpointReactorLayer),
373380
Layer.provideMerge(
374381
Layer.succeed(ThreadDeletionReactor, {

‎apps/server/integration/orphanedProviderSessionStartup.integration.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const startupDependencies = Layer.mergeAll(
115115
listSessions: () => Effect.succeed([]),
116116
getCapabilities: () => Effect.die("unused"),
117117
getInstanceInfo: () => Effect.die("unused"),
118+
refreshRateLimits: () => Effect.die("unused"),
118119
rollbackConversation: () => Effect.die("unused"),
119120
uploadFeedback: () => Effect.die("unused"),
120121
streamEvents: Stream.empty,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const RPC_REQUIRED_SCOPES = {
3232
[WS_METHODS.serverProbe]: AuthOrchestrationReadScope,
3333
[WS_METHODS.serverGetConfig]: AuthOrchestrationReadScope,
3434
[WS_METHODS.serverRefreshProviders]: AuthOrchestrationOperateScope,
35+
[WS_METHODS.serverRefreshProviderRateLimits]: AuthOrchestrationOperateScope,
3536
[WS_METHODS.serverUpdateProvider]: AuthOrchestrationOperateScope,
3637
[WS_METHODS.serverUpdateServer]: AuthOrchestrationOperateScope,
3738
[WS_METHODS.serverUpdateServerWithProgress]: AuthOrchestrationOperateScope,

‎apps/server/src/orchestration/Layers/CheckpointReactor.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function createProviderServiceHarness(
124124
continuationKey: `${providerName}:instance:${instanceId}`,
125125
},
126126
}),
127+
refreshRateLimits: () => unsupported(),
127128
rollbackConversation,
128129
uploadFeedback: () => unsupported(),
129130
get streamEvents() {

‎apps/server/src/orchestration/Layers/OrchestrationReactor.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { afterEach, describe, expect, it } from "vite-plus/test";
77

88
import { CheckpointReactor } from "../Services/CheckpointReactor.ts";
99
import { ProviderCommandReactor } from "../Services/ProviderCommandReactor.ts";
10+
import { ProviderRateLimitsReactor } from "../Services/ProviderRateLimitsReactor.ts";
1011
import { ProviderRuntimeIngestionService } from "../Services/ProviderRuntimeIngestion.ts";
1112
import { ThreadDeletionReactor } from "../Services/ThreadDeletionReactor.ts";
1213
import { OrchestrationReactor } from "../Services/OrchestrationReactor.ts";
@@ -23,7 +24,7 @@ describe("OrchestrationReactor", () => {
2324
runtime = null;
2425
});
2526

26-
it("starts provider ingestion, provider command, checkpoint, and thread deletion reactors", async () => {
27+
it("starts provider ingestion, provider command, rate limits, checkpoint, and thread deletion reactors", async () => {
2728
const started: string[] = [];
2829

2930
runtime = ManagedRuntime.make(
@@ -46,6 +47,15 @@ describe("OrchestrationReactor", () => {
4647
drain: Effect.void,
4748
}),
4849
),
50+
Layer.provideMerge(
51+
Layer.succeed(ProviderRateLimitsReactor, {
52+
start: () => {
53+
started.push("provider-rate-limits-reactor");
54+
return Effect.void;
55+
},
56+
drain: Effect.void,
57+
}),
58+
),
4959
Layer.provideMerge(
5060
Layer.succeed(CheckpointReactor, {
5161
start: () => {
@@ -83,6 +93,7 @@ describe("OrchestrationReactor", () => {
8393
expect(started).toEqual([
8494
"provider-runtime-ingestion",
8595
"provider-command-reactor",
96+
"provider-rate-limits-reactor",
8697
"checkpoint-reactor",
8798
"thread-deletion-reactor",
8899
"agent-awareness-relay",

‎apps/server/src/orchestration/Layers/OrchestrationReactor.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ import {
77
} from "../Services/OrchestrationReactor.ts";
88
import { CheckpointReactor } from "../Services/CheckpointReactor.ts";
99
import { ProviderCommandReactor } from "../Services/ProviderCommandReactor.ts";
10+
import { ProviderRateLimitsReactor } from "../Services/ProviderRateLimitsReactor.ts";
1011
import { ProviderRuntimeIngestionService } from "../Services/ProviderRuntimeIngestion.ts";
1112
import { ThreadDeletionReactor } from "../Services/ThreadDeletionReactor.ts";
1213
import * as AgentAwarenessRelay from "../../relay/AgentAwarenessRelay.ts";
1314

1415
export const makeOrchestrationReactor = Effect.gen(function* () {
1516
const providerRuntimeIngestion = yield* ProviderRuntimeIngestionService;
1617
const providerCommandReactor = yield* ProviderCommandReactor;
18+
const providerRateLimitsReactor = yield* ProviderRateLimitsReactor;
1719
const checkpointReactor = yield* CheckpointReactor;
1820
const threadDeletionReactor = yield* ThreadDeletionReactor;
1921
const agentAwarenessRelay = yield* AgentAwarenessRelay.AgentAwarenessRelay;
2022

2123
const start: OrchestrationReactorShape["start"] = Effect.fn("start")(function* () {
2224
yield* providerRuntimeIngestion.start();
2325
yield* providerCommandReactor.start();
26+
yield* providerRateLimitsReactor.start();
2427
yield* checkpointReactor.start();
2528
yield* threadDeletionReactor.start();
2629
yield* agentAwarenessRelay.start();

0 commit comments

Comments
 (0)