Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
52 changes: 15 additions & 37 deletions apps/mobile/src/features/settings/SettingsRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ import {
DEFAULT_SERVER_SETTINGS,
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
type ServerSettingsPatch,
} from "@t3tools/contracts";
import {
filterSharedServerPatch,
findSharedSettingsMismatches,
pickSharedServerSettings,
supportsSharedSettingsSync,
} from "@t3tools/client-runtime/state/shared-settings";
import { supportsSharedSettingsSync } from "@t3tools/client-runtime/state/shared-settings";
import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
import {
type AppUpdateCheckState,
Expand All @@ -61,6 +55,7 @@ import { SettingsRow } from "./components/SettingsRow";
import { SettingsSection } from "./components/SettingsSection";
import { SettingsSwitchRow } from "./components/SettingsSwitchRow";
import { resolveAgentAwarenessPlatformPresentation } from "./SettingsRouteScreen.logic";
import { planAutoSettleSettingsSync, type AutoSettleSettings } from "./autoSettleSettingsSync";

type NotificationStatus = "checking" | "enabled" | "disabled" | "unsupported";
type LiveActivityStatus = "checking" | "enabled" | "disabled" | "signed-out" | "linking";
Expand Down Expand Up @@ -588,10 +583,9 @@ function GeneralSettingsSection() {
const AUTO_SETTLE_DEFAULT_DAYS = DEFAULT_SERVER_SETTINGS.sidebarAutoSettleAfterDays ?? 3;

/**
* Auto-settlement is a user preference that every server has to hold. Mobile
* has no primary environment, so the first eligible sync target provides the
* reference value. Edits fan out to every eligible target, and a mismatch row
* lets the user push the reference out.
* Mobile edits auto-settle defaults across connected, capable environments.
* The first target supplies the displayed values. Applying them leaves each
* environment's other defaults and overrides intact.
*/
function AutoSettleSettingsRows() {
const { environments } = useEnvironments();
Expand All @@ -610,24 +604,20 @@ function AutoSettleSettingsRows() {
return null;
}

const writeToAll = (patch: ServerSettingsPatch) => {
const writeToAll = (patch: Partial<AutoSettleSettings>) => {
for (const environment of syncTargets) {
void updateSettings({ environmentId: environment.environmentId, input: { patch } });
}
};

const mismatches = findSharedSettingsMismatches({
primaryEnvironmentId: reference.environmentId,
primarySettings: referenceSettings,
primaryCapabilities: reference.serverConfig?.environment.capabilities,
environments: environments.map((environment) => ({
const { patch: autoSettlePatch, mismatches } = planAutoSettleSettingsSync(
{ environmentId: reference.environmentId, settings: referenceSettings },
syncTargets.map((environment) => ({
environmentId: environment.environmentId,
label: environment.label,
syncEligible: supportsSharedSettingsSync(environment),
settings: environment.serverConfig?.settings ?? null,
capabilities: environment.serverConfig?.environment.capabilities,
})),
});
);

const afterDays = referenceSettings.sidebarAutoSettleAfterDays;
const commitDays = () => {
Expand Down Expand Up @@ -681,38 +671,26 @@ function AutoSettleSettingsRows() {
{mismatches.length > 0 ? (
<View className="flex-row items-center gap-4 border-t border-border-subtle p-4">
<View className="min-w-0 flex-1">
<Text className="text-lg text-foreground">Settings differ</Text>
<Text className="text-lg text-foreground">Auto-settle defaults differ</Text>
<Text className="text-sm text-foreground-muted">
{mismatches.map((mismatch) => mismatch.label).join(", ")}
</Text>
</View>
<Pressable
accessibilityRole="button"
onPress={() => {
const patch = pickSharedServerSettings(
referenceSettings,
reference.serverConfig?.environment.capabilities,
);
for (const mismatch of mismatches) {
const target = environments.find(
(candidate) => candidate.environmentId === mismatch.environmentId,
);
void updateSettings({
environmentId: mismatch.environmentId,
input: {
patch: filterSharedServerPatch(
patch,
target?.serverConfig?.environment.capabilities,
target?.serverConfig?.settings,
referenceSettings,
),
},
input: { patch: autoSettlePatch },
});
}
}}
className="rounded-full bg-subtle px-4 py-2 active:opacity-70"
>
<Text className="text-base font-t3-medium text-foreground">Apply to all</Text>
<Text className="text-base font-t3-medium text-foreground">
Apply auto-settle defaults
</Text>
</Pressable>
</View>
) : null}
Expand Down
78 changes: 78 additions & 0 deletions apps/mobile/src/features/settings/autoSettleSettingsSync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { planAutoSettleSettingsSync } from "./autoSettleSettingsSync";

const reference = {
environmentId: EnvironmentId.make("reference"),
settings: {
...DEFAULT_SERVER_SETTINGS,
sidebarAutoSettleAfterDays: 7,
sidebarAutoSettleOnMerge: true,
newWorktreesStartFromOrigin: false,
continueThreadsAfterServerUpdate: false,
},
};

describe("auto-settle settings sync", () => {
it("ignores differences in independently configured environment settings", () => {
const target = {
environmentId: EnvironmentId.make("remote"),
label: "Remote",
settings: {
...reference.settings,
newWorktreesStartFromOrigin: true,
continueThreadsAfterServerUpdate: true,
sourceControlWritingStyle: {
...reference.settings.sourceControlWritingStyle,
customInstructions: "Keep this environment's writing instructions.",
},
},
};

const plan = planAutoSettleSettingsSync(reference, [target]);

expect(plan.mismatches).toEqual([]);
expect(plan.patch).toEqual({
sidebarAutoSettleAfterDays: 7,
sidebarAutoSettleOnMerge: true,
});
});

it("applies only auto-settle defaults when another environment differs", () => {
const target = {
environmentId: EnvironmentId.make("remote"),
label: "Remote",
settings: {
...reference.settings,
sidebarAutoSettleAfterDays: null,
sidebarAutoSettleOnMerge: false,
newWorktreesStartFromOrigin: true,
continueThreadsAfterServerUpdate: true,
sourceControlWritingStyle: {
...reference.settings.sourceControlWritingStyle,
customInstructions: "Preserve these instructions.",
},
},
};

const plan = planAutoSettleSettingsSync(reference, [target]);
const updated = { ...target.settings, ...plan.patch };

expect(plan.mismatches).toEqual([target]);
expect(updated.sidebarAutoSettleAfterDays).toBe(7);
expect(updated.sidebarAutoSettleOnMerge).toBe(true);
expect(updated.newWorktreesStartFromOrigin).toBe(true);
expect(updated.continueThreadsAfterServerUpdate).toBe(true);
expect(updated.sourceControlWritingStyle).toEqual(target.settings.sourceControlWritingStyle);
});

it("does not compare the reference or a target without loaded settings", () => {
const plan = planAutoSettleSettingsSync(reference, [
{ ...reference, label: "Reference" },
{ environmentId: EnvironmentId.make("loading"), label: "Loading", settings: null },
]);

expect(plan.mismatches).toEqual([]);
});
});
31 changes: 31 additions & 0 deletions apps/mobile/src/features/settings/autoSettleSettingsSync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { EnvironmentId, ServerSettings } from "@t3tools/contracts";

export type AutoSettleSettings = Pick<
ServerSettings,
"sidebarAutoSettleAfterDays" | "sidebarAutoSettleOnMerge"
>;

interface AutoSettleSyncTarget {
readonly environmentId: EnvironmentId;
readonly label: string;
readonly settings: AutoSettleSettings | null;
}

/** Receives connected, capable targets. Applying these defaults must preserve other settings. */
export function planAutoSettleSettingsSync(
reference: { readonly environmentId: EnvironmentId; readonly settings: AutoSettleSettings },
targets: readonly AutoSettleSyncTarget[],
) {
const patch: AutoSettleSettings = {
sidebarAutoSettleAfterDays: reference.settings.sidebarAutoSettleAfterDays,
sidebarAutoSettleOnMerge: reference.settings.sidebarAutoSettleOnMerge,
};
const mismatches = targets.filter(
(target) =>
target.environmentId !== reference.environmentId &&
target.settings !== null &&
(target.settings.sidebarAutoSettleAfterDays !== patch.sidebarAutoSettleAfterDays ||
target.settings.sidebarAutoSettleOnMerge !== patch.sidebarAutoSettleOnMerge),
);
return { patch, mismatches };
}
8 changes: 3 additions & 5 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ import {
environmentServerConfigsAtom,
primaryServerAvailableEditorsAtom,
primaryServerKeybindingsAtom,
primaryServerSettingsAtom,
serverEnvironment,
} from "../state/server";
import { terminalEnvironment } from "../state/terminal";
Expand Down Expand Up @@ -1506,7 +1505,6 @@ export default function ChatView(props: ChatViewProps) {
}, [routeKind, routeThreadRef, routeThreadState]);
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
const settings = useEnvironmentSettings(environmentId);
const primaryServerSettings = useAtomValue(primaryServerSettingsAtom);
const setStickyComposerModelSelection = useComposerDraftStore(
(store) => store.setStickyModelSelection,
);
Expand Down Expand Up @@ -5341,7 +5339,7 @@ export default function ChatView(props: ChatViewProps) {
? (draftThread?.startFromOrigin ?? false)
: canOverrideServerThreadEnvMode
? (pendingServerThreadStartFromOriginByThreadId[activeThread?.id ?? ""] ??
primaryServerSettings.newWorktreesStartFromOrigin)
settings.newWorktreesStartFromOrigin)
: false;
const sendEnvMode = resolveSendEnvMode({
requestedEnvMode: envMode,
Expand Down Expand Up @@ -7920,7 +7918,7 @@ export default function ChatView(props: ChatViewProps) {
envMode: mode,
startFromOrigin: resolveNewDraftStartFromOrigin({
envMode: mode,
newWorktreesStartFromOrigin: primaryServerSettings.newWorktreesStartFromOrigin,
newWorktreesStartFromOrigin: settings.newWorktreesStartFromOrigin,
}),
...(mode === "worktree" && draftThread?.worktreePath ? { worktreePath: null } : {}),
});
Expand All @@ -7932,7 +7930,7 @@ export default function ChatView(props: ChatViewProps) {
composerDraftTarget,
draftThread?.worktreePath,
isLocalDraftThread,
primaryServerSettings.newWorktreesStartFromOrigin,
settings.newWorktreesStartFromOrigin,
setPendingServerThreadEnvMode,
scheduleComposerFocus,
setDraftThreadContext,
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1814,8 +1814,7 @@ function OpenCommandPaletteDialog(props: {
},
});

// There is no projects listing page; the action targets the contextual
// project (active thread/draft, falling back to the first sidebar group).
// Target the active thread or draft's project, falling back to the first sidebar group.
const contextualProjectGroup =
(contextualProjectRef
? projectGroupByTargetKey.get(
Expand Down Expand Up @@ -1867,8 +1866,6 @@ function OpenCommandPaletteDialog(props: {
run: async () => {
await navigate({
to: item.to,
search: (previous) =>
item.to === "/settings/projects" ? { ...previous, project: undefined } : previous,
hash: item.targetId ?? item.id,
replace: pathname === item.to,
hashScrollIntoView: false,
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/settings/ConnectionsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,10 @@ export function ConnectionsSettings() {
<SettingsPageContainer>
{canManageLocalBackend ? (
<>
<SettingsSection {...searchableSetting("connections-environment")}>
<SettingsSection
{...searchableSetting("connections-environment")}
title={primaryEnvironment?.label ?? "Primary environment"}
>
{primaryVersionMismatch || primaryServerUpdateState.status !== "idle" ? (
<SettingsRow
title={
Expand Down
Loading
Loading