dsh-project-dept 1.0.1 → 1.0.3
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/README.md +5 -3
- package/README.zh.md +5 -3
- package/index.js +26 -12
- package/locale/en.json +4 -2
- package/locale/zh.json +4 -2
- package/package.json +2 -2
- package/skills/loop-ops/SKILL.md +124 -0
- package/skills/project-dept/README.md +366 -8
- package/skills/project-dept/README_EN.md +436 -7
- package/skills/project-dept/SKILL.md +10 -21
- package/skills/project-dept/evals/evals.json +252 -7
- package/skills/project-dept/manifest.yaml +29 -3
- package/skills/project-dept/references/blind-review.md +35 -0
- package/skills/project-dept/references/project-scaffold.md +10 -4
- package/skills/project-dept/scripts/check_review_form.py +649 -0
- package/skills/project-dept/scripts/check_skill.py +943 -0
- package/skills/project-dept/scripts/dept_gate.py +90 -7
- package/skills/project-dept/scripts/run_evals.py +1344 -0
- package/skills/project-dept/static/core/output-contract.md +7 -1
- package/skills/project-dept/static/core/workflow.md +3 -2
- package/skills/project-dept/tests/test_check_review_form.py +453 -0
- package/skills/project-dept/tests/test_check_skill.py +620 -0
- package/skills/project-dept/tests/test_dept_gate_baseline.py +229 -0
- package/skills/project-dept/tests/test_dept_gate_json.py +116 -0
- package/skills/project-dept/tests/test_run_evals.py +644 -0
- package/tests/bundle.test.js +29 -9
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""check_review_form.py — L2 复核单结构校验器(只查结构,不判技术结论)
|
|
4
|
+
|
|
5
|
+
七条规则
|
|
6
|
+
R1 §0 锚哈希 两次快照取值 + 「一致 / 不一致」结论;取值不同还要写限定语
|
|
7
|
+
R2 §1 判定 只允许 通过 / 通过但要修 / 不通过 三者之一(判定附近 3 行内)
|
|
8
|
+
R3 判定矛盾 判「通过」却留着未标「已修 / 已关闭」的必改项 ⇒ 缺陷
|
|
9
|
+
R4 独立性 出现「自检」且其附近有「未看 / 没看 / 先写 / 之后才 / 之前」之类限定
|
|
10
|
+
R5 机械证据 §1 里要有表格,且至少 1 个数据行带 命令 / 路径 / 行号 痕迹
|
|
11
|
+
R6 禁用证据 和旧版一致 / 与旧版一致 / 和 MEMORY / 与 MEMORY /
|
|
12
|
+
作者说 / 看起来合理 / 量级差不多 / 文件存在就算
|
|
13
|
+
R7 真问题 「问题」表格(有数据行),或「我重算了…确实没问题」豁免句
|
|
14
|
+
|
|
15
|
+
用法
|
|
16
|
+
python check_review_form.py <复核单路径> [--json]
|
|
17
|
+
|
|
18
|
+
退出码
|
|
19
|
+
0 = 合规
|
|
20
|
+
1 = 有缺陷
|
|
21
|
+
2 = 文件不存在 / 读不了(**不是通过**)
|
|
22
|
+
|
|
23
|
+
设计约束
|
|
24
|
+
- 只读;不改被校验的复核单。
|
|
25
|
+
- 只做结构断言,不判「复核结论本身对不对」——那是人的事。
|
|
26
|
+
- 缺文件返回 2 而不是 0:把「没跑」当「通过」是最坏的结果。
|
|
27
|
+
- --json 时 stdout 上只有一段 JSON,不混 banner / 分隔线。
|
|
28
|
+
"""
|
|
29
|
+
import argparse
|
|
30
|
+
import json
|
|
31
|
+
import os
|
|
32
|
+
import re
|
|
33
|
+
import sys
|
|
34
|
+
|
|
35
|
+
EXIT_PASS = 0
|
|
36
|
+
EXIT_FAIL = 1
|
|
37
|
+
EXIT_NOT_RUN = 2
|
|
38
|
+
|
|
39
|
+
# 规则键 -> 报告里的规则名(顺序即输出顺序)
|
|
40
|
+
RULES = [
|
|
41
|
+
("snapshot", "§0 锚哈希两次快照"),
|
|
42
|
+
("verdict", "§1 判定唯一且合法"),
|
|
43
|
+
("verdict_mustfix", "§1 判定与必改项不矛盾"),
|
|
44
|
+
("independence", "独立性:先独立结论再看自检"),
|
|
45
|
+
("evidence", "§1 机械证据表格"),
|
|
46
|
+
("banned", "禁用证据短语"),
|
|
47
|
+
("problem", "至少一条真问题"),
|
|
48
|
+
]
|
|
49
|
+
RULE_NAMES = dict(RULES)
|
|
50
|
+
|
|
51
|
+
# 规则 5/6 判据里点名的禁用短语(只查这些字面量,不扩展)
|
|
52
|
+
BANNED_PHRASES = (
|
|
53
|
+
"和旧版一致",
|
|
54
|
+
"与旧版一致",
|
|
55
|
+
"和 MEMORY",
|
|
56
|
+
"与 MEMORY",
|
|
57
|
+
"作者说",
|
|
58
|
+
"看起来合理",
|
|
59
|
+
"量级差不多",
|
|
60
|
+
"文件存在就算",
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# 判定只认这三种;顺序重要:长的在前,避免「通过」抢先匹配「通过但要修」
|
|
64
|
+
VERDICT_ALT = r"(通过但要修|不通过|通过)"
|
|
65
|
+
|
|
66
|
+
# 独立性限定语:出现「自检」时,附近至少要有其中一个
|
|
67
|
+
INDEPENDENCE_MARKERS = re.compile(
|
|
68
|
+
r"未看|没看|未读|没读|未打开|没打开|先写|先出|先给|之后才|之后|之前|独立于|后看|不看"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# 标题行与模板说明行不算独立性的证据(它们本来就长在模板里)。
|
|
72
|
+
INDEPENDENCE_SKIP_HINTS = ("模板", "必填", "示例", "说明", "要求", "提示")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _strip_lead_markers(line):
|
|
76
|
+
"""反复剥掉行首的引用标记、括号、列表符号与强调符,直到不再变化。
|
|
77
|
+
|
|
78
|
+
v1.3.4(A1 必改):复核人实测 `> **提示**:…`、`>**提示**`、`(**提示**)`、
|
|
79
|
+
`> - **提示**`、`> **说明**` 五例骨架行都被判成"不是模板痕迹"而白送 exit 0——
|
|
80
|
+
因为此前只剥一层标记,遇到 `> ` + `**` + `提示` 这种叠加形态就剥不干净。
|
|
81
|
+
"""
|
|
82
|
+
prev = None
|
|
83
|
+
out = line
|
|
84
|
+
while out != prev:
|
|
85
|
+
prev = out
|
|
86
|
+
out = out.lstrip()
|
|
87
|
+
out = out.lstrip(">((")
|
|
88
|
+
out = out.lstrip()
|
|
89
|
+
out = out.lstrip("-*+")
|
|
90
|
+
out = out.lstrip()
|
|
91
|
+
out = out.lstrip("*_`“\"\'")
|
|
92
|
+
return out
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _independence_candidate(line):
|
|
96
|
+
"""只认正文里的声明句:标题行、模板提示行一律不算。
|
|
97
|
+
|
|
98
|
+
演进(四条都是复核逼出来的):
|
|
99
|
+
- v1.3.1:标题行与模板提示行不算证据(模板标题自己写着「在打开自检之前完成」,等于白送)。
|
|
100
|
+
- v1.3.2:跳过规则收窄到**行首形态**(此前「行内任意位置出现提示词就整句跳过」,
|
|
101
|
+
正文里一句「我按要求先写…」会被误丢,假缺陷)。
|
|
102
|
+
- v1.3.3:行首是 `>` / `(` / `(` 时,去掉标记后必须以提示词开头才算模板痕迹。
|
|
103
|
+
- v1.3.4:标记可能**叠加**(`> **提示**`、`> - 提示`、`(**提示**)`),改为循环剥到稳定。
|
|
104
|
+
"""
|
|
105
|
+
stripped = line.lstrip()
|
|
106
|
+
if stripped.startswith("#"):
|
|
107
|
+
return False
|
|
108
|
+
body = _strip_lead_markers(stripped)
|
|
109
|
+
return not any(body.startswith(hint) for hint in INDEPENDENCE_SKIP_HINTS)
|
|
110
|
+
|
|
111
|
+
# §1 表格行里的机械证据痕迹(按验收标准点名的六类)
|
|
112
|
+
EVIDENCE_RE = re.compile(r"python|\.py\b|:\d+|--mode|sha256|HASH\s")
|
|
113
|
+
|
|
114
|
+
# 判定已修 / 已关闭的标注
|
|
115
|
+
FIXED_RE = re.compile(r"已修|已修复|已关闭|已闭合|已处理")
|
|
116
|
+
|
|
117
|
+
# 两次取值不同时,允许的「结论适用范围」限定语(「只对 start 版有效」之类)
|
|
118
|
+
LIMIT_RE = re.compile(
|
|
119
|
+
r"只对\s*start|只对\s*开始|只对\s*起始|仅对\s*start|start\s*版|"
|
|
120
|
+
r"start[^\n]{0,16}(?:有效|成立|适用)|本轮[^\n]{0,16}(?:有效|成立|适用)",
|
|
121
|
+
re.IGNORECASE,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _force_utf8_stdout():
|
|
126
|
+
"""Windows 控制台默认 GBK,中文输出会乱码或炸。尽量切到 UTF-8。"""
|
|
127
|
+
for stream_name in ("stdout", "stderr"):
|
|
128
|
+
stream = getattr(sys, stream_name, None)
|
|
129
|
+
if stream is None:
|
|
130
|
+
continue
|
|
131
|
+
try:
|
|
132
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
133
|
+
except Exception: # noqa: BLE001
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
_force_utf8_stdout()
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# ------------------------------------------------------------------ 基础工具
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def make_defect(rule, line, message, excerpt=""):
|
|
144
|
+
return {
|
|
145
|
+
"rule": rule,
|
|
146
|
+
"line": int(line),
|
|
147
|
+
"message": message,
|
|
148
|
+
"excerpt": excerpt,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def excerpt_of(line, limit=60):
|
|
153
|
+
s = (line or "").strip()
|
|
154
|
+
if len(s) > limit:
|
|
155
|
+
return s[:limit] + "…"
|
|
156
|
+
return s
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def read_text(path):
|
|
160
|
+
"""读 UTF-8(容忍 BOM)。返回 (text, error);error 为 None 表示成功。"""
|
|
161
|
+
if not os.path.exists(path):
|
|
162
|
+
return None, f"文件不存在: {path}"
|
|
163
|
+
if os.path.isdir(path):
|
|
164
|
+
return None, f"路径是目录不是文件: {path}"
|
|
165
|
+
try:
|
|
166
|
+
with open(path, "r", encoding="utf-8-sig") as f:
|
|
167
|
+
return f.read(), None
|
|
168
|
+
except UnicodeDecodeError as exc:
|
|
169
|
+
return None, f"不是 UTF-8 文本,读不出来: {path}({exc})"
|
|
170
|
+
except OSError as exc:
|
|
171
|
+
return None, f"文件读取失败: {path}({exc})"
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
HEADING_RE = re.compile(r"^##(?!#)\s*(\d+)\s*[.、.]?")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def find_sections(lines):
|
|
178
|
+
"""只按二级标题切节:{节号: (start_idx, end_idx)},0-based 半开区间。"""
|
|
179
|
+
heads = []
|
|
180
|
+
for idx, line in enumerate(lines):
|
|
181
|
+
m = HEADING_RE.match(line)
|
|
182
|
+
if m:
|
|
183
|
+
heads.append((idx, int(m.group(1))))
|
|
184
|
+
sections = {}
|
|
185
|
+
for pos, (idx, num) in enumerate(heads):
|
|
186
|
+
end = heads[pos + 1][0] if pos + 1 < len(heads) else len(lines)
|
|
187
|
+
if num not in sections:
|
|
188
|
+
sections[num] = (idx, end)
|
|
189
|
+
return sections
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _is_separator(line):
|
|
193
|
+
s = line.strip()
|
|
194
|
+
if not s.startswith("|"):
|
|
195
|
+
return False
|
|
196
|
+
core = s.strip("|").replace(" ", "")
|
|
197
|
+
return bool(core) and set(core) <= set("-:")
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def iter_table_blocks(lines, start, end):
|
|
201
|
+
"""产出表块 (header_idx, data_idx_list)。数据行 = 表头与分隔行之后的行。"""
|
|
202
|
+
i = start
|
|
203
|
+
while i < end:
|
|
204
|
+
if not lines[i].strip().startswith("|"):
|
|
205
|
+
i += 1
|
|
206
|
+
continue
|
|
207
|
+
j = i
|
|
208
|
+
while j < end and lines[j].strip().startswith("|"):
|
|
209
|
+
j += 1
|
|
210
|
+
block = list(range(i, j))
|
|
211
|
+
if len(block) >= 2 and _is_separator(lines[block[1]]):
|
|
212
|
+
data = block[2:]
|
|
213
|
+
else:
|
|
214
|
+
data = block[1:]
|
|
215
|
+
yield block[0], data
|
|
216
|
+
i = j
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _row_has_content(line):
|
|
220
|
+
return bool(re.sub(r"[|\s\-:]", "", line))
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# ------------------------------------------------------------------ R1 快照
|
|
224
|
+
|
|
225
|
+
MISSING_SNAPSHOT_MSG = "§0 缺被验快照:复核人无法证明期间文件没被改过"
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _snapshot_readings(lines, start, end):
|
|
229
|
+
"""收集两次法则的「取值」:
|
|
230
|
+
|
|
231
|
+
- kind='hash': `HASH <12hex> FILES <n>` 行,value=(hash, files)
|
|
232
|
+
- kind='tuple': 一行里 ≥2 个 8+ 位十六进制串(锚哈希 / sha256 行常见形态)
|
|
233
|
+
"""
|
|
234
|
+
readings = []
|
|
235
|
+
for idx in range(start, end):
|
|
236
|
+
line = lines[idx]
|
|
237
|
+
hashes = re.findall(r"HASH\s+([0-9a-fA-F]{12})\b", line)
|
|
238
|
+
if hashes:
|
|
239
|
+
files = None
|
|
240
|
+
fm = re.search(r"FILES\s*[=:]?\s*(\d+)", line)
|
|
241
|
+
if fm:
|
|
242
|
+
files = int(fm.group(1))
|
|
243
|
+
for value in hashes:
|
|
244
|
+
readings.append((idx + 1, "hash", value.lower(), files))
|
|
245
|
+
continue
|
|
246
|
+
tokens = re.findall(r"\b[0-9a-fA-F]{8,}\b", line)
|
|
247
|
+
if len(tokens) >= 2:
|
|
248
|
+
readings.append((idx + 1, "tuple", tuple(t.lower() for t in tokens), None))
|
|
249
|
+
return readings
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def check_snapshot(lines, sections):
|
|
253
|
+
defects = []
|
|
254
|
+
if 0 not in sections:
|
|
255
|
+
return [make_defect("snapshot", 1, MISSING_SNAPSHOT_MSG, "")]
|
|
256
|
+
|
|
257
|
+
start, end = sections[0]
|
|
258
|
+
body = "\n".join(lines[start:end])
|
|
259
|
+
readings = _snapshot_readings(lines, start, end)
|
|
260
|
+
|
|
261
|
+
hash_count = sum(1 for r in readings if r[1] == "hash")
|
|
262
|
+
word_hits = len(re.findall(r"(?i)\banchor\b|\bsha256\b", body))
|
|
263
|
+
hex_tokens = re.findall(r"\b[0-9a-fA-F]{8,}\b", body)
|
|
264
|
+
has_snapshot = hash_count >= 2 or (word_hits >= 2 and len(hex_tokens) >= 2)
|
|
265
|
+
if not has_snapshot:
|
|
266
|
+
return [make_defect("snapshot", start + 1, MISSING_SNAPSHOT_MSG, excerpt_of(lines[start]))]
|
|
267
|
+
|
|
268
|
+
# 结论:必须写「一致 / 不一致」
|
|
269
|
+
if "不一致" not in body and "一致" not in body:
|
|
270
|
+
defects.append(
|
|
271
|
+
make_defect(
|
|
272
|
+
"snapshot",
|
|
273
|
+
start + 1,
|
|
274
|
+
"§0 未给出「一致 / 不一致」结论:两次快照取值没有机械比对结果",
|
|
275
|
+
excerpt_of(lines[start]),
|
|
276
|
+
)
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
# 两次取值是否可比
|
|
280
|
+
mismatch_line = None
|
|
281
|
+
hash_vals = {r[2] for r in readings if r[1] == "hash"}
|
|
282
|
+
if len(hash_vals) > 1:
|
|
283
|
+
first = readings[0][2]
|
|
284
|
+
mismatch_line = next((r[0] for r in readings if r[2] != first), readings[0][0])
|
|
285
|
+
files_vals = {r[3] for r in readings if r[1] == "hash" and r[3] is not None}
|
|
286
|
+
if len(files_vals) > 1 and mismatch_line is None:
|
|
287
|
+
first_files = next(r[3] for r in readings if r[3] is not None)
|
|
288
|
+
mismatch_line = next((r[0] for r in readings if r[3] not in (None, first_files)), readings[0][0])
|
|
289
|
+
tuples = [r[2] for r in readings if r[1] == "tuple"]
|
|
290
|
+
if len(set(tuples)) > 1 and mismatch_line is None:
|
|
291
|
+
mismatch_line = next(r[0] for r in readings if r[1] == "tuple" and r[2] != tuples[0])
|
|
292
|
+
|
|
293
|
+
if mismatch_line is not None:
|
|
294
|
+
has_inconsistent = "不一致" in body
|
|
295
|
+
has_limit = bool(LIMIT_RE.search(body))
|
|
296
|
+
if not (has_inconsistent and has_limit):
|
|
297
|
+
defects.append(
|
|
298
|
+
make_defect(
|
|
299
|
+
"snapshot",
|
|
300
|
+
mismatch_line,
|
|
301
|
+
"两次快照取值不同,但没同时写明「不一致」与「只对 start 版有效」之类"
|
|
302
|
+
"的限定语(否则等于拿两次不同的快照下同一个结论)",
|
|
303
|
+
excerpt_of(lines[mismatch_line - 1]),
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
return defects
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
# ------------------------------------------------------------------ R2 判定
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _verdict_in_line(line):
|
|
313
|
+
"""从一行里认出 通过 / 通过但要修 / 不通过;认不出返回 None。"""
|
|
314
|
+
# 形态一:判定:X / **判定**:**X**
|
|
315
|
+
m = re.search(
|
|
316
|
+
r"判定(?:\*\*)?\s*[::]\s*(?:\*\*)?"
|
|
317
|
+
+ VERDICT_ALT
|
|
318
|
+
+ r"(?=\s*(?:\*\*)?\s*(?:[((,,。;;、))]|$))",
|
|
319
|
+
line,
|
|
320
|
+
)
|
|
321
|
+
if m:
|
|
322
|
+
return m.group(1)
|
|
323
|
+
# 形态二:整行(可带列表符号 / 加粗)就是一个判定
|
|
324
|
+
text = line.strip()
|
|
325
|
+
m = re.match(r"(?:[-*>]\s+)?\*\*" + VERDICT_ALT + r"\*\*", text)
|
|
326
|
+
if m:
|
|
327
|
+
return m.group(1)
|
|
328
|
+
m = re.match(r"(?:[-*>]\s+)?" + VERDICT_ALT + r"(?=$|[\s((::,,。;;、))])", text)
|
|
329
|
+
if m:
|
|
330
|
+
return m.group(1)
|
|
331
|
+
return None
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def check_verdict(lines, sections):
|
|
335
|
+
if 1 not in sections:
|
|
336
|
+
return None, [
|
|
337
|
+
make_defect(
|
|
338
|
+
"verdict",
|
|
339
|
+
1,
|
|
340
|
+
"缺 §1「我的独立结论」节:判定无处可查(只允许 通过 / 通过但要修 / 不通过)",
|
|
341
|
+
"",
|
|
342
|
+
)
|
|
343
|
+
]
|
|
344
|
+
|
|
345
|
+
start, end = sections[1]
|
|
346
|
+
candidates = [] # (line_idx0, verdict)
|
|
347
|
+
for idx in range(start, end):
|
|
348
|
+
if "判定" not in lines[idx]:
|
|
349
|
+
continue
|
|
350
|
+
for j in range(idx, min(idx + 4, end)): # 判定字样附近 3 行内
|
|
351
|
+
value = _verdict_in_line(lines[j])
|
|
352
|
+
if value:
|
|
353
|
+
candidates.append((j, value))
|
|
354
|
+
|
|
355
|
+
candidates = sorted(set(candidates))
|
|
356
|
+
if not candidates:
|
|
357
|
+
return None, [
|
|
358
|
+
make_defect(
|
|
359
|
+
"verdict",
|
|
360
|
+
start + 1,
|
|
361
|
+
"§1 未给出合法判定:只允许 通过 / 通过但要修 / 不通过 三者之一"
|
|
362
|
+
"(且须写在「判定」字样附近 3 行内)",
|
|
363
|
+
excerpt_of(lines[start]),
|
|
364
|
+
)
|
|
365
|
+
]
|
|
366
|
+
|
|
367
|
+
values = []
|
|
368
|
+
for _, value in candidates:
|
|
369
|
+
if value not in values:
|
|
370
|
+
values.append(value)
|
|
371
|
+
if len(values) > 1:
|
|
372
|
+
detail = " / ".join(f"「{v}」" for v in values)
|
|
373
|
+
lines_txt = "、".join(f"第 {i + 1} 行" for i, _ in candidates[:4])
|
|
374
|
+
return None, [
|
|
375
|
+
make_defect(
|
|
376
|
+
"verdict",
|
|
377
|
+
candidates[0][0] + 1,
|
|
378
|
+
f"§1 判定不唯一:同时出现 {detail}({lines_txt}),只能是一个",
|
|
379
|
+
excerpt_of(lines[candidates[0][0]]),
|
|
380
|
+
)
|
|
381
|
+
]
|
|
382
|
+
|
|
383
|
+
return candidates[0][1], []
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def check_verdict_mustfix(lines, verdict):
|
|
387
|
+
if verdict != "通过":
|
|
388
|
+
return []
|
|
389
|
+
pending = []
|
|
390
|
+
for header_idx, data in iter_table_blocks(lines, 0, len(lines)):
|
|
391
|
+
for idx in data:
|
|
392
|
+
row = lines[idx]
|
|
393
|
+
if "必改" not in row:
|
|
394
|
+
continue
|
|
395
|
+
if FIXED_RE.search(row):
|
|
396
|
+
continue
|
|
397
|
+
if not _row_has_content(row):
|
|
398
|
+
continue
|
|
399
|
+
pending.append(idx + 1)
|
|
400
|
+
if not pending:
|
|
401
|
+
return []
|
|
402
|
+
return [
|
|
403
|
+
make_defect(
|
|
404
|
+
"verdict_mustfix",
|
|
405
|
+
pending[0],
|
|
406
|
+
"判定为「通过」,但正文仍有未标注「已修 / 已关闭」的必改项——"
|
|
407
|
+
"判通过与必改项矛盾",
|
|
408
|
+
excerpt_of(lines[pending[0] - 1]),
|
|
409
|
+
)
|
|
410
|
+
]
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
# ------------------------------------------------------------------ R4 独立性
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def check_independence(lines):
|
|
417
|
+
hits = [i for i, line in enumerate(lines) if "自检" in line]
|
|
418
|
+
if not hits:
|
|
419
|
+
return [
|
|
420
|
+
make_defect(
|
|
421
|
+
"independence",
|
|
422
|
+
1,
|
|
423
|
+
"无法确认独立性:全文没有「自检」相关表述"
|
|
424
|
+
"(复核人必须先写独立结论、后看作者自检)",
|
|
425
|
+
"",
|
|
426
|
+
)
|
|
427
|
+
]
|
|
428
|
+
first_candidate = None
|
|
429
|
+
for idx in hits:
|
|
430
|
+
line = lines[idx]
|
|
431
|
+
if not _independence_candidate(line):
|
|
432
|
+
continue
|
|
433
|
+
if first_candidate is None:
|
|
434
|
+
first_candidate = idx
|
|
435
|
+
pos = line.find("自检")
|
|
436
|
+
window = line[max(0, pos - 40): pos + 40]
|
|
437
|
+
if INDEPENDENCE_MARKERS.search(window):
|
|
438
|
+
return []
|
|
439
|
+
# v1.3.2(A1 必改 ②):报第一个真正的正文候选行,别把被跳过的标题行当违规原文。
|
|
440
|
+
ref = first_candidate if first_candidate is not None else hits[0]
|
|
441
|
+
return [
|
|
442
|
+
make_defect(
|
|
443
|
+
"independence",
|
|
444
|
+
ref + 1,
|
|
445
|
+
"无法确认独立性:正文里出现「自检」但附近没有「未看 / 没看 / 先写 / "
|
|
446
|
+
"之后才」之类限定(标题行与模板提示行不算证据)",
|
|
447
|
+
excerpt_of(lines[ref]),
|
|
448
|
+
)
|
|
449
|
+
]
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
# ------------------------------------------------------------------ R5 证据
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def check_evidence(lines, sections):
|
|
456
|
+
if 1 not in sections:
|
|
457
|
+
return [
|
|
458
|
+
make_defect(
|
|
459
|
+
"evidence",
|
|
460
|
+
1,
|
|
461
|
+
"§1 缺机械证据:没有独立的 §1 节,无法核对表格",
|
|
462
|
+
"",
|
|
463
|
+
)
|
|
464
|
+
]
|
|
465
|
+
start, end = sections[1]
|
|
466
|
+
blocks = list(iter_table_blocks(lines, start, end))
|
|
467
|
+
if not blocks:
|
|
468
|
+
return [
|
|
469
|
+
make_defect(
|
|
470
|
+
"evidence",
|
|
471
|
+
start + 1,
|
|
472
|
+
"§1 缺机械证据:没有表格(至少要列出重跑 / 重算的命令与结果)",
|
|
473
|
+
excerpt_of(lines[start]),
|
|
474
|
+
)
|
|
475
|
+
]
|
|
476
|
+
evidence_header_hints = ("重算", "重跑", "重查", "方法", "命令")
|
|
477
|
+
best_rows = 0
|
|
478
|
+
for header_idx, data in blocks:
|
|
479
|
+
header = lines[header_idx]
|
|
480
|
+
if not any(hint in header for hint in evidence_header_hints):
|
|
481
|
+
continue
|
|
482
|
+
good = 0
|
|
483
|
+
for idx in data:
|
|
484
|
+
row = lines[idx]
|
|
485
|
+
if not _row_has_content(row):
|
|
486
|
+
continue
|
|
487
|
+
if "<" in row: # 模板占位符行不算证据
|
|
488
|
+
continue
|
|
489
|
+
if EVIDENCE_RE.search(row):
|
|
490
|
+
good += 1
|
|
491
|
+
best_rows = max(best_rows, good)
|
|
492
|
+
if best_rows >= 2:
|
|
493
|
+
return []
|
|
494
|
+
return [
|
|
495
|
+
make_defect(
|
|
496
|
+
"evidence",
|
|
497
|
+
blocks[0][0] + 1,
|
|
498
|
+
"§1 缺机械证据:需要「重算 / 重跑 / 重查」表里至少 2 行真实数据,"
|
|
499
|
+
"每行带 命令 / 路径 / 行号 痕迹(python、.py、:数字、--mode、sha256、HASH);"
|
|
500
|
+
"只写一行、或拿问题表凑数都不算",
|
|
501
|
+
excerpt_of(lines[blocks[0][0]]),
|
|
502
|
+
)
|
|
503
|
+
]
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
# ------------------------------------------------------------------ R6 禁用证据
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def check_banned(lines):
|
|
510
|
+
defects = []
|
|
511
|
+
for idx, line in enumerate(lines):
|
|
512
|
+
for phrase in BANNED_PHRASES:
|
|
513
|
+
if phrase in line:
|
|
514
|
+
defects.append(
|
|
515
|
+
make_defect(
|
|
516
|
+
"banned",
|
|
517
|
+
idx + 1,
|
|
518
|
+
f"禁用证据短语「{phrase}」:这类说法不能作为正确性依据"
|
|
519
|
+
"(正确锚点是独立重算 > 外部权威 > 自洽性)",
|
|
520
|
+
excerpt_of(line),
|
|
521
|
+
)
|
|
522
|
+
)
|
|
523
|
+
return defects
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
# ------------------------------------------------------------------ R7 真问题
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def check_problem(lines):
|
|
530
|
+
for header_idx, data in iter_table_blocks(lines, 0, len(lines)):
|
|
531
|
+
header = lines[header_idx]
|
|
532
|
+
if "问题" not in header:
|
|
533
|
+
continue
|
|
534
|
+
if any(_row_has_content(lines[idx]) for idx in data):
|
|
535
|
+
return []
|
|
536
|
+
for idx, line in enumerate(lines):
|
|
537
|
+
if "我重算了" not in line:
|
|
538
|
+
continue
|
|
539
|
+
if re.search(r"找不到真问题|要写|模板|必填|示例", line):
|
|
540
|
+
continue
|
|
541
|
+
if re.search(r"为什么|没问题|没有真问题|确实没问题|认为", line):
|
|
542
|
+
return []
|
|
543
|
+
return [
|
|
544
|
+
make_defect(
|
|
545
|
+
"problem",
|
|
546
|
+
1,
|
|
547
|
+
"找不到「问题」表(含数据行),也没有「我重算了哪几项、为什么认为确实"
|
|
548
|
+
"没问题」的豁免句——无法证明复核人真找了问题",
|
|
549
|
+
"",
|
|
550
|
+
)
|
|
551
|
+
]
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
# ------------------------------------------------------------------ 汇总
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def check_text(text):
|
|
558
|
+
lines = text.splitlines()
|
|
559
|
+
sections = find_sections(lines)
|
|
560
|
+
defects = []
|
|
561
|
+
defects.extend(check_snapshot(lines, sections))
|
|
562
|
+
verdict, verdict_defects = check_verdict(lines, sections)
|
|
563
|
+
defects.extend(verdict_defects)
|
|
564
|
+
defects.extend(check_verdict_mustfix(lines, verdict))
|
|
565
|
+
defects.extend(check_independence(lines))
|
|
566
|
+
defects.extend(check_evidence(lines, sections))
|
|
567
|
+
defects.extend(check_banned(lines))
|
|
568
|
+
defects.extend(check_problem(lines))
|
|
569
|
+
defects.sort(key=lambda d: (d["line"], d["rule"]))
|
|
570
|
+
return defects
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def build_payload(path, exit_code, defects, error=None):
|
|
574
|
+
hit_rules = {d["rule"] for d in defects}
|
|
575
|
+
rules = []
|
|
576
|
+
for key, name in RULES:
|
|
577
|
+
count = sum(1 for d in defects if d["rule"] == key)
|
|
578
|
+
rules.append(
|
|
579
|
+
{
|
|
580
|
+
"rule": key,
|
|
581
|
+
"name": name,
|
|
582
|
+
"ok": count == 0,
|
|
583
|
+
"defect_count": count,
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
return {
|
|
587
|
+
"ok": exit_code == EXIT_PASS,
|
|
588
|
+
"file": os.path.abspath(path),
|
|
589
|
+
"exit_code": exit_code,
|
|
590
|
+
"defects": defects,
|
|
591
|
+
"warnings": [],
|
|
592
|
+
"rules": rules,
|
|
593
|
+
"error": error,
|
|
594
|
+
"rule_keys_hit": sorted(hit_rules),
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def print_human(path, defects, exit_code):
|
|
599
|
+
print(f"REVIEW FORM CHECK · {os.path.abspath(path)}")
|
|
600
|
+
by_rule = {}
|
|
601
|
+
for d in defects:
|
|
602
|
+
by_rule.setdefault(d["rule"], []).append(d)
|
|
603
|
+
for key, name in RULES:
|
|
604
|
+
items = by_rule.get(key, [])
|
|
605
|
+
print(f"[{'x' if items else 'ok'}] {name}")
|
|
606
|
+
for d in items:
|
|
607
|
+
excerpt = d.get("excerpt") or ""
|
|
608
|
+
suffix = f"|原文:{excerpt}" if excerpt else ""
|
|
609
|
+
print(f" - 第 {d['line']} 行:{d['message']}{suffix}")
|
|
610
|
+
total = len(defects)
|
|
611
|
+
if exit_code == EXIT_PASS:
|
|
612
|
+
print("结论:合规(exit 0)")
|
|
613
|
+
else:
|
|
614
|
+
print(f"结论:有缺陷(exit 1,{total} 条)")
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
def run(path, as_json):
|
|
618
|
+
text, error = read_text(path)
|
|
619
|
+
if text is None:
|
|
620
|
+
if as_json:
|
|
621
|
+
payload = build_payload(path, EXIT_NOT_RUN, [], error)
|
|
622
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
623
|
+
else:
|
|
624
|
+
print(f"REVIEW FORM CHECK · {os.path.abspath(path)}")
|
|
625
|
+
print(f"[x] 无法执行:{error}")
|
|
626
|
+
print("结论:未执行(exit 2)")
|
|
627
|
+
return EXIT_NOT_RUN
|
|
628
|
+
|
|
629
|
+
defects = check_text(text)
|
|
630
|
+
exit_code = EXIT_FAIL if defects else EXIT_PASS
|
|
631
|
+
if as_json:
|
|
632
|
+
print(json.dumps(build_payload(path, exit_code, defects), ensure_ascii=False, indent=2))
|
|
633
|
+
else:
|
|
634
|
+
print_human(path, defects, exit_code)
|
|
635
|
+
return exit_code
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def main(argv=None):
|
|
639
|
+
parser = argparse.ArgumentParser(
|
|
640
|
+
description="L2 复核单结构校验器(只查结构,不判技术结论)"
|
|
641
|
+
)
|
|
642
|
+
parser.add_argument("path", help="复核单 markdown 路径")
|
|
643
|
+
parser.add_argument("--json", action="store_true", help="机器可读输出(stdout 只有 JSON)")
|
|
644
|
+
args = parser.parse_args(argv)
|
|
645
|
+
return run(args.path, args.json)
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
if __name__ == "__main__":
|
|
649
|
+
sys.exit(main())
|