@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,387 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""scope_plan.py — 文档实体范围记录器,不替用户选择、裁剪或填充业务。
|
|
4
|
+
|
|
5
|
+
输入为 plan-parse 完整抽取的 plan-entities.json:
|
|
6
|
+
{"portals":[{"name":"门户名"}], "courses":[{"title":"课名"}],
|
|
7
|
+
"maps":[{"name":"地图名", "stages":[{"name":"阶段名",
|
|
8
|
+
"courses":["课A","课B"], "exam":"考试名"}]}],
|
|
9
|
+
"exams":[{"name":"考试名"}], "projects":[{"name":"培训班名"}]}
|
|
10
|
+
阶段也可用 course 单课程或 items[];exams[] 可记录同阶段多个考试。
|
|
11
|
+
扁平 maps[].courses 仅按已给课程顺序展开,不补四阶段、不自动加考试。
|
|
12
|
+
显式 plan_only_maps 原样留痕;未提供的对象保持为空,缺项进入 unresolved。
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
PY scripts/scope_plan.py --entities raw.json --out-dir <蓝图目录>
|
|
16
|
+
PY scripts/scope_plan.py --verify-blueprint <bp.json>
|
|
17
|
+
PY scripts/scope_plan.py --self-test
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import re
|
|
26
|
+
import sys
|
|
27
|
+
|
|
28
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
29
|
+
from cli_kit import ensure_utf8_stdio, load_json, save_json # noqa: E402
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def entity_name(obj):
|
|
33
|
+
if isinstance(obj, dict):
|
|
34
|
+
return (obj.get("title") or obj.get("name") or "").strip()
|
|
35
|
+
return str(obj).strip() if obj is not None else ""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _list(value):
|
|
39
|
+
return value if isinstance(value, list) else ([] if value in (None, "") else [value])
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def norm_map(m):
|
|
43
|
+
"""保留阶段数、顺序与显式参数,不猜名称、不补阶段内容。"""
|
|
44
|
+
name = entity_name(m)
|
|
45
|
+
audience = m.get("audience")
|
|
46
|
+
is_new = audience == "new_employee" if audience is not None else bool(
|
|
47
|
+
re.search(r"新员工|入职|新兵营|新客户经理", name))
|
|
48
|
+
stages = []
|
|
49
|
+
if "stages" in m:
|
|
50
|
+
raw_stages = m.get("stages") or []
|
|
51
|
+
else:
|
|
52
|
+
raw_stages = [{"courses": [c]} for c in _list(m.get("courses"))]
|
|
53
|
+
if raw_stages and m.get("exam"):
|
|
54
|
+
raw_stages[-1]["exam"] = m["exam"]
|
|
55
|
+
for st in raw_stages:
|
|
56
|
+
st = dict(st) if isinstance(st, dict) else {"courses": [st]}
|
|
57
|
+
refs = _list(st.get("courses", st.get("course")))
|
|
58
|
+
exams = _list(st.get("exams", st.get("exam")))
|
|
59
|
+
if "items" in st:
|
|
60
|
+
refs = [it.get("course", it.get("title", it.get("course_ref")))
|
|
61
|
+
for it in st["items"] or [] if it.get("type") == "course"]
|
|
62
|
+
exams = [it.get("exam", it.get("name", it.get("exam_ref")))
|
|
63
|
+
for it in st["items"] or [] if it.get("type") == "exam"]
|
|
64
|
+
stages.append({**st, "name": st.get("name") or "", "refs": refs,
|
|
65
|
+
"exams": exams, "exam": exams[0] if exams else ""})
|
|
66
|
+
return {**m, "name": name, "is_new": is_new, "stages": stages}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def fill_map(m, idx, chosen, exams):
|
|
70
|
+
"""兼容旧单课程字段,并完整记录每阶段多课程及任意阶段考试。"""
|
|
71
|
+
items = []
|
|
72
|
+
for st in m["stages"]:
|
|
73
|
+
references = ([{"type": it["type"], "ref": it.get("course", it.get("title", it.get("course_ref")))
|
|
74
|
+
if it["type"] == "course" else it.get("exam", it.get("name", it.get("exam_ref")))}
|
|
75
|
+
for it in st["items"] or [] if it.get("type") in ("course", "exam")]
|
|
76
|
+
if "items" in st else
|
|
77
|
+
[{"type": "course", "ref": ref} for ref in st["refs"]] +
|
|
78
|
+
[{"type": "exam", "ref": ref} for ref in st["exams"]])
|
|
79
|
+
items.append({"stage": st["name"], "course_ref": st["refs"][0] if st["refs"] else None,
|
|
80
|
+
"course_refs": list(st["refs"]),
|
|
81
|
+
"exam_ref": st["exams"][0] if st["exams"] else "",
|
|
82
|
+
"exam_refs": list(st["exams"]), "references": references, "degraded": None})
|
|
83
|
+
return items
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def build_plan(raw):
|
|
87
|
+
names = {key: [entity_name(o) for o in raw.get(key) or []]
|
|
88
|
+
for key in ("courses", "exams", "projects", "portals")}
|
|
89
|
+
maps = [norm_map(m) for m in raw.get("maps") or []]
|
|
90
|
+
plan_only = list(raw.get("plan_only_maps") or [])
|
|
91
|
+
unresolved = []
|
|
92
|
+
for key, values in names.items():
|
|
93
|
+
for i, name in enumerate(values):
|
|
94
|
+
if not name:
|
|
95
|
+
unresolved.append({"path": "%s[%d]" % (key, i), "reason": "名称待明确"})
|
|
96
|
+
plan_maps = []
|
|
97
|
+
for mi, m in enumerate(maps):
|
|
98
|
+
if not m["name"]:
|
|
99
|
+
unresolved.append({"path": "maps[%d].name" % mi, "reason": "名称待明确"})
|
|
100
|
+
if not m["stages"]:
|
|
101
|
+
unresolved.append({"path": "maps[%d].stages" % mi, "reason": "阶段待明确"})
|
|
102
|
+
for si, st in enumerate(m["stages"]):
|
|
103
|
+
if not st["refs"] and not st["exams"] and not st.get("items"):
|
|
104
|
+
unresolved.append({"path": "maps[%d].stages[%d].items" % (mi, si),
|
|
105
|
+
"reason": "阶段内容待明确,不自动配课考"})
|
|
106
|
+
if not st["name"]:
|
|
107
|
+
unresolved.append({"path": "maps[%d].stages[%d].name" % (mi, si),
|
|
108
|
+
"reason": "阶段名称待明确"})
|
|
109
|
+
for kind, refs in (("courses", st["refs"]), ("exams", st["exams"])):
|
|
110
|
+
for ref in refs:
|
|
111
|
+
valid = (type(ref) is int and 0 <= ref < len(names[kind])) or (
|
|
112
|
+
isinstance(ref, str) and ref in names[kind])
|
|
113
|
+
if not valid:
|
|
114
|
+
unresolved.append({"path": "maps[%d].stages[%d].%s" % (mi, si, kind),
|
|
115
|
+
"reference": ref, "reason": "引用对象待明确,不替换"})
|
|
116
|
+
plan_maps.append({**m, "items": fill_map(m, mi, names["courses"], names["exams"])})
|
|
117
|
+
cats = []
|
|
118
|
+
for c in raw.get("courses") or []:
|
|
119
|
+
path = c.get("category_path") if isinstance(c, dict) else None
|
|
120
|
+
for node in (path.split("/") if isinstance(path, str) else path or []):
|
|
121
|
+
if node and node not in cats:
|
|
122
|
+
cats.append(node)
|
|
123
|
+
return {
|
|
124
|
+
"scope": {**{k: len(v) for k, v in names.items()}, "maps": len(plan_maps),
|
|
125
|
+
"maps_plan_only": len(plan_only), "categories": len(cats), "rotation_items": 0},
|
|
126
|
+
**names, "maps": plan_maps, "maps_plan_only": plan_only, "categories": cats,
|
|
127
|
+
"taxonomies": raw.get("taxonomies") or {},
|
|
128
|
+
"project_details": list(raw.get("projects") or []),
|
|
129
|
+
"dropped": [], "unresolved": unresolved,
|
|
130
|
+
"commitment": commitment(names["courses"], plan_maps, plan_only,
|
|
131
|
+
names["exams"], names["projects"], names["portals"]),
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def commitment(chosen, plan_maps, plan_only, exams, projects, portals=None):
|
|
136
|
+
parts = ["门户%d个" % len(portals or []), "课程%d门" % len(chosen),
|
|
137
|
+
"地图%d张" % len(plan_maps), "考试%d场" % len(exams), "培训班%d个" % len(projects)]
|
|
138
|
+
if plan_only:
|
|
139
|
+
parts.append("另有%d张地图显式标 plan_only 不建" % len(plan_only))
|
|
140
|
+
return "SCOPE 承诺:" + " / ".join(parts)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
REMOVED_KEYS = ("homeworks", "tier")
|
|
144
|
+
ALLOWED_TOP = {"meta", "customer", "portals", "taxonomies", "courses", "exams", "maps",
|
|
145
|
+
"plan_only_maps", "projects", "incentives", "assets", "timeline"}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def verify_blueprint(bp, plan):
|
|
149
|
+
"""独立比对建设量与 plan_only,尽可能核验名称、顺序及阶段引用。"""
|
|
150
|
+
diffs, shape = [], []
|
|
151
|
+
if not isinstance(bp, dict) or not bp:
|
|
152
|
+
return {"ok": False, "diffs": ["BLUEPRINT 读不到或为空"], "shape": []}
|
|
153
|
+
if not isinstance(plan, dict) or not plan.get("scope"):
|
|
154
|
+
return {"ok": False, "diffs": ["scope-plan.json 读不到或缺 scope 段"], "shape": []}
|
|
155
|
+
sc = plan["scope"]
|
|
156
|
+
for key in ("courses", "maps", "maps_plan_only", "exams", "projects", "portals"):
|
|
157
|
+
bp_key = "plan_only_maps" if key == "maps_plan_only" else key
|
|
158
|
+
got = bp.get(bp_key) or []
|
|
159
|
+
if key not in sc:
|
|
160
|
+
diffs.append("scope 缺 %s,需按文档重新记录" % key)
|
|
161
|
+
elif len(got) != sc[key]:
|
|
162
|
+
diffs.append("%s:BLUEPRINT=%d,scope=%s" % (key, len(got), sc[key]))
|
|
163
|
+
if isinstance(plan.get(key), list):
|
|
164
|
+
expected_names = [entity_name(o) for o in plan[key]]
|
|
165
|
+
if [entity_name(o) for o in got] != expected_names:
|
|
166
|
+
diffs.append("%s 名称或顺序与文档范围不一致" % key)
|
|
167
|
+
for mi, (actual, expected) in enumerate(zip(bp.get("maps") or [], plan.get("maps") or [])):
|
|
168
|
+
if "items" not in expected:
|
|
169
|
+
continue
|
|
170
|
+
stages = actual.get("stages") or []
|
|
171
|
+
if len(stages) != len(expected["items"]):
|
|
172
|
+
diffs.append("maps[%d] 阶段数与文档不一致" % mi)
|
|
173
|
+
for si, (st, item) in enumerate(zip(stages, expected["items"])):
|
|
174
|
+
if st.get("name", "") != item.get("stage", ""):
|
|
175
|
+
diffs.append("maps[%d].stages[%d] 名称与文档不一致" % (mi, si))
|
|
176
|
+
for kind, field, plural in (("course", "courses", "course_refs"),
|
|
177
|
+
("exam", "exams", "exam_refs")):
|
|
178
|
+
want = item.get(plural, _list(item.get(kind + "_ref")))
|
|
179
|
+
want = [entity_name((plan.get(field) or [])[r])
|
|
180
|
+
if type(r) is int and 0 <= r < len(plan.get(field) or []) else r for r in want]
|
|
181
|
+
refs = [it.get(kind + "_ref") for it in st.get("items") or [] if it.get("type") == kind]
|
|
182
|
+
got = [entity_name((bp.get(field) or [])[r])
|
|
183
|
+
if type(r) is int and 0 <= r < len(bp.get(field) or []) else None for r in refs]
|
|
184
|
+
if got != want:
|
|
185
|
+
diffs.append("maps[%d].stages[%d] %s 引用与文档不一致" % (mi, si, kind))
|
|
186
|
+
if "references" in item:
|
|
187
|
+
want_order = []
|
|
188
|
+
for ref in item["references"]:
|
|
189
|
+
field = "courses" if ref["type"] == "course" else "exams"
|
|
190
|
+
value = ref["ref"]
|
|
191
|
+
if type(value) is int and 0 <= value < len(plan.get(field) or []):
|
|
192
|
+
value = entity_name(plan[field][value])
|
|
193
|
+
want_order.append((ref["type"], value))
|
|
194
|
+
actual_order = []
|
|
195
|
+
for ref in st.get("items") or []:
|
|
196
|
+
if ref.get("type") not in ("course", "exam"):
|
|
197
|
+
continue
|
|
198
|
+
field = "courses" if ref["type"] == "course" else "exams"
|
|
199
|
+
value = ref.get(ref["type"] + "_ref")
|
|
200
|
+
value = entity_name(bp[field][value]) if type(value) is int and 0 <= value < len(bp.get(field) or []) else None
|
|
201
|
+
actual_order.append((ref["type"], value))
|
|
202
|
+
if actual_order != want_order:
|
|
203
|
+
diffs.append("maps[%d].stages[%d] 课考混排顺序与文档不一致" % (mi, si))
|
|
204
|
+
if isinstance(plan.get("taxonomies"), dict):
|
|
205
|
+
for key, expected in plan["taxonomies"].items():
|
|
206
|
+
actual = (bp.get("taxonomies") or {}).get(key) or []
|
|
207
|
+
if actual != (expected or []):
|
|
208
|
+
diffs.append("taxonomies.%s 分类完整树或顺序与文档不一致" % key)
|
|
209
|
+
|
|
210
|
+
def project_refs(project, entities):
|
|
211
|
+
out = []
|
|
212
|
+
config = (project.get("config") or {}) if isinstance(project, dict) else {}
|
|
213
|
+
for item in config.get("items") or []:
|
|
214
|
+
kind = item.get("type")
|
|
215
|
+
field = "courses" if kind == "course" else "exams"
|
|
216
|
+
ref = item.get(kind + "_ref", item.get(kind)) if isinstance(kind, str) else None
|
|
217
|
+
if type(ref) is int:
|
|
218
|
+
ref = entity_name(entities[field][ref]) if 0 <= ref < len(entities.get(field) or []) else None
|
|
219
|
+
out.append((kind, ref))
|
|
220
|
+
return out
|
|
221
|
+
|
|
222
|
+
if isinstance(plan.get("project_details"), list):
|
|
223
|
+
for i, (actual, expected) in enumerate(zip(bp.get("projects") or [], plan["project_details"])):
|
|
224
|
+
if project_refs(actual, bp) != project_refs(expected, plan):
|
|
225
|
+
diffs.append("projects[%d].config.items 原序挂载与文档不一致" % i)
|
|
226
|
+
unknown = sorted(set(bp) - ALLOWED_TOP - set(REMOVED_KEYS))
|
|
227
|
+
if unknown:
|
|
228
|
+
shape.append("顶层出现未知字段:%s" % "、".join(unknown))
|
|
229
|
+
for key in REMOVED_KEYS:
|
|
230
|
+
if key in bp:
|
|
231
|
+
shape.append("出现已移除字段 `%s`" % key)
|
|
232
|
+
plan_only = bp.get("plan_only_maps") or []
|
|
233
|
+
if not isinstance(plan_only, list):
|
|
234
|
+
shape.append("plan_only_maps 不是数组")
|
|
235
|
+
else:
|
|
236
|
+
for i, m in enumerate(plan_only):
|
|
237
|
+
if not isinstance(m, dict):
|
|
238
|
+
shape.append("plan_only_maps[%d] 不是对象" % i)
|
|
239
|
+
continue
|
|
240
|
+
miss = [f for f in ("name", "reason") if not m.get(f)]
|
|
241
|
+
if miss:
|
|
242
|
+
shape.append("plan_only_maps[%d] 缺字段 %s" % (i, "、".join(miss)))
|
|
243
|
+
if "stages" in m:
|
|
244
|
+
shape.append("plan_only_maps[%d] 不得含 stages(不建的图没有施工阶段)" % i)
|
|
245
|
+
return {"ok": not (diffs or shape), "diffs": diffs, "shape": shape}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def run(args):
|
|
249
|
+
if args.verify_blueprint:
|
|
250
|
+
bp = load_json(args.verify_blueprint, {})
|
|
251
|
+
plan = load_json(args.scope_plan or os.path.join(os.path.dirname(
|
|
252
|
+
os.path.abspath(args.verify_blueprint)), "scope-plan.json"), {})
|
|
253
|
+
res = verify_blueprint(bp, plan)
|
|
254
|
+
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
255
|
+
return 0 if res["ok"] else 2
|
|
256
|
+
raw = load_json(args.entities, None)
|
|
257
|
+
if not isinstance(raw, dict):
|
|
258
|
+
print("读不到实体文件:%s" % args.entities)
|
|
259
|
+
return 2
|
|
260
|
+
plan = build_plan(raw)
|
|
261
|
+
print(plan["commitment"])
|
|
262
|
+
for item in plan["unresolved"]:
|
|
263
|
+
print(" 待明确 %s:%s" % (item["path"], item["reason"]))
|
|
264
|
+
if args.out_dir:
|
|
265
|
+
out = os.path.join(args.out_dir, "scope-plan.json")
|
|
266
|
+
save_json(out, plan)
|
|
267
|
+
print("→ %s" % out)
|
|
268
|
+
if args.json:
|
|
269
|
+
print(json.dumps(plan, ensure_ascii=False, indent=2))
|
|
270
|
+
return 0
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def self_test():
|
|
274
|
+
cases = []
|
|
275
|
+
|
|
276
|
+
def ck(cond, label):
|
|
277
|
+
cases.append((bool(cond), label))
|
|
278
|
+
|
|
279
|
+
raw = {"portals": [{"name": "门户B"}, {"name": "门户A"}],
|
|
280
|
+
"courses": [{"title": "c%d" % i, "flag": "必修" if i == 15 else ""} for i in range(21)],
|
|
281
|
+
"maps": [{"name": "通用图"}, {"name": "新员工图", "audience": "general",
|
|
282
|
+
"stages": [{"name": "阶段一", "courses": ["c0", "c1"], "exam": "e1", "days": 9},
|
|
283
|
+
{"name": "阶段二", "course": "c2", "exams": ["e0", "e2"]},
|
|
284
|
+
{"name": "阶段三", "courses": []}]}] +
|
|
285
|
+
[{"name": "图%d" % i, "stages": []} for i in range(7)],
|
|
286
|
+
"exams": [{"name": "e%d" % i} for i in range(8)],
|
|
287
|
+
"projects": [{"name": "p%d" % i} for i in range(4)]}
|
|
288
|
+
plan = build_plan(raw)
|
|
289
|
+
ck(plan["scope"]["courses"] == 21 and plan["courses"][15] == "c15", "课程完整保序,不按必修重排")
|
|
290
|
+
ck(plan["scope"]["maps"] == 9 and plan["maps_plan_only"] == [], "全部地图保留,不按覆盖度减图")
|
|
291
|
+
ck(plan["scope"]["exams"] == 8 and plan["scope"]["projects"] == 4, "考试培训班不裁剪")
|
|
292
|
+
ck(plan["scope"]["portals"] == 2 and plan["portals"] == ["门户B", "门户A"], "门户数量名称保序")
|
|
293
|
+
ck(plan["maps"][1]["is_new"] is False, "明确 audience 优先于名称推断")
|
|
294
|
+
items = plan["maps"][1]["items"]
|
|
295
|
+
ck(items[0]["course_ref"] == "c0" and items[0]["course_refs"] == ["c0", "c1"], "单课程兼容字段和多课程并存")
|
|
296
|
+
ck(items[0]["exam_ref"] == "e1" and items[1]["exam_refs"] == ["e0", "e2"], "任意阶段和多个考试保留")
|
|
297
|
+
ck(items[2]["course_refs"] == [] and items[2]["exam_ref"] == "" and
|
|
298
|
+
any("items" in u["path"] for u in plan["unresolved"]), "空阶段不补课考并标待明确")
|
|
299
|
+
ck(plan["maps"][1]["stages"][0]["days"] == 9, "显式阶段参数保留")
|
|
300
|
+
ck(norm_map({"name": "扁平", "courses": ["A", "B"]})["stages"][-1]["refs"] == ["B"], "扁平课程不补四阶段")
|
|
301
|
+
ck(norm_map({"name": "缺阶段"})["stages"] == [], "缺阶段待明确,不造四阶段")
|
|
302
|
+
ck(build_plan({})["scope"]["portals"] == 0, "空文档不默认门户")
|
|
303
|
+
missing = build_plan({"maps": [{"name": "缺引用", "stages": [{"name": "一", "course": "不存在"}]}]})
|
|
304
|
+
ck(missing["maps"][0]["items"][0]["course_refs"] == ["不存在"] and bool(missing["unresolved"]), "缺引用保留待明确,不语义轮转")
|
|
305
|
+
bp = {"courses": raw["courses"], "exams": raw["exams"], "portals": raw["portals"],
|
|
306
|
+
"projects": raw["projects"], "maps": []}
|
|
307
|
+
for m in plan["maps"]:
|
|
308
|
+
stages = []
|
|
309
|
+
for item in m["items"]:
|
|
310
|
+
stages.append({"name": item["stage"], "items":
|
|
311
|
+
[{"type": "course", "course_ref": plan["courses"].index(c)} for c in item["course_refs"]] +
|
|
312
|
+
[{"type": "exam", "exam_ref": plan["exams"].index(e)} for e in item["exam_refs"]]})
|
|
313
|
+
bp["maps"].append({"name": m["name"], "stages": stages})
|
|
314
|
+
ck(verify_blueprint(bp, plan)["ok"], "超过旧配额蓝图及引用对账通过")
|
|
315
|
+
bp["maps"][1]["stages"][0]["items"][0]["course_ref"] = 3
|
|
316
|
+
ck(not verify_blueprint(bp, plan)["ok"], "合法下标但引用对象替换也拦截")
|
|
317
|
+
bp["maps"][1]["stages"][0]["items"][0]["course_ref"] = 0
|
|
318
|
+
bp["portals"][0] = {"name": "被改名"}
|
|
319
|
+
ck(not verify_blueprint(bp, plan)["ok"], "同数量门户改名拦截")
|
|
320
|
+
simple = build_plan({"maps": [{"name": "A"}], "plan_only_maps": [{"name": "B", "reason": "user_cut"}]})
|
|
321
|
+
ck(verify_blueprint({"maps": [{"name": "A", "stages": []}], "plan_only_maps": [{"name": "B", "reason": "user_cut"}]}, simple)["ok"], "显式 plan_only 可独立对账")
|
|
322
|
+
ck(not verify_blueprint({"maps": [], "plan_only_maps": [{"name": "A", "reason": "user_cut"}, {"name": "B", "reason": "user_cut"}]}, simple)["ok"], "地图总数相同但转 plan_only 也拦截")
|
|
323
|
+
ck(not verify_blueprint({"homeworks": []}, build_plan({}))["ok"], "移除字段仍拦截")
|
|
324
|
+
ck(not verify_blueprint({}, plan)["ok"] and not verify_blueprint(bp, {})["ok"], "缺蓝图或 scope 阻塞")
|
|
325
|
+
ck("门户2个" in plan["commitment"] and plan["dropped"] == [], "承诺按真实范围无剔除")
|
|
326
|
+
mixed = build_plan({"courses": [{"title": "A"}, {"title": "B"}], "exams": [{"name": "考"}],
|
|
327
|
+
"maps": [{"name": "混排", "stages": [{"name": "一", "items": [
|
|
328
|
+
{"type": "course", "course_ref": 0}, {"type": "exam", "exam_ref": 0},
|
|
329
|
+
{"type": "course", "course_ref": 1}]}]}]})
|
|
330
|
+
mixed_bp = {"courses": [{"title": "A"}, {"title": "B"}], "exams": [{"name": "考"}],
|
|
331
|
+
"maps": [{"name": "混排", "stages": [{"name": "一", "items": [
|
|
332
|
+
{"type": "course", "course_ref": 0}, {"type": "exam", "exam_ref": 0},
|
|
333
|
+
{"type": "course", "course_ref": 1}]}]}]}
|
|
334
|
+
ck(verify_blueprint(mixed_bp, mixed)["ok"], "课程考试混排原顺序可核验")
|
|
335
|
+
mixed_bp["maps"][0]["stages"][0]["items"][1:] = reversed(mixed_bp["maps"][0]["stages"][0]["items"][1:])
|
|
336
|
+
ck(not verify_blueprint(mixed_bp, mixed)["ok"], "课考各自顺序不变但混排改变也拦截")
|
|
337
|
+
import copy
|
|
338
|
+
full = {"courses": [{"title": "A"}, {"title": "B"}], "exams": [{"name": "考"}],
|
|
339
|
+
"taxonomies": {"course": [{"l1": "空分类", "l2": ["空子类"]}, {"l1": "有课分类", "l2": []}]},
|
|
340
|
+
"projects": [{"name": "班", "config": {"items": [
|
|
341
|
+
{"type": "course", "course_ref": 0}, {"type": "exam", "exam_ref": 0}]}}]}
|
|
342
|
+
full_plan = build_plan(full)
|
|
343
|
+
ck(verify_blueprint(full, full_plan)["ok"], "文档完整分类树和培训班挂载可核验")
|
|
344
|
+
changed = copy.deepcopy(full)
|
|
345
|
+
changed["taxonomies"]["course"].pop(0)
|
|
346
|
+
ck(not verify_blueprint(changed, full_plan)["ok"], "未被引用分类也不许删减")
|
|
347
|
+
changed = copy.deepcopy(full)
|
|
348
|
+
changed["taxonomies"]["course"].reverse()
|
|
349
|
+
ck(not verify_blueprint(changed, full_plan)["ok"], "分类原顺序改变也拦截")
|
|
350
|
+
changed = copy.deepcopy(full)
|
|
351
|
+
changed["projects"][0]["config"]["items"][0]["course_ref"] = 1
|
|
352
|
+
ck(not verify_blueprint(changed, full_plan)["ok"], "培训班合法下标换课也拦截")
|
|
353
|
+
changed = copy.deepcopy(full)
|
|
354
|
+
changed["projects"][0]["config"]["items"].reverse()
|
|
355
|
+
ck(not verify_blueprint(changed, full_plan)["ok"], "培训班挂载原顺序改变也拦截")
|
|
356
|
+
changed = copy.deepcopy(full)
|
|
357
|
+
changed["projects"][0]["config"]["items"] = []
|
|
358
|
+
ck(not verify_blueprint(changed, full_plan)["ok"], "培训班挂载不得静默清空")
|
|
359
|
+
named_plan = copy.deepcopy(full_plan)
|
|
360
|
+
named_plan["project_details"][0]["config"]["items"][0]["course_ref"] = "A"
|
|
361
|
+
named_plan["project_details"][0]["config"]["items"][1]["exam_ref"] = "考"
|
|
362
|
+
ck(verify_blueprint(full, named_plan)["ok"], "培训班原文名称可映射蓝图下标")
|
|
363
|
+
for ok, label in cases:
|
|
364
|
+
print(" %s %s" % ("PASS" if ok else "FAIL", label))
|
|
365
|
+
failed = sum(not ok for ok, _ in cases)
|
|
366
|
+
print("[self-test] %d/%d PASS" % (len(cases) - failed, len(cases)))
|
|
367
|
+
return 1 if failed else 0
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def main(argv=None):
|
|
371
|
+
ensure_utf8_stdio()
|
|
372
|
+
if argv is None:
|
|
373
|
+
argv = sys.argv[1:]
|
|
374
|
+
if "--self-test" in argv:
|
|
375
|
+
return self_test()
|
|
376
|
+
ap = argparse.ArgumentParser(description="记录文档完整范围、引用及待明确项,不裁剪填充")
|
|
377
|
+
ap.add_argument("--entities", help="完整方案实体 JSON(plan-parse 的 2g 落盘产物)")
|
|
378
|
+
ap.add_argument("--verify-blueprint", help="P-15:核验 BLUEPRINT 与文档范围一致")
|
|
379
|
+
ap.add_argument("--scope-plan", help="scope-plan.json 路径(默认取 BLUEPRINT 同目录)")
|
|
380
|
+
ap.add_argument("--out-dir", help="蓝图目录(写 scope-plan.json)")
|
|
381
|
+
ap.add_argument("--json", action="store_true", help="打印完整机读结果")
|
|
382
|
+
args = ap.parse_args(argv)
|
|
383
|
+
return run(args)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
if __name__ == "__main__":
|
|
387
|
+
sys.exit(main())
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""demo-init 分发自检(一条命令回答"我这台机器能不能跑")
|
|
3
|
+
|
|
4
|
+
用法:
|
|
5
|
+
<PY> scripts/selftest_all.py # 环境体检 + 全部离线自测(不连平台、不写平台)
|
|
6
|
+
<PY> scripts/selftest_all.py --with-cli # 额外探测 soke-cli 版本(只读;注意可能触发 CLI 自更新)
|
|
7
|
+
<PY> scripts/selftest_all.py --json # 机器可读输出,便于转交排障
|
|
8
|
+
|
|
9
|
+
退出码:0=全部通过;1=有失败项(环境缺失或自测不过)。
|
|
10
|
+
|
|
11
|
+
设计边界:本脚本只做只读探测。除各脚本自带的 --self-test 外不调用任何
|
|
12
|
+
soke-cli 业务命令;--with-cli 也仅执行 `--version`。
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
import re
|
|
21
|
+
import shutil
|
|
22
|
+
import subprocess
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
SKILL_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
26
|
+
SCRIPTS_DIR = os.path.join(SKILL_DIR, "scripts")
|
|
27
|
+
REFS_DIR = os.path.join(SKILL_DIR, "references")
|
|
28
|
+
|
|
29
|
+
CLI_CANDIDATES = [
|
|
30
|
+
os.environ.get("SOKE_CLI", ""),
|
|
31
|
+
os.path.expanduser("~/.npm-global/bin/soke-cli"),
|
|
32
|
+
"/usr/local/bin/soke-cli",
|
|
33
|
+
"/opt/homebrew/bin/soke-cli",
|
|
34
|
+
os.path.expanduser("~/.workbuddy/binaries/node/cli-connector-packages/bin/soke-cli"),
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
REQUIRED_CMDS = ["portal", "course", "exam", "learning-map", "training-class", "assign"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _run(cmd, timeout=300):
|
|
41
|
+
p = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
42
|
+
return p.returncode, (p.stdout or ""), (p.stderr or "")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def check_python():
|
|
46
|
+
ok = sys.version_info >= (3, 9)
|
|
47
|
+
return {"name": "Python 版本", "ok": ok, "level": "block",
|
|
48
|
+
"detail": "%d.%d.%d" % sys.version_info[:3] + ("" if ok else "(需 >= 3.9)")}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def check_pillow():
|
|
52
|
+
try:
|
|
53
|
+
import PIL
|
|
54
|
+
return {"name": "Pillow(出图依赖)", "ok": True, "level": "block",
|
|
55
|
+
"detail": "Pillow %s" % getattr(PIL, "__version__", "?")}
|
|
56
|
+
except Exception:
|
|
57
|
+
return {"name": "Pillow(出图依赖)", "ok": False, "level": "block",
|
|
58
|
+
"detail": "未安装 → 执行 %s -m pip install Pillow" % os.path.basename(sys.executable)}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def check_font():
|
|
62
|
+
"""中文字体缺失不会报错,但文字层会渲染成方块——必须在开工前发现。"""
|
|
63
|
+
cands = [os.environ.get("DEMO_FONT") or "",
|
|
64
|
+
"/System/Library/Fonts/PingFang.ttc",
|
|
65
|
+
"/System/Library/Fonts/Hiragino Sans GB.ttc",
|
|
66
|
+
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
|
67
|
+
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
|
|
68
|
+
"/usr/share/fonts/truetype/wqy/wqy-microhei.ttc",
|
|
69
|
+
"C:/Windows/Fonts/msyh.ttc", "C:/Windows/Fonts/simhei.ttf"]
|
|
70
|
+
hit = next((c for c in cands if c and os.path.isfile(c)), None)
|
|
71
|
+
return {"name": "中文字体", "ok": bool(hit), "level": "warn",
|
|
72
|
+
"detail": hit or "未找到 → 装 Noto Sans CJK/苹方,或设 DEMO_FONT=/path/to/font.ttf"}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def resolve_cli():
|
|
76
|
+
for c in CLI_CANDIDATES:
|
|
77
|
+
if c and os.path.isfile(c) and os.access(c, os.X_OK):
|
|
78
|
+
return c
|
|
79
|
+
return shutil.which("soke-cli")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def check_cli(with_cli=False):
|
|
83
|
+
path = resolve_cli()
|
|
84
|
+
if not path:
|
|
85
|
+
return {"name": "soke-cli", "ok": False, "level": "block",
|
|
86
|
+
"detail": "未找到 → npm i -g @sokeai/cli"}
|
|
87
|
+
if not with_cli:
|
|
88
|
+
return {"name": "soke-cli", "ok": True, "level": "block",
|
|
89
|
+
"detail": path + "(未验版本,加 --with-cli 可验)"}
|
|
90
|
+
rc, out, err = _run([path, "--version"], timeout=180)
|
|
91
|
+
ver = ""
|
|
92
|
+
m = re.search(r"(\d+\.\d+\.\d+)", out + err)
|
|
93
|
+
if m:
|
|
94
|
+
ver = m.group(1)
|
|
95
|
+
ok = bool(ver) and tuple(int(x) for x in ver.split(".")) >= (1, 0, 114)
|
|
96
|
+
return {"name": "soke-cli 版本", "ok": ok, "level": "block",
|
|
97
|
+
"detail": (ver or "无法解析版本") + ("(需 >= 1.0.114)" if not ok else "")}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def check_cmd_families():
|
|
101
|
+
"""版本号够 ≠ 命令集齐(托管版 1.0.108 无 portal)。这里只查本地 help,不触业务接口。"""
|
|
102
|
+
path = resolve_cli()
|
|
103
|
+
if not path:
|
|
104
|
+
return {"name": "命令族", "ok": False, "level": "block", "detail": "soke-cli 未找到,跳过"}
|
|
105
|
+
missing = []
|
|
106
|
+
for cmd in REQUIRED_CMDS:
|
|
107
|
+
rc, out, err = _run([path, cmd, "--help"], timeout=60)
|
|
108
|
+
blob = (out + err).lower()
|
|
109
|
+
if rc != 0 or "unknown command" in blob:
|
|
110
|
+
missing.append(cmd)
|
|
111
|
+
return {"name": "命令族(%d 项)" % len(REQUIRED_CMDS), "ok": not missing, "level": "block",
|
|
112
|
+
"detail": "齐全" if not missing else "缺:" + "、".join(missing)}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def check_refs_links():
|
|
116
|
+
"""references/*.md 互相引用的文件必须真实存在,否则运行时才会撞断链。"""
|
|
117
|
+
if not os.path.isdir(REFS_DIR):
|
|
118
|
+
return {"name": "文档引用", "ok": False, "level": "block", "detail": "references 目录不存在"}
|
|
119
|
+
names = {f for f in os.listdir(REFS_DIR) if f.endswith(".md")}
|
|
120
|
+
broken = {}
|
|
121
|
+
targets = [os.path.join(SKILL_DIR, "SKILL.md")] + [os.path.join(REFS_DIR, n) for n in sorted(names)]
|
|
122
|
+
for p in targets:
|
|
123
|
+
if not os.path.isfile(p):
|
|
124
|
+
continue
|
|
125
|
+
txt = open(p, encoding="utf-8").read()
|
|
126
|
+
for m in re.findall(r"(?<![\w/-])references/([A-Za-z0-9_-]+\.md)", txt):
|
|
127
|
+
if m not in names:
|
|
128
|
+
broken.setdefault(os.path.basename(p), set()).add(m)
|
|
129
|
+
ok = not broken
|
|
130
|
+
detail = "%d 份文档引用完整" % len(names) if ok else \
|
|
131
|
+
";".join("%s→%s" % (k, ",".join(sorted(v))) for k, v in broken.items())
|
|
132
|
+
return {"name": "文档引用", "ok": ok, "level": "warn", "detail": detail}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def check_doc_lint():
|
|
136
|
+
"""文档一致性门禁:版本三处一致 / img_picked=0 / 封面判据 / 后缀口径 / 章节重号 / 包卫生。
|
|
137
|
+
|
|
138
|
+
v3.29.0 新增。技能里同一事实存了 4 份(SKILL 黑名单 / 偏差表 / run-protocol / 模块闸门),
|
|
139
|
+
曾出现 4 组互相打架的口径;这一步把它们变成机读断言,改文档时立刻能发现"又退回去了"。
|
|
140
|
+
"""
|
|
141
|
+
path = os.path.join(SCRIPTS_DIR, "doc_lint.py")
|
|
142
|
+
if not os.path.isfile(path):
|
|
143
|
+
return {"name": "文档一致性", "ok": False, "level": "block", "detail": "doc_lint.py 缺失"}
|
|
144
|
+
rc, out, err = _run([sys.executable, path], timeout=120)
|
|
145
|
+
tail = (out.strip().splitlines() or [""])[-1][:110]
|
|
146
|
+
return {"name": "文档一致性", "ok": rc == 0, "level": "block",
|
|
147
|
+
"detail": (tail if rc == 0 else (tail or err.strip()[:110]))}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def run_self_tests():
|
|
151
|
+
"""逐个跑 scripts/*.py --self-test;无 --self-test 的脚本只做语法编译检查。"""
|
|
152
|
+
results = []
|
|
153
|
+
for name in sorted(os.listdir(SCRIPTS_DIR)):
|
|
154
|
+
if not name.endswith(".py") or name == os.path.basename(__file__):
|
|
155
|
+
continue
|
|
156
|
+
path = os.path.join(SCRIPTS_DIR, name)
|
|
157
|
+
src = open(path, encoding="utf-8").read()
|
|
158
|
+
if "--self-test" in src:
|
|
159
|
+
try:
|
|
160
|
+
rc, out, err = _run([sys.executable, path, "--self-test"], timeout=600)
|
|
161
|
+
except subprocess.TimeoutExpired:
|
|
162
|
+
results.append({"name": name, "ok": False, "level": "block", "detail": "自测超时"})
|
|
163
|
+
continue
|
|
164
|
+
tail = (out.strip().splitlines() or [""])[-1][:90]
|
|
165
|
+
results.append({"name": name, "ok": rc == 0, "level": "block",
|
|
166
|
+
"detail": ("PASS " + tail) if rc == 0 else ("FAIL " + (tail or err.strip()[:90]))})
|
|
167
|
+
else:
|
|
168
|
+
try:
|
|
169
|
+
compile(src, path, "exec")
|
|
170
|
+
ok, detail = True, "语法通过(无 --self-test)"
|
|
171
|
+
except SyntaxError as e:
|
|
172
|
+
ok, detail = False, "语法错误 %s:%s" % (e.lineno, e.msg)
|
|
173
|
+
results.append({"name": name, "ok": ok, "level": "block", "detail": detail})
|
|
174
|
+
return results
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def main(argv=None):
|
|
178
|
+
ap = argparse.ArgumentParser()
|
|
179
|
+
ap.add_argument("--with-cli", action="store_true", help="额外执行 soke-cli --version(可能触发自更新)")
|
|
180
|
+
ap.add_argument("--json", action="store_true", help="只输出 JSON")
|
|
181
|
+
ap.add_argument("--skip-selftests", action="store_true", help="只做环境体检,不跑脚本自测")
|
|
182
|
+
args = ap.parse_args(argv)
|
|
183
|
+
|
|
184
|
+
checks = [check_python(), check_pillow(), check_font(), check_cli(args.with_cli)]
|
|
185
|
+
if resolve_cli():
|
|
186
|
+
checks.append(check_cmd_families())
|
|
187
|
+
checks.append(check_refs_links())
|
|
188
|
+
checks.append(check_doc_lint())
|
|
189
|
+
if not args.skip_selftests:
|
|
190
|
+
checks.extend(run_self_tests())
|
|
191
|
+
|
|
192
|
+
failed = [c for c in checks if not c["ok"]]
|
|
193
|
+
blocking = [c for c in failed if c["level"] == "block"]
|
|
194
|
+
payload = {"ok": not blocking, "skill_dir": SKILL_DIR,
|
|
195
|
+
"python": sys.version.split()[0], "checks": checks}
|
|
196
|
+
|
|
197
|
+
if args.json:
|
|
198
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
199
|
+
else:
|
|
200
|
+
print("demo-init 分发自检 | 技能目录 %s" % SKILL_DIR)
|
|
201
|
+
for c in checks:
|
|
202
|
+
mark = "OK " if c["ok"] else ("FAIL" if c["level"] == "block" else "WARN")
|
|
203
|
+
print(" [%s] %-18s %s" % (mark, c["name"], c["detail"]))
|
|
204
|
+
print("\n结论:%s(阻断项 %d / 警告项 %d)" % (
|
|
205
|
+
"可以开工" if not blocking else "存在阻断项,按上面提示修复后再开工",
|
|
206
|
+
len(blocking), len([c for c in failed if c["level"] != "block"])))
|
|
207
|
+
return 0 if not blocking else 1
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
if __name__ == "__main__":
|
|
211
|
+
sys.exit(main())
|