Coverage for sources / agentsmgr / renderers / gemini.py: 65%
29 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 02:32 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-03 02:32 +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''' Gemini CLI renderer implementation.
23 Provides path resolution and targeting mode validation for Gemini CLI,
24 which supports both per-user and per-project configuration.
25'''
28from . import __
29from . import base as _base
32class GeminiRenderer( _base.RendererBase ):
33 ''' Renderer for Gemini CLI coder.
35 Supports both per-user and per-project configuration modes.
36 Per-user mode defaults to ~/.gemini/ with configuration file
37 override support via directory field in coder config.
38 '''
40 name = 'gemini'
41 modes_available = frozenset( ( 'per-user', 'per-project' ) )
42 mode_default = 'per-project'
43 memory_filename = 'GEMINI.md'
44 item_types_available = frozenset( ( 'commands', 'skills' ) )
46 def get_template_flavor( self, item_type: str ) -> str:
47 ''' Determines template flavor for Gemini CLI.
49 Gemini uses the gemini TOML command template flavor.
50 Gemini CLI does not support agents/subagents, only commands.
51 '''
52 if item_type == 'commands':
53 return 'gemini'
54 # Gemini CLI does not support agents/subagents
55 error_message = f"Gemini CLI does not support {item_type} generation"
56 raise __.Omnierror( error_message )
59 def resolve_base_directory(
60 self,
61 mode: _base.ExplicitTargetMode,
62 target: __.Path,
63 configuration: __.cabc.Mapping[ str, __.typx.Any ],
64 environment: __.cabc.Mapping[ str, str ],
65 ) -> __.Path:
66 ''' Resolves base output directory for Gemini CLI.
68 Per-project: .auxiliary/configuration/coders/gemini/
69 Per-user: ~/.gemini/ with configuration file overrides.
70 '''
71 self.validate_mode( mode )
72 if mode == 'per-project': 72 ↛ 73line 72 didn't jump to line 73 because the condition on line 72 was never true
73 return target / ".auxiliary/configuration/coders/gemini"
74 if mode == 'per-user': 74 ↛ 76line 74 didn't jump to line 76 because the condition on line 74 was always true
75 return self._resolve_user_directory( configuration, environment )
76 raise __.TargetModeNoSupport( self.name, mode )
78 def _resolve_user_directory(
79 self,
80 configuration: __.cabc.Mapping[ str, __.typx.Any ],
81 environment: __.cabc.Mapping[ str, str ],
82 ) -> __.Path:
83 ''' Resolves per-user directory following precedence rules.
85 Precedence order:
86 1. Configuration file override (directory field for this coder)
87 2. Default ~/.gemini/ location
89 Note: Gemini does not provide environment variable override
90 for user config path (unlike Claude's CLAUDE_CONFIG_DIR).
91 '''
92 coder_configuration = self._extract_coder_configuration(
93 configuration )
94 if 'directory' in coder_configuration: 94 ↛ 95line 94 didn't jump to line 95 because the condition on line 94 was never true
95 directory = __.Path( coder_configuration[ 'directory' ] )
96 return directory.expanduser( )
97 return __.Path.home( ) / '.gemini'
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 return _base.extract_coder_configuration( configuration, self.name )
109_base.RENDERERS[ 'gemini' ] = GeminiRenderer( )