Skip to content

fix: decode project keys with longest-match backtracking#92

Merged
Ark0N merged 1 commit into
Ark0N:masterfrom
TeigenZhang:fix/project-key-longest-match
May 19, 2026
Merged

fix: decode project keys with longest-match backtracking#92
Ark0N merged 1 commit into
Ark0N:masterfrom
TeigenZhang:fix/project-key-longest-match

Conversation

@TeigenZhang
Copy link
Copy Markdown
Contributor

Summary

When two sibling directories share a prefix (e.g. diary/ and diary-app/), the greedy shortest-match decoder in decodeProjectKey() picks the shorter name and then fails to resolve the remainder. As a result:

  • The homepage Resume Conversation list shows those workingDirs as $HOME
  • Resume targets the wrong folder

Fix

Switch to recursive backtracking with longest-join-first at each segment boundary; require every step to be a real directory on disk. Keep the greedy path as a fallback for deleted directories (so history of deleted projects still resolves).

Test plan

  • tsc --noEmit passes
  • npm run lint passes
  • npm run format:check passes
  • Manual verification: sibling directories ~/foo/diary/ and ~/foo/diary-app/ both resolve correctly in the Resume Conversation list and Resume button targets the right folder.

When two sibling directories share a prefix (e.g. `diary/` and
`diary-app/`), the greedy shortest-match decoder picked the shorter
name and then failed to resolve the remainder, so the homepage Resume
Conversation list showed those workingDirs as $HOME and resume targeted
the wrong folder. Switch to recursive backtracking with longest-join-first
at each segment boundary; require every step to be a real directory.
Keep the greedy path as a fallback for deleted dirs.
@Ark0N
Copy link
Copy Markdown
Owner

Ark0N commented May 19, 2026

Thanks for the thoughtful fix! Good catch on the sibling-prefix collision — the longest-match backtracking with the greedy fallback for deleted dirs is exactly the right shape. Merging.

@Ark0N Ark0N merged commit 73d81af into Ark0N:master May 19, 2026
1 check 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.

2 participants