@routerhub/agent-rules 1.5.29 → 1.5.30

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/package.json +1 -1
  2. package/postinstall.js +36 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routerhub/agent-rules",
3
- "version": "1.5.29",
3
+ "version": "1.5.30",
4
4
  "description": "Shared Copilot agent rules and guidelines for RouterHub projects",
5
5
  "main": "AGENTS.base.md",
6
6
  "bin": {
package/postinstall.js CHANGED
@@ -1,11 +1,39 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // 安装完成后仅打印提示,不再自动初始化规则文件
4
- // 如需生成规则文件,请手动执行对应命令
5
- console.log("");
6
- console.log("[agent-rules] 安装完成,如需手动操作:");
7
- console.log(" - 初始化规则: npx agent-rules init");
8
- console.log(" - 同步规则: npx agent-rules sync");
9
- console.log(" - 启动监听: npx agent-rules watch");
10
- console.log(" - 查看帮助: npx agent-rules help");
3
+ const { spawn } = require("child_process");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+
7
+ // 获取下游项目根目录(INIT_CWD npm/pnpm 执行 install 时的原始目录)
8
+ const projectRoot = process.env.INIT_CWD || process.cwd();
9
+ const packageRoot = __dirname;
10
+ const mergeScriptPath = path.join(packageRoot, "merge.js");
11
+
12
+ // 安全检查:如果项目根目录在 node_modules 内,说明 INIT_CWD 未正确设置,跳过初始化
13
+ if (projectRoot.includes("node_modules")) {
14
+ console.log("[agent-rules] 检测到在 node_modules 内运行,跳过自动初始化");
15
+ console.log("[agent-rules] 请手动执行: npx agent-rules init");
16
+ process.exit(0);
17
+ }
18
+
11
19
  console.log("");
20
+ console.log("[agent-rules] 安装完成,正在同步规则文件...");
21
+
22
+ // 执行 sync 生成所有规则输出文件
23
+ const syncProcess = spawn("node", [mergeScriptPath, "sync"], {
24
+ cwd: projectRoot,
25
+ stdio: "inherit",
26
+ });
27
+
28
+ syncProcess.on("close", (code) => {
29
+ if (code === 0) {
30
+ console.log("[agent-rules] 规则文件同步完成");
31
+ console.log("");
32
+ } else {
33
+ console.error("[agent-rules] 同步失败,退出码:", code);
34
+ }
35
+ });
36
+
37
+ syncProcess.on("error", (err) => {
38
+ console.error("[agent-rules] 同步过程出错:", err.message);
39
+ });