Coverage for sources/agentsmgr/renderers/qwen.py: 28%

31 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-24 01:49 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

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#============================================================================# 

19 

20 

21''' Qwen Code renderer implementation. 

22 

23 Provides path resolution and targeting mode validation for Qwen Code, 

24 which supports both per-user and per-project configuration. 

25''' 

26 

27 

28from . import __ 

29from . import base as _base 

30 

31 

32class QwenRenderer( _base.RendererBase ): 

33 ''' Renderer for Qwen Code coder. 

34 

35 Supports both per-user and per-project configuration modes. 

36 Per-user mode defaults to ~/.qwen/ with configuration file 

37 override support via directory field in coder config. 

38 ''' 

39 

40 name = 'qwen' 

41 modes_available = frozenset( ( 'per-user', 'per-project' ) ) 

42 mode_default = 'per-project' 

43 memory_filename = 'QWEN.md' 

44 

45 def get_template_flavor( self, item_type: str ) -> str: 

46 ''' Determines template flavor for Qwen Code. 

47 

48 Qwen shares markdown command format with Claude/Gemini 

49 (via gemini.toml.jinja for TOML) but uses own agent format 

50 with YAML frontmatter, so returns 'gemini' for commands 

51 and 'qwen' for agents. 

52 ''' 

53 if item_type == 'commands': 

54 return 'gemini' 

55 return 'qwen' 

56 

57 def resolve_base_directory( 

58 self, 

59 mode: _base.ExplicitTargetMode, 

60 target: __.Path, 

61 configuration: __.cabc.Mapping[ str, __.typx.Any ], 

62 environment: __.cabc.Mapping[ str, str ], 

63 ) -> __.Path: 

64 ''' Resolves base output directory for Qwen Code. 

65 

66 Per-project: .auxiliary/configuration/coders/qwen/ 

67 Per-user: ~/.qwen/ with configuration file overrides. 

68 ''' 

69 self.validate_mode( mode ) 

70 if mode == 'per-project': 

71 return target / ".auxiliary/configuration/coders/qwen" 

72 if mode == 'per-user': 

73 return self._resolve_user_directory( configuration, environment ) 

74 raise __.TargetModeNoSupport( self.name, mode ) 

75 

76 def _resolve_user_directory( 

77 self, 

78 configuration: __.cabc.Mapping[ str, __.typx.Any ], 

79 environment: __.cabc.Mapping[ str, str ], 

80 ) -> __.Path: 

81 ''' Resolves per-user directory following precedence rules. 

82 

83 Precedence order: 

84 1. Configuration file override (directory field for this coder) 

85 2. Default ~/.qwen/ location 

86 

87 Note: Qwen does not provide environment variable override 

88 for user config path (unlike Claude's CLAUDE_CONFIG_DIR). 

89 ''' 

90 coder_configuration = self._extract_coder_configuration( 

91 configuration ) 

92 if 'directory' in coder_configuration: 

93 directory = __.Path( coder_configuration[ 'directory' ] ) 

94 return directory.expanduser( ) 

95 return __.Path.home( ) / '.qwen' 

96 

97 def _extract_coder_configuration( 

98 self, configuration: __.cabc.Mapping[ str, __.typx.Any ] 

99 ) -> __.cabc.Mapping[ str, __.typx.Any ]: 

100 ''' Extracts configuration for this specific coder. 

101 

102 Looks for coder entry in configuration coders array by name. 

103 ''' 

104 coders = configuration.get( 'coders', ( ) ) 

105 for coder in coders: 

106 if coder.get( 'name' ) == self.name: 

107 return coder 

108 return { } 

109 

110 

111_base.RENDERERS[ 'qwen' ] = QwenRenderer( )