@hupan56/wlkj 3.3.13 → 3.3.14
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/bin/cli.js +1 -23
- package/package.json +29 -29
- package/templates/qoder/agents/design-agent.md +20 -0
- package/templates/qoder/agents/spec-generator.md +21 -0
- package/templates/qoder/commands/optional/wl-spec.md +2 -12
- package/templates/qoder/commands/optional/wl-status.md +0 -8
- package/templates/qoder/commands/wl-code.md +0 -8
- package/templates/qoder/commands/wl-commit.md +1 -11
- package/templates/qoder/commands/wl-init.md +129 -129
- package/templates/qoder/commands/wl-prd.md +0 -24
- package/templates/qoder/commands/wl-search.md +11 -26
- package/templates/qoder/commands/wl-task.md +1 -11
- package/templates/qoder/commands/wl-test.md +0 -8
- package/templates/qoder/config.yaml +8 -3
- package/templates/qoder/hooks/session-start.py +365 -384
- package/templates/qoder/hooks/stop-eval.py +254 -383
- package/templates/qoder/scripts/capability/adapters/mcp.py +314 -322
- package/templates/qoder/scripts/capability/registry.py +248 -245
- 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/init_doctor.py +2 -6
- package/templates/qoder/scripts/deployment/setup/install_qoderwork.py +14 -0
- package/templates/qoder/scripts/deployment/setup/setup.py +2 -16
- 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/build/build_entity_registry.py +12 -12
- package/templates/qoder/scripts/domain/kg/build/build_relations.py +12 -12
- 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/graph/kg_link_db.py +235 -0
- package/templates/qoder/scripts/domain/kg/graph/kg_semantic.py +5 -41
- package/templates/qoder/scripts/domain/kg/kg.py +0 -14
- package/templates/qoder/scripts/domain/kg/search/enrich_prompt.py +238 -0
- package/templates/qoder/scripts/domain/kg/server/perf_bench.py +197 -0
- package/templates/qoder/scripts/domain/kg/switch_project.py +2 -2
- package/templates/qoder/scripts/domain/kg/sync_repowiki.py +109 -0
- package/templates/qoder/scripts/domain/task/wlkj_panel.py +1348 -1503
- package/templates/qoder/scripts/engine/poller.py +219 -0
- package/templates/qoder/scripts/foundation/bootstrap.py +145 -156
- package/templates/qoder/scripts/orchestration/wlkj.py +189 -306
- package/templates/qoder/settings.json +0 -8
- package/templates/qoder/skills/wl-spec/SKILL.md +1 -1
- package/templates/qoder/commands/wl-data.md +0 -46
- package/templates/qoder/commands/wl-fix.md +0 -47
- package/templates/qoder/commands/wl-knowledge.md +0 -41
- package/templates/qoder/commands/wl-review.md +0 -49
- package/templates/qoder/contracts/insight.md +0 -55
- package/templates/qoder/hooks/pre-tool-use-commit.py +0 -124
- package/templates/qoder/scripts/foundation/io/context_cache.py +0 -94
- package/templates/qoder/scripts/tool_guide.md +0 -70
- package/templates/qoder/scripts/validation/eval/alignment_matrix.py +0 -176
- package/templates/qoder/scripts/validation/eval/bf2_content_fidelity.py +0 -110
- package/templates/qoder/scripts/validation/eval/bf2_llmjudge.py +0 -104
- package/templates/qoder/scripts/validation/eval/bf_score.py +0 -218
- package/templates/qoder/scripts/validation/eval/code_flywheel.py +0 -150
- package/templates/qoder/scripts/validation/eval/dispatcher_ab.py +0 -156
- package/templates/qoder/scripts/validation/eval/dispatcher_ab_2026-07-21.json +0 -23
- package/templates/qoder/scripts/validation/eval/feature_fidelity_flywheel.py +0 -143
- package/templates/qoder/scripts/validation/eval/gradient_matrix.py +0 -261
- package/templates/qoder/scripts/validation/eval/gradient_matrix_baseline_2026-07-21.json +0 -33
- package/templates/qoder/scripts/validation/eval/metrics_dashboard.py +0 -105
- package/templates/qoder/scripts/validation/eval/multi_turn_flywheel.py +0 -118
- package/templates/qoder/scripts/validation/eval/prd_fidelity_flywheel.py +0 -128
- package/templates/qoder/scripts/validation/eval/prd_flywheel.py +0 -148
- package/templates/qoder/scripts/validation/eval/prototype_fidelity_flywheel.py +0 -166
- package/templates/qoder/scripts/validation/eval/recall_flywheel.py +0 -148
- package/templates/qoder/scripts/validation/eval/robustness_flywheel.py +0 -139
- package/templates/qoder/scripts/validation/eval/speed_accuracy_flywheel.py +0 -188
- package/templates/qoder/scripts/validation/eval/task_flywheel.py +0 -124
- package/templates/qoder/scripts/validation/eval/token_flywheel.py +0 -88
- package/templates/qoder/scripts/validation/metrics/eval_code_ac.py +0 -177
- package/templates/qoder/scripts/validation/metrics/lint_cases.py +0 -170
- package/templates/qoder/scripts/validation/test/test_context_cache.py +0 -78
- package/templates/qoder/scripts/validation/test/test_lint_cases.py +0 -60
- package/templates/qoder/scripts/validation/test/test_pre_tool_use_commit.py +0 -70
- package/templates/workspace/specs/REQ-TEST-CTX/.context-cache.json +0 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# v3.0 路径自举: 引导到 common/bootstrap, 统一 sys.path 逻辑
|
|
3
|
+
import os as _o, sys as _s
|
|
4
|
+
_f = _o.path.abspath(__file__)
|
|
5
|
+
for _ in range(10):
|
|
6
|
+
_f = _o.path.dirname(_f)
|
|
7
|
+
_cp = _o.path.join(_f, 'foundation')
|
|
8
|
+
if _o.path.isfile(_o.path.join(_cp, 'bootstrap.py')):
|
|
9
|
+
break
|
|
10
|
+
if _cp not in _s.path: _s.path.insert(0, _cp)
|
|
11
|
+
from bootstrap import setup; setup()
|
|
12
|
+
from foundation.core.paths import get_repo_root
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
perf_bench.py — 知识图谱关键路径性能基准
|
|
16
|
+
|
|
17
|
+
诊断"用了工作流反而更慢"的根因, 并验证常驻化(daemon)加速层的效果。
|
|
18
|
+
|
|
19
|
+
两种测量模式:
|
|
20
|
+
1. 冷启动 (subprocess 跑 kg.py) — 模拟真实用户体验: 起进程→import→连库→跑
|
|
21
|
+
2. daemon 热路径 (kgd_client) — daemon 常驻时的 IPC 调用, 模型/连接已就绪
|
|
22
|
+
|
|
23
|
+
用法:
|
|
24
|
+
python perf_bench.py # 默认: 测冷启动 (--no-daemon)
|
|
25
|
+
python perf_bench.py --with-daemon # 同时测 daemon 热路径 (需先 kgd.py start)
|
|
26
|
+
python perf_bench.py --quick # 跳过 semantic (26s), 只测轻量路径
|
|
27
|
+
"""
|
|
28
|
+
import io
|
|
29
|
+
import os
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
import time
|
|
33
|
+
|
|
34
|
+
# UTF-8 输出 (Windows 终端默认 GBK 会乱码)
|
|
35
|
+
try:
|
|
36
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
37
|
+
except Exception:
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
KG_PY = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kg.py')
|
|
41
|
+
REPO_ROOT = get_repo_root()
|
|
42
|
+
|
|
43
|
+
# ── 测试用例 (覆盖四层) ──────────────────────────────────────────────
|
|
44
|
+
# (名称, kg子命令, 参数列表, 预期层)
|
|
45
|
+
CASES = [
|
|
46
|
+
('search-考勤(web)', 'search', ['考勤', '--platform', 'web'], '结构层'),
|
|
47
|
+
('search-车辆(web)', 'search', ['车辆', '--platform', 'web'], '结构层'),
|
|
48
|
+
('search-报销(app)', 'search', ['报销', '--platform', 'app'], '结构层'),
|
|
49
|
+
('api-asset', 'api', ['asset'], '结构层'),
|
|
50
|
+
('context_pack-车辆', 'context', ['车辆', '--platform', 'web'], '①③+设计'),
|
|
51
|
+
('impact-/asset', 'impact', ['/asset'], '图谱层'),
|
|
52
|
+
('feature-资产管理', 'feature', ['资产管理'], '图谱层'),
|
|
53
|
+
('semantic-报销', 'semantic', ['报销'], '向量层'), # 26s 慢王
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _run_kg(args, use_daemon=True, timeout=120):
|
|
58
|
+
"""跑一次 kg.py 子命令, 返回 (耗时秒, 返回码)。
|
|
59
|
+
|
|
60
|
+
use_daemon=True : 走默认 (kg.py 内部会优先 daemon)
|
|
61
|
+
use_daemon=False : 加 --no-daemon 强制冷路径
|
|
62
|
+
"""
|
|
63
|
+
cmd = [sys.executable, KG_PY] + args
|
|
64
|
+
if not use_daemon:
|
|
65
|
+
cmd.append('--no-daemon')
|
|
66
|
+
env = dict(os.environ)
|
|
67
|
+
env['PYTHONIOENCODING'] = 'utf-8'
|
|
68
|
+
t0 = time.time()
|
|
69
|
+
try:
|
|
70
|
+
# stdout 重定向到 DEVNULL, 只测耗时, 不看内容
|
|
71
|
+
r = subprocess.run(cmd, stdout=subprocess.DEVNULL,
|
|
72
|
+
stderr=subprocess.DEVNULL, cwd=REPO_ROOT,
|
|
73
|
+
env=env, timeout=timeout)
|
|
74
|
+
return time.time() - t0, r.returncode
|
|
75
|
+
except subprocess.TimeoutExpired:
|
|
76
|
+
return float(timeout), -1
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _median(samples):
|
|
80
|
+
"""取中位数 (抗抖动)。"""
|
|
81
|
+
s = sorted(samples)
|
|
82
|
+
n = len(s)
|
|
83
|
+
return s[n // 2] if n % 2 else (s[n // 2 - 1] + s[n // 2]) / 2.0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def bench_case(name, cmd, args, cold=True, daemon=False, repeats=3):
|
|
87
|
+
"""跑单个用例, 返回 (中位数耗时, 状态)。
|
|
88
|
+
|
|
89
|
+
cold=True : 测冷启动 (--no-daemon)
|
|
90
|
+
daemon=True: 测 daemon 热路径 (不加 --no-daemon, 但需 daemon 在线)
|
|
91
|
+
"""
|
|
92
|
+
if cold and daemon:
|
|
93
|
+
raise ValueError('cold 和 daemon 互斥')
|
|
94
|
+
# 重量级命令 (semantic 冷启动 ~27s) 只跑 1 次, 避免基准脚本本身过慢
|
|
95
|
+
if cmd == 'semantic' and cold:
|
|
96
|
+
repeats = 1
|
|
97
|
+
use_daemon = daemon
|
|
98
|
+
samples = []
|
|
99
|
+
status = 'ok'
|
|
100
|
+
for _ in range(repeats):
|
|
101
|
+
elapsed, rc = _run_kg([cmd] + args, use_daemon=use_daemon)
|
|
102
|
+
samples.append(elapsed)
|
|
103
|
+
if rc != 0:
|
|
104
|
+
status = 'rc=%d' % rc
|
|
105
|
+
return _median(samples), status
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def daemon_online():
|
|
109
|
+
"""探测 daemon 是否在线 (通过 kg.py status, 1s 超时)。"""
|
|
110
|
+
try:
|
|
111
|
+
from kgd import kgd_client
|
|
112
|
+
return kgd_client.ping(timeout=1.0)
|
|
113
|
+
except Exception:
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def fmt_speedup(cold_s, hot_s):
|
|
118
|
+
"""格式化加速比。"""
|
|
119
|
+
if hot_s <= 0.001:
|
|
120
|
+
return '-'
|
|
121
|
+
return '%.0fx' % (cold_s / hot_s)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def main():
|
|
125
|
+
args = sys.argv[1:]
|
|
126
|
+
quick = '--quick' in args
|
|
127
|
+
want_daemon = '--with-daemon' in args
|
|
128
|
+
|
|
129
|
+
print('=' * 72)
|
|
130
|
+
print('知识图谱性能基准 (repo: %s)' % os.path.basename(REPO_ROOT))
|
|
131
|
+
print('=' * 72)
|
|
132
|
+
|
|
133
|
+
if quick:
|
|
134
|
+
print('[quick 模式] 跳过 semantic (向量层 26s), 只测轻量路径\n')
|
|
135
|
+
cases = [c for c in CASES if c[1] != 'semantic']
|
|
136
|
+
else:
|
|
137
|
+
cases = CASES
|
|
138
|
+
|
|
139
|
+
cold_results = [] # [(name, secs, status, layer)]
|
|
140
|
+
hot_results = {} # name -> (secs, status)
|
|
141
|
+
|
|
142
|
+
# ── 1. 冷启动基线 (真实用户体验: 每次起一个进程) ──
|
|
143
|
+
print('[1/2] 冷启动基线 (--no-daemon, 模拟现状) ...')
|
|
144
|
+
for name, cmd, cargs, layer in cases:
|
|
145
|
+
secs, status = bench_case(name, cmd, cargs, cold=True)
|
|
146
|
+
cold_results.append((name, secs, status, layer))
|
|
147
|
+
marker = ' ' if status == 'ok' else '! '
|
|
148
|
+
print(' %s%-22s %6.2fs [%s] %s' % (marker, name, secs, layer, status))
|
|
149
|
+
print()
|
|
150
|
+
|
|
151
|
+
# ── 2. daemon 热路径 (常驻加速层) ──
|
|
152
|
+
if want_daemon:
|
|
153
|
+
online = daemon_online()
|
|
154
|
+
if not online:
|
|
155
|
+
print('[2/2] daemon 未在线 — 跳过热路径测试。')
|
|
156
|
+
print(' (先启动: python .qoder/scripts/domain/kg/server/kgd.py start)')
|
|
157
|
+
else:
|
|
158
|
+
print('[2/2] daemon 在线, 测热路径 ...')
|
|
159
|
+
for name, cmd, cargs, layer in cases:
|
|
160
|
+
secs, status = bench_case(name, cmd, cargs, cold=False, daemon=True)
|
|
161
|
+
hot_results[name] = (secs, status)
|
|
162
|
+
marker = ' ' if status == 'ok' else '! '
|
|
163
|
+
print(' %s%-22s %6.2fs [%s] %s' % (marker, name, secs, layer, status))
|
|
164
|
+
print()
|
|
165
|
+
|
|
166
|
+
# ── 汇总对比表 ──
|
|
167
|
+
print('-' * 72)
|
|
168
|
+
print('%-22s %10s %10s %10s' % ('用例', '冷启动', 'daemon', '加速'))
|
|
169
|
+
print('%-22s %10s %10s %10s' % ('─' * 18, '─' * 8, '─' * 8, '─' * 6))
|
|
170
|
+
for name, cold_s, status, layer in cold_results:
|
|
171
|
+
hot_s = hot_results.get(name, (None, None))[0]
|
|
172
|
+
hot_str = '%.2fs' % hot_s if hot_s else '-'
|
|
173
|
+
speed = fmt_speedup(cold_s, hot_s) if hot_s else '-'
|
|
174
|
+
print('%-22s %8.2fs %10s %10s' % (name, cold_s, hot_str, speed))
|
|
175
|
+
print('-' * 72)
|
|
176
|
+
|
|
177
|
+
# ── 诊断结论 ──
|
|
178
|
+
print('\n诊断:')
|
|
179
|
+
semantic_s = next((s for n, s, _, _ in cold_results if 'semantic' in n), None)
|
|
180
|
+
if semantic_s and semantic_s > 10:
|
|
181
|
+
print(' 🔴 semantic %.1fs — 模型冷加载占 99%%, 是头号慢源' % semantic_s)
|
|
182
|
+
print(' 解法: kgd.py start 常驻模型 → <0.5s')
|
|
183
|
+
elif semantic_s:
|
|
184
|
+
print(' 🟢 semantic %.1fs — 在可接受范围' % semantic_s)
|
|
185
|
+
|
|
186
|
+
total_cold = sum(s for _, s, _, _ in cold_results)
|
|
187
|
+
print(' 冷启动累积: %.1fs (一次 PRD 流程的隐性等待)' % total_cold)
|
|
188
|
+
if hot_results:
|
|
189
|
+
total_hot = sum(hot_results[n][0] for n in hot_results)
|
|
190
|
+
print(' daemon 累积: %.1fs → 整体提速 %.0fx' %
|
|
191
|
+
(total_hot, total_cold / max(total_hot, 0.01)))
|
|
192
|
+
|
|
193
|
+
return 0
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if __name__ == '__main__':
|
|
197
|
+
sys.exit(main())
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
python switch_project.py --email a@b.c --pw xxx # 非交互:直接指定
|
|
7
7
|
python switch_project.py --project-uuid <UUID> # 非交互:直接指定项目
|
|
8
8
|
|
|
9
|
-
需工作台后端在跑(默认 http://
|
|
9
|
+
需工作台后端在跑(默认 http://127.0.0.1:10010)。
|
|
10
10
|
"""
|
|
11
11
|
import json
|
|
12
12
|
import os
|
|
@@ -33,7 +33,7 @@ def _find_config_path():
|
|
|
33
33
|
CONFIG_PATH = _find_config_path()
|
|
34
34
|
|
|
35
35
|
# 平台地址(默认 10010,可 env 覆盖)
|
|
36
|
-
BASE_URL = os.environ.get("WLKJ_BASE_URL", "http://
|
|
36
|
+
BASE_URL = os.environ.get("WLKJ_BASE_URL", "http://127.0.0.1:10010")
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def bind(email, password, base_url=BASE_URL):
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""同步 Qoder Repo Wiki → 平台 PG wiki 表。
|
|
3
|
+
|
|
4
|
+
Qoder 自动为代码仓库生成 Repo Wiki(750+篇业务文档),存在:
|
|
5
|
+
data/code/{repo}/.qoder/repowiki/knowledge/zh/**/*.md
|
|
6
|
+
|
|
7
|
+
本脚本读这些 md → UPSERT 到 PG wiki 表(repo + keyword + title + description)。
|
|
8
|
+
这样知识层的 wiki 搜索(graphrag_ask/rag_search)能命中 Qoder 自动生成的高质量文档。
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
python sync_repowiki.py # 同步全部仓库
|
|
12
|
+
python sync_repowiki.py --repo fywl-ics # 只同步指定仓库
|
|
13
|
+
python sync_repowiki.py --dry-run # 只统计不写
|
|
14
|
+
"""
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import glob
|
|
18
|
+
|
|
19
|
+
_THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
20
|
+
_up1 = os.path.dirname(_THIS_DIR)
|
|
21
|
+
_up2 = os.path.dirname(_up1)
|
|
22
|
+
SCRIPTS_DIR = os.path.dirname(_up2)
|
|
23
|
+
REPO_ROOT = os.path.dirname(SCRIPTS_DIR)
|
|
24
|
+
CODE_ROOT = os.path.join(REPO_ROOT, "data", "code")
|
|
25
|
+
|
|
26
|
+
PG = dict(host="127.0.0.1", port=5432, user="wlinkj", password="changeme", dbname="wlinkj")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def scan_repowiki(repo):
|
|
30
|
+
"""扫描某仓库的 Repo Wiki,返回 [{path, title, content, dir_path}]。"""
|
|
31
|
+
wiki_base = os.path.join(CODE_ROOT, repo, ".qoder", "repowiki")
|
|
32
|
+
if not os.path.isdir(wiki_base):
|
|
33
|
+
return []
|
|
34
|
+
results = []
|
|
35
|
+
for md_path in glob.glob(os.path.join(wiki_base, "**", "*.md"), recursive=True):
|
|
36
|
+
try:
|
|
37
|
+
with open(md_path, encoding="utf-8") as f:
|
|
38
|
+
content = f.read()
|
|
39
|
+
# 标题:md 文件名或第一行 #
|
|
40
|
+
title = os.path.splitext(os.path.basename(md_path))[0]
|
|
41
|
+
for line in content.split("\n")[:5]:
|
|
42
|
+
if line.strip().startswith("#"):
|
|
43
|
+
title = line.strip().lstrip("#").strip()
|
|
44
|
+
break
|
|
45
|
+
# keyword:从目录路径提取业务模块名
|
|
46
|
+
rel = os.path.relpath(md_path, wiki_base)
|
|
47
|
+
parts = rel.replace("\\", "/").split("/")
|
|
48
|
+
keyword = parts[-2] if len(parts) >= 2 else title
|
|
49
|
+
results.append({
|
|
50
|
+
"path": md_path,
|
|
51
|
+
"rel_path": rel,
|
|
52
|
+
"title": title,
|
|
53
|
+
"keyword": keyword,
|
|
54
|
+
"content": content[:2000], # 取前2000字
|
|
55
|
+
})
|
|
56
|
+
except Exception:
|
|
57
|
+
continue
|
|
58
|
+
return results
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def sync_to_pg(wiki_items, repo):
|
|
62
|
+
"""UPSERT 到 PG wiki 表。"""
|
|
63
|
+
import psycopg2
|
|
64
|
+
from psycopg2.extras import execute_values
|
|
65
|
+
|
|
66
|
+
conn = psycopg2.connect(**PG)
|
|
67
|
+
conn.autocommit = True
|
|
68
|
+
cur = conn.cursor()
|
|
69
|
+
|
|
70
|
+
# ★ 不删旧数据(原 wiki 表有业务文档),只删 repowiki 来源的记录
|
|
71
|
+
# 用 md_path 前缀 'repowiki:' 标识(避免路径分隔符差异)
|
|
72
|
+
cur.execute("DELETE FROM wiki WHERE project = %s AND md_path LIKE 'repowiki:%%'", (repo,))
|
|
73
|
+
|
|
74
|
+
rows = [(w["keyword"], repo, w["title"], "repowiki:" + w["rel_path"], w["content"][:500])
|
|
75
|
+
for w in wiki_items]
|
|
76
|
+
if rows:
|
|
77
|
+
execute_values(
|
|
78
|
+
cur,
|
|
79
|
+
"INSERT INTO wiki(keyword, project, title, md_path, description) VALUES %s",
|
|
80
|
+
rows,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
print(f"[{repo}] 同步 {len(rows)} 篇 Wiki 到 PG")
|
|
84
|
+
conn.close()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def main():
|
|
88
|
+
import argparse
|
|
89
|
+
parser = argparse.ArgumentParser(description="同步 Qoder Repo Wiki → PG")
|
|
90
|
+
parser.add_argument("--repo", help="指定仓库名")
|
|
91
|
+
parser.add_argument("--dry-run", action="store_true", help="只统计不写")
|
|
92
|
+
args = parser.parse_args()
|
|
93
|
+
|
|
94
|
+
repos = [args.repo] if args.repo else ["fywl-ui", "fywl-ics", "Carmg-H5"]
|
|
95
|
+
total = 0
|
|
96
|
+
for repo in repos:
|
|
97
|
+
items = scan_repowiki(repo)
|
|
98
|
+
print(f" {repo}: 扫到 {len(items)} 篇 Repo Wiki")
|
|
99
|
+
if items:
|
|
100
|
+
for it in items[:3]:
|
|
101
|
+
print(f" [{it['keyword']}] {it['title']}")
|
|
102
|
+
if not args.dry_run:
|
|
103
|
+
sync_to_pg(items, repo)
|
|
104
|
+
total += len(items)
|
|
105
|
+
print(f"\n总计: {total} 篇 Wiki{'(dry-run 未写入)' if args.dry_run else ' 已同步到 PG'}")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
main()
|