Instead of checking for extension, check if file exists

This commit is contained in:
Alberto Simoes committed 2026-01-08 15:02:22 +00:00
1 parent 201db5afcb
commit c25fb66262
1 file changed
+20
+20
View File
@@ -128,6 +128,16 @@ class SerenaAgentMode(ToolInclusionDefinition, ToStringMixin):
path = Path(name_or_path)
if path.exists() and path.is_file():
return cls.from_yaml(name_or_path)
# If it looks like a file path but doesn't exist, raise FileNotFoundError
name_or_path_str = str(name_or_path)
if (
os.sep in name_or_path_str
or (os.altsep and os.altsep in name_or_path_str)
or name_or_path_str.endswith((".yml", ".yaml"))
):
raise FileNotFoundError(f"Mode file not found: {path.resolve()}")
return cls.from_name(str(name_or_path))
@@ -231,6 +241,16 @@ class SerenaAgentContext(ToolInclusionDefinition, ToStringMixin):
path = Path(name_or_path)
if path.exists() and path.is_file():
return cls.from_yaml(name_or_path)
# If it looks like a file path but doesn't exist, raise FileNotFoundError
name_or_path_str = str(name_or_path)
if (
os.sep in name_or_path_str
or (os.altsep and os.altsep in name_or_path_str)
or name_or_path_str.endswith((".yml", ".yaml"))
):
raise FileNotFoundError(f"Context file not found: {path.resolve()}")
return cls.from_name(str(name_or_path))
@classmethod