hookloom 0.0.0-stage → 1.0.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 +11 -0
- package/.codex-plugin/plugin.json +12 -0
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/dist/check-D6B_qnUy.mjs +65 -0
- package/dist/check-nhb0tW8i.mjs +1 -0
- package/dist/cli.mjs +887 -0
- package/dist/command-line-BBETAyPT.mjs +109 -0
- package/dist/dispatcher.mjs +838 -0
- package/dist/permission-rule-DXm-Jvfg.mjs +355 -0
- package/dist/registry.schema.json +25812 -0
- package/dist/schema-Bvs-uwjo.mjs +1 -0
- package/dist/schema-ChV-yJDT.mjs +5808 -0
- package/hooks/codex.json +172 -0
- package/hooks/hooks.json +345 -0
- package/launcher/hook.sh +10 -0
- package/package.json +67 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": {
|
|
3
|
+
"name": "Joseph Mearman"
|
|
4
|
+
},
|
|
5
|
+
"description": "Runs the hooks in your hookloom registry on every lifecycle event",
|
|
6
|
+
"homepage": "https://github.com/Mearman/hookloom",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"name": "hookloom",
|
|
9
|
+
"repository": "https://github.com/Mearman/hookloom",
|
|
10
|
+
"version": "1.0.0"
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": {
|
|
3
|
+
"name": "Joseph Mearman"
|
|
4
|
+
},
|
|
5
|
+
"description": "Runs the hooks in your hookloom registry on every lifecycle event",
|
|
6
|
+
"homepage": "https://github.com/Mearman/hookloom",
|
|
7
|
+
"hooks": "./hooks/codex.json",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"name": "hookloom",
|
|
10
|
+
"repository": "https://github.com/Mearman/hookloom",
|
|
11
|
+
"version": "1.0.0"
|
|
12
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joseph Mearman
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hookloom
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One hook registry for Claude Code and Codex.
|
|
4
|
+
|
|
5
|
+
It is for people who keep their own hooks and use either harness, or both, on one machine or several. Both harnesses install hookloom as a plugin. The plugin registers a single dispatcher on their lifecycle events, and the dispatcher runs whatever your registry lists for the event, so a hook is written once and applies to both.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
Node 22 or later with npm, and Claude Code, Codex or both.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx hookloom setup
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`setup` installs the plugin into each harness it finds, creates an empty registry and records where Node is, so that hooks also start in applications opened from the desktop. Then:
|
|
18
|
+
|
|
19
|
+
- In Claude Code, restart open sessions or run `/reload-plugins`.
|
|
20
|
+
- In Codex, start `codex`, enter `/hooks` and trust the hookloom entries. Codex skips them until you do.
|
|
21
|
+
|
|
22
|
+
Each machine needs its own `setup`. `--harness claude` or `--harness codex` limits a command to one harness, and `--source` installs from another marketplace, such as a local checkout or a fork.
|
|
23
|
+
|
|
24
|
+
To install by hand instead:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
claude plugin marketplace add Mearman/hookloom
|
|
28
|
+
claude plugin install hookloom@hookloom
|
|
29
|
+
codex plugin marketplace add Mearman/hookloom
|
|
30
|
+
codex plugin add hookloom@hookloom
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## The registry
|
|
34
|
+
|
|
35
|
+
The registry is `hookloom/registry.json` in your configuration directory (`~/.config` unless `XDG_CONFIG_HOME` is set, `%APPDATA%` on Windows). `HOOKLOOM_REGISTRY` names another file.
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"$schema": "https://unpkg.com/hookloom/dist/registry.schema.json",
|
|
40
|
+
"hooks": {
|
|
41
|
+
"PreToolUse": [
|
|
42
|
+
{
|
|
43
|
+
"harnesses": ["claude", "codex"],
|
|
44
|
+
"matcher": "Bash",
|
|
45
|
+
"hooks": [{ "type": "command", "command": "~/hooks/check-command.sh", "timeout": 10 }]
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Events, matchers, handler fields, exit codes and output are the harness's own: see the [Claude Code hooks reference](https://code.claude.com/docs/en/hooks) and the [Codex hooks reference](https://learn.chatgpt.com/docs/hooks). Command handlers work in both; HTTP handlers and `if`, `args`, `shell`, `onFailure` and `asyncRewake` are Claude Code only; `commandWindows` and `additionalContextLimit` are Codex only. A group may set `env`, and so may the whole file under `config.env`.
|
|
53
|
+
|
|
54
|
+
hookloom adds three handler fields:
|
|
55
|
+
|
|
56
|
+
| Field | Effect |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `when: {field, pattern}` | Start the handler only when the named input field matches the regular expression. |
|
|
59
|
+
| `cache: {ttl, key?, inputs?, replay?}` | Run at most once per `ttl` seconds for each value of the `key` input fields (the working directory by default), and again when a file matched by `inputs` changes. Not on events that can block. |
|
|
60
|
+
| `repeat: {window_seconds, ignore_digits?}` | Say the same thing to a session at most once per window. |
|
|
61
|
+
|
|
62
|
+
It also drops a Stop block that repeats the previous one when no tool has run since.
|
|
63
|
+
|
|
64
|
+
`npx hookloom validate` checks a registry against both harnesses.
|
|
65
|
+
|
|
66
|
+
## Moving your existing hooks
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npx hookloom import
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
reports which of your own hooks (Claude Code's user `settings.json` and Codex's `hooks.json`) can move into the registry, and why any must stay. Nothing changes until you add `--apply` with the acknowledgements it asks for:
|
|
73
|
+
|
|
74
|
+
- `--acknowledge-restart`: reload Claude Code sessions and close Codex sessions first. A Claude Code session that has not reloaded loses the moved hooks, and an open Codex session runs them twice.
|
|
75
|
+
- `--acknowledge-codex-review`: Codex reviews the dispatcher once, not each hook, so later registry edits run without review.
|
|
76
|
+
|
|
77
|
+
Every changed file is backed up first. `npx hookloom rollback` undoes the latest migration: untouched files return exactly as they were, and files changed since keep those changes.
|
|
78
|
+
|
|
79
|
+
These stay native:
|
|
80
|
+
|
|
81
|
+
- prompt, agent and MCP tool handlers;
|
|
82
|
+
- `FileChanged`, `WorktreeCreate` and `WorktreeRemove` hooks;
|
|
83
|
+
- Claude Code `SessionEnd` hooks needing more than 1.5 seconds, which a plugin cannot raise, and Codex shutdown hooks beyond 3 seconds;
|
|
84
|
+
- `asyncRewake` hooks, and model switch hooks with a matcher;
|
|
85
|
+
- project, local and managed settings, and hooks written inline in Codex's `config.toml`.
|
|
86
|
+
|
|
87
|
+
## Checking an installation
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npx hookloom status
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
reports installation, Codex approval, the registry and the recorded Node, and runs a test hook through each installed plugin.
|
|
94
|
+
|
|
95
|
+
## Updating
|
|
96
|
+
|
|
97
|
+
Run `claude plugin update hookloom@hookloom`, or `codex plugin add hookloom@hookloom` again. Codex asks you to approve the hooks again after an update, because the plugin's contents changed. Codex honours npm's release-age setting when it fetches the package; Claude Code does not.
|
|
98
|
+
|
|
99
|
+
## How it differs from native hooks
|
|
100
|
+
|
|
101
|
+
- All handlers of an event answer as one hook, so their output shares Claude Code's 10,000 character limit. Longer output is saved to a file by Claude Code rather than lost.
|
|
102
|
+
- Where handlers disagree, the strictest decision wins, and a handler that merely fails never discards another's decision.
|
|
103
|
+
- Handlers under Codex run in your shell, as native hooks do. On Windows that is PowerShell, which reports any failure as status 1: end a command that must block with `; exit $LASTEXITCODE`.
|
|
104
|
+
- The plugin runs the dispatcher on every event it registers, including events with no handlers.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
pnpm install
|
|
110
|
+
pnpm typecheck
|
|
111
|
+
pnpm lint:check
|
|
112
|
+
pnpm test
|
|
113
|
+
pnpm build
|
|
114
|
+
pnpm test:e2e
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`pnpm test:e2e` installs the built package into Claude Code and Codex in throwaway home directories, so it needs a build first, and npm 11.10 or later for its release-age cases.
|
|
118
|
+
|
|
119
|
+
## Help
|
|
120
|
+
|
|
121
|
+
`npx hookloom --help` lists the commands. Report a problem or ask a question in the [issue tracker](https://github.com/Mearman/hookloom/issues), with the output of `npx hookloom status`.
|
|
122
|
+
|
|
123
|
+
## Licence
|
|
124
|
+
|
|
125
|
+
MIT
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { r as permissionRuleProblem } from "./permission-rule-DXm-Jvfg.mjs";
|
|
2
|
+
import { m as harnesses, p as eventContract, t as handlersOf } from "./schema-ChV-yJDT.mjs";
|
|
3
|
+
// src/registry/check.ts
|
|
4
|
+
/**
|
|
5
|
+
* The rules a registry must meet for a harness to be able to run it, beyond its shape.
|
|
6
|
+
*/
|
|
7
|
+
const UNSUPPORTED_FIELDS = {
|
|
8
|
+
claude: ["additionalContextLimit", "commandWindows"],
|
|
9
|
+
codex: [
|
|
10
|
+
"args",
|
|
11
|
+
"asyncRewake",
|
|
12
|
+
"if",
|
|
13
|
+
"onFailure",
|
|
14
|
+
"shell"
|
|
15
|
+
]
|
|
16
|
+
};
|
|
17
|
+
const ADVISORY_DECIDING_EVENT = "UserPromptSubmit";
|
|
18
|
+
function handlerProblems(harness, event, contract, handler) {
|
|
19
|
+
const problems = [];
|
|
20
|
+
const background = handler.type === "command" && (handler.async === true || handler.asyncRewake === true);
|
|
21
|
+
const unsupported = UNSUPPORTED_FIELDS[harness].filter((field) => field in handler);
|
|
22
|
+
if (unsupported.length > 0) problems.push(`${harness} does not support the handler fields ${unsupported.join(", ")}`);
|
|
23
|
+
if (handler.type === "http" && harness !== "claude") problems.push("HTTP handlers are only supported by Claude Code");
|
|
24
|
+
if (handler.type === "command" && handler.async === true && handler.asyncRewake === true) problems.push("async and asyncRewake cannot be combined");
|
|
25
|
+
if (handler.if !== void 0) {
|
|
26
|
+
if (!contract.evaluatesIf) problems.push(`${harness} ignores if on this event`);
|
|
27
|
+
const problem = permissionRuleProblem(handler.if);
|
|
28
|
+
if (problem !== void 0) problems.push(problem);
|
|
29
|
+
}
|
|
30
|
+
if (handler.timeout !== void 0 && handler.timeout > contract.maxTimeoutSeconds) problems.push(`timeout ${String(handler.timeout)} exceeds the ${String(contract.maxTimeoutSeconds)} second limit a plugin hook has on this event`);
|
|
31
|
+
if (handler.cache !== void 0) {
|
|
32
|
+
if (contract.decides) problems.push("a deciding event cannot cache, because a silent hit would skip the decision");
|
|
33
|
+
if (background) problems.push("a background handler has no result to cache");
|
|
34
|
+
}
|
|
35
|
+
if (handler.repeat !== void 0) {
|
|
36
|
+
if (contract.decides && event !== ADVISORY_DECIDING_EVENT) problems.push("a deciding event cannot suppress repeats, because a dropped block would skip the decision");
|
|
37
|
+
if (background) problems.push("a background handler has no output to suppress");
|
|
38
|
+
}
|
|
39
|
+
return problems;
|
|
40
|
+
}
|
|
41
|
+
function groupProblems(harness, event, entry) {
|
|
42
|
+
const contract = eventContract(harness, event);
|
|
43
|
+
if (contract === void 0) return [`${harness} has no ${event} event`];
|
|
44
|
+
if (!contract.registeredByPlugin) return [`the plugin does not register ${event}; keep this hook in the native settings`];
|
|
45
|
+
const problems = [];
|
|
46
|
+
const matcher = entry.matcher ?? "";
|
|
47
|
+
if (matcher !== "") {
|
|
48
|
+
if (contract.matchField === void 0) problems.push(`${harness} does not support matchers on this event`);
|
|
49
|
+
try {
|
|
50
|
+
new RegExp(matcher);
|
|
51
|
+
} catch {
|
|
52
|
+
problems.push(`matcher ${JSON.stringify(matcher)} is not a valid regular expression`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [...problems, ...handlersOf(entry).flatMap((handler) => handlerProblems(harness, event, contract, handler))];
|
|
56
|
+
}
|
|
57
|
+
/** Every reason the registry cannot run on the harnesses its groups select, or an empty list when it can. */
|
|
58
|
+
function checkRegistry(registry, selected = harnesses) {
|
|
59
|
+
return Object.entries(registry.events).flatMap(([event, entries]) => entries.flatMap((entry) => entry.harnesses.filter((harness) => selected.includes(harness)).flatMap((harness) => groupProblems(harness, event, entry).map((message) => ({
|
|
60
|
+
harness,
|
|
61
|
+
event,
|
|
62
|
+
message
|
|
63
|
+
})))));
|
|
64
|
+
}
|
|
65
|
+
export { checkRegistry as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as checkRegistry } from "./check-D6B_qnUy.mjs";
|