@lilmgenius/win-hooks 1.10.0 → 1.12.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 +36 -130
- package/bin/win-hooks.mjs +94 -60
- package/hooks/codex-hooks.json +7 -7
- package/hooks/hooks.json +4 -4
- package/hooks/run-hook.cmd +43 -30
- package/hooks/win-hooks +10 -0
- package/package.json +8 -13
- package/src/env.mjs +122 -0
- package/src/heal.mjs +125 -0
- package/src/hosts.mjs +122 -0
- package/src/patch.mjs +93 -0
- package/src/rules.mjs +129 -0
- package/src/settings.mjs +61 -0
- package/src/verify.mjs +196 -0
- package/hooks/codex-patch-all +0 -75
- package/hooks/patch-all +0 -169
- package/hooks/reheal +0 -71
- package/scripts/apply-patches +0 -250
- package/scripts/codex-apply-patches +0 -108
- package/scripts/codex-find-incompatible +0 -94
- package/scripts/codex-verify +0 -393
- package/scripts/find-incompatible +0 -82
- package/scripts/fix-backslash-paths +0 -94
- package/scripts/fix-bare-commands +0 -147
- package/scripts/lib/plugins.sh +0 -132
- package/scripts/sync-version +0 -42
- package/scripts/verify +0 -334
package/README.md
CHANGED
|
@@ -4,170 +4,76 @@
|
|
|
4
4
|
|
|
5
5
|
### *"Linux? Nah. WinUX!"*
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**Windows auto-patcher for vibe coders.**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
**win-hooks fixes that. Automatically. Every session.**
|
|
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.
|
|
12
11
|
|
|
13
|
-
[](https://www.microsoft.com/windows)
|
|
13
|
+
[](https://docs.anthropic.com/en/docs/claude-code)
|
|
14
|
+
[](https://developers.openai.com/codex)
|
|
15
|
+
[](LICENSE)
|
|
17
16
|
|
|
18
17
|
</div>
|
|
19
18
|
|
|
20
19
|
---
|
|
21
20
|
|
|
22
|
-
##
|
|
21
|
+
## Install
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
Pick your tool and paste one line.
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
SessionStart hook error: /bin/bash: command not found
|
|
28
|
-
PreToolUse hook error: scripts/check.sh: No such file or directory
|
|
29
|
-
PostToolUse hook error: semgrep: command not found
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
The plugin may be fine on macOS or Linux, but its hooks assume Unix tools, `.sh` scripts, or shell paths that Windows does not run directly.
|
|
33
|
-
|
|
34
|
-
## Quick Start
|
|
35
|
-
|
|
36
|
-
### Claude Code
|
|
37
|
-
|
|
38
|
-
Paste once:
|
|
25
|
+
**Claude Code**
|
|
39
26
|
|
|
40
27
|
```bash
|
|
41
28
|
claude plugin marketplace add LilMGenius/win-hooks && claude plugin install win-hooks
|
|
42
29
|
```
|
|
43
30
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### Codex
|
|
47
|
-
|
|
48
|
-
Paste once:
|
|
31
|
+
**Codex**
|
|
49
32
|
|
|
50
33
|
```bash
|
|
51
34
|
codex plugin marketplace add LilMGenius/win-hooks && codex plugin add win-hooks@win-hooks
|
|
52
35
|
```
|
|
53
36
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
### CLI (npm)
|
|
57
|
-
|
|
58
|
-
Want a one-shot fix, or to run it in CI, without installing the plugin? Run it directly:
|
|
37
|
+
**Neither, just fix my plugins now**
|
|
59
38
|
|
|
60
39
|
```bash
|
|
61
|
-
npx @lilmgenius/win-hooks
|
|
62
|
-
npx @lilmgenius/win-hooks status # show the last repair result
|
|
40
|
+
npx @lilmgenius/win-hooks
|
|
63
41
|
```
|
|
64
42
|
|
|
65
|
-
|
|
43
|
+
That's the whole setup. No config, no flags, nothing to remember.
|
|
66
44
|
|
|
67
|
-
|
|
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.
|
|
68
46
|
|
|
69
|
-
|
|
47
|
+
## What it fixes
|
|
70
48
|
|
|
71
|
-
It
|
|
72
|
-
|
|
73
|
-
- `.sh` scripts called directly from Windows
|
|
74
|
-
- missing Unix-only commands such as `semgrep` or `shellcheck`
|
|
75
|
-
- bare `node`, `python`, `python3`, `npx`, or `npm` commands that work in Git Bash but fail through Windows hook dispatch
|
|
76
|
-
- Windows backslash paths inside hook commands
|
|
77
|
-
- UTF-8 BOM, CRLF, invalid JSON, missing wrappers, and broken wrapper files
|
|
78
|
-
- `python3` hooks blocked by the Microsoft Store Python alias
|
|
79
|
-
|
|
80
|
-
Original plugin files are backed up where hooks are patched, and already-compatible plugins are skipped.
|
|
81
|
-
|
|
82
|
-
## How It Stays Fixed
|
|
83
|
-
|
|
84
|
-
win-hooks runs automatically at session start.
|
|
85
|
-
|
|
86
|
-
Claude Code pipeline:
|
|
87
|
-
|
|
88
|
-
```mermaid
|
|
89
|
-
flowchart LR
|
|
90
|
-
A[scan plugins] --> B[patch hooks.json] --> C[normalize settings.json] --> D["verify & auto-repair"]
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Codex pipeline:
|
|
94
|
-
|
|
95
|
-
```mermaid
|
|
96
|
-
flowchart LR
|
|
97
|
-
A[scan plugins] --> B["add commandWindows wrappers"] --> C["verify & auto-repair"]
|
|
98
|
-
```
|
|
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.
|
|
99
50
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
It also checks again on your next prompt after a plugin update. Use `/reload-plugins` when you want the repaired hook config loaded without starting a new session.
|
|
103
|
-
|
|
104
|
-
## Check Status
|
|
105
|
-
|
|
106
|
-
The normal path is silent, so win-hooks writes a small heartbeat log:
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
tail -n 5 ~/.claude/win-hooks/last-run.log
|
|
110
|
-
tail -n 5 ~/.codex/win-hooks/last-run.log
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
- `phase=done` means the self-heal completed.
|
|
114
|
-
- a lone `phase=start` means the run was cut off mid-way and should retry next session.
|
|
115
|
-
- no file means it has not dispatched yet.
|
|
116
|
-
|
|
117
|
-
You can also run:
|
|
118
|
-
|
|
119
|
-
```text
|
|
120
|
-
/win-hooks:status
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Commands
|
|
124
|
-
|
|
125
|
-
| Command | Description |
|
|
51
|
+
| The error you see | What was wrong |
|
|
126
52
|
|---|---|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
|
|
130
|
-
|
|
53
|
+
| `check.sh: No such file or directory` | Windows can't run a `.sh` script directly |
|
|
54
|
+
| `semgrep: command not found` | The plugin expects a Unix tool you don't have |
|
|
55
|
+
| `'node' is not recognized` | Works in Git Bash, invisible to the process that launches hooks |
|
|
56
|
+
| `Python was not found; ... Microsoft Store` | Windows' fake `python3` placeholder shadowing your real one |
|
|
57
|
+
| `JSON Parse error: Unrecognized token` | An invisible byte (BOM) at the top of a config file |
|
|
58
|
+
| `Cannot find module 'C:\Users...'` | Backslashes in a path getting eaten before the hook runs |
|
|
131
59
|
|
|
132
|
-
|
|
133
|
-
- Claude Code / Codex
|
|
134
|
-
- Git for Windows
|
|
135
|
-
- Node.js available on PATH
|
|
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.
|
|
136
61
|
|
|
137
|
-
|
|
62
|
+
## How it stays fixed
|
|
138
63
|
|
|
139
|
-
|
|
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.
|
|
140
65
|
|
|
141
|
-
|
|
66
|
+
A healthy run is silent. To look anyway:
|
|
142
67
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
│ └── hooks.json.bak
|
|
148
|
-
├── _hooks/
|
|
149
|
-
│ ├── run-hook.cmd
|
|
150
|
-
│ └── <wrapper>
|
|
151
|
-
└── scripts/
|
|
152
|
-
└── setup.sh
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
The wrapper entry point is a polyglot `.cmd` file: Windows runs the batch portion, while Bash can run the shell portion. That keeps one repaired hook path usable across both Windows dispatch and Bash execution.
|
|
68
|
+
| Command | What it does |
|
|
69
|
+
|---|---|
|
|
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 |
|
|
156
72
|
|
|
157
|
-
|
|
73
|
+
## Privacy
|
|
158
74
|
|
|
159
|
-
|
|
160
|
-
plugin/
|
|
161
|
-
├── .codex-plugin/
|
|
162
|
-
│ └── plugin.json
|
|
163
|
-
├── hooks/
|
|
164
|
-
│ ├── hooks.json
|
|
165
|
-
│ └── hooks.json.codex-win-hooks.bak
|
|
166
|
-
└── _codex_hooks/
|
|
167
|
-
├── run-hook.cmd
|
|
168
|
-
└── <wrapper>
|
|
169
|
-
```
|
|
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.
|
|
170
76
|
|
|
171
|
-
|
|
77
|
+
## License
|
|
172
78
|
|
|
173
|
-
|
|
79
|
+
[MIT](LICENSE). How it works, and every failure mode it handles: [`AGENTS.md`](AGENTS.md).
|
package/bin/win-hooks.mjs
CHANGED
|
@@ -1,82 +1,116 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// win-hooks CLI
|
|
2
|
+
// win-hooks CLI - the single entry point. The plugin's own SessionStart and
|
|
3
|
+
// UserPromptSubmit hooks land here too, via hooks/run-hook.cmd -> hooks/win-hooks.
|
|
3
4
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
// win-hooks repair Claude Code and Codex plugin hooks
|
|
6
|
+
// win-hooks heal [host] repair one host (claude | codex)
|
|
7
|
+
// win-hooks status [host] report without changing anything
|
|
8
|
+
// win-hooks patch [host] report, repair what is not healthy, prove the result
|
|
8
9
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
10
|
+
// --changed-only skip when no plugin's hooks changed since the last run
|
|
11
|
+
// (the per-prompt guard; near-free on the hot path)
|
|
12
|
+
//
|
|
13
|
+
// Progress goes to stderr, never stdout: these hooks run under Claude Code,
|
|
14
|
+
// whose UserPromptSubmit stdout is injected into the model's context. `status`
|
|
15
|
+
// and `patch` are the exception - a person asked for their output.
|
|
16
|
+
|
|
17
|
+
import { isWindows } from '../src/env.mjs';
|
|
18
|
+
import { HOSTS } from '../src/hosts.mjs';
|
|
19
|
+
import { heal, inspect } from '../src/heal.mjs';
|
|
20
|
+
|
|
21
|
+
const USAGE = 'usage: win-hooks [heal|status|patch] [claude|codex] [--changed-only]';
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const flags = new Set(args.filter((a) => a.startsWith('--')));
|
|
25
|
+
const words = args.filter((a) => !a.startsWith('--'));
|
|
26
|
+
const command = ['heal', 'status', 'patch'].includes(words[0]) ? words.shift() : 'heal';
|
|
27
|
+
const hostIds = words.length ? words : Object.keys(HOSTS);
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
if (hostIds.some((id) => !HOSTS[id])) {
|
|
30
|
+
console.error(USAGE);
|
|
31
|
+
process.exit(2);
|
|
32
|
+
}
|
|
20
33
|
|
|
21
|
-
if (
|
|
22
|
-
// Hooks run natively on macOS
|
|
23
|
-
console.error('win-hooks
|
|
34
|
+
if (!isWindows()) {
|
|
35
|
+
// Hooks run natively on macOS and Linux. Nothing to repair is not an error.
|
|
36
|
+
console.error('win-hooks: not Windows - your plugin hooks already run natively here.');
|
|
24
37
|
process.exit(0);
|
|
25
38
|
}
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
'C:\\Program Files (x86)\\Git\\bin\\bash.exe',
|
|
34
|
-
);
|
|
35
|
-
for (const c of candidates) if (existsSync(c)) return c;
|
|
40
|
+
if (command !== 'heal') {
|
|
41
|
+
console.log(hostIds.map(command === 'patch' ? patchHost : statusOf).join('\n\n'));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const id of hostIds) {
|
|
36
46
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
const result = heal(id, { changedOnly: flags.has('--changed-only') });
|
|
48
|
+
if (result) for (const line of summarize(result)) console.error(line);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// One broken host must not take the session down with it.
|
|
51
|
+
console.error('win-hooks: ' + HOSTS[id].label + ' repair failed - ' + e.message);
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
function summarize({ host, patched, failed, settings, issues, fixes }) {
|
|
56
|
+
const lines = [];
|
|
57
|
+
for (const p of patched) lines.push('win-hooks: patched ' + p.plugin.id + ' (' + p.wrappers.join(', ') + ')');
|
|
58
|
+
for (const f of failed) lines.push('win-hooks: could not patch ' + f.plugin.id + ' - ' + f.error);
|
|
59
|
+
if (settings.length) lines.push('win-hooks: repaired ' + settings.length + ' hook command(s) in ' + host.label + ' settings');
|
|
60
|
+
for (const f of fixes) lines.push('win-hooks: ' + f);
|
|
61
|
+
if (patched.length || fixes.length) {
|
|
62
|
+
lines.push('win-hooks: repairs are on disk - run /reload-plugins to apply them to this session.');
|
|
49
63
|
}
|
|
50
|
-
|
|
64
|
+
const unresolved = issues.length - fixes.length;
|
|
65
|
+
if (unresolved > 0) lines.push('win-hooks: ' + unresolved + ' issue(s) need attention - run /win-hooks:patch');
|
|
66
|
+
return lines;
|
|
51
67
|
}
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
// Report, repair what is not healthy, then prove the result - one verb,
|
|
70
|
+
// because nobody inspects hooks for their own sake. A healthy host leaves
|
|
71
|
+
// nothing to decide, and a broken one was always going to be repaired, so
|
|
72
|
+
// splitting the two only asks the user which one they needed.
|
|
73
|
+
function patchHost(id) {
|
|
74
|
+
const before = inspect(id);
|
|
75
|
+
if (healthy(before)) return report(before) + heartbeat(before);
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
heal(id);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return report(before) + '\n\n repair failed - ' + e.message;
|
|
61
81
|
}
|
|
62
|
-
|
|
63
|
-
|
|
82
|
+
|
|
83
|
+
const after = inspect(id);
|
|
84
|
+
return report(before) + '\n\n' + report(after, 'after repair') + heartbeat(after)
|
|
85
|
+
+ '\n repairs are on disk - run /reload-plugins to apply them to this session.';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Every function below is a declaration, not a const: the dispatch above runs
|
|
89
|
+
// before this point in the module, and only declarations are hoisted.
|
|
90
|
+
function statusOf(id) {
|
|
91
|
+
const state = inspect(id);
|
|
92
|
+
return report(state) + heartbeat(state);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function healthy({ incompatible, issues, settings }) {
|
|
96
|
+
return !incompatible.length && !issues.length && !settings.length;
|
|
64
97
|
}
|
|
65
98
|
|
|
66
|
-
|
|
67
|
-
|
|
99
|
+
function report({ host, plugins, incompatible, issues, settings }, heading) {
|
|
100
|
+
const title = '# ' + host.label + (heading ? ' ' + heading : '')
|
|
101
|
+
+ ' - ' + plugins.length + ' hook file(s) scanned';
|
|
102
|
+
const lines = [title];
|
|
68
103
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
104
|
+
for (const i of incompatible) lines.push(' incompatible ' + i.id + ' [' + i.event + '] ' + i.command);
|
|
105
|
+
for (const i of issues) lines.push(' ' + i.type.padEnd(14) + i.plugin + ' ' + i.detail);
|
|
106
|
+
for (const s of settings) lines.push(' ' + s.type.padEnd(14) + s.path + ' ' + s.to);
|
|
107
|
+
if (lines.length === 1) lines.push(' healthy - every hook is Windows-compatible');
|
|
108
|
+
return lines.join('\n');
|
|
73
109
|
}
|
|
74
110
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
process.exit(2);
|
|
111
|
+
// The happy path is silent, so the run log is the only way to tell a healthy
|
|
112
|
+
// host apart from a hook that never dispatched at all (CASE-25).
|
|
113
|
+
function heartbeat({ log }) {
|
|
114
|
+
return '\n\n last runs:\n'
|
|
115
|
+
+ (log.length ? log.map((l) => ' ' + l) : [' (never run)']).join('\n');
|
|
81
116
|
}
|
|
82
|
-
process.exit(rc);
|
package/hooks/codex-hooks.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "win-hooks:
|
|
2
|
+
"description": "win-hooks: repairs Codex plugin hooks for Windows",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"SessionStart": [
|
|
5
5
|
{
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "bash \"${PLUGIN_ROOT}/hooks/
|
|
10
|
-
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" codex
|
|
9
|
+
"command": "bash \"${PLUGIN_ROOT}/hooks/win-hooks\" heal codex",
|
|
10
|
+
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex",
|
|
11
11
|
"timeout": 60,
|
|
12
|
-
"statusMessage": "win-hooks:
|
|
12
|
+
"statusMessage": "win-hooks: checking Codex plugin hooks"
|
|
13
13
|
}
|
|
14
14
|
]
|
|
15
15
|
}
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"hooks": [
|
|
20
20
|
{
|
|
21
21
|
"type": "command",
|
|
22
|
-
"command": "bash \"${PLUGIN_ROOT}/hooks/
|
|
23
|
-
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\"
|
|
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",
|
|
24
24
|
"timeout": 20,
|
|
25
|
-
"statusMessage": "win-hooks:
|
|
25
|
+
"statusMessage": "win-hooks: checking changed Codex plugin hooks"
|
|
26
26
|
}
|
|
27
27
|
]
|
|
28
28
|
}
|
package/hooks/hooks.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "win-hooks:
|
|
2
|
+
"description": "win-hooks: repairs Claude Code plugin hooks for Windows",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"SessionStart": [
|
|
5
5
|
{
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\"
|
|
10
|
-
"timeout":
|
|
9
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal",
|
|
10
|
+
"timeout": 60
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"hooks": [
|
|
18
18
|
{
|
|
19
19
|
"type": "command",
|
|
20
|
-
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\"
|
|
20
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal --changed-only"
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
}
|
package/hooks/run-hook.cmd
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
: << 'CMDBLOCK'
|
|
2
2
|
@echo off
|
|
3
|
-
REM
|
|
4
|
-
REM
|
|
5
|
-
REM
|
|
3
|
+
REM The entry point every patched hook is dispatched through - a single file
|
|
4
|
+
REM that is valid batch AND valid bash at once. cmd.exe runs the batch block
|
|
5
|
+
REM below; bash treats it as a quoted here-doc and falls through to the tail.
|
|
6
6
|
REM
|
|
7
|
-
REM
|
|
8
|
-
REM
|
|
7
|
+
REM Why a polyglot: Claude Code and Codex each dispatch hooks differently, and
|
|
8
|
+
REM the wrapper has to be reachable from both without shipping two files.
|
|
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).
|
|
9
11
|
REM
|
|
10
12
|
REM Usage: run-hook.cmd <script-name> [args...]
|
|
11
13
|
|
|
@@ -15,38 +17,49 @@ if "%~1"=="" (
|
|
|
15
17
|
)
|
|
16
18
|
|
|
17
19
|
set "HOOK_DIR=%~dp0"
|
|
20
|
+
set "WH_BASH="
|
|
18
21
|
|
|
19
|
-
REM Explicit override
|
|
20
|
-
REM
|
|
21
|
-
|
|
22
|
-
REM install. Skipped entirely unless set, so default behavior is unchanged.
|
|
23
|
-
if defined WH_BASH_EXE if exist "%WH_BASH_EXE%" (
|
|
24
|
-
"%WH_BASH_EXE%" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
|
|
25
|
-
exit /b %ERRORLEVEL%
|
|
26
|
-
)
|
|
22
|
+
REM Explicit override first: set WH_BASH_EXE when bash lives somewhere this
|
|
23
|
+
REM does not already look, e.g. a portable, scoop, or winget Git install.
|
|
24
|
+
if defined WH_BASH_EXE if exist "%WH_BASH_EXE%" set "WH_BASH=%WH_BASH_EXE%"
|
|
27
25
|
|
|
28
|
-
REM
|
|
29
|
-
if exist "C:\Program Files\Git\bin\bash.exe"
|
|
30
|
-
|
|
31
|
-
exit /b %ERRORLEVEL%
|
|
32
|
-
)
|
|
33
|
-
if exist "C:\Program Files (x86)\Git\bin\bash.exe" (
|
|
34
|
-
"C:\Program Files (x86)\Git\bin\bash.exe" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
|
|
35
|
-
exit /b %ERRORLEVEL%
|
|
36
|
-
)
|
|
26
|
+
REM Then Git for Windows, which is where it almost always is.
|
|
27
|
+
if not defined WH_BASH if exist "C:\Program Files\Git\bin\bash.exe" set "WH_BASH=C:\Program Files\Git\bin\bash.exe"
|
|
28
|
+
if not defined WH_BASH if exist "C:\Program Files (x86)\Git\bin\bash.exe" set "WH_BASH=C:\Program Files (x86)\Git\bin\bash.exe"
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
if defined WH_BASH goto :run
|
|
31
|
+
|
|
32
|
+
REM Finally PATH (MSYS2, Cygwin, a nonstandard install). Resolved by the FOR
|
|
33
|
+
REM path-search modifier below rather than by `where`, which costs a subprocess.
|
|
34
|
+
REM That modifier must not be named in a REM: cmd.exe expands it there too, and
|
|
35
|
+
REM a comment mentioning it is a syntax error.
|
|
36
|
+
for %%I in (bash.exe) do set "WH_BASH=%%~$PATH:I"
|
|
37
|
+
if not defined WH_BASH goto :nobash
|
|
38
|
+
|
|
39
|
+
REM PATH bash is often C:\Windows\System32\bash.exe, the WSL launcher, which
|
|
40
|
+
REM cannot open Windows paths and still exits 0 - it would swallow every hook
|
|
41
|
+
REM forever. So the candidate has to prove it can see the script it is about to
|
|
42
|
+
REM run (CASE-29). Only PATH is probed; the paths above are known-good. The
|
|
43
|
+
REM path goes through the environment because bash would receive it as $0 and
|
|
44
|
+
REM WSL's launcher does not forward $0 the way a real bash does.
|
|
45
|
+
set "WH_PROBE=%HOOK_DIR%%~1"
|
|
46
|
+
"%WH_BASH%" -c "test -f \"$WH_PROBE\"" >nul 2>&1
|
|
47
|
+
if errorlevel 1 goto :nobash
|
|
48
|
+
|
|
49
|
+
:run
|
|
50
|
+
REM %* would ignore the shift, so arguments are forwarded positionally. Eight
|
|
51
|
+
REM is every hook win-hooks generates; a ninth would be silently dropped.
|
|
52
|
+
"%WH_BASH%" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
|
|
53
|
+
exit /b %ERRORLEVEL%
|
|
44
54
|
|
|
45
|
-
|
|
55
|
+
:nobash
|
|
56
|
+
REM Fail-safe: no repair, never a broken session - but say so, because a hook
|
|
57
|
+
REM that does nothing quietly is the exact failure win-hooks exists to catch.
|
|
58
|
+
echo run-hook.cmd: no bash that can run "%~1"; skipping >&2
|
|
46
59
|
exit /b 0
|
|
47
60
|
CMDBLOCK
|
|
48
61
|
|
|
49
|
-
#
|
|
62
|
+
# bash: run the named script directly.
|
|
50
63
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
51
64
|
SCRIPT_NAME="$1"
|
|
52
65
|
shift
|
package/hooks/win-hooks
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# The bridge from a hook dispatch to the engine.
|
|
3
|
+
#
|
|
4
|
+
# run-hook.cmd already knows how to find bash on Windows, so win-hooks reaches
|
|
5
|
+
# its own engine exactly the way a patched plugin reaches its wrapper - if this
|
|
6
|
+
# path works here, it works there.
|
|
7
|
+
#
|
|
8
|
+
# Fail-safe: a missing runtime means no repair, never a broken session.
|
|
9
|
+
command -v node >/dev/null 2>&1 || exit 0
|
|
10
|
+
exec node "$(cd "$(dirname "$0")/.." && pwd)/bin/win-hooks.mjs" "$@"
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lilmgenius/win-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.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.",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node test/run.mjs"
|
|
11
|
+
},
|
|
8
12
|
"bin": {
|
|
9
13
|
"win-hooks": "bin/win-hooks.mjs"
|
|
10
14
|
},
|
|
11
15
|
"files": [
|
|
12
16
|
"bin/",
|
|
13
17
|
"hooks/",
|
|
14
|
-
"
|
|
18
|
+
"src/",
|
|
15
19
|
"LICENSE",
|
|
16
20
|
"README.md"
|
|
17
21
|
],
|
|
@@ -35,14 +39,5 @@
|
|
|
35
39
|
"bugs": {
|
|
36
40
|
"url": "https://github.com/LilMGenius/win-hooks/issues"
|
|
37
41
|
},
|
|
38
|
-
"keywords": [
|
|
39
|
-
"windows",
|
|
40
|
-
"hooks",
|
|
41
|
-
"claude-code",
|
|
42
|
-
"codex",
|
|
43
|
-
"compatibility",
|
|
44
|
-
"patch",
|
|
45
|
-
"cli",
|
|
46
|
-
"cross-platform"
|
|
47
|
-
]
|
|
42
|
+
"keywords": ["windows","hooks","claude-code","codex","plugin","compatibility","patch","cli","winux"]
|
|
48
43
|
}
|