Skip to content

fix(commit-widget): sort files and subdirectories alphabetically in renderDirectoryNode#235

Merged
ghinkle merged 2 commits into
nimbalyst:mainfrom
ademczuk:fix/commit-widget-sort-files
May 11, 2026
Merged

fix(commit-widget): sort files and subdirectories alphabetically in renderDirectoryNode#235
ghinkle merged 2 commits into
nimbalyst:mainfrom
ademczuk:fix/commit-widget-sort-files

Conversation

@ademczuk
Copy link
Copy Markdown
Collaborator

@ademczuk ademczuk commented May 10, 2026

Summary

Fixes #233. Files inside the commit proposal widget rendered in the order the model emitted them in filesToStage rather than alphabetically. Sort subdirectories by displayPath and files by basename inside renderDirectoryNode. Folders-before-files convention is preserved by the existing render order.

Changes

packages/runtime/src/ui/AgentTranscript/components/CustomToolWidgets/GitCommitConfirmationWidget.tsx:

  • Add two named, exported comparators at module scope: compareSubdirectoriesByDisplayPath and compareFilesByBasename.
  • Inside renderDirectoryNode, compute sortedSubdirectories and sortedFiles once via the comparators and use them at both render sites (root node + expanded subdirectory).
  • Export the DirectoryNode interface so tests can build fixture nodes without re-declaring the shape.

packages/runtime/src/ui/AgentTranscript/components/__tests__/GitCommitConfirmationWidget.helpers.test.ts (new):

  • Covers the issue Commit proposal widget: files unsorted within directories #233 example (.claude/commands/ reordering to alphabetical).
  • Covers basename-vs-full-path semantics (a path deep under deep/nested/... with basename zebra.ts should sort after a shallow path with basename apple.ts).
  • Covers paths without directory separators and already-sorted input.
  • Covers collapsed compound displayPath sorting on subdirectory nodes.
  • 6 tests, all pass locally (npm run test:unit -- --run packages/runtime/src/ui/AgentTranscript/components/__tests__/GitCommitConfirmationWidget.helpers.test.ts).

CHANGELOG.md (+1): entry under ### Fixed referencing #233.

Test plan

  • New helper test file passes locally.
  • Trigger a Smart Commit on a session with files spread across multiple directories.
  • Verify each directory renders its files alphabetically by basename.
  • Verify subdirectories within a parent render alphabetically by name.
  • Verify folders still render before files at every level.

Issue example to reproduce: .claude/commands/ should render analyze-code.md, bug-report.md, design.md, posthog-analysis.md, roadmap.md (alphabetical) rather than the model's emission order.

Single-concern PR. No new dependencies.

ademczuk added 2 commits May 10, 2026 20:54
…enderDirectoryNode

Files inside a directory rendered in the order the model emitted them in
filesToStage, which made it hard to scan a commit with many files in one
folder (the issue example: .claude/commands/ rendered analyze-code.md,
roadmap.md, bug-report.md, design.md, posthog-analysis.md instead of
alphabetical order).

Sort subdirectories by displayPath and files by basename inside
renderDirectoryNode. Folders-before-files convention is preserved by the
existing render order. Used at both render sites (root + expanded
subdirectory) so the tree renders deterministically.

Fixes #233.
Extract the two inline sort callbacks from renderDirectoryNode into
named module-level exports (compareSubdirectoriesByDisplayPath and
compareFilesByBasename) and add a focused helper test that covers the
issue #233 example, basename-vs-full-path semantics, root-level paths,
and collapsed compound displayPath nodes.

Also export the DirectoryNode interface so the test can build
fixture nodes without re-declaring the shape.

Corrects my prior claim that vitest + jsdom test infrastructure
was not in place: it is (vitest.config.ts environment: 'jsdom',
jsdom@26.1.0 in package.json, sibling __tests__/TranscriptWidgets.test.tsx).
@ghinkle ghinkle merged commit 0589154 into nimbalyst:main May 11, 2026
3 checks passed
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.

Commit proposal widget: files unsorted within directories

2 participants