@@ -67,6 +67,7 @@ def load_json_maybe_jsonc(text: str) -> dict:
6767
6868working_dir = Path (__file__ ).parent .parent .parent .resolve ()
6969install_path = working_dir / "install"
70+ defaults_path = working_dir / "tools" / "ci" / "defaults" / "maa_option.json"
7071version = len (sys .argv ) > 1 and sys .argv [1 ] or "v0.0.1"
7172
7273# the first parameter is self name
@@ -206,12 +207,50 @@ def install_manifest_cache():
206207 print (f"Warning: Manifest cache generation raised error: { e } " )
207208
208209
210+ def install_or_patch_maa_option ():
211+ """写入 MR3A 默认 maa_option,并保留上游新增字段。"""
212+ if not defaults_path .exists ():
213+ raise FileNotFoundError (f"Missing default config template: { defaults_path } " )
214+
215+ config_dir = install_path / "config"
216+ config_dir .mkdir (parents = True , exist_ok = True )
217+ target_path = config_dir / "maa_option.json"
218+
219+ with open (defaults_path , "r" , encoding = "utf-8" ) as f :
220+ defaults = load_json_maybe_jsonc (f .read ())
221+
222+ if not isinstance (defaults , dict ):
223+ raise ValueError (f"Invalid default config format in { defaults_path } : expected object" )
224+
225+ existing : dict = {}
226+ if target_path .exists ():
227+ try :
228+ with open (target_path , "r" , encoding = "utf-8" ) as f :
229+ parsed = load_json_maybe_jsonc (f .read ())
230+ if isinstance (parsed , dict ):
231+ existing = parsed
232+ else :
233+ print (f"Warning: { target_path } is not an object, using defaults only." )
234+ except Exception as e :
235+ print (f"Warning: Failed to parse { target_path } , using defaults only: { e } " )
236+
237+ merged = dict (existing )
238+ merged .update (defaults )
239+
240+ with open (target_path , "w" , encoding = "utf-8" ) as f :
241+ json .dump (merged , f , ensure_ascii = False , indent = 4 )
242+ f .write ("\n " )
243+
244+ print (f"Patched Maa option config: { target_path } " )
245+
246+
209247if __name__ == "__main__" :
210248 install_deps ()
211249 install_resource ()
212250 install_chores ()
213251 install_agent ()
214252 install_manifest_cache ()
253+ install_or_patch_maa_option ()
215254
216255 print (f"Install to { install_path } successfully." )
217256
0 commit comments