fix: lossless project directory encoding for paths with hyphens#16
Merged
Conversation
The old EncodeProjectName/DecodeProjectName used '-' as a simple replacement for '/'. Since '-' is a valid path character, paths like /Users/setkyar/my-project would round-trip as /Users/setkyar/my/project, producing broken path suggestions in the Create New Session modal's recent locations chips. Changes: - EncodeProjectName now uses '_' as sentinel: '__' -> literal '_', '_-' -> '/'. Hyphens pass through unchanged. - DecodeProjectName detects new format (contains '_') vs legacy (no '_') for backward compatibility with existing directories. - ListRecentLocations now recovers legacy hyphenated paths by reading the real 'cwd' from the session JSONL header when the decoded path doesn't exist on disk. Fixes: broken path suggestions when copying from recent locations with project names containing hyphens.
- Add TestResolveLocationReturnsDecodedPathWhenOnDisk for resolveLocation stat-hit happy path (returns decoded path directly when it exists on disk) - Clarify readSessionCWD comment: any file will do, not just 'first' - Replace bytes.TrimSpace(scanner.Bytes()) with strings.TrimSpace(scanner.Text()) and remove unused bytes import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The old
EncodeProjectName/DecodeProjectNameused-as a simple replacement for/. Since-is a valid path character, paths like/Users/setkyar/my-projectwould round-trip as/Users/setkyar/my/project, producing broken path suggestions in the Create New Session modal's recent locations chips.Changes
EncodeProjectNamenow uses_as sentinel:__→ literal_,_-→/. Hyphens pass through unchanged.DecodeProjectNamedetects new format (contains_) vs legacy (no_) for backward compatibility with existing directories.ListRecentLocationsnow recovers legacy hyphenated paths by reading the realcwdfrom the session JSONL header when the decoded path doesn't exist on disk.Test Plan
TestEncodeDecodeRoundTripwith hyphen and underscore pathsTestListRecentLocationsRecoversLegacyHyphenatedPaths— creates a legacy-encoded dir for/tmp/my-project, writes a session file with the realcwd, and verifiesListRecentLocationsreturns the correct path