ps-compat
PowerShell 5.1/7 compatibility + encoding pre-write checklist - consolidates anti-patterns #10/#13/#14/#16/#20, GAP-2 hook incident, P1-1 CRLF false positives
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-10
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- ps-compat
- triggers
- powershell 5.1, ps5, ps7, ps compatibility, encoding, CRLF, BOM, PSSA, Join-Path, cmatch, requires, bash-safe
- changelog
- 2026-09-02 — created: consolidates ANTI-PATTERN-CATALOG #10/#13/#14/#16/#20 + GAP-2 + P1-1 CRLF trap
- description
- PowerShell 5.1/7 compatibility + encoding pre-write checklist - consolidates anti-patterns #10/#13/#14/#16/#20, GAP-2 hook incident, P1-1 CRLF false positives
- token_budget
- 3000
03 SKILL.md 正文
When to Use
- Before writing or modifying any
.ps1file. - Before writing regex that scans Windows-authored files (frontmatter, docs, logs).
- When a script must run in both PS5.1 hook context and PS7.
- When output shows mojibake or garbled text (encoding suspect).
Rules
- Declare runtime:
#requires -Version 7.0if PS7-only; PS5.1-compat → avoid ternary? :,&&/||,??. - PS5.1 rejects
&&/||— useif/thenor Invoke-Bash (scripts/bash-safe.ps1). - Join-Path: named params only (
-Path/-ChildPath), never >2 positional (anti-pattern #10). - Init accumulators before
+=:$errors = @()(#13). -matchis case-INSENSITIVE; use-cmatchwhen casing matters (#14).- Write
.ps1ASCII-only when possible; Unicode → UTF-8 with BOM; always-Encoding UTF8onGet/Set-Content/Out-File(#16). - Windows files:
\r?\nnot\n; multiline(?m)^— CRLF breaks^key:scans (P1-1: ~10 FPs, doc:31-46). - Regex alternation:
[|]not\|— gates raw-scan||as FP (#20). - Mojibake may be console codepage, NOT file corruption — verify bytes (hex/UTF8) before "fixing".
Verification
Invoke-ScriptAnalyzer -Path <script>.ps1clean (or documented baseline) before commit[Parser]::ParseFile('<script>.ps1', [ref]$null, [ref]$errors)→$errors.Count -eq 0- Encoding edits re-read with
Get-Content -Encoding UTF8: no U+FFFD mojibake - Regex validated against LF (
"n") + CRLF ("rn"`) samples — both match
Anti-Rationalization
| Rationalization | Red Flag | Check |
|---|---|---|
| "PS7-only, 5.1 rules legacy" | Skip chain/encoding rules | Hooks/CI may run PS5.1 (GAP-2 2026-09-01) |
"\\n works locally" |
LF-only scans | Windows = CRLF (P1-1 audit:46) |
| "Small script, skip #requires" | Missing version decl | Gate + cross-ref flag it |
Red Flags
- No
#requiresheader;Get-Contentw/o-Encodingon non-ASCII;\n-only scans on Windows files;&&for PS5.1; emptycatchon encoding ops -> STOP commit until each hit is fixed per Rules 1-9 (PS5.1 hook breakage is a BLOCKER).
Refs: quality-gate | command-wrapper | bash-safe (scripts/bash-safe.ps1) | ANTI-PATTERN-CATALOG.md:21,24,25,27,31 | docs/mejoras/2026-09-01-gap-scan-repo.md:17-21 | docs/mejoras/2026-09-01-p1-1-spec-audit.md:31-46
04 同仓库更多 Skills
web-quality-audit
Comprehensive web audit: performance, a11y, SEO, responsive, animation, design tokens.
ui-engine
UI system — Grid/Flexbox/@layer/:has(), container queries, compositor-only animation, OKLCH tokens, component patterns
baseline-ui
Anti-slop UI — layout, typography, responsive, animation, tokens. Use for cleanup or polish.
skill-creator
Create new AI agent skills following Agent Skills spec -- auto-bootstrap unknown tasks, define structure, register in AGENTS.md
senior-engineer
Apply senior engineering competencies — system design, trade-off analysis, delegation, mentoring, and tech debt strategy
prompt-engineering
Design effective prompts using SPEARS framework — scope, principles, examples, assertions, refinements, with ReAct and multi-agent patterns