|
6 | 6 | type AuthEnvironmentScope, |
7 | 7 | } from "./auth.ts"; |
8 | 8 | import * as Effect from "effect/Effect"; |
| 9 | +import * as Option from "effect/Option"; |
9 | 10 | import * as Duration from "effect/Duration"; |
10 | 11 | import * as Schema from "effect/Schema"; |
11 | 12 | import * as SchemaTransformation from "effect/SchemaTransformation"; |
@@ -643,6 +644,16 @@ export type CodexSettings = typeof CodexSettings.Type; |
643 | 644 |
|
644 | 645 | const CLAUDE_AUTO_COMPACT_WINDOW_PATTERN = /^(?:|[1-9]\d{5}|1000000)$/; |
645 | 646 |
|
| 647 | +const CLAUDE_IDLE_COMPACTION_MODES = [ |
| 648 | + { value: "onReturn", label: "When you return" }, |
| 649 | + { value: "beforeCacheExpires", label: "Before the cache expires (beta)" }, |
| 650 | + { value: "off", label: "Never" }, |
| 651 | +] as const; |
| 652 | +const ClaudeIdleCompaction = Schema.Literals( |
| 653 | + CLAUDE_IDLE_COMPACTION_MODES.map((mode) => mode.value), |
| 654 | +); |
| 655 | +export type ClaudeIdleCompaction = typeof ClaudeIdleCompaction.Type; |
| 656 | + |
646 | 657 | export const ClaudeSettings = makeProviderSettingsSchema( |
647 | 658 | { |
648 | 659 | enabled: Schema.Boolean.pipe( |
@@ -694,9 +705,22 @@ export const ClaudeSettings = makeProviderSettingsSchema( |
694 | 705 | }, |
695 | 706 | }), |
696 | 707 | ), |
| 708 | + idleCompaction: ClaudeIdleCompaction.pipe( |
| 709 | + Schema.withDecodingDefault(Effect.succeed("onReturn" as const)), |
| 710 | + Schema.annotateKey({ |
| 711 | + title: "Compact idle threads", |
| 712 | + description: |
| 713 | + "When to compact a thread over 200,000 tokens whose prompt cache expired while you were away.", |
| 714 | + providerSettingsForm: { |
| 715 | + control: "select", |
| 716 | + options: CLAUDE_IDLE_COMPACTION_MODES, |
| 717 | + clearWhenEmpty: "omit", |
| 718 | + }, |
| 719 | + }), |
| 720 | + ), |
697 | 721 | }, |
698 | 722 | { |
699 | | - order: ["binaryPath", "homePath", "autoCompactWindow", "launchArgs"], |
| 723 | + order: ["binaryPath", "homePath", "autoCompactWindow", "idleCompaction", "launchArgs"], |
700 | 724 | }, |
701 | 725 | ); |
702 | 726 | export type ClaudeSettings = typeof ClaudeSettings.Type; |
@@ -1160,7 +1184,6 @@ export const ServerSettings = Schema.Struct({ |
1160 | 1184 | sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe( |
1161 | 1185 | Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)), |
1162 | 1186 | ), |
1163 | | - compactIdleThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), |
1164 | 1187 | snoozeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), |
1165 | 1188 | autoResumeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), |
1166 | 1189 | sidebarAutoSettleKeepPullRequests: Schema.Boolean.pipe( |
@@ -1334,6 +1357,20 @@ export const resolveProjectProviderInstanceEnabled = ( |
1334 | 1357 | : isUnconfiguredDefaultInstanceEnabled(instanceId); |
1335 | 1358 | }; |
1336 | 1359 |
|
| 1360 | +const decodeClaudeSettings = Schema.decodeUnknownOption(ClaudeSettings); |
| 1361 | + |
| 1362 | +export const resolveClaudeIdleCompaction = ( |
| 1363 | + settings: Pick<ServerSettings, "providerInstances">, |
| 1364 | + instanceId: ProviderInstanceId, |
| 1365 | +): ClaudeIdleCompaction => { |
| 1366 | + const instance = Object.hasOwn(settings.providerInstances, instanceId) |
| 1367 | + ? settings.providerInstances[instanceId] |
| 1368 | + : undefined; |
| 1369 | + return decodeClaudeSettings(instance?.config ?? {}).pipe( |
| 1370 | + Option.match({ onNone: () => "onReturn" as const, onSome: (config) => config.idleCompaction }), |
| 1371 | + ); |
| 1372 | +}; |
| 1373 | + |
1337 | 1374 | export const ServerSettingsOperation = Schema.Literals([ |
1338 | 1375 | "normalize", |
1339 | 1376 | "check-exists", |
@@ -1475,7 +1512,6 @@ export const ServerSettingsPatch = Schema.Struct({ |
1475 | 1512 | deviceHosts: Schema.optionalKey(SshDeviceHostConfigs), |
1476 | 1513 | easDeviceHosts: Schema.optionalKey(EasDeviceHostConfigs), |
1477 | 1514 | sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)), |
1478 | | - compactIdleThreads: Schema.optionalKey(Schema.Boolean), |
1479 | 1515 | sidebarAutoSettleKeepPullRequests: Schema.optionalKey(Schema.Boolean), |
1480 | 1516 | sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean), |
1481 | 1517 | autoResumeLimitedThreads: Schema.optionalKey(Schema.Boolean), |
|
0 commit comments