Edit pattern content with simple and advanced editing options.
(pattern_name)
| 940 | |
| 941 | |
| 942 | def pattern_editor(pattern_name): |
| 943 | """Edit pattern content with simple and advanced editing options.""" |
| 944 | if not pattern_name: |
| 945 | return |
| 946 | |
| 947 | pattern_path = os.path.join(pattern_dir, pattern_name) |
| 948 | system_file = os.path.join(pattern_path, "system.md") |
| 949 | user_file = os.path.join(pattern_path, "user.md") |
| 950 | |
| 951 | st.markdown(f"### Editing Pattern: {pattern_name}") |
| 952 | is_valid, message = validate_pattern(pattern_name) |
| 953 | if not is_valid: |
| 954 | st.error(message) |
| 955 | elif message != "Pattern is valid.": |
| 956 | st.warning(message) |
| 957 | else: |
| 958 | st.success("Pattern structure is valid") |
| 959 | |
| 960 | edit_mode = st.radio( |
| 961 | "Edit Mode", |
| 962 | ["Simple Editor", "Advanced (Wizard)"], |
| 963 | key=f"edit_mode_{pattern_name}", |
| 964 | horizontal=True, |
| 965 | ) |
| 966 | |
| 967 | if edit_mode == "Simple Editor": |
| 968 | if os.path.exists(system_file): |
| 969 | with open(system_file) as f: |
| 970 | content = f.read() |
| 971 | new_content = st.text_area("Edit system.md", content, height=600) |
| 972 | if st.button("Save system.md"): |
| 973 | with open(system_file, "w") as f: |
| 974 | f.write(new_content) |
| 975 | st.success("Saved successfully!") |
| 976 | else: |
| 977 | st.error("system.md file not found") |
| 978 | |
| 979 | if os.path.exists(user_file): |
| 980 | with open(user_file) as f: |
| 981 | content = f.read() |
| 982 | new_content = st.text_area("Edit user.md", content, height=300) |
| 983 | if st.button("Save user.md"): |
| 984 | with open(user_file, "w") as f: |
| 985 | f.write(new_content) |
| 986 | st.success("Saved successfully!") |
| 987 | |
| 988 | else: |
| 989 | if os.path.exists(system_file): |
| 990 | with open(system_file) as f: |
| 991 | content = f.read() |
| 992 | |
| 993 | sections = content.split("#") |
| 994 | edited_sections = [] |
| 995 | |
| 996 | for section in sections: |
| 997 | if not section.strip(): |
| 998 | continue |
| 999 |
no test coverage detected