platform_adapter

A set of rules for adapting commands, paths, environment settings, and errors to the operating system in use. It detects Linux, macOS, Windows, and WSL, which is Windows running a Linux environment.

In plain words
What is it for?
Use it when writing automation or development rules that must choose platform-specific commands, normalize paths, detect the current system, or adjust configuration and error handling.
Why use it?
Commands, path formats, shells, permissions, and line endings differ between operating systems. Shared project rules can therefore fail unless they account for those differences.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/wangqiqi/cursor-ai-rules/platform_adapter
Clone the repo
git clone --depth 1 https://github.com/wangqiqi/cursor-ai-rules

Made for: Cursor.

Per session 2,698 This file is loaded in full into every session.
When invoked 2,698 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02698 $0.02698
Opus 5 $0.01349 $0.01349
Sonnet 5 $0.00540 $0.00540
Haiku 4.5 $0.00270 $0.00270

Measured 2d ago against content hash a1c304792722, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

platform_adapter scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/system/platform_adapter.mdc · 424 lines

How it starts

The opening of the file, as written. The whole thing — 424 lines — stays where its author put it; the contents beside it link to each section on GitHub.

🌐 跨平台适配器 (Cross-platform Adapter)

版本: v4.3.0 | 最后更新: {{GENERATION_TIME}} | 作者: wangqiqi (https://github.com/wangqiqi)

🎯 核心使命 (Core Mission)

跨平台适配器统一管理.cursor规则体系在不同操作系统间的适配逻辑,确保:

  • 命令兼容性:自动选择适合当前平台的命令和参数
  • 路径规范化:统一处理不同操作系统的路径格式
  • 环境适配:根据操作系统特征调整行为和配置
  • 错误处理:平台特定的错误信息和恢复策略

🔍 平台检测 (Platform Detection)

操作系统识别 (OS Identification)

# 自动检测当前操作系统
detect_platform() {
    case "$(uname -s)" in
        Linux*)     PLATFORM="linux";;
        Darwin*)    PLATFORM="macos";;
        CYGWIN*|MINGW*|MSYS*) PLATFORM="windows";;
        *)          PLATFORM="unknown";;
    esac

    # Windows特殊处理:检测是否在WSL环境中
    if [[ "$PLATFORM" == "linux" ]] && [[ -n "$WSL_DISTRO_NAME" ]]; then
        PLATFORM="wsl"
    fi

    echo "$PLATFORM"
}

平台特征矩阵 (Platform Feature Matrix)

{
  "platform_features": {
    "linux": {
      "shell": "bash",
      "path_separator": "/",
      "case_sensitive": true,
      "permissions": "unix",
      "package_manager": ["apt", "yum", "dnf", "pacman"],
      "line_ending": "LF"
    },
    "macos": {
      "shell": "zsh",
      "path_separator": "/",
      "case_sensitive": false,
      "permissions": "unix",
      "package_manager": ["brew", "port"],
      "line_ending": "LF"
    },
    "windows": {
      "shell": "powershell",
      "path_separator": "\\",
      "case_sensitive": false,
      "permissions": "windows",
      "package_manager": ["choco", "winget", "scoop"],
      "line_ending": "CRLF"
    },
    "wsl": {
      "shell": "bash",
      "path_separator": "/",
      "case_sensitive": true,
      "permissions": "unix",
      "package_manager": ["apt"],
      "line_ending": "LF",
      "special_features": ["windows_integration"]
    }
  }
}

💻 命令适配 (Command Adaptation)

核心命令映射 (Core Command Mapping)

interface CommandMapping {
  [command: string]: {
    linux: string;
    macos: string;
    windows: string;
    wsl?: string;
  };
}

const commandMappings: CommandMapping = {
  "get_timestamp": {
    linux: "date '+%Y-%m-%d %H:%M:%S %Z'",
    macos: "date '+%Y-%m-%d %H:%M:%S %Z'",
    windows: "powershell -Command \"Get-Date -Format 'yyyy-MM-dd HH:mm:ss zzz'\"",
    wsl: "date '+%Y-%m-%d %H:%M:%S %Z'"
  },
  "get_user_name": {
    linux: "git config --get user.name",
    macos: "git config --get user.name",
    windows: "git config --get user.name",
    wsl: "git config --get user.name"
  },
  "get_user_email": {
    linux: "git config --get user.email",
    macos: "git config --get user.email",
    windows: "git config --get user.email",
    wsl: "git config --get user.email"
  },
  "list_directory": {
    linux: "ls -la",
    macos: "ls -la",
    windows: "powershell -Command \"Get-ChildItem -Force\"",
    wsl: "ls -la"
  },
  "create_directory": {
    linux: "mkdir -p",
    macos: "mkdir -p",
    windows: "powershell -Command \"New-Item -ItemType Directory -Force\"",
    wsl: "mkdir -p"
  }
};

Read the full file on GitHub · 424 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 424 lines · 2,698 tokens per session scan A a1c304792722

Subscribe to this mod's changes

platform_adapter is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (15 stars, last pushed 3mo ago), licensed MIT. It adds 2,698 tokens to every session, about $0.0135 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.