@hupan56/wlkj 3.0.0 → 3.1.2
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 +1435 -1373
- package/package.json +1 -1
- package/templates/qoder/commands/optional/wl-insight.md +6 -4
- package/templates/qoder/commands/optional/wl-report.md +20 -39
- package/templates/qoder/commands/optional/wl-status.md +4 -4
- package/templates/qoder/commands/wl-code.md +2 -2
- package/templates/qoder/commands/wl-design.md +5 -5
- package/templates/qoder/commands/wl-init.md +3 -3
- package/templates/qoder/commands/wl-prd.md +26 -13
- package/templates/qoder/commands/wl-req.md +3 -3
- package/templates/qoder/commands/wl-search.md +78 -47
- package/templates/qoder/commands/wl-task.md +343 -40
- package/templates/qoder/commands/wl-test.md +10 -10
- package/templates/qoder/config.yaml +35 -13
- package/templates/qoder/hooks/post-tool-use.py +181 -0
- package/templates/qoder/hooks/session-start.py +82 -1
- package/templates/qoder/hooks/stop-eval.py +207 -0
- package/templates/qoder/hooks/user-prompt-submit.py +139 -0
- package/templates/qoder/rules/wl-pipeline.md +70 -8
- package/templates/qoder/scripts/README.md +78 -115
- package/templates/qoder/scripts/capability/__init__.py +26 -0
- package/templates/qoder/scripts/capability/__main__.py +72 -0
- package/templates/qoder/scripts/capability/adapters/__init__.py +29 -0
- package/templates/qoder/scripts/capability/adapters/cli.py +316 -0
- package/templates/qoder/scripts/capability/adapters/mcp.py +334 -0
- package/templates/qoder/scripts/capability/adapters/qw.py +271 -0
- package/templates/qoder/scripts/capability/caps/__init__.py +27 -0
- package/templates/qoder/scripts/capability/caps/context.py +36 -0
- package/templates/qoder/scripts/capability/caps/cron.py +50 -0
- package/templates/qoder/scripts/capability/caps/identity.py +43 -0
- package/templates/qoder/scripts/capability/caps/memory.py +71 -0
- package/templates/qoder/scripts/capability/caps/notify.py +41 -0
- package/templates/qoder/scripts/capability/caps/present.py +48 -0
- package/templates/qoder/scripts/capability/caps/repo.py +31 -0
- package/templates/qoder/scripts/capability/caps/sandbox.py +43 -0
- package/templates/qoder/scripts/capability/chain.py +92 -0
- package/templates/qoder/scripts/capability/memory_chain.py +41 -0
- package/templates/qoder/scripts/capability/registry.py +246 -0
- package/templates/qoder/scripts/capability/registry_mcp.py +250 -0
- package/templates/qoder/scripts/capability/smoke_test.py +211 -0
- package/templates/qoder/scripts/capability/smoke_test_report.json +94 -0
- package/templates/qoder/scripts/{report → deployment/setup}/__init__.py +11 -11
- package/templates/qoder/scripts/{setup → deployment/setup}/carriers.py +33 -26
- package/templates/qoder/scripts/deployment/setup/carriers_verify.py +148 -0
- package/templates/qoder/scripts/{setup → deployment/setup}/init_doctor.py +40 -16
- package/templates/qoder/scripts/{setup → deployment/setup}/install_qoderwork.py +20 -12
- package/templates/qoder/scripts/{setup → deployment/setup}/platform_doctor.py +8 -2
- package/templates/qoder/scripts/{setup → deployment/setup}/repo_root.py +113 -112
- package/templates/qoder/scripts/{setup → deployment/setup}/setup.py +31 -11
- package/templates/qoder/scripts/{setup → deployment/setup}/setup_lanhu.py +13 -7
- package/templates/qoder/scripts/domain/__init__.py +0 -0
- package/templates/qoder/scripts/domain/design/__init__.py +0 -0
- package/templates/qoder/scripts/{report → domain/design}/fill_prototype.py +12 -6
- package/templates/qoder/scripts/{report → domain/design}/gen_design_doc.py +8 -2
- package/templates/qoder/scripts/{setup → domain/kg}/__init__.py +11 -11
- package/templates/qoder/scripts/domain/kg/build/__init__.py +0 -0
- package/templates/qoder/scripts/{kg → domain/kg/build}/build_entity_registry.py +7 -2
- package/templates/qoder/scripts/{kg → domain/kg/build}/build_relations.py +7 -2
- package/templates/qoder/scripts/{kg → domain/kg/build}/build_style_index.py +13 -7
- package/templates/qoder/scripts/{kg → domain/kg/build}/build_workflows.py +7 -2
- package/templates/qoder/scripts/{kg → domain/kg/build}/kg_build.py +76 -9
- package/templates/qoder/scripts/{kg → domain/kg/build}/kg_build_db.py +7 -2
- package/templates/qoder/scripts/{kg → domain/kg/build}/kg_incremental.py +11 -6
- package/templates/qoder/scripts/{report → domain/kg/build}/learn_aggregate.py +9 -4
- package/templates/qoder/scripts/domain/kg/extract/__init__.py +0 -0
- package/templates/qoder/scripts/{common → domain/kg/extract}/extract.py +430 -419
- package/templates/qoder/scripts/{common → domain/kg/extract}/test_extract.py +115 -115
- package/templates/qoder/scripts/{common → domain/kg/extract}/ts_extract.py +614 -536
- package/templates/qoder/scripts/domain/kg/graph/__init__.py +0 -0
- package/templates/qoder/scripts/{kg → domain/kg/graph}/kg_link_db.py +7 -2
- package/templates/qoder/scripts/domain/kg/graph/kg_semantic.py +683 -0
- package/templates/qoder/scripts/{kg → domain/kg}/kg.py +263 -30
- package/templates/qoder/scripts/{common → domain/kg}/kg_capabilities.py +182 -182
- package/templates/qoder/scripts/domain/kg/search/__init__.py +0 -0
- package/templates/qoder/scripts/{kg → domain/kg/search}/context_pack.py +30 -9
- package/templates/qoder/scripts/{kg → domain/kg/search}/enrich_prompt.py +10 -4
- package/templates/qoder/scripts/{kg → domain/kg/search}/prefetch.py +33 -8
- package/templates/qoder/scripts/{common → domain/kg/search}/search_engine.py +207 -205
- package/templates/qoder/scripts/{kg → domain/kg/search}/search_index.py +143 -77
- package/templates/qoder/scripts/domain/kg/server/__init__.py +0 -0
- package/templates/qoder/scripts/domain/kg/server/kgd.py +549 -0
- package/templates/qoder/scripts/domain/kg/server/perf_bench.py +197 -0
- package/templates/qoder/scripts/domain/kg/storage/__init__.py +0 -0
- package/templates/qoder/scripts/{kg → domain/kg/storage}/kg_duckdb.py +38 -14
- package/templates/qoder/scripts/domain/learning/__init__.py +0 -0
- package/templates/qoder/scripts/{report → domain/learning}/learn.py +8 -3
- package/templates/qoder/scripts/{mcp → domain/report}/__init__.py +11 -11
- package/templates/qoder/scripts/{report → domain/report}/add_session.py +9 -3
- package/templates/qoder/scripts/{report → domain/report}/export.py +10 -5
- package/templates/qoder/scripts/{report → domain/report}/report.py +9 -4
- package/templates/qoder/scripts/domain/report/report_snapshot.py +261 -0
- package/templates/qoder/scripts/{report → domain/report}/role.py +10 -4
- package/templates/qoder/scripts/{report → domain/report}/status.py +112 -9
- package/templates/qoder/scripts/domain/report/status_snapshot.py +191 -0
- package/templates/qoder/scripts/domain/requirement/__init__.py +0 -0
- package/templates/qoder/scripts/{report → domain/requirement}/archive_prd.py +8 -2
- package/templates/qoder/scripts/{report → domain/requirement}/req.py +228 -222
- package/templates/qoder/scripts/{kg → domain/task}/__init__.py +11 -11
- package/templates/qoder/scripts/{task → domain/task}/git_sync.py +40 -21
- package/templates/qoder/scripts/{task → domain/task}/syncgate.py +13 -8
- package/templates/qoder/scripts/{task → domain/task}/task.py +13 -5
- package/templates/qoder/scripts/{task → domain/task}/task_lifecycle.py +606 -596
- package/templates/qoder/scripts/{task → domain/task}/task_query.py +162 -161
- package/templates/qoder/scripts/{task → domain/task}/task_relations.py +425 -424
- package/templates/qoder/scripts/{task → domain/task}/team_sync.py +9 -4
- package/templates/qoder/scripts/domain/task/zentao_sync.py +370 -0
- package/templates/qoder/scripts/foundation/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation}/bootstrap.py +10 -10
- package/templates/qoder/scripts/foundation/core/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/core}/cmd_registry.py +1 -1
- package/templates/qoder/scripts/{common → foundation/core}/config.py +1 -1
- package/templates/qoder/scripts/{common → foundation/core}/paths.py +706 -586
- package/templates/qoder/scripts/foundation/data/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/data}/contract.py +2 -2
- package/templates/qoder/scripts/{common → foundation/data}/events.py +2 -2
- package/templates/qoder/scripts/{common → foundation/data}/result.py +1 -1
- package/templates/qoder/scripts/{common → foundation/data}/task_utils.py +427 -404
- package/templates/qoder/scripts/foundation/identity/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/identity}/check_publish.py +103 -98
- package/templates/qoder/scripts/{common → foundation/identity}/developer.py +239 -239
- package/templates/qoder/scripts/{common → foundation/identity}/guard.py +2 -2
- package/templates/qoder/scripts/{common → foundation/identity}/identity.py +14 -10
- package/templates/qoder/scripts/{common → foundation/identity}/roles.py +1 -1
- package/templates/qoder/scripts/foundation/integrations/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/integrations}/active_task.py +30 -15
- package/templates/qoder/scripts/{common → foundation/integrations}/feishu.py +2 -2
- package/templates/qoder/scripts/{common → foundation/integrations}/terms.py +3 -3
- package/templates/qoder/scripts/foundation/integrations/zentao_client.py +220 -0
- package/templates/qoder/scripts/foundation/io/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/io}/filelock.py +1 -1
- package/templates/qoder/scripts/{common → foundation/io}/reqid.py +1 -1
- package/templates/qoder/scripts/foundation/protocol/__init__.py +0 -0
- package/templates/qoder/scripts/foundation/protocol/duckdb_conn.py +39 -0
- package/templates/qoder/scripts/{common → foundation/protocol}/mcp_base.py +1 -1
- package/templates/qoder/scripts/foundation/utils/__init__.py +0 -0
- package/templates/qoder/scripts/{common → foundation/utils}/eval_api.py +12 -1
- package/templates/qoder/scripts/{common → foundation/utils}/pip_install.py +23 -6
- package/templates/qoder/scripts/{common → foundation/utils}/platform_guard.py +1 -1
- package/templates/qoder/scripts/orchestration/__init__.py +0 -0
- package/templates/qoder/scripts/orchestration/wlkj.py +185 -0
- package/templates/qoder/scripts/protocol/__init__.py +0 -0
- package/templates/qoder/scripts/protocol/browser/README.md +207 -0
- package/templates/qoder/scripts/protocol/browser/SKILL.md +265 -0
- package/templates/qoder/scripts/protocol/browser/config.env +9 -0
- package/templates/qoder/scripts/protocol/browser/references/cdp-api.md +110 -0
- package/templates/qoder/scripts/protocol/browser/references/migration-2.5.3.md +72 -0
- package/templates/qoder/scripts/protocol/browser/references/site-patterns/.gitkeep +0 -0
- package/templates/qoder/scripts/protocol/browser/scripts/browser-discovery.mjs +138 -0
- package/templates/qoder/scripts/protocol/browser/scripts/cdp-proxy.mjs +672 -0
- package/templates/qoder/scripts/protocol/browser/scripts/check-deps.mjs +206 -0
- package/templates/qoder/scripts/protocol/browser/scripts/find-url.mjs +253 -0
- package/templates/qoder/scripts/protocol/browser/scripts/match-site.mjs +46 -0
- package/templates/qoder/scripts/protocol/browser/templates/config.env.template +9 -0
- package/templates/qoder/scripts/protocol/mcp/__init__.py +11 -0
- package/templates/qoder/scripts/protocol/mcp/kg_mcp_server.py +478 -0
- package/templates/qoder/scripts/{mcp → protocol/mcp}/lanhu_stdio_wrapper.py +11 -5
- package/templates/qoder/scripts/{mcp → protocol/mcp}/mcp_doctor.py +47 -14
- package/templates/qoder/scripts/protocol/mcp/mcp_launcher.py +600 -0
- package/templates/qoder/scripts/{mcp → protocol/mcp}/mysql_mcp_server.py +181 -67
- package/templates/qoder/scripts/protocol/mcp/zentao_mcp_server.py +1920 -0
- package/templates/qoder/scripts/protocol/transports/__init__.py +56 -0
- package/templates/qoder/scripts/protocol/transports/base.py +87 -0
- package/templates/qoder/scripts/protocol/transports/cli.py +132 -0
- package/templates/qoder/scripts/protocol/transports/http.py +141 -0
- package/templates/qoder/scripts/protocol/transports/stdio.py +293 -0
- package/templates/qoder/scripts/run_weekly_update.bat +27 -18
- package/templates/qoder/scripts/run_weekly_update.sh +22 -13
- package/templates/qoder/scripts/validation/__init__.py +0 -0
- package/templates/qoder/scripts/validation/eval/__init__.py +0 -0
- package/templates/qoder/scripts/validation/eval/perf-report-2026-06-24.md +139 -0
- package/templates/qoder/scripts/validation/eval/qwork_harness.py +617 -0
- package/templates/qoder/scripts/validation/eval/report-commands.md +220 -0
- package/templates/qoder/scripts/validation/eval/transcript_timing.py +386 -0
- package/templates/qoder/scripts/validation/metrics/__init__.py +0 -0
- package/templates/qoder/scripts/{report → validation/metrics}/eval_prd.py +17 -10
- package/templates/qoder/scripts/validation/metrics/usability_score.py +750 -0
- package/templates/qoder/scripts/validation/test/__init__.py +11 -0
- package/templates/qoder/scripts/validation/test/assertion_gen.py +551 -0
- package/templates/qoder/scripts/{test → validation/test}/autotest.py +64 -4
- package/templates/qoder/scripts/{common → validation/test}/autotest_auth.py +1 -1
- package/templates/qoder/scripts/{test → validation/test}/autotest_batch.py +16 -3
- package/templates/qoder/scripts/{test → validation/test}/autotest_data.py +17 -12
- package/templates/qoder/scripts/validation/test/autotest_opencli.py +646 -0
- package/templates/qoder/scripts/{test → validation/test}/autotest_run.py +17 -3
- package/templates/qoder/scripts/validation/test/autotest_webaccess.py +571 -0
- package/templates/qoder/scripts/{test → validation/test}/benchmark.py +12 -6
- package/templates/qoder/scripts/{test → validation/test}/kg_auto_login.py +8 -2
- package/templates/qoder/scripts/{test → validation/test}/kg_test_runner.py +7 -2
- package/templates/qoder/scripts/{test → validation/test}/page_probe.py +8 -3
- package/templates/qoder/scripts/validation/test/smoke_all_commands.py +170 -0
- package/templates/qoder/settings.json +30 -0
- package/templates/qoder/skills/design-import/SKILL.md +22 -13
- package/templates/qoder/skills/design-review/SKILL.md +19 -10
- package/templates/qoder/skills/prd-generator/SKILL.md +22 -18
- package/templates/qoder/skills/prd-review/SKILL.md +6 -4
- package/templates/qoder/skills/prototype-generator/SKILL.md +63 -14
- package/templates/qoder/skills/spec-coder/SKILL.md +22 -13
- package/templates/qoder/skills/spec-generator/SKILL.md +22 -10
- package/templates/qoder/skills/test-generator/SKILL.md +7 -5
- package/templates/qoder/skills/wl-code/SKILL.md +23 -11
- package/templates/qoder/skills/wl-commit/SKILL.md +9 -8
- package/templates/qoder/skills/wl-design/SKILL.md +5 -3
- package/templates/qoder/skills/wl-init/SKILL.md +6 -6
- package/templates/qoder/skills/wl-insight/SKILL.md +23 -10
- package/templates/qoder/skills/wl-prd-full/SKILL.md +57 -6
- package/templates/qoder/skills/wl-prd-quick/SKILL.md +3 -3
- package/templates/qoder/skills/wl-prd-review/SKILL.md +16 -4
- package/templates/qoder/skills/wl-report/SKILL.md +25 -23
- package/templates/qoder/skills/wl-search/SKILL.md +149 -78
- package/templates/qoder/skills/wl-spec/SKILL.md +7 -5
- package/templates/qoder/skills/wl-status/SKILL.md +48 -16
- package/templates/qoder/skills/wl-task/SKILL.md +92 -10
- package/templates/qoder/skills/wl-test/SKILL.md +75 -29
- package/templates/qoder/templates/prd-full-template.md +7 -0
- package/templates/root/AGENTS.md +275 -236
- package/templates/root/requirements.txt +3 -0
- package/templates/root//344/275/277/347/224/250/350/257/264/346/230/216.md +3 -3
- package/templates/root//346/226/260/346/211/213/346/214/207/345/215/227.md +2 -2
- package/templates/.qoder/.runtime/ctx-cache-5660152f1d6dd819.md +0 -23
- package/templates/.qoder/.runtime/ctx-cache-afdce0dac06b25b0.md +0 -23
- package/templates/.qoder/.runtime/search-cache-eae7644e7b122f35.txt +0 -1
- package/templates/.qoder/learning/eval-history.jsonl +0 -28
- package/templates/data/index/wiki-index.json +0 -8
- package/templates/qoder/nul +0 -4
- package/templates/qoder/scripts/kg/extract.py +0 -398
- package/templates/qoder/scripts/kg/kg_semantic.py +0 -156
- package/templates/qoder/scripts/mcp/kg_mcp_server.py +0 -606
- package/templates/qoder/scripts/mcp/mcp_launcher.py +0 -442
- package/templates/qoder/scripts/mcp/zentao_mcp_server.py +0 -384
- package/templates/qoder/scripts/task/__init__.py +0 -11
- package/templates/qoder/scripts/test/__init__.py +0 -11
- package/templates/qoder/scripts/wlkj.py +0 -116
- /package/templates/qoder/scripts/{common → deployment}/__init__.py +0 -0
- /package/templates/qoder/scripts/{common → domain/kg/graph}/graph_traverse.py +0 -0
- /package/templates/qoder/scripts/{common → domain/kg/server}/repowiki.py +0 -0
- /package/templates/qoder/scripts/{common → foundation/io}/atomicio.py +0 -0
- /package/templates/qoder/scripts/{test → validation/test}/secure-ls.js +0 -0
|
@@ -1,596 +1,606 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""task_lifecycle.py - task 生命周期层 (v3.0 f6 从 task.py 拆出)"""
|
|
4
|
-
# v3.0 路径自举
|
|
5
|
-
import os as _o, sys as _s, argparse
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from datetime import datetime
|
|
8
|
-
_cp = _o.path.join(_o.path.dirname(_o.path.dirname(_o.path.abspath(__file__))), '
|
|
9
|
-
if _cp not in _s.path: _s.path.insert(0, _cp)
|
|
10
|
-
from bootstrap import setup; setup()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from
|
|
15
|
-
from
|
|
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
|
-
print(f"
|
|
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
|
-
data["
|
|
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
|
-
print(active.
|
|
222
|
-
return 0
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
data["
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
if
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
'
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
'',
|
|
453
|
-
'
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
'
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
""
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
print(
|
|
558
|
-
return
|
|
559
|
-
|
|
560
|
-
#
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""task_lifecycle.py - task 生命周期层 (v3.0 f6 从 task.py 拆出)"""
|
|
4
|
+
# v3.0 路径自举
|
|
5
|
+
import os as _o, sys as _s, argparse
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
_cp = _o.path.join(_o.path.dirname(_o.path.dirname(_o.path.abspath(__file__))), 'foundation')
|
|
9
|
+
if _cp not in _s.path: _s.path.insert(0, _cp)
|
|
10
|
+
from bootstrap import setup; setup()
|
|
11
|
+
from foundation.core.paths import get_repo_root
|
|
12
|
+
|
|
13
|
+
import os, sys, json, shutil
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from foundation.core.paths import (
|
|
17
|
+
DIR_TASKS, DIR_ARCHIVE, FILE_TASK_JSON,
|
|
18
|
+
get_repo_root, get_developer, get_tasks_dir,
|
|
19
|
+
)
|
|
20
|
+
from foundation.integrations.active_task import (
|
|
21
|
+
clear_active_task, resolve_active_task, resolve_context_key, set_active_task,
|
|
22
|
+
)
|
|
23
|
+
from foundation.data.task_utils import (
|
|
24
|
+
resolve_task_dir, run_task_hooks, load_task_json, write_task_json,
|
|
25
|
+
modify_task_json, assert_can_modify_task,
|
|
26
|
+
)
|
|
27
|
+
from foundation.io.atomicio import atomic_write_json, safe_read_json, atomic_write_text
|
|
28
|
+
from task_relations import _generate_slug
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def cmd_create(args: argparse.Namespace) -> int:
|
|
32
|
+
"""创建新任务。
|
|
33
|
+
|
|
34
|
+
创建:
|
|
35
|
+
- .qoder/tasks/<slug>/ 目录
|
|
36
|
+
- task.json (元数据)
|
|
37
|
+
- prd.md (空模板)
|
|
38
|
+
- implement.jsonl (实现上下文, 空文件)
|
|
39
|
+
- check.jsonl (检查上下文, 空文件)
|
|
40
|
+
"""
|
|
41
|
+
repo_root = get_repo_root()
|
|
42
|
+
title = args.title
|
|
43
|
+
slug = args.slug or _generate_slug(title)
|
|
44
|
+
assignee = args.assignee or get_developer(repo_root)
|
|
45
|
+
priority = args.priority or "P2"
|
|
46
|
+
|
|
47
|
+
# 生成日期前缀: MM-DD
|
|
48
|
+
date_prefix = datetime.now().strftime("%m-%d")
|
|
49
|
+
task_dir_name = f"{date_prefix}-{slug}"
|
|
50
|
+
|
|
51
|
+
tasks_dir = get_tasks_dir(repo_root)
|
|
52
|
+
task_dir = tasks_dir / task_dir_name
|
|
53
|
+
|
|
54
|
+
# 撞名处理: 同日同名 (两个 PM 都建"登录优化") 自动加 creator 后缀, 不阻塞
|
|
55
|
+
if task_dir.exists():
|
|
56
|
+
creator_tag = (assignee or "x")[:8]
|
|
57
|
+
# 加 creator 短标记; 仍撞则加 -2/-3
|
|
58
|
+
candidate = f"{date_prefix}-{slug}-{creator_tag}"
|
|
59
|
+
n = 2
|
|
60
|
+
while (tasks_dir / candidate).exists():
|
|
61
|
+
candidate = f"{date_prefix}-{slug}-{creator_tag}-{n}"
|
|
62
|
+
n += 1
|
|
63
|
+
if n > 99: # 防御性上限
|
|
64
|
+
print(f"Error: Task name collision exhausted: {slug}", file=sys.stderr)
|
|
65
|
+
return 1
|
|
66
|
+
task_dir_name = candidate
|
|
67
|
+
task_dir = tasks_dir / task_dir_name
|
|
68
|
+
print(f"Note: 同名任务已存在, 自动加后缀: {task_dir_name}")
|
|
69
|
+
|
|
70
|
+
# 创建目录
|
|
71
|
+
task_dir.mkdir(parents=True, exist_ok=True)
|
|
72
|
+
|
|
73
|
+
# 创建 task.json
|
|
74
|
+
now_iso = datetime.now().isoformat()
|
|
75
|
+
task_data = {
|
|
76
|
+
"title": title,
|
|
77
|
+
"slug": slug,
|
|
78
|
+
"status": "planning",
|
|
79
|
+
"priority": priority,
|
|
80
|
+
"assignee": assignee,
|
|
81
|
+
"creator": assignee,
|
|
82
|
+
"created_at": now_iso,
|
|
83
|
+
"updated_at": now_iso,
|
|
84
|
+
# 关联需求 (PRD↔Task 串联键, 用于可用性指标 F1 闭环率; 旧 task.json 无此字段, 读时默认 None)
|
|
85
|
+
"req_id": getattr(args, 'req_id', None),
|
|
86
|
+
"branch": None,
|
|
87
|
+
"base_branch": None,
|
|
88
|
+
"scope": None,
|
|
89
|
+
"parent": None,
|
|
90
|
+
"children": [],
|
|
91
|
+
"tags": [],
|
|
92
|
+
# B1 能力增强字段 (向后兼容: 旧 task.json 不含这些, 读时取默认值)
|
|
93
|
+
"due_date": None, # 截止日期 YYYY-MM-DD (可选)
|
|
94
|
+
"start_date": None, # 开始日期 YYYY-MM-DD (可选)
|
|
95
|
+
"estimate_hours": None, # 预估工时 (可选)
|
|
96
|
+
"blocked_by": [], # 依赖的任务 (数组, 自动维护反向 blocks)
|
|
97
|
+
"blocks": [], # 被哪些任务依赖 (自动维护)
|
|
98
|
+
# B3 阶段时间戳 (周期时间分析用)
|
|
99
|
+
"stage_ts": {
|
|
100
|
+
"created": now_iso,
|
|
101
|
+
"started": None, # cmd_start 时填
|
|
102
|
+
"completed": None, # cmd_finish 时填
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
write_task_json(task_dir, task_data)
|
|
106
|
+
|
|
107
|
+
# 创建 prd.md 模板
|
|
108
|
+
prd_file = task_dir / "prd.md"
|
|
109
|
+
prd_content = f"""# PRD: {title}
|
|
110
|
+
|
|
111
|
+
> Status: planning
|
|
112
|
+
> Assignee: {assignee or 'unassigned'}
|
|
113
|
+
> Priority: {priority}
|
|
114
|
+
> Created: {datetime.now().strftime("%Y-%m-%d %H:%M")}
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Background
|
|
119
|
+
|
|
120
|
+
<!-- Describe the business context -->
|
|
121
|
+
|
|
122
|
+
## Requirements
|
|
123
|
+
|
|
124
|
+
<!-- List functional requirements -->
|
|
125
|
+
|
|
126
|
+
## Acceptance Criteria
|
|
127
|
+
|
|
128
|
+
<!-- Define testable acceptance criteria -->
|
|
129
|
+
|
|
130
|
+
## Notes
|
|
131
|
+
|
|
132
|
+
<!-- Additional notes -->
|
|
133
|
+
"""
|
|
134
|
+
prd_file.write_text(prd_content, encoding="utf-8")
|
|
135
|
+
|
|
136
|
+
# 创建空的 JSONL 上下文文件
|
|
137
|
+
(task_dir / "implement.jsonl").write_text("", encoding="utf-8")
|
|
138
|
+
(task_dir / "check.jsonl").write_text("", encoding="utf-8")
|
|
139
|
+
|
|
140
|
+
print(f"Task created: {task_dir_name}")
|
|
141
|
+
print(f" Title: {title}")
|
|
142
|
+
print(f" Assignee: {assignee or 'unassigned'}")
|
|
143
|
+
print(f" Priority: {priority}")
|
|
144
|
+
print(f" Path: workspace/tasks/{task_dir_name}")
|
|
145
|
+
|
|
146
|
+
# 运行 after_create 钩子
|
|
147
|
+
run_task_hooks("after_create", task_dir / FILE_TASK_JSON, repo_root)
|
|
148
|
+
|
|
149
|
+
return 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# =============================================================================
|
|
153
|
+
# 命令: start
|
|
154
|
+
# =============================================================================
|
|
155
|
+
|
|
156
|
+
def cmd_start(args: argparse.Namespace) -> int:
|
|
157
|
+
"""设置活跃任务, 状态改为 in_progress。"""
|
|
158
|
+
repo_root = get_repo_root()
|
|
159
|
+
task_input = args.dir
|
|
160
|
+
|
|
161
|
+
if not task_input:
|
|
162
|
+
print("Error: task directory or name required", file=sys.stderr)
|
|
163
|
+
return 1
|
|
164
|
+
|
|
165
|
+
full_path = resolve_task_dir(task_input, repo_root)
|
|
166
|
+
|
|
167
|
+
if not full_path.is_dir():
|
|
168
|
+
print(f"Error: Task not found: {task_input}", file=sys.stderr)
|
|
169
|
+
return 1
|
|
170
|
+
|
|
171
|
+
# 零信任 ACL: 只有 creator/assignee/admin 能 start
|
|
172
|
+
try:
|
|
173
|
+
assert_can_modify_task(full_path, "start", repo_root)
|
|
174
|
+
except PermissionError as e:
|
|
175
|
+
print(str(e), file=sys.stderr)
|
|
176
|
+
return 4 # authz_denied
|
|
177
|
+
|
|
178
|
+
# 转为相对路径
|
|
179
|
+
try:
|
|
180
|
+
task_dir = full_path.relative_to(repo_root).as_posix()
|
|
181
|
+
except ValueError:
|
|
182
|
+
task_dir = str(full_path)
|
|
183
|
+
|
|
184
|
+
# 设置活跃任务
|
|
185
|
+
active = set_active_task(task_dir, repo_root)
|
|
186
|
+
if active:
|
|
187
|
+
print(f"Current task set to: {task_dir}")
|
|
188
|
+
print(f"Source: {active.source}")
|
|
189
|
+
|
|
190
|
+
# 更新 task.json 状态 (锁内 load-modify-write, 防并发丢更新)
|
|
191
|
+
def _start_mutator(data):
|
|
192
|
+
if data.get("status") == "planning":
|
|
193
|
+
now_iso = datetime.now().isoformat()
|
|
194
|
+
data["status"] = "in_progress"
|
|
195
|
+
data["updated_at"] = now_iso
|
|
196
|
+
stage_ts = data.get("stage_ts") or {}
|
|
197
|
+
stage_ts["started"] = now_iso
|
|
198
|
+
data["stage_ts"] = stage_ts
|
|
199
|
+
print("Status: planning -> in_progress")
|
|
200
|
+
modify_task_json(full_path, _start_mutator)
|
|
201
|
+
|
|
202
|
+
# 运行 after_start 钩子
|
|
203
|
+
run_task_hooks("after_start", full_path / FILE_TASK_JSON, repo_root)
|
|
204
|
+
return 0
|
|
205
|
+
else:
|
|
206
|
+
print("Error: Failed to set current task", file=sys.stderr)
|
|
207
|
+
return 1
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# =============================================================================
|
|
211
|
+
# 命令: current
|
|
212
|
+
# =============================================================================
|
|
213
|
+
|
|
214
|
+
def cmd_current(args: argparse.Namespace) -> int:
|
|
215
|
+
"""显示当前活跃任务。"""
|
|
216
|
+
repo_root = get_repo_root()
|
|
217
|
+
active = resolve_active_task(repo_root)
|
|
218
|
+
|
|
219
|
+
if args.source:
|
|
220
|
+
print(f"Current task: {active.task_path or '(none)'}")
|
|
221
|
+
print(f"Source: {active.source}")
|
|
222
|
+
return 0 if active.task_path else 1
|
|
223
|
+
|
|
224
|
+
if active.task_path:
|
|
225
|
+
print(active.task_path)
|
|
226
|
+
return 0
|
|
227
|
+
|
|
228
|
+
print("No active task", file=sys.stderr)
|
|
229
|
+
return 1
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# =============================================================================
|
|
233
|
+
# 命令: finish
|
|
234
|
+
# =============================================================================
|
|
235
|
+
|
|
236
|
+
def cmd_finish(args: argparse.Namespace) -> int:
|
|
237
|
+
"""完成当前任务 (状态改为 completed, 清除活跃任务指针)。"""
|
|
238
|
+
repo_root = get_repo_root()
|
|
239
|
+
# 先只读解析活跃任务 (resolve_active_task 不删指针), 做 ACL 校验;
|
|
240
|
+
# 校验通过后才 clear_active_task。否则 ACL 失败时指针已丢、status 没改,
|
|
241
|
+
# 用户必须重新 start 才能恢复活跃任务 (误触/会话被他人接手时尤其痛)。
|
|
242
|
+
active = resolve_active_task(repo_root)
|
|
243
|
+
current = active.task_path
|
|
244
|
+
|
|
245
|
+
if not current:
|
|
246
|
+
print("No current task set")
|
|
247
|
+
return 0
|
|
248
|
+
|
|
249
|
+
task_dir = repo_root / current
|
|
250
|
+
|
|
251
|
+
# 零信任 ACL: 只有 creator/assignee/admin 能 finish (先校验, 再清指针)
|
|
252
|
+
try:
|
|
253
|
+
assert_can_modify_task(task_dir, "finish", repo_root)
|
|
254
|
+
except PermissionError as e:
|
|
255
|
+
print(str(e), file=sys.stderr)
|
|
256
|
+
# active 指针未动, status 未改 —— 用户可重新 start 或由正确的人 finish
|
|
257
|
+
return 4 # authz_denied
|
|
258
|
+
|
|
259
|
+
# ACL 通过, 现在才安全地清除活跃任务指针
|
|
260
|
+
cleared = clear_active_task(repo_root)
|
|
261
|
+
print(f"Cleared current task (was: {cleared.task_path})")
|
|
262
|
+
print(f"Source: {cleared.source}")
|
|
263
|
+
|
|
264
|
+
# 锁内 load-modify-write, 防并发丢更新; 副作用 (飞书) 在锁外做
|
|
265
|
+
_finish_ctx = {}
|
|
266
|
+
def _finish_mutator(data):
|
|
267
|
+
if data.get("status") != "completed":
|
|
268
|
+
now_iso = datetime.now().isoformat()
|
|
269
|
+
data["status"] = "completed"
|
|
270
|
+
data["updated_at"] = now_iso
|
|
271
|
+
stage_ts = data.get("stage_ts") or {}
|
|
272
|
+
stage_ts["completed"] = now_iso
|
|
273
|
+
data["stage_ts"] = stage_ts
|
|
274
|
+
print("Status: -> completed")
|
|
275
|
+
_finish_ctx["now_iso"] = now_iso
|
|
276
|
+
_finish_ctx["stage_ts"] = stage_ts
|
|
277
|
+
_finish_ctx["assignee"] = data.get("assignee", "?")
|
|
278
|
+
# 算真实周期耗时 (小时): started -> completed, 供埋点用
|
|
279
|
+
started = stage_ts.get("started")
|
|
280
|
+
_finish_ctx["cycle_hours"] = None
|
|
281
|
+
if started:
|
|
282
|
+
try:
|
|
283
|
+
t_start = datetime.fromisoformat(started)
|
|
284
|
+
t_end = datetime.fromisoformat(now_iso)
|
|
285
|
+
_finish_ctx["cycle_hours"] = round(
|
|
286
|
+
(t_end - t_start).total_seconds() / 3600, 2)
|
|
287
|
+
except (ValueError, TypeError):
|
|
288
|
+
pass
|
|
289
|
+
modify_task_json(task_dir, _finish_mutator)
|
|
290
|
+
|
|
291
|
+
# D2: 飞书通知 (任务完成) —— 在锁外, 用 mutator 捕获的值
|
|
292
|
+
if _finish_ctx:
|
|
293
|
+
try:
|
|
294
|
+
from foundation.integrations.feishu import notify_task_finished
|
|
295
|
+
notify_task_finished(task_dir.name, _finish_ctx["assignee"], _finish_ctx.get("cycle_hours"))
|
|
296
|
+
except Exception:
|
|
297
|
+
pass # 飞书失败不阻塞任务完成
|
|
298
|
+
|
|
299
|
+
task_json_path = task_dir / FILE_TASK_JSON
|
|
300
|
+
if task_json_path.is_file():
|
|
301
|
+
run_task_hooks("after_finish", task_json_path, repo_root)
|
|
302
|
+
|
|
303
|
+
# 🧩 测试交接画像 (可选增强): finish 后在任务目录生成 test-handoff.md,
|
|
304
|
+
# 列出涉及的页面/按钮/接口, 供测试人员照着写用例。失败绝不阻塞任务完成。
|
|
305
|
+
try:
|
|
306
|
+
_generate_test_handoff(task_dir, repo_root)
|
|
307
|
+
except Exception as e:
|
|
308
|
+
print("[测试交接画像] 跳过 (不阻塞): " + str(e)[:80])
|
|
309
|
+
|
|
310
|
+
# 埋点: 任务完成反馈给 learning 引擎 (含真实周期耗时, 供可用性指标)
|
|
311
|
+
if _finish_ctx:
|
|
312
|
+
try:
|
|
313
|
+
# learn.py 在 domain/learning/, bootstrap 只注入一层子目录, 这里补上
|
|
314
|
+
_learn_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'learning')
|
|
315
|
+
if _learn_dir not in sys.path:
|
|
316
|
+
sys.path.insert(0, _learn_dir)
|
|
317
|
+
from learn import record_feedback
|
|
318
|
+
record_feedback('task_completed', {
|
|
319
|
+
'task': task_dir.name,
|
|
320
|
+
'assignee': _finish_ctx.get('assignee', '?'),
|
|
321
|
+
# cycle_hours = started->completed 的真实小时数 (None=未start直接finish)
|
|
322
|
+
'cycle_hours': _finish_ctx.get('cycle_hours'),
|
|
323
|
+
})
|
|
324
|
+
except Exception:
|
|
325
|
+
pass # 埋点失败不阻塞任务完成
|
|
326
|
+
|
|
327
|
+
return 0
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _extract_keywords(task_dir: Path) -> list:
|
|
331
|
+
"""从任务目录名 + task.json 标题 + PRD 正文提取业务关键词。
|
|
332
|
+
返回去重的关键词列表 (用于 page_probe 查页面画像)。
|
|
333
|
+
"""
|
|
334
|
+
kws = []
|
|
335
|
+
# 1. 任务目录名: 06-11-智能排班-环卫行业 → 智能排班, 环卫行业
|
|
336
|
+
dirname = task_dir.name
|
|
337
|
+
# 去掉日期前缀 (MM-DD- 或 MM-DD-)
|
|
338
|
+
parts = dirname.split('-')
|
|
339
|
+
# 找到第一个非纯数字段开始
|
|
340
|
+
biz_parts = []
|
|
341
|
+
started = False
|
|
342
|
+
for p in parts:
|
|
343
|
+
if not started:
|
|
344
|
+
if p.isdigit() and len(p) <= 2:
|
|
345
|
+
continue # 跳过 MM, DD
|
|
346
|
+
started = True
|
|
347
|
+
if p.strip():
|
|
348
|
+
biz_parts.append(p.strip())
|
|
349
|
+
if biz_parts:
|
|
350
|
+
kws.append(''.join(biz_parts)) # 整体: 智能排班环卫行业
|
|
351
|
+
if len(biz_parts) > 1:
|
|
352
|
+
kws.extend(biz_parts) # 分开: 智能排班, 环卫行业
|
|
353
|
+
|
|
354
|
+
# 2. task.json 的 title 字段
|
|
355
|
+
title = ''
|
|
356
|
+
try:
|
|
357
|
+
tj = task_dir / FILE_TASK_JSON
|
|
358
|
+
if tj.is_file():
|
|
359
|
+
data = load_task_json(task_dir) or {}
|
|
360
|
+
title = data.get('title', '')
|
|
361
|
+
if title and title not in kws:
|
|
362
|
+
kws.append(title)
|
|
363
|
+
except Exception:
|
|
364
|
+
pass
|
|
365
|
+
|
|
366
|
+
# 2.5 从标题/目录名里切出短业务词 (保险异常筛选 → 保险, 异常, 筛选)
|
|
367
|
+
# page_probe 用 LIKE 查 vue 路径, 短词命中率更高
|
|
368
|
+
import re
|
|
369
|
+
cn_chunks = re.findall(r'[\u4e00-\u9fa5]+', (dirname + title))
|
|
370
|
+
short_words = set()
|
|
371
|
+
for chunk in cn_chunks:
|
|
372
|
+
# 2-4 字的连续子串都是有意义的业务词候选
|
|
373
|
+
if 2 <= len(chunk) <= 4:
|
|
374
|
+
short_words.add(chunk)
|
|
375
|
+
elif len(chunk) > 4:
|
|
376
|
+
# 长词切前4字、后4字、中间4字 (覆盖"智能排班系统"→智能排班/排班系统)
|
|
377
|
+
short_words.add(chunk[:4])
|
|
378
|
+
short_words.add(chunk[-4:])
|
|
379
|
+
# 去太泛的词
|
|
380
|
+
generic = {'功能', '系统', '管理', '模块', '页面', '需求', '设计', '实现',
|
|
381
|
+
'新增', '修改', '查询', '删除', '操作', '记录', '列表', '详情'}
|
|
382
|
+
for w in short_words:
|
|
383
|
+
if w not in generic and w not in kws:
|
|
384
|
+
kws.append(w)
|
|
385
|
+
|
|
386
|
+
# 3. PRD 正文里的业务关键词 (从标题和需求段落粗提)
|
|
387
|
+
try:
|
|
388
|
+
prd = task_dir / 'prd.md'
|
|
389
|
+
if prd.is_file():
|
|
390
|
+
content = prd.read_text(encoding='utf-8', errors='ignore')
|
|
391
|
+
import re
|
|
392
|
+
# 提取中文词组 (2-6 字连续中文)
|
|
393
|
+
cn_words = re.findall(r'[\u4e00-\u9fa5]{2,6}', content)
|
|
394
|
+
# 去停用词 + 高频词
|
|
395
|
+
stop = {'功能', '需求', '系统', '页面', '数据', '支持', '可以',
|
|
396
|
+
'进行', '操作', '显示', '一个', '这个', '实现', '业务',
|
|
397
|
+
'测试', '使用', '如果', '需要', '必须', '以及', '界面'}
|
|
398
|
+
from collections import Counter
|
|
399
|
+
freq = Counter(w for w in cn_words if w not in stop)
|
|
400
|
+
for w, _ in freq.most_common(5):
|
|
401
|
+
if w not in kws and len(w) >= 2:
|
|
402
|
+
kws.append(w)
|
|
403
|
+
except Exception:
|
|
404
|
+
pass
|
|
405
|
+
|
|
406
|
+
# 去重保序, 过滤太短的
|
|
407
|
+
seen = set()
|
|
408
|
+
result = []
|
|
409
|
+
for k in kws:
|
|
410
|
+
if k and len(k) >= 2 and k not in seen:
|
|
411
|
+
seen.add(k)
|
|
412
|
+
result.append(k)
|
|
413
|
+
return result[:6] # 最多 6 个, 避免查太多
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def _generate_test_handoff(task_dir: Path, repo_root) -> None:
|
|
417
|
+
"""finish 后生成 test-handoff.md (开发→测试交接画像)。
|
|
418
|
+
从任务关键词查页面按钮+接口画像, 写入任务目录。无图谱/无匹配则跳过。
|
|
419
|
+
"""
|
|
420
|
+
try:
|
|
421
|
+
import page_probe
|
|
422
|
+
except ImportError:
|
|
423
|
+
sys.path.insert(0, str(repo_root / '.qoder' / 'scripts'))
|
|
424
|
+
import page_probe
|
|
425
|
+
|
|
426
|
+
kws = _extract_keywords(task_dir)
|
|
427
|
+
if not kws:
|
|
428
|
+
print("[测试交接画像] 跳过: 任务无明确业务关键词")
|
|
429
|
+
return
|
|
430
|
+
|
|
431
|
+
# 用每个关键词查画像, 合并结果
|
|
432
|
+
all_pages = []
|
|
433
|
+
seen_vue = set()
|
|
434
|
+
used_kws = []
|
|
435
|
+
for kw in kws:
|
|
436
|
+
profile = page_probe.build_page_profile(keyword=kw, repo_root=str(repo_root))
|
|
437
|
+
if not profile.get('ok'):
|
|
438
|
+
continue
|
|
439
|
+
for pg in profile['pages']:
|
|
440
|
+
if pg['vue_file'] in seen_vue:
|
|
441
|
+
continue
|
|
442
|
+
seen_vue.add(pg['vue_file'])
|
|
443
|
+
all_pages.append(pg)
|
|
444
|
+
used_kws.append(kw)
|
|
445
|
+
if len(all_pages) >= 12: # 够多了, 停止查更多关键词
|
|
446
|
+
break
|
|
447
|
+
|
|
448
|
+
handoff_path = task_dir / 'test-handoff.md'
|
|
449
|
+
if not all_pages:
|
|
450
|
+
# 没匹配到页面: 写一个提示性 handoff (让测试知道开发想覆盖什么)
|
|
451
|
+
lines = [
|
|
452
|
+
'# 测试交接: %s' % task_dir.name,
|
|
453
|
+
'',
|
|
454
|
+
'> 任务完成于 %s' % datetime.now().strftime('%Y-%m-%d %H:%M'),
|
|
455
|
+
'> 业务关键词: %s' % ', '.join(kws),
|
|
456
|
+
'',
|
|
457
|
+
'## ⚠️ 未能自动生成页面画像',
|
|
458
|
+
'',
|
|
459
|
+
'知识图谱里没有匹配这些关键词的页面按钮记录。可能原因:',
|
|
460
|
+
'- 功能是全新的, 代码还没被知识图谱索引',
|
|
461
|
+
'- 关键词与代码里的命名不一致',
|
|
462
|
+
'',
|
|
463
|
+
'**测试建议:** 手动确认涉及的页面, 或用 `autotest.py page --kw <准确关键词>` 重试。',
|
|
464
|
+
]
|
|
465
|
+
handoff_path.write_text('\n'.join(lines) + '\n', encoding='utf-8')
|
|
466
|
+
print("[测试交接画像] %s (无匹配页面, 已写提示)" % handoff_path.name)
|
|
467
|
+
return
|
|
468
|
+
|
|
469
|
+
# 渲染完整画像
|
|
470
|
+
total_btns = sum(len(pg['buttons']) for pg in all_pages)
|
|
471
|
+
lines = [
|
|
472
|
+
'# 测试交接: %s' % task_dir.name,
|
|
473
|
+
'',
|
|
474
|
+
'> 任务完成于 %s' % datetime.now().strftime('%Y-%m-%d %H:%M'),
|
|
475
|
+
'> 业务关键词: %s' % ', '.join(used_kws),
|
|
476
|
+
'> 共 %d 个页面, %d 个交互点' % (len(all_pages), total_btns),
|
|
477
|
+
'',
|
|
478
|
+
'> 💡 测试人员照此写用例, 不用自己找页面按钮。每行"按钮→接口"就是一个用例的核心断言点。',
|
|
479
|
+
'> 未解析到接口的按钮 (deferred/unresolved) 需现场点击确认实际调用。',
|
|
480
|
+
'',
|
|
481
|
+
]
|
|
482
|
+
|
|
483
|
+
# 复用 page_probe 的渲染, 但按页面输出
|
|
484
|
+
fake_profile = {'ok': True, 'pages': all_pages, 'stats': page_probe._trace_stats(str(repo_root))}
|
|
485
|
+
lines.append(page_probe.render_profile_md(fake_profile))
|
|
486
|
+
|
|
487
|
+
lines.append('')
|
|
488
|
+
lines.append('---')
|
|
489
|
+
lines.append('')
|
|
490
|
+
lines.append('## 测试用例生成')
|
|
491
|
+
lines.append('拿到这份画像后, 直接说:')
|
|
492
|
+
lines.append('- "测一下 %s" → 走 /wl-test quick 自动生成用例' % (used_kws[0] if used_kws else '这个功能'))
|
|
493
|
+
lines.append('- 或 `/wl-test browser %s` → 按任务 PRD 生成回归用例' % task_dir.name)
|
|
494
|
+
lines.append('- 也可 `autotest.py page --kw <更精确的关键词>` 单独查某页画像')
|
|
495
|
+
|
|
496
|
+
handoff_path.write_text('\n'.join(lines) + '\n', encoding='utf-8')
|
|
497
|
+
print("[测试交接画像] 已生成 %s (%d 页面, %d 交互点)"
|
|
498
|
+
% (handoff_path.name, len(all_pages), total_btns))
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def _cleanup_orphaned_refs(archived_task_name: str, repo_root) -> int:
|
|
502
|
+
"""归档任务后, 清理其它任务中对它的引用 (blocked_by/blocks/children/parent)。
|
|
503
|
+
|
|
504
|
+
不清理 → 僵尸任务永远 blocked, resolve_task_dir 找不到引用对象。
|
|
505
|
+
返回清理的引用数。
|
|
506
|
+
"""
|
|
507
|
+
tasks_dir = get_tasks_dir(repo_root)
|
|
508
|
+
if not tasks_dir.is_dir():
|
|
509
|
+
return 0
|
|
510
|
+
cleaned = 0
|
|
511
|
+
for task_subdir in tasks_dir.iterdir():
|
|
512
|
+
if not task_subdir.is_dir() or task_subdir.name == archived_task_name:
|
|
513
|
+
continue
|
|
514
|
+
task_json = task_subdir / FILE_TASK_JSON
|
|
515
|
+
if not task_json.is_file():
|
|
516
|
+
continue
|
|
517
|
+
changed = False
|
|
518
|
+
|
|
519
|
+
def _purge_refs(data):
|
|
520
|
+
nonlocal changed
|
|
521
|
+
for field in ("blocked_by", "blocks", "children"):
|
|
522
|
+
lst = data.get(field)
|
|
523
|
+
if isinstance(lst, list) and archived_task_name in lst:
|
|
524
|
+
data[field] = [x for x in lst if x != archived_task_name]
|
|
525
|
+
changed = True
|
|
526
|
+
# parent 是单值字段
|
|
527
|
+
if data.get("parent") == archived_task_name:
|
|
528
|
+
data["parent"] = None
|
|
529
|
+
changed = True
|
|
530
|
+
if changed:
|
|
531
|
+
data["updated_at"] = datetime.now().isoformat()
|
|
532
|
+
|
|
533
|
+
modify_task_json(task_subdir, _purge_refs)
|
|
534
|
+
if changed:
|
|
535
|
+
cleaned += 1
|
|
536
|
+
return cleaned
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
# =============================================================================
|
|
540
|
+
# 命令: archive
|
|
541
|
+
# =============================================================================
|
|
542
|
+
|
|
543
|
+
def cmd_archive(args: argparse.Namespace) -> int:
|
|
544
|
+
"""归档任务 (移动到 archive/ 目录)。事务化: 先 move 成功再改 status。"""
|
|
545
|
+
repo_root = get_repo_root()
|
|
546
|
+
task_input = args.dir
|
|
547
|
+
|
|
548
|
+
full_path = resolve_task_dir(task_input, repo_root)
|
|
549
|
+
if not full_path.is_dir():
|
|
550
|
+
print(f"Error: Task not found: {task_input}", file=sys.stderr)
|
|
551
|
+
return 1
|
|
552
|
+
|
|
553
|
+
# 零信任 ACL: 只有 creator/assignee/admin 能 archive
|
|
554
|
+
try:
|
|
555
|
+
assert_can_modify_task(full_path, "archive", repo_root)
|
|
556
|
+
except PermissionError as e:
|
|
557
|
+
print(str(e), file=sys.stderr)
|
|
558
|
+
return 4 # authz_denied
|
|
559
|
+
|
|
560
|
+
# 准备 archive 目标
|
|
561
|
+
year_month = datetime.now().strftime("%Y-%m")
|
|
562
|
+
archive_dir = repo_root / ".qoder" / "archive" / year_month
|
|
563
|
+
archive_dir.mkdir(parents=True, exist_ok=True)
|
|
564
|
+
|
|
565
|
+
dest = archive_dir / full_path.name
|
|
566
|
+
if dest.exists():
|
|
567
|
+
print(f"Error: Archive destination exists: {dest}", file=sys.stderr)
|
|
568
|
+
return 1
|
|
569
|
+
|
|
570
|
+
# 事务化: 先 move (失败则原任务完好无损), 成功后再改 status
|
|
571
|
+
try:
|
|
572
|
+
shutil.move(str(full_path), str(dest))
|
|
573
|
+
except (OSError, IOError) as e:
|
|
574
|
+
print(f"Error: Failed to archive (move failed, 原任务未动): {e}", file=sys.stderr)
|
|
575
|
+
return 1
|
|
576
|
+
|
|
577
|
+
# move 成功后在目标位置改 status (失败不影响归档, 仅 status 不更新)
|
|
578
|
+
task_data = load_task_json(dest)
|
|
579
|
+
if task_data:
|
|
580
|
+
task_data["status"] = "completed"
|
|
581
|
+
task_data["archived_at"] = datetime.now().isoformat()
|
|
582
|
+
task_data["updated_at"] = task_data["archived_at"]
|
|
583
|
+
write_task_json(dest, task_data)
|
|
584
|
+
|
|
585
|
+
# 运行 after_archive 钩子
|
|
586
|
+
run_task_hooks("after_archive", dest / FILE_TASK_JSON, repo_root)
|
|
587
|
+
|
|
588
|
+
# 清理孤儿依赖: 其它任务可能引用了本任务 (blocked_by/blocks/children/parent),
|
|
589
|
+
# 归档后这些引用变成死链 → 僵尸任务永远 blocked。扫描并移除。
|
|
590
|
+
cleaned = _cleanup_orphaned_refs(full_path.name, repo_root)
|
|
591
|
+
|
|
592
|
+
# 清除可能指向此任务的会话
|
|
593
|
+
active = resolve_active_task(repo_root)
|
|
594
|
+
if active.task_path and task_input in active.task_path:
|
|
595
|
+
clear_active_task(repo_root)
|
|
596
|
+
|
|
597
|
+
print(f"Task archived: {full_path.name} -> archive/{year_month}/{full_path.name}")
|
|
598
|
+
if cleaned:
|
|
599
|
+
print(f" (已清理 {cleaned} 个其它任务中对它的依赖引用)")
|
|
600
|
+
return 0
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
# =============================================================================
|
|
604
|
+
# 命令: list
|
|
605
|
+
# =============================================================================
|
|
606
|
+
|