Coverage for sources/agentsmgr/renderers/codex.py: 29%
31 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-23 02:37 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-23 02:37 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
4#============================================================================#
5# #
6# Licensed under the Apache License, Version 2.0 (the "License"); #
7# you may not use this file except in compliance with the License. #
8# You may obtain a copy of the License at #
9# #
10# http://www.apache.org/licenses/LICENSE-2.0 #
11# #
12# Unless required by applicable law or agreed to in writing, software #
13# distributed under the License is distributed on an "AS IS" BASIS, #
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15# See the License for the specific language governing permissions and #
16# limitations under the License. #
17# #
18#============================================================================#
21''' Codex CLI renderer implementation.
23 Provides path resolution and targeting mode validation for Codex CLI.
24 Codex CLI only supports per-user configuration as of version 0.44.0.
25'''
28from . import __
29from .base import RENDERERS, ExplicitTargetMode, RendererBase
32class CodexRenderer( RendererBase ):
33 ''' Renderer for Codex CLI coder.
35 Only supports per-user configuration mode. Codex CLI does not
36 support per-project configuration as of version 0.44.0. Per-user
37 mode respects CODEX_HOME environment variable with fallback to
38 configuration overrides and default location.
39 '''
41 name = 'codex'
42 modes_available = frozenset( ( 'per-user', ) )
43 mode_default = 'per-user'
44 memory_filename = 'AGENTS.md'
46 def get_template_flavor( self, item_type: str ) -> str:
47 ''' Determines template flavor for Codex CLI.
49 Codex uses same markdown format as Claude for all item types,
50 so always returns 'claude' flavor.
51 '''
52 return 'claude'
54 def resolve_base_directory(
55 self,
56 mode: ExplicitTargetMode,
57 target: __.Path,
58 configuration: __.cabc.Mapping[ str, __.typx.Any ],
59 environment: __.cabc.Mapping[ str, str ],
60 ) -> __.Path:
61 ''' Resolves base output directory for Codex CLI.
63 Only per-user mode is supported. Respects precedence: CODEX_HOME
64 environment variable, configuration file override (home key), or
65 default ~/.codex location. Per-project mode raises error with
66 explanation of Codex CLI limitation.
67 '''
68 self.validate_mode( mode )
69 if mode == 'per-user':
70 return self._resolve_user_directory( configuration, environment )
71 reason = (
72 "Codex CLI does not support per-project configuration. "
73 "Only per-user configuration in ~/.codex or $CODEX_HOME "
74 "is supported as of version 0.44.0." )
75 raise __.TargetModeNoSupport( self.name, mode, reason )
77 def _resolve_user_directory(
78 self,
79 configuration: __.cabc.Mapping[ str, __.typx.Any ],
80 environment: __.cabc.Mapping[ str, str ],
81 ) -> __.Path:
82 ''' Resolves per-user directory following precedence rules.
84 Precedence order:
85 1. CODEX_HOME environment variable
86 2. Configuration file override (home key for this coder)
87 3. Default ~/.codex location
88 '''
89 if 'CODEX_HOME' in environment:
90 directory = __.Path( environment[ 'CODEX_HOME' ] )
91 return directory.expanduser( )
92 coder_configuration = self._extract_coder_configuration(
93 configuration )
94 if 'home' in coder_configuration:
95 directory = __.Path( coder_configuration[ 'home' ] )
96 return directory.expanduser( )
97 return __.Path.home( ) / '.codex'
99 def _extract_coder_configuration(
100 self, configuration: __.cabc.Mapping[ str, __.typx.Any ]
101 ) -> __.cabc.Mapping[ str, __.typx.Any ]:
102 ''' Extracts configuration for this specific coder.
104 Looks for coder entry in configuration coders array by name.
105 '''
106 coders = configuration.get( 'coders', ( ) )
107 for coder in coders:
108 if coder.get( 'name' ) == self.name:
109 return coder
110 return { }
113RENDERERS[ 'codex' ] = CodexRenderer( )