[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M69BNJ1P2BKGDBMAZBT6S0AF":3,"skill-same:01M69BNJ1P2BKGDBMAZBT6S0AF":65},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":18,"categories":19,"keywords":30,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":45,"repositoryHtmlUrl":46,"repositoryHomepageUrl":17,"ownerHtmlUrl":47,"ownerBlogUrl":48,"ownerDescription":49,"updatedAt":50,"install":51,"resources":64},"01M69BNJ1P2BKGDBMAZBT6S0AF","rust-locator-patterns","PET Rust 编码规范","PET (Python Environment Tools) Rust coding conventions: locator ordering, thread safety, platform gating, JSONRPC rules, version detection, and path\u002Fsymlink handling. Reference when writing or reviewing Rust code in this repo to avoid convention violations that cause review churn.","PET（Python Environment Tools）Rust 编码约定：定位器顺序、线程安全、平台门控、JSONRPC 规则、版本检测以及路径\u002F符号链接处理。在本仓库编写或审查 Rust 代码时参考，以避免违反约定而导致审查反复修改。","microsoft\u002Fpython-environment-tools","microsoft","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6154722?v=4","01M698VYDXZ6JW5WH3CRV650R8","Microsoft","01M69BNE8385D7YQ637S4PQEQ7",209,"MIT",null,"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-locator-patterns\u002FSKILL.md",[20,25],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},"01M8BQ6TQZN6R52WBJ9H8NRMQM","软件开发工程师","PROFESSION","适用职业",{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},"01M8BSNPHVX9Y1H3B2ZX3V06RF","Rust 开发","SCENARIO","使用场景",[31,32,33,34,35,36],"rust","rust locator patterns","writing","review","python","code","2026-11-10 10:12:30",false,"---\nname: \"rust-locator-patterns\"\ndescription: \"PET (Python Environment Tools) Rust coding conventions: locator ordering, thread safety, platform gating, JSONRPC rules, version detection, and path\u002Fsymlink handling. Reference when writing or reviewing Rust code in this repo to avoid convention violations that cause review churn.\"\n---\n\n# PET Rust Locator Patterns & Conventions\n\nDomain knowledge for writing correct Rust code in the Python Environment Tools (PET) repository. Following these patterns prevents the most common review feedback and CI failures.\n\n## Locator Ordering (CRITICAL)\n\nThe order of locators in `create_locators()` in `crates\u002Fpet\u002Fsrc\u002Flocators.rs` determines identification priority. **More specific locators MUST come before generic ones.**\n\n### Priority Chain (required order):\n1. **Windows-specific:** Windows Store → Windows Registry → WinPython\n2. **Managed environments:** PyEnv → Pixi → Conda\n3. **Virtual envs (specific → generic):** Poetry → PipEnv → VirtualEnvWrapper → Venv → VirtualEnv\n4. **macOS-specific:** Homebrew → MacXCode → MacCmdLineTools → MacPythonOrg\n5. **Linux fallback:** LinuxGlobalPython (MUST BE LAST)\n\n**Why it matters:** If `Venv` runs before `Poetry`, a Poetry environment (which IS a venv) gets misidentified as a plain venv. The first locator whose `try_from()` returns `Some` wins.\n\n## Environment Identification (`try_from`)\n\nEach `try_from()` must be **precise enough to avoid false positives**:\n\n- **Poetry:** Match `{project-name}-{8-char-hash}-py{major}.{minor}` naming pattern AND verify location is in poetry cache dir\n- **Pipenv:** Look for `.project` file in centralized dir with hash-based naming\n- **Conda:** Require `conda-meta\u002F` directory with history file\n- **Pixi:** Require `.pixi\u002Fenvs\u002F` in path structure\n- **venv:** Check for `pyvenv.cfg` file (but many env types have this — venv is a fallback)\n- **VirtualEnv:** Activation scripts WITHOUT `pyvenv.cfg` (most generic, last resort)\n\n**Red flag:** A `try_from()` that only checks `pyvenv.cfg` existence — that matches ALL venvs, not just one type.\n\n## JSONRPC Protocol Rules\n\nThe server communicates via stdin\u002Fstdout. **Any stdout pollution breaks the protocol.**\n\n- **NEVER use `println!`** — it writes to stdout and corrupts JSONRPC messages\n- Use `log` crate macros: `info!()`, `trace!()`, `warn!()`, `error!()`\n- Log with elapsed time for diagnostic handlers (established pattern)\n- All tracing\u002Flogging writes to stderr via subscriber configuration\n\n## Thread Safety Patterns\n\nPET uses heavy concurrency for parallel discovery:\n\n- Shared state requires `Arc\u003CMutex\u003CT>>` or `Arc\u003CRwLock\u003CT>>`\n- Keep lock scopes minimal — clone data out, drop lock, then process\n- Use `.expect(\"context\")` on mutex locks, not bare `.unwrap()`\n- No nested locks (deadlock risk)\n- Consider `thread::scope` for structured concurrency\n\n## Platform-Specific Code\n\nUse `#[cfg(...)]` attributes for conditional compilation:\n\n```rust\n#[cfg(windows)]\nuse pet_windows_registry::WindowsRegistry;\n\n#[cfg(unix)]\nfn resolve_path(p: &Path) -> PathBuf { std::fs::canonicalize(p).unwrap_or(p.to_path_buf()) }\n\n#[cfg(target_os = \"macos\")]\nuse pet_homebrew::Homebrew;\n```\n\n**Do NOT use `if cfg!(windows) { ... }` for code that imports platform-specific modules** — the code inside still gets compiled on all platforms.\n\n### Platform Gotchas:\n- **Windows:** Avoid `canonicalize()` for directory junctions (breaks Scoop symlinks). Use `norm_case()` instead.\n- **macOS:** Homebrew has complex symlink chains; `resolve_symlink` before `canonicalize`\n- **Linux:** `\u002Fbin` may symlink to `\u002Fusr\u002Fbin` — handle both\n\n## Version Detection (Prefer File-Based)\n\n**Order of preference (cheapest first):**\n1. `pyvenv.cfg` — `version` or `version_info` field\n2. `conda-meta\u002Fpython-*.json` — package metadata\n3. `Include\u002Fpatchlevel.h` — CPython source header\n4. Parse from executable path (e.g., `python3.11`)\n5. Spawn Python `--version` — **LAST RESORT** (expensive, defeats PET's purpose)\n\n## Path & Symlink Handling\n\n- Use `pet_fs::path::resolve_symlink()` — the project's own resolver\n- For comparison: `canonicalize().unwrap_or(original)` then `norm_case()` for Windows UNC prefix handling\n- Preserve original user-facing paths; resolve only for identification\n\n## Testing Conventions\n\n- Feature-gated CI tests: `#[cfg_attr(feature = \"ci\", test)]` with `#[allow(dead_code)]`\n- Feature flags: `ci`, `ci-poetry-global`, `ci-jupyter-container`, `ci-homebrew-container`\n- Verification pattern: spawn Python, use `try_from()`, test symlinks, use `resolve`\n- Use `cargo test --features ci` for CI-gated tests\n\n## Serialization\n\n- All JSON-serialized structs use `#[serde(rename_all = \"camelCase\")]`\n- Matches the JSONRPC API conventions consumed by VS Code Python extension\n\n## Pre-Commit Requirements\n\nAlways run before committing:\n```bash\ncargo fmt --all\ncargo clippy --all -- -D warnings\n```\nNever suppress clippy warnings with `#[allow(...)]` without justification.\n\n## Conda-Specific Patterns\n\n- Conda manager detection takes precedence over mamba: `get_conda_manager(path).or_else(|| get_mamba_manager(path))`\n- Managers reported separately (Conda, Mamba) but environments remain `PythonEnvironmentKind::Conda`\n- Support detection from history files and conda-meta directories\n","# PET Rust Locator Patterns & Conventions\n\nDomain knowledge for writing correct Rust code in the Python Environment Tools (PET) repository. Following these patterns prevents the most common review feedback and CI failures.\n\n## Locator Ordering (CRITICAL)\n\nThe order of locators in `create_locators()` in `crates\u002Fpet\u002Fsrc\u002Flocators.rs` determines identification priority. **More specific locators MUST come before generic ones.**\n\n### Priority Chain (required order):\n1. **Windows-specific:** Windows Store → Windows Registry → WinPython\n2. **Managed environments:** PyEnv → Pixi → Conda\n3. **Virtual envs (specific → generic):** Poetry → PipEnv → VirtualEnvWrapper → Venv → VirtualEnv\n4. **macOS-specific:** Homebrew → MacXCode → MacCmdLineTools → MacPythonOrg\n5. **Linux fallback:** LinuxGlobalPython (MUST BE LAST)\n\n**Why it matters:** If `Venv` runs before `Poetry`, a Poetry environment (which IS a venv) gets misidentified as a plain venv. The first locator whose `try_from()` returns `Some` wins.\n\n## Environment Identification (`try_from`)\n\nEach `try_from()` must be **precise enough to avoid false positives**:\n\n- **Poetry:** Match `{project-name}-{8-char-hash}-py{major}.{minor}` naming pattern AND verify location is in poetry cache dir\n- **Pipenv:** Look for `.project` file in centralized dir with hash-based naming\n- **Conda:** Require `conda-meta\u002F` directory with history file\n- **Pixi:** Require `.pixi\u002Fenvs\u002F` in path structure\n- **venv:** Check for `pyvenv.cfg` file (but many env types have this — venv is a fallback)\n- **VirtualEnv:** Activation scripts WITHOUT `pyvenv.cfg` (most generic, last resort)\n\n**Red flag:** A `try_from()` that only checks `pyvenv.cfg` existence — that matches ALL venvs, not just one type.\n\n## JSONRPC Protocol Rules\n\nThe server communicates via stdin\u002Fstdout. **Any stdout pollution breaks the protocol.**\n\n- **NEVER use `println!`** — it writes to stdout and corrupts JSONRPC messages\n- Use `log` crate macros: `info!()`, `trace!()`, `warn!()`, `error!()`\n- Log with elapsed time for diagnostic handlers (established pattern)\n- All tracing\u002Flogging writes to stderr via subscriber configuration\n\n## Thread Safety Patterns\n\nPET uses heavy concurrency for parallel discovery:\n\n- Shared state requires `Arc\u003CMutex\u003CT>>` or `Arc\u003CRwLock\u003CT>>`\n- Keep lock scopes minimal — clone data out, drop lock, then process\n- Use `.expect(\"context\")` on mutex locks, not bare `.unwrap()`\n- No nested locks (deadlock risk)\n- Consider `thread::scope` for structured concurrency\n\n## Platform-Specific Code\n\nUse `#[cfg(...)]` attributes for conditional compilation:\n\n```rust\n#[cfg(windows)]\nuse pet_windows_registry::WindowsRegistry;\n\n#[cfg(unix)]\nfn resolve_path(p: &Path) -> PathBuf { std::fs::canonicalize(p).unwrap_or(p.to_path_buf()) }\n\n#[cfg(target_os = \"macos\")]\nuse pet_homebrew::Homebrew;\n```\n\n**Do NOT use `if cfg!(windows) { ... }` for code that imports platform-specific modules** — the code inside still gets compiled on all platforms.\n\n### Platform Gotchas:\n- **Windows:** Avoid `canonicalize()` for directory junctions (breaks Scoop symlinks). Use `norm_case()` instead.\n- **macOS:** Homebrew has complex symlink chains; `resolve_symlink` before `canonicalize`\n- **Linux:** `\u002Fbin` may symlink to `\u002Fusr\u002Fbin` — handle both\n\n## Version Detection (Prefer File-Based)\n\n**Order of preference (cheapest first):**\n1. `pyvenv.cfg` — `version` or `version_info` field\n2. `conda-meta\u002Fpython-*.json` — package metadata\n3. `Include\u002Fpatchlevel.h` — CPython source header\n4. Parse from executable path (e.g., `python3.11`)\n5. Spawn Python `--version` — **LAST RESORT** (expensive, defeats PET's purpose)\n\n## Path & Symlink Handling\n\n- Use `pet_fs::path::resolve_symlink()` — the project's own resolver\n- For comparison: `canonicalize().unwrap_or(original)` then `norm_case()` for Windows UNC prefix handling\n- Preserve original user-facing paths; resolve only for identification\n\n## Testing Conventions\n\n- Feature-gated CI tests: `#[cfg_attr(feature = \"ci\", test)]` with `#[allow(dead_code)]`\n- Feature flags: `ci`, `ci-poetry-global`, `ci-jupyter-container`, `ci-homebrew-container`\n- Verification pattern: spawn Python, use `try_from()`, test symlinks, use `resolve`\n- Use `cargo test --features ci` for CI-gated tests\n\n## Serialization\n\n- All JSON-serialized structs use `#[serde(rename_all = \"camelCase\")]`\n- Matches the JSONRPC API conventions consumed by VS Code Python extension\n\n## Pre-Commit Requirements\n\nAlways run before committing:\n```bash\ncargo fmt --all\ncargo clippy --all -- -D warnings\n```\nNever suppress clippy warnings with `#[allow(...)]` without justification.\n\n## Conda-Specific Patterns\n\n- Conda manager detection takes precedence over mamba: `get_conda_manager(path).or_else(|| get_mamba_manager(path))`\n- Managers reported separately (Conda, Mamba) but environments remain `PythonEnvironmentKind::Conda`\n- Support detection from history files and conda-meta directories\n",{"name":5,"description":7},"main","02dd29e49e3c71d4ec06e1072d6331494a12e01d",".github\u002Fskills\u002Frust-locator-patterns",48,"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools","https:\u002F\u002Fgithub.com\u002Fmicrosoft","https:\u002F\u002Fopensource.microsoft.com","Open source projects and samples from Microsoft","2026-11-10 02:07:34",{"source":9,"skillName":5,"commands":52,"prompt":62,"zipAvailable":63},[53,56,59],{"tool":54,"command":55},"npx","npx skills add microsoft\u002Fpython-environment-tools --skill rust-locator-patterns",{"tool":57,"command":58},"bunx","bunx skills add microsoft\u002Fpython-environment-tools --skill rust-locator-patterns",{"tool":60,"command":61},"pnpm","pnpm dlx skills add microsoft\u002Fpython-environment-tools --skill rust-locator-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-locator-patterns\u002FSKILL.md",true,[],[66,81],{"skillNo":67,"name":68,"nameZh":69,"description":70,"descriptionZh":71,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":72,"categories":73,"keywords":76,"publishedAt":37},"01M69BNM2MW8C61MRH902Q9BRQ","rust-precommit","Rust 预提交检查","Run the mandatory PET Rust pre-commit checks (cargo fmt + cargo clippy -D warnings) before every commit. Invoke whenever you are about to commit Rust changes, after applying review feedback, or whenever you need to verify formatting and lint cleanliness.","在每次提交前运行强制性的 PET Rust 预提交检查（cargo fmt + cargo clippy -D warnings）。当即将提交 Rust 更改、应用审查反馈后，或需要验证格式和 lint 是否干净时调用。","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-precommit\u002FSKILL.md",[74,75],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},[31,77,34,78,79,80],"rust precommit","commit","run","lint",{"skillNo":82,"name":83,"nameZh":84,"description":85,"descriptionZh":86,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":87,"categories":88,"keywords":91,"publishedAt":37},"01M69BNGJAVCG7WA93S1NK68AW","rust-coding-skill","PET 项目 Rust 编码","Use whenever editing Rust in PET to write allocation-aware, cross-platform, byte-safe code with behavior-proving tests.","在 PET 中编辑 Rust 代码时使用，以编写具备分配感知、跨平台、字节安全的代码，并附带可证明行为正确性的测试。","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-coding-skill\u002FSKILL.md",[89,90],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},[31,92,93,36],"rust coding skill","safe"]