show-me-the-env 0.95.0 → 0.96.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/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -0
- package/bin/agenv.mjs +19 -0
- package/package.json +4 -1
- package/plugins/win-hooks/LICENSE +21 -0
- package/plugins/win-hooks/README.md +87 -0
- package/plugins/win-hooks/bin/win-hooks.mjs +173 -0
- package/plugins/win-hooks/hooks/codex-hooks.json +31 -0
- package/plugins/win-hooks/hooks/hooks.json +26 -0
- package/plugins/win-hooks/hooks/hooks.map.json +3 -0
- package/plugins/win-hooks/hooks/run-hook.cmd +51 -0
- package/plugins/win-hooks/hooks/run.mjs +137 -0
- package/plugins/win-hooks/src/env.mjs +122 -0
- package/plugins/win-hooks/src/heal.mjs +147 -0
- package/plugins/win-hooks/src/hosts.mjs +210 -0
- package/plugins/win-hooks/src/patch.mjs +92 -0
- package/plugins/win-hooks/src/rules.mjs +171 -0
- package/plugins/win-hooks/src/settings.mjs +99 -0
- package/plugins/win-hooks/src/skills.mjs +123 -0
- package/plugins/win-hooks/src/stale.mjs +297 -0
- package/plugins/win-hooks/src/verify.mjs +264 -0
- package/src/adapters.mjs +1 -1
- package/src/machines/model-pick.mjs +18 -10
- package/src/machines/queue.mjs +1 -1
package/README.md
CHANGED
|
@@ -114,6 +114,8 @@ claude plugin marketplace add LilMGenius/show-me-the-env && claude plugin instal
|
|
|
114
114
|
codex plugin marketplace add LilMGenius/show-me-the-env && codex plugin add show-me-the-env@show-me-the-env
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
Without installing the plugin, `npx show-me-the-env win-hooks patch` checks and repairs both hosts once, from any terminal.
|
|
118
|
+
|
|
117
119
|
If you already have `win-hooks@win-hooks`, it keeps working; [plugins/win-hooks](plugins/win-hooks/README.md) says what the plugin fixes and how to move that install to the new name.
|
|
118
120
|
|
|
119
121
|
## Limitations
|
package/bin/agenv.mjs
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// agenv: save and restore a whole agent and coding environment as one versioned .agenv
|
|
3
3
|
// repository. Every command reads the same roots, plans through the same engine and reports
|
|
4
4
|
// the same statuses and exit codes; nothing here needs a language model.
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
5
6
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import { parseArgs } from 'node:util';
|
|
9
|
+
import { runningAsSea, whichAll } from '../src/adapters.mjs';
|
|
8
10
|
import { adopt, follow } from '../src/commands/adopt.mjs';
|
|
9
11
|
import { catalog } from '../src/commands/catalog.mjs';
|
|
10
12
|
import { contribute } from '../src/commands/contribute.mjs';
|
|
@@ -39,6 +41,7 @@ const HELP = [
|
|
|
39
41
|
" run Run a command at your commit on another machine, in a free lane there, and keep a receipt",
|
|
40
42
|
" ignored Keep ignored ledgers, evidence and notes in your private profile, and put them back on another machine",
|
|
41
43
|
" machine Attach another computer so it can take work: bootstrap writes its setup script, serve hands it over on this network",
|
|
44
|
+
" win-hooks Repair the Claude Code and Codex plugin hooks Windows cannot run: patch, status or heal [claude|codex]",
|
|
42
45
|
"",
|
|
43
46
|
"Options",
|
|
44
47
|
" --data-root <dir> The profile checkout (default: AGENV_DATA_ROOT)",
|
|
@@ -92,6 +95,20 @@ const OPTIONS = { 'data-root': { type: 'string' }, 'state-root': { type: 'string
|
|
|
92
95
|
// Commands that wait for Ctrl+C themselves to stop a server (ui, desktop) keep their own handling.
|
|
93
96
|
const STOPS_ITSELF = new Set(['ui', 'desktop']);
|
|
94
97
|
|
|
98
|
+
// The win-hooks CLI this package ships in plugins/win-hooks, the one the plugin's own hooks start.
|
|
99
|
+
// agenv win-hooks hands it every word and flag after its name and answers with its exit code, so a
|
|
100
|
+
// repair from a terminal needs no second package. A native build's process.execPath is agenv
|
|
101
|
+
// itself, so Node then comes from PATH, which the plugin's hooks need anyway.
|
|
102
|
+
const WIN_HOOKS_CLI = fileURLToPath(new URL('../plugins/win-hooks/bin/win-hooks.mjs', import.meta.url));
|
|
103
|
+
|
|
104
|
+
async function winHooks(args, env) {
|
|
105
|
+
const node = runningAsSea() ? (await whichAll('node', { env, platform: process.platform })).find((f) => !/\.(cmd|bat)$/i.test(f)) : process.execPath;
|
|
106
|
+
if (!node) return { exitCode: EXIT.failure, text: 'agenv win-hooks: no Node on PATH to start ' + WIN_HOOKS_CLI };
|
|
107
|
+
const r = spawnSync(node, [WIN_HOOKS_CLI, ...args], { env, stdio: ['inherit', 'pipe', 'inherit'], encoding: 'utf8', maxBuffer: 1 << 26, windowsHide: true });
|
|
108
|
+
if (r.error) return { exitCode: EXIT.failure, text: 'agenv win-hooks: ' + r.error.message };
|
|
109
|
+
return { exitCode: r.status ?? EXIT.failure, text: r.stdout.replace(/\r?\n$/, '') };
|
|
110
|
+
}
|
|
111
|
+
|
|
95
112
|
// Ctrl+C or SIGTERM cancels through the executor: the running step finishes, nothing new starts,
|
|
96
113
|
// its locks are released in the executor's finally, and the command then exits 130. A second
|
|
97
114
|
// interrupt exits at once; proper-lockfile removes the locks it holds as the process exits.
|
|
@@ -108,6 +125,8 @@ function cancelOnInterrupt(controller) {
|
|
|
108
125
|
}
|
|
109
126
|
|
|
110
127
|
export async function main(argv, env = process.env, { interrupts = false } = {}) {
|
|
128
|
+
// win-hooks reads its own words and flags, so they reach its CLI unparsed.
|
|
129
|
+
if (argv[0] === 'win-hooks') return winHooks(argv.slice(1), env);
|
|
111
130
|
let parsed;
|
|
112
131
|
try { parsed = parseArgs({ args: argv, options: { ...OPTIONS, ...RUN_OPTIONS, ...MACHINE_OPTIONS }, allowPositionals: true, strict: true }); }
|
|
113
132
|
catch (e) { return { exitCode: EXIT.invalidInput, text: e.message + '\n\n' + HELP }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "show-me-the-env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.96.0",
|
|
4
4
|
"description": "Save and restore your whole agent and coding environment as one versioned .agenv repository.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"scripts/",
|
|
44
44
|
"launchers/",
|
|
45
45
|
"skills/",
|
|
46
|
+
"plugins/win-hooks/bin/",
|
|
47
|
+
"plugins/win-hooks/hooks/",
|
|
48
|
+
"plugins/win-hooks/src/",
|
|
46
49
|
"ui/dist/",
|
|
47
50
|
"references/",
|
|
48
51
|
".claude-plugin/"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LilMGenius
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# win-hooks
|
|
4
|
+
|
|
5
|
+
### *"Linux? Nah. WinUX!"*
|
|
6
|
+
|
|
7
|
+
**Windows auto-patcher for vibe coders.**
|
|
8
|
+
|
|
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
|
+
|
|
12
|
+
[](https://www.microsoft.com/windows)
|
|
13
|
+
[](https://docs.anthropic.com/en/docs/claude-code)
|
|
14
|
+
[](https://developers.openai.com/codex)
|
|
15
|
+
[](LICENSE)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
Pick your tool and paste one line.
|
|
24
|
+
|
|
25
|
+
**Claude Code**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
claude plugin marketplace add LilMGenius/show-me-the-env && claude plugin install show-me-the-env@show-me-the-env
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Codex**
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
codex plugin marketplace add LilMGenius/show-me-the-env && codex plugin add show-me-the-env@show-me-the-env
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Neither, just fix my plugins now**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx show-me-the-env win-hooks
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That's the whole setup. No config, no flags, nothing to remember.
|
|
44
|
+
|
|
45
|
+
Installed it earlier as `win-hooks@win-hooks`? It keeps working: Claude Code keeps updating it from this repository, and Codex keeps running the version it installed. To move to the new name, run `claude plugin uninstall win-hooks@win-hooks && claude plugin marketplace remove win-hooks` or `codex plugin remove win-hooks@win-hooks && codex plugin marketplace remove win-hooks`, then the line above. Keep one of the two, or every repair runs twice.
|
|
46
|
+
|
|
47
|
+
You need Windows 10/11. Node.js already comes with Claude Code and Codex, and [Git for Windows](https://git-scm.com/download/win) is needed only for plugins whose hooks are shell scripts.
|
|
48
|
+
|
|
49
|
+
## What it fixes
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
| The error you see | What was wrong |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `check.sh: No such file or directory` | Windows can't run a `.sh` script directly |
|
|
56
|
+
| `semgrep: command not found` | The plugin expects a Unix tool you don't have |
|
|
57
|
+
| `'node' is not recognized` | Works in Git Bash, invisible to the process that launches hooks |
|
|
58
|
+
| `Python was not found; ... Microsoft Store` | Windows' fake `python3` placeholder shadowing your real one |
|
|
59
|
+
| `JSON Parse error: Unrecognized token` | An invisible byte (BOM) at the top of a config file |
|
|
60
|
+
| `Cannot find module 'C:\Users...'` | Backslashes in a path getting eaten before the hook runs |
|
|
61
|
+
| `hook exited with code 1` on every hook, in a Codex session that was fine an hour ago | Another Codex window updated the plugin and deleted the version this session was running |
|
|
62
|
+
| win-hooks' own hooks fail in sessions opened before its update, and `patch` says healthy | The update removed the version those sessions run from; win-hooks now remembers it and puts it back |
|
|
63
|
+
| `SKILL.md: failed to read file (os error 2)` for a skill, in a session opened before a skill install | The installer deleted the skill folder that session listed; win-hooks remembers the folder and links it to the same skill installed elsewhere |
|
|
64
|
+
| `hook exited with code 1` on every prompt, from a hook you wrote in `~/.codex/hooks.json` that starts with a quoted path | Codex runs it through PowerShell, which cannot start a program from a quoted path; win-hooks rewrites its Windows command, and you trust the file again in `/hooks` |
|
|
65
|
+
|
|
66
|
+
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.
|
|
67
|
+
|
|
68
|
+
It also repairs the damage no error message shows you: CRLF line endings, a `hooks.json` no parser will read, and the patched hook entries themselves - one that went missing, one that calls an interpreter on itself, one aimed at a target that is gone, and files an older win-hooks left behind.
|
|
69
|
+
|
|
70
|
+
## How it stays fixed
|
|
71
|
+
|
|
72
|
+
win-hooks repairs your plugins at every session start, including ones you install later, ones that break again after an update, and ones an older win-hooks left behind. Repairs are written next to the original file, never on top of it, and anything already working is left alone.
|
|
73
|
+
|
|
74
|
+
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:
|
|
75
|
+
|
|
76
|
+
| Command | What it does |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `/show-me-the-env:patch` | Checks every plugin, shows what it found, repairs anything broken |
|
|
79
|
+
| `npx show-me-the-env win-hooks patch` | The same, from any terminal |
|
|
80
|
+
|
|
81
|
+
## Privacy
|
|
82
|
+
|
|
83
|
+
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 the hook commands it repairs in your own hook settings (after a one-time backup beside the file) and a short local log of its own runs, so you can confirm it ran.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
[MIT](LICENSE). See the [architecture map](AGENTS.md#architecture) and [catalogue of failure modes](AGENTS.md#known-edge-cases--scenarios).
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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/run.mjs.
|
|
4
|
+
//
|
|
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
|
|
10
|
+
//
|
|
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).
|
|
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] [--announce]';
|
|
22
|
+
|
|
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);
|
|
28
|
+
|
|
29
|
+
if (hostIds.some((id) => !HOSTS[id])) {
|
|
30
|
+
console.error(USAGE);
|
|
31
|
+
process.exit(2);
|
|
32
|
+
}
|
|
33
|
+
|
|
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.');
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (command !== 'heal') {
|
|
41
|
+
console.log(hostIds.map(command === 'patch' ? patchHost : statusOf).join('\n\n'));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const announce = flags.has('--announce');
|
|
46
|
+
|
|
47
|
+
for (const id of hostIds) {
|
|
48
|
+
try {
|
|
49
|
+
const result = heal(id, { changedOnly: flags.has('--changed-only') });
|
|
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);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// One broken host must not take the session down with it.
|
|
56
|
+
console.error('win-hooks: ' + HOSTS[id].label + ' repair failed - ' + e.message);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
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
|
+
|
|
69
|
+
function summarize({ host, patched, failed, settings, issues, fixes }) {
|
|
70
|
+
const lines = [];
|
|
71
|
+
for (const p of patched) lines.push('win-hooks: patched ' + p.plugin.id + ' (' + p.hooks.join(', ') + ')');
|
|
72
|
+
for (const f of failed) lines.push('win-hooks: could not patch ' + f.plugin.id + ' - ' + f.error);
|
|
73
|
+
const repaired = settings.filter((s) => !s.manual);
|
|
74
|
+
if (repaired.length) lines.push('win-hooks: repaired ' + repaired.length + ' hook command(s) in ' + host.label + ' settings');
|
|
75
|
+
for (const s of settings.filter((s) => s.manual)) lines.push('win-hooks: ' + s.type + ' in ' + s.path + ' - ' + s.to);
|
|
76
|
+
lines.push(...retrustNotes(settings).map((note) => 'win-hooks: ' + note));
|
|
77
|
+
for (const f of fixes) lines.push('win-hooks: ' + f);
|
|
78
|
+
if (patched.length || fixes.length) {
|
|
79
|
+
lines.push('win-hooks: repairs are on disk - run /reload-plugins to apply them to this session.');
|
|
80
|
+
}
|
|
81
|
+
const unresolved = issues.length - fixes.length;
|
|
82
|
+
if (unresolved > 0) lines.push('win-hooks: ' + unresolved + ' issue(s) need attention - run /show-me-the-env:patch');
|
|
83
|
+
return lines;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// One verb, because nobody inspects hooks for their own sake: a healthy host
|
|
87
|
+
// leaves nothing to decide and a broken one was always going to be repaired,
|
|
88
|
+
// so splitting the two only asks the user which one they needed (CASE-30).
|
|
89
|
+
function patchHost(id) {
|
|
90
|
+
const before = inspect(id);
|
|
91
|
+
if (healthy(before)) return report(before) + heartbeat(before);
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
heal(id);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return report(before) + '\n\n repair failed - ' + e.message;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const after = inspect(id);
|
|
100
|
+
return report(before) + '\n\n' + report(after, 'after repair') + heartbeat(after)
|
|
101
|
+
+ '\n repairs are on disk - run /reload-plugins to apply them to this session.'
|
|
102
|
+
+ retrustNotes(before.settings).map((note) => '\n ' + note).join('');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Every function below is a declaration, not a const: the dispatch above runs
|
|
106
|
+
// before this point in the module, and only declarations are hoisted.
|
|
107
|
+
|
|
108
|
+
// A repaired user hooks file has a new hash, and Codex skips an untrusted hook
|
|
109
|
+
// without a word (CASE-33), so the person is told where to trust it again.
|
|
110
|
+
function retrustNotes(settings) {
|
|
111
|
+
return [...new Set(settings.filter((s) => s.retrust).map((s) => s.retrust))]
|
|
112
|
+
.map((file) => file + ' changed, so Codex skips its hooks until you trust them again in /hooks');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function statusOf(id) {
|
|
116
|
+
const state = inspect(id);
|
|
117
|
+
return report(state) + heartbeat(state);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// A root an open session runs from and cannot find is a broken session, even
|
|
121
|
+
// though no hook file is wrong (CASE-36). A restored one is working, and is
|
|
122
|
+
// listed so a person can see why a version directory holds only links.
|
|
123
|
+
function brokenRoots(roots = []) {
|
|
124
|
+
return roots.filter((r) => r.state !== 'restored');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function healthy({ incompatible, issues, settings, roots, skills = [] }) {
|
|
128
|
+
return !incompatible.length && !issues.length && !settings.length && !brokenRoots(roots).length && !skills.length;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function rootName(r) {
|
|
132
|
+
return r.plugin + '/' + r.version + ' (' + r.marketplace + ')';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function rootDetail(r) {
|
|
136
|
+
if (r.state === 'shadowing') {
|
|
137
|
+
return 'ranks above the installed ' + r.currentVersion + ', so Codex loads it and finds no plugin there';
|
|
138
|
+
}
|
|
139
|
+
return (r.state === 'missing' ? 'removed' : 'emptied') + ' while a session may still run from it; '
|
|
140
|
+
+ r.currentVersion + ' is installed';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function report({ host, plugins, incompatible, issues, settings, roots = [], skills = [] }, heading) {
|
|
144
|
+
const title = '# ' + host.label + (heading ? ' ' + heading : '')
|
|
145
|
+
+ ' - ' + plugins.length + ' hook file(s) scanned';
|
|
146
|
+
const lines = [title];
|
|
147
|
+
|
|
148
|
+
// The label column is measured, not guessed: a fixed width silently ran the
|
|
149
|
+
// longest issue types into the plugin name beside them.
|
|
150
|
+
const rows = [
|
|
151
|
+
...incompatible.map((i) => ['incompatible', i.id + ' [' + i.event + ']', i.command]),
|
|
152
|
+
...issues.map((i) => [i.type, i.plugin, i.detail]),
|
|
153
|
+
...settings.map((s) => [s.type, s.path, s.to]),
|
|
154
|
+
...brokenRoots(roots).map((r) => [r.state + ' root', rootName(r), rootDetail(r)]),
|
|
155
|
+
// A skill folder an open session listed and cannot read (CASE-37).
|
|
156
|
+
...skills.map((s) => [s.state + ' skill', s.name, 'listed by open sessions; installed at ' + s.source.replace(/\\/g, '/')]),
|
|
157
|
+
];
|
|
158
|
+
const info = roots.filter((r) => r.state === 'restored')
|
|
159
|
+
.map((r) => ['restored root', rootName(r), 'links to ' + r.currentVersion + ' for the sessions still running from it']);
|
|
160
|
+
const width = Math.max(0, ...[...rows, ...info].map(([type]) => type.length));
|
|
161
|
+
const line = ([type, subject, detail]) => ' ' + type.padEnd(width) + ' ' + subject + ' ' + detail;
|
|
162
|
+
lines.push(...rows.map(line));
|
|
163
|
+
if (!rows.length) lines.push(' healthy - every hook is Windows-compatible');
|
|
164
|
+
lines.push(...info.map(line));
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// The happy path is silent, so the run log is the only way to tell a healthy
|
|
169
|
+
// host apart from a hook that never dispatched at all (CASE-25).
|
|
170
|
+
function heartbeat({ log }) {
|
|
171
|
+
return '\n\n last runs:\n'
|
|
172
|
+
+ (log.length ? log.map((l) => ' ' + l) : [' (never run)']).join('\n');
|
|
173
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "win-hooks: repairs Codex plugin hooks for Windows",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"SessionStart": [
|
|
5
|
+
{
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "bash \"${PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal codex --announce",
|
|
10
|
+
"commandWindows": "cmd /c \"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex --announce",
|
|
11
|
+
"timeout": 60,
|
|
12
|
+
"statusMessage": "win-hooks: checking Codex plugin hooks"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"UserPromptSubmit": [
|
|
18
|
+
{
|
|
19
|
+
"hooks": [
|
|
20
|
+
{
|
|
21
|
+
"type": "command",
|
|
22
|
+
"command": "bash \"${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
|
+
"timeout": 20,
|
|
25
|
+
"statusMessage": "win-hooks: checking changed Codex plugin hooks"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "win-hooks: repairs Claude Code plugin hooks for Windows",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"SessionStart": [
|
|
5
|
+
{
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal --announce",
|
|
10
|
+
"timeout": 60
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"UserPromptSubmit": [
|
|
16
|
+
{
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal --changed-only"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
: << 'CMDBLOCK'
|
|
2
|
+
@echo off
|
|
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. Hook names are
|
|
7
|
+
REM extensionless because Claude Code prepends "bash" to any command containing
|
|
8
|
+
REM .sh, which would undo the patch (CASE-07).
|
|
9
|
+
REM
|
|
10
|
+
REM Both halves do the same small thing: start node on run.mjs, which resolves
|
|
11
|
+
REM the named hook and runs it. Nothing here looks for bash any more - that
|
|
12
|
+
REM decision moved into run.mjs, where it is ordinary code (CASE-29).
|
|
13
|
+
REM
|
|
14
|
+
REM Usage: run-hook.cmd <hook-name> [args...]
|
|
15
|
+
|
|
16
|
+
if "%~1"=="" (
|
|
17
|
+
echo win-hooks: run-hook.cmd was given no hook name >&2
|
|
18
|
+
exit /b 1
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
set "WH_NODE="
|
|
22
|
+
|
|
23
|
+
REM Explicit override first, for a portable or otherwise unusual node install.
|
|
24
|
+
if defined WH_NODE_EXE if exist "%WH_NODE_EXE%" set "WH_NODE=%WH_NODE_EXE%"
|
|
25
|
+
|
|
26
|
+
REM Then PATH, resolved by the FOR path-search modifier below, because `where`
|
|
27
|
+
REM costs a subprocess. Never name that modifier in a REM: cmd.exe expands it
|
|
28
|
+
REM there too and the comment breaks.
|
|
29
|
+
if not defined WH_NODE for %%I in (node.exe) do set "WH_NODE=%%~$PATH:I"
|
|
30
|
+
if not defined WH_NODE goto :nonode
|
|
31
|
+
|
|
32
|
+
REM %* forwards every argument, including the hook name run.mjs reads first.
|
|
33
|
+
REM The previous positional forwarding capped a hook at eight arguments because
|
|
34
|
+
REM cmd.exe's %* ignores shift; nothing shifts now, so the cap is gone (CASE-27).
|
|
35
|
+
"%WH_NODE%" "%~dp0run.mjs" %*
|
|
36
|
+
exit /b %ERRORLEVEL%
|
|
37
|
+
|
|
38
|
+
:nonode
|
|
39
|
+
REM Fail-safe: no repair, never a broken session - but say so, because a hook
|
|
40
|
+
REM that does nothing quietly is the exact failure win-hooks exists to catch.
|
|
41
|
+
echo win-hooks: no node found; skipping "%~1" >&2
|
|
42
|
+
exit /b 0
|
|
43
|
+
CMDBLOCK
|
|
44
|
+
|
|
45
|
+
# bash: the same dispatch, for Git Bash on Windows and for Codex's portable
|
|
46
|
+
# command on macOS and Linux.
|
|
47
|
+
command -v node >/dev/null 2>&1 || {
|
|
48
|
+
echo 'win-hooks: no node found; skipping' >&2
|
|
49
|
+
exit 0
|
|
50
|
+
}
|
|
51
|
+
exec node "$(cd "$(dirname "$0")" && pwd)/run.mjs" "$@"
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// The dispatcher every patched hook lands in, one step after run-hook.cmd.
|
|
2
|
+
//
|
|
3
|
+
// This file is copied verbatim into each patched plugin's hook directory, so
|
|
4
|
+
// it must not import anything from src/: there is no src/ beside it there. The
|
|
5
|
+
// bash resolution and the descriptor shapes below are therefore deliberately a
|
|
6
|
+
// second copy of what src/env.mjs and src/rules.mjs own, rather than a shared
|
|
7
|
+
// import - the alternative is shipping the whole engine into every plugin that
|
|
8
|
+
// has one broken hook.
|
|
9
|
+
//
|
|
10
|
+
// Usage: node run.mjs <hook-name> [args...]
|
|
11
|
+
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { dirname, join } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
const HOOK_DIR = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const PLUGIN_ROOT = dirname(HOOK_DIR);
|
|
19
|
+
|
|
20
|
+
const name = process.argv[2];
|
|
21
|
+
const args = process.argv.slice(3);
|
|
22
|
+
|
|
23
|
+
// Fail-safe everywhere below: a hook that cannot run must be a no-op, never a
|
|
24
|
+
// broken session. It still says so on stderr, because a hook that does nothing
|
|
25
|
+
// silently is the exact failure win-hooks exists to catch (CASE-29/32).
|
|
26
|
+
const skip = (why) => {
|
|
27
|
+
process.stderr.write('win-hooks: ' + why + '; skipping\n');
|
|
28
|
+
process.exit(0);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (!name) skip('run.mjs was given no hook name');
|
|
32
|
+
|
|
33
|
+
// Known-good bash paths are trusted without a probe, so the common case costs
|
|
34
|
+
// no subprocess. Anything found on PATH has to prove itself first.
|
|
35
|
+
const KNOWN_BASH = [
|
|
36
|
+
process.env.WH_BASH_EXE,
|
|
37
|
+
'C:/Program Files/Git/bin/bash.exe',
|
|
38
|
+
'C:/Program Files (x86)/Git/bin/bash.exe',
|
|
39
|
+
].filter(Boolean);
|
|
40
|
+
|
|
41
|
+
const toPosix = (p) => String(p || '').replace(/\\/g, '/');
|
|
42
|
+
|
|
43
|
+
// CASE-29: PATH bash on stock Windows is System32\bash.exe, the WSL launcher.
|
|
44
|
+
// It cannot open a Windows path and still exits 0, so it would swallow every
|
|
45
|
+
// hook forever. A candidate must prove it can see the file it is about to run.
|
|
46
|
+
// The path travels through the environment rather than as $0, because WSL
|
|
47
|
+
// reports $0 as /bin/bash and would pass a test it must fail.
|
|
48
|
+
const bashSees = (exe, target) => {
|
|
49
|
+
const r = spawnSync(exe, ['-c', 'test -f "$WH_PROBE"'], {
|
|
50
|
+
env: { ...process.env, WH_PROBE: toPosix(target) },
|
|
51
|
+
stdio: 'ignore',
|
|
52
|
+
windowsHide: true,
|
|
53
|
+
timeout: 10000,
|
|
54
|
+
});
|
|
55
|
+
return !r.error && r.status === 0;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// PATH is walked here rather than shelled out to `where.exe`, which would cost
|
|
59
|
+
// a subprocess and would itself have to be found on the PATH under test.
|
|
60
|
+
const pathDirs = () =>
|
|
61
|
+
String(process.env.PATH || '')
|
|
62
|
+
.split(';')
|
|
63
|
+
.map((d) => d.trim().replace(/^"|"$/g, ''))
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
|
|
66
|
+
const resolveBash = (target) => {
|
|
67
|
+
for (const exe of KNOWN_BASH) if (existsSync(exe)) return exe;
|
|
68
|
+
for (const dir of pathDirs()) {
|
|
69
|
+
const exe = join(dir, 'bash.exe');
|
|
70
|
+
if (existsSync(exe) && bashSees(exe, target)) return exe;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Is this bare name executable from PATH? The same walk as resolveBash, but
|
|
76
|
+
// across PATHEXT, since a dependency may be a .cmd or .bat shim, not an .exe.
|
|
77
|
+
const onPath = (bin) => {
|
|
78
|
+
const exts = String(process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean);
|
|
79
|
+
return pathDirs().some((d) => exts.some((ext) => existsSync(join(d, bin + ext))));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const readMap = () => {
|
|
83
|
+
const file = join(HOOK_DIR, 'hooks.map.json');
|
|
84
|
+
if (!existsSync(file)) return {};
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
87
|
+
} catch {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// A bash wrapper file sitting in this directory is an install patched before
|
|
93
|
+
// the map existed. Running it keeps that machine working until the next heal
|
|
94
|
+
// replaces it with an entry - which verify does, so this is a bridge, not a
|
|
95
|
+
// second supported layout.
|
|
96
|
+
const legacyWrapper = join(HOOK_DIR, name);
|
|
97
|
+
const entry = readMap()[name]
|
|
98
|
+
|| (existsSync(legacyWrapper) ? { exec: 'bash', absoluteTarget: legacyWrapper } : null);
|
|
99
|
+
|
|
100
|
+
if (!entry) skip('no hook named "' + name + '" in ' + HOOK_DIR);
|
|
101
|
+
|
|
102
|
+
// A hook win-hooks could not make runnable at patch time - no working Python,
|
|
103
|
+
// say. Exiting 0 in silence is the point: it is a deliberate no-op, and a line
|
|
104
|
+
// per invocation would be noise in every session until the plugin updates.
|
|
105
|
+
if (entry.disabled) process.exit(0);
|
|
106
|
+
|
|
107
|
+
// CASE-08: an optional dependency that simply is not installed here. Re-checked
|
|
108
|
+
// every run rather than at patch time, so installing it later just starts
|
|
109
|
+
// working, and its absence never fails the hook.
|
|
110
|
+
if (entry.requires) {
|
|
111
|
+
if (!onPath(entry.requires)) process.exit(0);
|
|
112
|
+
// The command is run as written and the hook's own arguments are not
|
|
113
|
+
// appended: the entry already holds the whole original command line, so
|
|
114
|
+
// forwarding them too would duplicate every argument (CASE-10).
|
|
115
|
+
const dep = spawnSync(entry.command, { stdio: 'inherit', shell: true, windowsHide: true });
|
|
116
|
+
process.exit(dep.status === null ? 0 : dep.status);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const target = entry.absoluteTarget || join(PLUGIN_ROOT, entry.target);
|
|
120
|
+
|
|
121
|
+
// exec is an absolute interpreter path baked in at patch time (CASE-09), the
|
|
122
|
+
// literal "bash" when only a run-time search can find one, or absent when the
|
|
123
|
+
// target is handed to the OS to run on its own.
|
|
124
|
+
let exe = entry.exec;
|
|
125
|
+
// "node" means the one already running: run-hook.cmd found it, and reusing it
|
|
126
|
+
// keeps a hook on the same interpreter that dispatched it.
|
|
127
|
+
if (exe === 'node') exe = process.execPath;
|
|
128
|
+
else if (exe === 'bash') {
|
|
129
|
+
exe = resolveBash(target);
|
|
130
|
+
if (!exe) skip('no bash that can run "' + name + '"');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const r = spawnSync(exe || target, exe ? [target, ...args] : args, {
|
|
134
|
+
stdio: 'inherit',
|
|
135
|
+
windowsHide: true,
|
|
136
|
+
});
|
|
137
|
+
process.exit(r.status === null ? 0 : r.status);
|