The best way to control Claude Code, Codex and more from any computer or phone
fix(contracts): accept legacy writing styles when reading settings (#21665)
Julius Marminge committed
Oct 19, 2026 at 16:28 UTC
f1d0f2ad8ac75ac056f98457eea732a95d255ccd
2 files changed
+80
-12
packages/contracts/src/settings.test.ts
+49
-9
@@ -915,6 +915,30 @@ describe("ServerSettings worktree defaults", () => {
915
});
916
917
describe("ServerSettings.sourceControlWritingStyle", () => {
918
+ it.each([
919
+ { legacy: "", mode: "repo_conventions", customInstructions: "" },
920
+ { legacy: " \t\n ", mode: "repo_conventions", customInstructions: "" },
921
+ {
922
+ legacy: " Prefer concise wording.\nKeep issue references. ",
923
+ mode: "custom",
924
+ customInstructions: "Prefer concise wording.\nKeep issue references.",
925
+ },
926
+ ])("normalizes legacy writing style $legacy in snapshots only", ({ legacy, ...expected }) => {
927
+ const style = { ...expected, followChangeRequestTemplates: true };
928
+ for (const [input, normalized] of [
929
+ [{ sourceControlWritingStyle: legacy }, { sourceControlWritingStyle: style }],
930
+ [
931
+ { projectSettingsOverrides: { project: { sourceControlWritingStyle: legacy } } },
932
+ { projectSettingsOverrides: { project: { sourceControlWritingStyle: style } } },
933
+ ],
934
+ ] as const) {
935
+ const settings = decodeServerSettings(input);
936
+ expect(settings).toMatchObject(normalized);
937
+ expect(encodeServerSettings(settings)).toMatchObject(normalized);
938
+ expect(() => decodeServerSettingsPatch(input)).toThrow();
939
+ }
940
+ });
941
+
942
it("defaults all style settings for legacy configs", () => {
943
const settings = decodeServerSettings({});
944
@@ -926,17 +950,33 @@ describe("ServerSettings.sourceControlWritingStyle", () => {
950
expect(settings.sourceControlWriterModelSelection).toBeNull();
951
});
952
929
- it("trims partial style updates", () => {
930
- const patch = decodeServerSettingsPatch({
931
- sourceControlWritingStyle: {
932
- mode: "custom",
933
- customInstructions: " Prefer concise wording. ",
934
- },
935
- });
936
-
937
- expect(patch.sourceControlWritingStyle).toEqual({
953
+ it("preserves structured encoding and trims partial style updates", () => {
954
+ const style = {
955
mode: "custom",
956
customInstructions: "Prefer concise wording.",
957
+ followChangeRequestTemplates: false,
958
+ };
959
+ const input = {
960
+ sourceControlWritingStyle: style,
961
+ projectSettingsOverrides: { project: { sourceControlWritingStyle: style } },
962
+ };
963
+ expect(encodeServerSettings(decodeServerSettings(input))).toMatchObject(input);
964
+ expect(decodeServerSettingsPatch(input)).toEqual(input);
965
+
966
+ const partial = { mode: "custom", customInstructions: " Prefer concise wording. " };
967
+ const normalized = { mode: "custom", customInstructions: "Prefer concise wording." };
968
+ expect(
969
+ decodeServerSettingsPatch({
970
+ sourceControlWritingStyle: partial,
971
+ projectSettingsOverrides: { project: { sourceControlWritingStyle: partial } },
972
+ }),
973
+ ).toEqual({
974
+ sourceControlWritingStyle: normalized,
975
+ projectSettingsOverrides: {
976
+ project: {
977
+ sourceControlWritingStyle: { ...normalized, followChangeRequestTemplates: true },
978
+ },
979
+ },
980
});
981
});
982
});
packages/contracts/src/settings.ts
+31
-3
@@ -816,6 +816,26 @@ export const SourceControlWritingStyleSettings = Schema.Struct({
816
});
817
export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
818
819
+const SourceControlWritingStyleSetting = Schema.Union([
820
+ TrimmedString,
821
+ SourceControlWritingStyleSettings,
822
+]).pipe(
823
+ Schema.decodeTo(
824
+ Schema.toType(SourceControlWritingStyleSettings),
825
+ SchemaTransformation.transform({
826
+ decode: (value) =>
827
+ typeof value === "string"
828
+ ? {
829
+ mode: value.length > 0 ? ("custom" as const) : ("repo_conventions" as const),
830
+ customInstructions: value,
831
+ followChangeRequestTemplates: true,
832
+ }
833
+ : value,
834
+ encode: (value) => value,
835
+ }),
836
+ ),
837
+);
838
+
839
export const BranchNamingMode = Schema.Literals(["static", "semantic", "custom"]);
840
export type BranchNamingMode = typeof BranchNamingMode.Type;
841
@@ -964,7 +984,7 @@ export const ProjectSettingsOverrides = Schema.Struct({
984
sourceControlWriterModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
985
reviewGuideModelSelection: Schema.optionalKey(Schema.NullOr(ModelSelection)),
986
reviewGuideInstructions: Schema.optionalKey(TrimmedString),
967
- sourceControlWritingStyle: Schema.optionalKey(SourceControlWritingStyleSettings),
987
+ sourceControlWritingStyle: Schema.optionalKey(SourceControlWritingStyleSetting),
988
removeAgentCreditsOnMerge: Schema.optionalKey(Schema.Boolean),
989
branchNamingMode: Schema.optionalKey(BranchNamingMode),
990
branchNamePrefix: Schema.optionalKey(TrimmedString),
@@ -1204,7 +1224,7 @@ export const ServerSettings = Schema.Struct({
1224
branchNamePrefix: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed("t3"))),
1225
branchNameInstructions: TrimmedString.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
1226
removeAgentCreditsOnMerge: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
1207
- sourceControlWritingStyle: SourceControlWritingStyleSettings.pipe(
1227
+ sourceControlWritingStyle: SourceControlWritingStyleSetting.pipe(
1228
Schema.withDecodingDefault(Effect.succeed({})),
1229
),
1230
sourceControlWriterModelSelection: Schema.NullOr(ModelSelection).pipe(
@@ -1432,7 +1452,15 @@ export const ServerSettingsPatch = Schema.Struct({
1452
* field existed cannot wipe it by editing another key.
1453
*/
1454
projectSettingsOverrides: Schema.optionalKey(
1435
- Schema.Record(ProjectId, Schema.NullOr(ProjectSettingsOverrides)),
1455
+ Schema.Record(
1456
+ ProjectId,
1457
+ Schema.NullOr(
1458
+ Schema.Struct({
1459
+ ...ProjectSettingsOverrides.fields,
1460
+ sourceControlWritingStyle: Schema.optionalKey(SourceControlWritingStyleSettings),
1461
+ }),
1462
+ ),
1463
+ ),
1464
),
1465
enableAgentDeviceAccess: Schema.optionalKey(Schema.Boolean),
1466
enableDeviceSupport: Schema.optionalKey(Schema.Boolean),