@routerhub/agent-rules 1.5.83 → 1.5.84

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 (2) hide show
  1. package/merge.js +51 -3
  2. package/package.json +1 -1
package/merge.js CHANGED
@@ -7,9 +7,10 @@
7
7
  * node merge.js [command]
8
8
  *
9
9
  * command:
10
- * init 初始化规则文件,并在缺失时创建 AGENTS.private.md 模板
11
- * sync 重新生成所有规则输出文件
12
- * watch 监听 AGENTS.private.md 变化并自动同步
10
+ * init 初始化规则文件,并在缺失时创建 AGENTS.private.md 模板
11
+ * sync 重新生成所有规则输出文件
12
+ * update 自动更新 @routerhub/agent-rules 到最新版本并重新生成规则文件
13
+ * watch 监听 AGENTS.private.md 变化并自动同步
13
14
  *
14
15
  * 输出文件:
15
16
  * AGENTS.md 全量合并(兼容 Cursor/Claude Code)
@@ -614,6 +615,44 @@ function watchAgents() {
614
615
  });
615
616
  }
616
617
 
618
+ function selfUpdate() {
619
+ const { execSync } = require("child_process");
620
+
621
+ // 检测包管理器:按锁文件优先级 pnpm > yarn > npm
622
+ const lockFiles = [
623
+ { name: "pnpm", file: "pnpm-lock.yaml", cmd: "pnpm update @routerhub/agent-rules --latest" },
624
+ { name: "yarn", file: "yarn.lock", cmd: "yarn upgrade @routerhub/agent-rules --latest" },
625
+ { name: "npm", file: "package-lock.json", cmd: "npm update @routerhub/agent-rules@latest" },
626
+ ];
627
+
628
+ let pm = lockFiles[lockFiles.length - 1]; // 默认 npm
629
+ for (const candidate of lockFiles) {
630
+ if (fs.existsSync(path.join(currentRoot, candidate.file))) {
631
+ pm = candidate;
632
+ break;
633
+ }
634
+ }
635
+
636
+ console.log(`📦 检测到包管理器: ${pm.name}`);
637
+ console.log(`🔄 正在更新 @routerhub/agent-rules 到最新版本...`);
638
+ console.log(` 执行: ${pm.cmd}`);
639
+
640
+ try {
641
+ execSync(pm.cmd, { cwd: currentRoot, stdio: "inherit" });
642
+ console.log("");
643
+ console.log("✅ 包更新完成,正在重新生成规则文件...");
644
+ } catch (err) {
645
+ console.error(`❌ 包更新失败: ${err.message}`);
646
+ console.error(" 请手动执行: " + pm.cmd);
647
+ process.exit(1);
648
+ }
649
+
650
+ // 更新完成后执行 sync,重新生成所有规则输出文件
651
+ mergeAgents(getDefaultConfig());
652
+ console.log("");
653
+ console.log("✅ 规则文件已全部更新完成!");
654
+ }
655
+
617
656
  function main() {
618
657
  const command = process.argv[2];
619
658
 
@@ -628,6 +667,9 @@ function main() {
628
667
  console.log(
629
668
  " agent-rules sync 重新生成所有规则输出文件(CLAUDE.md + AGENTS.md + copilot-instructions.md + instructions/*.instructions.md)",
630
669
  );
670
+ console.log(
671
+ " agent-rules update 自动更新 @routerhub/agent-rules 到最新版本并重新生成规则文件",
672
+ );
631
673
  console.log(
632
674
  " agent-rules watch 监听 AGENTS.private.md,变更后自动同步所有规则文件",
633
675
  );
@@ -659,6 +701,12 @@ function main() {
659
701
  return;
660
702
  }
661
703
 
704
+ if (command === "update") {
705
+ selfUpdate();
706
+ return;
707
+ }
708
+
709
+
662
710
  if (command === "watch") {
663
711
  watchAgents();
664
712
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routerhub/agent-rules",
3
- "version": "1.5.83",
3
+ "version": "1.5.84",
4
4
  "description": "Shared Copilot agent rules and guidelines for RouterHub projects",
5
5
  "main": "AGENTS.base.md",
6
6
  "bin": {