@rbbtsn0w/adg 0.4.0-beta.3 → 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.
- package/dist/src/adapters/anthropic.js +51 -2
- package/dist/src/adapters/codex.js +33 -1
- package/dist/src/adapters/index.js +2 -2
- package/dist/src/agents/claude.js +7 -1
- package/dist/src/commands/adapt.js +6 -0
- package/dist/src/commands/install.js +16 -3
- package/dist/src/hooks.js +69 -0
- package/docs/authoring.md +42 -1
- package/docs/hooks-strategy.md +82 -0
- package/package.json +1 -1
|
@@ -1,6 +1,52 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
1
2
|
import { join } from "node:path";
|
|
2
3
|
import { resolveProjectedSkills } from "../skills.js";
|
|
3
4
|
import { isExposed } from "../components.js";
|
|
5
|
+
/**
|
|
6
|
+
* Claude auto-loads this plugin-relative path; declaring it in `manifest.hooks`
|
|
7
|
+
* duplicates the load and fails ("Duplicate hooks file detected").
|
|
8
|
+
*/
|
|
9
|
+
const STANDARD_HOOKS = "hooks/hooks.json";
|
|
10
|
+
/**
|
|
11
|
+
* Translate ADG's `hooks` (a *directory*, per the universal manifest) into the
|
|
12
|
+
* value Claude's plugin.json expects, or undefined to omit the field.
|
|
13
|
+
*
|
|
14
|
+
* Two Claude rules drive this:
|
|
15
|
+
* - `hooks` must be a config *file*, not a directory — a bare `./hooks/` is
|
|
16
|
+
* rejected with `hooks: Invalid input`, breaking `claude plugin install`.
|
|
17
|
+
* - the standard `hooks/hooks.json` is loaded automatically, so `manifest.hooks`
|
|
18
|
+
* must reference only *additional* files — repeating the standard path fails
|
|
19
|
+
* to load with "Duplicate hooks file detected".
|
|
20
|
+
*
|
|
21
|
+
* So: resolve the directory to its config file (conventional `hooks.json`, else
|
|
22
|
+
* its sole `*.json`), pass an explicit `*.json` reference through, and return
|
|
23
|
+
* undefined when the result is unresolvable/ambiguous OR is the auto-loaded
|
|
24
|
+
* standard path — in every "undefined" case the caller omits `hooks`.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveClaudeHooksFile(pluginDir, hooks) {
|
|
27
|
+
const rel = hooks.replace(/\/+$/, "");
|
|
28
|
+
const abs = join(pluginDir, rel);
|
|
29
|
+
let file;
|
|
30
|
+
if (existsSync(abs) && statSync(abs).isFile()) {
|
|
31
|
+
file = hooks.endsWith(".json") ? hooks : undefined;
|
|
32
|
+
}
|
|
33
|
+
else if (existsSync(abs) && statSync(abs).isDirectory()) {
|
|
34
|
+
if (existsSync(join(abs, "hooks.json")))
|
|
35
|
+
file = `${rel}/hooks.json`;
|
|
36
|
+
else {
|
|
37
|
+
const jsons = readdirSync(abs).filter((f) => f.endsWith(".json") && statSync(join(abs, f)).isFile());
|
|
38
|
+
file = jsons.length === 1 ? `${rel}/${jsons[0]}` : undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Path missing on disk: only trust an explicit file reference.
|
|
43
|
+
file = hooks.endsWith(".json") ? hooks : undefined;
|
|
44
|
+
}
|
|
45
|
+
if (!file)
|
|
46
|
+
return undefined;
|
|
47
|
+
// Drop the auto-loaded standard path; only non-standard hook files belong here.
|
|
48
|
+
return file.replace(/^\.\//, "") === STANDARD_HOOKS ? undefined : file;
|
|
49
|
+
}
|
|
4
50
|
/**
|
|
5
51
|
* Generate a Claude (.claude-plugin/plugin.json) manifest from an ADG manifest.
|
|
6
52
|
*
|
|
@@ -27,8 +73,11 @@ export function toAnthropicManifest(pluginDir, manifest, selection) {
|
|
|
27
73
|
out.commands = manifest.commands;
|
|
28
74
|
if (manifest.agents && isExposed(selection, "agents"))
|
|
29
75
|
out.agents = manifest.agents;
|
|
30
|
-
if (manifest.hooks && isExposed(selection, "hooks"))
|
|
31
|
-
|
|
76
|
+
if (manifest.hooks && isExposed(selection, "hooks")) {
|
|
77
|
+
const hooksFile = resolveClaudeHooksFile(pluginDir, manifest.hooks);
|
|
78
|
+
if (hooksFile)
|
|
79
|
+
out.hooks = hooksFile;
|
|
80
|
+
}
|
|
32
81
|
if (manifest.mcp && isExposed(selection, "mcp"))
|
|
33
82
|
out.mcp = manifest.mcp;
|
|
34
83
|
if (manifest.apps && isExposed(selection, "apps"))
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
1
2
|
import { join } from "node:path";
|
|
2
3
|
import { resolveProjectedSkills } from "../skills.js";
|
|
4
|
+
import { isExposed } from "../components.js";
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the hooks config *file* Codex should reference. ADG declares `hooks` as
|
|
7
|
+
* a directory, but Codex (unlike Claude) has no auto-load — it needs an explicit
|
|
8
|
+
* file path. Prefer a Codex-specific variant (`hooks/hooks-codex.json`, the
|
|
9
|
+
* convention upstream plugins like superpowers use), then the standard
|
|
10
|
+
* `hooks/hooks.json`, else the directory's sole `*.json`. An explicit `*.json`
|
|
11
|
+
* reference passes through; an unresolvable/ambiguous directory yields undefined
|
|
12
|
+
* so the caller omits `hooks`.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveCodexHooksFile(pluginDir, hooks) {
|
|
15
|
+
const rel = hooks.replace(/\/+$/, "");
|
|
16
|
+
const abs = join(pluginDir, rel);
|
|
17
|
+
if (existsSync(abs) && statSync(abs).isDirectory()) {
|
|
18
|
+
for (const candidate of ["hooks-codex.json", "hooks.json"]) {
|
|
19
|
+
if (existsSync(join(abs, candidate)))
|
|
20
|
+
return `${rel}/${candidate}`;
|
|
21
|
+
}
|
|
22
|
+
const jsons = readdirSync(abs).filter((f) => f.endsWith(".json") && statSync(join(abs, f)).isFile());
|
|
23
|
+
return jsons.length === 1 ? `${rel}/${jsons[0]}` : undefined;
|
|
24
|
+
}
|
|
25
|
+
// A file (or a path missing on disk): only trust an explicit *.json reference.
|
|
26
|
+
return hooks.endsWith(".json") ? hooks : undefined;
|
|
27
|
+
}
|
|
3
28
|
/**
|
|
4
29
|
* Generate a Codex (.codex-plugin/plugin.json) manifest from an ADG manifest.
|
|
5
30
|
*
|
|
@@ -10,7 +35,9 @@ import { resolveProjectedSkills } from "../skills.js";
|
|
|
10
35
|
* (an explicit `skills` array, a partial install `selection`, or `strict: false`)
|
|
11
36
|
* emits the bare skill-id array Codex expects: `manifest.skills` arrays are
|
|
12
37
|
* declared as *paths* (`./skills/foo`), so they are resolved to identifiers
|
|
13
|
-
* rather than passed through. Codex
|
|
38
|
+
* rather than passed through. Beyond skills, Codex also consumes `hooks` — but as
|
|
39
|
+
* an explicit config *file* (no auto-load), so a declared hooks directory is
|
|
40
|
+
* resolved to its Codex-variant file via `resolveCodexHooksFile`.
|
|
14
41
|
*/
|
|
15
42
|
export function toCodexManifest(pluginDir, manifest, selection) {
|
|
16
43
|
// Codex's array form is bare ids, so a strict skills *array* is resolved to
|
|
@@ -28,5 +55,10 @@ export function toCodexManifest(pluginDir, manifest, selection) {
|
|
|
28
55
|
out.homepage = manifest.homepage;
|
|
29
56
|
if (manifest.license)
|
|
30
57
|
out.license = manifest.license;
|
|
58
|
+
if (manifest.hooks && isExposed(selection, "hooks")) {
|
|
59
|
+
const hooksFile = resolveCodexHooksFile(pluginDir, manifest.hooks);
|
|
60
|
+
if (hooksFile)
|
|
61
|
+
out.hooks = hooksFile;
|
|
62
|
+
}
|
|
31
63
|
return { defaultPath: join(".codex-plugin", "plugin.json"), manifest: out };
|
|
32
64
|
}
|
|
@@ -16,7 +16,7 @@ export const ADAPTER_TARGETS = ["claude", "codex", "antigravity"];
|
|
|
16
16
|
/**
|
|
17
17
|
* Component categories each adapter target can actually express, mirroring what
|
|
18
18
|
* the adapters emit: the Claude manifest carries skills/agents/commands/hooks/mcp
|
|
19
|
-
* plus apps (`toAnthropicManifest`), while Codex
|
|
19
|
+
* plus apps (`toAnthropicManifest`), while Codex consumes skills and hooks
|
|
20
20
|
* (`toCodexManifest`). Antigravity (`agy`) discovers components by convention
|
|
21
21
|
* (skills/agents/commands/hooks dirs + mcp_config.json) and does not surface
|
|
22
22
|
* apps, so apps maps only to the Claude target. Used to derive which agents a
|
|
@@ -24,7 +24,7 @@ export const ADAPTER_TARGETS = ["claude", "codex", "antigravity"];
|
|
|
24
24
|
*/
|
|
25
25
|
export const ADAPTER_COMPONENTS = {
|
|
26
26
|
claude: ["skills", "agents", "commands", "hooks", "mcp", "apps"],
|
|
27
|
-
codex: ["skills"],
|
|
27
|
+
codex: ["skills", "hooks"],
|
|
28
28
|
antigravity: ["skills", "agents", "commands", "hooks", "mcp"],
|
|
29
29
|
};
|
|
30
30
|
export { toAnthropicManifest, toCodexManifest, toAntigravityManifest };
|
|
@@ -81,8 +81,14 @@ export const claudeAgent = {
|
|
|
81
81
|
syncMarketplace(ctx.pluginsDir);
|
|
82
82
|
const affected = [];
|
|
83
83
|
for (const p of ctx.plugins) {
|
|
84
|
-
|
|
84
|
+
const r = run(["plugin", "install", `${p}@${MARKETPLACE}`, "--scope", ctx.scope]);
|
|
85
|
+
if (r.ok)
|
|
85
86
|
affected.push(p);
|
|
87
|
+
// Surface the CLI's reason instead of silently dropping the plugin — a
|
|
88
|
+
// rejected manifest (e.g. `hooks: Invalid input`) otherwise looks like a
|
|
89
|
+
// no-op "missing" with no diagnostic.
|
|
90
|
+
else
|
|
91
|
+
console.error(`claude: failed to install ${p}@${MARKETPLACE}: ${r.out.trim()}`);
|
|
86
92
|
}
|
|
87
93
|
return { agent: "claude", affected, skipped: false };
|
|
88
94
|
},
|
|
@@ -2,6 +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 { checkHookEvents } from "../hooks.js";
|
|
5
6
|
/**
|
|
6
7
|
* Generate runtime-specific manifests for the given targets from a plugin's
|
|
7
8
|
* .agents/.plugin.json. The output path honors the manifest's `adapters`
|
|
@@ -11,6 +12,11 @@ import { writeJson } from "../fsutil.js";
|
|
|
11
12
|
export function adaptPlugin(pluginDir, targets, selection) {
|
|
12
13
|
const manifest = readManifest(pluginDir);
|
|
13
14
|
const results = [];
|
|
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}`);
|
|
14
20
|
for (const target of targets) {
|
|
15
21
|
const adapter = ADAPTERS[target];
|
|
16
22
|
if (!adapter)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { basename, join, relative, resolve } from "node:path";
|
|
4
4
|
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
@@ -19,6 +19,10 @@ import { skillDescriptionLoader } from "../skills.js";
|
|
|
19
19
|
import { resolveAgents } from "../agents/index.js";
|
|
20
20
|
// Generated runtime projections never count toward a plugin's content hash.
|
|
21
21
|
const HASH_IGNORE = PROJECTION_DIRS;
|
|
22
|
+
/** Content hash over a plugin's packaged payload (hooks files are authored content, not generated). */
|
|
23
|
+
function contentHash(dir, manifest) {
|
|
24
|
+
return folderHash(dir, HASH_IGNORE, packageFilter(manifest, { includeProjections: false }));
|
|
25
|
+
}
|
|
22
26
|
/**
|
|
23
27
|
* Install a single local plugin directory into a plugins directory: copy the
|
|
24
28
|
* source, generate adapter manifests, compute the folder hash, and update both
|
|
@@ -48,7 +52,7 @@ export function installPlugin(opts) {
|
|
|
48
52
|
// copy) and, when asked, short-circuit if it matches what's already recorded —
|
|
49
53
|
// so an unchanged upstream source is never re-copied, re-adapted, or re-locked.
|
|
50
54
|
if (opts.skipUnchanged && prev) {
|
|
51
|
-
const sourceHash =
|
|
55
|
+
const sourceHash = contentHash(source, manifest);
|
|
52
56
|
if (prev.folderHash === sourceHash && prev.version === manifest.version) {
|
|
53
57
|
return { name, installedTo: dest, folderHash: sourceHash, adapted: [], changed: false };
|
|
54
58
|
}
|
|
@@ -65,7 +69,7 @@ export function installPlugin(opts) {
|
|
|
65
69
|
const selection = opts.selection ?? prev?.selection;
|
|
66
70
|
const targets = opts.targets ?? [...ADAPTER_TARGETS];
|
|
67
71
|
const adapted = adaptPlugin(dest, targets, selection).map((r) => r.file);
|
|
68
|
-
const hash =
|
|
72
|
+
const hash = contentHash(dest, manifest);
|
|
69
73
|
const changed = !prev || prev.folderHash !== hash || prev.version !== manifest.version;
|
|
70
74
|
const entry = {
|
|
71
75
|
origin,
|
|
@@ -112,6 +116,15 @@ function discoverPlugins(root) {
|
|
|
112
116
|
continue;
|
|
113
117
|
const raw = JSON.parse(readFileSync(native.manifestFile, "utf8"));
|
|
114
118
|
const manifest = fromNativeManifest(raw, native.kind);
|
|
119
|
+
// A Claude manifest omits `hooks` (Claude auto-loads hooks/hooks.json), and
|
|
120
|
+
// `walkNative` prefers it over a sibling Codex manifest that *does* declare
|
|
121
|
+
// hooks — so the reverse-adapt would silently drop the hooks payload. Recover
|
|
122
|
+
// it from disk: a hooks/ directory means the ADG manifest must declare it, or
|
|
123
|
+
// packagedRoots won't copy it and every downstream projection loses hooks.
|
|
124
|
+
const hooksDir = join(native.dir, "hooks");
|
|
125
|
+
if (!manifest.hooks && existsSync(hooksDir) && statSync(hooksDir).isDirectory()) {
|
|
126
|
+
manifest.hooks = "./hooks/";
|
|
127
|
+
}
|
|
115
128
|
writeJson(join(native.dir, ADG_MANIFEST_PATH), manifest);
|
|
116
129
|
converted.push(manifest.name);
|
|
117
130
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resolveCodexHooksFile } from "./adapters/codex.js";
|
|
4
|
+
/**
|
|
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.
|
|
9
|
+
*/
|
|
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
|
+
]),
|
|
28
|
+
};
|
|
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;
|
|
37
|
+
}
|
|
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) : [];
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
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.
|
|
53
|
+
*/
|
|
54
|
+
export function checkHookEvents(pluginDir, targets) {
|
|
55
|
+
const warnings = [];
|
|
56
|
+
for (const t of targets) {
|
|
57
|
+
if (t !== "claude" && t !== "codex")
|
|
58
|
+
continue;
|
|
59
|
+
const rel = hooksFileForTarget(pluginDir, t);
|
|
60
|
+
if (!rel)
|
|
61
|
+
continue;
|
|
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`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return warnings;
|
|
69
|
+
}
|
package/docs/authoring.md
CHANGED
|
@@ -154,13 +154,54 @@ Two ways to declare them:
|
|
|
154
154
|
- **agents** — `"./agents/"`, a dir of sub-agent definition `.md` files.
|
|
155
155
|
- **mcp** — `"./mcp/.mcp.json"`, an MCP server config file (points at a *file*,
|
|
156
156
|
not a dir).
|
|
157
|
-
- **hooks**, **apps** — directories, same pattern.
|
|
157
|
+
- **hooks**, **apps** — directories, same pattern. For hooks, see **Hooks**
|
|
158
|
+
below — agents differ on the hook config format, so ADG can compile a single
|
|
159
|
+
universal definition into each agent's native file.
|
|
158
160
|
|
|
159
161
|
Declare only what you ship. Omit a field and that component is absent from both
|
|
160
162
|
the runtime projections and the installed package.
|
|
161
163
|
|
|
162
164
|
---
|
|
163
165
|
|
|
166
|
+
## Hooks
|
|
167
|
+
|
|
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
|
+
]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
164
205
|
## Dependencies
|
|
165
206
|
|
|
166
207
|
```jsonc
|
|
@@ -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.
|