Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const AUTO_SETTLE_SETTING_KEYS: ReadonlySet<string> = new Set([
"sidebarAutoSettleAfterDays",
"autoSettleFinishedChildrenAfterHours",
"autoArchiveSettledAfterDays",
"threadHistoryTrimAfterDays",
"autoResumeLimitedThreads",
"snoozeLimitedThreads",
]);
Expand Down
37 changes: 37 additions & 0 deletions apps/mobile/src/features/settings/ThreadSettingsSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DEFAULT_AUTO_ARCHIVE_SETTLED_AFTER_DAYS,
DEFAULT_AUTO_SETTLE_FINISHED_CHILDREN_AFTER_HOURS,
DEFAULT_SERVER_SETTINGS,
DEFAULT_THREAD_HISTORY_TRIM_AFTER_DAYS,
} from "@t3tools/contracts";
import { supportsSharedSettingsSync } from "@t3tools/client-runtime/state/shared-settings";
import { AppText as Text } from "../../components/ui/AppText";
Expand Down Expand Up @@ -114,6 +115,12 @@ export function AutoSettleSettingsRows(props: {
(target) =>
target.environment.serverConfig.environment.capabilities.threadAutoArchive === true,
);
const supportsHistoryTrim =
!projectSelected &&
displayTargets.every(
(target) =>
target.environment.serverConfig.environment.capabilities.threadHistoryTrim === true,
);
const { patch: autoSettlePatch, mismatches } = planAutoSettleSettingsSync(
{
environmentId: reference.environment.environmentId,
Expand All @@ -129,6 +136,7 @@ export function AutoSettleSettingsRows(props: {
{
includeFinishedChildren: supportsFinishedChildAutoSettlement,
includeAutoArchive: supportsAutoArchive,
includeHistoryTrim: supportsHistoryTrim,
},
);

Expand All @@ -138,6 +146,7 @@ export function AutoSettleSettingsRows(props: {
const afterDays = referenceSettings.sidebarAutoSettleAfterDays;
const childAfterHours = referenceSettings.autoSettleFinishedChildrenAfterHours;
const archiveAfterDays = referenceSettings.autoArchiveSettledAfterDays;
const trimAfterDays = referenceSettings.threadHistoryTrimAfterDays;

return (
<View className="gap-6">
Expand Down Expand Up @@ -242,6 +251,34 @@ export function AutoSettleSettingsRows(props: {
) : null}
</SettingsSection>
) : null}
{supportsHistoryTrim ? (
<SettingsSection title="Thread history">
<SettingsSwitchRow
icon="archivebox"
label="Trim old threads"
subtitle="After this many days without use, a thread's tool output and reasoning are removed to save space. Messages, plans and file changes stay, and you can still search and continue the thread. Running, pinned and snoozed threads and threads with an open pull request are skipped."
value={trimAfterDays > 0}
disabled={disabledFor("threadHistoryTrimAfterDays")}
onValueChange={(value) =>
writeToAll({
threadHistoryTrimAfterDays: value ? DEFAULT_THREAD_HISTORY_TRIM_AFTER_DAYS : 0,
})
}
/>
{trimAfterDays > 0 ? (
<View className="flex-row items-center gap-4 px-4 py-4 android:min-h-14 android:py-3">
<View className="w-[22px] android:w-6" />
<Text className="flex-1 text-foreground text-lg android:text-base">Unused days</Text>
<AutoSettleDurationField
unit="trimDay"
value={trimAfterDays}
disabled={disabledFor("threadHistoryTrimAfterDays")}
onValueChange={(value) => writeToAll({ threadHistoryTrimAfterDays: value })}
/>
</View>
) : null}
</SettingsSection>
) : null}
{!props.pending && mismatches.length > 0 ? (
<SettingsSection title="Across environments">
<View className="gap-3 p-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe("auto-settle settings sync", () => {
key: "autoSettleFinishedChildrenAfterHours",
},
{ option: "includeAutoArchive", key: "autoArchiveSettledAfterDays" },
{ option: "includeHistoryTrim", key: "threadHistoryTrimAfterDays" },
] as const)("syncs $key only when the caller includes it", ({ option, key }) => {
const target = {
environmentId: EnvironmentId.make("remote"),
Expand Down
19 changes: 15 additions & 4 deletions apps/mobile/src/features/settings/autoSettleSettingsSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type AutoSettleSettings = Pick<
| "sidebarAutoSettleAfterDays"
| "autoSettleFinishedChildrenAfterHours"
| "autoArchiveSettledAfterDays"
| "threadHistoryTrimAfterDays"
>;

interface AutoSettleSyncTarget {
Expand All @@ -21,12 +22,17 @@ export function planAutoSettleSettingsSync(
readonly settings: AutoSettleSettings;
},
targets: readonly AutoSettleSyncTarget[],
// Child auto-settle and auto-archive are environment-wide and unknown to older servers, so
// callers include them only outside project scope and when every target supports them.
// Child auto-settle, auto-archive and trimming are environment-wide and unknown to older servers,
// so callers include them only outside project scope and when every target supports them.
{
includeFinishedChildren = false,
includeAutoArchive = false,
}: { readonly includeFinishedChildren?: boolean; readonly includeAutoArchive?: boolean } = {},
includeHistoryTrim = false,
}: {
readonly includeFinishedChildren?: boolean;
readonly includeAutoArchive?: boolean;
readonly includeHistoryTrim?: boolean;
} = {},
) {
const patch: Partial<AutoSettleSettings> = {
sidebarAutoSettleAfterDays: reference.settings.sidebarAutoSettleAfterDays,
Expand All @@ -39,6 +45,9 @@ export function planAutoSettleSettingsSync(
...(includeAutoArchive
? { autoArchiveSettledAfterDays: reference.settings.autoArchiveSettledAfterDays }
: {}),
...(includeHistoryTrim
? { threadHistoryTrimAfterDays: reference.settings.threadHistoryTrimAfterDays }
: {}),
};
const mismatches = targets.filter(
(target) =>
Expand All @@ -50,7 +59,9 @@ export function planAutoSettleSettingsSync(
target.settings.autoSettleFinishedChildrenAfterHours !==
patch.autoSettleFinishedChildrenAfterHours) ||
(includeAutoArchive &&
target.settings.autoArchiveSettledAfterDays !== patch.autoArchiveSettledAfterDays)),
target.settings.autoArchiveSettledAfterDays !== patch.autoArchiveSettledAfterDays) ||
(includeHistoryTrim &&
target.settings.threadHistoryTrimAfterDays !== patch.threadHistoryTrimAfterDays)),
);
return { patch, mismatches };
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
MAX_AUTO_ARCHIVE_SETTLED_AFTER_DAYS,
MAX_AUTO_SETTLE_FINISHED_CHILDREN_AFTER_HOURS,
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
MAX_THREAD_HISTORY_TRIM_AFTER_DAYS,
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
} from "@t3tools/contracts";
import type { ComponentProps } from "react";
Expand All @@ -28,6 +29,12 @@ const UNITS = {
noun: "day",
label: "Days settled before a thread is archived",
},
trimDay: {
min: 1,
max: MAX_THREAD_HISTORY_TRIM_AFTER_DAYS,
noun: "day",
label: "Days unused before a thread is trimmed",
},
} as const;

export type AutoSettleDurationFieldProps = Pick<
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.serverGetStorageCleanupReport]: AuthOrchestrationReadScope,
[WS_METHODS.serverGetDatabaseStorage]: AuthOrchestrationReadScope,
[WS_METHODS.serverGetSettings]: AuthOrchestrationReadScope,
[WS_METHODS.serverGetThreadHistoryTrim]: AuthOrchestrationReadScope,
[WS_METHODS.serverPreviewThreadHistoryTrim]: AuthOrchestrationReadScope,
[WS_METHODS.peerLinksList]: AuthAccessReadScope,
[WS_METHODS.serverGetAgentGateway]: AuthAccessReadScope,
[WS_METHODS.tailnetDevicesList]: AuthAccessReadScope,
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/environment/ServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const make = Effect.gen(function* () {
threadAutoSettleOptOut: true,
threadAutoSettleFinishedChildren: true,
threadAutoArchive: true,
threadHistoryTrim: true,
threadProjectFromScratch: true,
threadTitleRegeneration: true,
commandOutputStreaming: true,
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/observability/RpcInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const RPC_AGGREGATES = {
[WS_METHODS.serverGetStorageCleanupReport]: "server",
[WS_METHODS.serverGetDatabaseStorage]: "server",
[WS_METHODS.serverReclaimDatabaseSpace]: "server",
[WS_METHODS.serverGetThreadHistoryTrim]: "server",
[WS_METHODS.serverPreviewThreadHistoryTrim]: "server",
[WS_METHODS.serverTrimThreadHistory]: "server",
[WS_METHODS.serverGetAgentGateway]: "server",
[WS_METHODS.serverUpdateAgentGateway]: "server",
[WS_METHODS.serverRevealAgentGatewayToken]: "server",
Expand Down
Loading
Loading