feat(settings): resolve t3.json inside the project settings resolver #12954
Mergedjuliusmarmingemerged 9 commits into
worktree-submodules/t3json fromrefs/pull/12954/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/contracts/src/settings.ts line 1183OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1176,5 +1176,8 @@11761176 environmentIcon: ForwardCompatibleNullable(EnvironmentMachineKind).pipe(11771177 Schema.withDecodingDefault(Effect.succeed(null)),11781178 ),1179- defaultThreadEnvMode: ThreadEnvMode.pipe(1180- Schema.withDecodingDefault(Effect.succeed("local" as const satisfies ThreadEnvMode)),1179+ /**1180+ * Null defers to the repository's t3.json, then to "local". Older servers1181+ * always wrote a value, so a stored one keeps winning over the file.1182+ */1183+ defaultThreadEnvMode: ForwardCompatibleNullable(ThreadEnvMode).pipe(apps/web/src/components/settings/ProjectDefaultsSettings.tsx line 302OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -302,16 +294,9 @@302- settings.defaultThreadEnvMode !== DEFAULT_SERVER_SETTINGS.defaultThreadEnvMode ? (303- <SettingResetButton304- label="default workspace"305- onClick={() =>306- updateSettings({307- defaultThreadEnvMode: DEFAULT_SERVER_SETTINGS.defaultThreadEnvMode,308- })309- }310- />311- ) : null294+ ? "Where new threads in this project start. Inherit follows the environment, then the repository's t3.json."295+ : "Where new threads start. Inherit follows the repository's t3.json, or the current checkout."312296 }297+ status={inheritedEnvModeLabel ? `Resolves to: ${inheritedEnvModeLabel}` : undefined}313298 control={314299 <Select315- value={mixedWorkspace ? null : settings.defaultThreadEnvMode}300+ value={mixedWorkspace ? null : (settings.defaultThreadEnvMode ?? "inherit")}316301 onValueChange={(value) => {317- if (value === "local" || value === "worktree")302+ if (value === "inherit") updateSettings({ defaultThreadEnvMode: null });
- apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx line 60OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -50,7 +50,11 @@5050 };51515252 const WORKSPACE_CHOICES: ReadonlyArray<{53- readonly mode: ThreadEnvMode;53+ readonly mode: ThreadEnvMode | null;5454 readonly label: string;5555 readonly description: string;5656 }> = [57+ {58+ mode: null,59+ label: "Inherit",60+ description: "Follow the repository's t3.json, or the current checkout.",
- apps/web/src/components/settings/scopedSettings.ts lines 255 to 258Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -234,3 +235,10 @@234235 };235236 continue;236237 }238+ // A picker's "Inherit" sends null; for keys whose override239+ // cannot store null that means remove the override.240+ if (241+ value === null &&242+ !isNullableProjectSettingsOverride(key as ProjectScopedServerSettingKey)243+ ) {244+ delete next[key];
juliusmarminge changed the title
- packages/shared/src/projectSettings.ts lines 111 to 114OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -65,0 +94,21 @@94+): ResolvedProjectSettings {95+ const resolved = resolveProjectOverrides(settings, projectId, project);96+ return projectFile === undefined ? resolved : applyProjectFile(resolved, projectFile);97+}98+99+function applyProjectFile(100+ resolved: ResolvedProjectSettings,101+ projectFile: T3ProjectFile | null,102+): ResolvedProjectSettings {103+ let effective: Record<string, unknown> | null = null;104+ let sources: Record<ProjectScopedServerSettingKey, ProjectSettingSource> | null = null;105+ for (const [key, { field, builtIn }] of Object.entries(PROJECT_FILE_BACKED_SETTINGS)) {106+ const settingKey = key as ProjectScopedServerSettingKey;107+ if (resolved.settings[settingKey] !== null) continue;108+ const fromFile = projectFile?.[field];109+ effective ??= { ...resolved.settings };110+ effective[settingKey] = fromFile ?? builtIn;111+ if (fromFile !== undefined) {112+ sources ??= { ...resolved.sources };113+ sources[settingKey] = "t3.json";114+ }
- packages/shared/src/projectSettings.ts lines 151 to 153Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -87,3 +146,6 @@87146 for (const key of PROJECT_SCOPED_SERVER_SETTING_KEYS) {88147 if (!Object.hasOwn(overrides, key)) continue;89148 const value = overrides[key];149+ // A forward-compatible decode leaves an unknown value as a present150+ // undefined; that is not an override.151+ if (value === undefined) continue;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/web/src/components/settings/SettingsScopeContext.tsx line 27Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2,6 +7,21 @@2738 import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments";9+import { getProjectFileQueryAtom } from "../files/projectFilesQueryState";410 import { useSettingsProjectGroups } from "./useSettingsProjectGroups";511 import { resolveScopedSettingsTargets, selectScopedSettingsEnvironments } from "./scopedSettings";612 import { resolveSettingsScope, type SettingsScopeSearch } from "./settingsScope";71314+/**15+ * Each member's decoded t3.json, so file-backed settings show the file as a16+ * layer in the inheritance chain. A member is only present once its read has17+ * settled; the query atom caches per (environment, cwd).18+ */19+function useMemberProjectFiles(scope: ReturnType<typeof resolveSettingsScope>) {20+ const members = scope.kind === "project" || scope.kind === "checkout" ? scope.members : [];21+ return useAtomValue(22+ useMemo(23+ () =>24+ Atom.make((get) => {25+ const files = new Map<string, T3ProjectFile | null>();26+ for (const member of members) {27+ const result = get(
juliusmarminge merged this742173a
juliusmarminge closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed