@d5render/cli 0.1.6 → 0.1.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.
- package/README.md +0 -4
- package/bin/copilot.js +3165 -2832
- package/bin/d5cli +64 -102
- package/package.json +3 -3
- package/CHANGELOG.md +0 -7
- package/bin/CHANGELOG.md +0 -2
package/bin/d5cli
CHANGED
|
@@ -6,12 +6,12 @@ import { argv, env, exit, platform } from "node:process";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
|
|
8
8
|
//#region package.json
|
|
9
|
-
var name = "@d5render/cli";
|
|
10
|
-
var version = "0.1.
|
|
9
|
+
var name$1 = "@d5render/cli";
|
|
10
|
+
var version = "0.1.12";
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region copilot/server/config.ts
|
|
14
|
-
const name
|
|
14
|
+
const name = "d5_mcp_review_builtin";
|
|
15
15
|
const report = "report";
|
|
16
16
|
const getHash = "getHash";
|
|
17
17
|
const file = "./copilot.js";
|
|
@@ -37,7 +37,7 @@ const envUsed = {
|
|
|
37
37
|
};
|
|
38
38
|
const tools = [
|
|
39
39
|
"--additional-mcp-config",
|
|
40
|
-
JSON.stringify({ mcpServers: { [name
|
|
40
|
+
JSON.stringify({ mcpServers: { [name]: {
|
|
41
41
|
type: "local",
|
|
42
42
|
command: "node",
|
|
43
43
|
args: [serveFile, `--customizenv=${JSON.stringify(envUsed)}`],
|
|
@@ -59,6 +59,54 @@ function buildEnv() {
|
|
|
59
59
|
return envJson$1;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region copilot/bin/install.ts
|
|
64
|
+
function install() {
|
|
65
|
+
if (!env.CI) return;
|
|
66
|
+
console.log("install copilot...");
|
|
67
|
+
let success = false;
|
|
68
|
+
let local = "";
|
|
69
|
+
try {
|
|
70
|
+
local = execSync("npm list @github/copilot -g --depth=0 --json").toString();
|
|
71
|
+
} catch {
|
|
72
|
+
local = "{}";
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const localInfo = JSON.parse(local);
|
|
76
|
+
const localVersion = localInfo.dependencies ? localInfo.dependencies?.["@github/copilot"]?.version : void 0;
|
|
77
|
+
if (!localVersion) {
|
|
78
|
+
installCopilot();
|
|
79
|
+
success = true;
|
|
80
|
+
console.log("install copilot success");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (localVersion !== execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com").toString().trim()) {
|
|
84
|
+
execSync("npm uninstall -g @github/copilot --force");
|
|
85
|
+
installCopilot();
|
|
86
|
+
success = true;
|
|
87
|
+
console.log("update copilot success");
|
|
88
|
+
} else {
|
|
89
|
+
success = true;
|
|
90
|
+
console.log("copilot exists and is up-to-date");
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error(error);
|
|
94
|
+
}
|
|
95
|
+
if (!success) try {
|
|
96
|
+
console.warn("try to reinstall copilot...");
|
|
97
|
+
installCopilot();
|
|
98
|
+
success = true;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error);
|
|
101
|
+
}
|
|
102
|
+
if (success) return;
|
|
103
|
+
console.warn("try to reinstall copilot...");
|
|
104
|
+
installCopilot();
|
|
105
|
+
}
|
|
106
|
+
function installCopilot() {
|
|
107
|
+
execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", { stdio: "inherit" });
|
|
108
|
+
}
|
|
109
|
+
|
|
62
110
|
//#endregion
|
|
63
111
|
//#region packages/gitlab/url.ts
|
|
64
112
|
function buildHeaders() {
|
|
@@ -92,47 +140,12 @@ const commits = () => {
|
|
|
92
140
|
};
|
|
93
141
|
|
|
94
142
|
//#endregion
|
|
95
|
-
//#region
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const urls = envUsed.DINGTALK_WEBHOOK.split(",");
|
|
99
|
-
return Promise.all(urls.map((url) => fetch(url, {
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: { "Content-Type": "application/json" },
|
|
102
|
-
body: JSON.stringify({
|
|
103
|
-
msgtype: "markdown",
|
|
104
|
-
markdown: {
|
|
105
|
-
title,
|
|
106
|
-
text
|
|
107
|
-
},
|
|
108
|
-
at: {
|
|
109
|
-
atMobiles: ["17856104313"],
|
|
110
|
-
isAtAll: false
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
})));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region copilot/bin/deploy.ts
|
|
118
|
-
const root = () => {
|
|
119
|
-
const dir = env.HOME ?? env.HOMEPATH;
|
|
120
|
-
if (!dir) throw new Error("cannot find home directory");
|
|
121
|
-
return dir;
|
|
122
|
-
};
|
|
143
|
+
//#region copilot/bin/utils.ts
|
|
144
|
+
const root = env.HOME ?? env.HOMEPATH ?? env.LOCALAPPDATA;
|
|
145
|
+
if (!root) throw new Error("cannot find home directory");
|
|
123
146
|
const cwd = join(dirname(fileURLToPath(import.meta.url)), "../");
|
|
124
147
|
function deploy() {
|
|
125
|
-
|
|
126
|
-
const cl = join(cwd, "bin/CHANGELOG.md");
|
|
127
|
-
const clt = existsSync(cl) ? readFileSync(cl, "utf8") : "";
|
|
128
|
-
const clr = join(cwd, name.split("/").map(() => "..").join("/"), `${name.replaceAll("/", "-")}-notice`);
|
|
129
|
-
let need = !!clt;
|
|
130
|
-
if (existsSync(clr)) {
|
|
131
|
-
if (readFileSync(clr, "utf8") === version) need = false;
|
|
132
|
-
}
|
|
133
|
-
if (need && env.DINGTALK_WEBHOOK) send("NOTICE", `#### cli upgrade\n\n${clt}\n\n##### [HISTORY CHANGELOG](https://www.npmjs.com/package/${name}/v/${version}?activeTab=code)`).then(() => writeFileSync(clr, version)).catch(() => {});
|
|
134
|
-
}
|
|
135
|
-
const dir = join(root(), ".copilot/skills/codereview");
|
|
148
|
+
const dir = join(root, ".copilot/skills/codereview");
|
|
136
149
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
137
150
|
const skillRoot = join(cwd, ".skills/review");
|
|
138
151
|
const versiono = readFileSync(join(cwd, ".skills/review/version"), "utf8");
|
|
@@ -142,12 +155,9 @@ function deploy() {
|
|
|
142
155
|
const instructionsRoot = join(cwd, ".github/instructions");
|
|
143
156
|
readdirSync(instructionsRoot).forEach((instruction) => copyFileSync(join(instructionsRoot, instruction), join(dir, instruction)));
|
|
144
157
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
function canireview() {
|
|
149
|
-
const { CI_MERGE_REQUEST_IID, CI_COMMIT_SHA, CI_PROJECT_PATH } = envUsed;
|
|
150
|
-
const file$1 = join(root(), ".ci-ai-review", CI_PROJECT_PATH || "defaults");
|
|
158
|
+
function need() {
|
|
159
|
+
const { CI_MERGE_REQUEST_IID, CI_COMMIT_SHA, CI_PROJECT_PATH } = env;
|
|
160
|
+
const file$1 = join(root, ".ci-ai-review", CI_PROJECT_PATH || "defaults");
|
|
151
161
|
const dir = dirname(file$1);
|
|
152
162
|
if (CI_MERGE_REQUEST_IID) {
|
|
153
163
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
@@ -181,60 +191,12 @@ function canireview() {
|
|
|
181
191
|
return !yes;
|
|
182
192
|
}
|
|
183
193
|
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region copilot/bin/install.ts
|
|
186
|
-
function install() {
|
|
187
|
-
if (!env.CI) return;
|
|
188
|
-
console.log("install copilot...");
|
|
189
|
-
let success = false;
|
|
190
|
-
let local = "";
|
|
191
|
-
try {
|
|
192
|
-
local = execSync("npm list @github/copilot -g --depth=0 --json").toString();
|
|
193
|
-
} catch {
|
|
194
|
-
local = "{}";
|
|
195
|
-
}
|
|
196
|
-
try {
|
|
197
|
-
const localInfo = JSON.parse(local);
|
|
198
|
-
const localVersion = localInfo.dependencies ? localInfo.dependencies?.["@github/copilot"]?.version : void 0;
|
|
199
|
-
if (!localVersion) {
|
|
200
|
-
installCopilot();
|
|
201
|
-
success = true;
|
|
202
|
-
console.log("install copilot success");
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
if (localVersion !== execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com").toString().trim()) {
|
|
206
|
-
execSync("npm uninstall -g @github/copilot --force");
|
|
207
|
-
installCopilot();
|
|
208
|
-
success = true;
|
|
209
|
-
console.log("update copilot success");
|
|
210
|
-
} else {
|
|
211
|
-
success = true;
|
|
212
|
-
console.log("copilot exists and is up-to-date");
|
|
213
|
-
}
|
|
214
|
-
} catch (error) {
|
|
215
|
-
console.error(error);
|
|
216
|
-
}
|
|
217
|
-
if (!success) try {
|
|
218
|
-
console.warn("try to reinstall copilot...");
|
|
219
|
-
installCopilot();
|
|
220
|
-
success = true;
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error(error);
|
|
223
|
-
}
|
|
224
|
-
if (success) return;
|
|
225
|
-
console.warn("try to reinstall copilot...");
|
|
226
|
-
installCopilot();
|
|
227
|
-
}
|
|
228
|
-
function installCopilot() {
|
|
229
|
-
execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", { stdio: "inherit" });
|
|
230
|
-
}
|
|
231
|
-
|
|
232
194
|
//#endregion
|
|
233
195
|
//#region copilot/bin/index.ts
|
|
234
|
-
const prompt = `call the mcp tool '${name
|
|
235
|
-
Then, use chinese as default language to organize the report into JSON format and call the mcp tool '${name
|
|
196
|
+
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.
|
|
197
|
+
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 "中文".`;
|
|
236
198
|
deploy();
|
|
237
|
-
if (
|
|
199
|
+
if (need()) {
|
|
238
200
|
install();
|
|
239
201
|
const copilot = spawn("node", [
|
|
240
202
|
findCopilopt(),
|
|
@@ -250,7 +212,7 @@ if (canireview()) {
|
|
|
250
212
|
copilot.stdout.on("data", (data) => console.log(data.toString()));
|
|
251
213
|
copilot.stderr.on("data", (data) => console.error(data.toString()));
|
|
252
214
|
copilot.on("close", (code) => exit(code));
|
|
253
|
-
}
|
|
215
|
+
} else console.log("重复提交,进程跳过");
|
|
254
216
|
function findCopilopt() {
|
|
255
217
|
let copilot = execSync("npm list @github/copilot -g -p").toString().trim();
|
|
256
218
|
if (!copilot) try {
|
|
@@ -266,7 +228,7 @@ function findCopilopt() {
|
|
|
266
228
|
if (!binPath) throw new Error("non copilot executable found");
|
|
267
229
|
const copilotVersion = copilotPackage.version || "unknown";
|
|
268
230
|
const copilotPath = join(copilot, binPath);
|
|
269
|
-
console.log(`${name} server:
|
|
231
|
+
console.log(`${name$1} server:
|
|
270
232
|
version: ${version}
|
|
271
233
|
path: ${serveFile}
|
|
272
234
|
copilot:
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "jasirou",
|
|
6
6
|
"main": "./bin/d5cli",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.12",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
10
10
|
"@types/node": "^25.0.3",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
".github/instructions/review.instructions.md",
|
|
20
20
|
".github/instructions/severity.instructions.md",
|
|
21
21
|
".skills/review",
|
|
22
|
-
"bin",
|
|
23
|
-
"
|
|
22
|
+
"bin/copilot.js",
|
|
23
|
+
"bin/d5cli"
|
|
24
24
|
],
|
|
25
25
|
"bin": {
|
|
26
26
|
"d5cli": "bin/d5cli"
|
package/CHANGELOG.md
DELETED
package/bin/CHANGELOG.md
DELETED