[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M69BNJ1P2BKGDBMAZBT6S0AF":3,"skill-same:01M69BNJ1P2BKGDBMAZBT6S0AF":53},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":25,"linkOnly":26,"markdownContent":27,"markdownBody":28,"frontMatter":29,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":33,"repositoryHtmlUrl":34,"repositoryHomepageUrl":6,"ownerHtmlUrl":35,"ownerBlogUrl":36,"ownerDescription":37,"updatedAt":38,"install":39,"resources":52},"01M69BNJ1P2BKGDBMAZBT6S0AF","rust-locator-patterns",null,"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.","microsoft\u002Fpython-environment-tools","microsoft","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6154722?v=4","01M698VYDXZ6JW5WH3CRV650R8","Microsoft","01M69BNE8385D7YQ637S4PQEQ7",209,"MIT","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-locator-patterns\u002FSKILL.md",[],[19,20,21,22,23,24],"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":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add microsoft\u002Fpython-environment-tools --skill rust-locator-patterns",{"tool":45,"command":46},"bunx","bunx skills add microsoft\u002Fpython-environment-tools --skill rust-locator-patterns",{"tool":48,"command":49},"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,[],[54,65],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":25},"01M69BNM2MW8C61MRH902Q9BRQ","rust-precommit","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.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-precommit\u002FSKILL.md",[],[19,61,22,62,63,64],"rust precommit","commit","run","lint",{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":76,"publishedAt":25},"01M69BNGJAVCG7WA93S1NK68AW","rust-coding-skill","Use whenever editing Rust in PET to write allocation-aware, cross-platform, byte-safe code with behavior-proving tests.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fpython-environment-tools\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Frust-coding-skill\u002FSKILL.md",[71],{"categoryNo":72,"categoryName":73,"taxonomyType":74,"taxonomyTypeDesc":75},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[19,77,78,24],"rust coding skill","safe"]