@hupan56/wlkj 2.7.11 → 3.0.0
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 +375 -78
- package/package.json +29 -29
- package/templates/.qoder/.runtime/ctx-cache-5660152f1d6dd819.md +23 -0
- package/templates/.qoder/.runtime/ctx-cache-afdce0dac06b25b0.md +23 -0
- package/templates/.qoder/.runtime/search-cache-eae7644e7b122f35.txt +1 -0
- package/templates/.qoder/learning/eval-history.jsonl +28 -0
- package/templates/data/index/wiki-index.json +8 -0
- package/templates/qoder/agents/insight-planning.md +1 -1
- package/templates/qoder/agents/insight-research.md +28 -15
- package/templates/qoder/commands/optional/wl-insight.md +159 -161
- package/templates/qoder/commands/optional/wl-report.md +4 -4
- package/templates/qoder/commands/optional/wl-status.md +2 -2
- package/templates/qoder/commands/wl-code.md +2 -2
- package/templates/qoder/commands/wl-design.md +2 -2
- package/templates/qoder/commands/wl-init.md +3 -3
- package/templates/qoder/commands/wl-prd.md +2 -2
- package/templates/qoder/commands/wl-req.md +43 -0
- package/templates/qoder/commands/wl-search.md +8 -8
- package/templates/qoder/commands/wl-task.md +17 -17
- package/templates/qoder/commands/wl-test.md +41 -15
- package/templates/qoder/config.yaml +17 -1
- package/templates/qoder/hooks/session-start.py +12 -22
- package/templates/qoder/nul +4 -0
- package/templates/qoder/rules/wl-pipeline.md +22 -48
- package/templates/qoder/scripts/README.md +139 -0
- package/templates/qoder/scripts/common/autotest_auth.py +109 -0
- package/templates/qoder/scripts/common/bootstrap.py +145 -0
- package/templates/qoder/scripts/common/check_publish.py +98 -0
- package/templates/qoder/scripts/common/cmd_registry.py +112 -0
- package/templates/qoder/scripts/common/config.py +187 -0
- package/templates/qoder/scripts/common/contract.py +317 -0
- package/templates/qoder/scripts/common/developer.py +2 -1
- package/templates/qoder/scripts/common/feishu.py +10 -9
- package/templates/qoder/scripts/common/guard.py +159 -0
- package/templates/qoder/scripts/common/identity.py +121 -2
- package/templates/qoder/scripts/common/kg_capabilities.py +182 -0
- package/templates/qoder/scripts/common/mcp_base.py +268 -0
- package/templates/qoder/scripts/common/paths.py +187 -1
- package/templates/qoder/scripts/common/result.py +223 -0
- package/templates/qoder/scripts/common/roles.py +60 -0
- package/templates/qoder/scripts/common/task_utils.py +21 -9
- package/templates/qoder/scripts/common/test_extract.py +115 -0
- package/templates/qoder/scripts/kg/__init__.py +11 -0
- package/templates/qoder/scripts/kg/build_entity_registry.py +196 -0
- package/templates/qoder/scripts/kg/build_relations.py +127 -0
- package/templates/qoder/scripts/{build_style_index.py → kg/build_style_index.py} +39 -10
- package/templates/qoder/scripts/kg/build_workflows.py +144 -0
- package/templates/qoder/scripts/{context_pack.py → kg/context_pack.py} +18 -11
- package/templates/qoder/scripts/{enrich_prompt.py → kg/enrich_prompt.py} +232 -226
- package/templates/qoder/scripts/{extract_api_params.py → kg/extract.py} +398 -246
- package/templates/qoder/scripts/{kg.py → kg/kg.py} +638 -708
- package/templates/qoder/scripts/{kg_build.py → kg/kg_build.py} +618 -612
- package/templates/qoder/scripts/{kg_build_db.py → kg/kg_build_db.py} +333 -327
- package/templates/qoder/scripts/{kg_duckdb.py → kg/kg_duckdb.py} +38 -37
- package/templates/qoder/scripts/{kg_incremental.py → kg/kg_incremental.py} +420 -393
- package/templates/qoder/scripts/{kg_link_db.py → kg/kg_link_db.py} +230 -224
- package/templates/qoder/scripts/{kg_semantic.py → kg/kg_semantic.py} +156 -150
- package/templates/qoder/scripts/kg/prefetch.py +359 -0
- package/templates/qoder/scripts/{search_index.py → kg/search_index.py} +70 -14
- package/templates/qoder/scripts/mcp/__init__.py +11 -0
- package/templates/qoder/scripts/{kg_mcp_server.py → mcp/kg_mcp_server.py} +77 -272
- package/templates/qoder/scripts/{lanhu_stdio_wrapper.py → mcp/lanhu_stdio_wrapper.py} +125 -119
- package/templates/qoder/scripts/{check_mcp.py → mcp/mcp_doctor.py} +515 -298
- package/templates/qoder/scripts/{mcp_launcher.py → mcp/mcp_launcher.py} +442 -414
- package/templates/qoder/scripts/{mysql_mcp_server.py → mcp/mysql_mcp_server.py} +347 -396
- package/templates/qoder/scripts/{zentao_mcp_server.py → mcp/zentao_mcp_server.py} +384 -424
- package/templates/qoder/scripts/report/__init__.py +11 -0
- package/templates/qoder/scripts/{add_session.py → report/add_session.py} +250 -244
- package/templates/qoder/scripts/{archive_prd.py → report/archive_prd.py} +383 -377
- package/templates/qoder/scripts/{eval_prd.py → report/eval_prd.py} +73 -11
- package/templates/qoder/scripts/{export.py → report/export.py} +63 -0
- package/templates/qoder/scripts/{fill_prototype.py → report/fill_prototype.py} +6 -0
- package/templates/qoder/scripts/{gen_design_doc.py → report/gen_design_doc.py} +400 -394
- package/templates/qoder/scripts/{learn.py → report/learn.py} +152 -146
- package/templates/qoder/scripts/{learn_aggregate.py → report/learn_aggregate.py} +207 -201
- package/templates/qoder/scripts/{report.py → report/report.py} +287 -281
- package/templates/qoder/scripts/report/req.py +222 -0
- package/templates/qoder/scripts/report/role.py +33 -0
- package/templates/qoder/scripts/{status.py → report/status.py} +634 -628
- package/templates/qoder/scripts/setup/__init__.py +11 -0
- package/templates/qoder/scripts/setup/carriers.py +662 -0
- package/templates/qoder/scripts/{init_doctor.py → setup/init_doctor.py} +63 -26
- package/templates/qoder/scripts/{install_qoderwork.py → setup/install_qoderwork.py} +36 -26
- package/templates/qoder/scripts/{platform_doctor.py → setup/platform_doctor.py} +265 -259
- package/templates/qoder/scripts/{repo_root.py → setup/repo_root.py} +112 -106
- package/templates/qoder/scripts/{setup.py → setup/setup.py} +147 -0
- package/templates/qoder/scripts/{setup_lanhu.py → setup/setup_lanhu.py} +973 -963
- package/templates/qoder/scripts/task/__init__.py +11 -0
- package/templates/qoder/scripts/{git_sync.py → task/git_sync.py} +52 -31
- package/templates/qoder/scripts/{syncgate.py → task/syncgate.py} +6 -0
- package/templates/qoder/scripts/task/task.py +221 -0
- package/templates/qoder/scripts/task/task_lifecycle.py +596 -0
- package/templates/qoder/scripts/task/task_query.py +161 -0
- package/templates/qoder/scripts/task/task_relations.py +424 -0
- package/templates/qoder/scripts/{team_sync.py → task/team_sync.py} +93 -20
- package/templates/qoder/scripts/test/__init__.py +11 -0
- package/templates/qoder/scripts/{autotest.py → test/autotest.py} +1174 -1751
- package/templates/qoder/scripts/{autotest_batch.py → test/autotest_batch.py} +242 -224
- package/templates/qoder/scripts/test/autotest_data.py +675 -0
- package/templates/qoder/scripts/{autotest_run.py → test/autotest_run.py} +309 -297
- package/templates/qoder/scripts/{benchmark.py → test/benchmark.py} +6 -0
- package/templates/qoder/scripts/{kg_auto_login.py → test/kg_auto_login.py} +202 -196
- package/templates/qoder/scripts/{kg_test_runner.py → test/kg_test_runner.py} +7 -1
- package/templates/qoder/scripts/{page_probe.py → test/page_probe.py} +465 -459
- package/templates/qoder/scripts/wlkj.py +116 -0
- package/templates/qoder/settings.json +1 -10
- package/templates/qoder/skills/design-import/SKILL.md +226 -226
- package/templates/qoder/skills/design-review/SKILL.md +82 -82
- package/templates/qoder/skills/prd-generator/SKILL.md +26 -16
- package/templates/qoder/skills/prd-review/SKILL.md +5 -5
- package/templates/qoder/skills/prototype-generator/SKILL.md +256 -256
- package/templates/qoder/skills/spec-coder/SKILL.md +4 -4
- package/templates/qoder/skills/spec-generator/SKILL.md +4 -4
- package/templates/qoder/skills/test-generator/SKILL.md +5 -5
- package/templates/qoder/skills/wl-code/SKILL.md +4 -4
- package/templates/qoder/skills/wl-commit/SKILL.md +4 -4
- package/templates/qoder/skills/wl-design/SKILL.md +3 -3
- package/templates/qoder/skills/wl-init/SKILL.md +8 -8
- package/templates/qoder/skills/wl-insight/SKILL.md +5 -5
- package/templates/qoder/skills/wl-prd-full/SKILL.md +6 -6
- package/templates/qoder/skills/wl-prd-quick/SKILL.md +6 -6
- package/templates/qoder/skills/wl-prd-review/SKILL.md +4 -4
- package/templates/qoder/skills/wl-report/SKILL.md +7 -7
- package/templates/qoder/skills/wl-search/SKILL.md +13 -13
- package/templates/qoder/skills/wl-spec/SKILL.md +5 -5
- package/templates/qoder/skills/wl-status/SKILL.md +5 -5
- package/templates/qoder/skills/wl-task/SKILL.md +6 -6
- package/templates/qoder/skills/wl-test/SKILL.md +102 -39
- package/templates/root/AGENTS.md +39 -40
- package/templates/qoder/hooks/inject-workflow-state.py +0 -169
- package/templates/qoder/scripts/__pycache__/check_mcp_launch.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/__pycache__/install_qoderwork.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/__pycache__/mcp_launcher.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/__pycache__/platform_doctor.cpython-39.pyc +0 -0
- package/templates/qoder/scripts/check_carriers.py +0 -238
- package/templates/qoder/scripts/check_mcp_launch.py +0 -183
- package/templates/qoder/scripts/check_qoderwork_consistency.py +0 -166
- package/templates/qoder/scripts/collect_prds.py +0 -31
- package/templates/qoder/scripts/common/mentions.py +0 -134
- package/templates/qoder/scripts/common/utf8.py +0 -38
- package/templates/qoder/scripts/extract_routes.py +0 -54
- package/templates/qoder/scripts/extract_routes_tree.py +0 -78
- package/templates/qoder/scripts/handoff.py +0 -22
- package/templates/qoder/scripts/init_developer.py +0 -76
- package/templates/qoder/scripts/parse_prds.py +0 -33
- package/templates/qoder/scripts/role.py +0 -51
- package/templates/qoder/scripts/sync_carriers.py +0 -259
- package/templates/qoder/scripts/task.py +0 -1261
- package/templates/qoder/scripts/workspace_init.py +0 -102
- package/templates/qoder/skills/prompt-enrich/SKILL.md +0 -90
- package/templates/qoder/skills/prototype-generator/SKILL.md.zcode-79180-2af4721f-f9a6-412c-88db-c0af680d211b.tmp +0 -0
- /package/templates/qoder/scripts/{secure-ls.js → test/secure-ls.js} +0 -0
|
@@ -1,393 +1,420 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
def
|
|
280
|
-
"""
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# v3.0 路径自举: 引导到 common/bootstrap, 统一 sys.path 逻辑
|
|
3
|
+
import os as _o, sys as _s
|
|
4
|
+
_cp = _o.path.join(_o.path.dirname(_o.path.dirname(_o.path.abspath(__file__))), 'common')
|
|
5
|
+
if _cp not in _s.path: _s.path.insert(0, _cp)
|
|
6
|
+
from bootstrap import setup; setup()
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
Incremental UPSERT builder for the DuckDB knowledge graph.
|
|
10
|
+
|
|
11
|
+
Instead of full rebuild (build_style_index.py → kg_duckdb.py bulk_import),
|
|
12
|
+
this takes a list of changed files (from git diff) and only updates the
|
|
13
|
+
entities + edges that belong to those files.
|
|
14
|
+
|
|
15
|
+
Performance: ~0.2s per file vs 60s full rebuild.
|
|
16
|
+
For 500 changed files: ~2 minutes incremental vs 5+ minutes full rebuild.
|
|
17
|
+
|
|
18
|
+
Usage:
|
|
19
|
+
python kg_incremental.py # auto-detect changes via git diff
|
|
20
|
+
python kg_incremental.py file1.vue file2.ts # explicit file list
|
|
21
|
+
"""
|
|
22
|
+
import json
|
|
23
|
+
import os
|
|
24
|
+
import re
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
SCRIPTS = os.path.join(os.path.dirname(os.path.abspath(__file__)))
|
|
28
|
+
sys.path.insert(0, SCRIPTS)
|
|
29
|
+
|
|
30
|
+
from common.paths import DATA_INDEX_DIR, PROJECT_ROOT
|
|
31
|
+
from kg_duckdb import get_db, init_schema, upsert_entity, upsert_alias, upsert_edge, delete_edges_from
|
|
32
|
+
from common.ts_extract import ts_build_api_fn_table, ts_trace_clicks
|
|
33
|
+
from common.extract import build_api_fn_table
|
|
34
|
+
from common.test_extract import extract_test_assertions
|
|
35
|
+
|
|
36
|
+
CODE_DIR = str(PROJECT_ROOT / 'data' / 'code')
|
|
37
|
+
INDEX_DIR = str(DATA_INDEX_DIR)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _git(*args, cwd=None, timeout=None):
|
|
41
|
+
"""git 命令包装(与 git_sync._git 一致)。网络操作必传 timeout; 本地操作可不传。
|
|
42
|
+
|
|
43
|
+
返回 rc=124 表示超时, rc=127 表示 git 未安装, 不让进程崩溃或挂死。
|
|
44
|
+
"""
|
|
45
|
+
import subprocess
|
|
46
|
+
try:
|
|
47
|
+
kw = dict(cwd=cwd, capture_output=True, text=True, encoding='utf-8', errors='replace')
|
|
48
|
+
if timeout:
|
|
49
|
+
kw['timeout'] = timeout
|
|
50
|
+
return subprocess.run(['git'] + list(args), **kw)
|
|
51
|
+
except FileNotFoundError:
|
|
52
|
+
import types
|
|
53
|
+
return types.SimpleNamespace(returncode=127, stdout='', stderr='git not installed')
|
|
54
|
+
except subprocess.TimeoutExpired:
|
|
55
|
+
import types
|
|
56
|
+
return types.SimpleNamespace(returncode=124, stdout='', stderr='git {} timed out'.format(' '.join(args[:3])))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_changed_files():
|
|
60
|
+
"""Auto-detect ALL changed files since last kg_build via stored commit hash.
|
|
61
|
+
|
|
62
|
+
Records the last-built commit per project in build_meta table.
|
|
63
|
+
Next run diffs from that commit to HEAD, capturing ALL changes (not just last 2 commits).
|
|
64
|
+
"""
|
|
65
|
+
changed = []
|
|
66
|
+
if not os.path.isdir(CODE_DIR):
|
|
67
|
+
return changed
|
|
68
|
+
import subprocess
|
|
69
|
+
|
|
70
|
+
# Read last-built commits from DuckDB build_meta
|
|
71
|
+
last_commits = {}
|
|
72
|
+
try:
|
|
73
|
+
con = get_db()
|
|
74
|
+
rows = con.execute("SELECT key, value FROM build_meta WHERE key LIKE 'last_commit_%'").fetchall()
|
|
75
|
+
con.close()
|
|
76
|
+
for k, v in rows:
|
|
77
|
+
last_commits[k.replace('last_commit_', '')] = v
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
current_commits = {}
|
|
82
|
+
for proj in os.listdir(CODE_DIR):
|
|
83
|
+
proj_path = os.path.join(CODE_DIR, proj)
|
|
84
|
+
if not os.path.isdir(os.path.join(proj_path, '.git')):
|
|
85
|
+
continue
|
|
86
|
+
try:
|
|
87
|
+
# Get current HEAD (本地操作, 快速)
|
|
88
|
+
r = _git('rev-parse', 'HEAD', cwd=proj_path)
|
|
89
|
+
if r.returncode != 0:
|
|
90
|
+
continue
|
|
91
|
+
current_head = r.stdout.strip()
|
|
92
|
+
current_commits[proj] = current_head
|
|
93
|
+
|
|
94
|
+
# Determine diff range: from last-built commit to HEAD
|
|
95
|
+
last_built = last_commits.get(proj)
|
|
96
|
+
if last_built and last_built != current_head:
|
|
97
|
+
# Diff from last build to now — captures ALL changes since last build
|
|
98
|
+
diff_rev_range = ['diff', '--name-only', last_built, current_head]
|
|
99
|
+
elif not last_built:
|
|
100
|
+
# First run — get last 7 days of changes (or all if repo is new)
|
|
101
|
+
r3 = _git('log', '--since=7 days ago', '--oneline', cwd=proj_path)
|
|
102
|
+
log_lines = [l for l in r3.stdout.strip().split('\n') if l.strip()]
|
|
103
|
+
if len(log_lines) >= 2:
|
|
104
|
+
old_commit = log_lines[-1].split()[0]
|
|
105
|
+
diff_rev_range = ['diff', '--name-only', old_commit, current_head]
|
|
106
|
+
else:
|
|
107
|
+
continue # No changes or single commit
|
|
108
|
+
else:
|
|
109
|
+
continue # Already up to date, no diff needed
|
|
110
|
+
|
|
111
|
+
r2 = _git(*diff_rev_range, cwd=proj_path)
|
|
112
|
+
# P2-11: 必须判 returncode。若 diff 失败 (如 last_built commit 被 git gc
|
|
113
|
+
# 掉、对象库损坏), r2.stdout 可能是错误信息, 把它当文件名加入 changed
|
|
114
|
+
# 会让后续 _cleanup_deleted_file 误删真实文件。
|
|
115
|
+
if r2.returncode != 0:
|
|
116
|
+
continue
|
|
117
|
+
for f in r2.stdout.strip().split('\n'):
|
|
118
|
+
f = f.strip()
|
|
119
|
+
if f:
|
|
120
|
+
changed.append(os.path.join(proj_path, f.replace('/', os.sep)))
|
|
121
|
+
except Exception:
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
# Save current commits as last-built
|
|
125
|
+
try:
|
|
126
|
+
con = get_db()
|
|
127
|
+
for proj, commit in current_commits.items():
|
|
128
|
+
con.execute(
|
|
129
|
+
"INSERT OR REPLACE INTO build_meta VALUES (?, ?)",
|
|
130
|
+
['last_commit_%s' % proj, commit]
|
|
131
|
+
)
|
|
132
|
+
con.close()
|
|
133
|
+
except Exception:
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
return changed
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def incremental_update(changed_files):
|
|
140
|
+
"""Update DuckDB incrementally for a list of changed files.
|
|
141
|
+
|
|
142
|
+
For each file:
|
|
143
|
+
- .vue: re-extract trace_clicks, UPSERT button entities + click edges
|
|
144
|
+
- .ts (api): re-extract api functions, UPSERT endpoint entities
|
|
145
|
+
- .java (test): re-extract test assertions, UPSERT test entities
|
|
146
|
+
"""
|
|
147
|
+
con = get_db()
|
|
148
|
+
init_schema(con)
|
|
149
|
+
|
|
150
|
+
stats = {'vue': 0, 'ts': 0, 'java_test': 0, 'edges_updated': 0, 'entities_upserted': 0}
|
|
151
|
+
|
|
152
|
+
# 判断是否有 api 文件变更 — 决定是否需要重建 api_table
|
|
153
|
+
has_api_changes = any(
|
|
154
|
+
f.replace('\\', '/').endswith('.ts') and '/api/' in f.replace('\\', '/')
|
|
155
|
+
for f in changed_files if os.path.isfile(f)
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
api_dir = _find_api_dir()
|
|
159
|
+
|
|
160
|
+
if has_api_changes:
|
|
161
|
+
# api 文件变了 — 必须重建完整 api_table
|
|
162
|
+
api_table = ts_build_api_fn_table(api_dir) if api_dir else {}
|
|
163
|
+
# 缓存到文件, 供下次增量复用
|
|
164
|
+
if api_table and api_dir:
|
|
165
|
+
_save_api_cache(api_table, api_dir)
|
|
166
|
+
else:
|
|
167
|
+
# api 文件没变 — 从缓存加载 (毫秒级, 不扫文件系统)
|
|
168
|
+
api_table = _load_api_cache(api_dir)
|
|
169
|
+
if not api_table:
|
|
170
|
+
# 缓存不存在 (首次运行) — 重建并缓存
|
|
171
|
+
api_table = ts_build_api_fn_table(api_dir) if api_dir else {}
|
|
172
|
+
if api_table and api_dir:
|
|
173
|
+
_save_api_cache(api_table, api_dir)
|
|
174
|
+
|
|
175
|
+
for filepath in changed_files:
|
|
176
|
+
if not os.path.isfile(filepath):
|
|
177
|
+
# File was deleted — clean up its entities
|
|
178
|
+
_cleanup_deleted_file(con, filepath)
|
|
179
|
+
continue
|
|
180
|
+
|
|
181
|
+
rel_path = filepath.replace('\\', '/')
|
|
182
|
+
|
|
183
|
+
if filepath.endswith('.vue'):
|
|
184
|
+
stats['vue'] += 1
|
|
185
|
+
_update_vue_file(con, filepath, api_table, stats)
|
|
186
|
+
|
|
187
|
+
elif filepath.endswith('.ts') and '/api/' in rel_path:
|
|
188
|
+
stats['ts'] += 1
|
|
189
|
+
_update_api_file(con, filepath, stats)
|
|
190
|
+
|
|
191
|
+
elif filepath.endswith('Test.java'):
|
|
192
|
+
stats['java_test'] += 1
|
|
193
|
+
_update_test_file(con, filepath, stats)
|
|
194
|
+
|
|
195
|
+
# After file updates, refresh PRD + Wiki from git_sync's JSON output
|
|
196
|
+
_refresh_prds_and_wiki(con, stats)
|
|
197
|
+
|
|
198
|
+
con.close()
|
|
199
|
+
return stats
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _refresh_prds_and_wiki(con, stats):
|
|
203
|
+
"""Import PRD index + Wiki from git_sync's JSON output into DuckDB.
|
|
204
|
+
|
|
205
|
+
git_sync.py writes these as JSON; kg_incremental reads them and UPSERTs
|
|
206
|
+
into DuckDB so MCP tools can query them.
|
|
207
|
+
"""
|
|
208
|
+
INDEX = str(DATA_INDEX_DIR)
|
|
209
|
+
import json as _json
|
|
210
|
+
|
|
211
|
+
# PRD
|
|
212
|
+
prd_path = os.path.join(INDEX, '_build_cache', 'prd-index.json')
|
|
213
|
+
if not os.path.isfile(prd_path):
|
|
214
|
+
prd_path = os.path.join(INDEX, 'prd-index.json')
|
|
215
|
+
if os.path.isfile(prd_path):
|
|
216
|
+
try:
|
|
217
|
+
prds = _json.load(open(prd_path, encoding='utf-8'))
|
|
218
|
+
con.execute("DELETE FROM prds")
|
|
219
|
+
rows = [(f, info.get('title', ''),
|
|
220
|
+
_json.dumps(info.get('keywords', []), ensure_ascii=False),
|
|
221
|
+
_json.dumps(info.get('features', []), ensure_ascii=False),
|
|
222
|
+
_json.dumps(info.get('cn_terms', []), ensure_ascii=False))
|
|
223
|
+
for f, info in prds.items()]
|
|
224
|
+
if rows:
|
|
225
|
+
_batch_insert(con, 'prds', rows, ignore=True)
|
|
226
|
+
stats['prds_refreshed'] = len(rows)
|
|
227
|
+
except Exception:
|
|
228
|
+
pass
|
|
229
|
+
|
|
230
|
+
# Wiki
|
|
231
|
+
wiki_path = os.path.join(INDEX, 'wiki-index.json')
|
|
232
|
+
if os.path.isfile(wiki_path):
|
|
233
|
+
try:
|
|
234
|
+
wiki = _json.load(open(wiki_path, encoding='utf-8'))
|
|
235
|
+
con.execute("DELETE FROM wiki")
|
|
236
|
+
wiki_rows = []
|
|
237
|
+
for kw, entries in (wiki.get('index', {}) if isinstance(wiki, dict) else {}).items():
|
|
238
|
+
for e in (entries if isinstance(entries, list) else []):
|
|
239
|
+
wiki_rows.append((kw, e.get('project', ''), e.get('title', ''),
|
|
240
|
+
e.get('md_path', ''), e.get('description', '')))
|
|
241
|
+
if wiki_rows:
|
|
242
|
+
_batch_insert(con, 'wiki', wiki_rows)
|
|
243
|
+
stats['wiki_refreshed'] = len(wiki_rows)
|
|
244
|
+
except Exception:
|
|
245
|
+
pass
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _find_api_dir():
|
|
249
|
+
"""Find the fywl-ui api directory."""
|
|
250
|
+
apps = os.path.join(CODE_DIR, 'fywl-ui', 'apps')
|
|
251
|
+
if os.path.isdir(apps):
|
|
252
|
+
for app in os.listdir(apps):
|
|
253
|
+
candidate = os.path.join(apps, app, 'src', 'api')
|
|
254
|
+
if os.path.isdir(candidate):
|
|
255
|
+
return candidate
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _load_api_table_from_duckdb(con):
|
|
260
|
+
"""从 DuckDB 加载 api_table (api 函数名→端点), 避免重建。"""
|
|
261
|
+
table = {}
|
|
262
|
+
try:
|
|
263
|
+
rows = con.execute("SELECT id, props FROM entities WHERE type = 'ENDPOINT'").fetchall()
|
|
264
|
+
for eid, props_json in rows:
|
|
265
|
+
url = eid.replace('E:', '')
|
|
266
|
+
props = json.loads(props_json) if props_json else {}
|
|
267
|
+
fn_name = props.get('api_fn', '')
|
|
268
|
+
if fn_name:
|
|
269
|
+
table[fn_name] = {'url': url, 'verb': props.get('verb', '?'),
|
|
270
|
+
'file': props.get('source_file', '')}
|
|
271
|
+
except Exception:
|
|
272
|
+
pass
|
|
273
|
+
return table
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
_API_CACHE_PATH = os.path.join(INDEX_DIR, '.api-table-cache.json')
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _save_api_cache(api_table, api_dir):
|
|
280
|
+
"""保存 api_table 到缓存文件 (含 api_dir 的 mtime 作为失效依据)。"""
|
|
281
|
+
import time
|
|
282
|
+
cache = {
|
|
283
|
+
'api_dir_mtime': os.path.getmtime(api_dir) if os.path.isdir(api_dir) else 0,
|
|
284
|
+
'saved_at': time.time(),
|
|
285
|
+
'table': api_table,
|
|
286
|
+
}
|
|
287
|
+
with open(_API_CACHE_PATH, 'w', encoding='utf-8') as f:
|
|
288
|
+
json.dump(cache, f, ensure_ascii=False)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _load_api_cache(api_dir):
|
|
292
|
+
"""从缓存文件加载 api_table。如果缓存不存在或过期返回 {}。"""
|
|
293
|
+
if not os.path.isfile(_API_CACHE_PATH):
|
|
294
|
+
return {}
|
|
295
|
+
try:
|
|
296
|
+
cache = json.load(open(_API_CACHE_PATH, encoding='utf-8'))
|
|
297
|
+
# 检查 api_dir 的 mtime 是否变了
|
|
298
|
+
current_mtime = os.path.getmtime(api_dir) if api_dir and os.path.isdir(api_dir) else 0
|
|
299
|
+
if cache.get('api_dir_mtime') == current_mtime:
|
|
300
|
+
return cache.get('table', {})
|
|
301
|
+
except Exception:
|
|
302
|
+
pass
|
|
303
|
+
return {}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _update_vue_file(con, filepath, api_table, stats):
|
|
307
|
+
"""Re-extract traces from one Vue file and UPSERT its button entities + edges."""
|
|
308
|
+
try:
|
|
309
|
+
content = open(filepath, 'rb').read().decode('utf-8', errors='replace')
|
|
310
|
+
except Exception:
|
|
311
|
+
return
|
|
312
|
+
if '@click' not in content:
|
|
313
|
+
return
|
|
314
|
+
|
|
315
|
+
traces = ts_trace_clicks(filepath, content, api_table)
|
|
316
|
+
vue_norm = filepath.replace('\\', '/')
|
|
317
|
+
# Normalize vue_short — MUST match kg_build.py's format exactly
|
|
318
|
+
if '/views/' in vue_norm:
|
|
319
|
+
vue_short = vue_norm.split('/views/')[-1]
|
|
320
|
+
elif '/pages/' in vue_norm:
|
|
321
|
+
vue_short = vue_norm.split('/pages/')[-1]
|
|
322
|
+
else:
|
|
323
|
+
vue_short = os.path.basename(filepath)
|
|
324
|
+
|
|
325
|
+
for t in traces:
|
|
326
|
+
handler = t.get('handler', '')
|
|
327
|
+
eid = 'B:%s:%s' % (vue_short, handler)
|
|
328
|
+
# UPSERT entity (INSERT OR REPLACE, no duplicates)
|
|
329
|
+
upsert_entity(con, eid, 'BUTTON', handler, '',
|
|
330
|
+
{'button_text': t.get('button', ''),
|
|
331
|
+
'vue_file': vue_norm,
|
|
332
|
+
'confidence': t.get('confidence', '')})
|
|
333
|
+
upsert_alias(con, handler.lower(), eid)
|
|
334
|
+
stats['entities_upserted'] += 1
|
|
335
|
+
|
|
336
|
+
# Delete ALL old edges from this button first, then insert fresh
|
|
337
|
+
delete_edges_from(con, eid)
|
|
338
|
+
ep = t.get('endpoint')
|
|
339
|
+
if ep and ep != 'None':
|
|
340
|
+
to_eid = 'E:%s' % ep
|
|
341
|
+
upsert_edge(con, eid, to_eid, 'clicks', props={
|
|
342
|
+
'button': t.get('button', ''),
|
|
343
|
+
'confidence': t.get('confidence', ''),
|
|
344
|
+
})
|
|
345
|
+
stats['edges_updated'] += 1
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _update_api_file(con, filepath, stats):
|
|
349
|
+
"""Re-extract API functions from one .ts file and UPSERT endpoint entities."""
|
|
350
|
+
# Re-use the bulk api_table extraction on this single file's directory
|
|
351
|
+
api_dir = os.path.dirname(filepath)
|
|
352
|
+
file_table = build_api_fn_table(api_dir)
|
|
353
|
+
for fn_name, info in file_table.items():
|
|
354
|
+
# Only update functions defined in THIS file
|
|
355
|
+
if info.get('file', '').replace('\\', '/') != filepath.replace('\\', '/'):
|
|
356
|
+
continue
|
|
357
|
+
eid = 'E:%s' % info['url']
|
|
358
|
+
upsert_entity(con, eid, 'ENDPOINT', info['url'], '',
|
|
359
|
+
{'verb': info.get('verb', '?'),
|
|
360
|
+
'api_fn': fn_name,
|
|
361
|
+
'source_file': filepath.replace('\\', '/')})
|
|
362
|
+
upsert_alias(con, fn_name.lower(), eid)
|
|
363
|
+
stats['entities_upserted'] += 1
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _update_test_file(con, filepath, stats):
|
|
367
|
+
"""Re-extract test assertions from one Test.java and UPSERT test entities."""
|
|
368
|
+
tests = extract_test_assertions(os.path.dirname(filepath))
|
|
369
|
+
# Filter to only this file
|
|
370
|
+
file_norm = filepath.replace('\\', '/')
|
|
371
|
+
for t in tests:
|
|
372
|
+
if t.get('file', '').replace('\\', '/') != file_norm:
|
|
373
|
+
continue
|
|
374
|
+
name = '%s.%s' % (t['class'], t['method'])
|
|
375
|
+
eid = 'T:%s' % name
|
|
376
|
+
upsert_entity(con, eid, 'TEST', name, '',
|
|
377
|
+
{'display': t.get('display_name', ''),
|
|
378
|
+
'deps': t.get('injected_deps', []),
|
|
379
|
+
'assertions': t.get('assertions', []),
|
|
380
|
+
'package': t.get('package', '')})
|
|
381
|
+
upsert_alias(con, name.lower(), eid)
|
|
382
|
+
stats['entities_upserted'] += 1
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _cleanup_deleted_file(con, filepath):
|
|
386
|
+
"""Remove entities belonging to a deleted file."""
|
|
387
|
+
rel = filepath.replace('\\', '/')
|
|
388
|
+
# Delete buttons from this vue file
|
|
389
|
+
if '.vue' in rel:
|
|
390
|
+
vue_short = rel.split('/views/')[-1] if '/views/' in rel else os.path.basename(rel)
|
|
391
|
+
con.execute("DELETE FROM entities WHERE id LIKE 'B:%s:%%'" % vue_short.replace("'", "''"))
|
|
392
|
+
con.execute("DELETE FROM edges WHERE from_id LIKE 'B:%s:%%'" % vue_short.replace("'", "''"))
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
if __name__ == '__main__':
|
|
396
|
+
if len(sys.argv) > 1:
|
|
397
|
+
changed = sys.argv[1:]
|
|
398
|
+
else:
|
|
399
|
+
print('Auto-detecting changes via git diff...')
|
|
400
|
+
changed = get_changed_files()
|
|
401
|
+
|
|
402
|
+
if not changed:
|
|
403
|
+
print('No changes detected.')
|
|
404
|
+
sys.exit(0)
|
|
405
|
+
|
|
406
|
+
# Filter to relevant file types
|
|
407
|
+
relevant = [f for f in changed if f.endswith(('.vue', '.ts', '.java'))]
|
|
408
|
+
print('Changed files: %d total, %d relevant' % (len(changed), len(relevant)))
|
|
409
|
+
|
|
410
|
+
if relevant:
|
|
411
|
+
import time
|
|
412
|
+
t0 = time.time()
|
|
413
|
+
stats = incremental_update(relevant)
|
|
414
|
+
elapsed = time.time() - t0
|
|
415
|
+
print('Incremental update done in %.1fs' % elapsed)
|
|
416
|
+
print(' Vue: %d, TS: %d, Java: %d' % (stats['vue'], stats['ts'], stats['java_test']))
|
|
417
|
+
print(' Entities UPSERTed: %d' % stats['entities_upserted'])
|
|
418
|
+
print(' Edges updated: %d' % stats['edges_updated'])
|
|
419
|
+
else:
|
|
420
|
+
print('No relevant files to update.')
|