Skip to content

Commit 36402b7

Browse files
Copilotiloveitaly
andauthored
Fix deterministic ordering for implode.py cursor and github modes (#3)
* Initial plan * Initial analysis: identified file ordering issue in implode.py Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com> * Fix deterministic ordering for implode.py cursor and github modes Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com> * Add .gitignore for Python cache files and revert instructions.md Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com> * Simplify .gitignore to minimal Python cache files only Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com>
1 parent b84b5bf commit 36402b7

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Python cache files
2+
__pycache__/
3+
*.pyc
4+
*.pyo
5+
*.py[cod]

implode.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ def get_ordered_files(file_list, section_globs_keys):
3030

3131
return ordered_files
3232

33+
def get_ordered_files_github(file_list, section_globs_keys):
34+
"""Order GitHub instruction files based on SECTION_GLOBS key order, with unmapped files at the end.
35+
Handles .instructions suffix by stripping it for ordering purposes."""
36+
# Create dict mapping base filename (without .instructions) to the actual file
37+
file_dict = {}
38+
for f in file_list:
39+
base_stem = f.stem.replace('.instructions', '')
40+
file_dict[base_stem] = f
41+
42+
ordered_files = []
43+
44+
# Add files in SECTION_GLOBS order
45+
for section_name in section_globs_keys:
46+
filename = header_to_filename(section_name)
47+
if filename in file_dict:
48+
ordered_files.append(file_dict[filename])
49+
del file_dict[filename]
50+
51+
# Add any remaining files (not in SECTION_GLOBS) sorted alphabetically
52+
remaining_files = sorted(file_dict.values(), key=lambda p: p.name)
53+
ordered_files.extend(remaining_files)
54+
55+
return ordered_files
56+
3357
def bundle_cursor_rules(rules_dir, output_file):
3458
rule_files = list(Path(rules_dir).glob("*.mdc"))
3559
general = [f for f in rule_files if f.stem == "general"]
@@ -79,7 +103,8 @@ def bundle_github_instructions(instructions_dir, output_file):
79103
instr_files = list(Path(instructions_dir).glob("*.instructions.md"))
80104

81105
# Order the instruction files based on SECTION_GLOBS
82-
ordered_files = get_ordered_files(instr_files, SECTION_GLOBS.keys())
106+
# We need to create a modified version that strips .instructions from stems for ordering
107+
ordered_files = get_ordered_files_github(instr_files, SECTION_GLOBS.keys())
83108

84109
with open(output_file, "w") as out:
85110
# Write general copilot instructions if present

0 commit comments

Comments
 (0)