Files
wehub-resource-sync adc62957a7
CI / Multi-repo Path Gate (AST-grep) (windows-latest) (push) Has been cancelled
CI / Version Consistency Check (push) Has been cancelled
CI / npm pack + install test (push) Has been cancelled
CI / Lint & Type Check (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Test (Windows path suite) (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / No Committed Build Artifacts (push) Has been cancelled
CI / Multi-repo Path Gate (AST-grep) (ubuntu-latest) (push) Has been cancelled
Upgrade Test / omc update + session-start hook (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:36:54 +08:00

29 lines
1.4 KiB
JavaScript

/**
* Claude Code project-directory character sanitization (hook-runtime mirror).
*
* Mirror of `src/utils/encode-project-path.ts` — keep the two in sync. The TS
* helper is the source of truth; this `.mjs` copy exists because the hook
* runtime loads raw scripts and cannot import the compiled `dist/` util.
*
* Claude Code stores a project's transcripts under
* `~/.claude/projects/<encoded>`. For normal-length project paths, this helper
* mirrors Claude Code's character replacement step: every character that is not
* an ASCII letter or digit is replaced by `-` (path separators, dots, the
* Windows drive colon, and also underscores, spaces, and non-ASCII characters).
* For example:
*
* POSIX: /home/me/proj -> -home-me-proj
* POSIX: /home/me/my.proj -> -home-me-my-proj
* POSIX: /home/me/00_proj -> -home-me-00-proj
* Windows: C:\Users\me\proj -> C--Users-me-proj
*
* Any character left unsanitized produces a name that never matches the real
* directory, so any lookup keyed on the encoded name silently finds nothing.
* This helper intentionally mirrors only Claude Code's normal-length character
* replacement/sanitization step, not its full long-path contract (which also
* truncates very long encoded names and appends a hash).
*/
export function encodeProjectPath(projectPath) {
return projectPath.replace(/[^a-zA-Z0-9]/g, '-');
}