@d5render/cli 0.0.66 → 0.0.80

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.
@@ -1,74 +1,76 @@
1
- import { execSync, spawn } from "node:child_process";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { env, exit, platform } from "node:process";
5
- import { errorMessage, getHash, getPrompt, name, report, tools } from "./copilot.config.js";
6
-
7
- const prompt = `call the mcp tool '${name}-${getHash}' to load review commits, if the task encounters an error, throw that, otherwise, you can decide for yourself which tools to use to enrich context and determine whether a specific commit needs to be reviewed.
8
- Then, use chinese as default language to organize the report into JSON format and call the mcp tool '${name}-${report}', please ignore error encountered when calling this and report title should not contain words such as MCP or "中文".`;
9
-
10
- install();
11
- const copilot = spawn("node", [findCopilopt(), "--stream", "off", ...tools, "-p", prompt], {
12
- cwd: env.CI_PROJECT_DIR,
13
- ...(platform === "win32" && { windowsHide: true }),
14
- });
15
-
16
- let hasError = false;
17
- const errorRegex = new RegExp(errorMessage, "i");
18
- copilot.stdout.on("data", (data) => {
19
- const str = String(data);
20
- console.log(str);
21
-
22
- if (errorRegex.test(str)) hasError = true;
23
- });
24
- copilot.stderr.on("data", (data) => console.error(String(data)));
25
- copilot.on("close", () => {
26
- if (hasError) exit(1);
27
- else exit(0);
28
- });
29
-
30
- function install() {
31
- if (!env.CI) return;
32
- console.log("install dependencies...");
33
- try {
34
- const local =
35
- platform !== "win32"
36
- ? execSync("npm i -g @github/copilot --registry=https://registry.npmmirror.com --force")
37
- : execSync("npm list @github/copilot -g --depth=0 --json").toString();
38
- const localInfo = JSON.parse(local);
39
- const localVersion = localInfo.dependencies?.["@github/copilot"]?.version;
40
- const remoteVersion = execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com")
41
- .toString()
42
- .trim();
43
- if (localVersion !== remoteVersion) {
44
- execSync("npm uninstall -g @github/copilot --force");
45
- execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", {
46
- stdio: "inherit",
47
- });
48
- }
49
- } catch (error) {
50
- console.error(error);
51
- }
52
- }
53
- function findCopilopt() {
54
- let copilot = execSync("npm list @github/copilot -g -p").toString().trim();
55
- if (!copilot) {
56
- try {
57
- const pathEnv = env.PATH || env.Path || "";
58
- const pathSeparator = platform === "win32" ? ";" : ":";
59
- const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
60
- if (npm) copilot = join(npm, "node_modules", "@github", "copilot");
61
- } catch {}
62
- }
63
- const pkg = join(copilot, "package.json");
64
- if (!existsSync(pkg)) throw new Error("找不到 copilot 包");
65
- const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
66
- // return join(copilot, copilotPackage.bin.copilot);
67
- // 兼容 bin 字段可能是字符串或对象的情况
68
- const binPath =
69
- typeof copilotPackage.bin === "string"
70
- ? copilotPackage.bin
71
- : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
72
- if (!binPath) throw new Error("找不到 copilot 可执行文件路径");
73
- return join(copilot, binPath);
74
- }
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync, spawn } from "node:child_process";
4
+ import { existsSync, readFileSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { env, exit, platform } from "node:process";
7
+ import { errorMessage, getHash, name, report, tools } from "../copilot.config.js";
8
+
9
+ const prompt = `call the mcp tool '${name}-${getHash}' to load review commits, if the task encounters an error, throw that, otherwise, you can decide for yourself which tools to use to enrich context and determine whether a specific commit needs to be reviewed.
10
+ Then, use chinese as default language to organize the report into JSON format and call the mcp tool '${name}-${report}', please ignore error encountered when calling this and report title should not contain words such as MCP or "中文".`;
11
+
12
+ install();
13
+ const copilot = spawn("node", [findCopilopt(), "--stream", "off", ...tools, "-p", prompt], {
14
+ cwd: env.CI_PROJECT_DIR,
15
+ ...(platform === "win32" && { windowsHide: true }),
16
+ });
17
+
18
+ let hasError = false;
19
+ const errorRegex = new RegExp(errorMessage, "i");
20
+ copilot.stdout.on("data", (data) => {
21
+ const str = String(data);
22
+ console.log(str);
23
+
24
+ if (errorRegex.test(str)) hasError = true;
25
+ });
26
+ copilot.stderr.on("data", (data) => console.error(String(data)));
27
+ copilot.on("close", () => {
28
+ if (hasError) exit(1);
29
+ else exit(0);
30
+ });
31
+
32
+ function install() {
33
+ if (!env.CI) return;
34
+ console.log("install dependencies...");
35
+ try {
36
+ const local =
37
+ platform !== "win32"
38
+ ? execSync("npm i -g @github/copilot --registry=https://registry.npmmirror.com --force")
39
+ : execSync("npm list @github/copilot -g --depth=0 --json").toString();
40
+ const localInfo = JSON.parse(local);
41
+ const localVersion = localInfo.dependencies?.["@github/copilot"]?.version;
42
+ const remoteVersion = execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com")
43
+ .toString()
44
+ .trim();
45
+ if (localVersion !== remoteVersion) {
46
+ execSync("npm uninstall -g @github/copilot --force");
47
+ execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", {
48
+ stdio: "inherit",
49
+ });
50
+ }
51
+ } catch (error) {
52
+ console.error(error);
53
+ }
54
+ }
55
+ function findCopilopt() {
56
+ let copilot = execSync("npm list @github/copilot -g -p").toString().trim();
57
+ if (!copilot) {
58
+ try {
59
+ const pathEnv = env.PATH || env.Path || "";
60
+ const pathSeparator = platform === "win32" ? ";" : ":";
61
+ const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
62
+ if (npm) copilot = join(npm, "node_modules", "@github", "copilot");
63
+ } catch {}
64
+ }
65
+ const pkg = join(copilot, "package.json");
66
+ if (!existsSync(pkg)) throw new Error("找不到 copilot 包");
67
+ const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
68
+ // return join(copilot, copilotPackage.bin.copilot);
69
+ // 兼容 bin 字段可能是字符串或对象的情况
70
+ const binPath =
71
+ typeof copilotPackage.bin === "string"
72
+ ? copilotPackage.bin
73
+ : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
74
+ if (!binPath) throw new Error("找不到 copilot 可执行文件路径");
75
+ return join(copilot, binPath);
76
+ }
package/copilot.config.js CHANGED
@@ -1,68 +1,68 @@
1
- import { dirname, join } from "node:path";
2
- import { fileURLToPath } from "node:url";
3
-
4
- export const name = "d5_mcp_review_builtin";
5
- export const report = "report";
6
- export const getPrompt = "default_review_requirements";
7
- export const getHash = "getHash";
8
-
9
- export const errorMessage = "error: call mcp " + name;
10
- export const noMandatory = "dont't call under non-mandatory conditions";
11
-
12
- export const file = join(dirname(fileURLToPath(import.meta.url)), "dist/copilot.js");
13
-
14
- const { argv } = process;
15
- const envArg = argv.find((arg) => arg.startsWith("--customizenv="));
16
- let envJson = {};
17
- if (envArg) envJson = JSON.parse(envArg.replace("--customizenv=", ""));
18
- function toEnv(key, defaultValue = undefined) {
19
- return envJson[key] || process.env[key] || defaultValue;
20
- }
21
- // 辣鸡: https://github.com/modelcontextprotocol/typescript-sdk/issues/259
22
- export const envUsed = {
23
- CI_SERVER_URL: toEnv("CI_SERVER_URL"),
24
- CI_PROJECT_PATH: toEnv("CI_PROJECT_PATH"),
25
- CI_PROJECT_ID: toEnv("CI_PROJECT_ID"),
26
- CI_PROJECT_NAME: toEnv("CI_PROJECT_NAME"),
27
-
28
- CI_COMMIT_SHA: toEnv("CI_COMMIT_SHA"),
29
- CI_COMMIT_BEFORE_SHA: toEnv("CI_COMMIT_BEFORE_SHA"),
30
-
31
- CI_COMMIT_AUTHOR: toEnv("CI_COMMIT_AUTHOR"),
32
- CI_COMMIT_AUTHOR_EMAIL: toEnv("CI_COMMIT_AUTHOR_EMAIL"),
33
-
34
- CI_MERGE_REQUEST_IID: toEnv("CI_MERGE_REQUEST_IID"),
35
- CI_MERGE_REQUEST_TITLE: toEnv("CI_MERGE_REQUEST_TITLE"),
36
- CI_MERGE_REQUEST_DESCRIPTION: toEnv("CI_MERGE_REQUEST_DESCRIPTION"),
37
-
38
- JIRA_BASE_URL: toEnv("JIRA_BASE_URL", "http://jira.d5techs.com.cn"),
39
-
40
- DINGTALK_WEBHOOK: toEnv("DINGTALK_WEBHOOK"),
41
- GITLAB_TOKEN: toEnv("GITLAB_TOKEN"),
42
- JIRA_PAT: toEnv("JIRA_PAT"),
43
- JIRA_COOKIE: toEnv("JIRA_COOKIE"),
44
-
45
- JIRA_USERNAME: toEnv("JIRA_USERNAME"),
46
- JIRA_PASSWORD: toEnv("JIRA_PASSWORD")
47
- };
48
-
49
- const config = JSON.stringify({
50
- mcpServers: {
51
- [name]: {
52
- type: "local",
53
- command: "node",
54
- args: [file, `--customizenv=${JSON.stringify(envUsed)}`],
55
- tools: ["*"]
56
- }
57
- }
58
- });
59
- export const tools = [
60
- "--additional-mcp-config",
61
- config,
62
- "--allow-all-tools",
63
- "--resume",
64
- "--deny-tool",
65
- "write",
66
- "--deny-tool",
67
- "github-mcp-server"
68
- ];
1
+ import { dirname, join } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ export const name = "d5_mcp_review_builtin";
5
+ export const report = "report";
6
+ export const getPrompt = "default_review_requirements";
7
+ export const getHash = "getHash";
8
+
9
+ export const errorMessage = "error: call mcp " + name;
10
+ export const noMandatory = "dont't call under non-mandatory conditions";
11
+
12
+ export const file = join(dirname(fileURLToPath(import.meta.url)), "bin/copilot.js");
13
+
14
+ const { argv } = process;
15
+ const envArg = argv.find((arg) => arg.startsWith("--customizenv="));
16
+ let envJson = {};
17
+ if (envArg) envJson = JSON.parse(envArg.replace("--customizenv=", ""));
18
+ function toEnv(key, defaultValue = undefined) {
19
+ return envJson[key] || process.env[key] || defaultValue;
20
+ }
21
+ // 辣鸡: https://github.com/modelcontextprotocol/typescript-sdk/issues/259
22
+ export const envUsed = {
23
+ CI_SERVER_URL: toEnv("CI_SERVER_URL"),
24
+ CI_PROJECT_PATH: toEnv("CI_PROJECT_PATH"),
25
+ CI_PROJECT_ID: toEnv("CI_PROJECT_ID"),
26
+ CI_PROJECT_NAME: toEnv("CI_PROJECT_NAME"),
27
+
28
+ CI_COMMIT_SHA: toEnv("CI_COMMIT_SHA"),
29
+ CI_COMMIT_BEFORE_SHA: toEnv("CI_COMMIT_BEFORE_SHA"),
30
+
31
+ CI_COMMIT_AUTHOR: toEnv("CI_COMMIT_AUTHOR"),
32
+ CI_COMMIT_AUTHOR_EMAIL: toEnv("CI_COMMIT_AUTHOR_EMAIL"),
33
+
34
+ CI_MERGE_REQUEST_IID: toEnv("CI_MERGE_REQUEST_IID"),
35
+ CI_MERGE_REQUEST_TITLE: toEnv("CI_MERGE_REQUEST_TITLE"),
36
+ CI_MERGE_REQUEST_DESCRIPTION: toEnv("CI_MERGE_REQUEST_DESCRIPTION"),
37
+
38
+ JIRA_BASE_URL: toEnv("JIRA_BASE_URL", "http://jira.d5techs.com.cn"),
39
+
40
+ DINGTALK_WEBHOOK: toEnv("DINGTALK_WEBHOOK"),
41
+ GITLAB_TOKEN: toEnv("GITLAB_TOKEN"),
42
+ JIRA_PAT: toEnv("JIRA_PAT"),
43
+ JIRA_COOKIE: toEnv("JIRA_COOKIE"),
44
+
45
+ JIRA_USERNAME: toEnv("JIRA_USERNAME"),
46
+ JIRA_PASSWORD: toEnv("JIRA_PASSWORD")
47
+ };
48
+
49
+ const config = JSON.stringify({
50
+ mcpServers: {
51
+ [name]: {
52
+ type: "local",
53
+ command: "node",
54
+ args: [file, `--customizenv=${JSON.stringify(envUsed)}`],
55
+ tools: ["*"]
56
+ }
57
+ }
58
+ });
59
+ export const tools = [
60
+ "--additional-mcp-config",
61
+ config,
62
+ "--allow-all-tools",
63
+ "--resume",
64
+ "--deny-tool",
65
+ "write",
66
+ "--deny-tool",
67
+ "github-mcp-server"
68
+ ];
package/package.json CHANGED
@@ -3,8 +3,8 @@
3
3
  "type": "module",
4
4
  "license": "MIT",
5
5
  "author": "jasirou",
6
- "main": "./standalone.js",
7
- "version": "0.0.66",
6
+ "main": "./bin/d5cli",
7
+ "version": "0.0.80",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.24.3",
10
10
  "@types/node": "22.18.1",
@@ -14,16 +14,15 @@
14
14
  "zod": "^4.1.13"
15
15
  },
16
16
  "files": [
17
- "dist",
18
- "./copilot.config.js",
19
- "./standalone.js"
17
+ "bin",
18
+ "./copilot.config.js"
20
19
  ],
21
20
  "bin": {
22
- "d5cli": "standalone.js"
21
+ "d5cli": "bin/d5cli"
23
22
  },
24
23
  "scripts": {
25
24
  "build:copilot": "rolldown -c packages/copilot/rolldown.config.ts",
26
- "environment": "node ./scripts.js",
27
- "release": "node ./scripts.js publish"
25
+ "setup": "node ./setup.js",
26
+ "release": "node ./setup.js publish"
28
27
  }
29
28
  }