Skip to content

fix: lossless project directory encoding for paths with hyphens#16

Merged
setkyar merged 2 commits into
mainfrom
fix/project-path-hyphen-decoding
May 30, 2026
Merged

fix: lossless project directory encoding for paths with hyphens#16
setkyar merged 2 commits into
mainfrom
fix/project-path-hyphen-decoding

Conversation

@setkyar
Copy link
Copy Markdown
Contributor

@setkyar setkyar commented May 30, 2026

Problem

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.

Test Plan

  • Expanded TestEncodeDecodeRoundTrip with hyphen and underscore paths
  • Added TestListRecentLocationsRecoversLegacyHyphenatedPaths — creates a legacy-encoded dir for /tmp/my-project, writes a session file with the real cwd, and verifies ListRecentLocations returns the correct path

setkyar added 2 commits May 30, 2026 15:08
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
@setkyar setkyar merged commit 99fb9ff into main May 30, 2026
1 check passed
@setkyar setkyar deleted the fix/project-path-hyphen-decoding branch May 30, 2026 08:49
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.

1 participant