Skip to content

Commit 706d940

Browse files
committed
chore: merge main to include the upstream CI fix
2 parents b1bb899 + 18f7254 commit 706d940

122 files changed

Lines changed: 8332 additions & 2945 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.

‎apps/mobile/src/features/settings/SettingsRouteScreen.tsx‎

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ import {
4141
DEFAULT_SERVER_SETTINGS,
4242
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
4343
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
44-
type ServerSettingsPatch,
4544
} from "@t3tools/contracts";
46-
import {
47-
filterSharedServerPatch,
48-
findSharedSettingsMismatches,
49-
pickSharedServerSettings,
50-
supportsSharedSettingsSync,
51-
} from "@t3tools/client-runtime/state/shared-settings";
45+
import { supportsSharedSettingsSync } from "@t3tools/client-runtime/state/shared-settings";
5246
import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
5347
import {
5448
type AppUpdateCheckState,
@@ -61,6 +55,7 @@ import { SettingsRow } from "./components/SettingsRow";
6155
import { SettingsSection } from "./components/SettingsSection";
6256
import { SettingsSwitchRow } from "./components/SettingsSwitchRow";
6357
import { resolveAgentAwarenessPlatformPresentation } from "./SettingsRouteScreen.logic";
58+
import { planAutoSettleSettingsSync, type AutoSettleSettings } from "./autoSettleSettingsSync";
6459

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

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

613-
const writeToAll = (patch: ServerSettingsPatch) => {
607+
const writeToAll = (patch: Partial<AutoSettleSettings>) => {
614608
for (const environment of syncTargets) {
615609
void updateSettings({ environmentId: environment.environmentId, input: { patch } });
616610
}
617611
};
618612

619-
const mismatches = findSharedSettingsMismatches({
620-
primaryEnvironmentId: reference.environmentId,
621-
primarySettings: referenceSettings,
622-
primaryCapabilities: reference.serverConfig?.environment.capabilities,
623-
environments: environments.map((environment) => ({
613+
const { patch: autoSettlePatch, mismatches } = planAutoSettleSettingsSync(
614+
{ environmentId: reference.environmentId, settings: referenceSettings },
615+
syncTargets.map((environment) => ({
624616
environmentId: environment.environmentId,
625617
label: environment.label,
626-
syncEligible: supportsSharedSettingsSync(environment),
627618
settings: environment.serverConfig?.settings ?? null,
628-
capabilities: environment.serverConfig?.environment.capabilities,
629619
})),
630-
});
620+
);
631621

632622
const afterDays = referenceSettings.sidebarAutoSettleAfterDays;
633623
const commitDays = () => {
@@ -681,38 +671,26 @@ function AutoSettleSettingsRows() {
681671
{mismatches.length > 0 ? (
682672
<View className="flex-row items-center gap-4 border-t border-border-subtle p-4">
683673
<View className="min-w-0 flex-1">
684-
<Text className="text-lg text-foreground">Settings differ</Text>
674+
<Text className="text-lg text-foreground">Auto-settle defaults differ</Text>
685675
<Text className="text-sm text-foreground-muted">
686676
{mismatches.map((mismatch) => mismatch.label).join(", ")}
687677
</Text>
688678
</View>
689679
<Pressable
690680
accessibilityRole="button"
691681
onPress={() => {
692-
const patch = pickSharedServerSettings(
693-
referenceSettings,
694-
reference.serverConfig?.environment.capabilities,
695-
);
696682
for (const mismatch of mismatches) {
697-
const target = environments.find(
698-
(candidate) => candidate.environmentId === mismatch.environmentId,
699-
);
700683
void updateSettings({
701684
environmentId: mismatch.environmentId,
702-
input: {
703-
patch: filterSharedServerPatch(
704-
patch,
705-
target?.serverConfig?.environment.capabilities,
706-
target?.serverConfig?.settings,
707-
referenceSettings,
708-
),
709-
},
685+
input: { patch: autoSettlePatch },
710686
});
711687
}
712688
}}
713689
className="rounded-full bg-subtle px-4 py-2 active:opacity-70"
714690
>
715-
<Text className="text-base font-t3-medium text-foreground">Apply to all</Text>
691+
<Text className="text-base font-t3-medium text-foreground">
692+
Apply auto-settle defaults
693+
</Text>
716694
</Pressable>
717695
</View>
718696
) : null}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { planAutoSettleSettingsSync } from "./autoSettleSettingsSync";
5+
6+
const reference = {
7+
environmentId: EnvironmentId.make("reference"),
8+
settings: {
9+
...DEFAULT_SERVER_SETTINGS,
10+
sidebarAutoSettleAfterDays: 7,
11+
sidebarAutoSettleOnMerge: true,
12+
newWorktreesStartFromOrigin: false,
13+
continueThreadsAfterServerUpdate: false,
14+
},
15+
};
16+
17+
describe("auto-settle settings sync", () => {
18+
it("ignores differences in independently configured environment settings", () => {
19+
const target = {
20+
environmentId: EnvironmentId.make("remote"),
21+
label: "Remote",
22+
settings: {
23+
...reference.settings,
24+
newWorktreesStartFromOrigin: true,
25+
continueThreadsAfterServerUpdate: true,
26+
sourceControlWritingStyle: {
27+
...reference.settings.sourceControlWritingStyle,
28+
customInstructions: "Keep this environment's writing instructions.",
29+
},
30+
},
31+
};
32+
33+
const plan = planAutoSettleSettingsSync(reference, [target]);
34+
35+
expect(plan.mismatches).toEqual([]);
36+
expect(plan.patch).toEqual({
37+
sidebarAutoSettleAfterDays: 7,
38+
sidebarAutoSettleOnMerge: true,
39+
});
40+
});
41+
42+
it("applies only auto-settle defaults when another environment differs", () => {
43+
const target = {
44+
environmentId: EnvironmentId.make("remote"),
45+
label: "Remote",
46+
settings: {
47+
...reference.settings,
48+
sidebarAutoSettleAfterDays: null,
49+
sidebarAutoSettleOnMerge: false,
50+
newWorktreesStartFromOrigin: true,
51+
continueThreadsAfterServerUpdate: true,
52+
sourceControlWritingStyle: {
53+
...reference.settings.sourceControlWritingStyle,
54+
customInstructions: "Preserve these instructions.",
55+
},
56+
},
57+
};
58+
59+
const plan = planAutoSettleSettingsSync(reference, [target]);
60+
const updated = { ...target.settings, ...plan.patch };
61+
62+
expect(plan.mismatches).toEqual([target]);
63+
expect(updated.sidebarAutoSettleAfterDays).toBe(7);
64+
expect(updated.sidebarAutoSettleOnMerge).toBe(true);
65+
expect(updated.newWorktreesStartFromOrigin).toBe(true);
66+
expect(updated.continueThreadsAfterServerUpdate).toBe(true);
67+
expect(updated.sourceControlWritingStyle).toEqual(target.settings.sourceControlWritingStyle);
68+
});
69+
70+
it("does not compare the reference or a target without loaded settings", () => {
71+
const plan = planAutoSettleSettingsSync(reference, [
72+
{ ...reference, label: "Reference" },
73+
{ environmentId: EnvironmentId.make("loading"), label: "Loading", settings: null },
74+
]);
75+
76+
expect(plan.mismatches).toEqual([]);
77+
});
78+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { EnvironmentId, ServerSettings } from "@t3tools/contracts";
2+
3+
export type AutoSettleSettings = Pick<
4+
ServerSettings,
5+
"sidebarAutoSettleAfterDays" | "sidebarAutoSettleOnMerge"
6+
>;
7+
8+
interface AutoSettleSyncTarget {
9+
readonly environmentId: EnvironmentId;
10+
readonly label: string;
11+
readonly settings: AutoSettleSettings | null;
12+
}
13+
14+
/** Receives connected, capable targets. Applying these defaults must preserve other settings. */
15+
export function planAutoSettleSettingsSync(
16+
reference: { readonly environmentId: EnvironmentId; readonly settings: AutoSettleSettings },
17+
targets: readonly AutoSettleSyncTarget[],
18+
) {
19+
const patch: AutoSettleSettings = {
20+
sidebarAutoSettleAfterDays: reference.settings.sidebarAutoSettleAfterDays,
21+
sidebarAutoSettleOnMerge: reference.settings.sidebarAutoSettleOnMerge,
22+
};
23+
const mismatches = targets.filter(
24+
(target) =>
25+
target.environmentId !== reference.environmentId &&
26+
target.settings !== null &&
27+
(target.settings.sidebarAutoSettleAfterDays !== patch.sidebarAutoSettleAfterDays ||
28+
target.settings.sidebarAutoSettleOnMerge !== patch.sidebarAutoSettleOnMerge),
29+
);
30+
return { patch, mismatches };
31+
}

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import {
1313
CommandId,
1414
DEFAULT_PROVIDER_INTERACTION_MODE,
1515
DEFAULT_RUNTIME_MODE,
16+
DEFAULT_SERVER_SETTINGS,
1617
MessageId,
1718
T3_PROJECT_FILE_NAME,
1819
ThreadId,
1920
} from "@t3tools/contracts";
21+
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
2022
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
2123
import {
2224
isDefaultThreadEnvModeSettled,
@@ -428,17 +430,32 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
428430
if (t3ProjectFileData === null || t3ProjectFileData.truncated) return null;
429431
return parseT3ProjectFile(t3ProjectFileData.contents)?.defaultThreadEnvMode ?? null;
430432
}, [t3ProjectFileData]);
433+
// Environment settings with the project's overrides applied; the
434+
// aggregate's own legacy fields still count until the server folds them.
435+
const projectSettings = useMemo(
436+
() =>
437+
resolveProjectSettings(
438+
selectedEnvironmentServerConfig?.settings ?? DEFAULT_SERVER_SETTINGS,
439+
selectedProject?.id ?? null,
440+
selectedProject,
441+
),
442+
[selectedEnvironmentServerConfig?.settings, selectedProject],
443+
);
444+
const projectThreadEnvMode =
445+
projectSettings.sources.defaultThreadEnvMode === "project"
446+
? projectSettings.settings.defaultThreadEnvMode
447+
: undefined;
431448
const defaultWorkspaceMode: WorkspaceMode = resolveDefaultThreadEnvMode({
432-
projectSetting: selectedProject?.defaultThreadEnvMode,
449+
projectSetting: projectThreadEnvMode,
433450
projectFile: t3ProjectFileDefaultMode,
434-
globalDefault: selectedEnvironmentServerConfig?.settings.defaultThreadEnvMode ?? "local",
451+
globalDefault: projectSettings.settings.defaultThreadEnvMode,
435452
});
436453
// While unsettled the resolved default is provisional. Nothing may write
437454
// it into the draft during that window (the auto-branch effect does), or
438455
// the frozen interim value beats the t3.json default once it loads.
439456
const defaultWorkspaceModeSettled = isDefaultThreadEnvModeSettled({
440457
explicitMode: selectedProjectDraft.workspaceSelection?.mode,
441-
projectSetting: selectedProject?.defaultThreadEnvMode,
458+
projectSetting: projectThreadEnvMode,
442459
projectFilePending: t3ProjectFileQuery.isPending,
443460
});
444461
const workspaceMode = selectedProjectDraft.workspaceSelection?.mode ?? defaultWorkspaceMode;
@@ -449,9 +466,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
449466
// value keeps tracking the server setting when the config loads late.
450467
const draftStartFromOrigin = selectedProjectDraft.workspaceSelection?.startFromOrigin;
451468
const startFromOrigin =
452-
draftStartFromOrigin ??
453-
selectedEnvironmentServerConfig?.settings.newWorktreesStartFromOrigin ??
454-
true;
469+
draftStartFromOrigin ?? projectSettings.settings.newWorktreesStartFromOrigin;
455470
const runtimeMode = selectedProjectDraft.runtimeMode ?? DEFAULT_RUNTIME_MODE;
456471

457472
// Antigravity keeps unavailable selections so sign-out or a catalog change
@@ -463,9 +478,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
463478
);
464479
const projectDefaultModelSelection = resolveDefaultableModelSelection(
465480
selectedEnvironmentServerConfig,
466-
selectedProject?.defaultModelSelection ??
467-
selectedEnvironmentServerConfig?.settings.defaultModelSelection ??
468-
null,
481+
projectSettings.settings.defaultModelSelection,
469482
);
470483
const storedStickyModelSelection = useStickyComposerModelSelection();
471484
const stickyModelSelection = resolveDefaultableModelSelection(

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export const make = Effect.gen(function* () {
222222
threadSettlement: true,
223223
threadAutoSettlement: true,
224224
threadRestartContinuation: true,
225+
projectSettingsOverrides: true,
225226
threadSnooze: true,
226227
environmentThemes: true,
227228
usageLimitSources: true,

‎apps/server/src/git/GitManager.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ import {
2929
type VcsStatusRemoteResult,
3030
VcsStatusResult,
3131
ModelSelection,
32+
type ProjectId,
3233
SourceControlProviderError,
3334
type SourceControlWritingStyleSettings,
35+
type ThreadId,
3436
} from "@t3tools/contracts";
37+
import {
38+
hasProjectSettingsOverrides,
39+
resolveProjectSettings,
40+
} from "@t3tools/shared/projectSettings";
41+
import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
3542
import {
3643
detectSourceControlProviderFromGitRemoteUrl,
3744
mergeGitStatusParts,
@@ -661,6 +668,28 @@ export const make = Effect.gen(function* () {
661668

662669
const sourceControlProvider = (cwd: string) => sourceControlProviders.resolve({ cwd });
663670
const serverSettingsService = yield* ServerSettings.ServerSettingsService;
671+
// Optional: git actions also run from the CLI and tests without orchestration.
672+
const projectionQuery = yield* Effect.serviceOption(
673+
ProjectionSnapshotQuery.ProjectionSnapshotQuery,
674+
);
675+
/** Environment settings with the acting project's overrides applied. */
676+
const projectSettingsFor = Effect.fnUntraced(function* (input: {
677+
readonly cwd: string;
678+
readonly threadId?: ThreadId | undefined;
679+
}) {
680+
const settings = yield* serverSettingsService.getSettings;
681+
if (!hasProjectSettingsOverrides(settings) || Option.isNone(projectionQuery)) return settings;
682+
const projectId = yield* (
683+
input.threadId !== undefined
684+
? projectionQuery.value
685+
.getThreadShellById(input.threadId)
686+
.pipe(Effect.map(Option.map((thread) => thread.projectId)))
687+
: projectionQuery.value
688+
.getActiveProjectByWorkspaceRoot(input.cwd)
689+
.pipe(Effect.map(Option.map((project) => project.id)))
690+
).pipe(Effect.orElseSucceed(() => Option.none<ProjectId>()));
691+
return resolveProjectSettings(settings, Option.getOrNull(projectId)).settings;
692+
});
664693
const readRepositoryInstructions = (cwd: string, fileName: string) =>
665694
Effect.gen(function* () {
666695
const root = yield* fileSystem.realPath(cwd);
@@ -2600,7 +2629,7 @@ export const make = Effect.gen(function* () {
26002629
let commitMessageForStep = input.commitMessage;
26012630
let preResolvedCommitSuggestion: CommitAndBranchSuggestion | undefined = undefined;
26022631

2603-
const textGenerationSettings = yield* serverSettingsService.getSettings.pipe(
2632+
const textGenerationSettings = yield* projectSettingsFor(input).pipe(
26042633
Effect.flatMap((settings) =>
26052634
settings.sourceControlWriterModelSelection === null
26062635
? Effect.succeed({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
682682
if (context._tag === "Some") {
683683
assert.deepEqual(context.value, {
684684
id: ThreadId.make("thread-1"),
685+
projectId: asProjectId("project-1"),
685686
title: "Thread 1",
686687
session: snapshot.threads[0]?.session,
687688
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ const ProjectionThreadActivityIdRowSchema = Schema.Struct({
142142
const ProjectionThreadSessionDbRowSchema = ProjectionThreadSession;
143143
const ProjectionThreadRuntimeContextDbRowSchema = Schema.Struct({
144144
id: ThreadId,
145+
projectId: ProjectId,
145146
title: Schema.String,
146147
session: Schema.NullOr(ProjectionThreadSessionDbRowSchema),
147148
});
@@ -1231,6 +1232,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
12311232
sql`
12321233
SELECT
12331234
threads.thread_id AS id,
1235+
threads.project_id AS "projectId",
12341236
threads.title,
12351237
sessions.thread_id AS "threadId",
12361238
sessions.status,
@@ -1251,6 +1253,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
12511253
Effect.map((rows) =>
12521254
rows.map((row) => ({
12531255
id: row.id,
1256+
projectId: row.projectId,
12541257
title: row.title,
12551258
session: row.threadId === null ? null : row,
12561259
})),
@@ -3164,6 +3167,7 @@ pending_approval_requests AS (
31643167
);
31653168
return Option.map(context, (row) => ({
31663169
id: row.id,
3170+
projectId: row.projectId,
31673171
title: row.title,
31683172
session: row.session === null ? null : mapSessionRow(row.session),
31693173
}));

0 commit comments

Comments
 (0)