@sokeai/cli 1.0.116 → 1.0.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/multi/demo-init/CHANGELOG.md +1241 -0
- package/skills/multi/demo-init/README.md +137 -0
- package/skills/multi/demo-init/SKILL.legacy.md +307 -0
- package/skills/multi/demo-init/assets/placeholder.pptx +0 -0
- package/skills/multi/demo-init/references/anti-patterns.md +83 -0
- package/skills/multi/demo-init/references/asset-design.md +230 -0
- package/skills/multi/demo-init/references/asset-spec.md +94 -0
- package/skills/multi/demo-init/references/blueprint-schema.md +174 -0
- package/skills/multi/demo-init/references/cli-onboarding.md +207 -0
- package/skills/multi/demo-init/references/cli-shared.md +183 -0
- package/skills/multi/demo-init/references/contracts.md +34 -0
- package/skills/multi/demo-init/references/course-setup.md +265 -0
- package/skills/multi/demo-init/references/demo-defaults.md +132 -0
- package/skills/multi/demo-init/references/demo-verify.md +355 -0
- package/skills/multi/demo-init/references/exam-setup.md +245 -0
- package/skills/multi/demo-init/references/gates-matrix.md +38 -0
- package/skills/multi/demo-init/references/map-setup.md +283 -0
- package/skills/multi/demo-init/references/plan-parse.md +185 -0
- package/skills/multi/demo-init/references/platform-access.md +55 -0
- package/skills/multi/demo-init/references/platform-commands.md +510 -0
- package/skills/multi/demo-init/references/point-setup.md +308 -0
- package/skills/multi/demo-init/references/portal-modules.md +130 -0
- package/skills/multi/demo-init/references/portal-setup.md +342 -0
- package/skills/multi/demo-init/references/project-setup.md +173 -0
- package/skills/multi/demo-init/references/run-protocol.md +208 -0
- package/skills/multi/demo-init/references/taxonomy-setup.md +101 -0
- package/skills/multi/demo-init/scripts/assign_backfill.py +281 -0
- package/skills/multi/demo-init/scripts/blueprint_lint.py +693 -0
- package/skills/multi/demo-init/scripts/blueprint_write.py +390 -0
- package/skills/multi/demo-init/scripts/category_bind.py +303 -0
- package/skills/multi/demo-init/scripts/category_create.py +748 -0
- package/skills/multi/demo-init/scripts/category_reassign.py +405 -0
- package/skills/multi/demo-init/scripts/category_verify.py +373 -0
- package/skills/multi/demo-init/scripts/cli_kit.py +597 -0
- package/skills/multi/demo-init/scripts/cli_probe.py +205 -0
- package/skills/multi/demo-init/scripts/course_build.py +857 -0
- package/skills/multi/demo-init/scripts/course_cover_repair.py +243 -0
- package/skills/multi/demo-init/scripts/doc_lint.py +619 -0
- package/skills/multi/demo-init/scripts/dup_cleanup.py +299 -0
- package/skills/multi/demo-init/scripts/dup_scan.py +368 -0
- package/skills/multi/demo-init/scripts/exam_build.py +551 -0
- package/skills/multi/demo-init/scripts/extract_docx.py +370 -0
- package/skills/multi/demo-init/scripts/gen_assets.py +1366 -0
- package/skills/multi/demo-init/scripts/guard.py +1272 -0
- package/skills/multi/demo-init/scripts/map_rebuild.py +391 -0
- package/skills/multi/demo-init/scripts/oss_image_upload.py +367 -0
- package/skills/multi/demo-init/scripts/portal_build.py +450 -0
- package/skills/multi/demo-init/scripts/portal_home_apply.py +255 -0
- package/skills/multi/demo-init/scripts/portal_home_layout.py +398 -0
- package/skills/multi/demo-init/scripts/project_build.py +309 -0
- package/skills/multi/demo-init/scripts/rebuild_taxonomy_map.py +100 -0
- package/skills/multi/demo-init/scripts/scope_plan.py +387 -0
- package/skills/multi/demo-init/scripts/selftest_all.py +211 -0
- package/skills/multi/demo-init/scripts/stock_probe.py +452 -0
- package/skills/multi/demo-init/scripts/taxonomy_build.py +512 -0
- package/skills/multi/demo-init-4.1.0.zip +0 -0
- package/skills/multi/demo-init-4.1.1.zip +0 -0
- package/skills/multi/demo-init-4.1.2.zip +0 -0
- package/skills/multi/demo-init-4.1.3.zip +0 -0
- package/skills/multi/ziQIJJpL +0 -0
- package/skills/multi/ziRsINis +0 -0
- package/skills/multi/ziUjKWRm +0 -0
- package/skills/multi/zipFWfuj +0 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""demo-init 文档一致性门禁(doc_lint)
|
|
4
|
+
|
|
5
|
+
起因(v3.29.0):技能在 48 小时里发了 19 个版本,同类结论被写进 4 个地方
|
|
6
|
+
(SKILL 反面模式 / platform-commands 偏差表 / run-protocol 事故清单 / 各模块闸门矩阵),
|
|
7
|
+
出现 4 组**互相打架的事实源**——执行模型读到哪份就照哪份干,同一套施工结果不稳定:
|
|
8
|
+
|
|
9
|
+
1. 同名处置:一边「命中即复用、绝不加后缀」,另一边「追加数字后缀重建」
|
|
10
|
+
2. `img_picked`:一边 0(脚本与 course-setup 已定版),另一边 1(偏差表 #67 与反面模式 #22)
|
|
11
|
+
3. 封面判据:一边「只看 img_url」,另一边「img_url 不可作判据、只看 picture」
|
|
12
|
+
4. 日志截断:一边 120 字符,另一边 200 字符
|
|
13
|
+
|
|
14
|
+
本脚本把这些口径变成**机读断言**——再出现反向写法即 rc=2,拦住"改完又退回去"。
|
|
15
|
+
|
|
16
|
+
用法:
|
|
17
|
+
<PY> scripts/doc_lint.py # 人读输出
|
|
18
|
+
<PY> scripts/doc_lint.py --json # 机器可读
|
|
19
|
+
<PY> scripts/doc_lint.py --self-test # 检测器自测(临时夹具,不依赖技能内容)
|
|
20
|
+
|
|
21
|
+
退出码:0=全部通过;2=有违规(阻断入库/分发)。
|
|
22
|
+
设计边界:只读扫描 `.md` 与目录卫生,不连平台、不改任何文件。
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import argparse
|
|
28
|
+
import json
|
|
29
|
+
import os
|
|
30
|
+
import re
|
|
31
|
+
import sys
|
|
32
|
+
import tempfile
|
|
33
|
+
|
|
34
|
+
SKILL_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
35
|
+
REFS_DIR = os.path.join(SKILL_DIR, "references")
|
|
36
|
+
SKILL_MD = os.path.join(SKILL_DIR, "SKILL.md")
|
|
37
|
+
README_MD = os.path.join(SKILL_DIR, "README.md")
|
|
38
|
+
CHANGELOG_MD = os.path.join(SKILL_DIR, "CHANGELOG.md")
|
|
39
|
+
|
|
40
|
+
# 历史留档文件不参与"口径断言"(它记录的是当时的错误结论,属审计物证,不许改写)
|
|
41
|
+
HISTORY_FILES = {"CHANGELOG.md", "SKILL.legacy.md"}
|
|
42
|
+
|
|
43
|
+
# ---- 口径常量(唯一真值,改这里等于改口径) ----
|
|
44
|
+
SKILL_MAX_CHARS = 16000
|
|
45
|
+
|
|
46
|
+
# v4.0.0 外置的三份长表:文件必须在,且 SKILL.md 必须留指针(否则又会被内联回去)
|
|
47
|
+
EXTERNALIZED = {
|
|
48
|
+
"contracts.md": "契约速查",
|
|
49
|
+
"anti-patterns.md": "反面模式",
|
|
50
|
+
"gates-matrix.md": "闸门",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# 租户级否定结论锚点:这些断言只在当前租户成立,换租户必须复验 → 必须带 [租户级]
|
|
54
|
+
TENANT_ANCHORS = [
|
|
55
|
+
"恒 **[12000] 无权限**",
|
|
56
|
+
"考试分类创建 `[12000] 无权限`",
|
|
57
|
+
"update-stage --select-items 通道疑似坏",
|
|
58
|
+
"地图改分类无可用通道",
|
|
59
|
+
"OSS 死链",
|
|
60
|
+
"直传 OSS 未设 Content-Type",
|
|
61
|
+
"商品全量回写",
|
|
62
|
+
"`learning-map +assign` 404 无权限",
|
|
63
|
+
]
|
|
64
|
+
TENANT_TAG = "[租户级]"
|
|
65
|
+
|
|
66
|
+
IMG_PICKED_OK = "0"
|
|
67
|
+
LOG_TRUNCATE_OK = "120"
|
|
68
|
+
FORBIDDEN_SUFFIX = ["追加数字后缀重建", "撞名加数字后缀", "后缀重试处理"]
|
|
69
|
+
SUFFIX_EXEMPT = ("废止", "不加", "⛔", "禁", "修正", "已改", "作废")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _read(path: str) -> str:
|
|
73
|
+
with open(path, encoding="utf-8") as fh:
|
|
74
|
+
return fh.read()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _md_files() -> list:
|
|
78
|
+
out = [SKILL_MD, README_MD]
|
|
79
|
+
if os.path.isdir(REFS_DIR):
|
|
80
|
+
out += [os.path.join(REFS_DIR, n) for n in sorted(os.listdir(REFS_DIR)) if n.endswith(".md")]
|
|
81
|
+
return [p for p in out if os.path.isfile(p)]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _lint_files() -> list:
|
|
85
|
+
"""参与口径断言的文件(排除历史留档)。"""
|
|
86
|
+
return [p for p in _md_files() if os.path.basename(p) not in HISTORY_FILES]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# ------------------------------------------------------------------ 检查项
|
|
90
|
+
|
|
91
|
+
def check_versions() -> dict:
|
|
92
|
+
"""SKILL frontmatter / README 版本行 / CHANGELOG 首条 三处必须同号。"""
|
|
93
|
+
got = {}
|
|
94
|
+
if os.path.isfile(SKILL_MD):
|
|
95
|
+
m = re.search(r"^version:\s*([0-9]+\.[0-9]+\.[0-9]+)", _read(SKILL_MD), re.M)
|
|
96
|
+
got["SKILL.md"] = m.group(1) if m else None
|
|
97
|
+
if os.path.isfile(README_MD):
|
|
98
|
+
m = re.search(r"当前\s*`?([0-9]+\.[0-9]+\.[0-9]+)`?", _read(README_MD))
|
|
99
|
+
got["README.md"] = m.group(1) if m else None
|
|
100
|
+
if os.path.isfile(CHANGELOG_MD):
|
|
101
|
+
m = re.search(r"^##\s*([0-9]+\.[0-9]+\.[0-9]+)", _read(CHANGELOG_MD), re.M)
|
|
102
|
+
got["CHANGELOG.md"] = m.group(1) if m else None
|
|
103
|
+
vals = [v for v in got.values() if v]
|
|
104
|
+
ok = len(vals) == len(got) and len(set(vals)) == 1
|
|
105
|
+
return {"name": "版本三处一致", "ok": ok,
|
|
106
|
+
"detail": " / ".join("%s=%s" % (k, v or "缺失") for k, v in got.items())}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def check_img_picked() -> dict:
|
|
110
|
+
"""写入载荷里的 img_picked 只允许 0(1/2/3 = 平台默认封面模板 → 编辑页空白)。"""
|
|
111
|
+
bad = []
|
|
112
|
+
pat = re.compile(r"img_picked['\"]?\s*[:=]\s*['\"]?([0-9])")
|
|
113
|
+
for p in _lint_files():
|
|
114
|
+
for i, line in enumerate(_read(p).split("\n"), 1):
|
|
115
|
+
for m in pat.finditer(line):
|
|
116
|
+
if m.group(1) == IMG_PICKED_OK:
|
|
117
|
+
continue
|
|
118
|
+
if any(k in line for k in ("原写", "已改", "作废", "修正", "-H", "此前", "曾传")):
|
|
119
|
+
continue
|
|
120
|
+
bad.append("%s:%d img_picked=%s" % (os.path.basename(p), i, m.group(1)))
|
|
121
|
+
return {"name": "img_picked 恒为 0", "ok": not bad,
|
|
122
|
+
"detail": "全部为 0" if not bad else ";".join(bad[:6])}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def check_log_truncate() -> dict:
|
|
126
|
+
"""日志单行截断口径只能有一个数字(120)。"""
|
|
127
|
+
bad = []
|
|
128
|
+
pat = re.compile(r"(超\s*|前\s*)([0-9]{2,4})\s*字符")
|
|
129
|
+
for p in _lint_files():
|
|
130
|
+
for i, line in enumerate(_read(p).split("\n"), 1):
|
|
131
|
+
for m in pat.finditer(line):
|
|
132
|
+
if m.group(2) != LOG_TRUNCATE_OK:
|
|
133
|
+
bad.append("%s:%d %s 字符" % (os.path.basename(p), i, m.group(2)))
|
|
134
|
+
return {"name": "日志截断 120 唯一", "ok": not bad,
|
|
135
|
+
"detail": "口径唯一" if not bad else ";".join(bad[:6])}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def check_suffix_policy() -> dict:
|
|
139
|
+
"""禁止加后缀制造对象;首次直建及失败恢复由执行策略检查约束。"""
|
|
140
|
+
bad = []
|
|
141
|
+
for p in _lint_files():
|
|
142
|
+
for i, line in enumerate(_read(p).split("\n"), 1):
|
|
143
|
+
for ph in FORBIDDEN_SUFFIX:
|
|
144
|
+
if ph in line and not any(k in line for k in ("废止", "修正", "⛔")):
|
|
145
|
+
bad.append("%s:%d 「%s」" % (os.path.basename(p), i, ph))
|
|
146
|
+
if "数字后缀" in line and not any(k in line for k in SUFFIX_EXEMPT):
|
|
147
|
+
bad.append("%s:%d 「数字后缀」缺少复用/禁用语境" % (os.path.basename(p), i))
|
|
148
|
+
return {"name": "首建不查重/失败恢复不加后缀", "ok": not bad,
|
|
149
|
+
"detail": "口径唯一" if not bad else ";".join(bad[:6])}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def check_img_url_criterion() -> dict:
|
|
153
|
+
"""封面判据:不得再写「picture 非空即落库 / img_url 不可作判据」。"""
|
|
154
|
+
bad = []
|
|
155
|
+
pats = [re.compile(r"picture[^。;\n]{0,12}非空[^。;\n]{0,8}(即|就)"),]
|
|
156
|
+
for p in _lint_files():
|
|
157
|
+
for i, line in enumerate(_read(p).split("\n"), 1):
|
|
158
|
+
if any(k in line for k in ("作废", "修正", "-H", "≠", "误判", "旧判据")):
|
|
159
|
+
continue
|
|
160
|
+
if re.search(r"img_url[^。;\n]{0,6}不可作判据", line):
|
|
161
|
+
bad.append("%s:%d「img_url 不可作判据」" % (os.path.basename(p), i))
|
|
162
|
+
for pat in pats:
|
|
163
|
+
if pat.search(line):
|
|
164
|
+
bad.append("%s:%d「picture 非空即落库」" % (os.path.basename(p), i))
|
|
165
|
+
return {"name": "封面判据=img_url", "ok": not bad,
|
|
166
|
+
"detail": "判据唯一" if not bad else ";".join(bad[:6])}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def check_at_references() -> dict:
|
|
170
|
+
"""`@references/` 已废(与「不再 @ 注入」冲突),必须为 0。"""
|
|
171
|
+
bad = []
|
|
172
|
+
for p in _md_files():
|
|
173
|
+
c = _read(p).count("@references/")
|
|
174
|
+
if c:
|
|
175
|
+
bad.append("%s×%d" % (os.path.basename(p), c))
|
|
176
|
+
return {"name": "@references 残留=0", "ok": not bad,
|
|
177
|
+
"detail": "无残留" if not bad else ";".join(bad)}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def check_section_numbers() -> dict:
|
|
181
|
+
"""同一文件内 `## <中文数字>、` 不得重号(追加式改动最容易留下重号)。"""
|
|
182
|
+
bad = []
|
|
183
|
+
for p in _md_files():
|
|
184
|
+
seen = {}
|
|
185
|
+
for i, line in enumerate(_read(p).split("\n"), 1):
|
|
186
|
+
m = re.match(r"^##\s+([一二三四五六七八九十]+)、", line)
|
|
187
|
+
if not m:
|
|
188
|
+
continue
|
|
189
|
+
n = m.group(1)
|
|
190
|
+
if n in seen:
|
|
191
|
+
bad.append("%s §%s 重号(第 %d 行与第 %d 行)" % (os.path.basename(p), n, seen[n], i))
|
|
192
|
+
else:
|
|
193
|
+
seen[n] = i
|
|
194
|
+
return {"name": "章节号不重复", "ok": not bad,
|
|
195
|
+
"detail": "无重号" if not bad else ";".join(bad[:6])}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def check_blacklist_order() -> dict:
|
|
199
|
+
"""反面模式表必须按编号单调(v4.0.0:表已外置,SKILL 与 anti-patterns 都要扫)。"""
|
|
200
|
+
targets = [SKILL_MD, os.path.join(REFS_DIR, "anti-patterns.md")]
|
|
201
|
+
targets = [p for p in targets if os.path.isfile(p)]
|
|
202
|
+
if not targets:
|
|
203
|
+
return {"name": "反面模式编号单调", "ok": False, "detail": "两份候选文件都缺失"}
|
|
204
|
+
scanned = []
|
|
205
|
+
for path in targets:
|
|
206
|
+
text = _read(path)
|
|
207
|
+
m = re.search(r"^#{1,3} 反面模式黑名单.*?$", text, re.M)
|
|
208
|
+
if not m:
|
|
209
|
+
continue
|
|
210
|
+
scanned.append(os.path.basename(path))
|
|
211
|
+
tail = text[m.end():]
|
|
212
|
+
nxt = re.search(r"^#{1,2} ", tail, re.M)
|
|
213
|
+
block = tail[:nxt.start()] if nxt else tail
|
|
214
|
+
keys = []
|
|
215
|
+
for line in block.split("\n"):
|
|
216
|
+
mm = re.match(r"^\| (\d+)([a-z]?) \|", line)
|
|
217
|
+
if mm:
|
|
218
|
+
keys.append((int(mm.group(1)), mm.group(2)))
|
|
219
|
+
if not keys:
|
|
220
|
+
return {"name": "反面模式编号单调", "ok": True,
|
|
221
|
+
"detail": "%s 有章节但无条目" % os.path.basename(path)}
|
|
222
|
+
out_of_order = [(keys[i - 1], keys[i]) for i in range(1, len(keys)) if keys[i] < keys[i - 1]]
|
|
223
|
+
dup = len(keys) != len(set(keys))
|
|
224
|
+
maxn = max(k[0] for k in keys)
|
|
225
|
+
suffixed = ["%d%s" % (n, s) for n, s in keys if s]
|
|
226
|
+
detail = "%s:%d 条,编号 1→%d" % (os.path.basename(path), len(keys), maxn)
|
|
227
|
+
if suffixed:
|
|
228
|
+
# 6b 之类后缀条目会让「条数」比「最大编号」多,不是错误,说清楚免得误读
|
|
229
|
+
detail += "(另有后缀条目 %s)" % "、".join(suffixed[:5])
|
|
230
|
+
if out_of_order:
|
|
231
|
+
detail += ";乱序 %s" % ",".join("%s→%s" % (a, b) for a, b in out_of_order[:3])
|
|
232
|
+
if dup:
|
|
233
|
+
detail += ";有重复编号"
|
|
234
|
+
return {"name": "反面模式编号单调", "ok": not out_of_order and not dup, "detail": detail}
|
|
235
|
+
return {"name": "反面模式编号单调", "ok": True, "detail": "未找到该章节,跳过"}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def check_skill_budget() -> dict:
|
|
239
|
+
"""SKILL.md 常驻体量上限(v4.0.0:外置后必须守住,防止再膨胀回 38K)。"""
|
|
240
|
+
if not os.path.isfile(SKILL_MD):
|
|
241
|
+
return {"name": "SKILL.md 体量预算", "ok": False, "detail": "SKILL.md 缺失"}
|
|
242
|
+
n = len(_read(SKILL_MD))
|
|
243
|
+
return {"name": "SKILL.md 体量预算", "ok": n <= SKILL_MAX_CHARS,
|
|
244
|
+
"detail": "%d 字符(上限 %d)" % (n, SKILL_MAX_CHARS)}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def check_externalized() -> dict:
|
|
248
|
+
"""三份外置长表必须在,且 SKILL.md 里有指针;SKILL.md 不得再内联 70 条黑名单。"""
|
|
249
|
+
bad = []
|
|
250
|
+
skill = _read(SKILL_MD) if os.path.isfile(SKILL_MD) else ""
|
|
251
|
+
for fname, keyword in EXTERNALIZED.items():
|
|
252
|
+
path = os.path.join(REFS_DIR, fname)
|
|
253
|
+
if not os.path.isfile(path):
|
|
254
|
+
bad.append("缺 references/%s" % fname)
|
|
255
|
+
continue
|
|
256
|
+
if "references/" + fname not in skill:
|
|
257
|
+
bad.append("SKILL.md 无 references/%s 指针" % fname)
|
|
258
|
+
if keyword not in skill:
|
|
259
|
+
bad.append("SKILL.md 未提及「%s」用途" % keyword)
|
|
260
|
+
# 防回涨:SKILL.md 里若出现 ≥40 行反面模式表格,说明又被内联了
|
|
261
|
+
rows = len(re.findall(r"^\| \d+[a-z]? \| .+ \|", skill, re.M))
|
|
262
|
+
if rows >= 40:
|
|
263
|
+
bad.append("SKILL.md 内联了 %d 行编号表格(应外置)" % rows)
|
|
264
|
+
return {"name": "长表已外置且留指针", "ok": not bad,
|
|
265
|
+
"detail": "三份外置文件齐备" if not bad else ";".join(bad[:6])}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def check_tenant_tags() -> dict:
|
|
269
|
+
"""租户级否定结论必须带 [租户级] 标记 + 文档内有分级图例(换租户不得直接照抄)。"""
|
|
270
|
+
path = os.path.join(REFS_DIR, "platform-commands.md")
|
|
271
|
+
if not os.path.isfile(path):
|
|
272
|
+
return {"name": "租户级结论有标记", "ok": False, "detail": "platform-commands.md 缺失"}
|
|
273
|
+
lines = _read(path).split("\n")
|
|
274
|
+
bad = []
|
|
275
|
+
if "## 零、结论口径分级" not in "\n".join(lines) or TENANT_TAG not in "\n".join(lines):
|
|
276
|
+
bad.append("缺「结论口径分级」图例")
|
|
277
|
+
for anchor in TENANT_ANCHORS:
|
|
278
|
+
hits = [ln for ln in lines if anchor in ln]
|
|
279
|
+
if not hits:
|
|
280
|
+
bad.append("锚点失配「%s」(条目被改写或删除)" % anchor[:18])
|
|
281
|
+
continue
|
|
282
|
+
if not any(TENANT_TAG in ln for ln in hits):
|
|
283
|
+
bad.append("「%s」未标 %s" % (anchor[:18], TENANT_TAG))
|
|
284
|
+
return {"name": "租户级结论有标记", "ok": not bad,
|
|
285
|
+
"detail": "%d 条锚点全部已标" % len(TENANT_ANCHORS) if not bad else ";".join(bad[:6])}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def check_package_hygiene() -> dict:
|
|
289
|
+
"""分发包不得含 .DS_Store / __pycache__ / 客户产物目录。"""
|
|
290
|
+
bad = []
|
|
291
|
+
for root, dirs, files in os.walk(SKILL_DIR):
|
|
292
|
+
for d in list(dirs):
|
|
293
|
+
if d in ("__pycache__", "demo-assets"):
|
|
294
|
+
bad.append(os.path.relpath(os.path.join(root, d), SKILL_DIR) + "/")
|
|
295
|
+
dirs.remove(d)
|
|
296
|
+
for f in files:
|
|
297
|
+
if f in (".DS_Store", "Thumbs.db") or f.endswith(".pyc"):
|
|
298
|
+
bad.append(os.path.relpath(os.path.join(root, f), SKILL_DIR))
|
|
299
|
+
return {"name": "包卫生(无缓存/客户产物)", "ok": not bad,
|
|
300
|
+
"detail": "干净" if not bad else ";".join(bad[:6])}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def check_refs_links() -> dict:
|
|
304
|
+
"""references 交叉引用不得断链(含 SKILL.md 内引用)。"""
|
|
305
|
+
if not os.path.isdir(REFS_DIR):
|
|
306
|
+
return {"name": "文档引用无断链", "ok": False, "detail": "references 目录不存在"}
|
|
307
|
+
names = {n for n in os.listdir(REFS_DIR) if n.endswith(".md")}
|
|
308
|
+
broken = {}
|
|
309
|
+
for p in _md_files():
|
|
310
|
+
for m in re.findall(r"(?<![\w/-])references/([A-Za-z0-9_-]+\.md)", _read(p)):
|
|
311
|
+
if m not in names:
|
|
312
|
+
broken.setdefault(os.path.basename(p), set()).add(m)
|
|
313
|
+
return {"name": "文档引用无断链", "ok": not broken,
|
|
314
|
+
"detail": "%d 份文档引用完整" % len(names) if not broken else
|
|
315
|
+
";".join("%s→%s" % (k, ",".join(sorted(v))) for k, v in broken.items())}
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
# 闸门命名空间白名单(新增模块时在这里登记,否则其闸门编号不会被承认)
|
|
319
|
+
GATE_NS = {"G", "P", "S", "D", "flow", "onboard", "taxonomy", "course", "exam",
|
|
320
|
+
"map", "project", "portal", "point", "asset"}
|
|
321
|
+
|
|
322
|
+
# 退役闸门(v4.1.3):编号不复用,历史 run.log / 台账 / 复盘里允许出现,但不再要求有定义
|
|
323
|
+
RETIRED_GATES = {"P-5", "P-14"}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def check_gate_namespace() -> dict:
|
|
327
|
+
"""闸门编号必须有命名空间前缀,且被引用的编号必须存在(v4.1.0)。
|
|
328
|
+
|
|
329
|
+
背景:同一件事被叫「闸门 7」「Gate 4c」「闸门 15」三种写法,跨文件引用指到不存在的编号
|
|
330
|
+
(blueprint-schema 曾三处「闸门 15」、一处「闸门 16」都不存在),执行方按编号查不到判据。
|
|
331
|
+
约定:`G-<n>` 编排/`P-<n>` 解析/`S-<n>` 契约/`D-<n>` 终验/`<模块>-G<n>` 模块汇总/
|
|
332
|
+
`<模块>-S<n>` 模块步骤/`flow-G<n>` 流程内联门。
|
|
333
|
+
"""
|
|
334
|
+
defined = set()
|
|
335
|
+
for p in _md_files():
|
|
336
|
+
text = _read(p)
|
|
337
|
+
# 定义点 1:表格首列是编号
|
|
338
|
+
for m in re.finditer(r"^\|\s*`?([A-Za-z][A-Za-z0-9]*-[GS]?[0-9]+[a-z]?)`?\s*\|", text, re.M):
|
|
339
|
+
defined.add(m.group(1))
|
|
340
|
+
# 定义点 2:加粗或标题里的编号(**`D-1`**:… / ## `D-3`:…,反引号可省)
|
|
341
|
+
for m in re.finditer(r"\*\*`?([A-Za-z][A-Za-z0-9]*-[GS]?[0-9]+[a-z]?)`?(?:[(::]|\*\*)", text):
|
|
342
|
+
defined.add(m.group(1))
|
|
343
|
+
for m in re.finditer(r"^#{2,4}\s+`?([A-Za-z][A-Za-z0-9]*-[GS]?[0-9]+[a-z]?)`?", text, re.M):
|
|
344
|
+
defined.add(m.group(1))
|
|
345
|
+
defined = {g for g in defined if g.split("-")[0] in GATE_NS}
|
|
346
|
+
|
|
347
|
+
bad, refs = [], 0
|
|
348
|
+
bare = re.compile(r"(?:闸门|Gate)\s*#?\s*[0-9]")
|
|
349
|
+
# 形如 `S-8` / `P-15` / `map-G3` 的 token 一律视为闸门引用,必须命中定义
|
|
350
|
+
token = re.compile(r"(?<![A-Za-z0-9_-])([A-Za-z][A-Za-z0-9]*-[GS]?[0-9]+[a-z]?)(?![A-Za-z0-9_-])")
|
|
351
|
+
namespaces = {"G", "P", "S", "D", "flow"} | {x.split("-")[0] for x in defined}
|
|
352
|
+
for p in _lint_files():
|
|
353
|
+
for i, line in enumerate(_read(p).split("\n"), 1):
|
|
354
|
+
if bare.search(line):
|
|
355
|
+
bad.append("%s:%d 裸编号(缺命名空间前缀)" % (os.path.basename(p), i))
|
|
356
|
+
for m in token.finditer(line):
|
|
357
|
+
gid = m.group(1)
|
|
358
|
+
if gid.split("-")[0] not in namespaces:
|
|
359
|
+
continue
|
|
360
|
+
refs += 1
|
|
361
|
+
if gid not in defined and gid not in RETIRED_GATES:
|
|
362
|
+
bad.append("%s:%d 引用了不存在的闸门 `%s`" % (os.path.basename(p), i, gid))
|
|
363
|
+
return {"name": "闸门编号有命名空间", "ok": not bad,
|
|
364
|
+
"detail": "%d 个已定义编号,%d 处引用全部命中" % (len(defined), refs) if not bad
|
|
365
|
+
else ";".join(bad[:6])}
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def check_execution_policy() -> dict:
|
|
369
|
+
"""三阶段调度与创建恢复/默认分类口径必须同源,核心字段检查不变。"""
|
|
370
|
+
skill = _read(SKILL_MD) if os.path.isfile(SKILL_MD) else ""
|
|
371
|
+
required = ("方案确认一次", "施工结果按模块批量自动验收", "交付最终汇总",
|
|
372
|
+
"首次直建一次", "删后回读", "来源不明不删", "已有默认分类",
|
|
373
|
+
"无可用分类", "课程和题库分类照原文", "必要结果回读")
|
|
374
|
+
bad = ["SKILL 缺口径「%s」" % word for word in required if word not in skill]
|
|
375
|
+
forbidden = (
|
|
376
|
+
r"允许并强制.{0,20}单条同名探测",
|
|
377
|
+
r"(?:对象[^。;\n]{0,20}撞名先|create.{0,16}前)[^。;\n]{0,30}单条同名探测",
|
|
378
|
+
r"Step 未过闸门禁止进下一步",
|
|
379
|
+
r"交付前.{0,40}dup_scan[^。;\n]{0,16}必跑",
|
|
380
|
+
r"前置闸门[^\n]*dup_scan",
|
|
381
|
+
r"(?:同名门户唯一|同名唯一|同 title 门户\*\*只有)",
|
|
382
|
+
r"没有蓝图也要跑",
|
|
383
|
+
r"stock_probe[^\n]{0,30}(?:强制|必跑)",
|
|
384
|
+
)
|
|
385
|
+
for path in _lint_files():
|
|
386
|
+
for number, line in enumerate(_read(path).splitlines(), 1):
|
|
387
|
+
# 反面模式只检查正确做法列,不把反例误判为现行指令。
|
|
388
|
+
policy = line
|
|
389
|
+
if os.path.basename(path) == "anti-patterns.md" and line.startswith("|"):
|
|
390
|
+
policy = line.rsplit("|", 2)[-2]
|
|
391
|
+
if any(word in policy for word in ("废止", "已退役", "不要求", "不再要求", "不得要求", "不核", "不强制", "| ❌")):
|
|
392
|
+
continue
|
|
393
|
+
if any(re.search(pattern, policy) for pattern in forbidden):
|
|
394
|
+
bad.append("%s:%d 仍含细闸门/建前查重或全租户强制扫描口径" % (os.path.basename(path), number))
|
|
395
|
+
return {"name": "三阶段与创建分类口径", "ok": not bad,
|
|
396
|
+
"detail": "三阶段调度、首次直建、可证恢复与技术默认分类一致" if not bad else ";".join(bad[:8])}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def check_cap_single_source() -> dict:
|
|
400
|
+
"""检查文档驱动范围不再被固定配额覆盖。
|
|
401
|
+
|
|
402
|
+
保留函数名兼容现有自测及外部调用。
|
|
403
|
+
"""
|
|
404
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
405
|
+
from scope_plan import build_plan
|
|
406
|
+
raw = {"courses": [{"title": "C%d" % i} for i in range(13)],
|
|
407
|
+
"maps": [], "exams": [{"name": "E%d" % i} for i in range(7)],
|
|
408
|
+
"projects": [{"name": "P%d" % i} for i in range(4)]}
|
|
409
|
+
plan = build_plan(raw)
|
|
410
|
+
ok = (len(plan["courses"]) == 13 and len(plan["exams"]) == 7
|
|
411
|
+
and len(plan["projects"]) == 4 and not plan["maps"])
|
|
412
|
+
return {"name": "文档驱动范围", "ok": ok,
|
|
413
|
+
"detail": "完整保留文档数量,未补建地图" if ok else "仍存在硬截取或自动扩建"}
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
CHECKS = [check_versions, check_img_picked, check_log_truncate, check_suffix_policy,
|
|
417
|
+
check_img_url_criterion, check_at_references, check_section_numbers,
|
|
418
|
+
check_blacklist_order, check_skill_budget, check_externalized,
|
|
419
|
+
check_tenant_tags, check_gate_namespace, check_execution_policy, check_cap_single_source,
|
|
420
|
+
check_package_hygiene, check_refs_links]
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
# ------------------------------------------------------------------ 自测
|
|
425
|
+
|
|
426
|
+
def _write(path: str, text: str) -> None:
|
|
427
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
428
|
+
fh.write(text)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def self_test() -> int:
|
|
432
|
+
"""用临时夹具验证各检测器「该报的报、不该报的不报」。"""
|
|
433
|
+
global SKILL_DIR, REFS_DIR, SKILL_MD, README_MD, CHANGELOG_MD
|
|
434
|
+
saved = (SKILL_DIR, REFS_DIR, SKILL_MD, README_MD, CHANGELOG_MD)
|
|
435
|
+
cases = []
|
|
436
|
+
|
|
437
|
+
def ck(cond, label):
|
|
438
|
+
cases.append((bool(cond), label))
|
|
439
|
+
|
|
440
|
+
with tempfile.TemporaryDirectory(prefix="doc-lint-") as tmp:
|
|
441
|
+
SKILL_DIR = tmp
|
|
442
|
+
REFS_DIR = os.path.join(tmp, "references")
|
|
443
|
+
os.makedirs(REFS_DIR)
|
|
444
|
+
SKILL_MD = os.path.join(tmp, "SKILL.md")
|
|
445
|
+
README_MD = os.path.join(tmp, "README.md")
|
|
446
|
+
CHANGELOG_MD = os.path.join(tmp, "CHANGELOG.md")
|
|
447
|
+
|
|
448
|
+
# 1) 全绿基线(v4.0.0:含三份外置长表 + 租户级图例)
|
|
449
|
+
def write_baseline():
|
|
450
|
+
_write(SKILL_MD, "---\nversion: 9.9.9\n---\n"
|
|
451
|
+
"## 分层\n\n"
|
|
452
|
+
"方案确认一次、施工结果按模块批量自动验收、交付最终汇总。\n"
|
|
453
|
+
"首次直建一次,删后回读,来源不明不删;已有默认分类,无可用分类 pending;\n"
|
|
454
|
+
"课程和题库分类照原文,必要结果回读保留。\n"
|
|
455
|
+
"| 文件 | 内容 |\n|---|---|\n"
|
|
456
|
+
"| `references/contracts.md` | 契约速查 |\n"
|
|
457
|
+
"| `references/anti-patterns.md` | 反面模式全集 |\n"
|
|
458
|
+
"| `references/gates-matrix.md` | 闸门矩阵 |\n\n"
|
|
459
|
+
"## 反面模式黑名单\n\n| # | a | b |\n|---|---|---|\n"
|
|
460
|
+
"| 1 | x | y |\n| 2 | x | y |\n\n## 闸门\n")
|
|
461
|
+
_write(README_MD, "当前 `9.9.9`。\n载荷 `img_picked:0`;日志前 120 字符截断。\n")
|
|
462
|
+
_write(CHANGELOG_MD, "## 9.9.9 — x\n")
|
|
463
|
+
_write(os.path.join(REFS_DIR, "contracts.md"), "# 契约速查\n")
|
|
464
|
+
_write(os.path.join(REFS_DIR, "anti-patterns.md"),
|
|
465
|
+
"# 反面模式黑名单\n\n| 1 | x | y |\n| 2 | x | y |\n")
|
|
466
|
+
_write(os.path.join(REFS_DIR, "gates-matrix.md"), "# 闸门\n")
|
|
467
|
+
legend = "## 零、结论口径分级\n\n| `%s` | 租户 |\n" % TENANT_TAG
|
|
468
|
+
rows = "".join("| `%s` %s | x | y |\n" % (TENANT_TAG, a) for a in TENANT_ANCHORS)
|
|
469
|
+
_write(os.path.join(REFS_DIR, "platform-commands.md"), legend + rows)
|
|
470
|
+
|
|
471
|
+
write_baseline()
|
|
472
|
+
ok = all(c()["ok"] for c in CHECKS)
|
|
473
|
+
ck(ok, "基线全绿")
|
|
474
|
+
|
|
475
|
+
# 2) img_picked=1 必须被抓
|
|
476
|
+
_write(README_MD, "当前 `9.9.9`。\n载荷 `img_picked:1`。\n")
|
|
477
|
+
ck(not check_img_picked()["ok"], "抓到 img_picked=1")
|
|
478
|
+
# 2b) 带「原写」的历史说明不算违规
|
|
479
|
+
_write(README_MD, "当前 `9.9.9`。\n本条原写 `img_picked:1`,已改。\n")
|
|
480
|
+
ck(check_img_picked()["ok"], "历史说明豁免")
|
|
481
|
+
|
|
482
|
+
# 3) 截断 200 必须被抓
|
|
483
|
+
_write(README_MD, "当前 `9.9.9`。\n日志超 200 字符截断。\n")
|
|
484
|
+
ck(not check_log_truncate()["ok"], "抓到 200 字符")
|
|
485
|
+
_write(README_MD, "当前 `9.9.9`。\n日志前 120 字符截断。\n")
|
|
486
|
+
ck(check_log_truncate()["ok"], "120 字符通过")
|
|
487
|
+
|
|
488
|
+
# 4) 后缀重建必须被抓,「不加数字后缀」不算
|
|
489
|
+
_write(README_MD, "当前 `9.9.9`。\n撞名 → 名称追加数字后缀重建。\n")
|
|
490
|
+
ck(not check_suffix_policy()["ok"], "抓到后缀重建")
|
|
491
|
+
_write(README_MD, "当前 `9.9.9`。\n命中即复用,⛔ 不加数字后缀。\n")
|
|
492
|
+
ck(check_suffix_policy()["ok"], "首建直建及失败恢复不加后缀口径通过")
|
|
493
|
+
|
|
494
|
+
# 5) 版本不一致必须被抓
|
|
495
|
+
_write(README_MD, "当前 `1.0.0`。\n")
|
|
496
|
+
ck(not check_versions()["ok"], "抓到版本不一致")
|
|
497
|
+
_write(README_MD, "当前 `9.9.9`。\n")
|
|
498
|
+
ck(check_versions()["ok"], "版本一致通过")
|
|
499
|
+
|
|
500
|
+
# 6) 章节重号必须被抓
|
|
501
|
+
_write(REFS_DIR + "/x.md", "## 六、a\n## 七、b\n## 六、c\n")
|
|
502
|
+
ck(not check_section_numbers()["ok"], "抓到章节重号")
|
|
503
|
+
_write(REFS_DIR + "/x.md", "## 六、a\n## 七、b\n## 八、c\n")
|
|
504
|
+
ck(check_section_numbers()["ok"], "顺序章节通过")
|
|
505
|
+
|
|
506
|
+
# 7) 反面模式乱序必须被抓
|
|
507
|
+
_write(SKILL_MD, "---\nversion: 9.9.9\n---\n## 反面模式黑名单\n\n| 1 | x | y |\n| 3 | x | y |\n| 2 | x | y |\n")
|
|
508
|
+
ck(not check_blacklist_order()["ok"], "抓到黑名单乱序")
|
|
509
|
+
# 7b) 后缀条目(6 与 6b)不是重复,detail 要说清楚
|
|
510
|
+
_write(SKILL_MD, "---\nversion: 9.9.9\n---\n## 反面模式黑名单\n\n"
|
|
511
|
+
"| 1 | x | y |\n| 6 | x | y |\n| 6b | x | y |\n| 7 | x | y |\n")
|
|
512
|
+
r = check_blacklist_order()
|
|
513
|
+
ck(r["ok"], "6 与 6b 不算重复")
|
|
514
|
+
ck("6b" in r["detail"], "后缀条目在 detail 里点名(条数≠最大编号有解释)")
|
|
515
|
+
# 7c) 真重复编号必须被抓
|
|
516
|
+
_write(SKILL_MD, "---\nversion: 9.9.9\n---\n## 反面模式黑名单\n\n| 1 | x | y |\n| 2 | x | y |\n| 2 | x | y |\n")
|
|
517
|
+
ck(not check_blacklist_order()["ok"], "抓到真重复编号")
|
|
518
|
+
|
|
519
|
+
# 8) @references 残留必须被抓
|
|
520
|
+
_write(REFS_DIR + "/x.md", "见 `@references/y.md`\n")
|
|
521
|
+
ck(not check_at_references()["ok"], "抓到 @references")
|
|
522
|
+
_write(REFS_DIR + "/x.md", "见 `references/y.md`\n")
|
|
523
|
+
_write(REFS_DIR + "/y.md", "# y\n")
|
|
524
|
+
ck(check_at_references()["ok"], "无反残留")
|
|
525
|
+
ck(check_refs_links()["ok"], "引用完整")
|
|
526
|
+
_write(REFS_DIR + "/x.md", "见 `references/nope.md`\n")
|
|
527
|
+
ck(not check_refs_links()["ok"], "抓到断链")
|
|
528
|
+
|
|
529
|
+
# 9) 包卫生
|
|
530
|
+
_write(os.path.join(tmp, ".DS_Store"), "x")
|
|
531
|
+
ck(not check_package_hygiene()["ok"], "抓到 .DS_Store")
|
|
532
|
+
os.remove(os.path.join(tmp, ".DS_Store"))
|
|
533
|
+
ck(check_package_hygiene()["ok"], "卫生通过")
|
|
534
|
+
|
|
535
|
+
# 10) SKILL 体量超预算必须被抓
|
|
536
|
+
write_baseline()
|
|
537
|
+
_write(SKILL_MD, _read(SKILL_MD) + "\n" + "x" * (SKILL_MAX_CHARS + 100))
|
|
538
|
+
ck(not check_skill_budget()["ok"], "抓到 SKILL 超体量")
|
|
539
|
+
write_baseline()
|
|
540
|
+
ck(check_skill_budget()["ok"], "体量预算通过")
|
|
541
|
+
|
|
542
|
+
# 11) 外置文件缺失 / SKILL 无指针 必须被抓
|
|
543
|
+
os.remove(os.path.join(REFS_DIR, "contracts.md"))
|
|
544
|
+
ck(not check_externalized()["ok"], "抓到外置文件缺失")
|
|
545
|
+
write_baseline()
|
|
546
|
+
_write(SKILL_MD, "---\nversion: 9.9.9\n---\n## 闸门\n")
|
|
547
|
+
ck(not check_externalized()["ok"], "抓到 SKILL 无外置指针")
|
|
548
|
+
write_baseline()
|
|
549
|
+
ck(check_externalized()["ok"], "外置齐备通过")
|
|
550
|
+
|
|
551
|
+
# 11b) 闸门命名空间:裸编号 / 悬空引用必须被抓
|
|
552
|
+
_write(REFS_DIR + "/gates-matrix.md", "| # | x |\n|---|---|\n| G-1 | 施工序 |\n")
|
|
553
|
+
_write(REFS_DIR + "/plan.md", "| # | x |\n|---|---|\n| P-1 | 解析 |\n")
|
|
554
|
+
_write(REFS_DIR + "/x.md", "见闸门 `G-1`,另见 `P-1`。\n")
|
|
555
|
+
ck(check_gate_namespace()["ok"], "命名空间引用通过")
|
|
556
|
+
_write(REFS_DIR + "/x.md", "见闸门 7 的判据。\n")
|
|
557
|
+
ck(not check_gate_namespace()["ok"], "抓到裸编号")
|
|
558
|
+
_write(REFS_DIR + "/x.md", "见闸门 `G-99`。\n")
|
|
559
|
+
ck(not check_gate_namespace()["ok"], "抓到悬空闸门引用")
|
|
560
|
+
os.remove(REFS_DIR + "/x.md")
|
|
561
|
+
write_baseline()
|
|
562
|
+
|
|
563
|
+
# 12) 租户级漏标必须被抓
|
|
564
|
+
pc = os.path.join(REFS_DIR, "platform-commands.md")
|
|
565
|
+
_write(pc, _read(pc).replace("`%s` 商品全量回写" % TENANT_TAG, "商品全量回写"))
|
|
566
|
+
ck(not check_tenant_tags()["ok"], "抓到租户级漏标")
|
|
567
|
+
_write(pc, _read(pc).replace("## 零、结论口径分级", "## 其他"))
|
|
568
|
+
ck(not check_tenant_tags()["ok"], "抓到缺口径图例")
|
|
569
|
+
write_baseline()
|
|
570
|
+
ck(check_tenant_tags()["ok"], "租户级标记通过")
|
|
571
|
+
|
|
572
|
+
# 13) 三阶段合并不取消核心技术检查。
|
|
573
|
+
ck(check_execution_policy()["ok"], "三阶段与创建默认分类基线通过")
|
|
574
|
+
_write(README_MD, _read(README_MD) + "\nStep 未过闸门禁止进下一步\n")
|
|
575
|
+
ck(not check_execution_policy()["ok"], "抓到细步骤独立闸门回退")
|
|
576
|
+
write_baseline()
|
|
577
|
+
_write(README_MD, _read(README_MD) + "\n交付前 scripts/dup_scan.py 必跑\n")
|
|
578
|
+
ck(not check_execution_policy()["ok"], "抓到交付强制全租户扫描")
|
|
579
|
+
write_baseline()
|
|
580
|
+
_write(SKILL_MD, _read(SKILL_MD).replace("来源不明不删", "未知也删"))
|
|
581
|
+
ck(not check_execution_policy()["ok"], "缺失未知归属不删护栏必须阻塞")
|
|
582
|
+
write_baseline()
|
|
583
|
+
ck(check_img_picked()["ok"] and check_img_url_criterion()["ok"], "合并调度仍保留封面核心检查")
|
|
584
|
+
ck(check_cap_single_source()["ok"], "文档完整范围通过,不再执行旧配额")
|
|
585
|
+
|
|
586
|
+
SKILL_DIR, REFS_DIR, SKILL_MD, README_MD, CHANGELOG_MD = saved
|
|
587
|
+
failed = [label for ok, label in cases if not ok]
|
|
588
|
+
for ok, label in cases:
|
|
589
|
+
print(" %s %s" % ("PASS" if ok else "FAIL", label))
|
|
590
|
+
print("[self-test] %d/%d PASS" % (len(cases) - len(failed), len(cases)))
|
|
591
|
+
return 0 if not failed else 1
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
# ------------------------------------------------------------------ 入口
|
|
595
|
+
|
|
596
|
+
def main(argv=None) -> int:
|
|
597
|
+
ap = argparse.ArgumentParser(description="demo-init 文档一致性门禁")
|
|
598
|
+
ap.add_argument("--json", action="store_true", help="只输出 JSON")
|
|
599
|
+
ap.add_argument("--self-test", action="store_true", help="检测器自测")
|
|
600
|
+
args = ap.parse_args(argv)
|
|
601
|
+
|
|
602
|
+
if args.self_test:
|
|
603
|
+
return self_test()
|
|
604
|
+
|
|
605
|
+
results = [fn() for fn in CHECKS]
|
|
606
|
+
bad = [r for r in results if not r["ok"]]
|
|
607
|
+
payload = {"ok": not bad, "skill_dir": SKILL_DIR, "checks": results}
|
|
608
|
+
if args.json:
|
|
609
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
610
|
+
else:
|
|
611
|
+
print("demo-init 文档一致性门禁 | %s" % SKILL_DIR)
|
|
612
|
+
for r in results:
|
|
613
|
+
print(" [%s] %-20s %s" % ("OK " if r["ok"] else "FAIL", r["name"], r["detail"]))
|
|
614
|
+
print("\n结论:%s(违规 %d 项)" % ("口径一致" if not bad else "存在互相打架的口径,先修再分发", len(bad)))
|
|
615
|
+
return 0 if not bad else 2
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
if __name__ == "__main__":
|
|
619
|
+
sys.exit(main())
|