@@ -65,36 +65,49 @@ def parse_blocks(text: str, block_word: str = "Commit", multiple: bool = True) -
6565 return matches [0 ].strip ()
6666
6767def parse_steps_markdown (md : str ):
68- """
69- Parse the markdown steps block and return a list of step dicts.
70- Now supports both context_identifiers and modify_identifiers.
71- """
7268 steps = []
73- step_blocks = re .split (r'---\s*' , md )
74- for block in step_blocks :
75- block = block .strip ()
76- if not block or block .startswith ("*** End Steps" ):
77- continue
78- # Parse step number and description
79- m = re .match (
80- r'(\d+)\.\s+\*\*(.*?)\*\*\s*\n\s*\*\*instructions\*\*:\s*(.*?)\n\s*\*\*context_identifiers\*\*:\s*((?:- .*\n?)*)\s*\*\*modify_identifiers\*\*:\s*((?:- .*\n?)*)' ,
81- block , re .DOTALL )
82- if not m :
69+
70+ # Extract only content between *** Begin Steps and *** End Steps
71+ match = re .search (r"\*\*\* Begin Steps(.*?)\*\*\* End Steps" , md , re .DOTALL )
72+ if not match :
73+ return []
74+
75+ steps_block = match .group (1 ).strip ()
76+
77+ # Split steps by '---'
78+ raw_steps = [s .strip () for s in steps_block .split ('---' ) if s .strip ()]
79+
80+ for raw_step in raw_steps :
81+ # Match step number and description
82+ step_header = re .match (r"(\d+)\.\s+\*\*(.*?)\*\*" , raw_step )
83+ if not step_header :
8384 continue
84- step_num = int (m .group (1 ))
85- description = m .group (2 ).strip ()
86- instructions = m .group (3 ).strip ()
87- context_block = m .group (4 )
88- modify_block = m .group (5 )
89- context_identifiers = [line [2 :].strip () for line in context_block .strip ().splitlines () if line .strip ().startswith ('-' )]
90- modify_identifiers = [line [2 :].strip () for line in modify_block .strip ().splitlines () if line .strip ().startswith ('-' )]
85+
86+ step_num = int (step_header .group (1 ))
87+ description = step_header .group (2 ).strip ()
88+
89+ # Match instructions
90+ instructions_match = re .search (r"\*\*instructions\*\*:\s*(.*?)(?=\*\*context_identifiers\*\*:)" , raw_step , re .DOTALL )
91+ instructions = instructions_match .group (1 ).strip () if instructions_match else ""
92+
93+ # Match context identifiers
94+ context_match = re .search (r"\*\*context_identifiers\*\*:\s*(.*?)(?=\*\*modify_identifiers\*\*:)" , raw_step , re .DOTALL )
95+ context_block = context_match .group (1 ).strip () if context_match else ""
96+ context_identifiers = re .findall (r"- (.+)" , context_block )
97+
98+ # Match modifying identifiers
99+ modify_match = re .search (r"\*\*modify_identifiers\*\*:\s*(.*)" , raw_step , re .DOTALL )
100+ modify_match = modify_match .group (1 ).strip () if modify_match else ""
101+ modify_identifiers = re .findall (r"- (.+)" , modify_match )
102+
91103 steps .append ({
92104 "step" : step_num ,
93105 "description" : description ,
94106 "instructions" : instructions ,
95- "context_identifiers" : context_identifiers ,
96- "modify_identifiers" : modify_identifiers
107+ "context_identifiers" : [ identifier . strip () for identifier in context_identifiers ] ,
108+ "modify_identifiers" : [ identifier . strip () for identifier in modify_identifiers ]
97109 })
110+
98111 return steps
99112
100113async def delete_file (file_path : str ) -> bool :
0 commit comments