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.
Files changed (45) hide show
  1. package/README.md +276 -2
  2. package/bin/gx-stdio-mcp.js +145 -0
  3. package/bin/gx.js +99 -0
  4. package/contracts/README.md +40 -0
  5. package/contracts/alignment.schema.json +99 -0
  6. package/contracts/code-chunk.schema.json +28 -0
  7. package/contracts/evidence.schema.json +108 -0
  8. package/contracts/examples/alignment.example.json +26 -0
  9. package/contracts/examples/code-chunk.example.json +20 -0
  10. package/contracts/examples/evidence.add-field.json +49 -0
  11. package/contracts/examples/evidence.verify-manifest.json +52 -0
  12. package/contracts/examples/ext-method.example.json +14 -0
  13. package/contracts/examples/manifest.example.json +13 -0
  14. package/contracts/examples/unknown.extension-coverage.json +29 -0
  15. package/contracts/ext-method.schema.json +57 -0
  16. package/contracts/manifest.schema.json +27 -0
  17. package/contracts/unknown.schema.json +119 -0
  18. package/eval/README.md +52 -0
  19. package/eval/code-search-eval.json +216 -0
  20. package/package.json +38 -4
  21. package/src/adapters/cli/args.js +94 -0
  22. package/src/adapters/cli/output.js +66 -0
  23. package/src/adapters/platform/mcpClient.js +202 -0
  24. package/src/application/applyWorkflow.js +138 -0
  25. package/src/application/auditCommand.js +130 -0
  26. package/src/application/auditWorkflow.js +41 -0
  27. package/src/application/chunksCommand.js +87 -0
  28. package/src/application/errors.js +27 -0
  29. package/src/application/evalSearchCommand.js +148 -0
  30. package/src/application/initWorkflow.js +563 -0
  31. package/src/application/pullWorkflow.js +74 -0
  32. package/src/application/scanCommand.js +71 -0
  33. package/src/application/scanWorkflow.js +689 -0
  34. package/src/application/verifyWorkflow.js +142 -0
  35. package/src/domain/canonicalJson.js +72 -0
  36. package/src/domain/chunker.js +297 -0
  37. package/src/domain/digest.js +60 -0
  38. package/src/domain/java/JavaAstChunker.java +139 -0
  39. package/src/domain/java/JavaAstScanner.java +107 -0
  40. package/src/domain/javaAst.js +186 -0
  41. package/src/domain/jdk.js +66 -0
  42. package/src/domain/keepBlocks.js +122 -0
  43. package/src/store/backupStore.js +106 -0
  44. package/src/store/localStore.js +79 -0
  45. package/templates/platform-rules.md +29 -0
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gx.local/contracts/code-chunk.schema.json",
4
+ "title": "GX Code Chunk",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["chunkId", "projectId", "planId", "path", "startLine", "endLine", "granularity", "signature", "layer", "annotations", "frameworkTags", "contentHash", "embedding"],
8
+ "properties": {
9
+ "chunkId": { "type": "string", "pattern": "^ck_[a-f0-9]{32}$" },
10
+ "projectId": { "type": "string", "minLength": 1 },
11
+ "planId": { "type": "string", "minLength": 1 },
12
+ "modelId": { "type": ["string", "null"] },
13
+ "path": { "type": "string", "minLength": 1 },
14
+ "startLine": { "type": "integer", "minimum": 1 },
15
+ "endLine": { "type": "integer", "minimum": 1 },
16
+ "granularity": { "type": "string", "enum": ["file", "class", "method"] },
17
+ "signature": { "type": "string" },
18
+ "className": { "type": ["string", "null"] },
19
+ "methodName": { "type": ["string", "null"] },
20
+ "layer": { "type": "string" },
21
+ "annotations": { "type": "array", "items": { "type": "string" } },
22
+ "frameworkTags": { "type": "array", "items": { "type": "string" } },
23
+ "intent": { "type": ["string", "null"] },
24
+ "contentHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
25
+ "content": { "type": ["string", "null"] },
26
+ "embedding": { "type": ["array", "null"], "items": { "type": "number" } }
27
+ }
28
+ }
@@ -0,0 +1,108 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gx.local/contracts/evidence.schema.json",
4
+ "title": "GX Evidence",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "evidenceId",
9
+ "subject",
10
+ "producer",
11
+ "operation",
12
+ "parameters",
13
+ "normalizedResult",
14
+ "confidence",
15
+ "authority",
16
+ "locations",
17
+ "coverage",
18
+ "limitations",
19
+ "evidenceLinks",
20
+ "createdAt"
21
+ ],
22
+ "properties": {
23
+ "evidenceId": {
24
+ "type": "string",
25
+ "pattern": "^ev_[a-f0-9]{64}$"
26
+ },
27
+ "subject": {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": ["kind", "id", "name", "digest"],
31
+ "properties": {
32
+ "kind": {
33
+ "enum": ["plan", "model", "field", "relation", "index", "generated-file", "extension-file"]
34
+ },
35
+ "id": { "type": "string", "minLength": 1 },
36
+ "name": { "type": "string", "minLength": 1 },
37
+ "path": { "type": "string" },
38
+ "digest": {
39
+ "type": "object",
40
+ "additionalProperties": false,
41
+ "required": ["sha256"],
42
+ "properties": {
43
+ "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
44
+ }
45
+ }
46
+ }
47
+ },
48
+ "producer": {
49
+ "type": "object",
50
+ "additionalProperties": false,
51
+ "required": ["id", "name", "version"],
52
+ "properties": {
53
+ "id": { "type": "string", "minLength": 1 },
54
+ "name": { "type": "string", "minLength": 1 },
55
+ "version": { "type": "string", "minLength": 1 }
56
+ }
57
+ },
58
+ "operation": { "type": "string", "minLength": 1 },
59
+ "parameters": { "type": "object" },
60
+ "normalizedResult": { "type": "object" },
61
+ "confidence": { "enum": ["observed", "derived", "inferred"] },
62
+ "authority": {
63
+ "enum": ["platform-metadata", "generated-code", "extension-code", "cli-scan", "analyst-inference"]
64
+ },
65
+ "locations": {
66
+ "type": "array",
67
+ "items": {
68
+ "type": "object",
69
+ "additionalProperties": false,
70
+ "required": ["kind", "path"],
71
+ "properties": {
72
+ "kind": { "enum": ["metadata-path", "file"] },
73
+ "path": { "type": "string", "minLength": 1 },
74
+ "line": { "type": "integer", "minimum": 1 }
75
+ }
76
+ }
77
+ },
78
+ "coverage": {
79
+ "type": "object",
80
+ "additionalProperties": false,
81
+ "required": ["status", "facets"],
82
+ "properties": {
83
+ "status": { "enum": ["complete", "partial", "unknown"] },
84
+ "facets": {
85
+ "type": "object",
86
+ "additionalProperties": {
87
+ "type": "object",
88
+ "additionalProperties": false,
89
+ "required": ["available"],
90
+ "properties": {
91
+ "available": { "type": "boolean" },
92
+ "reason": { "type": "string" }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ },
98
+ "limitations": {
99
+ "type": "array",
100
+ "items": { "type": "string" }
101
+ },
102
+ "evidenceLinks": {
103
+ "type": "array",
104
+ "items": { "type": "string", "pattern": "^ev_[a-f0-9]{64}$" }
105
+ },
106
+ "createdAt": { "type": "string", "format": "date-time" }
107
+ }
108
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "planId": "plan-1",
3
+ "ok": true,
4
+ "extPointCount": 1,
5
+ "drift": {
6
+ "planId": "plan-1",
7
+ "manifestVersion": 2,
8
+ "currentVersion": 2,
9
+ "drifted": [],
10
+ "missing": [],
11
+ "extra": [],
12
+ "reason": null
13
+ },
14
+ "missingAnnotations": [],
15
+ "staleReferences": [],
16
+ "todos": [],
17
+ "coverage": {
18
+ "status": "partial",
19
+ "facets": {
20
+ "manifest": { "available": true, "reason": null },
21
+ "ext_points": { "available": true, "reason": null },
22
+ "file_hashes": { "available": true, "reason": null },
23
+ "compilation": { "available": false, "reason": "未执行编译" }
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "chunkId": "ck_0123456789abcdef0123456789abcdef",
3
+ "projectId": "plan-1",
4
+ "planId": "plan-1",
5
+ "modelId": null,
6
+ "path": "src/main/java/demo/OrderService.java",
7
+ "startLine": 5,
8
+ "endLine": 9,
9
+ "granularity": "method",
10
+ "signature": "OrderService.save()",
11
+ "className": "OrderService",
12
+ "methodName": "save",
13
+ "layer": "service",
14
+ "annotations": ["Transactional"],
15
+ "frameworkTags": ["java", "spring"],
16
+ "intent": "保存订单",
17
+ "contentHash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
+ "content": "public void save(Order order) {}",
19
+ "embedding": null
20
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "evidenceId": "ev_119633fc59ff39cb8a96b4680127f08fb97c8ea509a432bdd6761d3fcf0e2a52",
3
+ "subject": {
4
+ "kind": "field",
5
+ "id": "order.amount",
6
+ "name": "amount",
7
+ "path": "Plan/Order/amount",
8
+ "digest": {
9
+ "sha256": "0000000000000000000000000000000000000000000000000000000000000000"
10
+ }
11
+ },
12
+ "producer": {
13
+ "id": "gx-mcp",
14
+ "name": "gx-code-mcp",
15
+ "version": "1.0.0"
16
+ },
17
+ "operation": "add_entity_field",
18
+ "parameters": {
19
+ "planId": "plan-1",
20
+ "modelId": "order",
21
+ "fieldName": "approvalAmount"
22
+ },
23
+ "normalizedResult": {
24
+ "applied": true,
25
+ "fieldType": "Long"
26
+ },
27
+ "confidence": "observed",
28
+ "authority": "platform-metadata",
29
+ "locations": [
30
+ {
31
+ "kind": "metadata-path",
32
+ "path": "Plan/Order/approvalAmount"
33
+ }
34
+ ],
35
+ "coverage": {
36
+ "status": "complete",
37
+ "facets": {
38
+ "metadata": {
39
+ "available": true
40
+ },
41
+ "validation": {
42
+ "available": true
43
+ }
44
+ }
45
+ },
46
+ "limitations": [],
47
+ "evidenceLinks": [],
48
+ "createdAt": "2026-10-24T10:00:00Z"
49
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "evidenceId": "ev_c0605367905a6430118cdcc79529c0c8b5dde809d8a2c533d4cda7d2a9e48710",
3
+ "subject": {
4
+ "kind": "generated-file",
5
+ "id": "order",
6
+ "name": "Order.java",
7
+ "path": "src/main/java/gx/cn01/order/pojo/entity/Order.java",
8
+ "digest": {
9
+ "sha256": "0000000000000000000000000000000000000000000000000000000000000000"
10
+ }
11
+ },
12
+ "producer": {
13
+ "id": "gx-code-agent",
14
+ "name": "gx-code-agent",
15
+ "version": "0.1.0"
16
+ },
17
+ "operation": "verify_manifest",
18
+ "parameters": {
19
+ "manifestPath": ".gx/manifest.json"
20
+ },
21
+ "normalizedResult": {
22
+ "drifted": [],
23
+ "missing": [],
24
+ "extra": []
25
+ },
26
+ "confidence": "observed",
27
+ "authority": "cli-scan",
28
+ "locations": [
29
+ {
30
+ "kind": "file",
31
+ "path": "src/main/java/gx/cn01/order/pojo/entity/Order.java",
32
+ "line": 1
33
+ }
34
+ ],
35
+ "coverage": {
36
+ "status": "partial",
37
+ "facets": {
38
+ "generated_files": {
39
+ "available": true
40
+ },
41
+ "compilation": {
42
+ "available": false,
43
+ "reason": "未执行 mvn compile"
44
+ }
45
+ }
46
+ },
47
+ "limitations": [
48
+ "未执行编译,编译级引用关系未验证"
49
+ ],
50
+ "evidenceLinks": [],
51
+ "createdAt": "2026-10-24T10:05:00Z"
52
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "entity": "Order",
3
+ "intent": "金额大于 10 万时进入二级审批",
4
+ "triggers": [
5
+ "BEFORE_SAVE"
6
+ ],
7
+ "class": "OrderApprovalHook",
8
+ "method": "checkApproval",
9
+ "codeHash": "f40e1d51669e8cd0e5cb5912c17c9808985836f4ce6254f5db5048025537792b",
10
+ "fields": [
11
+ "amount",
12
+ "status"
13
+ ]
14
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "planId": "plan-1",
3
+ "metadataVersion": 47,
4
+ "generatedAt": "2026-10-24T10:00:00Z",
5
+ "files": [
6
+ {
7
+ "path": "src/main/java/gx/cn01/order/pojo/entity/Order.java",
8
+ "sha256": "0000000000000000000000000000000000000000000000000000000000000000",
9
+ "generated": true
10
+ }
11
+ ],
12
+ "manifestHash": "c4219e4e668a9f5e40201bfcf787f44dad71f99f5c737c2da6093433a78947aa"
13
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "unknownId": "unk_addbb8e48aba64fd5cbc21d77822d37362e2b237e4edc349a542d3e953ad69e1",
3
+ "revision": 1,
4
+ "question": "Order 扩展层是否仍引用已删除字段 amount?",
5
+ "domain": "metadata-drift",
6
+ "status": "open",
7
+ "severity": "high",
8
+ "scope": {
9
+ "planId": "plan-1",
10
+ "modelId": "order",
11
+ "fieldId": "amount"
12
+ },
13
+ "requiredConfidence": "observed",
14
+ "requiredAuthority": "cli-scan",
15
+ "supportingEvidenceIds": [
16
+ "ev_c0605367905a6430118cdcc79529c0c8b5dde809d8a2c533d4cda7d2a9e48710"
17
+ ],
18
+ "contradictingEvidenceIds": [],
19
+ "recommendedProbes": [
20
+ {
21
+ "operation": "gx scan",
22
+ "rationale": "重新扫描扩展层引用"
23
+ }
24
+ ],
25
+ "resolution": null,
26
+ "mutationEvidenceIds": [
27
+ "ev_c0605367905a6430118cdcc79529c0c8b5dde809d8a2c533d4cda7d2a9e48710"
28
+ ]
29
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gx.local/contracts/ext-method.schema.json",
4
+ "title": "GX ExtMethod Declaration",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "entity",
9
+ "intent",
10
+ "triggers",
11
+ "class",
12
+ "method",
13
+ "codeHash"
14
+ ],
15
+ "properties": {
16
+ "entity": {
17
+ "type": "string",
18
+ "minLength": 1
19
+ },
20
+ "intent": {
21
+ "type": "string",
22
+ "minLength": 1
23
+ },
24
+ "triggers": {
25
+ "type": "array",
26
+ "items": {
27
+ "type": "string",
28
+ "minLength": 1
29
+ }
30
+ },
31
+ "class": {
32
+ "type": "string",
33
+ "minLength": 1
34
+ },
35
+ "method": {
36
+ "type": "string",
37
+ "minLength": 1
38
+ },
39
+ "codeHash": {
40
+ "type": "string",
41
+ "pattern": "^[a-f0-9]{64}$"
42
+ },
43
+ "fields": {
44
+ "type": "array",
45
+ "items": {
46
+ "type": "string",
47
+ "minLength": 1
48
+ }
49
+ },
50
+ "file": {
51
+ "type": [
52
+ "string",
53
+ "null"
54
+ ]
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gx.local/contracts/manifest.schema.json",
4
+ "title": "GX Generation Manifest",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["planId", "metadataVersion", "generatedAt", "files", "manifestHash"],
8
+ "properties": {
9
+ "planId": { "type": "string", "minLength": 1 },
10
+ "metadataVersion": { "type": "integer", "minimum": 1 },
11
+ "generatedAt": { "type": "string", "format": "date-time" },
12
+ "files": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "required": ["path", "sha256", "generated"],
18
+ "properties": {
19
+ "path": { "type": "string", "minLength": 1 },
20
+ "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
21
+ "generated": { "type": "boolean" }
22
+ }
23
+ }
24
+ },
25
+ "manifestHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
26
+ }
27
+ }
@@ -0,0 +1,119 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://gx.local/contracts/unknown.schema.json",
4
+ "title": "GX Residual Unknown",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "unknownId",
9
+ "revision",
10
+ "question",
11
+ "domain",
12
+ "status",
13
+ "severity",
14
+ "scope",
15
+ "requiredConfidence",
16
+ "requiredAuthority",
17
+ "supportingEvidenceIds",
18
+ "contradictingEvidenceIds",
19
+ "recommendedProbes",
20
+ "resolution",
21
+ "mutationEvidenceIds"
22
+ ],
23
+ "properties": {
24
+ "unknownId": {
25
+ "type": "string",
26
+ "pattern": "^unk_[a-f0-9]{64}$"
27
+ },
28
+ "revision": { "type": "integer", "minimum": 1 },
29
+ "question": { "type": "string", "minLength": 1 },
30
+ "domain": {
31
+ "enum": ["metadata-drift", "extension-coverage", "generated-drift", "migration"]
32
+ },
33
+ "status": {
34
+ "enum": ["open", "investigating", "blocked", "contradicted", "resolved"]
35
+ },
36
+ "severity": { "enum": ["low", "medium", "high", "critical"] },
37
+ "scope": {
38
+ "type": "object",
39
+ "additionalProperties": false,
40
+ "required": ["planId"],
41
+ "properties": {
42
+ "planId": { "type": "string", "minLength": 1 },
43
+ "modelId": { "type": "string" },
44
+ "fieldId": { "type": "string" },
45
+ "filePath": { "type": "string" }
46
+ }
47
+ },
48
+ "requiredConfidence": { "enum": ["observed", "derived", "inferred"] },
49
+ "requiredAuthority": {
50
+ "enum": ["platform-metadata", "generated-code", "extension-code", "cli-scan", "analyst-inference"]
51
+ },
52
+ "supportingEvidenceIds": {
53
+ "type": "array",
54
+ "items": { "type": "string", "pattern": "^ev_[a-f0-9]{64}$" }
55
+ },
56
+ "contradictingEvidenceIds": {
57
+ "type": "array",
58
+ "items": { "type": "string", "pattern": "^ev_[a-f0-9]{64}$" }
59
+ },
60
+ "recommendedProbes": {
61
+ "type": "array",
62
+ "items": {
63
+ "type": "object",
64
+ "additionalProperties": false,
65
+ "required": ["operation", "rationale"],
66
+ "properties": {
67
+ "operation": { "type": "string", "minLength": 1 },
68
+ "rationale": { "type": "string", "minLength": 1 }
69
+ }
70
+ }
71
+ },
72
+ "resolution": {
73
+ "oneOf": [
74
+ { "type": "null" },
75
+ {
76
+ "type": "object",
77
+ "additionalProperties": false,
78
+ "required": ["disposition", "rationale", "evidenceIds"],
79
+ "properties": {
80
+ "disposition": { "enum": ["verified", "withdrawn", "out-of-scope"] },
81
+ "rationale": { "type": "string", "minLength": 1 },
82
+ "evidenceIds": {
83
+ "type": "array",
84
+ "items": { "type": "string", "pattern": "^ev_[a-f0-9]{64}$" }
85
+ }
86
+ }
87
+ }
88
+ ]
89
+ },
90
+ "mutationEvidenceIds": {
91
+ "type": "array",
92
+ "items": { "type": "string", "pattern": "^ev_[a-f0-9]{64}$" }
93
+ }
94
+ },
95
+ "allOf": [
96
+ {
97
+ "if": {
98
+ "properties": { "status": { "const": "resolved" } },
99
+ "required": ["status"]
100
+ },
101
+ "then": {
102
+ "properties": {
103
+ "resolution": { "type": "object" }
104
+ }
105
+ }
106
+ },
107
+ {
108
+ "if": {
109
+ "properties": { "status": { "const": "contradicted" } },
110
+ "required": ["status"]
111
+ },
112
+ "then": {
113
+ "properties": {
114
+ "contradictingEvidenceIds": { "type": "array", "minItems": 1 }
115
+ }
116
+ }
117
+ }
118
+ ]
119
+ }
package/eval/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # 代码检索评测集
2
+
3
+ `code-search-eval.json` 用于评估平台 `search_code` 的混合检索质量。
4
+
5
+ ## 用法
6
+
7
+ ```bash
8
+ GX_API_TOKEN=gxmcp_xxx gx eval-search \
9
+ --plan <planId> \
10
+ --dataset eval/code-search-eval.json \
11
+ --limit 5 \
12
+ --out .gx/eval-search.json
13
+ ```
14
+
15
+ 指标:
16
+
17
+ - `HitRate@K`:前 K 条命中期望文件/签名的比例;
18
+ - `MRR`:首个正确命中的平均倒数排名;
19
+ - `avgLatencyMs`:平均检索延迟;
20
+ - `embeddingAvailableCount`:语义检索实际启用的 query 数。
21
+
22
+ ## 数据集格式
23
+
24
+ ```json
25
+ {
26
+ "planId": "1187804490695311360",
27
+ "cases": [
28
+ {
29
+ "id": "c01",
30
+ "query": "故障",
31
+ "tags": ["keyword"],
32
+ "expectedAny": [
33
+ { "path": "defaultService/src/main/java/.../WkMalfunctionController.java" },
34
+ { "pathSuffix": "wkProjectTreeLeftMenu.vue" },
35
+ { "signature": "WkMalfunctionHook.fillDefaultName()" }
36
+ ]
37
+ }
38
+ ]
39
+ }
40
+ ```
41
+
42
+ `expectedAny` 任一项命中即算正确。
43
+
44
+ ## wk1 基线(2026-10-25)
45
+
46
+ - 14 条 query
47
+ - HitRate@5:`1.0`
48
+ - MRR:`0.9524`
49
+ - 平均延迟:`835ms`
50
+ - 语义检索可用:`14/14`
51
+
52
+ 其他项目建议复制本文件并按自身模块补充 query 与期望。