MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / pattern_editor

Function pattern_editor

scripts/python_ui/streamlit.py:943–1028  ·  view source on GitHub ↗

Edit pattern content with simple and advanced editing options.

(pattern_name)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 1

validate_patternFunction · 0.85

Tested by

no test coverage detected