@lilmgenius/win-hooks 1.11.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -67
- package/bin/win-hooks.mjs +70 -20
- package/hooks/codex-hooks.json +3 -3
- package/hooks/hooks.json +1 -1
- package/hooks/run-hook.cmd +15 -20
- package/hooks/win-hooks +3 -5
- package/package.json +4 -12
- package/src/heal.mjs +7 -6
- package/src/hosts.mjs +21 -3
- package/src/rules.mjs +15 -0
- package/src/verify.mjs +1 -2
package/README.md
CHANGED
|
@@ -6,31 +6,21 @@
|
|
|
6
6
|
|
|
7
7
|
**Windows auto-patcher for vibe coders.**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
win-hooks repairs the plugin hooks that break on your Windows machine.<br>
|
|
10
|
+
Automatically, at every session start, and again for ones added later.
|
|
11
11
|
|
|
12
|
-
[](https://www.microsoft.com/windows)
|
|
13
|
+
[](https://docs.anthropic.com/en/docs/claude-code)
|
|
14
|
+
[](https://developers.openai.com/codex)
|
|
15
|
+
[](LICENSE)
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Install
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
SessionStart hook error: /bin/bash: command not found
|
|
25
|
-
PreToolUse hook error: scripts/check.sh: No such file or directory
|
|
26
|
-
PostToolUse hook error: semgrep: command not found
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
You installed a plugin. It works fine for everyone on a Mac. On your machine it greets you with red text every single time you open a session.
|
|
30
|
-
|
|
31
|
-
Nothing is broken on your end. Almost every plugin is written and tested on macOS or Linux, so its hooks quietly assume Unix tools that Windows does not have. You are not supposed to fix that by hand. **win-hooks does it for you.**
|
|
32
|
-
|
|
33
|
-
## Install it once, forget it exists
|
|
23
|
+
Pick your tool and paste one line.
|
|
34
24
|
|
|
35
25
|
**Claude Code**
|
|
36
26
|
|
|
@@ -44,16 +34,19 @@ claude plugin marketplace add LilMGenius/win-hooks && claude plugin install win-
|
|
|
44
34
|
codex plugin marketplace add LilMGenius/win-hooks && codex plugin add win-hooks@win-hooks
|
|
45
35
|
```
|
|
46
36
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Prefer a one-shot fix, or need it in CI? Skip the plugin and run it directly:
|
|
37
|
+
**Neither, just fix my plugins now**
|
|
50
38
|
|
|
51
39
|
```bash
|
|
52
|
-
npx @lilmgenius/win-hooks
|
|
53
|
-
npx @lilmgenius/win-hooks status # show what it found last time
|
|
40
|
+
npx @lilmgenius/win-hooks
|
|
54
41
|
```
|
|
55
42
|
|
|
56
|
-
|
|
43
|
+
That's the whole setup. No config, no flags, nothing to remember.
|
|
44
|
+
|
|
45
|
+
You need Windows 10/11 and [Git for Windows](https://git-scm.com/download/win). Node.js already comes with Claude Code and Codex.
|
|
46
|
+
|
|
47
|
+
## What it fixes
|
|
48
|
+
|
|
49
|
+
You installed a plugin. It works fine for everyone on a Mac. On your machine it greets you with red text every time you open a session.
|
|
57
50
|
|
|
58
51
|
| The error you see | What was wrong |
|
|
59
52
|
|---|---|
|
|
@@ -64,58 +57,23 @@ npx @lilmgenius/win-hooks status # show what it found last time
|
|
|
64
57
|
| `JSON Parse error: Unrecognized token` | An invisible byte (BOM) at the top of a config file |
|
|
65
58
|
| `Cannot find module 'C:\Users...'` | Backslashes in a path getting eaten before the hook runs |
|
|
66
59
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## Staying fixed
|
|
60
|
+
None of that is your fault. Almost every plugin is written and tested on macOS or Linux, so its hooks assume Unix tools that Windows does not have.
|
|
70
61
|
|
|
71
|
-
|
|
72
|
-
flowchart LR
|
|
73
|
-
A[scan installed plugins] --> B[patch broken hooks] --> C[verify & auto-repair]
|
|
74
|
-
```
|
|
62
|
+
## How it stays fixed
|
|
75
63
|
|
|
76
|
-
|
|
64
|
+
win-hooks repairs your plugins at every session start, including ones you install later and ones that break again after an update. Repairs are written next to the original file, never on top of it, and anything already working is left alone.
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
npx @lilmgenius/win-hooks status
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Or, inside a session:
|
|
66
|
+
At the start of a session it says so in one line, so you can tell a clean run from a hook that never fired. To look closer:
|
|
85
67
|
|
|
86
68
|
| Command | What it does |
|
|
87
69
|
|---|---|
|
|
88
|
-
| `/win-hooks:
|
|
89
|
-
|
|
|
90
|
-
|
|
91
|
-
## Requirements
|
|
92
|
-
|
|
93
|
-
Windows 10/11, and [Git for Windows](https://git-scm.com/download/win) — which you almost certainly already have. Node.js comes with Claude Code and Codex.
|
|
70
|
+
| `/win-hooks:patch` | Checks every plugin, shows what it found, repairs anything broken |
|
|
71
|
+
| `npx @lilmgenius/win-hooks patch` | The same, from any terminal |
|
|
94
72
|
|
|
95
73
|
## Privacy
|
|
96
74
|
|
|
97
|
-
win-hooks runs entirely on your machine and sends nothing anywhere. No telemetry, no network calls, no account.
|
|
98
|
-
|
|
99
|
-
## For the curious
|
|
100
|
-
|
|
101
|
-
win-hooks never edits a plugin's own scripts. It writes a small `_hooks/` directory next to them, containing one wrapper per broken hook plus a single `run-hook.cmd` — a file that is valid batch *and* valid shell at once, so Windows and Git Bash can each run the same entry point. The plugin's `hooks.json` is then pointed at the wrapper, with the original saved as `hooks.json.bak`.
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
plugin/
|
|
105
|
-
├── hooks/
|
|
106
|
-
│ ├── hooks.json → now points at the wrapper
|
|
107
|
-
│ └── hooks.json.bak → your original, untouched
|
|
108
|
-
└── _hooks/
|
|
109
|
-
├── run-hook.cmd → batch + shell polyglot entry point
|
|
110
|
-
└── check → resolves the real interpreter, then execs
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Codex works the same way, with one difference: it has a native `commandWindows` field, so win-hooks *adds* the Windows command instead of replacing the portable one. Your plugins keep working unchanged on macOS and Linux.
|
|
114
|
-
|
|
115
|
-
Wrapper filenames are deliberately extensionless (`check`, not `check.sh`) — Claude Code auto-prepends `bash` to anything containing `.sh` on Windows, which would undo the fix.
|
|
116
|
-
|
|
117
|
-
Contributors: [`AGENTS.md`](AGENTS.md) documents every failure mode win-hooks handles, with the root cause behind each one.
|
|
75
|
+
win-hooks runs entirely on your machine and sends nothing anywhere. No telemetry, no network calls, no account. Outside a plugin's own folder it writes only a short local log of its own runs, so you can confirm it ran.
|
|
118
76
|
|
|
119
77
|
## License
|
|
120
78
|
|
|
121
|
-
[MIT](LICENSE).
|
|
79
|
+
[MIT](LICENSE). How it works, and every failure mode it handles: [`AGENTS.md`](AGENTS.md).
|
package/bin/win-hooks.mjs
CHANGED
|
@@ -2,26 +2,28 @@
|
|
|
2
2
|
// win-hooks CLI - the single entry point. The plugin's own SessionStart and
|
|
3
3
|
// UserPromptSubmit hooks land here too, via hooks/run-hook.cmd -> hooks/win-hooks.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// heal [host] silent repair; --changed-only skips when no plugin's hooks
|
|
6
|
+
// changed since the last run (the near-free per-prompt guard);
|
|
7
|
+
// --announce speaks the result into the session (CASE-32)
|
|
8
|
+
// status [host] report, change nothing
|
|
9
|
+
// patch [host] report, repair what is not healthy, prove the result
|
|
8
10
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
11
|
+
// Progress goes to stderr, never stdout: a UserPromptSubmit hook's stdout is
|
|
12
|
+
// injected into the model's context. `status`, `patch`, and an announced heal
|
|
13
|
+
// are the exceptions - a person asked for the first two, and the third is a
|
|
14
|
+
// session-start hook, whose stdout both hosts inject into the session as it
|
|
15
|
+
// stands (CASE-32).
|
|
14
16
|
|
|
15
17
|
import { isWindows } from '../src/env.mjs';
|
|
16
18
|
import { HOSTS } from '../src/hosts.mjs';
|
|
17
19
|
import { heal, inspect } from '../src/heal.mjs';
|
|
18
20
|
|
|
19
|
-
const USAGE = 'usage: win-hooks [heal|status] [claude|codex] [--changed-only]';
|
|
21
|
+
const USAGE = 'usage: win-hooks [heal|status|patch] [claude|codex] [--changed-only] [--announce]';
|
|
20
22
|
|
|
21
23
|
const args = process.argv.slice(2);
|
|
22
24
|
const flags = new Set(args.filter((a) => a.startsWith('--')));
|
|
23
25
|
const words = args.filter((a) => !a.startsWith('--'));
|
|
24
|
-
const command = ['heal', 'status'].includes(words[0]) ? words.shift() : 'heal';
|
|
26
|
+
const command = ['heal', 'status', 'patch'].includes(words[0]) ? words.shift() : 'heal';
|
|
25
27
|
const hostIds = words.length ? words : Object.keys(HOSTS);
|
|
26
28
|
|
|
27
29
|
if (hostIds.some((id) => !HOSTS[id])) {
|
|
@@ -35,21 +37,35 @@ if (!isWindows()) {
|
|
|
35
37
|
process.exit(0);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
if (command
|
|
39
|
-
console.log(hostIds.map(
|
|
40
|
+
if (command !== 'heal') {
|
|
41
|
+
console.log(hostIds.map(command === 'patch' ? patchHost : statusOf).join('\n\n'));
|
|
40
42
|
process.exit(0);
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
const announce = flags.has('--announce');
|
|
46
|
+
|
|
43
47
|
for (const id of hostIds) {
|
|
44
48
|
try {
|
|
45
49
|
const result = heal(id, { changedOnly: flags.has('--changed-only') });
|
|
46
|
-
if (result)
|
|
50
|
+
if (!result) continue;
|
|
51
|
+
const lines = summarize(result);
|
|
52
|
+
if (announce) lines.unshift(announcement(result));
|
|
53
|
+
for (const line of lines) (announce ? console.log : console.error)(line);
|
|
47
54
|
} catch (e) {
|
|
48
55
|
// One broken host must not take the session down with it.
|
|
49
56
|
console.error('win-hooks: ' + HOSTS[id].label + ' repair failed - ' + e.message);
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
|
|
60
|
+
// One line a person can read at session start. A silent happy path is
|
|
61
|
+
// indistinguishable from a hook the host never dispatched, and the run log
|
|
62
|
+
// cannot separate them either, since a manual repair writes the same line
|
|
63
|
+
// (CASE-32). Said once per session, never per prompt.
|
|
64
|
+
function announcement({ host, scanned, patched, issues, fixes }) {
|
|
65
|
+
return 'win-hooks: ' + host.label + ' - ' + scanned + ' hook file(s) checked, '
|
|
66
|
+
+ patched.length + ' repaired, ' + Math.max(issues.length - fixes.length, 0) + ' issue(s) open';
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
function summarize({ host, patched, failed, settings, issues, fixes }) {
|
|
54
70
|
const lines = [];
|
|
55
71
|
for (const p of patched) lines.push('win-hooks: patched ' + p.plugin.id + ' (' + p.wrappers.join(', ') + ')');
|
|
@@ -60,20 +76,54 @@ function summarize({ host, patched, failed, settings, issues, fixes }) {
|
|
|
60
76
|
lines.push('win-hooks: repairs are on disk - run /reload-plugins to apply them to this session.');
|
|
61
77
|
}
|
|
62
78
|
const unresolved = issues.length - fixes.length;
|
|
63
|
-
if (unresolved > 0) lines.push('win-hooks: ' + unresolved + ' issue(s) need attention - run /win-hooks:
|
|
79
|
+
if (unresolved > 0) lines.push('win-hooks: ' + unresolved + ' issue(s) need attention - run /win-hooks:patch');
|
|
64
80
|
return lines;
|
|
65
81
|
}
|
|
66
82
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
// One verb, because nobody inspects hooks for their own sake: a healthy host
|
|
84
|
+
// leaves nothing to decide and a broken one was always going to be repaired,
|
|
85
|
+
// so splitting the two only asks the user which one they needed (CASE-30).
|
|
86
|
+
function patchHost(id) {
|
|
87
|
+
const before = inspect(id);
|
|
88
|
+
if (healthy(before)) return report(before) + heartbeat(before);
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
heal(id);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return report(before) + '\n\n repair failed - ' + e.message;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const after = inspect(id);
|
|
97
|
+
return report(before) + '\n\n' + report(after, 'after repair') + heartbeat(after)
|
|
98
|
+
+ '\n repairs are on disk - run /reload-plugins to apply them to this session.';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Every function below is a declaration, not a const: the dispatch above runs
|
|
102
|
+
// before this point in the module, and only declarations are hoisted.
|
|
103
|
+
function statusOf(id) {
|
|
104
|
+
const state = inspect(id);
|
|
105
|
+
return report(state) + heartbeat(state);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function healthy({ incompatible, issues, settings }) {
|
|
109
|
+
return !incompatible.length && !issues.length && !settings.length;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function report({ host, plugins, incompatible, issues, settings }, heading) {
|
|
113
|
+
const title = '# ' + host.label + (heading ? ' ' + heading : '')
|
|
114
|
+
+ ' - ' + plugins.length + ' hook file(s) scanned';
|
|
115
|
+
const lines = [title];
|
|
70
116
|
|
|
71
117
|
for (const i of incompatible) lines.push(' incompatible ' + i.id + ' [' + i.event + '] ' + i.command);
|
|
72
118
|
for (const i of issues) lines.push(' ' + i.type.padEnd(14) + i.plugin + ' ' + i.detail);
|
|
73
119
|
for (const s of settings) lines.push(' ' + s.type.padEnd(14) + s.path + ' ' + s.to);
|
|
74
120
|
if (lines.length === 1) lines.push(' healthy - every hook is Windows-compatible');
|
|
75
|
-
|
|
76
|
-
lines.push('', ' last runs:');
|
|
77
|
-
lines.push(...(log.length ? log.map((l) => ' ' + l) : [' (never run)']));
|
|
78
121
|
return lines.join('\n');
|
|
79
122
|
}
|
|
123
|
+
|
|
124
|
+
// The happy path is silent, so the run log is the only way to tell a healthy
|
|
125
|
+
// host apart from a hook that never dispatched at all (CASE-25).
|
|
126
|
+
function heartbeat({ log }) {
|
|
127
|
+
return '\n\n last runs:\n'
|
|
128
|
+
+ (log.length ? log.map((l) => ' ' + l) : [' (never run)']).join('\n');
|
|
129
|
+
}
|
package/hooks/codex-hooks.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "bash \"${PLUGIN_ROOT}/hooks/win-hooks\" heal codex",
|
|
10
|
-
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex",
|
|
9
|
+
"command": "bash \"${PLUGIN_ROOT}/hooks/win-hooks\" heal codex --announce",
|
|
10
|
+
"commandWindows": "cmd /c \"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex --announce",
|
|
11
11
|
"timeout": 60,
|
|
12
12
|
"statusMessage": "win-hooks: checking Codex plugin hooks"
|
|
13
13
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
{
|
|
21
21
|
"type": "command",
|
|
22
22
|
"command": "bash \"${PLUGIN_ROOT}/hooks/win-hooks\" heal codex --changed-only",
|
|
23
|
-
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex --changed-only",
|
|
23
|
+
"commandWindows": "cmd /c \"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex --changed-only",
|
|
24
24
|
"timeout": 20,
|
|
25
25
|
"statusMessage": "win-hooks: checking changed Codex plugin hooks"
|
|
26
26
|
}
|
package/hooks/hooks.json
CHANGED
package/hooks/run-hook.cmd
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
: << 'CMDBLOCK'
|
|
2
2
|
@echo off
|
|
3
|
-
REM The entry point every patched hook is dispatched through
|
|
4
|
-
REM
|
|
5
|
-
REM
|
|
6
|
-
REM
|
|
7
|
-
REM
|
|
8
|
-
REM
|
|
9
|
-
REM Wrapper names are extensionless because Claude Code prepends "bash" to any
|
|
10
|
-
REM command containing .sh on Windows, which would undo the patch (CASE-07).
|
|
3
|
+
REM The entry point every patched hook is dispatched through: one file that is
|
|
4
|
+
REM valid batch AND valid bash at once, so Claude Code and Codex can each
|
|
5
|
+
REM dispatch it their own way. cmd.exe runs the batch block below; bash treats
|
|
6
|
+
REM it as a quoted here-doc and falls through to the tail. Wrapper names are
|
|
7
|
+
REM extensionless because Claude Code prepends "bash" to any command containing
|
|
8
|
+
REM .sh, which would undo the patch (CASE-07).
|
|
11
9
|
REM
|
|
12
10
|
REM Usage: run-hook.cmd <script-name> [args...]
|
|
13
11
|
|
|
@@ -19,8 +17,7 @@ if "%~1"=="" (
|
|
|
19
17
|
set "HOOK_DIR=%~dp0"
|
|
20
18
|
set "WH_BASH="
|
|
21
19
|
|
|
22
|
-
REM Explicit override first
|
|
23
|
-
REM does not already look, e.g. a portable, scoop, or winget Git install.
|
|
20
|
+
REM Explicit override first, for a portable, scoop, or winget Git install.
|
|
24
21
|
if defined WH_BASH_EXE if exist "%WH_BASH_EXE%" set "WH_BASH=%WH_BASH_EXE%"
|
|
25
22
|
|
|
26
23
|
REM Then Git for Windows, which is where it almost always is.
|
|
@@ -29,19 +26,17 @@ if not defined WH_BASH if exist "C:\Program Files (x86)\Git\bin\bash.exe" set "W
|
|
|
29
26
|
|
|
30
27
|
if defined WH_BASH goto :run
|
|
31
28
|
|
|
32
|
-
REM Finally PATH (MSYS2, Cygwin, a nonstandard install)
|
|
33
|
-
REM path-search modifier below
|
|
34
|
-
REM
|
|
35
|
-
REM a comment mentioning it is a syntax error.
|
|
29
|
+
REM Finally PATH (MSYS2, Cygwin, a nonstandard install), resolved by the FOR
|
|
30
|
+
REM path-search modifier below - `where` costs a subprocess. Never name that
|
|
31
|
+
REM modifier in a REM: cmd.exe expands it there too and the comment breaks.
|
|
36
32
|
for %%I in (bash.exe) do set "WH_BASH=%%~$PATH:I"
|
|
37
33
|
if not defined WH_BASH goto :nobash
|
|
38
34
|
|
|
39
|
-
REM PATH bash is often C:\Windows\System32\bash.exe, the WSL launcher
|
|
40
|
-
REM cannot open Windows paths
|
|
41
|
-
REM forever.
|
|
42
|
-
REM run (CASE-29)
|
|
43
|
-
REM
|
|
44
|
-
REM WSL's launcher does not forward $0 the way a real bash does.
|
|
35
|
+
REM PATH bash is often C:\Windows\System32\bash.exe, the WSL launcher: it
|
|
36
|
+
REM cannot open Windows paths yet still exits 0, so it would swallow every hook
|
|
37
|
+
REM forever. A PATH candidate must prove it can see the script it is about to
|
|
38
|
+
REM run (CASE-29); the paths above are known-good. The probe travels through
|
|
39
|
+
REM the environment because WSL does not forward $0 the way a real bash does.
|
|
45
40
|
set "WH_PROBE=%HOOK_DIR%%~1"
|
|
46
41
|
"%WH_BASH%" -c "test -f \"$WH_PROBE\"" >nul 2>&1
|
|
47
42
|
if errorlevel 1 goto :nobash
|
package/hooks/win-hooks
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
# The bridge from a hook dispatch to the engine.
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# its own engine exactly the way a patched plugin reaches its wrapper - if this
|
|
6
|
-
# path works here, it works there.
|
|
2
|
+
# The bridge from a hook dispatch to the engine. win-hooks reaches its own
|
|
3
|
+
# engine exactly the way a patched plugin reaches its wrapper, so if this path
|
|
4
|
+
# works here it works there.
|
|
7
5
|
#
|
|
8
6
|
# Fail-safe: a missing runtime means no repair, never a broken session.
|
|
9
7
|
command -v node >/dev/null 2>&1 || exit 0
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lilmgenius/win-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "Windows auto-patcher for vibe coders.",
|
|
8
|
+
"longDescription": "win-hooks scans the Claude Code and Codex plugins installed on a Windows machine and repairs the hooks that cannot run there: .sh scripts cmd.exe cannot execute, bare Unix commands and interpreters that do not resolve, UTF-8 BOMs, and backslash paths. It repairs at every session start and again whenever a plugin update reverts a fix, so plugins installed later are covered too.",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"test": "node test/run.mjs"
|
|
10
11
|
},
|
|
@@ -38,14 +39,5 @@
|
|
|
38
39
|
"bugs": {
|
|
39
40
|
"url": "https://github.com/LilMGenius/win-hooks/issues"
|
|
40
41
|
},
|
|
41
|
-
"keywords": [
|
|
42
|
-
"windows",
|
|
43
|
-
"hooks",
|
|
44
|
-
"claude-code",
|
|
45
|
-
"codex",
|
|
46
|
-
"compatibility",
|
|
47
|
-
"patch",
|
|
48
|
-
"cli",
|
|
49
|
-
"cross-platform"
|
|
50
|
-
]
|
|
42
|
+
"keywords": ["windows","hooks","claude-code","codex","plugin","compatibility","patch","cli","winux"]
|
|
51
43
|
}
|
package/src/heal.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Orchestration: the one code path every surface goes through - the plugin's
|
|
2
2
|
// own hooks, the CLI, and the slash commands.
|
|
3
3
|
//
|
|
4
|
-
// Two rules govern this file.
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
4
|
+
// Two rules govern this file. It prints nothing itself: a UserPromptSubmit
|
|
5
|
+
// hook's stdout is injected into the model's context, so progress chatter
|
|
6
|
+
// would silently poison every prompt. The one place that is a feature rather
|
|
7
|
+
// than a hazard is session start, and only the CLI decides that, from
|
|
8
|
+
// --announce (CASE-32). And an environmental failure degrades to a no-op
|
|
9
|
+
// rather than breaking the session it exists to protect.
|
|
9
10
|
|
|
10
11
|
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
12
|
import { join, dirname } from 'node:path';
|
|
@@ -99,7 +100,7 @@ export function heal(hostId, { changedOnly = false } = {}) {
|
|
|
99
100
|
issues: issues.length,
|
|
100
101
|
});
|
|
101
102
|
|
|
102
|
-
return { host, patched, failed, settings, issues, fixes };
|
|
103
|
+
return { host, scanned: plugins.length, patched, failed, settings, issues, fixes };
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
// Report without touching anything.
|
package/src/hosts.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
10
10
|
import { existsSync } from 'node:fs';
|
|
11
11
|
import { join, resolve } from 'node:path';
|
|
12
12
|
import { HOME, readJson, toPosix } from './env.mjs';
|
|
13
|
+
import { DISPATCH_PREFIX, opensWithQuotedPath } from './rules.mjs';
|
|
13
14
|
|
|
14
15
|
// Both hosts use the same hooks.json shape:
|
|
15
16
|
// { hooks: { <Event>: [ { hooks: [ { type: "command", command } ] } ] } }
|
|
@@ -66,6 +67,11 @@ const claude = {
|
|
|
66
67
|
sourceCommand: (hook) => hook.command,
|
|
67
68
|
patchedCommand: (hook) => hook.command,
|
|
68
69
|
applyPatch: (hook, ref) => { hook.command = ref; },
|
|
70
|
+
// The shells that may dispatch a command this host emits. Claude Code runs a
|
|
71
|
+
// Windows hook command through cmd.exe, the one shell that also accepts a
|
|
72
|
+
// quoted path in command position, so the reference below needs no prefix.
|
|
73
|
+
// The CASE-31 gate executes wrapperRef under every shell named here.
|
|
74
|
+
dispatchers: ['cmd'],
|
|
69
75
|
wrapperRef: (wrapper, args) =>
|
|
70
76
|
'"${CLAUDE_PLUGIN_ROOT}/_hooks/run-hook.cmd" ' + wrapper + (args ? ' ' + args : ''),
|
|
71
77
|
};
|
|
@@ -97,6 +103,13 @@ function listCodexPlugins() {
|
|
|
97
103
|
});
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
// A commandWindows this tool wrote before CASE-31 opens with a quoted path,
|
|
107
|
+
// which a PowerShell dispatcher cannot parse. It is ours to re-derive, so it
|
|
108
|
+
// counts as unpatched; a commandWindows a plugin author wrote is left alone.
|
|
109
|
+
const isStaleCodexPatch = (hook) =>
|
|
110
|
+
String(hook.commandWindows || '').replace(/\\/g, '/').includes('_codex_hooks/run-hook.cmd')
|
|
111
|
+
&& opensWithQuotedPath(hook.commandWindows);
|
|
112
|
+
|
|
100
113
|
const codex = {
|
|
101
114
|
id: 'codex',
|
|
102
115
|
label: 'Codex',
|
|
@@ -111,12 +124,17 @@ const codex = {
|
|
|
111
124
|
listPlugins: listCodexPlugins,
|
|
112
125
|
// A hook that already carries commandWindows is patched; leave the portable
|
|
113
126
|
// command alone so it still runs natively on macOS and Linux.
|
|
114
|
-
sourceCommand: (hook) => (hook.commandWindows ? null : hook.command),
|
|
127
|
+
sourceCommand: (hook) => (hook.commandWindows && !isStaleCodexPatch(hook) ? null : hook.command),
|
|
115
128
|
patchedCommand: (hook) => hook.commandWindows,
|
|
116
129
|
applyPatch: (hook, ref) => { hook.commandWindows = ref; },
|
|
117
|
-
// Codex
|
|
130
|
+
// Codex hands commandWindows to the session shell, which is cmd.exe or
|
|
131
|
+
// PowerShell depending on how the session was started - so the reference has
|
|
132
|
+
// to carry the CASE-31 prefix. The backslashes are for the cmd.exe that ends
|
|
133
|
+
// up running the wrapper.
|
|
134
|
+
dispatchers: ['cmd', 'powershell'],
|
|
118
135
|
wrapperRef: (wrapper, args) =>
|
|
119
|
-
'"${PLUGIN_ROOT}\\_codex_hooks\\run-hook.cmd" ' + wrapper
|
|
136
|
+
DISPATCH_PREFIX + '"${PLUGIN_ROOT}\\_codex_hooks\\run-hook.cmd" ' + wrapper
|
|
137
|
+
+ (args ? ' ' + args : ''),
|
|
120
138
|
};
|
|
121
139
|
|
|
122
140
|
export const HOSTS = { claude, codex };
|
package/src/rules.mjs
CHANGED
|
@@ -56,6 +56,21 @@ export function isIncompatible(cmd, { rootVar, isInstalled = () => true } = {})
|
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// CASE-31: the shell that dispatches a hook command is the host's choice, not
|
|
60
|
+
// ours. Every Windows shell runs a bare command name in command position, but
|
|
61
|
+
// only cmd.exe also accepts a quoted path there - PowerShell reads the leading
|
|
62
|
+
// quote as a string expression and rejects every argument after it. A command
|
|
63
|
+
// that has to survive an unknown dispatcher therefore opens with cmd /c, which
|
|
64
|
+
// is a command name under both and hands the quoted path to the cmd.exe that
|
|
65
|
+
// was wanted all along.
|
|
66
|
+
export const DISPATCH_PREFIX = 'cmd /c ';
|
|
67
|
+
|
|
68
|
+
export const opensWithQuotedPath = (cmd) => /^["']/.test(decode(cmd).trim());
|
|
69
|
+
|
|
70
|
+
// Would this command survive every shell the host might dispatch it through?
|
|
71
|
+
export const isDispatchable = (cmd, dispatchers) =>
|
|
72
|
+
!opensWithQuotedPath(cmd) || dispatchers.every((shell) => shell === 'cmd');
|
|
73
|
+
|
|
59
74
|
// Wrapper filenames are extensionless, so Claude Code's Windows auto-detection
|
|
60
75
|
// does not prepend "bash" to anything containing ".sh" (CASE-07).
|
|
61
76
|
export function wrapperName(cmd, rootVar) {
|
package/src/verify.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Health check for already-patched plugins, with optional auto-repair.
|
|
2
2
|
//
|
|
3
3
|
// The issue types below are a closed vocabulary, shared verbatim with
|
|
4
|
-
// skills/
|
|
5
|
-
// all three.
|
|
4
|
+
// skills/patch/SKILL.md. Adding one means updating both.
|
|
6
5
|
|
|
7
6
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'node:fs';
|
|
8
7
|
import { join } from 'node:path';
|