fix(hooks): add Windows PowerShell 5.1 compatibility to install_hook_wrapper.ps1

`ConvertFrom-Json -AsHashtable` is PowerShell 7+ only, and the Windows 11
reference machine used to validate this PR ships with Windows PowerShell
5.1 only (no `pwsh` on PATH). Without this follow-up, running the
installer on stock Windows fails at the parse step and leaves the
installation half-applied.

- Fall back to a manual `PSCustomObject` -> `Hashtable` conversion when
  `-AsHashtable` raises, so the script parses the existing
  settings.local.json on both PS 5.1 and PS 7+.
- Normalize both hook buckets (`PreToolUse`, `PostToolUse`) and their
  inner `hooks` arrays as `System.Collections.ArrayList` before
  serialization. PS 5.1 `ConvertTo-Json` otherwise collapses
  single-element arrays into bare objects, which breaks the canonical
  PR #1524 shape.
- Create the `skills/continuous-learning/hooks` destination directory
  when it does not exist yet, and emit a clearer error if
  settings.local.json is missing entirely.
- Update `INSTALL-HOOK-WRAPPER-FIX-20260422.md` to document the PS 5.1
  compatibility guarantee and to cross-link PR #1542 (companion simple
  patcher).

Verified on Windows 11 / Windows PowerShell 5.1.26100.8115 by running
`powershell -NoProfile -ExecutionPolicy Bypass -File
docs/fixes/install_hook_wrapper.ps1` against a sandbox `$env:USERPROFILE`
and against the real settings.local.json. Both produce the canonical
PR #1524 shape with LF-only output.
This commit is contained in:
suusuu0927
2026-04-22 06:55:29 +09:00
parent c32f0fffb1
commit b6bce947f1
2 changed files with 116 additions and 9 deletions

View File

@@ -46,8 +46,21 @@ pwsh -File docs/fixes/install_hook_wrapper.ps1
The script backs up `settings.local.json` to
`settings.local.json.bak-<timestamp>` before writing.
## PowerShell 5.1 compatibility
`ConvertFrom-Json -AsHashtable` is PowerShell 7+ only. The script tries
`-AsHashtable` first and falls back to a manual `PSCustomObject`
`Hashtable` conversion on Windows PowerShell 5.1. Both hook buckets
(`PreToolUse`, `PostToolUse`) and their inner `hooks` arrays are
materialized as `System.Collections.ArrayList` before serialization, so
PS 5.1's `ConvertTo-Json` cannot collapse single-element arrays into
bare objects. Verified by running `powershell -NoProfile -File
docs/fixes/install_hook_wrapper.ps1` on a Windows 11 machine with only
Windows PowerShell 5.1 installed (no `pwsh`).
## Related
- PR #1524 — settings.local.json shape fix (same argv-dup root cause)
- PR #1511 — skip `AppInstallerPythonRedirector.exe` in observer python resolution
- PR #1539 — locale-independent `detect-project.sh`
- PR #1542`patch_settings_cl_v2_simple.ps1` companion fix