@@ -52,7 +52,6 @@ import {
5252 type CodexRateLimitSnapshot ,
5353 type CodexResetCreditsSummary ,
5454} from "./codexUsageLimits.ts" ;
55- import { CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID } from "../codexModelOptions.ts" ;
5655import * as HostProcess from "@t3tools/shared/HostProcess" ;
5756import packageJson from "../../package.json" with { type : "json" } ;
5857const isCodexAppServerSpawnError = Schema . is ( CodexErrors . CodexAppServerSpawnError ) ;
@@ -94,6 +93,8 @@ export interface CodexAppServerProviderSnapshot {
9493 readonly version : string | undefined ;
9594 readonly models : ReadonlyArray < ServerProviderModel > | undefined ;
9695 readonly serviceTier ?: string | undefined ;
96+ readonly daybreakEnabled ?: boolean | undefined ;
97+ readonly apiKeyCyberAccessProgramsDisabled ?: boolean | undefined ;
9798 readonly skills : ReadonlyArray < ServerProviderSkill > ;
9899}
99100
@@ -249,24 +250,21 @@ export function mapCodexModelCapabilities(
249250 } ) ;
250251 }
251252 const cyberAccessPrograms = model . availableAccessPrograms ?. cyber ?? [ ] ;
252- // Only Daybreak programmes need a choice; standard-only models keep their usual controls.
253- if ( cyberAccessPrograms . some ( ( program ) => program !== "standard" ) ) {
253+ if ( cyberAccessPrograms . length > 0 ) {
254+ // Codex's own clients request Standard unless Daybreak is on; omitting the field does not.
255+ const defaultProgram = cyberAccessPrograms . includes ( "standard" )
256+ ? "standard"
257+ : cyberAccessPrograms [ 0 ] ;
254258 optionDescriptors . push ( {
255259 id : "cyberAccessProgram" ,
256260 label : "Cyber Access" ,
257261 type : "select" ,
258- options : [
259- {
260- id : CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID ,
261- label : "Automatic" ,
262- isDefault : true ,
263- } ,
264- ...cyberAccessPrograms . map ( ( program ) => ( {
265- id : program ,
266- label : CYBER_ACCESS_PROGRAM_LABELS [ program ] ?? program ,
267- } ) ) ,
268- ] ,
269- currentValue : CODEX_AUTOMATIC_CYBER_ACCESS_PROGRAM_ID ,
262+ options : cyberAccessPrograms . map ( ( program ) => ( {
263+ id : program ,
264+ label : CYBER_ACCESS_PROGRAM_LABELS [ program ] ?? program ,
265+ ...( program === defaultProgram ? { isDefault : true } : { } ) ,
266+ } ) ) ,
267+ ...( defaultProgram === undefined ? { } : { currentValue : defaultProgram } ) ,
270268 } ) ;
271269 }
272270
@@ -308,6 +306,58 @@ export function applyPreferredCodexDefaultModel(
308306 } ) ;
309307}
310308
309+ /** Mirrors Codex: `daybreak = true` prefers a Daybreak program, Blue before Red. */
310+ export function applyConfiguredCodexCyberAccess (
311+ models : ReadonlyArray < ServerProviderModel > ,
312+ input : {
313+ readonly daybreakEnabled : boolean ;
314+ readonly apiKeyProgramsDisabled : boolean ;
315+ } ,
316+ ) : ReadonlyArray < ServerProviderModel > {
317+ if ( ! input . daybreakEnabled && ! input . apiKeyProgramsDisabled ) return models ;
318+ return models . map ( ( model ) => {
319+ const descriptors = model . capabilities ?. optionDescriptors ;
320+ if ( ! model . capabilities || ! descriptors ) return model ;
321+ return {
322+ ...model ,
323+ capabilities : {
324+ ...model . capabilities ,
325+ // Codex rejects explicit programs in this session, so none can be offered or sent.
326+ optionDescriptors : ( input . apiKeyProgramsDisabled
327+ ? descriptors . filter ( ( descriptor ) => descriptor . id !== "cyberAccessProgram" )
328+ : descriptors
329+ ) . map ( ( descriptor ) => {
330+ if ( descriptor . id !== "cyberAccessProgram" || descriptor . type !== "select" ) {
331+ return descriptor ;
332+ }
333+ const value = [ "daybreakBlue" , "daybreakRed" ] . find ( ( program ) =>
334+ descriptor . options . some ( ( option ) => option . id === program ) ,
335+ ) ;
336+ if ( ! value ) return descriptor ;
337+ return {
338+ ...descriptor ,
339+ currentValue : value ,
340+ options : descriptor . options . map ( ( { isDefault : _isDefault , ...option } ) =>
341+ option . id === value ? { ...option , isDefault : true } : option ,
342+ ) ,
343+ } ;
344+ } ) ,
345+ } ,
346+ } ;
347+ } ) ;
348+ }
349+
350+ /** Applies when a selection names no program, such as older threads and agent-started turns. */
351+ export function codexDefaultCyberAccessProgram (
352+ models : ReadonlyArray < ServerProviderModel > ,
353+ slug : string ,
354+ ) : string | undefined {
355+ const descriptor = models
356+ . find ( ( model ) => model . slug === slug )
357+ ?. capabilities ?. optionDescriptors ?. find ( ( { id } ) => id === "cyberAccessProgram" ) ;
358+ return descriptor ?. type === "select" ? descriptor . currentValue : undefined ;
359+ }
360+
311361function applyConfiguredCodexServiceTier (
312362 models : ReadonlyArray < ServerProviderModel > ,
313363 serviceTier : string | undefined ,
@@ -585,7 +635,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
585635
586636 // Optional discovery must finish before the outer timeout can discard the account result.
587637 const deadlineMs = spawnedAtMs + CODEX_AUTH_PROBE_TIMEOUT_MS - CODEX_DISCOVERY_MARGIN_MS ;
588- const [ skillsResponse , models , serviceTier , rateLimits ] = yield * Effect . all (
638+ const [ skillsResponse , models , config , rateLimits ] = yield * Effect . all (
589639 [
590640 withCodexDiscoveryDeadline ( client . request ( "skills/list" , { cwds : [ input . cwd ] } ) , deadlineMs ) ,
591641 accountResponse . account ?. type === "chatgpt"
@@ -602,7 +652,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
602652 deadlineMs ,
603653 CODEX_CONFIG_PROBE_TIMEOUT_MS ,
604654 ) . pipe (
605- Effect . map ( ( response ) => response ?. config . service_tier ?? undefined ) ,
655+ Effect . map ( ( response ) => response ?. config ) ,
606656 Effect . catch ( ( ) => Effect . logDebug ( "Codex config read failed." ) . pipe ( Effect . as ( undefined ) ) ) ,
607657 ) ,
608658 // Usage is an enrichment: a failure or a slow answer degrades to "no
@@ -640,7 +690,12 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
640690 ...( rateLimits ? { rateLimits } : { } ) ,
641691 version,
642692 models,
643- serviceTier,
693+ serviceTier : config ?. service_tier ?? undefined ,
694+ daybreakEnabled : config ?. [ "daybreak" ] === true ,
695+ apiKeyCyberAccessProgramsDisabled :
696+ accountResponse . account ?. type === "apiKey" &&
697+ ( config ?. [ "features" ] as { readonly api_key_cyber_access_programs ?: unknown } | undefined )
698+ ?. api_key_cyber_access_programs === false ,
644699 skills : skillsResponse ? parseCodexSkillsListResponse ( skillsResponse , input . cwd ) : [ ] ,
645700 } satisfies CodexAppServerProviderSnapshot ;
646701} ) ;
@@ -901,6 +956,11 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
901956 appendCustomCodexModels ( snapshot . models ?? [ ] , codexSettings . customModels ) ,
902957 applyPreferredCodexDefaultModel ,
903958 ( models ) => applyConfiguredCodexServiceTier ( models , snapshot . serviceTier ) ,
959+ ( models ) =>
960+ applyConfiguredCodexCyberAccess ( models , {
961+ daybreakEnabled : snapshot . daybreakEnabled === true ,
962+ apiKeyProgramsDisabled : snapshot . apiKeyCyberAccessProgramsDisabled === true ,
963+ } ) ,
904964 ) ,
905965 skills : snapshot . skills ,
906966 slashCommands : [
0 commit comments