@goodfoot/agent-hooks 1.0.0 → 1.0.1
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 +138 -16
- package/dist/agents/codex/scaffold.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/scaffold.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,27 +1,128 @@
|
|
|
1
1
|
# `@goodfoot/agent-hooks`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
runtime previously split across `@goodfoot/claude-code-hooks` and
|
|
5
|
-
`@goodfoot/codex-hooks`, with per-agent entry points.
|
|
3
|
+
**Build AI coding agent hooks in TypeScript — one package, any supported agent.**
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pre-declared.
|
|
5
|
+
`@goodfoot/agent-hooks` is the unified successor to `@goodfoot/claude-code-hooks` and
|
|
6
|
+
`@goodfoot/codex-hooks`: a shared agent-neutral core (hook factory primitive, transport
|
|
7
|
+
driver, `Logger`, env/stdin utilities) with a per-agent entry point on top. Write
|
|
8
|
+
TypeScript hooks, compile them with the bundled CLI, and run the resulting
|
|
9
|
+
self-contained executables under Claude Code or Codex.
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
**Status: `1.0.0`.** Two entry points ship and are published: `@goodfoot/agent-hooks/claude-code`
|
|
12
|
+
(full parity with `@goodfoot/claude-code-hooks`) and `@goodfoot/agent-hooks/codex` (full
|
|
13
|
+
parity with `@goodfoot/codex-hooks`). Antigravity CLI support exists internally as typed
|
|
14
|
+
factories, output builders, and a conformance matrix, but is **not** part of this
|
|
15
|
+
release's public surface — there is no `@goodfoot/agent-hooks/antigravity` export yet,
|
|
16
|
+
and `--agent antigravity` is rejected by the CLI. It ships once a non-interactive,
|
|
17
|
+
authenticated Antigravity CLI exists to validate against.
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @goodfoot/agent-hooks
|
|
23
|
+
# or npm install, pnpm, etc.
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Write a hook
|
|
29
|
+
|
|
30
|
+
Import factories from your target agent's entry point. **Note:** you must use
|
|
31
|
+
`export default` and the factory function — the CLI's build step relies on it.
|
|
32
|
+
|
|
33
|
+
Claude Code (`@goodfoot/agent-hooks/claude-code`):
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { preToolUseHook, preToolUseOutput } from '@goodfoot/agent-hooks/claude-code';
|
|
37
|
+
|
|
38
|
+
export default preToolUseHook({ matcher: 'Bash' }, async (input, { logger }) => {
|
|
39
|
+
const { command } = input.tool_input as { command: string };
|
|
40
|
+
|
|
41
|
+
// Use logger, NEVER console.log
|
|
42
|
+
logger.info('Checking command', { command });
|
|
43
|
+
|
|
44
|
+
if (command.trim() === 'ls') {
|
|
45
|
+
return preToolUseOutput({
|
|
46
|
+
systemMessage: 'Auto-approved: ls command is safe.',
|
|
47
|
+
hookSpecificOutput: { permissionDecision: 'allow' },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return preToolUseOutput({ systemMessage: 'Command passed through for review.' });
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Codex (`@goodfoot/agent-hooks/codex`):
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { preToolUseHook, preToolUseOutput } from '@goodfoot/agent-hooks/codex';
|
|
59
|
+
|
|
60
|
+
export default preToolUseHook(async (input, { logger }) => {
|
|
61
|
+
logger.info('Checking tool call', { tool: input.tool_name });
|
|
62
|
+
return preToolUseOutput({});
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Compile
|
|
67
|
+
|
|
68
|
+
The `--agent` flag is required and never inferred — always pass it explicitly:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx -y @goodfoot/agent-hooks --agent claude-code -i "hooks/**/*.ts" -o "./dist/hooks.json"
|
|
72
|
+
npx -y @goodfoot/agent-hooks --agent codex -i "src/**/*.ts" -o ".codex/hooks.json"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Or scaffold a starter project:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npx -y @goodfoot/agent-hooks --agent claude-code --scaffold ./my-hooks --hooks Stop,SubagentStop -o dist/hooks.json
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Run `npx -y @goodfoot/agent-hooks --help` for the full flag reference, including
|
|
82
|
+
Codex-specific options (e.g. `--plugin-root`), `--log`/`--log-env-var`, `--executable`,
|
|
83
|
+
and `--loader`.
|
|
84
|
+
|
|
85
|
+
### 3. Run
|
|
86
|
+
|
|
87
|
+
The compiled output is a self-contained executable per hook; point your agent's hook
|
|
88
|
+
configuration (Claude Code's `hooks.json`, Codex's plugin `hooks.json`) at the compiled
|
|
89
|
+
files, same as with the deprecated per-agent packages.
|
|
90
|
+
|
|
91
|
+
## Hook events
|
|
92
|
+
|
|
93
|
+
Each entry point exports one factory function and one matching output builder per
|
|
94
|
+
supported event. Import both from the same entry point (`@goodfoot/agent-hooks/claude-code`
|
|
95
|
+
or `@goodfoot/agent-hooks/codex`) — do not mix events or output builders across agents.
|
|
96
|
+
|
|
97
|
+
- **Claude Code** (`src/agents/claude-code`): the full 30-factory surface ported from
|
|
98
|
+
`@goodfoot/claude-code-hooks`, including `preToolUseHook`, `postToolUseHook`,
|
|
99
|
+
`sessionStartHook`, `notificationHook`, `permissionRequestHook`, `elicitationHook`,
|
|
100
|
+
task/teammate hooks, `worktreeCreateHook`, and the `tool-helpers` type guards
|
|
101
|
+
(`isBashTool`, `isEditTool`, …).
|
|
102
|
+
- **Codex** (`src/agents/codex`): the 10-factory surface ported from
|
|
103
|
+
`@goodfoot/codex-hooks`, including `preToolUseHook`, `postToolUseHook`,
|
|
104
|
+
`sessionStartHook`, `stopHook`, `subagentStartHook`/`subagentStopHook`,
|
|
105
|
+
`userPromptSubmitHook`, `preCompactHook`/`postCompactHook`, and `permissionRequestHook`.
|
|
106
|
+
|
|
107
|
+
## Fail-open advisory hooks
|
|
108
|
+
|
|
109
|
+
Both entry points support the same opt-in `unexpectedError: "continue"` hook config used
|
|
110
|
+
by the deprecated packages: unexpected runtime failures (stdin read, parse, handler
|
|
111
|
+
execution, output serialization, stdout write, logger cleanup) are swallowed into the
|
|
112
|
+
empty response instead of surfacing a failed-hook error. It is rejected — at the type
|
|
113
|
+
level and at runtime — for events where fail-open would be unsafe (`PreToolUse`,
|
|
114
|
+
`PermissionRequest`, blocking `Stop`/`SubagentStop`, `WorktreeCreate`/`WorktreeRemove` on
|
|
115
|
+
Claude Code; permission/blocking events on Codex). A thrown `HookBlockError` always wins
|
|
116
|
+
over this policy and still blocks.
|
|
22
117
|
|
|
23
118
|
## Core API
|
|
24
119
|
|
|
120
|
+
The root export (`@goodfoot/agent-hooks`, no subpath) exposes only the agent-neutral
|
|
121
|
+
core that each entry point is built on. It has no knowledge of exit codes or stdout
|
|
122
|
+
policy — that's owned entirely by each agent's transport. Use this if you're extending
|
|
123
|
+
an existing entry point or adding support for a new agent; hook authors targeting
|
|
124
|
+
Claude Code or Codex should import from the per-agent entry point instead.
|
|
125
|
+
|
|
25
126
|
### `defineHook(eventName, config, handler, policyGate?)`
|
|
26
127
|
|
|
27
128
|
Factory primitive every agent's per-event factory builds on:
|
|
@@ -127,6 +228,27 @@ Structured logging ported behavior-identically from the source packages:
|
|
|
127
228
|
silent by default, never writes stdout/stderr, optional JSON Lines file output
|
|
128
229
|
via `AGENT_HOOKS_LOG_FILE`, event subscription via `logger.on(level, handler)`.
|
|
129
230
|
|
|
231
|
+
## Exports map policy
|
|
232
|
+
|
|
233
|
+
The `exports` map is an explicit, closed list of subpaths. It deliberately
|
|
234
|
+
does **not** include a `./*` wildcard subpath (unlike the deprecated source
|
|
235
|
+
packages): a wildcard would make every internal module independently importable,
|
|
236
|
+
defeating the root-export lint. This is a permanent rule enforced by the
|
|
237
|
+
package's own test suite (`tests/export-surface.test.ts`), which also carries
|
|
238
|
+
a fail-case fixture proving the check rejects a wildcard entry.
|
|
239
|
+
|
|
240
|
+
## Migrating from `@goodfoot/claude-code-hooks` / `@goodfoot/codex-hooks`
|
|
241
|
+
|
|
242
|
+
Both source packages are deprecated in favor of this one. Migration is a dependency
|
|
243
|
+
swap, not a behavior change:
|
|
244
|
+
|
|
245
|
+
1. Replace the dependency: `@goodfoot/claude-code-hooks` → `@goodfoot/agent-hooks`, or
|
|
246
|
+
`@goodfoot/codex-hooks` → `@goodfoot/agent-hooks`.
|
|
247
|
+
2. Update imports to the matching entry point: `@goodfoot/agent-hooks/claude-code` or
|
|
248
|
+
`@goodfoot/agent-hooks/codex`. Factory and output-builder names are unchanged.
|
|
249
|
+
3. Update `build` scripts and any committed `hooks.json` to invoke the `agent-hooks` CLI
|
|
250
|
+
binary with the required `--agent <claude-code|codex>` flag.
|
|
251
|
+
|
|
130
252
|
## Development
|
|
131
253
|
|
|
132
254
|
```bash
|
package/dist/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ import { scaffoldProject } from "./scaffold.js";
|
|
|
26
26
|
// ============================================================================
|
|
27
27
|
// Constants
|
|
28
28
|
// ============================================================================
|
|
29
|
-
const VERSION = "1.0.
|
|
29
|
+
const VERSION = "1.0.1";
|
|
30
30
|
const DEFAULT_ESBUILD_LOADERS = {
|
|
31
31
|
".md": "text",
|
|
32
32
|
};
|
package/dist/scaffold.js
CHANGED
|
@@ -131,7 +131,7 @@ function generatePackageJson(projectName, outputPath) {
|
|
|
131
131
|
typecheck: "tsc --noEmit",
|
|
132
132
|
},
|
|
133
133
|
dependencies: {
|
|
134
|
-
"@goodfoot/agent-hooks": "^1.0.
|
|
134
|
+
"@goodfoot/agent-hooks": "^1.0.1",
|
|
135
135
|
},
|
|
136
136
|
devDependencies: {
|
|
137
137
|
"@biomejs/biome": "2.4.16",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodfoot/agent-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Unified agent hooks library: shared core runtime with per-agent entry points for Claude Code, Codex, and Antigravity",
|
|
5
5
|
"homepage": "https://github.com/goodfoot-io/marketplace/tree/main/packages/agent-hooks",
|
|
6
6
|
"repository": {
|