@hupan56/wlkj 3.3.15 → 3.3.17
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/package.json +1 -1
- package/templates/qoder/scripts/capability/registry_mcp.py +4 -10
- package/templates/qoder/scripts/capability/smoke_test_report.json.new +94 -0
- package/templates/qoder/scripts/deployment/setup/install_qoderwork.py +4 -1
- package/templates/qoder/scripts/domain/integration/return_to_platform.py +2 -4
- package/templates/qoder/scripts/domain/integration/spec_upload.py +4 -4
- package/templates/qoder/scripts/domain/kg/extract/asset/__init__.py +10 -0
- package/templates/qoder/scripts/domain/kg/extract/asset/asset_tree.py +57 -0
- package/templates/qoder/scripts/domain/kg/extract/asset/discussion_importer.py +62 -0
- package/templates/qoder/scripts/domain/kg/extract/asset/prd_importer.py +146 -0
- package/templates/qoder/scripts/domain/kg/extract/asset/prototype_importer.py +64 -0
- package/templates/qoder/scripts/domain/kg/extract/asset/returns_importer.py +52 -0
- package/templates/qoder/scripts/domain/kg/extract/build_goal3.py +104 -0
- package/templates/qoder/scripts/domain/kg/extract/build_goal4.py +55 -0
- package/templates/qoder/scripts/domain/kg/extract/build_goal5.py +95 -0
- package/templates/qoder/scripts/domain/kg/extract/db/__init__.py +8 -0
- package/templates/qoder/scripts/domain/kg/extract/db/data_profile.py +22 -0
- package/templates/qoder/scripts/domain/kg/extract/db/fk_extractor.py +55 -0
- package/templates/qoder/scripts/domain/kg/extract/db/schema_extractor.py +90 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/__init__.py +9 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/community_summarizer.py +206 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/embed_builder.py +132 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/naming_matcher.py +80 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/promote.py +59 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/recompute.py +93 -0
- package/templates/qoder/scripts/domain/kg/extract/inference/weak_link.py +421 -0
- package/templates/qoder/scripts/domain/kg/extract/mybatis/__init__.py +9 -0
- package/templates/qoder/scripts/domain/kg/extract/mybatis/all.py +79 -0
- package/templates/qoder/scripts/domain/kg/extract/mybatis/mapper_parser.py +99 -0
- package/templates/qoder/scripts/domain/kg/extract/mybatis/relation_builder.py +69 -0
- package/templates/qoder/scripts/domain/kg/extract/mybatis/sql_extractor.py +78 -0
- package/templates/qoder/scripts/domain/kg/extract/prd/__init__.py +8 -0
- package/templates/qoder/scripts/domain/kg/extract/prd/prd_chunk_embed.py +105 -0
- package/templates/qoder/scripts/domain/kg/extract/prd/prd_llm_extract.py +153 -0
- package/templates/qoder/scripts/domain/kg/extract/prd/req_anchor.py +120 -0
- package/templates/qoder/scripts/domain/kg/switch_project.py +18 -5
- package/templates/qoder/scripts/domain/kg/sync_repowiki.py +109 -0
- package/templates/qoder/scripts/domain/task/wlkj_panel.py +14 -169
- package/templates/qoder/scripts/engine/poller.py +219 -0
- package/templates/qoder/scripts/orchestration/wlkj.py +0 -106
- package/templates/qoder/settings.json +0 -8
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@ _KNOWLEDGE_SERVER_ALIASES = ["wlinkj-knowledge", "qoder-knowledge-graph"]
|
|
|
51
51
|
SERVERS: dict[str, dict] = {
|
|
52
52
|
"qoder-knowledge-graph": {
|
|
53
53
|
"kind": "http",
|
|
54
|
-
"url":
|
|
54
|
+
"url": "http://127.0.0.1:10010/mcp",
|
|
55
55
|
"note": "知识图谱。已改为 http 模式,指向资产平台 MCP 服务(POST /mcp JSON-RPC)",
|
|
56
56
|
},
|
|
57
57
|
"qoder-zentao": {
|
|
@@ -73,22 +73,16 @@ SERVERS: dict[str, dict] = {
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
def _mcp_config_path() -> Path:
|
|
76
|
-
"""定位 mcp_config.json(在仓库根/宿主下)。
|
|
77
|
-
|
|
78
|
-
★ switch_project.py 实际写入位置是 {repo}/.qoder/mcp_config.json(云模式连云 bind 后),
|
|
79
|
-
必须优先查这里——否则读不到 token,transport 用空 token 调云 MCP 鉴权失败(历史 bug:
|
|
80
|
-
引擎 search 全返回"MCP返回非JSON"+递归降级套娃)。老形态 repo/mcp_config.json 兼容。
|
|
81
|
-
"""
|
|
76
|
+
"""定位 mcp_config.json(在仓库根/宿主下)。"""
|
|
82
77
|
repo = _get_repo_root()
|
|
83
78
|
# registry_mcp.py 在 .../scripts/capability/, mcp_config.json 在宿主根(.qoder)。
|
|
84
79
|
for cand in [
|
|
85
|
-
repo / "
|
|
86
|
-
repo / "mcp_config.json", # 老形态:仓库根
|
|
80
|
+
repo / "mcp_config.json",
|
|
87
81
|
repo / "registry_mcp_config.json",
|
|
88
82
|
]:
|
|
89
83
|
if cand.is_file():
|
|
90
84
|
return cand
|
|
91
|
-
return repo / "
|
|
85
|
+
return repo / "mcp_config.json"
|
|
92
86
|
|
|
93
87
|
|
|
94
88
|
def _load_servers() -> dict[str, dict]:
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"timestamp": "2026-06-26 21:25:55",
|
|
3
|
+
"servers": {
|
|
4
|
+
"qoder-knowledge-graph": {
|
|
5
|
+
"available": true,
|
|
6
|
+
"tools_indexed": 17,
|
|
7
|
+
"latency_ms": 437.0,
|
|
8
|
+
"sample_tools": [
|
|
9
|
+
"search_code",
|
|
10
|
+
"search_api",
|
|
11
|
+
"search_prd",
|
|
12
|
+
"get_impact",
|
|
13
|
+
"context_360"
|
|
14
|
+
],
|
|
15
|
+
"spawn_pid": 38616,
|
|
16
|
+
"status": "PASS"
|
|
17
|
+
},
|
|
18
|
+
"qoder-zentao": {
|
|
19
|
+
"available": true,
|
|
20
|
+
"tools_indexed": 66,
|
|
21
|
+
"latency_ms": 3657.0,
|
|
22
|
+
"sample_tools": [
|
|
23
|
+
"check_zentao_status",
|
|
24
|
+
"get_zentao_url",
|
|
25
|
+
"list_products",
|
|
26
|
+
"get_product",
|
|
27
|
+
"create_product"
|
|
28
|
+
],
|
|
29
|
+
"spawn_pid": 11224,
|
|
30
|
+
"status": "PASS"
|
|
31
|
+
},
|
|
32
|
+
"qoder-mysql": {
|
|
33
|
+
"available": true,
|
|
34
|
+
"tools_indexed": 6,
|
|
35
|
+
"latency_ms": 3484.0,
|
|
36
|
+
"sample_tools": [
|
|
37
|
+
"list_envs",
|
|
38
|
+
"query_schema",
|
|
39
|
+
"query_data",
|
|
40
|
+
"query_distinct",
|
|
41
|
+
"list_databases"
|
|
42
|
+
],
|
|
43
|
+
"spawn_pid": 37868,
|
|
44
|
+
"status": "PASS"
|
|
45
|
+
},
|
|
46
|
+
"lanhu": {
|
|
47
|
+
"available": true,
|
|
48
|
+
"tools_indexed": 13,
|
|
49
|
+
"latency_ms": 3156.0,
|
|
50
|
+
"sample_tools": [
|
|
51
|
+
"lanhu_resolve_invite_link",
|
|
52
|
+
"lanhu_list_product_documents",
|
|
53
|
+
"lanhu_get_pages",
|
|
54
|
+
"lanhu_get_ai_analyze_page_result",
|
|
55
|
+
"lanhu_get_designs"
|
|
56
|
+
],
|
|
57
|
+
"spawn_pid": 36836,
|
|
58
|
+
"status": "PASS"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"call_tool": {
|
|
62
|
+
"status": "PASS",
|
|
63
|
+
"latency_ms": 3953.0,
|
|
64
|
+
"text_preview": "Chinese: 保险 -> English: ins insurance vehlife/insurance\n\n[Carmg-H5] 12 files\n Carmg-H5/src/.../main/List.vue -> data/code/Carmg-H5/src/modules/icsAbnormalCenter/module/main/List.vue\n Carmg-H5/src/",
|
|
65
|
+
"is_error": false
|
|
66
|
+
},
|
|
67
|
+
"memory": {
|
|
68
|
+
"available": true,
|
|
69
|
+
"providers": [
|
|
70
|
+
{
|
|
71
|
+
"provider": "McpMemoryProvider",
|
|
72
|
+
"available": true,
|
|
73
|
+
"hit": true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"provider": "FileMemoryCap",
|
|
77
|
+
"available": true,
|
|
78
|
+
"hit": false
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"provider": "NoOpMemoryCap",
|
|
82
|
+
"available": false,
|
|
83
|
+
"hit": false
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"status": "PASS"
|
|
87
|
+
},
|
|
88
|
+
"summary": {
|
|
89
|
+
"all_pass": true,
|
|
90
|
+
"active_servers": 4,
|
|
91
|
+
"total_servers": 4,
|
|
92
|
+
"total_tools": 102
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -396,6 +396,9 @@ def find_python_with_core_deps():
|
|
|
396
396
|
def rewrite_mcp_json_for_launcher():
|
|
397
397
|
"""把 mcp.json 里所有 python MCP (kg/mysql/lanhu) 改成 launcher 模式。
|
|
398
398
|
|
|
399
|
+
★ kg 走云平台 SSE url(共识),不走 launcher——在 for srv 循环已配 SSE,
|
|
400
|
+
这里跳过 kg(不改 launcher),保住 SSE 配置。
|
|
401
|
+
|
|
399
402
|
旧 (写死路径): {"command": "E:\\...\\python.exe", "args": ["E:\\...\\server.py"]}
|
|
400
403
|
新 (launcher): {"command": "<py cmd>", "args": ["<home>/.qoderwork/mcp_launcher.py", "<name>"]}
|
|
401
404
|
|
|
@@ -438,7 +441,7 @@ def rewrite_mcp_json_for_launcher():
|
|
|
438
441
|
}
|
|
439
442
|
changed = False
|
|
440
443
|
for srv, sub in name_map.items():
|
|
441
|
-
# 共识:kg 走云平台(默认 10.89.7.120:10010/mcp,config platform_mcp.url 可覆盖)
|
|
444
|
+
# 共识:kg 走云平台(默认 http://10.89.7.120:10010/mcp,config platform_mcp.url 可覆盖)
|
|
442
445
|
if srv == "qoder-knowledge-graph":
|
|
443
446
|
_pm = "http://10.89.7.120:10010/mcp"
|
|
444
447
|
try:
|
|
@@ -20,7 +20,6 @@ integration.return_to_platform —— 引擎产出回流平台的统一通道。
|
|
|
20
20
|
"""
|
|
21
21
|
from __future__ import annotations
|
|
22
22
|
|
|
23
|
-
import os
|
|
24
23
|
from typing import Optional
|
|
25
24
|
|
|
26
25
|
|
|
@@ -35,7 +34,6 @@ def _load_mcp_config() -> dict:
|
|
|
35
34
|
except Exception:
|
|
36
35
|
repo = Path(__file__).resolve().parent.parent.parent.parent.parent
|
|
37
36
|
for cand in [
|
|
38
|
-
repo / ".qoder" / "mcp_config.json", # ★ switch_project 写这里,优先查(否则读不到 token → 回流误报"无 X-Engine-Token")
|
|
39
37
|
repo / "mcp_config.json",
|
|
40
38
|
]:
|
|
41
39
|
try:
|
|
@@ -123,7 +121,7 @@ def _via_http(payload: dict) -> tuple[bool, str]:
|
|
|
123
121
|
|
|
124
122
|
|
|
125
123
|
def _platform_base() -> str:
|
|
126
|
-
"""平台 base url
|
|
124
|
+
"""平台 base url(http://127.0.0.1:10010),从 mcp_config server url 推导。"""
|
|
127
125
|
from urllib.parse import urlparse
|
|
128
126
|
cfg = _load_mcp_config()
|
|
129
127
|
for srv in (cfg.get("mcpServers") or {}).values():
|
|
@@ -135,7 +133,7 @@ def _platform_base() -> str:
|
|
|
135
133
|
if ep:
|
|
136
134
|
p = urlparse(ep)
|
|
137
135
|
return "%s://%s" % (p.scheme, p.netloc)
|
|
138
|
-
return
|
|
136
|
+
return "http://127.0.0.1:10010"
|
|
139
137
|
|
|
140
138
|
|
|
141
139
|
def _engine_token() -> Optional[str]:
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
契约: wlinkj-workspace/docs/SPEC-MCP-CONTRACT.md v1(create/confirm/update/get_spec)
|
|
6
6
|
|
|
7
7
|
流程: 解析契约头 → 有platform_spec_id走update/无走create → confirm → 回写幂等锚
|
|
8
|
-
传输: POST /mcp direct JSON-RPC + X-MCP-Token
|
|
8
|
+
传输: POST /mcp direct JSON-RPC + X-MCP-Token(同 engine/poller.py:_mcp_call)
|
|
9
9
|
"""
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
import json, os, re, sys, urllib.request, urllib.error
|
|
@@ -24,8 +24,8 @@ def _load_mcp_config() -> dict:
|
|
|
24
24
|
repo = get_repo_root()
|
|
25
25
|
except Exception:
|
|
26
26
|
repo = Path(__file__).resolve().parent.parent.parent.parent.parent
|
|
27
|
-
for cand in [repo / "
|
|
28
|
-
repo / "mcp_config.json"]:
|
|
27
|
+
for cand in [repo / "mcp_config.json",
|
|
28
|
+
repo / ".qoder" / "mcp_config.json"]:
|
|
29
29
|
try:
|
|
30
30
|
if cand.is_file():
|
|
31
31
|
with open(cand, encoding="utf-8") as f:
|
|
@@ -48,7 +48,7 @@ def _resolve_endpoint() -> Tuple[str, str, str]:
|
|
|
48
48
|
u = srv.get("url", "")
|
|
49
49
|
if "/mcp" in u:
|
|
50
50
|
base = u.split("/mcp")[0]; break
|
|
51
|
-
base = (base or
|
|
51
|
+
base = (base or "http://127.0.0.1:10010").rstrip("/")
|
|
52
52
|
token = os.environ.get("WLKJ_MCP_TOKEN", "")
|
|
53
53
|
if not token:
|
|
54
54
|
for srv in (cfg.get("mcpServers") or {}).values():
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""资产中心 25 表吸收 (GOAL 4)。
|
|
3
|
+
|
|
4
|
+
子模块:
|
|
5
|
+
prd_importer prds + prd_versions → 业务知识 (调 LLM)
|
|
6
|
+
prototype_importer prototypes + annotations → 意图知识
|
|
7
|
+
discussion_importer discussions → 决策知识 (LLM)
|
|
8
|
+
asset_tree assets → 模块结构
|
|
9
|
+
returns_importer asset_returns → 实践知识
|
|
10
|
+
"""
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""资产树 → 模块结构知识。
|
|
3
|
+
|
|
4
|
+
assets 表 (飞书式文件树, 330节点) → MODULE 实体。
|
|
5
|
+
"01_PRD/02_设计/03_交付" 这种结构本身就是项目知识。
|
|
6
|
+
parent_id 递归 → 模块层级。
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
import os, sys
|
|
10
|
+
|
|
11
|
+
_THIS = os.path.dirname(os.path.abspath(__file__))
|
|
12
|
+
for _i in range(8):
|
|
13
|
+
_p = os.path.dirname(_THIS)
|
|
14
|
+
if os.path.isfile(os.path.join(_p, 'foundation', 'bootstrap.py')):
|
|
15
|
+
sys.path.insert(0, _p); break
|
|
16
|
+
_THIS = _p
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def import_asset_tree(project_id: str = None, logger=print):
|
|
20
|
+
"""assets 表 → MODULE 实体 + 层级边。"""
|
|
21
|
+
try:
|
|
22
|
+
from dotenv import load_dotenv
|
|
23
|
+
for p in ['wlinkj-workspace/backend/.env', '.env']:
|
|
24
|
+
if os.path.isfile(p): load_dotenv(p); break
|
|
25
|
+
except: pass
|
|
26
|
+
sys.path.insert(0, os.path.join(os.getcwd(), 'wlinkj-workspace', 'backend'))
|
|
27
|
+
from app.db import SessionLocal
|
|
28
|
+
from app.models import Asset
|
|
29
|
+
from domain.kg.extract.java import pg_upsert
|
|
30
|
+
|
|
31
|
+
db = SessionLocal()
|
|
32
|
+
q = db.query(Asset)
|
|
33
|
+
if project_id: q = q.filter(Asset.project_id == project_id)
|
|
34
|
+
assets = q.all()
|
|
35
|
+
logger(' [asset-tree] %d 个资产节点' % len(assets))
|
|
36
|
+
|
|
37
|
+
entities, edges = [], []
|
|
38
|
+
for a in assets:
|
|
39
|
+
repo_id = 'asset-%s' % (a.project_id or 'global')[:8]
|
|
40
|
+
entities.append({
|
|
41
|
+
'id': 'asset:%s' % a.id, 'repo_id': repo_id,
|
|
42
|
+
'type': 'MODULE' if a.is_folder else 'ASSET',
|
|
43
|
+
'canonical': a.name, 'cn': a.type or '',
|
|
44
|
+
'props': {'project_id': a.project_id, 'kind': 'folder' if a.is_folder else 'file',
|
|
45
|
+
'mime': a.mime_type, 'source': 'asset_center'},
|
|
46
|
+
})
|
|
47
|
+
# parent_id → 层级边
|
|
48
|
+
if a.parent_id:
|
|
49
|
+
edges.append({
|
|
50
|
+
'from_id': 'asset:%s' % a.id, 'to_id': 'asset:%s' % a.parent_id,
|
|
51
|
+
'edge_type': 'child_of', 'from_repo': repo_id, 'to_repo': repo_id,
|
|
52
|
+
'confidence': 1.0, 'source': 'explicit',
|
|
53
|
+
})
|
|
54
|
+
db.close()
|
|
55
|
+
|
|
56
|
+
upsert_r = pg_upsert.upsert_batch(entities, edges) if (entities or edges) else {'ok': False}
|
|
57
|
+
return {'assets': len(assets), 'entities': len(entities), 'edges': len(edges), 'upsert': upsert_r}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""讨论 → 决策知识。
|
|
3
|
+
|
|
4
|
+
discussion_messages → DECISION 实体 (LLM 抽取决策点)。
|
|
5
|
+
当前 0 数据, 管线先建好, 等团队用起来立刻生效。
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
import os, sys
|
|
9
|
+
|
|
10
|
+
_THIS = os.path.dirname(os.path.abspath(__file__))
|
|
11
|
+
for _i in range(8):
|
|
12
|
+
_p = os.path.dirname(_THIS)
|
|
13
|
+
if os.path.isfile(os.path.join(_p, 'foundation', 'bootstrap.py')):
|
|
14
|
+
sys.path.insert(0, _p); break
|
|
15
|
+
_THIS = _p
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def import_discussions(project_id: str = None, logger=print):
|
|
19
|
+
"""讨论 → KG。"""
|
|
20
|
+
try:
|
|
21
|
+
from dotenv import load_dotenv
|
|
22
|
+
for p in ['wlinkj-workspace/backend/.env', '.env']:
|
|
23
|
+
if os.path.isfile(p): load_dotenv(p); break
|
|
24
|
+
except: pass
|
|
25
|
+
sys.path.insert(0, os.path.join(os.getcwd(), 'wlinkj-workspace', 'backend'))
|
|
26
|
+
from app.db import SessionLocal
|
|
27
|
+
from app.models import Discussion, DiscussionMessage
|
|
28
|
+
from domain.kg.extract.java import pg_upsert
|
|
29
|
+
|
|
30
|
+
db = SessionLocal()
|
|
31
|
+
q = db.query(Discussion)
|
|
32
|
+
if project_id: q = q.filter(Discussion.project_id == project_id)
|
|
33
|
+
discussions = q.all()
|
|
34
|
+
logger(' [asset-disc] %d 个讨论' % len(discussions))
|
|
35
|
+
|
|
36
|
+
entities, edges = [], []
|
|
37
|
+
for d in discussions:
|
|
38
|
+
repo_id = 'asset-%s' % (d.project_id or 'global')[:8]
|
|
39
|
+
# 讨论 → DECISION 实体
|
|
40
|
+
entities.append({
|
|
41
|
+
'id': 'disc:%s' % d.id, 'repo_id': repo_id, 'type': 'DECISION',
|
|
42
|
+
'canonical': d.title[:80], 'cn': '',
|
|
43
|
+
'props': {'kind': 'discussion', 'project_id': d.project_id, 'source': 'asset_center'},
|
|
44
|
+
})
|
|
45
|
+
# 消息 → 关联到讨论
|
|
46
|
+
msgs = db.query(DiscussionMessage).filter(DiscussionMessage.discussion_id == d.id).all()
|
|
47
|
+
for m in msgs:
|
|
48
|
+
if not m.content: continue
|
|
49
|
+
entities.append({
|
|
50
|
+
'id': 'discmsg:%s' % m.id, 'repo_id': repo_id, 'type': 'DECISION',
|
|
51
|
+
'canonical': m.content[:60], 'cn': m.author_name or '',
|
|
52
|
+
'props': {'discussion_id': d.id, 'author': m.author_name, 'source': 'discussion_msg'},
|
|
53
|
+
})
|
|
54
|
+
edges.append({
|
|
55
|
+
'from_id': 'discmsg:%s' % m.id, 'to_id': 'disc:%s' % d.id,
|
|
56
|
+
'edge_type': 'decided_in', 'from_repo': repo_id, 'to_repo': repo_id,
|
|
57
|
+
'confidence': 1.0, 'source': 'explicit',
|
|
58
|
+
})
|
|
59
|
+
db.close()
|
|
60
|
+
|
|
61
|
+
upsert_r = pg_upsert.upsert_batch(entities, edges) if (entities or edges) else {'ok': False}
|
|
62
|
+
return {'discussions': len(discussions), 'entities': len(entities), 'edges': len(edges), 'upsert': upsert_r}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""资产中心 prds + prd_versions → KG 业务知识吸收。
|
|
3
|
+
|
|
4
|
+
把工作台 SQLite/PG 的 prds 表灌进 KG (当前0吸收)。
|
|
5
|
+
对每个有正文的 PRD:
|
|
6
|
+
1. 调 prd_llm_extract 抽功能点/字段/规则/端点/权限
|
|
7
|
+
2. 调 prd_chunk_embed 做向量 (LightRAG vector 路)
|
|
8
|
+
3. 调 req_anchor 锚到 REQ-ID
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
_THIS = os.path.dirname(os.path.abspath(__file__))
|
|
15
|
+
for _i in range(8):
|
|
16
|
+
_p = os.path.dirname(_THIS)
|
|
17
|
+
if os.path.isfile(os.path.join(_p, 'foundation', 'bootstrap.py')):
|
|
18
|
+
sys.path.insert(0, _p); break
|
|
19
|
+
_THIS = _p
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def import_all_prds(project_id: str = None, do_embed: bool = False, llm_limit: int = 10, logger=print):
|
|
23
|
+
"""扫资产中心所有 PRD → LLM 抽取 + 锚定。
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
project_id: 限定某项目 (None=全部)
|
|
27
|
+
do_embed: 是否做 embedding (慢, 默认False)
|
|
28
|
+
llm_limit: LLM 抽取上限 (避免154个PRD全调qwen超时; 0=不调LLM只锚定)
|
|
29
|
+
Returns: {stats}
|
|
30
|
+
"""
|
|
31
|
+
from domain.kg.extract.prd import prd_llm_extract, prd_chunk_embed, req_anchor
|
|
32
|
+
|
|
33
|
+
# 连工作台 DB 读 PRD
|
|
34
|
+
try:
|
|
35
|
+
from dotenv import load_dotenv
|
|
36
|
+
for p in ['wlinkj-workspace/backend/.env', '.env']:
|
|
37
|
+
if os.path.isfile(p):
|
|
38
|
+
load_dotenv(p); break
|
|
39
|
+
except Exception:
|
|
40
|
+
pass
|
|
41
|
+
sys.path.insert(0, os.path.join(os.getcwd(), 'wlinkj-workspace', 'backend'))
|
|
42
|
+
from app.db import SessionLocal
|
|
43
|
+
from app.models import PRD, PRDVersion
|
|
44
|
+
from sqlalchemy import text
|
|
45
|
+
|
|
46
|
+
db = SessionLocal()
|
|
47
|
+
q = db.query(PRD)
|
|
48
|
+
if project_id:
|
|
49
|
+
q = q.filter(PRD.project_id == project_id)
|
|
50
|
+
prds = q.all()
|
|
51
|
+
logger(' [asset-prd] %d 个 PRD 待吸收' % len(prds))
|
|
52
|
+
|
|
53
|
+
all_entities, all_edges = [], []
|
|
54
|
+
embedded = 0
|
|
55
|
+
llm_done = 0
|
|
56
|
+
for prd in prds:
|
|
57
|
+
# 取最新版本正文
|
|
58
|
+
ver = db.query(PRDVersion).filter(PRDVersion.prd_id == prd.id).order_by(PRDVersion.version.desc()).first()
|
|
59
|
+
content_md = ver.content_md if ver else ''
|
|
60
|
+
repo_id = 'asset-%s' % (prd.project_id or 'global')[:8]
|
|
61
|
+
|
|
62
|
+
# ① PRD 实体本身 (写 entities, group=prd)
|
|
63
|
+
all_entities.append({
|
|
64
|
+
'id': 'prd:%s' % prd.id, 'repo_id': repo_id, 'type': 'PRD',
|
|
65
|
+
'canonical': prd.title[:80], 'cn': prd.category or '',
|
|
66
|
+
'props': {'project_id': prd.project_id, 'status': prd.status,
|
|
67
|
+
'version': prd.current_version, 'source': 'asset_center'},
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
# ② REQ-ID 锚定 (PRD 标题 → anchors)
|
|
71
|
+
a_ent, a_edg = req_anchor.anchor_prd(prd.id, prd.title, prd.project_id, repo_id)
|
|
72
|
+
all_entities += a_ent
|
|
73
|
+
all_edges += a_edg
|
|
74
|
+
|
|
75
|
+
# ③ 有正文且未超 LLM 上限 → LLM 抽取
|
|
76
|
+
if content_md and len(content_md) > 100 and llm_done < llm_limit:
|
|
77
|
+
extracted = prd_llm_extract.extract_prd_knowledge(content_md)
|
|
78
|
+
e_ent, e_edg = prd_llm_extract.to_entities_edges(
|
|
79
|
+
extracted, prd.id, prd.project_id, repo_id)
|
|
80
|
+
all_entities += e_ent
|
|
81
|
+
all_edges += e_edg
|
|
82
|
+
llm_done += 1
|
|
83
|
+
|
|
84
|
+
# ④ embedding (可选, 慢)
|
|
85
|
+
if do_embed and len(content_md) > 500:
|
|
86
|
+
try:
|
|
87
|
+
r = prd_chunk_embed.embed_prd(prd.id, content_md, repo_id)
|
|
88
|
+
embedded += r.get('embedded', 0)
|
|
89
|
+
except Exception:
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
db.close()
|
|
93
|
+
|
|
94
|
+
# 写 PG
|
|
95
|
+
from domain.kg.extract.java import pg_upsert
|
|
96
|
+
upsert_r = pg_upsert.upsert_batch(all_entities, all_edges) if (all_entities or all_edges) else {'ok': False}
|
|
97
|
+
|
|
98
|
+
# ★ 同时把锚点写进 anchors 专用表 (GOAL 1 建的)
|
|
99
|
+
anchor_records = []
|
|
100
|
+
seen_anchor = set()
|
|
101
|
+
for e in all_entities:
|
|
102
|
+
if e.get('type') == 'ANCHOR':
|
|
103
|
+
aid = e['id']
|
|
104
|
+
if aid in seen_anchor:
|
|
105
|
+
continue
|
|
106
|
+
seen_anchor.add(aid)
|
|
107
|
+
anchor_records.append({
|
|
108
|
+
'id': aid,
|
|
109
|
+
'project_id': e['props'].get('project_id'),
|
|
110
|
+
'title': e.get('cn', ''),
|
|
111
|
+
'kind': e['props'].get('kind', 'feature'),
|
|
112
|
+
'prd_id': e['props'].get('prd_id'),
|
|
113
|
+
})
|
|
114
|
+
anchor_ok = _upsert_anchors(anchor_records) if anchor_records else 0
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
'prds_total': len(prds),
|
|
118
|
+
'entities': len(all_entities),
|
|
119
|
+
'edges': len(all_edges),
|
|
120
|
+
'embedded': embedded,
|
|
121
|
+
'anchors': anchor_ok,
|
|
122
|
+
'upsert': upsert_r,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _upsert_anchors(records):
|
|
127
|
+
"""写 anchors 专用表。"""
|
|
128
|
+
from domain.kg.extract.java import pg_upsert as _pg
|
|
129
|
+
engine, _ = _pg._get_pg_engine()
|
|
130
|
+
if engine is None or not records:
|
|
131
|
+
return 0
|
|
132
|
+
from sqlalchemy import text
|
|
133
|
+
ok = 0
|
|
134
|
+
with engine.begin() as conn:
|
|
135
|
+
for r in records:
|
|
136
|
+
try:
|
|
137
|
+
conn.execute(text("""
|
|
138
|
+
INSERT INTO anchors (id, project_id, title, kind, prd_id)
|
|
139
|
+
VALUES (:id, :pid, :title, :kind, :prd)
|
|
140
|
+
ON CONFLICT (id) DO UPDATE SET title=EXCLUDED.title, updated_at=now()
|
|
141
|
+
"""), {'id': r['id'], 'pid': r.get('project_id'), 'title': r.get('title', ''),
|
|
142
|
+
'kind': r.get('kind', 'feature'), 'prd': r.get('prd_id')})
|
|
143
|
+
ok += 1
|
|
144
|
+
except Exception:
|
|
145
|
+
pass
|
|
146
|
+
return ok
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""原型 + 标注 → 意图知识。
|
|
3
|
+
|
|
4
|
+
把 prototypes 表灌进 KG (当前10个原型, 0标注 - 管线先建好)。
|
|
5
|
+
prototype → PAGE 实体; annotation → CONSTRAINT 实体。
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
import os, sys
|
|
9
|
+
|
|
10
|
+
_THIS = os.path.dirname(os.path.abspath(__file__))
|
|
11
|
+
for _i in range(8):
|
|
12
|
+
_p = os.path.dirname(_THIS)
|
|
13
|
+
if os.path.isfile(os.path.join(_p, 'foundation', 'bootstrap.py')):
|
|
14
|
+
sys.path.insert(0, _p); break
|
|
15
|
+
_THIS = _p
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def import_prototypes(project_id: str = None, logger=print):
|
|
19
|
+
"""原型 + 标注 → KG。"""
|
|
20
|
+
try:
|
|
21
|
+
from dotenv import load_dotenv
|
|
22
|
+
for p in ['wlinkj-workspace/backend/.env', '.env']:
|
|
23
|
+
if os.path.isfile(p): load_dotenv(p); break
|
|
24
|
+
except: pass
|
|
25
|
+
sys.path.insert(0, os.path.join(os.getcwd(), 'wlinkj-workspace', 'backend'))
|
|
26
|
+
from app.db import SessionLocal
|
|
27
|
+
from app.models import Prototype, PrototypeAnnotation
|
|
28
|
+
from domain.kg.extract.java import pg_upsert
|
|
29
|
+
|
|
30
|
+
db = SessionLocal()
|
|
31
|
+
q = db.query(Prototype)
|
|
32
|
+
if project_id: q = q.filter(Prototype.project_id == project_id)
|
|
33
|
+
protos = q.all()
|
|
34
|
+
logger(' [asset-proto] %d 个原型' % len(protos))
|
|
35
|
+
|
|
36
|
+
entities, edges = [], []
|
|
37
|
+
for p in protos:
|
|
38
|
+
repo_id = 'asset-%s' % (p.project_id or 'global')[:8]
|
|
39
|
+
# 原型 → PAGE 实体
|
|
40
|
+
entities.append({
|
|
41
|
+
'id': 'proto:%s' % p.id, 'repo_id': repo_id, 'type': 'PAGE',
|
|
42
|
+
'canonical': p.feature or p.id[:8], 'cn': p.platform or '',
|
|
43
|
+
'props': {'kind': 'prototype', 'project_id': p.project_id,
|
|
44
|
+
'status': p.status, 'source': 'asset_center'},
|
|
45
|
+
})
|
|
46
|
+
# 该原型的标注 → CONSTRAINT
|
|
47
|
+
anns = db.query(PrototypeAnnotation).filter(PrototypeAnnotation.prototype_id == p.id).all()
|
|
48
|
+
for a in anns:
|
|
49
|
+
if not a.comment: continue
|
|
50
|
+
entities.append({
|
|
51
|
+
'id': 'ANNO:%s' % a.id, 'repo_id': repo_id, 'type': 'CONSTRAINT',
|
|
52
|
+
'canonical': a.comment[:60], 'cn': a.type or '',
|
|
53
|
+
'props': {'prototype_id': p.id, 'status': a.status,
|
|
54
|
+
'coords': {'x': a.x, 'y': a.y}, 'source': 'annotation'},
|
|
55
|
+
})
|
|
56
|
+
edges.append({
|
|
57
|
+
'from_id': 'ANNO:%s' % a.id, 'to_id': 'proto:%s' % p.id,
|
|
58
|
+
'edge_type': 'annotates', 'from_repo': repo_id, 'to_repo': repo_id,
|
|
59
|
+
'confidence': 1.0, 'source': 'explicit',
|
|
60
|
+
})
|
|
61
|
+
db.close()
|
|
62
|
+
|
|
63
|
+
upsert_r = pg_upsert.upsert_batch(entities, edges) if (entities or edges) else {'ok': False}
|
|
64
|
+
return {'prototypes': len(protos), 'entities': len(entities), 'edges': len(edges), 'upsert': upsert_r}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""回流历史 → 实践知识。
|
|
3
|
+
|
|
4
|
+
asset_returns (引擎→平台产出) → embedding (能搜"之前怎么做的")。
|
|
5
|
+
当前3条, 是引擎回流的PRD/原型/资产。
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
import os, sys
|
|
9
|
+
|
|
10
|
+
_THIS = os.path.dirname(os.path.abspath(__file__))
|
|
11
|
+
for _i in range(8):
|
|
12
|
+
_p = os.path.dirname(_THIS)
|
|
13
|
+
if os.path.isfile(os.path.join(_p, 'foundation', 'bootstrap.py')):
|
|
14
|
+
sys.path.insert(0, _p); break
|
|
15
|
+
_THIS = _p
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def import_returns(project_id: str = None, logger=print):
|
|
19
|
+
"""asset_returns → KG 实践知识。"""
|
|
20
|
+
try:
|
|
21
|
+
from dotenv import load_dotenv
|
|
22
|
+
for p in ['wlinkj-workspace/backend/.env', '.env']:
|
|
23
|
+
if os.path.isfile(p): load_dotenv(p); break
|
|
24
|
+
except: pass
|
|
25
|
+
sys.path.insert(0, os.path.join(os.getcwd(), 'wlinkj-workspace', 'backend'))
|
|
26
|
+
from app.db import SessionLocal
|
|
27
|
+
from app.models import AssetReturn
|
|
28
|
+
from domain.kg.extract.java import pg_upsert
|
|
29
|
+
|
|
30
|
+
db = SessionLocal()
|
|
31
|
+
q = db.query(AssetReturn)
|
|
32
|
+
if project_id: q = q.filter(AssetReturn.project_id == project_id)
|
|
33
|
+
returns = q.all()
|
|
34
|
+
logger(' [asset-ret] %d 条回流' % len(returns))
|
|
35
|
+
|
|
36
|
+
entities, edges = [], []
|
|
37
|
+
for r in returns:
|
|
38
|
+
repo_id = 'asset-%s' % (r.project_id or 'global')[:8]
|
|
39
|
+
# 回流产出 → 实体 (按 return_type 分类)
|
|
40
|
+
etype = {'prd': 'PRD', 'prototype': 'PAGE', 'asset': 'ASSET'}.get(r.return_type, 'ASSET')
|
|
41
|
+
entities.append({
|
|
42
|
+
'id': 'return:%s' % r.id, 'repo_id': repo_id, 'type': etype,
|
|
43
|
+
'canonical': r.title[:80], 'cn': r.return_type or '',
|
|
44
|
+
'props': {'project_id': r.project_id, 'return_type': r.return_type,
|
|
45
|
+
'source': r.source, 'status': r.status,
|
|
46
|
+
'preview': (r.content_preview or '')[:200],
|
|
47
|
+
'source': 'asset_return'},
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
db.close()
|
|
51
|
+
upsert_r = pg_upsert.upsert_batch(entities, edges) if (entities or edges) else {'ok': False}
|
|
52
|
+
return {'returns': len(returns), 'entities': len(entities), 'edges': len(edges), 'upsert': upsert_r}
|