@rbbtsn0w/adg 0.4.0-beta.8 → 0.4.0-beta.9
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/antigravity-hooks.js +449 -0
- package/dist/src/adapters/antigravity.js +20 -7
- package/dist/src/adapters/index.js +1 -1
- package/dist/src/agents/antigravity.js +11 -5
- package/dist/src/agents/codex.js +10 -1
- package/dist/src/agents/types.js +3 -1
- package/dist/src/commands/adapt.js +12 -5
- package/dist/src/commands/install.js +2 -1
- package/dist/src/commands/status.js +13 -1
- package/dist/src/commands/unlink.js +2 -1
- package/dist/src/hooks.js +16 -9
- package/dist/src/package.js +2 -3
- package/dist/src/render/plugins.js +10 -1
- package/docs/authoring.md +23 -8
- package/docs/cli-json.md +4 -1
- package/docs/hooks-strategy.md +23 -26
- package/package.json +1 -1
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { cpSync, existsSync, readFileSync, renameSync, rmSync, statSync } from "node:fs";
|
|
3
|
+
import { basename, join, resolve } from "node:path";
|
|
4
|
+
import { isExposed } from "../components.js";
|
|
5
|
+
import { writeJson, writeText } from "../fsutil.js";
|
|
6
|
+
const TARGET_FILE = "hooks.json";
|
|
7
|
+
const PROJECTION_DIR = ".antigravity-plugin";
|
|
8
|
+
const RUNNER_FILE = "hook-runner.mjs";
|
|
9
|
+
const NATIVE_OVERRIDE = "hooks-antigravity.json";
|
|
10
|
+
const EVENT_MAP = {
|
|
11
|
+
SessionStart: "PreInvocation",
|
|
12
|
+
PreToolUse: "PreToolUse",
|
|
13
|
+
PostToolUse: "PostToolUse",
|
|
14
|
+
Stop: "Stop",
|
|
15
|
+
};
|
|
16
|
+
const TOOL_ALIASES = {
|
|
17
|
+
Bash: "run_command",
|
|
18
|
+
Read: "view_file",
|
|
19
|
+
Write: "write_to_file",
|
|
20
|
+
Edit: "replace_file_content|multi_replace_file_content",
|
|
21
|
+
Glob: "find_by_name",
|
|
22
|
+
Grep: "grep_search",
|
|
23
|
+
WebSearch: "search_web",
|
|
24
|
+
WebFetch: "read_url_content",
|
|
25
|
+
Agent: "invoke_subagent",
|
|
26
|
+
AskUserQuestion: "ask_question",
|
|
27
|
+
};
|
|
28
|
+
const ANTIGRAVITY_TOOL_NAMES = new Set(Object.values(TOOL_ALIASES).flatMap((name) => name.split("|")));
|
|
29
|
+
const ANTIGRAVITY_TOOL_EVENTS = new Set(["PreToolUse", "PostToolUse"]);
|
|
30
|
+
const ANTIGRAVITY_DIRECT_EVENTS = new Set(["PreInvocation", "PostInvocation", "Stop"]);
|
|
31
|
+
function hookSources(pluginDir, manifest) {
|
|
32
|
+
if (!manifest.hooks)
|
|
33
|
+
return {};
|
|
34
|
+
const declared = resolve(pluginDir, manifest.hooks);
|
|
35
|
+
if (existsSync(declared) && statSync(declared).isDirectory()) {
|
|
36
|
+
const native = join(declared, NATIVE_OVERRIDE);
|
|
37
|
+
const canonical = join(declared, TARGET_FILE);
|
|
38
|
+
return {
|
|
39
|
+
...(existsSync(canonical) ? { canonical } : {}),
|
|
40
|
+
...(existsSync(native) ? { native } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (basename(declared) === NATIVE_OVERRIDE)
|
|
44
|
+
return { native: declared };
|
|
45
|
+
return { canonical: declared };
|
|
46
|
+
}
|
|
47
|
+
function cleanupGenerated(pluginDir, preserveTarget = false) {
|
|
48
|
+
if (!preserveTarget)
|
|
49
|
+
rmSync(join(pluginDir, TARGET_FILE), { force: true });
|
|
50
|
+
rmSync(join(pluginDir, PROJECTION_DIR, RUNNER_FILE), { force: true });
|
|
51
|
+
}
|
|
52
|
+
function parseJsonFile(file, label) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new Error(`invalid ${label} JSON in ${file}: ${String(error)}`, { cause: error });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function isRecord(value) {
|
|
61
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
function validateNativeHandler(value, path) {
|
|
64
|
+
if (!isRecord(value))
|
|
65
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path} must be an object`);
|
|
66
|
+
if ((value.type ?? "command") !== "command") {
|
|
67
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path}.type must be "command"`);
|
|
68
|
+
}
|
|
69
|
+
if (typeof value.command !== "string" || !value.command.trim()) {
|
|
70
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path}.command must be a non-empty string`);
|
|
71
|
+
}
|
|
72
|
+
if (value.timeout !== undefined && (!Number.isInteger(value.timeout) || value.timeout <= 0)) {
|
|
73
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path}.timeout must be a positive integer`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function validateNativeHandlers(value, path) {
|
|
77
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
78
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path} must be a non-empty array`);
|
|
79
|
+
}
|
|
80
|
+
value.forEach((handler, index) => validateNativeHandler(handler, `${path}[${index}]`));
|
|
81
|
+
}
|
|
82
|
+
function validateNativeDocument(value) {
|
|
83
|
+
if (!isRecord(value) || Object.keys(value).length === 0) {
|
|
84
|
+
throw new Error("invalid native Antigravity hooks schema: root must be a non-empty object");
|
|
85
|
+
}
|
|
86
|
+
for (const [hookName, rawDefinition] of Object.entries(value)) {
|
|
87
|
+
if (!isRecord(rawDefinition)) {
|
|
88
|
+
throw new Error(`invalid native Antigravity hooks schema: hook "${hookName}" must be an object`);
|
|
89
|
+
}
|
|
90
|
+
let eventCount = 0;
|
|
91
|
+
for (const [field, eventValue] of Object.entries(rawDefinition)) {
|
|
92
|
+
if (field === "enabled") {
|
|
93
|
+
if (typeof eventValue !== "boolean") {
|
|
94
|
+
throw new Error(`invalid native Antigravity hooks schema: ${hookName}.enabled must be boolean`);
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (ANTIGRAVITY_DIRECT_EVENTS.has(field)) {
|
|
99
|
+
validateNativeHandlers(eventValue, `${hookName}.${field}`);
|
|
100
|
+
eventCount += 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (ANTIGRAVITY_TOOL_EVENTS.has(field)) {
|
|
104
|
+
if (!Array.isArray(eventValue) || eventValue.length === 0) {
|
|
105
|
+
throw new Error(`invalid native Antigravity hooks schema: ${hookName}.${field} must be a non-empty array`);
|
|
106
|
+
}
|
|
107
|
+
eventValue.forEach((rawGroup, groupIndex) => {
|
|
108
|
+
const path = `${hookName}.${field}[${groupIndex}]`;
|
|
109
|
+
if (!isRecord(rawGroup))
|
|
110
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path} must be an object`);
|
|
111
|
+
if (rawGroup.matcher !== undefined && typeof rawGroup.matcher !== "string") {
|
|
112
|
+
throw new Error(`invalid native Antigravity hooks schema: ${path}.matcher must be a string`);
|
|
113
|
+
}
|
|
114
|
+
validateNativeHandlers(rawGroup.hooks, `${path}.hooks`);
|
|
115
|
+
});
|
|
116
|
+
eventCount += 1;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
throw new Error(`invalid native Antigravity hooks schema: unknown field ${hookName}.${field}`);
|
|
120
|
+
}
|
|
121
|
+
if (eventCount === 0) {
|
|
122
|
+
throw new Error(`invalid native Antigravity hooks schema: hook "${hookName}" declares no events`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function replaceJson(file, value) {
|
|
127
|
+
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
128
|
+
try {
|
|
129
|
+
writeJson(temporary, value);
|
|
130
|
+
renameSync(temporary, file);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
rmSync(temporary, { force: true });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function replaceText(file, value) {
|
|
137
|
+
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
138
|
+
try {
|
|
139
|
+
writeText(temporary, value);
|
|
140
|
+
renameSync(temporary, file);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
rmSync(temporary, { force: true });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function replaceFile(file, source) {
|
|
147
|
+
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
148
|
+
try {
|
|
149
|
+
cpSync(source, temporary);
|
|
150
|
+
renameSync(temporary, file);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
rmSync(temporary, { force: true });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function parseGroups(value) {
|
|
157
|
+
return Array.isArray(value) ? value.filter((group) => typeof group === "object" && group !== null) : [];
|
|
158
|
+
}
|
|
159
|
+
function matcherIncludesStartup(matcher) {
|
|
160
|
+
if (matcher === undefined || matcher === "")
|
|
161
|
+
return true;
|
|
162
|
+
if (typeof matcher !== "string")
|
|
163
|
+
return false;
|
|
164
|
+
try {
|
|
165
|
+
return new RegExp(`^(?:${matcher})$`).test("startup");
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function translateToolMatcher(matcher) {
|
|
172
|
+
if (matcher === undefined || matcher === "" || matcher === "*")
|
|
173
|
+
return typeof matcher === "string" ? matcher : "";
|
|
174
|
+
if (typeof matcher !== "string")
|
|
175
|
+
return undefined;
|
|
176
|
+
const tokens = matcher.split("|");
|
|
177
|
+
if (tokens.some((token) => !/^[A-Za-z0-9_]+$/.test(token)))
|
|
178
|
+
return undefined;
|
|
179
|
+
const translated = [];
|
|
180
|
+
for (const token of tokens) {
|
|
181
|
+
const alias = TOOL_ALIASES[token];
|
|
182
|
+
if (alias)
|
|
183
|
+
translated.push(alias);
|
|
184
|
+
else if (ANTIGRAVITY_TOOL_NAMES.has(token))
|
|
185
|
+
translated.push(token);
|
|
186
|
+
else
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
return translated.join("|");
|
|
190
|
+
}
|
|
191
|
+
function runnerCommand(pluginDir, event, command) {
|
|
192
|
+
const encoded = Buffer.from(command, "utf8").toString("base64url");
|
|
193
|
+
const runner = join(resolve(pluginDir), PROJECTION_DIR, RUNNER_FILE);
|
|
194
|
+
const quotedRunner = process.platform === "win32"
|
|
195
|
+
? `"${runner.replaceAll("/", "\\")}"`
|
|
196
|
+
: `'${runner.replaceAll("'", `'"'"'`)}'`;
|
|
197
|
+
return `node ${quotedRunner} ${event} ${encoded}`;
|
|
198
|
+
}
|
|
199
|
+
function translateHandlers(pluginDir, pluginName, event, value, warnings) {
|
|
200
|
+
if (!Array.isArray(value))
|
|
201
|
+
return [];
|
|
202
|
+
const translated = [];
|
|
203
|
+
for (const raw of value) {
|
|
204
|
+
if (typeof raw !== "object" || raw === null)
|
|
205
|
+
continue;
|
|
206
|
+
const handler = raw;
|
|
207
|
+
if ((handler.type ?? "command") !== "command") {
|
|
208
|
+
warnings.push(`${pluginName}: ${event} handler type "${String(handler.type)}" is not supported by antigravity`);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (handler.async === true) {
|
|
212
|
+
warnings.push(`${pluginName}: async ${event} command handlers are not supported by antigravity`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (typeof handler.command !== "string" || !handler.command.trim()) {
|
|
216
|
+
warnings.push(`${pluginName}: ${event} command handler has no command`);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const timeout = typeof handler.timeout === "number" && Number.isInteger(handler.timeout) && handler.timeout > 0
|
|
220
|
+
? handler.timeout
|
|
221
|
+
: 30;
|
|
222
|
+
translated.push({ type: "command", command: runnerCommand(pluginDir, event, handler.command), timeout });
|
|
223
|
+
}
|
|
224
|
+
return translated;
|
|
225
|
+
}
|
|
226
|
+
function translateDirectEvent(pluginDir, pluginName, event, groups, warnings) {
|
|
227
|
+
const handlers = [];
|
|
228
|
+
for (const group of groups) {
|
|
229
|
+
if (event === "SessionStart" && !matcherIncludesStartup(group.matcher)) {
|
|
230
|
+
warnings.push(`${pluginName}: SessionStart matcher "${String(group.matcher)}" has no Antigravity startup mapping`);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
handlers.push(...translateHandlers(pluginDir, pluginName, event, group.hooks, warnings));
|
|
234
|
+
}
|
|
235
|
+
return handlers;
|
|
236
|
+
}
|
|
237
|
+
function translateToolEvent(pluginDir, pluginName, event, groups, warnings) {
|
|
238
|
+
const translated = [];
|
|
239
|
+
for (const group of groups) {
|
|
240
|
+
const matcher = translateToolMatcher(group.matcher);
|
|
241
|
+
if (matcher === undefined) {
|
|
242
|
+
warnings.push(`${pluginName}: ${event} matcher "${String(group.matcher)}" cannot be safely mapped to antigravity`);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const hooks = translateHandlers(pluginDir, pluginName, event, group.hooks, warnings);
|
|
246
|
+
if (hooks.length)
|
|
247
|
+
translated.push({ matcher, hooks });
|
|
248
|
+
}
|
|
249
|
+
return translated;
|
|
250
|
+
}
|
|
251
|
+
function translateDocument(pluginDir, pluginName, document) {
|
|
252
|
+
const warnings = [];
|
|
253
|
+
const definition = {};
|
|
254
|
+
const hooks = typeof document.hooks === "object" && document.hooks !== null
|
|
255
|
+
? document.hooks
|
|
256
|
+
: {};
|
|
257
|
+
for (const event of Object.keys(hooks)) {
|
|
258
|
+
if (!(event in EVENT_MAP)) {
|
|
259
|
+
warnings.push(`hook event "${event}" is not a supported antigravity hook mapping — antigravity will not fire it`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const sessionStart = translateDirectEvent(pluginDir, pluginName, "SessionStart", parseGroups(hooks.SessionStart), warnings);
|
|
263
|
+
if (sessionStart.length)
|
|
264
|
+
definition.PreInvocation = sessionStart;
|
|
265
|
+
const preToolUse = translateToolEvent(pluginDir, pluginName, "PreToolUse", parseGroups(hooks.PreToolUse), warnings);
|
|
266
|
+
if (preToolUse.length)
|
|
267
|
+
definition.PreToolUse = preToolUse;
|
|
268
|
+
const postToolUse = translateToolEvent(pluginDir, pluginName, "PostToolUse", parseGroups(hooks.PostToolUse), warnings);
|
|
269
|
+
if (postToolUse.length)
|
|
270
|
+
definition.PostToolUse = postToolUse;
|
|
271
|
+
const stop = translateDirectEvent(pluginDir, pluginName, "Stop", parseGroups(hooks.Stop), warnings);
|
|
272
|
+
if (stop.length)
|
|
273
|
+
definition.Stop = stop;
|
|
274
|
+
return { definition, warnings };
|
|
275
|
+
}
|
|
276
|
+
/** Materialize a plugin's hooks under Antigravity's required root filename and native schema. */
|
|
277
|
+
export function writeAntigravityHooks(pluginDir, manifest, selection) {
|
|
278
|
+
const target = join(pluginDir, TARGET_FILE);
|
|
279
|
+
const sources = hookSources(pluginDir, manifest);
|
|
280
|
+
const sourceIsTarget = sources.canonical !== undefined && resolve(sources.canonical) === resolve(target);
|
|
281
|
+
if (!isExposed(selection, "hooks") || (!sources.native && !sources.canonical)) {
|
|
282
|
+
cleanupGenerated(pluginDir, sourceIsTarget);
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
if (sourceIsTarget) {
|
|
286
|
+
rmSync(join(pluginDir, PROJECTION_DIR, RUNNER_FILE), { force: true });
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
if (sources.native) {
|
|
290
|
+
const document = parseJsonFile(sources.native, "native Antigravity hooks");
|
|
291
|
+
validateNativeDocument(document);
|
|
292
|
+
replaceFile(target, sources.native);
|
|
293
|
+
rmSync(join(pluginDir, PROJECTION_DIR, RUNNER_FILE), { force: true });
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
const document = parseJsonFile(sources.canonical, "canonical hooks");
|
|
297
|
+
const { definition, warnings } = translateDocument(pluginDir, manifest.name, document);
|
|
298
|
+
if (Object.keys(definition).length) {
|
|
299
|
+
const projected = { [manifest.name]: definition };
|
|
300
|
+
validateNativeDocument(projected);
|
|
301
|
+
replaceText(join(pluginDir, PROJECTION_DIR, RUNNER_FILE), HOOK_RUNNER);
|
|
302
|
+
replaceJson(target, projected);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
cleanupGenerated(pluginDir);
|
|
306
|
+
}
|
|
307
|
+
return warnings;
|
|
308
|
+
}
|
|
309
|
+
const HOOK_RUNNER = String.raw `import { spawnSync } from "node:child_process";
|
|
310
|
+
import { readFileSync } from "node:fs";
|
|
311
|
+
import { dirname, resolve } from "node:path";
|
|
312
|
+
import { fileURLToPath } from "node:url";
|
|
313
|
+
|
|
314
|
+
const [event, encodedCommand] = process.argv.slice(2);
|
|
315
|
+
const rawInput = readFileSync(0, "utf8");
|
|
316
|
+
let input;
|
|
317
|
+
try {
|
|
318
|
+
input = rawInput.trim() ? JSON.parse(rawInput) : {};
|
|
319
|
+
} catch (error) {
|
|
320
|
+
fail("invalid Antigravity hook input", error);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (event === "SessionStart" && input.invocationNum !== 0) {
|
|
324
|
+
emit({});
|
|
325
|
+
process.exit(0);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
329
|
+
const command = Buffer.from(encodedCommand, "base64url").toString("utf8")
|
|
330
|
+
.replaceAll("$" + "{CLAUDE_PLUGIN_ROOT}", pluginRoot)
|
|
331
|
+
.replaceAll("$" + "{PLUGIN_ROOT}", pluginRoot);
|
|
332
|
+
const childInput = claudeInput(event, input);
|
|
333
|
+
const child = spawnSync(command, {
|
|
334
|
+
cwd: pluginRoot,
|
|
335
|
+
env: { ...process.env, CLAUDE_PLUGIN_ROOT: pluginRoot, PLUGIN_ROOT: pluginRoot },
|
|
336
|
+
input: JSON.stringify(childInput),
|
|
337
|
+
encoding: "utf8",
|
|
338
|
+
shell: true,
|
|
339
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
340
|
+
});
|
|
341
|
+
if (child.stderr) process.stderr.write(child.stderr);
|
|
342
|
+
if (child.error) fail("failed to launch hook command", child.error);
|
|
343
|
+
if (child.status !== 0) process.exit(child.status ?? 1);
|
|
344
|
+
|
|
345
|
+
const output = parseOutput(event, child.stdout);
|
|
346
|
+
emit(antigravityOutput(event, output));
|
|
347
|
+
|
|
348
|
+
function claudeInput(hookEvent, source) {
|
|
349
|
+
const common = {
|
|
350
|
+
...source,
|
|
351
|
+
session_id: source.conversationId,
|
|
352
|
+
transcript_path: source.transcriptPath,
|
|
353
|
+
cwd: source.workspacePaths?.[0] ?? pluginRoot,
|
|
354
|
+
hook_event_name: hookEvent,
|
|
355
|
+
};
|
|
356
|
+
if (hookEvent === "SessionStart") return { ...common, source: "startup" };
|
|
357
|
+
if (hookEvent === "PreToolUse" || hookEvent === "PostToolUse") {
|
|
358
|
+
return {
|
|
359
|
+
...common,
|
|
360
|
+
tool_name: claudeToolName(source.toolCall?.name),
|
|
361
|
+
tool_input: source.toolCall?.args ?? {},
|
|
362
|
+
tool_response: source.toolCall?.result,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (hookEvent === "Stop") return { ...common, stop_hook_active: false };
|
|
366
|
+
return common;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function claudeToolName(name) {
|
|
370
|
+
return ({
|
|
371
|
+
run_command: "Bash",
|
|
372
|
+
view_file: "Read",
|
|
373
|
+
write_to_file: "Write",
|
|
374
|
+
replace_file_content: "Edit",
|
|
375
|
+
multi_replace_file_content: "Edit",
|
|
376
|
+
find_by_name: "Glob",
|
|
377
|
+
grep_search: "Grep",
|
|
378
|
+
search_web: "WebSearch",
|
|
379
|
+
read_url_content: "WebFetch",
|
|
380
|
+
invoke_subagent: "Agent",
|
|
381
|
+
ask_question: "AskUserQuestion",
|
|
382
|
+
})[name] ?? name;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function parseOutput(hookEvent, stdout) {
|
|
386
|
+
const text = stdout.trim();
|
|
387
|
+
if (!text) return {};
|
|
388
|
+
try {
|
|
389
|
+
return JSON.parse(text);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (hookEvent === "SessionStart") return { additionalContext: text };
|
|
392
|
+
fail("hook command returned invalid JSON", error);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function antigravityOutput(hookEvent, output) {
|
|
397
|
+
if (output.continue === false) {
|
|
398
|
+
const reason = output.stopReason ?? output.reason ?? "Claude hook stopped processing";
|
|
399
|
+
if (hookEvent === "PreToolUse") return { decision: "deny", reason };
|
|
400
|
+
if (hookEvent === "Stop") return { decision: "stop" };
|
|
401
|
+
fail(hookEvent + " continue:false output has no safe Antigravity mapping", reason);
|
|
402
|
+
}
|
|
403
|
+
if (hookEvent === "SessionStart") {
|
|
404
|
+
if (Array.isArray(output.injectSteps)) return output;
|
|
405
|
+
const context = output.hookSpecificOutput?.additionalContext
|
|
406
|
+
?? output.additionalContext
|
|
407
|
+
?? output.additional_context;
|
|
408
|
+
return typeof context === "string" && context ? { injectSteps: [{ ephemeralMessage: context }] } : {};
|
|
409
|
+
}
|
|
410
|
+
if (hookEvent === "PreToolUse") {
|
|
411
|
+
const specific = output.hookSpecificOutput ?? {};
|
|
412
|
+
const decision = specific.permissionDecision ?? output.permissionDecision ?? output.decision;
|
|
413
|
+
const reason = specific.permissionDecisionReason ?? output.reason;
|
|
414
|
+
if (specific.updatedInput !== undefined) {
|
|
415
|
+
process.stderr.write("antigravity hook bridge: Claude updatedInput is unsupported; requesting confirmation\n");
|
|
416
|
+
return { decision: "ask", reason: reason ?? "Hook requested a tool-input change that Antigravity cannot apply" };
|
|
417
|
+
}
|
|
418
|
+
if (decision === "deny" || decision === "block") return { decision: "deny", ...(reason ? { reason } : {}) };
|
|
419
|
+
if (decision === "allow" || decision === "approve") return { decision: "allow", ...(reason ? { reason } : {}) };
|
|
420
|
+
if (decision === "ask") return { decision: "ask", ...(reason ? { reason } : {}) };
|
|
421
|
+
if (decision === "defer") {
|
|
422
|
+
process.stderr.write("antigravity hook bridge: Claude defer is unsupported; requesting confirmation\n");
|
|
423
|
+
return { decision: "ask", reason: reason ?? "Hook deferred to Antigravity's permission flow" };
|
|
424
|
+
}
|
|
425
|
+
return { decision: "allow", ...(reason ? { reason } : {}) };
|
|
426
|
+
}
|
|
427
|
+
if (hookEvent === "PostToolUse") {
|
|
428
|
+
if (output.decision === "block") {
|
|
429
|
+
fail("PostToolUse block output has no safe Antigravity mapping", output.reason ?? "block");
|
|
430
|
+
}
|
|
431
|
+
return {};
|
|
432
|
+
}
|
|
433
|
+
if (hookEvent === "Stop") {
|
|
434
|
+
return output.decision === "block"
|
|
435
|
+
? { decision: "continue", ...(output.reason ? { reason: output.reason } : {}) }
|
|
436
|
+
: { decision: "stop" };
|
|
437
|
+
}
|
|
438
|
+
return {};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function emit(value) {
|
|
442
|
+
process.stdout.write(JSON.stringify(value) + "\n");
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function fail(message, error) {
|
|
446
|
+
process.stderr.write("antigravity hook bridge: " + message + ": " + String(error) + "\n");
|
|
447
|
+
process.exit(1);
|
|
448
|
+
}
|
|
449
|
+
`;
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
import { cpSync, existsSync, rmSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
1
3
|
import { isExposed } from "../components.js";
|
|
2
4
|
import { mcpConfigPath } from "../mcp.js";
|
|
5
|
+
export const ANTIGRAVITY_MCP_CONFIG = "mcp_config.json";
|
|
3
6
|
/**
|
|
4
7
|
* Generate an Antigravity (`agy`) plugin.json from an ADG manifest.
|
|
5
8
|
*
|
|
6
9
|
* Antigravity discovers a plugin by scanning a directory for a root `plugin.json`
|
|
7
|
-
* plus sibling component dirs
|
|
8
|
-
*
|
|
10
|
+
* plus sibling component dirs and `mcp_config.json`, so the manifest is emitted
|
|
11
|
+
* at the plugin folder root and contains only the plugin name.
|
|
9
12
|
*/
|
|
10
|
-
export function toAntigravityManifest(_pluginDir, manifest,
|
|
11
|
-
|
|
13
|
+
export function toAntigravityManifest(_pluginDir, manifest, _selection) {
|
|
14
|
+
return { defaultPath: "plugin.json", manifest: { name: manifest.name } };
|
|
15
|
+
}
|
|
16
|
+
/** Materialize ADG's MCP pointer under Antigravity's required conventional name. */
|
|
17
|
+
export function writeAntigravityMcpConfig(pluginDir, manifest, selection) {
|
|
18
|
+
const target = join(pluginDir, ANTIGRAVITY_MCP_CONFIG);
|
|
12
19
|
const mcp = mcpConfigPath(manifest);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
const source = mcp ? resolve(pluginDir, mcp) : undefined;
|
|
21
|
+
// An authored mcp_config.json is already the canonical payload, not a
|
|
22
|
+
// generated projection. Never remove or copy it onto itself.
|
|
23
|
+
if (source === resolve(target))
|
|
24
|
+
return;
|
|
25
|
+
rmSync(target, { force: true });
|
|
26
|
+
if (source && isExposed(selection, "mcp") && existsSync(source)) {
|
|
27
|
+
cpSync(source, target);
|
|
28
|
+
}
|
|
16
29
|
}
|
|
@@ -18,7 +18,7 @@ export const ADAPTER_TARGETS = ["claude", "codex", "antigravity"];
|
|
|
18
18
|
* the adapters emit: the Claude manifest carries skills/agents/commands/hooks/mcp
|
|
19
19
|
* plus apps (`toAnthropicManifest`), while Codex consumes skills/hooks/mcp
|
|
20
20
|
* (`toCodexManifest`). Antigravity (`agy`) discovers components by convention
|
|
21
|
-
* (skills/agents/commands/hooks dirs +
|
|
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
|
|
23
23
|
* plugin is adaptable to from its exposed component types.
|
|
24
24
|
*/
|
|
@@ -6,7 +6,8 @@ import { readManifest } from "../manifest.js";
|
|
|
6
6
|
import { isExposed } from "../components.js";
|
|
7
7
|
import { installedPluginDir, lockPath } from "../paths.js";
|
|
8
8
|
import { readLock } from "../lock.js";
|
|
9
|
-
import { toAntigravityManifest } from "../adapters/antigravity.js";
|
|
9
|
+
import { toAntigravityManifest, writeAntigravityMcpConfig } from "../adapters/antigravity.js";
|
|
10
|
+
import { writeAntigravityHooks } from "../adapters/antigravity-hooks.js";
|
|
10
11
|
import { skippedResult } from "./base.js";
|
|
11
12
|
/**
|
|
12
13
|
* Antigravity (`agy`) agent — physical-directory model, no CLI.
|
|
@@ -31,10 +32,11 @@ import { skippedResult } from "./base.js";
|
|
|
31
32
|
* project query can't surface globally-installed plugins (and vice versa).
|
|
32
33
|
*
|
|
33
34
|
* Tradeoff (in-place): partial installs are best-effort, and a `skills` value is
|
|
34
|
-
* read from the single convention dir `<plugin>/skills/`.
|
|
35
|
-
* the
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* read from the single convention dir `<plugin>/skills/`. Generated
|
|
36
|
+
* `mcp_config.json` honors the MCP selection, but an authored file already using
|
|
37
|
+
* that conventional name cannot be hidden without deleting canonical payload.
|
|
38
|
+
* The auto-scan model also does NOT honor: dir-level pruning (a narrowed skill
|
|
39
|
+
* subset, a dropped directory category), nor a multi-root skills path-list (e.g.
|
|
38
40
|
* `["./skills/one","./extra/two"]` — only the `skills/` root is exposed; `extra/`
|
|
39
41
|
* is not). These would require a separate self-contained projection dir, which the
|
|
40
42
|
* in-place model deliberately avoids; the full canonical dirs are read in place.
|
|
@@ -125,6 +127,8 @@ export function ensureAntigravityRoot(dir, selection) {
|
|
|
125
127
|
const manifest = readManifest(dir);
|
|
126
128
|
const { manifest: pluginJson } = toAntigravityManifest(dir, manifest, selection);
|
|
127
129
|
writeJson(join(dir, ANTIGRAVITY_MANIFEST), pluginJson);
|
|
130
|
+
writeAntigravityMcpConfig(dir, manifest, selection);
|
|
131
|
+
writeAntigravityHooks(dir, manifest, selection);
|
|
128
132
|
for (const field of CONVENTION_FIELDS) {
|
|
129
133
|
const link = join(dir, field);
|
|
130
134
|
rmIfSymlink(link); // clear a stale alias (incl. a broken one); a real source dir is left untouched
|
|
@@ -183,6 +187,8 @@ function removeProjection(scanDir, name, realDir) {
|
|
|
183
187
|
if (realDir) {
|
|
184
188
|
// The real store dir is known: drop the in-place manifest + convention aliases.
|
|
185
189
|
rmSync(join(realDir, ANTIGRAVITY_MANIFEST), { force: true });
|
|
190
|
+
writeAntigravityMcpConfig(realDir, readManifest(realDir), { components: [] });
|
|
191
|
+
writeAntigravityHooks(realDir, readManifest(realDir), { components: [] });
|
|
186
192
|
for (const field of CONVENTION_FIELDS)
|
|
187
193
|
rmIfSymlink(join(realDir, field));
|
|
188
194
|
if (resolve(target) === resolve(realDir))
|
package/dist/src/agents/codex.js
CHANGED
|
@@ -94,10 +94,19 @@ export const codexAgent = {
|
|
|
94
94
|
return undefined; // no generated marketplace → can't scope the query
|
|
95
95
|
const res = run(["plugin", "list"]);
|
|
96
96
|
if (!res.ok)
|
|
97
|
-
return
|
|
97
|
+
return codexListFailure(res.out);
|
|
98
98
|
return parseCodexPluginList(res.out, mp);
|
|
99
99
|
},
|
|
100
100
|
};
|
|
101
|
+
/** Preserve Codex's diagnostic and offer cleanup for a stale ADG project marketplace. */
|
|
102
|
+
export function codexListFailure(out) {
|
|
103
|
+
const detail = out.trim() || "codex plugin list failed without an error message";
|
|
104
|
+
const staleMarketplace = detail.match(/- `(adg-[0-9a-f]{8})` at .*marketplace root does not contain a supported manifest/);
|
|
105
|
+
return {
|
|
106
|
+
error: detail,
|
|
107
|
+
...(staleMarketplace ? { recoveryCommand: `codex plugin marketplace remove ${staleMarketplace[1]}` } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
101
110
|
/**
|
|
102
111
|
* Parse `codex plugin list` output into the *installed and enabled* plugin names
|
|
103
112
|
* from a given marketplace. The listing is a whitespace-aligned table whose
|
package/dist/src/agents/types.js
CHANGED
|
@@ -3,6 +3,8 @@ import { ADAPTERS } from "../adapters/index.js";
|
|
|
3
3
|
import { readManifest } from "../manifest.js";
|
|
4
4
|
import { writeJson } from "../fsutil.js";
|
|
5
5
|
import { checkHookEvents } from "../hooks.js";
|
|
6
|
+
import { writeAntigravityMcpConfig } from "../adapters/antigravity.js";
|
|
7
|
+
import { writeAntigravityHooks } from "../adapters/antigravity-hooks.js";
|
|
6
8
|
/**
|
|
7
9
|
* Generate runtime-specific manifests for the given targets from a plugin's
|
|
8
10
|
* .agents/.plugin.json. The output path honors the manifest's `adapters`
|
|
@@ -12,11 +14,9 @@ import { checkHookEvents } from "../hooks.js";
|
|
|
12
14
|
export function adaptPlugin(pluginDir, targets, selection) {
|
|
13
15
|
const manifest = readManifest(pluginDir);
|
|
14
16
|
const results = [];
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
for (const w of checkHookEvents(pluginDir, targets))
|
|
19
|
-
console.error(`hooks: ${w}`);
|
|
17
|
+
// Surface target event gaps before they become silent no-ops. Antigravity's
|
|
18
|
+
// adapter may add more mechanical-translation diagnostics below.
|
|
19
|
+
const hookWarnings = new Set(checkHookEvents(pluginDir, targets));
|
|
20
20
|
for (const target of targets) {
|
|
21
21
|
const adapter = ADAPTERS[target];
|
|
22
22
|
if (!adapter)
|
|
@@ -26,7 +26,14 @@ export function adaptPlugin(pluginDir, targets, selection) {
|
|
|
26
26
|
// runtime mandates its own (.claude-plugin/ , .codex-plugin/).
|
|
27
27
|
const file = join(pluginDir, defaultPath);
|
|
28
28
|
writeJson(file, out);
|
|
29
|
+
if (target === "antigravity") {
|
|
30
|
+
writeAntigravityMcpConfig(pluginDir, manifest, selection);
|
|
31
|
+
for (const warning of writeAntigravityHooks(pluginDir, manifest, selection))
|
|
32
|
+
hookWarnings.add(warning);
|
|
33
|
+
}
|
|
29
34
|
results.push({ target, file });
|
|
30
35
|
}
|
|
36
|
+
for (const warning of hookWarnings)
|
|
37
|
+
console.error(`hooks: ${warning}`);
|
|
31
38
|
return results;
|
|
32
39
|
}
|
|
@@ -336,7 +336,8 @@ export async function addPlugins(opts) {
|
|
|
336
336
|
const scope = opts.scope ?? "project";
|
|
337
337
|
const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
|
|
338
338
|
agents = resolved.map((a) => {
|
|
339
|
-
const
|
|
339
|
+
const queryResult = a.listInstalled?.(ctxFor([]));
|
|
340
|
+
const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
|
|
340
341
|
const alreadyInstalled = (name) => agentInstalled !== undefined
|
|
341
342
|
? agentInstalled.includes(name)
|
|
342
343
|
: existingPlugins.has(name);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { listPlugins } from "./list.js";
|
|
3
|
-
import { allAgents, resolveAgents } from "../agents/index.js";
|
|
3
|
+
import { allAgents, isAgentListFailure, resolveAgents } from "../agents/index.js";
|
|
4
4
|
import { lockPath } from "../paths.js";
|
|
5
5
|
/** Diff the store against each agent's live plugin list. Read-only. */
|
|
6
6
|
export function pluginStatus(opts) {
|
|
@@ -16,6 +16,18 @@ export function pluginStatus(opts) {
|
|
|
16
16
|
if (installed === undefined) {
|
|
17
17
|
return { id: a.id, displayName: a.displayName, queryable: false, inSync: [], missing: [], agentOnly: [] };
|
|
18
18
|
}
|
|
19
|
+
if (isAgentListFailure(installed)) {
|
|
20
|
+
return {
|
|
21
|
+
id: a.id,
|
|
22
|
+
displayName: a.displayName,
|
|
23
|
+
queryable: false,
|
|
24
|
+
queryError: installed.error,
|
|
25
|
+
recoveryCommand: installed.recoveryCommand,
|
|
26
|
+
inSync: [],
|
|
27
|
+
missing: [],
|
|
28
|
+
agentOnly: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
19
31
|
const agentSet = new Set(installed);
|
|
20
32
|
// If we're in project scope and the project doesn't have an ADG lock file,
|
|
21
33
|
// the project is not initialized with ADG plugins. We should not report global
|
|
@@ -9,7 +9,8 @@ export function unlinkPlugins(opts) {
|
|
|
9
9
|
if (!agent)
|
|
10
10
|
return { target: opts.target, unlinked: [] };
|
|
11
11
|
const scope = opts.global ? "user" : "project";
|
|
12
|
-
const
|
|
12
|
+
const queryResult = agent.listInstalled?.({ pluginsDir: opts.pluginsDir, plugins: [], scope });
|
|
13
|
+
const installedInAgent = Array.isArray(queryResult) ? queryResult : undefined;
|
|
13
14
|
const installedInStore = listPlugins(opts.pluginsDir).map((p) => p.name);
|
|
14
15
|
// A name is valid if it is installed in either the store OR the agent (if queryable).
|
|
15
16
|
const validNames = new Set([...installedInStore, ...(installedInAgent ?? [])]);
|
package/dist/src/hooks.js
CHANGED
|
@@ -2,10 +2,9 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { resolveCodexHooksFile } from "./adapters/codex.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* is reported as unknown rather than hidden. Codex is a subset of Claude's set.
|
|
5
|
+
* Canonical Claude events each target can consume or mechanically map, from the
|
|
6
|
+
* official runtime docs. This table drives diagnostics; target adapters remain
|
|
7
|
+
* responsible for projection.
|
|
9
8
|
*/
|
|
10
9
|
const SUPPORTED_EVENTS = {
|
|
11
10
|
claude: new Set([
|
|
@@ -25,6 +24,7 @@ const SUPPORTED_EVENTS = {
|
|
|
25
24
|
"PostToolUse", "PreCompact", "PostCompact", "UserPromptSubmit",
|
|
26
25
|
"SubagentStop", "Stop",
|
|
27
26
|
]),
|
|
27
|
+
antigravity: new Set(["SessionStart", "PreToolUse", "PostToolUse", "Stop"]),
|
|
28
28
|
};
|
|
29
29
|
/** The hooks file `target` will actually load (plugin-relative), or undefined. */
|
|
30
30
|
function hooksFileForTarget(pluginDir, target) {
|
|
@@ -32,6 +32,12 @@ function hooksFileForTarget(pluginDir, target) {
|
|
|
32
32
|
// the shared file) — reuse the adapter's resolution so the lint matches reality.
|
|
33
33
|
if (target === "codex")
|
|
34
34
|
return resolveCodexHooksFile(pluginDir, "./hooks/");
|
|
35
|
+
if (target === "antigravity") {
|
|
36
|
+
const native = join(pluginDir, "hooks", "hooks-antigravity.json");
|
|
37
|
+
if (existsSync(native))
|
|
38
|
+
return undefined; // Native DSL does not need Claude-event linting.
|
|
39
|
+
return existsSync(join(pluginDir, "hooks", "hooks.json")) ? "hooks/hooks.json" : undefined;
|
|
40
|
+
}
|
|
35
41
|
// Claude auto-loads only the standard hooks/hooks.json.
|
|
36
42
|
return existsSync(join(pluginDir, "hooks", "hooks.json")) ? "hooks/hooks.json" : undefined;
|
|
37
43
|
}
|
|
@@ -47,21 +53,22 @@ function hookEventsOf(file) {
|
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
50
|
-
* Warn when a
|
|
51
|
-
*
|
|
52
|
-
* surfaces instead of silently doing nothing. Pure read-only lint — no transform.
|
|
56
|
+
* Warn when a canonical hook event cannot run on a target. This is read-only;
|
|
57
|
+
* Antigravity's actual translation lives in its target adapter.
|
|
53
58
|
*/
|
|
54
59
|
export function checkHookEvents(pluginDir, targets) {
|
|
55
60
|
const warnings = [];
|
|
56
61
|
for (const t of targets) {
|
|
57
|
-
if (t !== "claude" && t !== "codex")
|
|
62
|
+
if (t !== "claude" && t !== "codex" && t !== "antigravity")
|
|
58
63
|
continue;
|
|
59
64
|
const rel = hooksFileForTarget(pluginDir, t);
|
|
60
65
|
if (!rel)
|
|
61
66
|
continue;
|
|
62
67
|
for (const event of hookEventsOf(join(pluginDir, rel))) {
|
|
63
68
|
if (!SUPPORTED_EVENTS[t].has(event)) {
|
|
64
|
-
warnings.push(
|
|
69
|
+
warnings.push(t === "antigravity"
|
|
70
|
+
? `hook event "${event}" is not a supported antigravity hook mapping — antigravity will not fire it`
|
|
71
|
+
: `hook event "${event}" is not a known ${t} hook event — ${t} will not fire it`);
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
}
|
package/dist/src/package.js
CHANGED
|
@@ -13,9 +13,8 @@ import { mcpConfigPath } from "./mcp.js";
|
|
|
13
13
|
const META_RE = /^(README|LICEN[CS]E|CHANGELOG|NOTICE)(\..+)?$/i;
|
|
14
14
|
/**
|
|
15
15
|
* Generated runtime projections — shipped, but excluded from the content hash.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* stays hash-ignored rather than registering as spurious drift.
|
|
16
|
+
* Antigravity projects its manifest and hooks config at the plugin root, while
|
|
17
|
+
* its generated hook protocol runner lives under `.antigravity-plugin`.
|
|
19
18
|
*/
|
|
20
19
|
export const PROJECTION_DIRS = [".claude-plugin", ".codex-plugin", ".antigravity-plugin"];
|
|
21
20
|
/** Extract the first path segment of a manifest component value (e.g. "./skills/" -> "skills"). */
|
|
@@ -116,7 +116,16 @@ export function renderStatus(statuses) {
|
|
|
116
116
|
for (const s of statuses) {
|
|
117
117
|
out.push(ui.name(s.displayName));
|
|
118
118
|
if (!s.queryable) {
|
|
119
|
-
|
|
119
|
+
if (s.queryError) {
|
|
120
|
+
out.push(ui.meta(" live state unknown — agent CLI query failed"));
|
|
121
|
+
for (const line of s.queryError.split("\n"))
|
|
122
|
+
out.push(ui.warn(` ${line}`));
|
|
123
|
+
if (s.recoveryCommand)
|
|
124
|
+
out.push(ui.meta(` → ${s.recoveryCommand}`));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
out.push(ui.meta(" live state unknown — agent CLI not available or not queryable"));
|
|
128
|
+
}
|
|
120
129
|
continue;
|
|
121
130
|
}
|
|
122
131
|
out.push(ui.meta(` in sync (${s.inSync.length})${s.inSync.length ? ": " + s.inSync.join(", ") : ""}`));
|
package/docs/authoring.md
CHANGED
|
@@ -153,7 +153,8 @@ Two ways to declare them:
|
|
|
153
153
|
- **commands** — `"./commands/"`, a dir of slash-command markdown files.
|
|
154
154
|
- **agents** — `"./agents/"`, a dir of sub-agent definition `.md` files.
|
|
155
155
|
- **mcpServers** — `"./.mcp.json"`, an MCP server config file (points at a *file*,
|
|
156
|
-
not a dir).
|
|
156
|
+
not a dir). ADG keeps that pointer for Claude and Codex; Antigravity instead
|
|
157
|
+
materializes the referenced file as the required sibling `mcp_config.json`.
|
|
157
158
|
- **hooks**, **apps** — directories, same pattern. For hooks, see **Hooks**
|
|
158
159
|
below — agents differ on the hook config format, so ADG can compile a single
|
|
159
160
|
universal definition into each agent's native file.
|
|
@@ -165,11 +166,11 @@ the runtime projections and the installed package.
|
|
|
165
166
|
|
|
166
167
|
## Hooks
|
|
167
168
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
ADG adopts Claude's hook schema as its canonical source instead of defining a
|
|
170
|
+
fourth hook DSL. Codex consumes that structure directly, while Antigravity has a
|
|
171
|
+
different root filename, schema, event model, and JSON I/O contract. ADG routes
|
|
172
|
+
Claude/Codex files and mechanically projects the supported subset for
|
|
173
|
+
Antigravity. (Rationale and the unify-vs-adopt decision rule:
|
|
173
174
|
[docs/hooks-strategy.md](hooks-strategy.md).)
|
|
174
175
|
|
|
175
176
|
- **Author** `hooks/hooks.json` in Claude's hook format (see the
|
|
@@ -181,9 +182,23 @@ ADG only routes/lints them. (Rationale and the unify-vs-adopt decision rule:
|
|
|
181
182
|
Need genuinely different Codex behavior? Ship a `hooks/hooks-codex.json` and ADG
|
|
182
183
|
references that for Codex instead (per-agent override; Claude still uses
|
|
183
184
|
`hooks/hooks.json`).
|
|
185
|
+
- **Antigravity** requires `hooks.json` at the plugin root. ADG generates that
|
|
186
|
+
target file from the canonical Claude definition and bridges supported command
|
|
187
|
+
output into Antigravity's JSON protocol. For behavior that cannot be expressed
|
|
188
|
+
mechanically, ship native Antigravity DSL as `hooks/hooks-antigravity.json`;
|
|
189
|
+
ADG validates it, then copies it to the required root filename without
|
|
190
|
+
rewriting it. Invalid canonical or native input leaves the last-known-good
|
|
191
|
+
generated projection in place.
|
|
184
192
|
- **Lint** — at `adapt`/install ADG warns when your hooks use an event a target
|
|
185
|
-
|
|
186
|
-
|
|
193
|
+
cannot fire or map. Unsupported events/handlers are omitted from the generated
|
|
194
|
+
Antigravity file, but warnings do not abort synchronization.
|
|
195
|
+
|
|
196
|
+
The first Antigravity mapping set covers `SessionStart` (startup only),
|
|
197
|
+
`PreToolUse`, `PostToolUse`, and `Stop`. Tool matcher aliases are translated only
|
|
198
|
+
when they are deterministic; use the native override for target-specific tools,
|
|
199
|
+
asynchronous handlers, or output fields that have no Antigravity equivalent.
|
|
200
|
+
At runtime, an unsupported control output fails explicitly rather than being
|
|
201
|
+
silently weakened.
|
|
187
202
|
|
|
188
203
|
```json
|
|
189
204
|
{
|
package/docs/cli-json.md
CHANGED
|
@@ -101,7 +101,10 @@ Field notes:
|
|
|
101
101
|
- `targets` contains the resolved target ids requested by `--target`; omitted
|
|
102
102
|
`--target` resolves to all registered targets.
|
|
103
103
|
- `queryable: false` means the agent CLI could not be queried; the arrays are
|
|
104
|
-
then empty because live state is unknown.
|
|
104
|
+
then empty because live state is unknown. When the CLI ran but rejected the
|
|
105
|
+
query, `queryError` contains its diagnostic and `recoveryCommand` contains a
|
|
106
|
+
safe repair command when ADG recognizes the failure. Both fields are omitted
|
|
107
|
+
when unavailable.
|
|
105
108
|
- `inSync`, `missing`, and `agentOnly` are name-level comparisons. Content drift
|
|
106
109
|
is not represented; use `adg plugins sync` when a full runtime refresh is
|
|
107
110
|
required.
|
package/docs/hooks-strategy.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Design note: hooks strategy & the unify-vs-adopt principle
|
|
2
2
|
|
|
3
|
-
**Status:** Accepted
|
|
3
|
+
**Status:** Accepted, amended 2026-06-29 · **Context:** issue #32, the retired `adg.hooks/v1` DSL
|
|
4
4
|
|
|
5
5
|
This note records *why* ADG does not own a hooks DSL, and the decision rule that produced that outcome —
|
|
6
6
|
so the same wheel isn't reinvented.
|
|
@@ -21,46 +21,43 @@ layer, draw a hard line:
|
|
|
21
21
|
|
|
22
22
|
## Worked example: hooks
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
Claude's shape (`{hooks:{Event:[{matcher,hooks:[{type,command}]}]}}`) remains the
|
|
25
|
+
canonical authoring format. Codex consumes it and accepts `${CLAUDE_PLUGIN_ROOT}`.
|
|
26
|
+
Antigravity does not: it requires a root `hooks.json`, named hook definitions,
|
|
27
|
+
different lifecycle structure, and camelCase stdin/stdout contracts. The corrected
|
|
28
|
+
decision is still **adopt Claude's format**, but add a thin Antigravity target
|
|
29
|
+
adapter rather than pretending the native formats are identical.
|
|
28
30
|
|
|
29
31
|
`superpowers` ships three hook files (`hooks.json`, `hooks-codex.json`, `hooks-cursor.json`) — but that is
|
|
30
32
|
**behavioral divergence, not format divergence**: the author chose different matchers and *different scripts*
|
|
31
33
|
per agent. A DSL with `commandByTarget`/`matcherByTarget` does not make that "author once" — the author still
|
|
32
34
|
specifies both behaviors, just in one file. So the retired DSL had **no sweet spot**:
|
|
33
|
-
- homogeneous plugin → a single native `hooks/hooks.json`
|
|
35
|
+
- homogeneous Claude/Codex plugin → a single native `hooks/hooks.json` runs on both (DSL adds nothing);
|
|
34
36
|
- divergent plugin → DSL only relocates the N behaviors into override syntax (DSL adds syntax, not leverage).
|
|
35
37
|
|
|
36
38
|
### What ADG does instead (router + linter)
|
|
37
39
|
- **Same behavior across agents → one file.** Author `hooks/hooks.json` in Claude's format; Claude
|
|
38
|
-
auto-loads it, Codex references the same file
|
|
40
|
+
auto-loads it, Codex references the same file, and Antigravity mechanically projects its supported subset.
|
|
39
41
|
- **Different behavior per agent → N native files + routing.** Author ships `hooks/hooks-codex.json` (etc.);
|
|
40
|
-
|
|
42
|
+
`hooks/hooks-antigravity.json` is the Antigravity escape hatch. ADG routes each native override.
|
|
41
43
|
- **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)
|
|
44
|
+
Claude-only `UserPromptExpansion` on Codex or Antigravity) rather than silently dropping behavior.
|
|
43
45
|
|
|
44
|
-
##
|
|
46
|
+
## Thin Antigravity translation
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
Antigravity triggered the previously conditional translation layer. It remains
|
|
49
|
+
target-local and deterministic; it is not a revived public DSL.
|
|
48
50
|
|
|
49
|
-
**
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
- **File projection** — write Antigravity's required root `hooks.json` without touching canonical source files.
|
|
52
|
+
- **Schema projection** — convert `SessionStart`, `PreToolUse`, `PostToolUse`, and `Stop` into named native definitions.
|
|
53
|
+
- **Matcher aliases** — translate only exact built-in tool names and simple alternations; warn and omit unsafe regex rewrites.
|
|
54
|
+
- **Protocol bridge** — set canonical plugin-root environment variables and translate the supported stdin/stdout fields.
|
|
55
|
+
- **Native escape hatch** — validate and copy `hooks/hooks-antigravity.json` verbatim when a plugin needs target-specific semantics.
|
|
56
|
+
- **Failure safety** — validate before atomic replacement, retain the last-known-good projection on invalid input, and fail runtime control outputs that cannot be preserved safely.
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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.
|
|
58
|
+
**Out of scope:** inventing target-specific commands, guessing complex matcher
|
|
59
|
+
semantics, or emulating fields for which Antigravity has no equivalent. These
|
|
60
|
+
produce diagnostics and require a native override.
|
|
64
61
|
|
|
65
62
|
## The manifest is the same *pattern*, not the same *conclusion*
|
|
66
63
|
|