gx-code-agent 0.0.0-stage → 0.1.1
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 +276 -2
- package/bin/gx-stdio-mcp.js +145 -0
- package/bin/gx.js +99 -0
- package/contracts/README.md +40 -0
- package/contracts/alignment.schema.json +99 -0
- package/contracts/code-chunk.schema.json +28 -0
- package/contracts/evidence.schema.json +108 -0
- package/contracts/examples/alignment.example.json +26 -0
- package/contracts/examples/code-chunk.example.json +20 -0
- package/contracts/examples/evidence.add-field.json +49 -0
- package/contracts/examples/evidence.verify-manifest.json +52 -0
- package/contracts/examples/ext-method.example.json +14 -0
- package/contracts/examples/manifest.example.json +13 -0
- package/contracts/examples/unknown.extension-coverage.json +29 -0
- package/contracts/ext-method.schema.json +57 -0
- package/contracts/manifest.schema.json +27 -0
- package/contracts/unknown.schema.json +119 -0
- package/eval/README.md +52 -0
- package/eval/code-search-eval.json +216 -0
- package/package.json +38 -4
- package/src/adapters/cli/args.js +94 -0
- package/src/adapters/cli/output.js +66 -0
- package/src/adapters/platform/mcpClient.js +202 -0
- package/src/application/applyWorkflow.js +138 -0
- package/src/application/auditCommand.js +130 -0
- package/src/application/auditWorkflow.js +41 -0
- package/src/application/chunksCommand.js +87 -0
- package/src/application/errors.js +27 -0
- package/src/application/evalSearchCommand.js +148 -0
- package/src/application/initWorkflow.js +563 -0
- package/src/application/pullWorkflow.js +74 -0
- package/src/application/scanCommand.js +71 -0
- package/src/application/scanWorkflow.js +689 -0
- package/src/application/verifyWorkflow.js +142 -0
- package/src/domain/canonicalJson.js +72 -0
- package/src/domain/chunker.js +297 -0
- package/src/domain/digest.js +60 -0
- package/src/domain/java/JavaAstChunker.java +139 -0
- package/src/domain/java/JavaAstScanner.java +107 -0
- package/src/domain/javaAst.js +186 -0
- package/src/domain/jdk.js +66 -0
- package/src/domain/keepBlocks.js +122 -0
- package/src/store/backupStore.js +106 -0
- package/src/store/localStore.js +79 -0
- package/templates/platform-rules.md +29 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { McpHttpClient } from "../adapters/platform/mcpClient.js";
|
|
4
|
+
import { readJson, writeJson } from "../store/localStore.js";
|
|
5
|
+
import { scanWorkflow } from "./scanWorkflow.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 执行 gx scan,并在配置允许时上报 record_ext_points。
|
|
9
|
+
*
|
|
10
|
+
* @param {Record<string, unknown>} args
|
|
11
|
+
* @param {{ stdout: NodeJS.WriteStream, stderr: NodeJS.WriteStream }} io
|
|
12
|
+
* @returns {Promise<Record<string, unknown>>}
|
|
13
|
+
*/
|
|
14
|
+
export async function runScan(args, io = { stdout: process.stdout, stderr: process.stderr }) {
|
|
15
|
+
const dir = path.resolve(String(args.dir || process.cwd()));
|
|
16
|
+
const sourceDirs = typeof args["source-dir"] === "string"
|
|
17
|
+
? args["source-dir"].split(",").map((item) => item.trim()).filter(Boolean)
|
|
18
|
+
: undefined;
|
|
19
|
+
const result = scanWorkflow({ dir, sourceDirs, compile: Boolean(args.compile), classpath: typeof args.classpath === "string" ? args.classpath : undefined });
|
|
20
|
+
const config = readJson(path.join(dir, ".gx", "config.json"), {});
|
|
21
|
+
const planId = String(args.plan || config.planId || "");
|
|
22
|
+
const url = String(args.url || config.mcpUrl || "http://127.0.0.1:4013/mcp");
|
|
23
|
+
const token = String(args.token || process.env.GX_API_TOKEN || "");
|
|
24
|
+
const explicitReport = Boolean(args.report);
|
|
25
|
+
const autoReport = !args["no-report"] && Boolean(planId && token);
|
|
26
|
+
const shouldReport = explicitReport || autoReport;
|
|
27
|
+
|
|
28
|
+
if (explicitReport && (!planId || !token)) {
|
|
29
|
+
throw new Error("gx scan --report 需要 planId(--plan 或 .gx/config.json)与 API Token");
|
|
30
|
+
}
|
|
31
|
+
if (!shouldReport) {
|
|
32
|
+
result.report = {
|
|
33
|
+
status: "skipped",
|
|
34
|
+
reason: !planId ? "未配置 planId" : !token ? "缺少 API Token" : "使用 --no-report 跳过"
|
|
35
|
+
};
|
|
36
|
+
io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const client = new McpHttpClient({ url, token });
|
|
41
|
+
try {
|
|
42
|
+
const report = await client.callTool("record_ext_points", {
|
|
43
|
+
planId,
|
|
44
|
+
methods: result.extPoints,
|
|
45
|
+
replace: true
|
|
46
|
+
});
|
|
47
|
+
result.report = { status: "reported", planId, ...report };
|
|
48
|
+
writeJson(path.join(dir, ".gx", "ext-points.json"), {
|
|
49
|
+
planId,
|
|
50
|
+
reportedAt: new Date().toISOString(),
|
|
51
|
+
extPoints: result.extPoints,
|
|
52
|
+
unannotatedMethods: result.unannotatedMethods,
|
|
53
|
+
report
|
|
54
|
+
});
|
|
55
|
+
io.stdout.write(`已上报 ${report.accepted?.length ?? 0} 个扩展点,拒绝 ${report.rejected?.length ?? 0} 个\n`);
|
|
56
|
+
for (const rejected of report.rejected ?? []) {
|
|
57
|
+
io.stderr.write(`[warn] ${rejected.method?.class}#${rejected.method?.method}: ${rejected.reason}\n`);
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
result.report = { status: "failed", reason: error instanceof Error ? error.message : String(error) };
|
|
61
|
+
if (explicitReport) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
io.stderr.write(`[warn] record_ext_points 上报失败:${result.report.reason}\n`);
|
|
65
|
+
} finally {
|
|
66
|
+
await client.close();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
70
|
+
return result;
|
|
71
|
+
}
|