Skip to content

Fix deterministic ordering for implode.py cursor and github modes#3

Merged
iloveitaly merged 5 commits into
masterfrom
copilot/fix-a3dcd7da-0ecd-40d7-85ba-751d62490d3b
Aug 11, 2025
Merged

Fix deterministic ordering for implode.py cursor and github modes#3
iloveitaly merged 5 commits into
masterfrom
copilot/fix-a3dcd7da-0ecd-40d7-85ba-751d62490d3b

Conversation

Copilot AI commented Aug 1, 2025

Copy link
Copy Markdown
Contributor

Problem

The py implode.py cursor and py implode.py github commands were producing different section orderings in their output instructions.md files, making the results non-deterministic depending on which mode was used.

For example, running both commands on the same repository would produce different section orders:

Cursor mode output:

## Python
## Python App
## Pytest Integration Tests
## Python Route Tests
## Fastapi
## React
## React Router
...

GitHub mode output (before fix):

## Fastapi
## Pytest Integration Tests  
## Python App
## Python Route Tests
## Python
## React Router
## React
...

Root Cause

The issue was in how file stems were handled between the two modes:

  1. Cursor mode: Files like python.mdc have stems like python which correctly match the SECTION_GLOBS key conversions
  2. GitHub mode: Files like python.instructions.md have stems like python.instructions which don't match the SECTION_GLOBS conversions because the .instructions suffix was included

When files couldn't be matched to SECTION_GLOBS keys, they were treated as "remaining files" and sorted alphabetically instead of following the intended deterministic order.

Solution

Created a new get_ordered_files_github() function that strips the .instructions suffix from file stems before matching against SECTION_GLOBS keys. This ensures both modes use the same ordering logic based on the predefined section order in constants.py.

Additional Changes

  • Added comprehensive .gitignore file to exclude Python cache files and other artifacts
  • Instructions.md is not included in this PR to allow local testing of just the implode.py changes

Verification

Both modes now produce sections in the same deterministic order for common files:

  1. Python
  2. Python App
  3. Pytest Integration Tests
  4. Python Route Tests
  5. FastAPI
  6. React
  7. React Router
  8. Shell
  9. TypeScript
    (plus any additional sections specific to each mode, in alphabetical order)

The fix maintains backward compatibility and doesn't change the behavior for cursor mode, only corrects the ordering issue in github mode.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 1, 2025 23:57
Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com>
Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com>
Copilot AI changed the title [WIP] py impode.py cursor and py implode.py github does not order the resulting instructions.md in the same way. Can you fix this so the instruction ordering is deterministic? Fix deterministic ordering for implode.py cursor and github modes Aug 2, 2025
Copilot AI requested a review from iloveitaly August 2, 2025 00:01
@iloveitaly

Copy link
Copy Markdown
Owner

@copilot

  1. can we add cache files to gitignore
  2. can you omit adding the mutated instructions.md so i can test this locally? I just want to updated implode.py

Taking another look at this change, is there anything you would update?

Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com>

Copilot AI commented Aug 8, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

  1. can we add cache files to gitignore
    ...

Done! Changes made in commit 4fbf031:

  1. ✅ Added comprehensive .gitignore file to exclude Python cache files (pycache, *.pyc, etc.)
  2. ✅ Reverted instructions.md to original state so you can test locally

Only implode.py contains the actual fix now. The get_ordered_files_github() function properly handles the .instructions suffix stripping to ensure deterministic ordering between cursor and github modes.

@iloveitaly

Copy link
Copy Markdown
Owner

@copilot That .gitignore update is too insane. Can we just add in what we needed to avoid adding additional junk to this PR?

Co-authored-by: iloveitaly <150855+iloveitaly@users.noreply.github.com>

Copilot AI commented Aug 10, 2025

Copy link
Copy Markdown
Contributor Author

@copilot That .gitignore update is too insane. Can we just add in what we needed to avoid adding additional junk to this PR?

Done! Simplified the .gitignore to include only minimal Python cache files (pycache, *.pyc, *.pyo, *.py[cod]) in commit bb0c3ed. Much cleaner and focused on just what's needed for this PR.

@iloveitaly iloveitaly marked this pull request as ready for review August 11, 2025 11:58
@iloveitaly iloveitaly merged commit 36402b7 into master Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants