claude-everything-workflow 0.2.11 → 0.2.13

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.
Files changed (39) hide show
  1. package/.claude-plugin/hooks.json +1 -6
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/README.md +1 -2
  5. package/README.zh-CN.md +1 -2
  6. package/docs/plugins.md +4 -4
  7. package/evals/routing-scenarios.json +9 -0
  8. package/hooks/check-code-size.js +4 -126
  9. package/hooks/check-console-log.js +4 -79
  10. package/hooks/check-edited-file.js +139 -0
  11. package/hooks/commit-quality.js +1029 -72
  12. package/hooks/runtime/antigravity-pre-tool.js +116 -0
  13. package/package.json +4 -3
  14. package/rules/02-implementation.md +1 -1
  15. package/rules/common/hooks.md +2 -2
  16. package/scripts/cleanup-retired-skills.js +80 -3
  17. package/scripts/install-antigravity.js +65 -105
  18. package/scripts/install-rules.js +27 -7
  19. package/scripts/install.ps1 +21 -25
  20. package/scripts/install.sh +2 -2
  21. package/scripts/merge-claude-settings.cjs +14 -2
  22. package/scripts/retired-skill-files.json +50 -0
  23. package/scripts/verify/commit-quality.test.js +481 -0
  24. package/scripts/verify/core.js +0 -1
  25. package/scripts/verify/install-rules.test.js +258 -22
  26. package/scripts/verify/metadata-checks.js +18 -10
  27. package/scripts/verify/runtime-checks.js +57 -2
  28. package/scripts/verify/workflow-checks.js +11 -1
  29. package/settings.json +1 -6
  30. package/skills/feature-acceptance/SKILL.md +1 -1
  31. package/skills/systematic-debugging/SKILL.md +7 -4
  32. package/skills/systematic-debugging/references/diagnostic-scenarios.md +7 -0
  33. package/agents/database-reviewer.md +0 -41
  34. package/agents/e2e-runner.md +0 -21
  35. package/agents/harness-optimizer.md +0 -93
  36. package/agents/refactor-cleaner.md +0 -54
  37. package/agents/security-reviewer.md +0 -47
  38. package/references/agents/refactor-cleaner.md +0 -75
  39. package/references/agents/security-reviewer.md +0 -542
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /**
5
+ * Antigravity PreToolUse Hook 适配器
6
+ *
7
+ * 读取 Antigravity camelCase stdin JSON,将含 git commit 的 run_command 调用
8
+ * 转发给 hooks/commit-quality.js,并输出符合 hooks.json 契约的 JSON 决策。
9
+ */
10
+
11
+ const path = require("node:path");
12
+ const { spawnSync } = require("node:child_process");
13
+ const { isHookEnabled } = require("./hook-flags");
14
+
15
+ const HOOK_ID = "pre:bash:commit-quality";
16
+ const PROFILES = "standard,strict";
17
+
18
+ function isValidDirString(value) {
19
+ return typeof value === "string" && value.trim().length > 0 && !value.includes("\0");
20
+ }
21
+
22
+ function resolveWorkDir(payload) {
23
+ const workspacePaths = Array.isArray(payload?.workspacePaths) ? payload.workspacePaths : [];
24
+ const workspaceRoot = workspacePaths.find(isValidDirString);
25
+ const baseCwd = isValidDirString(payload?.cwd)
26
+ ? payload.cwd
27
+ : workspaceRoot || process.cwd();
28
+
29
+ const rawToolCwd = payload?.toolCall?.args?.Cwd;
30
+ if (rawToolCwd !== undefined && rawToolCwd !== null) {
31
+ if (typeof rawToolCwd !== "string" || rawToolCwd.includes("\0")) {
32
+ return { valid: false };
33
+ }
34
+ if (rawToolCwd.trim()) {
35
+ const resolved = path.isAbsolute(rawToolCwd)
36
+ ? rawToolCwd
37
+ : path.resolve(baseCwd, rawToolCwd);
38
+ return { valid: true, cwd: resolved };
39
+ }
40
+ }
41
+
42
+ return { valid: true, cwd: baseCwd };
43
+ }
44
+
45
+ function run(raw) {
46
+ if (!isHookEnabled(HOOK_ID, { profiles: PROFILES })) {
47
+ return { decision: "allow" };
48
+ }
49
+
50
+ let payload;
51
+ try {
52
+ payload = JSON.parse(raw);
53
+ } catch {
54
+ return { decision: "allow" };
55
+ }
56
+
57
+ const toolName = payload?.toolCall?.name;
58
+ const commandLine = payload?.toolCall?.args?.CommandLine;
59
+ if (toolName !== "run_command" || typeof commandLine !== "string" || !commandLine.trim()) {
60
+ return { decision: "allow" };
61
+ }
62
+
63
+ if (!/\bcommit\b/i.test(commandLine)) {
64
+ return { decision: "allow" };
65
+ }
66
+
67
+ const workDir = resolveWorkDir(payload);
68
+ if (!workDir.valid) {
69
+ return { decision: "deny", reason: "Invalid run_command working directory." };
70
+ }
71
+
72
+ const commitQualityPath = path.resolve(__dirname, "..", "commit-quality.js");
73
+ const result = spawnSync(process.execPath, [commitQualityPath], {
74
+ input: JSON.stringify({ tool_input: { command: commandLine } }),
75
+ cwd: workDir.cwd,
76
+ encoding: "utf8",
77
+ timeout: 8000,
78
+ });
79
+
80
+ if (result.error || (result.status !== 0 && result.status !== 2)) {
81
+ return {
82
+ decision: "deny",
83
+ reason: "Could not run the commit check in the requested working directory.",
84
+ };
85
+ }
86
+ const reason = (result.stderr || "").trim();
87
+ if (result.status === 2) {
88
+ return {
89
+ decision: "deny",
90
+ reason: reason || "Commit blocked by cew-commit-quality hook.",
91
+ };
92
+ }
93
+
94
+ return reason ? { decision: "allow", reason } : { decision: "allow" };
95
+ }
96
+
97
+ module.exports = { run };
98
+
99
+ if (require.main === module) {
100
+ let raw = "";
101
+ process.stdin.setEncoding("utf8");
102
+ process.stdin.on("data", (chunk) => {
103
+ raw += chunk;
104
+ });
105
+ process.stdin.on("end", () => {
106
+ try {
107
+ process.stdout.write(`${JSON.stringify(run(raw))}\n`);
108
+ } catch (error) {
109
+ const message = error instanceof Error ? error.message : String(error);
110
+ process.stdout.write(
111
+ `${JSON.stringify({ decision: "allow", reason: `cew-commit-quality hook error: ${message}` })}\n`,
112
+ );
113
+ }
114
+ process.exit(0);
115
+ });
116
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "claude-everything-workflow",
3
- "version": "0.2.11",
4
- "description": "Claude Code and Codex harness with rules, skills, agents, hooks, and verification gates.",
3
+ "version": "0.2.13",
4
+ "description": "Claude Code, Codex, and Antigravity harness with rules, skills, agents, hooks, and verification gates.",
5
5
  "keywords": [
6
6
  "claude-code",
7
7
  "codex",
8
+ "antigravity",
8
9
  "agents",
9
10
  "harness",
10
11
  "skills"
@@ -23,6 +24,7 @@
23
24
  "test:install-rules": "node scripts/verify/install-rules.test.js",
24
25
  "test:learning": "node --test scripts/verify/learning.test.js",
25
26
  "test:plugins": "node --test scripts/verify/plugin-distribution.test.js",
27
+ "test:hooks": "node --test scripts/verify/commit-quality.test.js",
26
28
  "eval:scenarios": "node scripts/eval-scenarios.js",
27
29
  "verify:upstream": "node scripts/verify-upstream-capability-map.js",
28
30
  "pack:dry-run": "npm pack --dry-run"
@@ -44,7 +46,6 @@
44
46
  "docs/plugins.md",
45
47
  "evals/",
46
48
  "settings.json",
47
- "agents/",
48
49
  "bin/",
49
50
  "commands/",
50
51
  "hooks/",
@@ -23,6 +23,6 @@
23
23
 
24
24
  ## 代码与安全禁止 (CRITICAL)
25
25
 
26
- - 调试残留、类型抑制和耦合问题按目标项目标准检查;不得为掩盖真实错误添加抑制或绕过检查。`hooks/check-console-log.js` 对 `console.log`、`debugger`、`@ts-ignore`、`@ts-nocheck` 和 `any` 的提示属于兼容性警告,需结合真实用途判断。
26
+ - 调试残留、类型抑制和耦合问题按目标项目标准检查;不得为掩盖真实错误添加抑制或绕过检查。`hooks/check-edited-file.js` 对 `console.log`、`debugger`、`@ts-ignore`、`@ts-nocheck` 和 `any` 的提示属于兼容性警告,需结合真实用途判断。
27
27
  - 禁止硬编码密钥、API key、token、secret 或密码(改用环境变量)、SQL 字符串拼接(改用参数化)、未校验外部输入、明文密码(改用 hash)、绕过验证或质量门 Hook,以及提交调试代码。
28
28
  - 危险操作必须在沙箱或等价隔离环境中执行;安全敏感改动提交前按风险检查 SQL 注入、XSS、敏感信息泄露和依赖漏洞。发现违规时立即指出问题、解释原因并提供修复方案。
@@ -10,8 +10,8 @@
10
10
 
11
11
  - 摘要字段以 `rules/common/context-hygiene.md` 为唯一来源;不按轮数机械总结,不保存完整 transcript,不覆盖用户规则和决策;敏感内容只记录风险和证据位置,不持久化原值。
12
12
  - `ECC_HOOK_PROFILE` 支持 `minimal`、默认 `standard` 和 `strict`;`ECC_DISABLED_HOOKS` 禁用指定 Hook ID。
13
- - 会阻止提交的质量门 Hook 默认关闭,只有团队明确需要时启用。
14
- - `check-code-size` 与 `check-console-log` 是兼容性提示,不替代目标项目 lint 或类型规则;项目已有等价检查
13
+ - `standard`、`strict` 默认启用提交检查:疑似密钥命中时阻止提交,提交格式与调试代码仅警告;`minimal` 不启用此 Hook。它不替代目标项目的安全检查与质量门。
14
+ - `check-edited-file`(Hook ID `post:edit:quality`,仍兼容单独禁用 `post:edit:console-log` 与 `post:edit:code-size`)是兼容性提示,不替代目标项目 lint 或类型规则;项目已有等价检查
15
15
  或约定不适用时,可用 `ECC_DISABLED_HOOKS` 关闭相应提示,不能借此绕过项目质量门。
16
16
 
17
17
  ## 权限
@@ -3,6 +3,7 @@
3
3
 
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
+ const { createHash } = require("node:crypto");
6
7
 
7
8
  function writeLine(message) {
8
9
  process.stdout.write(`${message}\n`);
@@ -24,6 +25,20 @@ function isSafeRelative(value) {
24
25
  );
25
26
  }
26
27
 
28
+ function validateHashMap(rawMap, label, isValidKey) {
29
+ const entries = rawMap === undefined ? {} : rawMap;
30
+ if (!entries || typeof entries !== "object" || Array.isArray(entries)) {
31
+ throw new Error(`Invalid retired ${label} manifest`);
32
+ }
33
+ for (const [key, hashes] of Object.entries(entries)) {
34
+ if (!isValidKey(key) || !Array.isArray(hashes) || hashes.length === 0 ||
35
+ !hashes.every((hash) => typeof hash === "string" && /^[a-f0-9]{64}$/.test(hash))) {
36
+ throw new Error(`Invalid retired ${label} entry: ${key}`);
37
+ }
38
+ }
39
+ return Object.entries(entries);
40
+ }
41
+
27
42
  function validateManifest(manifest) {
28
43
  if (
29
44
  !manifest ||
@@ -45,7 +60,17 @@ function validateManifest(manifest) {
45
60
  throw new Error(`Invalid retired skill entry: ${skill}`);
46
61
  }
47
62
  }
48
- return entries;
63
+ const agents = validateHashMap(
64
+ manifest.retired_agent_hashes,
65
+ "agent",
66
+ (name) => /^[a-z0-9-]+\.md$/.test(name),
67
+ );
68
+ const references = validateHashMap(
69
+ manifest.retired_reference_hashes,
70
+ "reference",
71
+ (relative) => isSafeRelative(relative) && relative.endsWith(".md"),
72
+ );
73
+ return { skills: entries, agents, references };
49
74
  }
50
75
 
51
76
  function lstatIfExists(target) {
@@ -168,6 +193,42 @@ function cleanupSkill({ installRoot, skill, knownFiles, dryRun }) {
168
193
  }
169
194
  }
170
195
 
196
+ function cleanupHashedFiles({ installRoot, subDir, entries, label, removeEmptyParents, dryRun }) {
197
+ const rootDir = path.join(installRoot, subDir);
198
+ if (lstatIfExists(installRoot)?.isSymbolicLink()) return;
199
+ const dirStat = lstatIfExists(rootDir);
200
+ if (!dirStat) return;
201
+ if (dirStat.isSymbolicLink() || !dirStat.isDirectory()) return;
202
+
203
+ const directories = new Set();
204
+ for (const [relative, hashes] of entries) {
205
+ const target = path.join(rootDir, relative);
206
+ if (removeEmptyParents) collectKnownDirectories(rootDir, relative, directories);
207
+ if (hasSymlinkParent(rootDir, target)) {
208
+ writeLine(`Preserving retired ${label} through symlink: ${target}`);
209
+ continue;
210
+ }
211
+ const stat = lstatIfExists(target);
212
+ if (!stat) continue;
213
+ if (stat.isSymbolicLink()) {
214
+ writeLine(`Preserving symlinked retired ${label}: ${target}`);
215
+ continue;
216
+ }
217
+ if (!stat.isFile()) continue;
218
+ // SHA-256 of LF text, including host-transformed copies generated for Antigravity.
219
+ const text = fs.readFileSync(target, "utf8").replace(/\r\n/g, "\n");
220
+ if (!hashes.includes(createHash("sha256").update(text).digest("hex"))) {
221
+ writeLine(`Preserving customized retired ${label}: ${target}`);
222
+ continue;
223
+ }
224
+ writeLine(`${dryRun ? "[dry-run] " : ""}Remove retired ${label}: ${target}`);
225
+ if (!dryRun) fs.rmSync(target, { force: true });
226
+ }
227
+ if (!dryRun && removeEmptyParents) {
228
+ removeEmptyKnownDirectories(directories);
229
+ }
230
+ }
231
+
171
232
  function main(argv = process.argv.slice(2)) {
172
233
  const dryRun = argv.includes("--dry-run");
173
234
  const validateOnly = argv.includes("--validate");
@@ -184,10 +245,26 @@ function main(argv = process.argv.slice(2)) {
184
245
 
185
246
  const manifestPath = path.join(__dirname, "retired-skill-files.json");
186
247
  const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
187
- const retiredSkills = validateManifest(manifest);
248
+ const retired = validateManifest(manifest);
188
249
  if (validateOnly) return 0;
189
250
 
190
251
  const installRoot = path.resolve(positional[0]);
252
+ cleanupHashedFiles({
253
+ installRoot,
254
+ subDir: "agents",
255
+ entries: retired.agents,
256
+ label: "agent",
257
+ removeEmptyParents: false,
258
+ dryRun,
259
+ });
260
+ cleanupHashedFiles({
261
+ installRoot,
262
+ subDir: "references",
263
+ entries: retired.references,
264
+ label: "reference",
265
+ removeEmptyParents: true,
266
+ dryRun,
267
+ });
191
268
  const skillsRoot = path.join(installRoot, "skills");
192
269
  const skillsRootStat = lstatIfExists(skillsRoot);
193
270
  if (skillsRootStat?.isSymbolicLink()) {
@@ -198,7 +275,7 @@ function main(argv = process.argv.slice(2)) {
198
275
  throw new Error(`Expected skills directory: ${skillsRoot}`);
199
276
  }
200
277
 
201
- for (const [skill, knownFiles] of retiredSkills) {
278
+ for (const [skill, knownFiles] of retired.skills) {
202
279
  cleanupSkill({ installRoot, skill, knownFiles, dryRun });
203
280
  }
204
281
  return 0;
@@ -3,7 +3,6 @@
3
3
 
4
4
  const fs = require("node:fs");
5
5
  const path = require("node:path");
6
- const crypto = require("node:crypto");
7
6
  const { spawnSync } = require("node:child_process");
8
7
  const {
9
8
  BACKUP_ROOT_NAME,
@@ -11,6 +10,7 @@ const {
11
10
  defaultBackupId,
12
11
  finalizeBackups,
13
12
  installRules,
13
+ replaceFile,
14
14
  validateBackupId,
15
15
  validateRuleTargets,
16
16
  } = require("./install-rules");
@@ -19,27 +19,6 @@ const PLUGIN_NAME = "claude-everything-workflow";
19
19
  const PLUGIN_SUBPATH = path.posix.join(".gemini/config/plugins", PLUGIN_NAME);
20
20
  const PLUGIN_HOME_REF = `~/.gemini/config/plugins/${PLUGIN_NAME}`;
21
21
 
22
- const DEFAULT_ANTIGRAVITY_TOOLS = [
23
- "read_file",
24
- "edit_file",
25
- "write_file",
26
- "run_command",
27
- "manage_task",
28
- "search_web",
29
- ];
30
-
31
- const TOOL_MAP = {
32
- Read: ["read_file"],
33
- Glob: ["read_file"],
34
- Grep: ["read_file"],
35
- Edit: ["edit_file"],
36
- MultiEdit: ["edit_file"],
37
- Write: ["write_file"],
38
- Bash: ["run_command", "manage_task"],
39
- WebSearch: ["search_web"],
40
- WebFetch: ["search_web"],
41
- };
42
-
43
22
  function lstatIfExists(target) {
44
23
  try {
45
24
  return fs.lstatSync(target);
@@ -168,30 +147,6 @@ function parseFrontmatter(text) {
168
147
  return { data, body: match[2] };
169
148
  }
170
149
 
171
- function mapTools(rawTools, agentFile = "agent") {
172
- if (rawTools === undefined) {
173
- return [...DEFAULT_ANTIGRAVITY_TOOLS];
174
- }
175
- if (!Array.isArray(rawTools)) {
176
- throw new Error(`agents/${agentFile} declares invalid tools field`);
177
- }
178
- const mapped = [];
179
- const seen = new Set();
180
- for (const tool of rawTools) {
181
- const targets = TOOL_MAP[tool] || (DEFAULT_ANTIGRAVITY_TOOLS.includes(tool) ? [tool] : []);
182
- for (const target of targets) {
183
- if (!seen.has(target)) {
184
- seen.add(target);
185
- mapped.push(target);
186
- }
187
- }
188
- }
189
- if (mapped.length === 0) {
190
- throw new Error(`agents/${agentFile} declares no supported Antigravity tools`);
191
- }
192
- return mapped;
193
- }
194
-
195
150
  function normalizeRepoUrl(repo) {
196
151
  const raw = typeof repo === "string" ? repo : repo?.url;
197
152
  if (typeof raw !== "string" || !raw.trim()) {
@@ -221,6 +176,41 @@ function buildPluginManifest(sourceRoot) {
221
176
  return JSON.stringify(manifest, null, 2) + "\n";
222
177
  }
223
178
 
179
+ function buildHooksConfig() {
180
+ return (
181
+ JSON.stringify(
182
+ {
183
+ "cew-commit-quality": {
184
+ PreToolUse: [
185
+ {
186
+ matcher: "run_command",
187
+ hooks: [
188
+ {
189
+ type: "command",
190
+ command: "node ./hooks/runtime/antigravity-pre-tool.js",
191
+ timeout: 15,
192
+ },
193
+ ],
194
+ },
195
+ ],
196
+ },
197
+ },
198
+ null,
199
+ 2,
200
+ ) + "\n"
201
+ );
202
+ }
203
+
204
+ function rewriteAntigravityReferences(relative, text) {
205
+ let updated = text
206
+ .replace(/`commands\/(pr|verify|to-spec|learn)\.md`/g, (_, cmd) => `\`${PLUGIN_HOME_REF}/skills/${cmd}/SKILL.md\``)
207
+ .replace(/`commands\/code-review\.md`/g, `\`${PLUGIN_HOME_REF}/skills/code-review/SKILL.md\``);
208
+ if (relative === "skills/continuous-learning-v2/SKILL.md") {
209
+ updated = updated.replace(/`commands\/`/g, `\`${PLUGIN_HOME_REF}/skills/learn/SKILL.md\``);
210
+ }
211
+ return updated;
212
+ }
213
+
224
214
  function writeManagedFile({ pluginRoot, relative, content, mode, backupId, dryRun, log }) {
225
215
  const target = checkedPath(pluginRoot, relative);
226
216
  const next = Buffer.isBuffer(content) ? content : Buffer.from(content, "utf8");
@@ -233,27 +223,13 @@ function writeManagedFile({ pluginRoot, relative, content, mode, backupId, dryRu
233
223
  const backup = checkedPath(pluginRoot, path.posix.join(BACKUP_ROOT_NAME, backupId, relative));
234
224
  log(`${dryRun ? "[dry-run] " : ""}备份文件: ${backup}`);
235
225
  if (!dryRun) {
236
- fs.mkdirSync(path.dirname(backup), { recursive: true });
237
- fs.copyFileSync(target, backup);
226
+ replaceFile(backup, previous, existingStat.mode);
238
227
  }
239
228
  }
240
229
  }
241
230
  if (!dryRun) {
242
231
  const writableMode = mode !== undefined ? (mode & 0o777) | 0o200 : undefined;
243
- fs.mkdirSync(path.dirname(target), { recursive: true });
244
- const temp = `${target}.tmp-${crypto.randomUUID()}`;
245
- try {
246
- fs.writeFileSync(temp, next, {
247
- flag: "wx",
248
- ...(writableMode !== undefined ? { mode: writableMode } : {}),
249
- });
250
- if (process.platform !== "win32" && writableMode !== undefined) {
251
- fs.chmodSync(temp, writableMode);
252
- }
253
- fs.renameSync(temp, target);
254
- } finally {
255
- fs.rmSync(temp, { force: true });
256
- }
232
+ replaceFile(target, next, writableMode ?? existingStat?.mode ?? 0o644);
257
233
  } else {
258
234
  log(`[dry-run] 写入文件: ${target}`);
259
235
  }
@@ -301,43 +277,6 @@ function buildCommandSkills(sourceRoot) {
301
277
  return generated;
302
278
  }
303
279
 
304
- function buildAgentFiles(sourceRoot) {
305
- const agentsDir = path.join(sourceRoot, "agents");
306
- if (!fs.existsSync(agentsDir)) return [];
307
- const generated = [];
308
- for (const entry of fs.readdirSync(agentsDir, { withFileTypes: true })) {
309
- if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
310
- const raw = fs.readFileSync(path.join(agentsDir, entry.name), "utf8");
311
- const { data, body } = parseFrontmatter(raw);
312
- if (
313
- !data ||
314
- typeof data.name !== "string" ||
315
- !data.name.trim() ||
316
- typeof data.description !== "string" ||
317
- !data.description.trim()
318
- ) {
319
- throw new Error(`agents/${entry.name} missing name or description`);
320
- }
321
- const tools = mapTools(data.tools, entry.name);
322
- const updatedBody = body
323
- .replace(/`(skills\/[^`\s]+)`/g, (_, target) => `\`${PLUGIN_HOME_REF}/${target}\``)
324
- .replace(/`(references\/agents\/[^`\s]+)`/g, (_, target) => `\`${PLUGIN_HOME_REF}/${target}\``)
325
- .replace(/^\n+/, "");
326
- const frontmatter = [
327
- `name: ${data.name}`,
328
- `description: ${JSON.stringify(data.description)}`,
329
- "subagent: true",
330
- "mainAgent: false",
331
- `tools: [${tools.join(", ")}]`,
332
- ].join("\n");
333
- generated.push({
334
- relative: path.posix.join("agents", entry.name),
335
- content: `---\n${frontmatter}\n---\n\n${updatedBody}`,
336
- });
337
- }
338
- return generated;
339
- }
340
-
341
280
  function runRetiredSkillCleanup(sourceRoot, pluginRoot, dryRun, log) {
342
281
  const script = path.join(sourceRoot, "scripts/cleanup-retired-skills.js");
343
282
  const args = [script, pluginRoot];
@@ -371,19 +310,27 @@ function installAntigravity({
371
310
  path.join(sourceRoot, "scripts/learning"),
372
311
  "scripts/learning",
373
312
  );
313
+ const hookFiles = [
314
+ "hooks/commit-quality.js",
315
+ "hooks/runtime/hook-flags.js",
316
+ "hooks/runtime/antigravity-pre-tool.js",
317
+ ].map((relPath) => {
318
+ const srcPath = path.join(sourceRoot, relPath);
319
+ return { srcPath, relPath, mode: fs.statSync(srcPath).mode & 0o777 };
320
+ });
374
321
  const commandSkills = buildCommandSkills(sourceRoot);
375
- const agentFiles = buildAgentFiles(sourceRoot);
376
322
 
377
323
  const managedPaths = [
378
324
  BACKUP_ROOT_NAME,
379
325
  "plugin.json",
326
+ "hooks.json",
380
327
  "rules/AGENTS.md",
381
328
  "harness/manifest.json",
382
329
  ...refFiles.map((item) => item.relPath),
383
330
  ...skillFiles.map((item) => item.relPath),
384
331
  ...learningFiles.map((item) => item.relPath),
332
+ ...hookFiles.map((item) => item.relPath),
385
333
  ...commandSkills.map((item) => item.relative),
386
- ...agentFiles.map((item) => item.relative),
387
334
  ];
388
335
 
389
336
  // Validate every target before the first write; checkedPath refuses symlinks.
@@ -405,6 +352,14 @@ function installAntigravity({
405
352
  dryRun,
406
353
  log,
407
354
  });
355
+ writeManagedFile({
356
+ pluginRoot,
357
+ relative: "hooks.json",
358
+ content: buildHooksConfig(),
359
+ backupId,
360
+ dryRun,
361
+ log,
362
+ });
408
363
  writeManagedFile({
409
364
  pluginRoot,
410
365
  relative: "rules/AGENTS.md",
@@ -421,17 +376,21 @@ function installAntigravity({
421
376
  log,
422
377
  });
423
378
 
424
- for (const item of [...refFiles, ...skillFiles, ...learningFiles]) {
379
+ for (const item of [...refFiles, ...skillFiles, ...learningFiles, ...hookFiles]) {
380
+ let content = fs.readFileSync(item.srcPath);
381
+ if (item.relPath.startsWith("skills/") && item.relPath.endsWith(".md")) {
382
+ content = rewriteAntigravityReferences(item.relPath, content.toString("utf8"));
383
+ }
425
384
  writeManagedFile({
426
385
  pluginRoot,
427
386
  relative: item.relPath,
428
- content: fs.readFileSync(item.srcPath),
387
+ content,
429
388
  mode: item.mode,
430
389
  dryRun,
431
390
  log,
432
391
  });
433
392
  }
434
- for (const item of [...commandSkills, ...agentFiles]) {
393
+ for (const item of commandSkills) {
435
394
  writeManagedFile({
436
395
  pluginRoot,
437
396
  relative: item.relative,
@@ -448,6 +407,7 @@ function installAntigravity({
448
407
  backupId,
449
408
  dryRun,
450
409
  log,
410
+ transformContent: rewriteAntigravityReferences,
451
411
  });
452
412
 
453
413
  runRetiredSkillCleanup(sourceRoot, pluginRoot, dryRun, log);
@@ -461,7 +421,7 @@ function installAntigravity({
461
421
  return pluginRoot;
462
422
  }
463
423
 
464
- module.exports = { PLUGIN_SUBPATH, installAntigravity, parseFrontmatter, mapTools };
424
+ module.exports = { PLUGIN_SUBPATH, installAntigravity, parseFrontmatter };
465
425
 
466
426
  function parseCli(argv) {
467
427
  let dryRun = false;
@@ -73,9 +73,17 @@ function replaceFile(file, content, mode = 0o600) {
73
73
  }
74
74
  }
75
75
 
76
- function copyRule({ source, root, relative, backupId, dryRun, log, merged }) {
76
+ function copyRule({ source, root, relative, backupId, dryRun, log, merged, transformContent }) {
77
77
  const target = checkedPath(root, relative);
78
- const content = merged ?? fs.readFileSync(source);
78
+ let content;
79
+ if (merged) {
80
+ content = merged;
81
+ } else {
82
+ const raw = fs.readFileSync(source);
83
+ content = transformContent
84
+ ? Buffer.from(transformContent(relative, raw.toString("utf8")), "utf8")
85
+ : raw;
86
+ }
79
87
  const exists = fs.existsSync(target);
80
88
  if (exists) {
81
89
  const previous = fs.readFileSync(target);
@@ -114,13 +122,16 @@ function mergeRuleText(local, base, incoming) {
114
122
  }
115
123
 
116
124
  function installMergedImplementationRule(options, knownHashes, hostLabel) {
117
- const { source, root, relative, dryRun, log } = options;
125
+ const { source, root, relative, dryRun, log, transformContent } = options;
118
126
  const target = checkedPath(root, relative);
119
127
  const base = checkedPath(root, IMPLEMENTATION_RULE_BASE);
120
128
  const incoming = checkedPath(root, IMPLEMENTATION_RULE_INCOMING);
121
129
  const previous = fs.existsSync(base) ? fs.readFileSync(base) : null;
122
130
  const local = fs.existsSync(target) ? fs.readFileSync(target) : null;
123
- const next = fs.readFileSync(source);
131
+ const rawNext = fs.readFileSync(source);
132
+ const next = transformContent
133
+ ? Buffer.from(transformContent(relative, rawNext.toString("utf8")), "utf8")
134
+ : rawNext;
124
135
  const localHash = local && digest(local);
125
136
  const pristine = !local || localHash === digest(next) ||
126
137
  (previous ? localHash === digest(previous) : knownHashes.includes(localHash));
@@ -331,7 +342,15 @@ function validateRuleTargets({ sourceRoot, installRoot, host }) {
331
342
  return { policy, root, rulesRoot, relatives };
332
343
  }
333
344
 
334
- function installRules({ sourceRoot, installRoot, host, backupId = defaultBackupId(), dryRun = false, log = console.log }) {
345
+ function installRules({
346
+ sourceRoot,
347
+ installRoot,
348
+ host,
349
+ backupId = defaultBackupId(),
350
+ dryRun = false,
351
+ log = console.log,
352
+ transformContent,
353
+ }) {
335
354
  validateBackupId(backupId);
336
355
  const { policy, root, rulesRoot, relatives } = validateRuleTargets({ sourceRoot, installRoot, host });
337
356
  const legacy = JSON.parse(fs.readFileSync(path.join(sourceRoot, "scripts/legacy-common-rule-hashes.json"), "utf8"));
@@ -339,7 +358,7 @@ function installRules({ sourceRoot, installRoot, host, backupId = defaultBackupI
339
358
  const source = path.join(rulesRoot, relative);
340
359
  if (policy.mergedRule && relative === "02-implementation.md") {
341
360
  installMergedImplementationRule(
342
- { source, root, relative: policy.mergedRule.relative, backupId, dryRun, log },
361
+ { source, root, relative: policy.mergedRule.relative, backupId, dryRun, log, transformContent },
343
362
  legacy.files[relative] || [],
344
363
  policy.mergedRule.hostLabel,
345
364
  );
@@ -350,7 +369,7 @@ function installRules({ sourceRoot, installRoot, host, backupId = defaultBackupI
350
369
  continue;
351
370
  }
352
371
  const targetDir = policy.dirFor(relative);
353
- copyRule({ source, root, relative: `${targetDir}/${relative}`, backupId, dryRun, log });
372
+ copyRule({ source, root, relative: `${targetDir}/${relative}`, backupId, dryRun, log, transformContent });
354
373
  if (policy.retireColdFromRules && targetDir === "references/rules") {
355
374
  retireRule({
356
375
  source, root, relative: `rules/${relative}`,
@@ -370,6 +389,7 @@ module.exports = {
370
389
  BACKUP_ROOT_NAME,
371
390
  checkedPath,
372
391
  defaultBackupId,
392
+ replaceFile,
373
393
  validateBackupId,
374
394
  validateRuleTargets,
375
395
  installRules,