claude-everything-workflow 0.2.10 → 0.2.12

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/AGENTS.md +1 -1
  5. package/README.md +10 -6
  6. package/README.zh-CN.md +11 -7
  7. package/bin/claude-everything-workflow.js +16 -4
  8. package/commands/code-review.md +4 -4
  9. package/docs/plugins.md +21 -2
  10. package/evals/routing-scenarios.json +11 -2
  11. package/hooks/check-code-size.js +4 -126
  12. package/hooks/check-console-log.js +4 -79
  13. package/hooks/check-edited-file.js +139 -0
  14. package/hooks/commit-quality.js +1029 -72
  15. package/hooks/runtime/antigravity-pre-tool.js +116 -0
  16. package/package.json +4 -2
  17. package/rules/02-implementation.md +1 -1
  18. package/rules/common/hooks.md +2 -2
  19. package/scripts/cleanup-retired-skills.js +36 -3
  20. package/scripts/eval-scenarios.js +46 -14
  21. package/scripts/install-antigravity.js +545 -0
  22. package/scripts/install-rules.js +145 -49
  23. package/scripts/install.ps1 +76 -8
  24. package/scripts/install.sh +74 -21
  25. package/scripts/merge-claude-settings.cjs +14 -2
  26. package/scripts/retired-skill-files.json +12 -0
  27. package/scripts/verify/commit-quality.test.js +481 -0
  28. package/scripts/verify/install-rules.test.js +499 -10
  29. package/scripts/verify/metadata-checks.js +27 -1
  30. package/scripts/verify/runtime-checks.js +57 -2
  31. package/scripts/verify/scenario-checks.test.js +39 -10
  32. package/scripts/verify/workflow-checks.js +5 -1
  33. package/settings.json +1 -6
  34. package/skills/README.md +1 -1
  35. package/skills/code-review/SKILL.md +15 -21
  36. package/skills/implement/SKILL.md +2 -2
  37. package/skills/systematic-debugging/SKILL.md +7 -4
  38. package/skills/systematic-debugging/references/diagnostic-scenarios.md +7 -0
  39. package/agents/harness-optimizer.md +0 -93
@@ -7,6 +7,7 @@ const path = require("node:path");
7
7
  const crypto = require("node:crypto");
8
8
  const { spawnSync } = require("node:child_process");
9
9
  const { installRules, finalizeBackups, BACKUP_ROOT_NAME } = require("../install-rules");
10
+ const { installAntigravity, parseFrontmatter, mapTools } = require("../install-antigravity");
10
11
 
11
12
  const sourceRoot = path.resolve(__dirname, "../..");
12
13
  const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-rules-"));
@@ -177,13 +178,63 @@ function checkCodexImplementationRuleUpgrades() {
177
178
  assert.equal(read(stock), read(source), "a known older distribution still upgrades");
178
179
  }
179
180
 
181
+ function checkAntigravityImplementationRuleUpgrades() {
182
+ const fixture = path.join(tempRoot, "ag-rule-source");
183
+ const filename = "02-implementation.md";
184
+ const source = path.join(fixture, "rules", filename);
185
+ const old = [
186
+ "# Implementation",
187
+ "Scope: fix bugs.",
188
+ "",
189
+ "# Checks",
190
+ "Run unit tests.",
191
+ "",
192
+ ].join("\n");
193
+ const hash = crypto.createHash("sha256").update(old).digest("hex");
194
+ fs.mkdirSync(path.join(fixture, "rules/common"), { recursive: true });
195
+ fs.mkdirSync(path.join(fixture, "scripts"));
196
+ fs.writeFileSync(source, old);
197
+ fs.writeFileSync(path.join(fixture, "rules/common/testing.md"), "Run checks.\n");
198
+ fs.writeFileSync(path.join(fixture, "scripts/legacy-common-rule-hashes.json"),
199
+ JSON.stringify({ files: { [filename]: [hash] } }));
200
+
201
+ const installRoot = path.join(tempRoot, "ag-rule-install");
202
+ const active = path.join(installRoot, "references/rules", filename);
203
+ const base = path.join(installRoot, ".cew-rule-state/02-implementation.base.md");
204
+ const incoming = path.join(installRoot, ".cew-rule-state/02-implementation.incoming.md");
205
+ const run = () => installRules({ sourceRoot: fixture, installRoot, host: "antigravity", log: () => {} });
206
+
207
+ run();
208
+ assert.equal(fs.existsSync(path.join(installRoot, "rules", filename)), false,
209
+ "Antigravity must keep detailed rules out of auto-loaded rules/");
210
+ assert.equal(read(active), old);
211
+ assert.equal(read(path.join(installRoot, "references/rules/common/testing.md")), "Run checks.\n");
212
+
213
+ const personal = old.replace("fix bugs.", "fix bugs. Leave unrelated work alone.").replace(/\n/g, "\r\n");
214
+ fs.writeFileSync(active, personal);
215
+ const updated = old.replace("unit tests", "unit and integration tests");
216
+ fs.writeFileSync(source, updated);
217
+ run();
218
+ const merged = personal.replace("unit tests", "unit and integration tests");
219
+ assert.equal(fs.readFileSync(active, "utf8"), merged, "Antigravity merges independent upstream edits");
220
+
221
+ fs.writeFileSync(source, updated.replace("Scope: fix bugs.", "Scope: add features."));
222
+ run();
223
+ assert.equal(fs.readFileSync(active, "utf8"), merged, "overlapping edits keep personal rule intact");
224
+ assert.equal(read(base), updated);
225
+ assert.equal(read(incoming), read(source));
226
+ }
227
+
180
228
  function checkInstallerCliOptions() {
181
229
  const profile = path.join(tempRoot, "invalid-cli-profile");
182
230
  for (const [options, message] of [
183
231
  [["--unknown-option"], /Unknown option: --unknown-option/],
184
232
  [["--claude-only", "--codex-only"], /cannot be used together/],
185
233
  [["--codex-only", "--claude-only"], /cannot be used together/],
234
+ [["--claude-only", "--antigravity-only"], /cannot be used together/],
235
+ [["--codex-only", "--antigravity-only"], /cannot be used together/],
186
236
  [["--claude-only", "--codex-only", "--help"], /cannot be used together/],
237
+ [["--antigravity-only", "--claude-only", "--help"], /cannot be used together/],
187
238
  ]) {
188
239
  const result = spawnSync(process.execPath, [
189
240
  path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install", ...options,
@@ -195,7 +246,7 @@ function checkInstallerCliOptions() {
195
246
  assert.notEqual(result.status, 0, "invalid CLI options must fail before installation");
196
247
  assert.match(result.stderr, message);
197
248
  }
198
- for (const host of [".claude", ".codex"]) {
249
+ for (const host of [".claude", ".codex", ".gemini"]) {
199
250
  assert.equal(fs.existsSync(path.join(profile, host)), false);
200
251
  }
201
252
  for (const help of ["--help", "-h"]) {
@@ -208,7 +259,7 @@ function checkInstallerCliOptions() {
208
259
  assert.ifError(result.error);
209
260
  assert.equal(result.status, 0, "install help must succeed without installing");
210
261
  assert.match(result.stdout, /Usage:/);
211
- for (const host of [".claude", ".codex"]) {
262
+ for (const host of [".claude", ".codex", ".gemini"]) {
212
263
  assert.equal(fs.existsSync(path.join(profile, host)), false);
213
264
  }
214
265
  }
@@ -222,6 +273,8 @@ function checkBashHelpOptions() {
222
273
  ["--help", "--claude-only", "--codex-only"],
223
274
  ["--claude-only", "--help", "--codex-only"],
224
275
  ["--claude-only", "--codex-only", "--help"],
276
+ ["--help", "--antigravity-only", "--codex-only"],
277
+ ["--claude-only", "--antigravity-only", "--help"],
225
278
  ["--help", "--unknown-option"],
226
279
  ["--unknown-option", "--help"],
227
280
  ];
@@ -238,14 +291,18 @@ function checkBashHelpOptions() {
238
291
  assert.notEqual(result.status, 0, `Bash must reject invalid options even with help: ${options.join(" ")}`);
239
292
  assert.match(result.stderr, /Unknown option|cannot be used together/);
240
293
  }
241
- for (const host of [".claude", ".codex"]) {
294
+ for (const host of [".claude", ".codex", ".gemini"]) {
242
295
  assert.equal(fs.existsSync(path.join(profile, host)), false);
243
296
  }
244
297
  }
245
298
  }
246
299
 
247
300
  function checkInstallerLinkedRoots() {
248
- for (const host of [".claude", ".codex"]) {
301
+ for (const [host, flag] of [
302
+ [".claude", "--claude-only"],
303
+ [".codex", "--codex-only"],
304
+ [".gemini", "--antigravity-only"],
305
+ ]) {
249
306
  const profile = path.join(tempRoot, "linked-profile" + host);
250
307
  const outside = path.join(tempRoot, "linked-outside" + host);
251
308
  fs.mkdirSync(profile);
@@ -253,8 +310,7 @@ function checkInstallerLinkedRoots() {
253
310
  fs.writeFileSync(path.join(outside, "AGENTS.md"), "Keep external user content\n");
254
311
  fs.symlinkSync(outside, path.join(profile, host), process.platform === "win32" ? "junction" : "dir");
255
312
  const result = spawnSync(process.execPath, [
256
- path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install",
257
- host === ".claude" ? "--claude-only" : "--codex-only",
313
+ path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install", flag,
258
314
  ], {
259
315
  cwd: sourceRoot,
260
316
  env: {
@@ -297,6 +353,60 @@ function checkInstallerMergeFailure() {
297
353
  assert.equal(fs.readFileSync(settingsPath, "utf8"), previous);
298
354
  }
299
355
 
356
+ function checkRetiredAgentCleanup() {
357
+ const fixture = path.join(tempRoot, "retired-agent");
358
+ const agents = path.join(fixture, "agents");
359
+ const name = "harness-optimizer.md";
360
+ const target = path.join(agents, name);
361
+ const cleanup = path.join(fixture, "cleanup-retired-skills.js");
362
+ const original = "Distributed agent\n";
363
+ const manifest = JSON.parse(read(path.join(sourceRoot, "scripts/retired-skill-files.json")));
364
+ manifest.retired_agent_hashes = { [name]: [crypto.createHash("sha256").update(original).digest("hex")] };
365
+ fs.mkdirSync(agents, { recursive: true });
366
+ fs.copyFileSync(path.join(sourceRoot, "scripts/cleanup-retired-skills.js"), cleanup);
367
+ fs.writeFileSync(path.join(fixture, "retired-skill-files.json"), JSON.stringify(manifest));
368
+ const run = (...args) => {
369
+ const result = spawnSync(process.execPath, [cleanup, fixture, ...args], { encoding: "utf8" });
370
+ assert.ifError(result.error);
371
+ assert.equal(result.status, 0, result.stderr);
372
+ };
373
+
374
+ fs.writeFileSync(target, original.replace("\n", "\r\n"));
375
+ fs.chmodSync(target, 0o444);
376
+ run("--dry-run");
377
+ assert.equal(read(target), original);
378
+ run();
379
+ assert.equal(fs.existsSync(target), false, "remove an unmodified distribution on upgrade");
380
+ fs.writeFileSync(target, original + "My changes\n");
381
+ run();
382
+ assert.equal(read(target), original + "My changes\n");
383
+
384
+ const outside = path.join(fixture, "personal-agents");
385
+ fs.renameSync(agents, outside);
386
+ fs.writeFileSync(path.join(outside, name), original);
387
+ fs.symlinkSync(outside, agents, process.platform === "win32" ? "junction" : "dir");
388
+ run();
389
+ assert.equal(read(path.join(outside, name)), original, "preserve files outside the install root's agents directory");
390
+
391
+ // File-level symlink inside a regular agents/ directory must also be preserved.
392
+ if (process.platform === "win32") {
393
+ fs.rmdirSync(agents);
394
+ } else {
395
+ fs.unlinkSync(agents);
396
+ }
397
+ fs.mkdirSync(agents);
398
+ const linkedFileTarget = path.join(outside, "linked.md");
399
+ fs.writeFileSync(linkedFileTarget, original);
400
+ if (process.platform !== "win32") {
401
+ fs.symlinkSync(linkedFileTarget, path.join(agents, name));
402
+ const linkRun = spawnSync(process.execPath, [cleanup, fixture], { encoding: "utf8" });
403
+ assert.ifError(linkRun.error);
404
+ assert.equal(linkRun.status, 0, linkRun.stderr);
405
+ assert.match(linkRun.stdout, /Preserving symlinked retired agent:/);
406
+ assert.equal(read(linkedFileTarget), original);
407
+ }
408
+ }
409
+
300
410
  function checkInstallerEntrypoint() {
301
411
  const profile = path.join(tempRoot, "installer-profile");
302
412
  const windows = process.platform === "win32";
@@ -313,9 +423,11 @@ function checkInstallerEntrypoint() {
313
423
  assert.notEqual(invalid.status, 0, "direct installer must reject unknown options before writing");
314
424
  assert.equal(fs.existsSync(path.join(profile, ".claude")), false);
315
425
  assert.equal(fs.existsSync(path.join(profile, ".codex")), false);
426
+ assert.equal(fs.existsSync(path.join(profile, ".gemini")), false);
316
427
  for (const only of [
317
428
  windows ? ["-ClaudeOnly", "-CodexOnly"] : ["--claude-only", "--codex-only"],
318
429
  windows ? ["-CodexOnly", "-ClaudeOnly"] : ["--codex-only", "--claude-only"],
430
+ windows ? ["-ClaudeOnly", "-AntigravityOnly"] : ["--claude-only", "--antigravity-only"],
319
431
  ]) {
320
432
  const conflict = spawnSync(executable, [...args, ...only], {
321
433
  cwd: sourceRoot, env, encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
@@ -323,7 +435,7 @@ function checkInstallerEntrypoint() {
323
435
  assert.ifError(conflict.error);
324
436
  assert.notEqual(conflict.status, 0, "direct installer must reject conflicting host options");
325
437
  assert.match(conflict.stderr, /cannot be used together/);
326
- for (const host of [".claude", ".codex"]) {
438
+ for (const host of [".claude", ".codex", ".gemini"]) {
327
439
  assert.equal(fs.existsSync(path.join(profile, host)), false);
328
440
  }
329
441
  }
@@ -333,10 +445,12 @@ function checkInstallerEntrypoint() {
333
445
  });
334
446
  assert.ifError(result.error);
335
447
  assert.equal(result.status, 0, result.stdout + result.stderr);
448
+ return result;
336
449
  };
337
450
  run([windows ? "-DryRun" : "--dry-run"]);
338
451
  assert.equal(fs.existsSync(path.join(profile, ".claude")), false);
339
452
  assert.equal(fs.existsSync(path.join(profile, ".codex")), false);
453
+ assert.equal(fs.existsSync(path.join(profile, ".gemini")), false);
340
454
  // Seed an older installation to exercise retirement and policy replacement through the real CLI.
341
455
  for (const host of [".claude", ".codex"]) {
342
456
  const skills = path.join(profile, host, "skills");
@@ -384,9 +498,35 @@ function checkInstallerEntrypoint() {
384
498
  type: "command",
385
499
  command: 'node scripts/hooks/run-with-flags.js post:write:console-log hooks/check-console-log.js standard,strict',
386
500
  };
501
+ const claudeRootPrefix = windows ? path.join(profile, ".claude") : "$HOME/.claude";
502
+ const oldEditHooks = [
503
+ {
504
+ type: "command",
505
+ command: `node "${claudeRootPrefix}/hooks/runtime/run-with-flags.js" post:edit:console-log "${claudeRootPrefix}/hooks/check-console-log.js" standard,strict`,
506
+ timeout: 5,
507
+ },
508
+ {
509
+ type: "command",
510
+ command: `node "${claudeRootPrefix}/hooks/runtime/run-with-flags.js" post:edit:code-size "${claudeRootPrefix}/hooks/check-code-size.js" standard,strict`,
511
+ timeout: 5,
512
+ },
513
+ ];
514
+ const legacyEditMatcherGroup = {
515
+ matcher: "Edit",
516
+ hooks: [
517
+ {
518
+ type: "command",
519
+ command: `node "${claudeRootPrefix}/hooks/runtime/run-with-flags.js" post:edit:console-log "${claudeRootPrefix}/hooks/check-console-log.js" standard,strict`,
520
+ timeout: 5,
521
+ },
522
+ ],
523
+ };
387
524
  fs.writeFileSync(settingsPath, JSON.stringify({
388
525
  hooks: {
389
- PostToolUse: [{ ...userHookGroup, hooks: [...userHookGroup.hooks, retiredConsole] }],
526
+ PostToolUse: [
527
+ { ...userHookGroup, hooks: [...userHookGroup.hooks, retiredConsole, ...oldEditHooks] },
528
+ legacyEditMatcherGroup,
529
+ ],
390
530
  SessionStart: [{ ...unrelatedHook, hooks: [...unrelatedHook.hooks, retiredSession] }],
391
531
  },
392
532
  }));
@@ -400,11 +540,40 @@ function checkInstallerEntrypoint() {
400
540
  const installedSettings = JSON.parse(read(settingsPath).replace(/^\uFEFF/, ""));
401
541
  assert.deepEqual(installedSettings.hooks.PostToolUse[0], userHookGroup);
402
542
  assert.deepEqual(installedSettings.hooks.SessionStart, [unrelatedHook]);
403
- assert.equal(installedSettings.hooks.PostToolUse.flatMap(({ hooks }) => hooks)
404
- .filter(({ command }) => command?.includes("hooks/check-console-log.js")).length, 1);
543
+ assert.equal(installedSettings.hooks.PostToolUse.some((g) => g.matcher === "Edit"), false,
544
+ "legacy matcher=Edit official console-log hook must be cleaned on upgrade");
545
+ const allPostEditCommands = installedSettings.hooks.PostToolUse.flatMap(({ hooks }) => hooks)
546
+ .map(({ command }) => command || "");
547
+ assert.equal(allPostEditCommands.filter((c) => /hooks[\\/]check-edited-file\.js/.test(c)).length, 1);
548
+ assert.equal(allPostEditCommands.filter((c) => /hooks[\\/]check-console-log\.js/.test(c)).length, 0);
549
+ assert.equal(allPostEditCommands.filter((c) => /hooks[\\/]check-code-size\.js/.test(c)).length, 0);
405
550
  const codexRule = path.join(profile, ".codex/rules/02-implementation.md");
406
551
  const customizedRule = read(codexRule) + "\nKeep unrelated work separate.\n";
407
552
  fs.writeFileSync(codexRule, customizedRule);
553
+ assert.equal(fs.existsSync(path.join(profile, ".gemini")), false,
554
+ "default install must not create ~/.gemini when it does not already exist");
555
+
556
+ // Default install must skip symlinked ~/.gemini without failing Claude/Codex updates.
557
+ const linkedGeminiOutside = path.join(tempRoot, "installer-linked-gemini");
558
+ fs.mkdirSync(linkedGeminiOutside);
559
+ fs.writeFileSync(path.join(linkedGeminiOutside, "sentinel.txt"), "keep\n");
560
+ fs.symlinkSync(
561
+ linkedGeminiOutside,
562
+ path.join(profile, ".gemini"),
563
+ windows ? "junction" : "dir",
564
+ );
565
+ const skippedLinked = run();
566
+ assert.match(skippedLinked.stdout, /Skipping Antigravity plugin sync/);
567
+ assert.deepEqual(fs.readdirSync(linkedGeminiOutside), ["sentinel.txt"]);
568
+ assert.equal(read(codexRule), customizedRule, "the host installer must preserve the active Codex rule");
569
+
570
+ // Once a regular ~/.gemini directory exists, default install syncs Antigravity automatically.
571
+ if (windows) {
572
+ fs.rmdirSync(path.join(profile, ".gemini"));
573
+ } else {
574
+ fs.unlinkSync(path.join(profile, ".gemini"));
575
+ }
576
+ fs.mkdirSync(path.join(profile, ".gemini"));
408
577
  run();
409
578
  assert.equal(read(codexRule), customizedRule, "the host installer must preserve the active Codex rule");
410
579
  assert.equal(read(path.join(backups, earlier, "AGENTS.md")), "My original instructions\n");
@@ -430,6 +599,7 @@ function checkInstallerEntrypoint() {
430
599
  }
431
600
  assert.equal(fs.existsSync(path.join(profile, host, "skills/wayfinder/agents")), false);
432
601
  assert.equal(fs.existsSync(path.join(profile, host, "scripts/install-rules.js")), false);
602
+ assert.equal(fs.existsSync(path.join(profile, host, "scripts/install-antigravity.js")), false);
433
603
  assert.equal(fs.existsSync(path.join(profile, host, "scripts/eval-scenarios.js")), false,
434
604
  "安装不应保留仅供包内评测的场景脚本");
435
605
  assert.equal(fs.existsSync(path.join(profile, host, "scripts/verify/scenario-checks.test.js")), false,
@@ -441,6 +611,321 @@ function checkInstallerEntrypoint() {
441
611
  assert.match(read(path.join(profile, host, "skills/handoff/agents/openai.yaml")),
442
612
  /allow_implicit_invocation: true/);
443
613
  }
614
+
615
+ const agRoot = path.join(profile, ".gemini/config/plugins/claude-everything-workflow");
616
+ const pkg = JSON.parse(read(path.join(sourceRoot, "package.json")));
617
+ const manifest = JSON.parse(read(path.join(agRoot, "plugin.json")));
618
+ assert.equal(manifest.name, pkg.name);
619
+ assert.equal(manifest.version, pkg.version);
620
+ assert.deepEqual(fs.readdirSync(path.join(agRoot, "rules")), ["AGENTS.md"]);
621
+ assert.match(read(path.join(agRoot, "rules/AGENTS.md")), /plugins\/claude-everything-workflow\/references\/rules\//);
622
+ assert.equal(read(path.join(agRoot, "references/rules/common/testing.md")),
623
+ read(path.join(sourceRoot, "rules/common/testing.md")));
624
+ assert.equal(fs.existsSync(path.join(agRoot, "skills/README.md")), false);
625
+ const agSkills = fs.readdirSync(path.join(agRoot, "skills"), { withFileTypes: true })
626
+ .filter((entry) => entry.isDirectory());
627
+ assert.equal(agSkills.length, 22);
628
+ for (const dir of agSkills) {
629
+ const skillMd = read(path.join(agRoot, "skills", dir.name, "SKILL.md"));
630
+ assert.match(skillMd, new RegExp(`^---\\nname: ${dir.name}\\ndescription: .+`, "m"));
631
+ }
632
+ assert.doesNotMatch(read(path.join(agRoot, "skills/pr/SKILL.md")), /\$ARGUMENTS/);
633
+ assert.doesNotMatch(read(path.join(agRoot, "skills/learn/SKILL.md")), /\$ARGUMENTS/);
634
+ const agAgents = fs.readdirSync(path.join(agRoot, "agents")).sort();
635
+ const expectedAgents = ["database-reviewer.md", "e2e-runner.md", "refactor-cleaner.md", "security-reviewer.md"];
636
+ assert.deepEqual(agAgents, expectedAgents);
637
+ for (const host of [".claude", ".codex"]) {
638
+ assert.deepEqual(fs.readdirSync(path.join(profile, host, "agents")).sort(), expectedAgents);
639
+ }
640
+ for (const agentFile of agAgents) {
641
+ const body = read(path.join(agRoot, "agents", agentFile));
642
+ assert.match(body, /^subagent: true$/m);
643
+ assert.match(body, /^mainAgent: false$/m);
644
+ assert.match(body, /^tools: \[/m);
645
+ assert.doesNotMatch(body, /^model:/m);
646
+ }
647
+ assert.match(read(path.join(agRoot, "agents/e2e-runner.md")),
648
+ /~\/\.gemini\/config\/plugins\/claude-everything-workflow\/skills\/feature-acceptance\/references\/e2e-testing\.md/);
649
+ assert.match(read(path.join(agRoot, "agents/security-reviewer.md")),
650
+ /~\/\.gemini\/config\/plugins\/claude-everything-workflow\/references\/agents\/security-reviewer\.md/);
651
+ assert.equal(fs.existsSync(path.join(agRoot, "scripts/learning/projects.js")), true);
652
+ assert.equal(fs.existsSync(path.join(agRoot, "harness/manifest.json")), true);
653
+ assert.equal(fs.existsSync(path.join(agRoot, "scripts/install-antigravity.js")), false);
654
+
655
+ // Antigravity hooks.json and rewritten plugin references.
656
+ const agHooks = JSON.parse(read(path.join(agRoot, "hooks.json")));
657
+ assert.equal(
658
+ agHooks["cew-commit-quality"]?.PreToolUse?.[0]?.matcher,
659
+ "run_command",
660
+ );
661
+ assert.equal(
662
+ agHooks["cew-commit-quality"]?.PreToolUse?.[0]?.hooks?.[0]?.command,
663
+ "node ./hooks/runtime/antigravity-pre-tool.js",
664
+ );
665
+ assert.equal(fs.existsSync(path.join(agRoot, "hooks/commit-quality.js")), true);
666
+ assert.equal(fs.existsSync(path.join(agRoot, "hooks/runtime/hook-flags.js")), true);
667
+ assert.equal(fs.existsSync(path.join(agRoot, "hooks/runtime/antigravity-pre-tool.js")), true);
668
+ assert.doesNotMatch(read(path.join(agRoot, "references/rules/05-git-workflow.md")), /`commands\/pr\.md`/);
669
+ assert.match(
670
+ read(path.join(agRoot, "references/rules/05-git-workflow.md")),
671
+ /~\/\.gemini\/config\/plugins\/claude-everything-workflow\/skills\/pr\/SKILL\.md/,
672
+ );
673
+ assert.doesNotMatch(read(path.join(agRoot, "skills/continuous-learning-v2/SKILL.md")), /`commands\/`/);
674
+
675
+ // Re-running Antigravity install with unchanged files must not create a spurious backup.
676
+ const agBackups = path.join(agRoot, BACKUP_ROOT_NAME);
677
+ const beforeSnapshots = fs.existsSync(agBackups) ? fs.readdirSync(agBackups) : [];
678
+ installAntigravity({ sourceRoot, homeDir: profile, backupId: "noop-reinstall", log: () => {} });
679
+ assert.equal(fs.existsSync(path.join(agBackups, "noop-reinstall")), false);
680
+ assert.deepEqual(fs.existsSync(agBackups) ? fs.readdirSync(agBackups) : [], beforeSnapshots);
681
+
682
+ // Exercise bundled Antigravity PreToolUse adapter against a disposable git repo.
683
+ const hookRepo = path.join(tempRoot, "ag-hook-repo");
684
+ fs.mkdirSync(hookRepo, { recursive: true });
685
+ const runGit = (...gitArgs) => {
686
+ const res = spawnSync("git", gitArgs, { cwd: hookRepo, encoding: "utf8" });
687
+ assert.equal(res.status, 0, res.stderr);
688
+ };
689
+ runGit("init", "-q");
690
+ runGit("config", "user.name", "Test");
691
+ runGit("config", "user.email", "test@example.com");
692
+ const invokeHook = (commandLine, extraEnv = {}, opts = {}) => {
693
+ const toolCwd = "toolCwd" in opts ? opts.toolCwd : hookRepo;
694
+ const legacyCwd = "legacyCwd" in opts ? opts.legacyCwd : agRoot;
695
+ const args = { CommandLine: commandLine };
696
+ if (toolCwd !== undefined) args.Cwd = toolCwd;
697
+ const payload = { toolCall: { name: "run_command", args } };
698
+ if (legacyCwd !== undefined) payload.cwd = legacyCwd;
699
+ if (opts.workspacePaths !== undefined) payload.workspacePaths = opts.workspacePaths;
700
+ const res = spawnSync(process.execPath, ["./hooks/runtime/antigravity-pre-tool.js"], {
701
+ cwd: agRoot,
702
+ env: { ...process.env, ...extraEnv },
703
+ input: JSON.stringify(payload),
704
+ encoding: "utf8",
705
+ timeout: 10000,
706
+ });
707
+ assert.ifError(res.error);
708
+ assert.equal(res.status, 0, res.stderr);
709
+ return JSON.parse(res.stdout);
710
+ };
711
+
712
+ fs.writeFileSync(path.join(hookRepo, "clean.js"), "export const ok = true;\n");
713
+ runGit("add", "clean.js");
714
+ assert.deepEqual(invokeHook('git commit -m "feat: clean"'), { decision: "allow" });
715
+ assert.deepEqual(invokeHook("git status"), { decision: "allow" });
716
+ assert.deepEqual(
717
+ invokeHook("git status", {}, { toolCwd: path.join(tempRoot, "missing-cwd") }),
718
+ { decision: "allow" },
719
+ );
720
+
721
+ const secretVal = "skTest0123456789abcdef012345";
722
+ fs.writeFileSync(path.join(hookRepo, "secret.js"), `const apiKey = "${secretVal}";\n`);
723
+ runGit("add", "secret.js");
724
+ const denied = invokeHook('git commit -m "feat: secret"');
725
+ assert.equal(denied.decision, "deny");
726
+ assert.match(denied.reason, /检测到疑似密钥/);
727
+ assert.equal(denied.reason.includes(secretVal), false);
728
+ assert.equal(
729
+ invokeHook('git commit -m "feat: legacy"', {}, { toolCwd: null, legacyCwd: hookRepo }).decision,
730
+ "deny",
731
+ );
732
+ assert.equal(
733
+ invokeHook('git commit -m "feat: workspace"', {}, {
734
+ toolCwd: undefined,
735
+ legacyCwd: undefined,
736
+ workspacePaths: [hookRepo],
737
+ }).decision,
738
+ "deny",
739
+ );
740
+ assert.equal(
741
+ invokeHook('git commit -m "feat: empty-cwd"', {}, {
742
+ toolCwd: "",
743
+ legacyCwd: undefined,
744
+ workspacePaths: [hookRepo],
745
+ }).decision,
746
+ "deny",
747
+ );
748
+ assert.equal(
749
+ invokeHook('git commit -m "feat: rel-cwd"', {}, {
750
+ toolCwd: path.basename(hookRepo),
751
+ legacyCwd: undefined,
752
+ workspacePaths: [tempRoot],
753
+ }).decision,
754
+ "deny",
755
+ );
756
+ assert.equal(
757
+ invokeHook('git commit -m "feat: invalid"', {}, { toolCwd: path.join(tempRoot, "missing-cwd") }).decision,
758
+ "deny",
759
+ );
760
+ assert.deepEqual(invokeHook('git commit -m "feat: secret"', { ECC_HOOK_PROFILE: "minimal" }), {
761
+ decision: "allow",
762
+ });
763
+ assert.deepEqual(
764
+ invokeHook('git commit -m "feat: secret"', { ECC_DISABLED_HOOKS: "pre:bash:commit-quality" }),
765
+ { decision: "allow" },
766
+ );
767
+ }
768
+
769
+ function checkAntigravityOnlyInstaller() {
770
+ const profile = path.join(tempRoot, "antigravity-only-profile");
771
+ const agRoot = path.join(profile, ".gemini/config/plugins/claude-everything-workflow");
772
+ const legacyAgents = path.join(profile, ".gemini/AGENTS.md");
773
+ fs.mkdirSync(path.join(agRoot, "skills/research"), { recursive: true });
774
+ fs.writeFileSync(path.join(agRoot, "skills/research/SKILL.md"), "Old distributed content\n");
775
+ fs.writeFileSync(path.join(agRoot, "skills/research/personal-notes.md"), "Keep my notes\n");
776
+ fs.writeFileSync(legacyAgents, "Keep legacy user file\n");
777
+
778
+ const runCli = (extra = []) => {
779
+ const result = spawnSync(process.execPath, [
780
+ path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install", "--antigravity-only", ...extra,
781
+ ], {
782
+ cwd: sourceRoot,
783
+ env: { ...process.env, USERPROFILE: profile, HOME: profile },
784
+ encoding: "utf8",
785
+ timeout: 60000,
786
+ maxBuffer: 8 * 1024 * 1024,
787
+ });
788
+ assert.ifError(result.error);
789
+ assert.equal(result.status, 0, result.stdout + result.stderr);
790
+ return result;
791
+ };
792
+
793
+ runCli(["--dry-run"]);
794
+ assert.equal(fs.existsSync(path.join(agRoot, "plugin.json")), false);
795
+
796
+ const first = runCli();
797
+ assert.equal(fs.existsSync(path.join(profile, ".claude")), false);
798
+ assert.equal(fs.existsSync(path.join(profile, ".codex")), false);
799
+ assert.equal(read(legacyAgents), "Keep legacy user file\n", "legacy ~/.gemini/AGENTS.md must not be removed");
800
+ assert.match(first.stdout, /\.gemini[\\/]AGENTS\.md/);
801
+ assert.equal(fs.existsSync(path.join(agRoot, "skills/research/SKILL.md")), false);
802
+ assert.equal(read(path.join(agRoot, "skills/research/personal-notes.md")), "Keep my notes\n");
803
+
804
+ const agImpl = path.join(agRoot, "references/rules/02-implementation.md");
805
+ const customized = read(agImpl) + "\nKeep Antigravity personal rule.\n";
806
+ fs.writeFileSync(agImpl, customized);
807
+ fs.writeFileSync(path.join(agRoot, "plugin.json"), '{"name":"old"}\n');
808
+ runCli();
809
+ assert.equal(read(agImpl), customized, "reinstall must preserve Antigravity personal 02-implementation.md");
810
+ const backupsDir = path.join(agRoot, BACKUP_ROOT_NAME);
811
+ const snapshots = fs.readdirSync(backupsDir);
812
+ assert.equal(snapshots.length, 1);
813
+ assert.equal(read(path.join(backupsDir, snapshots[0], "plugin.json")), '{"name":"old"}\n');
814
+ }
815
+
816
+ function checkAntigravityEdgeCases() {
817
+ // 1. Pre-write rule target validation must refuse symlinked references/rules before writing any file.
818
+ const precheckHome = path.join(tempRoot, "ag-precheck-home");
819
+ const outsideRules = path.join(tempRoot, "ag-outside-rules");
820
+ const precheckPlugin = path.join(precheckHome, ".gemini/config/plugins/claude-everything-workflow");
821
+ fs.mkdirSync(outsideRules, { recursive: true });
822
+ fs.mkdirSync(path.join(precheckPlugin, "references"), { recursive: true });
823
+ fs.symlinkSync(
824
+ outsideRules,
825
+ path.join(precheckPlugin, "references/rules"),
826
+ process.platform === "win32" ? "junction" : "dir",
827
+ );
828
+ assert.throws(
829
+ () => installAntigravity({ sourceRoot, homeDir: precheckHome, log: () => {} }),
830
+ /symlink/i,
831
+ );
832
+ assert.equal(fs.existsSync(path.join(precheckPlugin, "plugin.json")), false,
833
+ "symlinked references/rules must fail before any partial plugin write");
834
+ assert.deepEqual(fs.readdirSync(outsideRules), []);
835
+
836
+ // 2. Read-only source files (0o444) install with owner-writable permissions so upgrades succeed.
837
+ {
838
+ const roHome = path.join(tempRoot, "ag-ro-home");
839
+ const roSource = path.join(tempRoot, "ag-ro-source");
840
+ fs.cpSync(sourceRoot, roSource, {
841
+ recursive: true,
842
+ filter: (src) => !src.includes(`${path.sep}node_modules`) && !src.includes(`${path.sep}.git`),
843
+ });
844
+ const roRef = path.join(roSource, "references/git-worktrees.md");
845
+ const roRule = path.join(roSource, "rules/01-base.md");
846
+ fs.chmodSync(roRef, 0o444);
847
+ fs.chmodSync(roRule, 0o444);
848
+ try {
849
+ const installedRoot = installAntigravity({ sourceRoot: roSource, homeDir: roHome, log: () => {} });
850
+ const installedRef = path.join(installedRoot, "references/git-worktrees.md");
851
+ const installedRule = path.join(installedRoot, "references/rules/01-base.md");
852
+ assert.ok((fs.statSync(installedRef).mode & 0o200) !== 0, "installed file must keep owner write bit");
853
+ assert.ok(fs.statSync(installedRule).mode & 0o200, "installed rule must be owner-writable");
854
+ // Older installers could leave this target read-only.
855
+ fs.chmodSync(installedRule, 0o400);
856
+ fs.chmodSync(roRef, 0o644);
857
+ fs.writeFileSync(roRef, "# Updated worktrees\n");
858
+ const originalRule = read(roRule);
859
+ fs.chmodSync(roRule, 0o644);
860
+ fs.writeFileSync(roRule, "# Updated rule\n");
861
+ fs.chmodSync(roRule, 0o444);
862
+ installAntigravity({ sourceRoot: roSource, homeDir: roHome, backupId: "upgrade", log: () => {} });
863
+ assert.equal(read(installedRef), "# Updated worktrees\n");
864
+ assert.equal(read(installedRule), "# Updated rule\n");
865
+ assert.ok(fs.statSync(installedRule).mode & 0o200, "upgraded rule must be owner-writable");
866
+ const backup = path.join(installedRoot, BACKUP_ROOT_NAME, "upgrade", "references/rules/01-base.md");
867
+ assert.equal(read(backup), originalRule);
868
+ // Reuse the same snapshot ID, as happens for two updates within the same second.
869
+ fs.writeFileSync(installedRule, "Previous local rule\n");
870
+ installAntigravity({ sourceRoot: roSource, homeDir: roHome, backupId: "upgrade", log: () => {} });
871
+ assert.equal(read(backup), "Previous local rule\n");
872
+ assert.equal(read(installedRule), "# Updated rule\n");
873
+ } finally {
874
+ fs.chmodSync(roRef, 0o644);
875
+ fs.chmodSync(roRule, 0o644);
876
+ }
877
+ }
878
+
879
+ // 3. Symlinked $HOME is allowed when .gemini chain itself is clean.
880
+ const realHome = path.join(tempRoot, "ag-real-home");
881
+ const linkedHome = path.join(tempRoot, "ag-linked-home");
882
+ fs.mkdirSync(realHome);
883
+ fs.symlinkSync(realHome, linkedHome, process.platform === "win32" ? "junction" : "dir");
884
+ const linkedPlugin = installAntigravity({ sourceRoot, homeDir: linkedHome, log: () => {} });
885
+ assert.equal(fs.existsSync(path.join(linkedPlugin, "plugin.json")), true);
886
+
887
+ // 4. Zero-indent YAML lists parse cleanly; invalid/unmapped explicit tools throw instead of fail-open.
888
+ const parsedList = parseFrontmatter("---\nname: demo\ntools:\n- Read\n- Grep\n---\n\nBody\n");
889
+ assert.deepEqual(parsedList.data.tools, ["Read", "Grep"]);
890
+ assert.deepEqual(mapTools(["Read", "Grep"], "demo.md"), ["read_file"]);
891
+ assert.throws(() => mapTools(["UnknownTool"], "demo.md"), /no supported Antigravity tools/);
892
+ assert.throws(() => mapTools([], "demo.md"), /no supported Antigravity tools/);
893
+ assert.throws(() => mapTools("Read", "demo.md"), /invalid tools/);
894
+
895
+ // 5. Reject "." as --backup-id in both CLI entrypoints.
896
+ for (const script of ["scripts/install-rules.js", "scripts/install-antigravity.js"]) {
897
+ const args = script.endsWith("install-rules.js")
898
+ ? [path.join(sourceRoot, script), "codex", path.join(tempRoot, "unused"), "--backup-id", "."]
899
+ : [path.join(sourceRoot, script), path.join(tempRoot, "unused"), "--backup-id", "."];
900
+ const res = spawnSync(process.execPath, args, { cwd: sourceRoot, encoding: "utf8" });
901
+ assert.notEqual(res.status, 0);
902
+ assert.match(res.stderr, /Invalid --backup-id/);
903
+ }
904
+
905
+ // 6. Bash --antigravity-only works without rsync on PATH.
906
+ if (process.platform !== "win32") {
907
+ const noRsyncProfile = path.join(tempRoot, "ag-no-rsync-profile");
908
+ const noRsyncBin = path.join(tempRoot, "ag-no-rsync-bin");
909
+ fs.mkdirSync(noRsyncBin, { recursive: true });
910
+ fs.symlinkSync(process.execPath, path.join(noRsyncBin, "node"));
911
+ for (const tool of ["dirname", "date"]) {
912
+ const located = spawnSync("which", [tool], { encoding: "utf8" }).stdout.trim();
913
+ if (located) fs.symlinkSync(located, path.join(noRsyncBin, tool));
914
+ }
915
+ const executable = process.env.CEW_TEST_BASH || "bash";
916
+ const res = spawnSync(executable, ["scripts/install.sh", "--antigravity-only"], {
917
+ cwd: sourceRoot,
918
+ env: { ...process.env, HOME: noRsyncProfile, PATH: `${noRsyncBin}:/bin` },
919
+ encoding: "utf8",
920
+ timeout: 60000,
921
+ });
922
+ assert.ifError(res.error);
923
+ assert.equal(res.status, 0, res.stdout + res.stderr);
924
+ assert.equal(
925
+ fs.existsSync(path.join(noRsyncProfile, ".gemini/config/plugins/claude-everything-workflow/plugin.json")),
926
+ true,
927
+ );
928
+ }
444
929
  }
445
930
 
446
931
  try {
@@ -487,13 +972,17 @@ try {
487
972
  assert.deepEqual(fs.readdirSync(outside), []);
488
973
  assert.throws(() => install("invalid", "unknown"), /host/i);
489
974
  checkLegacyMigration();
975
+ checkRetiredAgentCleanup();
490
976
  checkPromotedImplementationRule();
491
977
  checkCodexImplementationRuleUpgrades();
978
+ checkAntigravityImplementationRuleUpgrades();
492
979
  checkInstallerCliOptions();
493
980
  checkBashHelpOptions();
494
981
  checkInstallerLinkedRoots();
495
982
  checkInstallerMergeFailure();
496
983
  checkInstallerEntrypoint();
984
+ checkAntigravityOnlyInstaller();
985
+ checkAntigravityEdgeCases();
497
986
  console.log("Rule installation tests passed (migration, backups, custom rules, symlink safety, both hosts, installer dry-run and execution).");
498
987
  } finally {
499
988
  // Only remove the exact private directory returned by mkdtemp; never a caller-supplied path.