@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,243 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""存量课程封面修复:把 `picture` 里的脏数据/死链改写成可显示的封面。
|
|
4
|
+
|
|
5
|
+
适用症状(均为 soke-cli `course +update --image` 或旧 api 载荷留下的):
|
|
6
|
+
1) picture = ["map[h:270 image:https://… w:480 x:0 y:0]"] → img_url 回落默认占位图
|
|
7
|
+
2) picture 为合法对象但 img_url 带 /crop,… → CDN 404 裂图
|
|
8
|
+
|
|
9
|
+
修复动作(逐门):从现有 picture 里提取出真实图片地址(不改图),
|
|
10
|
+
用「全载荷 + imgObj 裁剪参数全 0」重写一次,再重新 publish,最后回读 img_url 是否 200。
|
|
11
|
+
|
|
12
|
+
用法:
|
|
13
|
+
python3 course_cover_repair.py --dry-run # 只体检,不写
|
|
14
|
+
python3 course_cover_repair.py --course-id <uuid> # 修一门
|
|
15
|
+
python3 course_cover_repair.py --all # 修当前租户全部「封面异常」课程
|
|
16
|
+
python3 course_cover_repair.py --all --limit 3 # 只修前 3 门(试水)
|
|
17
|
+
|
|
18
|
+
退出码:0=全部恢复正常;2=仍有未恢复项;1=执行失败。
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import argparse
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import re
|
|
27
|
+
import shutil
|
|
28
|
+
import subprocess
|
|
29
|
+
import sys
|
|
30
|
+
import time
|
|
31
|
+
import urllib.request
|
|
32
|
+
|
|
33
|
+
DEFAULT_CLI_CANDIDATES = [
|
|
34
|
+
os.environ.get("SOKE_CLI", ""),
|
|
35
|
+
os.path.expanduser("~/.workbuddy/binaries/node/cli-connector-packages/bin/soke-cli"),
|
|
36
|
+
"/usr/local/bin/soke-cli",
|
|
37
|
+
"/opt/homebrew/bin/soke-cli",
|
|
38
|
+
os.path.expanduser("~/.npm-global/bin/soke-cli"),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
URL_RE = re.compile(r"https?://[^\s\"'\]\}]+")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def resolve_cli() -> str:
|
|
45
|
+
for cand in DEFAULT_CLI_CANDIDATES:
|
|
46
|
+
if cand and os.path.isfile(cand) and os.access(cand, os.X_OK):
|
|
47
|
+
return cand
|
|
48
|
+
found = shutil.which("soke-cli")
|
|
49
|
+
if found:
|
|
50
|
+
return found
|
|
51
|
+
raise SystemExit("未找到 soke-cli,请先安装:npm i -g @sokeai/cli")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def parse_json(raw: str) -> dict:
|
|
55
|
+
idx = raw.find("{")
|
|
56
|
+
if idx < 0:
|
|
57
|
+
raise ValueError(f"响应不是 JSON:{raw[:200]}")
|
|
58
|
+
obj, _ = json.JSONDecoder().raw_decode(raw[idx:])
|
|
59
|
+
return obj if isinstance(obj, dict) else {}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def is_ok(resp: dict) -> bool:
|
|
63
|
+
return str(resp.get("code")) == "200" and str(resp.get("status", "ok")).lower() in ("ok", "success")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def http_code(url: str) -> int:
|
|
67
|
+
if not url:
|
|
68
|
+
return 0
|
|
69
|
+
for method in ("HEAD", "GET"):
|
|
70
|
+
try:
|
|
71
|
+
req = urllib.request.Request(url, method=method)
|
|
72
|
+
with urllib.request.urlopen(req, timeout=15) as resp:
|
|
73
|
+
if method == "GET":
|
|
74
|
+
resp.read(1)
|
|
75
|
+
return resp.status
|
|
76
|
+
except Exception:
|
|
77
|
+
continue
|
|
78
|
+
return 0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def picture_image(pic) -> str:
|
|
82
|
+
"""从对象 / list / 'map[…]' 字符串三种形态里捞出图片地址。"""
|
|
83
|
+
if isinstance(pic, list) and pic:
|
|
84
|
+
return picture_image(pic[0])
|
|
85
|
+
if isinstance(pic, dict):
|
|
86
|
+
return str(pic.get("image") or "")
|
|
87
|
+
if isinstance(pic, str):
|
|
88
|
+
found = URL_RE.search(pic)
|
|
89
|
+
return found.group(0) if found else ""
|
|
90
|
+
return ""
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def diagnose(data: dict) -> tuple[str, str]:
|
|
94
|
+
"""返回 (状态, 图片地址)。状态:ok / false_go_map / false_crop404 / false_default / no_picture。
|
|
95
|
+
|
|
96
|
+
v3.29.0:脏串判据补齐 list 形态——平台实际返回的是 `["map[…]"]]`(数组里塞字符串),
|
|
97
|
+
原实现只判 `isinstance(pic, str)`,会把脏数据误诊成 false_default(处置路径相同但诊断错,
|
|
98
|
+
台账与工单话术会跟着错)。
|
|
99
|
+
"""
|
|
100
|
+
pic = data.get("picture")
|
|
101
|
+
pic0 = pic[0] if isinstance(pic, list) and pic else pic
|
|
102
|
+
uri = picture_image(pic)
|
|
103
|
+
img = data.get("img_url") or ""
|
|
104
|
+
if isinstance(pic0, str) and pic0.lstrip("[\"' ").startswith("map["):
|
|
105
|
+
return "false_go_map", uri
|
|
106
|
+
if "/crop," in img:
|
|
107
|
+
return "false_crop404", uri
|
|
108
|
+
if not uri:
|
|
109
|
+
return "no_picture", ""
|
|
110
|
+
if img.endswith("course-cover-two.png") or not img:
|
|
111
|
+
return "false_default", uri
|
|
112
|
+
if img == uri and http_code(img) == 200:
|
|
113
|
+
return "ok", uri
|
|
114
|
+
return ("ok" if http_code(img) == 200 else "false_unreachable"), uri
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def self_test() -> int:
|
|
118
|
+
"""离线桩测试:只验封面三态判定与 URL 提取(http_code 用桩替身,不发请求)。
|
|
119
|
+
|
|
120
|
+
真实事故:`picture` 里是 `["map[h:270 …]"]` 这种 Go 序列化脏串,
|
|
121
|
+
旧的「picture 非空即已修复」判据会把 10 门全判通过,实际前端仍是默认图。
|
|
122
|
+
"""
|
|
123
|
+
global http_code
|
|
124
|
+
cases = []
|
|
125
|
+
|
|
126
|
+
def ck(cond, label):
|
|
127
|
+
cases.append((bool(cond), label))
|
|
128
|
+
|
|
129
|
+
uri = "https://newsokecdn.soke.cn/demo/cover.png"
|
|
130
|
+
ck(picture_image({"image": uri}) == uri, "picture_image 对象形态")
|
|
131
|
+
ck(picture_image([{"image": uri}]) == uri, "picture_image list 形态")
|
|
132
|
+
ck(picture_image('["map[h:270 image:%s w:480 x:0 y:0]"]' % uri) == uri, "picture_image 从 map 脏串捞 URL")
|
|
133
|
+
ck(picture_image(None) == "" and picture_image("") == "", "picture_image 空值返回空")
|
|
134
|
+
|
|
135
|
+
http_code = lambda url: 200
|
|
136
|
+
ck(diagnose({"picture": {"image": uri}, "img_url": uri})[0] == "ok", "diagnose 可显示")
|
|
137
|
+
ck(diagnose({"picture": '["map[h:270 image:%s]"]' % uri, "img_url": "https://x/default.png"})[0]
|
|
138
|
+
== "false_go_map", "diagnose 抓 map 脏串")
|
|
139
|
+
ck(diagnose({"picture": {"image": uri}, "img_url": uri + "/crop,x_0,y_0,w_480,h_270"})[0]
|
|
140
|
+
== "false_crop404", "diagnose 抓 crop 死链")
|
|
141
|
+
ck(diagnose({"picture": {"image": uri}, "img_url": "https://x/course-cover-two.png"})[0]
|
|
142
|
+
== "false_default", "diagnose 抓回落默认图")
|
|
143
|
+
ck(diagnose({"picture": {}, "img_url": ""})[0] == "no_picture", "diagnose 抓无图")
|
|
144
|
+
|
|
145
|
+
http_code = lambda url: 0
|
|
146
|
+
ck(diagnose({"picture": {"image": uri}, "img_url": "https://x/other.png"})[0]
|
|
147
|
+
== "false_unreachable", "diagnose 抓不可达")
|
|
148
|
+
|
|
149
|
+
failed = [label for ok_, label in cases if not ok_]
|
|
150
|
+
for ok_, label in cases:
|
|
151
|
+
print(" %s %s" % ("PASS" if ok_ else "FAIL", label))
|
|
152
|
+
print(json.dumps({"ok": not failed, "assertions": len(cases)}, ensure_ascii=False))
|
|
153
|
+
return 0 if not failed else 1
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def main() -> int:
|
|
157
|
+
if "--self-test" in sys.argv[1:]:
|
|
158
|
+
return self_test()
|
|
159
|
+
ap = argparse.ArgumentParser(description="存量课程封面修复")
|
|
160
|
+
ap.add_argument("--course-id", action="append", help="指定课程 uuid(可多次)")
|
|
161
|
+
ap.add_argument("--all", action="store_true", help="扫描全部在架课程")
|
|
162
|
+
ap.add_argument("--limit", type=int, default=0, help="最多处理 N 门")
|
|
163
|
+
ap.add_argument("--dry-run", action="store_true", help="只体检不写")
|
|
164
|
+
ap.add_argument("--no-republish", action="store_true", help="不重新发布(默认会 publish 保住发布态)")
|
|
165
|
+
ap.add_argument("--sleep", type=float, default=3.0)
|
|
166
|
+
args = ap.parse_args()
|
|
167
|
+
|
|
168
|
+
cli = resolve_cli()
|
|
169
|
+
|
|
170
|
+
def call(a: list[str]) -> dict:
|
|
171
|
+
return parse_json(subprocess.run([cli] + a, capture_output=True, text=True).stdout)
|
|
172
|
+
|
|
173
|
+
targets: list[str] = list(args.course_id or [])
|
|
174
|
+
if args.all:
|
|
175
|
+
resp = call(["course", "+list-courses", "--status", "1", "--format", "json"])
|
|
176
|
+
for c in (resp.get("data") or {}).get("list") or []:
|
|
177
|
+
if c.get("uuid"):
|
|
178
|
+
targets.append(c["uuid"])
|
|
179
|
+
if not targets:
|
|
180
|
+
print(json.dumps({"ok": False, "error": "未指定课程:用 --course-id 或 --all"}, ensure_ascii=False))
|
|
181
|
+
return 1
|
|
182
|
+
|
|
183
|
+
results = []
|
|
184
|
+
for cid in targets:
|
|
185
|
+
data = (call(["course", "+get-course", "--course-id", cid, "--format", "json"]).get("data") or {})
|
|
186
|
+
state, uri = diagnose(data)
|
|
187
|
+
rec = {"course_id": cid, "title": data.get("title"), "before": state, "photo_uri": uri}
|
|
188
|
+
if state == "ok":
|
|
189
|
+
rec["action"] = "skip(已正常)"
|
|
190
|
+
results.append(rec)
|
|
191
|
+
continue
|
|
192
|
+
if state == "no_picture":
|
|
193
|
+
rec["action"] = "skip(课程本就没设封面,需指定图片)"
|
|
194
|
+
results.append(rec)
|
|
195
|
+
continue
|
|
196
|
+
if not uri:
|
|
197
|
+
rec["action"] = "skip(无法从 picture 提取图片地址)"
|
|
198
|
+
results.append(rec)
|
|
199
|
+
continue
|
|
200
|
+
|
|
201
|
+
rec["action"] = "would_repair" if args.dry_run else "repair"
|
|
202
|
+
if not args.dry_run:
|
|
203
|
+
cat = data.get("category_id") or ""
|
|
204
|
+
payload = {
|
|
205
|
+
"action": "update", "uuid": cid, "title": data.get("title") or "",
|
|
206
|
+
"description": data.get("description") or "",
|
|
207
|
+
"category_id": cat, "categories": [cat], "category_path": [cat],
|
|
208
|
+
"img_picked": 0,
|
|
209
|
+
"imgObj": {"image": uri, "w": 0, "h": 0, "x": 0, "y": 0},
|
|
210
|
+
}
|
|
211
|
+
resp = call(["api", "PUT", f"/skills/course/update/{cid}", "--as", "user",
|
|
212
|
+
"--data", json.dumps(payload, ensure_ascii=False)])
|
|
213
|
+
rec["write_ok"] = is_ok(resp) and resp.get("data") not in (0, None, False)
|
|
214
|
+
rec["write_msg"] = resp.get("message")
|
|
215
|
+
time.sleep(args.sleep)
|
|
216
|
+
if rec["write_ok"] and not args.no_republish:
|
|
217
|
+
pub = call(["course", "+publish", "--course-id", cid, "--format", "json"])
|
|
218
|
+
rec["publish_ok"] = is_ok(pub)
|
|
219
|
+
rec["publish_msg"] = pub.get("message")
|
|
220
|
+
time.sleep(args.sleep)
|
|
221
|
+
after = (call(["course", "+get-course", "--course-id", cid, "--format", "json"]).get("data") or {})
|
|
222
|
+
rec["after"], _ = diagnose(after)
|
|
223
|
+
rec["img_url"] = after.get("img_url")
|
|
224
|
+
rec["http"] = http_code(rec["img_url"])
|
|
225
|
+
rec["publish_time"] = after.get("publish_time")
|
|
226
|
+
results.append(rec)
|
|
227
|
+
if args.limit and len([r for r in results if r.get("write_ok")]) >= args.limit:
|
|
228
|
+
break
|
|
229
|
+
|
|
230
|
+
repaired = [r for r in results if r.get("after") == "ok"]
|
|
231
|
+
pending = [r for r in results if r.get("action") in ("repair", "would_repair") and r.get("after") != "ok"]
|
|
232
|
+
print(json.dumps({
|
|
233
|
+
"ok": not pending,
|
|
234
|
+
"scanned": len(results),
|
|
235
|
+
"repaired": len(repaired),
|
|
236
|
+
"pending": len(pending),
|
|
237
|
+
"results": results,
|
|
238
|
+
}, ensure_ascii=False, indent=2))
|
|
239
|
+
return 0 if not pending else 2
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
if __name__ == "__main__":
|
|
243
|
+
sys.exit(main())
|