@rbbtsn0w/adg 0.4.0-beta.4 → 0.4.0-beta.5

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.
@@ -1,7 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import { adaptPlugin } from "../commands/adapt.js";
4
- import { liftHooksFromDisk } from "../hooks.js";
5
4
  import { addPlugins } from "../commands/install.js";
6
5
  import { validatePlugin } from "../commands/validate.js";
7
6
  import { listPlugins } from "../commands/list.js";
@@ -185,19 +184,6 @@ async function runPluginsVerb(verb, rest, cmd) {
185
184
  }
186
185
  return;
187
186
  }
188
- case "lift-hooks": {
189
- const { positionals } = parseVerb(verb, cmd.flags, rest);
190
- const pluginDir = resolve(positionals[0] ?? process.cwd());
191
- const res = liftHooksFromDisk(pluginDir);
192
- if (!res) {
193
- console.log(ui.meta(`no native hooks found in ${pluginDir} (looked for hooks/hooks.json, hooks/hooks-codex.json)`));
194
- return;
195
- }
196
- console.log(`${ui.ok("lifted")} ${ui.name(res.sources.join(" + "))} ${ui.meta(`-> ${res.file}`)}`);
197
- for (const w of res.warnings)
198
- console.error(ui.warn(` ${w}`));
199
- return;
200
- }
201
187
  case "validate": {
202
188
  const { positionals } = parseVerb(verb, cmd.flags, rest);
203
189
  const pluginDir = resolve(positionals[0] ?? process.cwd());
@@ -111,17 +111,6 @@ export const PLUGIN_COMMANDS = {
111
111
  positional: "<dir> plugin directory (default: current directory)",
112
112
  flags: [],
113
113
  },
114
- "lift-hooks": {
115
- summary: "unify native hook files into a universal .agents/hooks.json",
116
- synopsis: "adg plugins lift-hooks [<dir>]",
117
- positional: "<dir> plugin directory (default: current directory)",
118
- blurb: "The inverse of the hooks DSL compile: read a plugin's native hooks\n" +
119
- "(hooks/hooks.json, hooks/hooks-codex.json), canonicalize the env token, and\n" +
120
- "fold the per-agent differences (matcher/command) into one .agents/hooks.json\n" +
121
- "(adg.hooks/v1) so you maintain a single source. The native files are left in\n" +
122
- "place; a later `adapt` regenerates them from the DSL.",
123
- flags: [],
124
- },
125
114
  "import-skills": {
126
115
  summary: "wrap an existing skills/ dir as a plugin",
127
116
  synopsis: "adg plugins import-skills <skills-dir> --as <name>",
@@ -2,7 +2,7 @@ import { join } from "node:path";
2
2
  import { ADAPTERS } from "../adapters/index.js";
3
3
  import { readManifest } from "../manifest.js";
4
4
  import { writeJson } from "../fsutil.js";
5
- import { compileHooksToDisk } from "../hooks.js";
5
+ import { checkHookEvents } from "../hooks.js";
6
6
  /**
7
7
  * Generate runtime-specific manifests for the given targets from a plugin's
8
8
  * .agents/.plugin.json. The output path honors the manifest's `adapters`
@@ -12,13 +12,11 @@ import { compileHooksToDisk } from "../hooks.js";
12
12
  export function adaptPlugin(pluginDir, targets, selection) {
13
13
  const manifest = readManifest(pluginDir);
14
14
  const results = [];
15
- // Compile the universal hooks DSL (if any) to each target's native hook file
16
- // first, so the adapters' hooks resolvers see the generated files. A no-op for
17
- // plugins that ship hand-authored hooks. Warnings surface but never block.
18
- for (const compiled of compileHooksToDisk(pluginDir, targets)) {
19
- for (const w of compiled.warnings)
20
- console.error(`hooks: ${w}`);
21
- }
15
+ // Lint the plugin's hooks against each target's event support: a hook on an
16
+ // event a target can't fire (e.g. a Claude-only event projected to Codex) is a
17
+ // silent no-op otherwise. Read-only — ADG never transforms hooks.
18
+ for (const w of checkHookEvents(pluginDir, targets))
19
+ console.error(`hooks: ${w}`);
22
20
  for (const target of targets) {
23
21
  const adapter = ADAPTERS[target];
24
22
  if (!adapter)
@@ -6,7 +6,6 @@ import { fromNativeManifest } from "../adapters/reverse.js";
6
6
  import { adaptPlugin } from "./adapt.js";
7
7
  import { copyPluginDir, toPosix, writeJson } from "../fsutil.js";
8
8
  import { folderHash } from "../hash.js";
9
- import { ADG_HOOKS_PATH, GENERATED_HOOK_FILES } from "../hooks.js";
10
9
  import { packageFilter, PROJECTION_DIRS } from "../package.js";
11
10
  import { lockPath, marketplacePath, marketplaceSourcePath, pluginDir } from "../paths.js";
12
11
  import { readLock, upsertEntry, writeLock } from "../lock.js";
@@ -20,22 +19,9 @@ import { skillDescriptionLoader } from "../skills.js";
20
19
  import { resolveAgents } from "../agents/index.js";
21
20
  // Generated runtime projections never count toward a plugin's content hash.
22
21
  const HASH_IGNORE = PROJECTION_DIRS;
23
- /**
24
- * Content hash over a plugin's packaged payload. Mirrors the projection rule for
25
- * the hooks DSL: when a plugin opts in (`.agents/hooks.json` present), the
26
- * compiled `hooks/*.json` outputs are generated, so they are excluded from the
27
- * hash — letting an authoring source (no compiled files) and an installed copy
28
- * (with them) hash identically, and keeping a compiler change from bumping the
29
- * content hash.
30
- */
22
+ /** Content hash over a plugin's packaged payload (hooks files are authored content, not generated). */
31
23
  function contentHash(dir, manifest) {
32
- const base = packageFilter(manifest, { includeProjections: false });
33
- // `GENERATED_HOOK_FILES` keys are POSIX; normalize so a backslash path (Windows)
34
- // still matches and the generated files are excluded from the hash there too.
35
- const include = existsSync(join(dir, ADG_HOOKS_PATH))
36
- ? (rel) => base(rel) && !GENERATED_HOOK_FILES.has(toPosix(rel))
37
- : base;
38
- return folderHash(dir, HASH_IGNORE, include);
24
+ return folderHash(dir, HASH_IGNORE, packageFilter(manifest, { includeProjections: false }));
39
25
  }
40
26
  /**
41
27
  * Install a single local plugin directory into a plugins directory: copy the
package/dist/src/hooks.js CHANGED
@@ -1,262 +1,69 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { writeJson } from "./fsutil.js";
3
+ import { resolveCodexHooksFile } from "./adapters/codex.js";
4
4
  /**
5
- * ADG universal hooks DSL (`adg.hooks/v1`) and its per-agent compiler.
6
- *
7
- * Agents do not share a hook format: Claude auto-loads `hooks/hooks.json` and
8
- * uses `${CLAUDE_PLUGIN_ROOT}`; Codex references an explicit file and uses
9
- * `${PLUGIN_ROOT}`; and real plugins (e.g. superpowers) genuinely diverge per
10
- * agent — different matcher vocabularies (`clear|compact` vs `resume|clear`) and
11
- * even different scripts. So the DSL is authored once with a canonical
12
- * `${PLUGIN_ROOT}` token, and carries *optional* per-target overrides for the
13
- * parts that truly differ. The compiler resolves overrides, translates the env
14
- * token, and warns (never silently drops) on events a target may not support.
15
- *
16
- * The universal source lives at `.agents/hooks.json` and is opt-in: plugins that
17
- * still ship hand-authored `hooks/*.json` keep working unchanged.
5
+ * Hook events each target fires, from the official docs (Claude
6
+ * code.claude.com/docs/en/hooks, Codex developers.openai.com/codex/hooks). Used
7
+ * only to warn — never to drop — so an event these lists haven't caught up with
8
+ * is reported as unknown rather than hidden. Codex is a subset of Claude's set.
18
9
  */
19
- export const ADG_HOOKS_SCHEMA_VERSION = "adg.hooks/v1";
20
- /** Canonical location of the universal hooks document inside a plugin. */
21
- export const ADG_HOOKS_PATH = ".agents/hooks.json";
22
- /**
23
- * Where each target's compiled hook file lands (plugin-relative, POSIX). Claude
24
- * auto-loads `hooks/hooks.json`; Codex references `hooks/hooks-codex.json` from
25
- * its manifest. These are generated outputs — shipped, but excluded from the
26
- * content hash (see `GENERATED_HOOK_FILES`).
27
- */
28
- export const HOOK_OUTPUT = {
29
- claude: "hooks/hooks.json",
30
- codex: "hooks/hooks-codex.json",
31
- };
32
- /** The set of generated hook files, treated like adapter projections (not hashed). */
33
- export const GENERATED_HOOK_FILES = new Set(Object.values(HOOK_OUTPUT));
34
- /** The plugin-root env variable each target expands. */
35
- const ENV_TOKEN = {
36
- claude: "CLAUDE_PLUGIN_ROOT",
37
- codex: "PLUGIN_ROOT",
10
+ const SUPPORTED_EVENTS = {
11
+ claude: new Set([
12
+ "SessionStart", "Setup", "SessionEnd",
13
+ "UserPromptSubmit", "UserPromptExpansion", "Stop", "StopFailure",
14
+ "PreToolUse", "PostToolUse", "PostToolUseFailure", "PostToolBatch",
15
+ "PermissionRequest", "PermissionDenied",
16
+ "SubagentStart", "SubagentStop", "TeammateIdle",
17
+ "TaskCreated", "TaskCompleted",
18
+ "InstructionsLoaded", "ConfigChange", "FileChanged", "CwdChanged",
19
+ "WorktreeCreate", "WorktreeRemove",
20
+ "PreCompact", "PostCompact",
21
+ "Elicitation", "ElicitationResult", "Notification", "MessageDisplay",
22
+ ]),
23
+ codex: new Set([
24
+ "SessionStart", "SubagentStart", "PreToolUse", "PermissionRequest",
25
+ "PostToolUse", "PreCompact", "PostCompact", "UserPromptSubmit",
26
+ "SubagentStop", "Stop",
27
+ ]),
38
28
  };
39
- /**
40
- * Documented hook events. Used only to *warn* on an unfamiliar event — the
41
- * compiler still emits it, so an event this list hasn't caught up with is never
42
- * silently dropped. (Codex's vocabulary is not fully published; this is Claude's
43
- * set, treated as the canonical baseline.)
44
- */
45
- const KNOWN_EVENTS = new Set([
46
- "PreToolUse",
47
- "PostToolUse",
48
- "UserPromptSubmit",
49
- "Notification",
50
- "Stop",
51
- "SubagentStop",
52
- "PreCompact",
53
- "SessionStart",
54
- "SessionEnd",
55
- ]);
56
- /** Reserved object keys that must never be used as event names (prototype-pollution guard). */
57
- const UNSAFE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
58
- const isUnsafeKey = (key) => UNSAFE_KEYS.has(key);
59
- /** Replace the canonical `${PLUGIN_ROOT}` token with the target's env variable. */
60
- function translateEnv(value, target) {
61
- // Function replacement so `$` in the substitution is never treated specially.
62
- return value.replaceAll("${PLUGIN_ROOT}", () => `\${${ENV_TOKEN[target]}}`);
29
+ /** The hooks file `target` will actually load (plugin-relative), or undefined. */
30
+ function hooksFileForTarget(pluginDir, target) {
31
+ // Codex references a file from its manifest (its own variant if shipped, else
32
+ // the shared file) — reuse the adapter's resolution so the lint matches reality.
33
+ if (target === "codex")
34
+ return resolveCodexHooksFile(pluginDir, "./hooks/");
35
+ // Claude auto-loads only the standard hooks/hooks.json.
36
+ return existsSync(join(pluginDir, "hooks", "hooks.json")) ? "hooks/hooks.json" : undefined;
63
37
  }
64
- /**
65
- * Compile the universal hooks document into one target's native `hooks.json`
66
- * object, resolving per-target overrides and translating the env token. Returns
67
- * the native object plus any non-fatal warnings (unknown events).
68
- */
69
- export function compileHooks(src, target) {
70
- const warnings = [];
71
- const out = { hooks: {} };
72
- for (const [event, entries] of Object.entries(src.hooks)) {
73
- if (isUnsafeKey(event)) {
74
- // Defensive: a reserved name (e.g. "__proto__") would mutate the map's
75
- // prototype rather than add an event. parseAdgHooks rejects these at the
76
- // authoring boundary; skip-with-warning covers direct callers.
77
- warnings.push(`skipped reserved hook event name "${event}"`);
78
- continue;
79
- }
80
- if (!KNOWN_EVENTS.has(event)) {
81
- warnings.push(`unknown hook event "${event}" — emitted for ${target} but it may not fire`);
82
- }
83
- out.hooks[event] = entries.map((entry) => {
84
- const matcher = entry.matcherByTarget?.[target] ?? entry.matcher;
85
- const actions = entry.actions.map((a) => {
86
- const command = translateEnv(a.commandByTarget?.[target] ?? a.command, target);
87
- return { type: a.type, command, ...(a.async !== undefined ? { async: a.async } : {}) };
88
- });
89
- return { ...(matcher !== undefined ? { matcher } : {}), hooks: actions };
90
- });
38
+ /** Event names declared in a Claude-format hooks file; tolerant (the agents validate). */
39
+ function hookEventsOf(file) {
40
+ try {
41
+ const doc = JSON.parse(readFileSync(file, "utf8"));
42
+ const map = doc?.hooks;
43
+ return typeof map === "object" && map !== null ? Object.keys(map) : [];
91
44
  }
92
- return { hooks: out, warnings };
93
- }
94
- /** Rewrite any agent's plugin-root token back to the canonical `${PLUGIN_ROOT}`. */
95
- function canonicalizeEnv(value) {
96
- return value.replaceAll("${CLAUDE_PLUGIN_ROOT}", () => "${PLUGIN_ROOT}");
97
- }
98
- /**
99
- * Lift native hook files into one universal document — the inverse of
100
- * `compileHooks`. Where the targets agree, a single canonical value is emitted;
101
- * where they genuinely diverge (matcher or command), the difference is captured
102
- * as a per-target override, so recompiling reproduces each native file. Targets
103
- * are aligned positionally per event; a shape mismatch is reported (not dropped)
104
- * and the primary (Claude when present) is used as the structural base.
105
- */
106
- export function liftHooks(natives) {
107
- const warnings = [];
108
- const present = Object.keys(natives).filter((t) => natives[t]);
109
- const events = new Set(present.flatMap((t) => Object.keys(natives[t].hooks)));
110
- const out = { schemaVersion: ADG_HOOKS_SCHEMA_VERSION, hooks: {} };
111
- for (const event of events) {
112
- if (isUnsafeKey(event)) {
113
- warnings.push(`skipped reserved hook event name "${event}"`);
114
- continue;
115
- }
116
- // An event only some targets define becomes a *shared* entry after compile —
117
- // so it would start firing on agents that never had it. Surface that.
118
- const definedIn = present.filter((t) => natives[t].hooks[event]);
119
- if (present.length > 1 && definedIn.length < present.length) {
120
- warnings.push(`hook event "${event}" is only defined for ${definedIn.join(", ")}; it will apply to every agent after compile`);
121
- }
122
- const primary = natives.claude?.hooks[event] ? "claude" : "codex";
123
- const other = present.find((t) => t !== primary && natives[t].hooks[event]);
124
- const baseEntries = natives[primary].hooks[event];
125
- const otherEntries = other ? natives[other].hooks[event] : undefined;
126
- if (other && otherEntries && otherEntries.length !== baseEntries.length) {
127
- warnings.push(`hook event "${event}" has a different shape per target; lifted from ${primary}`);
128
- }
129
- out.hooks[event] = baseEntries.map((entry, i) => {
130
- const oEntry = otherEntries?.[i];
131
- const adg = { actions: [] };
132
- if (entry.matcher !== undefined)
133
- adg.matcher = entry.matcher;
134
- if (other && oEntry && oEntry.matcher !== undefined && oEntry.matcher !== entry.matcher) {
135
- adg.matcherByTarget = { [other]: oEntry.matcher };
136
- }
137
- adg.actions = entry.hooks.map((act, j) => {
138
- const a = { type: "command", command: canonicalizeEnv(act.command) };
139
- if (act.async !== undefined)
140
- a.async = act.async;
141
- const oAct = oEntry?.hooks[j];
142
- if (other && oAct) {
143
- const oCmd = canonicalizeEnv(oAct.command);
144
- if (oCmd !== a.command)
145
- a.commandByTarget = { [other]: oCmd };
146
- }
147
- return a;
148
- });
149
- return adg;
150
- });
45
+ catch {
46
+ return [];
151
47
  }
152
- return { hooks: out, warnings };
153
48
  }
154
49
  /**
155
- * Read a plugin's native hook files (`hooks/hooks.json`, `hooks/hooks-codex.json`)
156
- * and lift them into one universal `.agents/hooks.json`, the inverse of the
157
- * compile step. Returns undefined when the plugin ships no native hooks (nothing
158
- * to convert). The native files are left in place — a later adapt regenerates
159
- * them from the DSL. Throws on a malformed native file rather than guessing.
50
+ * Warn when a plugin's hooks file declares an event the target agent can't fire,
51
+ * so a no-op hook (e.g. a Claude-only `UserPromptExpansion` projected to Codex)
52
+ * surfaces instead of silently doing nothing. Pure read-only lint — no transform.
160
53
  */
161
- export function liftHooksFromDisk(pluginDir) {
162
- const natives = {};
163
- const sources = [];
164
- for (const target of Object.keys(HOOK_OUTPUT)) {
165
- const file = join(pluginDir, HOOK_OUTPUT[target]);
166
- if (!existsSync(file))
54
+ export function checkHookEvents(pluginDir, targets) {
55
+ const warnings = [];
56
+ for (const t of targets) {
57
+ if (t !== "claude" && t !== "codex")
167
58
  continue;
168
- const parsed = JSON.parse(readFileSync(file, "utf8"));
169
- const hooksMap = parsed?.hooks;
170
- // `typeof null === "object"`, so guard the `hooks` map against null explicitly.
171
- if (typeof parsed !== "object" || parsed === null || typeof hooksMap !== "object" || hooksMap === null) {
172
- throw new Error(`${HOOK_OUTPUT[target]} is not a valid hooks file (missing \`hooks\` map)`);
173
- }
174
- natives[target] = parsed;
175
- sources.push(target);
176
- }
177
- if (sources.length === 0)
178
- return undefined;
179
- const { hooks, warnings } = liftHooks(natives);
180
- writeJson(join(pluginDir, ADG_HOOKS_PATH), hooks);
181
- return { file: ADG_HOOKS_PATH, sources, warnings };
182
- }
183
- /**
184
- * If `pluginDir` opts into the DSL (has `.agents/hooks.json`), compile it to each
185
- * requested target's native hook file and write them under `hooks/`. A no-op
186
- * (returns []) when the DSL source is absent — plugins shipping hand-authored
187
- * `hooks/*.json` are left untouched. Only claude/codex are compiled today;
188
- * targets without a `HOOK_OUTPUT` mapping (e.g. antigravity) are skipped.
189
- */
190
- export function compileHooksToDisk(pluginDir, targets) {
191
- const src = join(pluginDir, ADG_HOOKS_PATH);
192
- if (!existsSync(src))
193
- return [];
194
- const doc = parseAdgHooks(JSON.parse(readFileSync(src, "utf8")));
195
- const written = [];
196
- for (const target of targets) {
197
- if (!(target in HOOK_OUTPUT))
59
+ const rel = hooksFileForTarget(pluginDir, t);
60
+ if (!rel)
198
61
  continue;
199
- const t = target;
200
- const { hooks, warnings } = compileHooks(doc, t);
201
- const rel = HOOK_OUTPUT[t];
202
- writeJson(join(pluginDir, rel), hooks);
203
- written.push({ file: rel, warnings });
204
- }
205
- return written;
206
- }
207
- const VALID_TARGETS = new Set(["claude", "codex"]);
208
- /** Reject an unknown target key in an override map — it would be silently ignored at compile time. */
209
- function checkTargetKeys(value, where) {
210
- if (value === undefined)
211
- return;
212
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
213
- throw new Error(`${where} must be an object keyed by target`);
214
- }
215
- for (const [key, val] of Object.entries(value)) {
216
- if (!VALID_TARGETS.has(key))
217
- throw new Error(`${where} has unknown target "${key}" (expected claude|codex)`);
218
- // A non-string override would crash translateEnv (`.replaceAll` on a non-string).
219
- if (typeof val !== "string")
220
- throw new Error(`${where} value for target "${key}" must be a string`);
221
- }
222
- }
223
- /**
224
- * Parse and shallowly validate a raw `.agents/hooks.json` payload. Throws with a
225
- * pointed message rather than letting a malformed document surface as a deep
226
- * runtime error during compilation.
227
- */
228
- export function parseAdgHooks(raw) {
229
- if (typeof raw !== "object" || raw === null)
230
- throw new Error("hooks document must be a JSON object");
231
- const d = raw;
232
- if (d.schemaVersion !== ADG_HOOKS_SCHEMA_VERSION) {
233
- throw new Error(`hooks document must declare schemaVersion "${ADG_HOOKS_SCHEMA_VERSION}"`);
234
- }
235
- if (typeof d.hooks !== "object" || d.hooks === null)
236
- throw new Error("hooks document missing `hooks` map");
237
- for (const [event, entries] of Object.entries(d.hooks)) {
238
- if (isUnsafeKey(event))
239
- throw new Error(`hook event name "${event}" is reserved and not allowed`);
240
- if (!Array.isArray(entries))
241
- throw new Error(`hook event "${event}" must be an array of entries`);
242
- for (const entry of entries) {
243
- if (typeof entry !== "object" || entry === null)
244
- throw new Error(`hook event "${event}" entry must be an object`);
245
- const e = entry;
246
- if (!Array.isArray(e.actions))
247
- throw new Error(`hook event "${event}" entry missing \`actions\` array`);
248
- checkTargetKeys(e.matcherByTarget, `hook event "${event}" matcherByTarget`);
249
- for (const action of e.actions) {
250
- if (typeof action !== "object" || action === null)
251
- throw new Error(`hook action in "${event}" must be an object`);
252
- const a = action;
253
- if (a.type !== "command")
254
- throw new Error(`hook action in "${event}" must have type "command"`);
255
- if (typeof a.command !== "string")
256
- throw new Error(`hook action in "${event}" missing string \`command\``);
257
- checkTargetKeys(a.commandByTarget, `hook action in "${event}" commandByTarget`);
62
+ for (const event of hookEventsOf(join(pluginDir, rel))) {
63
+ if (!SUPPORTED_EVENTS[t].has(event)) {
64
+ warnings.push(`hook event "${event}" is not a known ${t} hook event — ${t} will not fire it`);
258
65
  }
259
66
  }
260
67
  }
261
- return raw;
68
+ return warnings;
262
69
  }
package/docs/authoring.md CHANGED
@@ -165,56 +165,40 @@ the runtime projections and the installed package.
165
165
 
166
166
  ## Hooks
167
167
 
168
- Agents do not share a hook format. Claude **auto-loads** `hooks/hooks.json` and
169
- expands `${CLAUDE_PLUGIN_ROOT}`; Codex references an explicit
170
- `hooks/hooks-codex.json` from its manifest and expands `${PLUGIN_ROOT}`; and the
171
- matcher vocabularies differ (e.g. `startup|clear|compact` vs
172
- `startup|resume|clear`). Two ways to author:
173
-
174
- - **Hand-authored (passthrough)** — ship the native files yourself under
175
- `hooks/`. ADG carries them as-is: Claude auto-loads `hooks/hooks.json`, and the
176
- Codex projection references `hooks/hooks-codex.json` (falling back to
177
- `hooks/hooks.json`). Nothing is rewritten.
178
-
179
- - **Universal DSL (recommended, author once)** — add `.agents/hooks.json`
180
- (`adg.hooks/v1`). Write the canonical command with the **braced** `${PLUGIN_ROOT}`
181
- token (only `${PLUGIN_ROOT}` is translated — a bare `$PLUGIN_ROOT` is left
182
- as-is); capture the parts that genuinely differ per agent as `matcherByTarget` /
183
- `commandByTarget` overrides (keyed by `claude`/`codex`). On `adapt`/install ADG
184
- compiles it to each target's native file (`hooks/hooks.json`,
185
- `hooks/hooks-codex.json`), translating the env token and applying overrides. The
186
- compiled files ship but do not count toward the content hash. An event ADG
187
- doesn't recognize is still emitted, with a warning.
188
-
189
- ```json
190
- {
191
- "schemaVersion": "adg.hooks/v1",
192
- "hooks": {
193
- "SessionStart": [
194
- {
195
- "matcher": "startup|clear|compact",
196
- "matcherByTarget": { "codex": "startup|resume|clear" },
197
- "actions": [
198
- {
199
- "type": "command",
200
- "command": "\"${PLUGIN_ROOT}/hooks/run-hook.cmd\" session-start",
201
- "commandByTarget": { "codex": "\"${PLUGIN_ROOT}/hooks/run-hook.cmd\" session-start-codex" },
202
- "async": false
203
- }
204
- ]
205
- }
206
- ]
207
- }
168
+ Agent hook formats have **converged on Claude's**: Claude Code's hook schema is the
169
+ de-facto standard, Codex consumes the same structure (and accepts
170
+ `${CLAUDE_PLUGIN_ROOT}`), and Antigravity uses the same shape. So ADG does **not**
171
+ define its own hook DSL — you author hooks once in **Claude's native format** and
172
+ ADG only routes/lints them. (Rationale and the unify-vs-adopt decision rule:
173
+ [docs/hooks-strategy.md](hooks-strategy.md).)
174
+
175
+ - **Author** `hooks/hooks.json` in Claude's hook format (see the
176
+ [Claude hooks reference](https://code.claude.com/docs/en/hooks)), using
177
+ `${CLAUDE_PLUGIN_ROOT}` for the plugin root.
178
+ - **Claude** auto-loads `hooks/hooks.json`; ADG omits the manifest `hooks` field so
179
+ the load isn't duplicated.
180
+ - **Codex** consumes the same file: ADG references it from `.codex-plugin/plugin.json`.
181
+ Need genuinely different Codex behavior? Ship a `hooks/hooks-codex.json` and ADG
182
+ references that for Codex instead (per-agent override; Claude still uses
183
+ `hooks/hooks.json`).
184
+ - **Lint** — at `adapt`/install ADG warns when your hooks use an event a target
185
+ can't fire (e.g. `UserPromptExpansion` is Claude-only, so it never fires in Codex).
186
+ It only warns; it never rewrites your hooks.
187
+
188
+ ```json
189
+ {
190
+ "hooks": {
191
+ "SessionStart": [
192
+ {
193
+ "matcher": "startup|clear|compact",
194
+ "hooks": [
195
+ { "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" session-start" }
196
+ ]
197
+ }
198
+ ]
208
199
  }
209
- ```
210
-
211
- Schema: [adg-hooks.schema.json](../schemas/adg-hooks.schema.json).
212
-
213
- **Migrating an existing plugin** — already maintain native `hooks/hooks.json` +
214
- `hooks/hooks-codex.json` by hand? Run `adg plugins lift-hooks [<dir>]` to fold
215
- both into one `.agents/hooks.json` (canonicalizing the env token and capturing
216
- per-agent differences as overrides). The native files stay put; a later `adapt`
217
- regenerates them from the DSL.
200
+ }
201
+ ```
218
202
 
219
203
  ---
220
204
 
@@ -0,0 +1,82 @@
1
+ # Design note: hooks strategy & the unify-vs-adopt principle
2
+
3
+ **Status:** Accepted · **Date:** 2026-06-26 · **Context:** issue #32, the retired `adg.hooks/v1` DSL
4
+
5
+ This note records *why* ADG does not own a hooks DSL, and the decision rule that produced that outcome —
6
+ so the same wheel isn't reinvented.
7
+
8
+ ## The principle
9
+
10
+ When a feature spans multiple runtimes, **build a unifying ADG layer only when both hold:**
11
+ 1. the runtimes **genuinely diverge** (not just cosmetically), **and**
12
+ 2. there is **no de-facto standard or convergence** to adopt instead.
13
+
14
+ Otherwise, **adopt the de-facto standard** and keep ADG's role to routing/linting. And within any unifying
15
+ layer, draw a hard line:
16
+
17
+ - **Mechanical translation — ADG may do it.** Deterministic, behavior-preserving rewrites: env-token
18
+ substitution, event-name aliasing, file location/discovery. Same behavior, different spelling.
19
+ - **Behavioral synthesis — ADG must not do it.** Which matcher to fire on, which script/command to run.
20
+ That is the author's intent and cannot be invented; it can only be authored.
21
+
22
+ ## Worked example: hooks
23
+
24
+ The three agents' hook **formats have converged on Claude's**: same JSON shape
25
+ (`{hooks:{Event:[{matcher,hooks:[{type,command}]}]}}`), Codex consumes it and accepts
26
+ `${CLAUDE_PLUGIN_ROOT}`, Antigravity is same-shape. So criterion (2) fails → **adopt Claude's format**, don't
27
+ invent a 4th.
28
+
29
+ `superpowers` ships three hook files (`hooks.json`, `hooks-codex.json`, `hooks-cursor.json`) — but that is
30
+ **behavioral divergence, not format divergence**: the author chose different matchers and *different scripts*
31
+ per agent. A DSL with `commandByTarget`/`matcherByTarget` does not make that "author once" — the author still
32
+ specifies both behaviors, just in one file. So the retired DSL had **no sweet spot**:
33
+ - homogeneous plugin → a single native `hooks/hooks.json` already runs on all three (DSL adds nothing);
34
+ - divergent plugin → DSL only relocates the N behaviors into override syntax (DSL adds syntax, not leverage).
35
+
36
+ ### What ADG does instead (router + linter)
37
+ - **Same behavior across agents → one file.** Author `hooks/hooks.json` in Claude's format; Claude
38
+ auto-loads it, Codex references the same file. This is the real "one file, many agents".
39
+ - **Different behavior per agent → N native files + routing.** Author ships `hooks/hooks-codex.json` (etc.);
40
+ ADG's adapter resolvers route each agent to its file. ADG does not synthesize variants.
41
+ - **Lint** (`checkHookEvents`, `src/hooks.ts`): warn when a hook uses an event a target can't fire (e.g.
42
+ Claude-only `UserPromptExpansion` on Codex) — read-only, never a transform.
43
+
44
+ ## Conditional plan: thin mechanical translation (build only when a target needs it)
45
+
46
+ ADG currently supports Claude + Codex hook targets, and **neither needs translation** (Codex accepts Claude's
47
+ format + `${CLAUDE_PLUGIN_ROOT}`). So no translation code exists today — deliberately (YAGNI).
48
+
49
+ **Trigger to implement:** ADG adds a hook target that diverges *mechanically* — most likely **Antigravity**
50
+ or **Cursor**. When that happens, add only these deterministic, behavior-preserving steps to the per-agent
51
+ hook handling (a small `HookTranslation` per target, near the adapter resolvers — *not* a revived DSL):
52
+
53
+ - **Env-token substitution** — rewrite `${CLAUDE_PLUGIN_ROOT}` → the target's plugin-root var, for targets
54
+ that don't accept Claude's. (Claude: none; Codex: none — accepts it; Antigravity: TBD.)
55
+ - **Event-name aliases** — a per-target rename table for events that are the same concept under a different
56
+ name. Known/suspected (verify against the live agent before shipping):
57
+
58
+ | Canonical (Claude) | Antigravity | Codex |
59
+ |---|---|---|
60
+ | `PostToolUse` | `PostInvocation` (reported) | `PostToolUse` |
61
+ | (others) | TBD — verify from the binary/docs | subset, same names |
62
+
63
+ **Out of scope even then:** matcher values, command/script selection, async semantics — behavioral, author-owned.
64
+
65
+ ## The manifest is the same *pattern*, not the same *conclusion*
66
+
67
+ `adg.plugin/v1` (`.agents/.plugin.json`) uses the same canonical-plus-adapters shape, but it stays justified:
68
+ 1. manifests **genuinely diverge** (per-vendor locations, `skills` encoded as bare-id array vs path array,
69
+ different metadata; superpowers ships 5 manifests) and there is **no adopted manifest standard**
70
+ (`AGENTS.md` standardizes *instructions*, not packaging) — so criteria (1) and (2) both hold; and
71
+ 2. the manifest is also **ADG's own control plane** — `dependencies`, `strict`, partial-install selection,
72
+ and `.plugin-lock.json` integrity all key off it. Hooks carried no such ADG-internal role.
73
+
74
+ Its **projection mapping** (skills/commands/agents/hooks/mcp → per-agent) shares the hooks risk and would
75
+ lose value if vendors converge; its **control-plane core** does not.
76
+
77
+ ## Revisit triggers
78
+ - `AGENTS.md` (Linux Foundation / Agentic AI Foundation) expands to cover plugin packaging/manifests.
79
+ - Vendors converge on component field encodings (e.g. a single `skills` form).
80
+ - A formal cross-vendor **hooks** protocol emerges.
81
+
82
+ If any fires, shrink the relevant ADG layer toward routing + control-plane only — the move made here for hooks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.4.0-beta.4",
3
+ "version": "0.4.0-beta.5",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,70 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://RbBtSn0w.dev/schemas/adg-hooks.schema.json",
4
- "title": "ADG Universal Hooks",
5
- "description": "Universal hooks document stored at .agents/hooks.json. Authored once with the canonical ${PLUGIN_ROOT} token and optional per-target overrides; compiled to each agent's native hook file (Claude hooks/hooks.json, Codex hooks/hooks-codex.json).",
6
- "type": "object",
7
- "required": ["schemaVersion", "hooks"],
8
- "additionalProperties": false,
9
- "properties": {
10
- "schemaVersion": {
11
- "type": "string",
12
- "description": "Hooks schema version.",
13
- "const": "adg.hooks/v1"
14
- },
15
- "hooks": {
16
- "type": "object",
17
- "description": "Map of event name (e.g. SessionStart) to its matcher/action groups.",
18
- "additionalProperties": {
19
- "type": "array",
20
- "items": { "$ref": "#/definitions/entry" }
21
- }
22
- }
23
- },
24
- "definitions": {
25
- "target": {
26
- "type": "string",
27
- "enum": ["claude", "codex"]
28
- },
29
- "entry": {
30
- "type": "object",
31
- "required": ["actions"],
32
- "additionalProperties": false,
33
- "properties": {
34
- "matcher": {
35
- "type": "string",
36
- "description": "Default matcher for this group."
37
- },
38
- "matcherByTarget": {
39
- "type": "object",
40
- "description": "Per-target matcher override (agents use different matcher vocabularies).",
41
- "additionalProperties": { "type": "string" },
42
- "propertyNames": { "$ref": "#/definitions/target" }
43
- },
44
- "actions": {
45
- "type": "array",
46
- "items": { "$ref": "#/definitions/action" }
47
- }
48
- }
49
- },
50
- "action": {
51
- "type": "object",
52
- "required": ["type", "command"],
53
- "additionalProperties": false,
54
- "properties": {
55
- "type": { "type": "string", "const": "command" },
56
- "command": {
57
- "type": "string",
58
- "description": "Canonical command line; reference the plugin root as ${PLUGIN_ROOT}."
59
- },
60
- "async": { "type": "boolean" },
61
- "commandByTarget": {
62
- "type": "object",
63
- "description": "Per-target command override for genuine behavioral divergence (still using ${PLUGIN_ROOT}).",
64
- "additionalProperties": { "type": "string" },
65
- "propertyNames": { "$ref": "#/definitions/target" }
66
- }
67
- }
68
- }
69
- }
70
- }