@zh0vy4n/dsh-ops-kit 0.0.0-stage → 0.1.0
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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +170 -2
- package/SKILL.md +107 -0
- package/bin/dream.mjs +690 -0
- package/bin/verify.py +456 -0
- package/check.bat +36 -0
- package/cordis.patch.yml +6 -0
- package/docs/PLUGIN.md +95 -0
- package/docs/SKILLS.md +84 -0
- package/dsh/index.js +173 -0
- package/gate.bat +31 -0
- package/icon.svg +7 -0
- package/kit.config.example.json +201 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +55 -4
- package/scripts/rename-package.mjs +78 -0
- package/scripts/selfcheck.mjs +193 -0
- package/scripts/selfcheck.sh +173 -0
- package/scripts/sync-skill.mjs +81 -0
- package/scripts/sync-skill.sh +44 -0
- package/scripts/test-plugin.mjs +66 -0
package/bin/verify.py
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""verify.py — 发版前的静态闸门(通用版)
|
|
4
|
+
|
|
5
|
+
python verify.py 静态检查:node --check 配置里所有 syntaxGlobs + 内联脚本解析
|
|
6
|
+
python verify.py --probes 再加登记表里标记为默认的探针(慢)
|
|
7
|
+
python verify.py --probes=all 全跑;--probes=名字1,名字2 点名跑
|
|
8
|
+
python verify.py --changed 只验本次改动(git),并挑覆盖这些文件的探针
|
|
9
|
+
python verify.py --quiet 只打结论
|
|
10
|
+
|
|
11
|
+
任何一项失败都非 0 退出。发布脚本在 audit 通过后调用它,失败即中止发布。
|
|
12
|
+
|
|
13
|
+
配置来自 kit.config.json(脚本同目录 / 上一级 / 上两级 / 当前目录逐级向上找,或 --config=路径):
|
|
14
|
+
syntaxGlobs 要 node --check 的文件通配,相对仓库根
|
|
15
|
+
inlineHtml {"file": "页面.html", "parser": ""};file 必填,parser 留空走内置解析
|
|
16
|
+
probes 探针登记表 .tsv 路径(列:id / 文件 / 说明 / 覆盖 / 默认 / 覆盖文件通配)
|
|
17
|
+
probeDefault "默认" 那一列的 0 基下标,默认 4
|
|
18
|
+
"""
|
|
19
|
+
import glob
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import shlex
|
|
24
|
+
import shutil
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
27
|
+
import tempfile
|
|
28
|
+
|
|
29
|
+
# Windows 下从无控制台的宿主起的进程会新开黑窗,所有 spawn 都必须带 CREATE_NO_WINDOW
|
|
30
|
+
NO_WIN = getattr(subprocess, "CREATE_NO_WINDOW", 0) if os.name == "nt" else 0
|
|
31
|
+
|
|
32
|
+
try: # Windows 控制台默认 GBK,中文结论会乱码
|
|
33
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
34
|
+
except Exception:
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
38
|
+
QUIET = "--quiet" in sys.argv
|
|
39
|
+
TAG = "[kit] " # 结论行固定前缀:和仓库自带的 verify 区分开
|
|
40
|
+
CHANGED = "--changed" in sys.argv
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def find_config():
|
|
44
|
+
for a in sys.argv:
|
|
45
|
+
if a.startswith("--config="):
|
|
46
|
+
return os.path.abspath(a.split("=", 1)[1])
|
|
47
|
+
cands = [HERE, os.path.dirname(HERE), os.path.dirname(os.path.dirname(HERE)), os.getcwd()]
|
|
48
|
+
for d in cands:
|
|
49
|
+
p = os.path.join(d, "kit.config.json")
|
|
50
|
+
if os.path.exists(p):
|
|
51
|
+
return p
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
CFG_PATH = find_config()
|
|
56
|
+
if not CFG_PATH:
|
|
57
|
+
print(TAG + "verify FAIL: 找不到 kit.config.json(用 --config=路径 指定)", flush=True)
|
|
58
|
+
sys.exit(2)
|
|
59
|
+
ROOT = os.path.dirname(CFG_PATH)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def pick_tmpdir():
|
|
63
|
+
"""挑一个真能写的临时目录。
|
|
64
|
+
|
|
65
|
+
不能信 tempfile.gettempdir():受限环境里它会退回 getcwd(),而插件/服务进程的
|
|
66
|
+
工作目录常常是只读的安装目录,于是 mkstemp 抛 PermissionError。这里逐个候选试写,
|
|
67
|
+
第一个写得进去的即用;全都不行就返回 None(交给 mkstemp 用系统默认,失败照旧报错)。
|
|
68
|
+
"""
|
|
69
|
+
cands = []
|
|
70
|
+
for name in ("KIT_TMPDIR", "TMPDIR", "TEMP", "TMP"):
|
|
71
|
+
v = os.environ.get(name)
|
|
72
|
+
if v:
|
|
73
|
+
cands.append(v)
|
|
74
|
+
try:
|
|
75
|
+
cands.append(tempfile.gettempdir())
|
|
76
|
+
except Exception:
|
|
77
|
+
pass
|
|
78
|
+
cands.append(os.path.join(ROOT, ".kit-tmp"))
|
|
79
|
+
cands.append(os.getcwd())
|
|
80
|
+
for c in cands:
|
|
81
|
+
try:
|
|
82
|
+
os.makedirs(c, exist_ok=True)
|
|
83
|
+
probe = os.path.join(c, ".kit-tmp-probe")
|
|
84
|
+
with open(probe, "w", encoding="utf-8") as f:
|
|
85
|
+
f.write("1")
|
|
86
|
+
os.remove(probe)
|
|
87
|
+
return c
|
|
88
|
+
except Exception:
|
|
89
|
+
continue
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
TMPDIR = pick_tmpdir()
|
|
94
|
+
try:
|
|
95
|
+
with open(CFG_PATH, encoding="utf-8") as f:
|
|
96
|
+
CFG = json.load(f)
|
|
97
|
+
except Exception as e:
|
|
98
|
+
print(TAG + "verify FAIL: kit.config.json 解析失败:%s" % e, flush=True)
|
|
99
|
+
sys.exit(2)
|
|
100
|
+
|
|
101
|
+
def _inline_list(raw):
|
|
102
|
+
"""inlineHtml 三种写法都吃:{"file":...} / [{"file":...}, ...] / "path.html"。"""
|
|
103
|
+
if isinstance(raw, dict):
|
|
104
|
+
return [raw] if raw.get("file") else []
|
|
105
|
+
if isinstance(raw, str):
|
|
106
|
+
return [{"file": raw}]
|
|
107
|
+
if isinstance(raw, list):
|
|
108
|
+
return [x for x in raw if isinstance(x, dict) and x.get("file")]
|
|
109
|
+
return []
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
SYNTAX_GLOBS = CFG.get("syntaxGlobs") or []
|
|
113
|
+
INLINE_LIST = _inline_list(CFG.get("inlineHtml"))
|
|
114
|
+
# 探针执行器可换:probeCommand 模板,支持 {node} {python} {file};默认 node <file>
|
|
115
|
+
PROBE_CMD = str(CFG.get("probeCommand") or "").strip()
|
|
116
|
+
PROBE_REG = os.path.join(ROOT, CFG["probes"]) if CFG.get("probes") else ""
|
|
117
|
+
PROBE_DEFAULT_COL = int(CFG.get("probeDefault", 4))
|
|
118
|
+
|
|
119
|
+
# 探针选择:不带 --probes 不跑;--probes 跑默认的;--probes=all 全跑;--probes=a,b 点名跑
|
|
120
|
+
PROBE_SEL = ""
|
|
121
|
+
for _a in sys.argv:
|
|
122
|
+
if _a == "--probes":
|
|
123
|
+
PROBE_SEL = "default"
|
|
124
|
+
elif _a.startswith("--probes="):
|
|
125
|
+
PROBE_SEL = _a.split("=", 1)[1].strip() or "default"
|
|
126
|
+
WITH_PROBES = bool(PROBE_SEL)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def say(s):
|
|
130
|
+
if not QUIET:
|
|
131
|
+
print(TAG + s, flush=True)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def registry():
|
|
135
|
+
rows = []
|
|
136
|
+
if not PROBE_REG or not os.path.exists(PROBE_REG):
|
|
137
|
+
return rows
|
|
138
|
+
with open(PROBE_REG, encoding="utf-8") as f:
|
|
139
|
+
for ln in f:
|
|
140
|
+
ln = ln.rstrip("\n")
|
|
141
|
+
if not ln.strip() or ln.lstrip().startswith("#"):
|
|
142
|
+
continue
|
|
143
|
+
cols = [c.strip() for c in ln.split("\t")]
|
|
144
|
+
if len(cols) < 2 or not cols[1]:
|
|
145
|
+
continue
|
|
146
|
+
cols += [""] * (6 - len(cols))
|
|
147
|
+
rows.append({"id": cols[0], "file": cols[1], "what": cols[2], "covers": cols[3],
|
|
148
|
+
"default": cols[PROBE_DEFAULT_COL] in ("1", "yes", "y", "true"),
|
|
149
|
+
"files": cols[5]})
|
|
150
|
+
return rows
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def pick_probes():
|
|
154
|
+
rows = registry()
|
|
155
|
+
if not PROBE_SEL:
|
|
156
|
+
return []
|
|
157
|
+
if PROBE_SEL == "default":
|
|
158
|
+
return [r for r in rows if r["default"]]
|
|
159
|
+
if PROBE_SEL == "all":
|
|
160
|
+
return rows
|
|
161
|
+
want = [x.strip() for x in PROBE_SEL.replace("\n", ",").split(",") if x.strip()]
|
|
162
|
+
out = []
|
|
163
|
+
for w in want:
|
|
164
|
+
hit = [r for r in rows if w in (r["id"], r["file"], r["file"][:-3])]
|
|
165
|
+
if hit:
|
|
166
|
+
out.extend(hit)
|
|
167
|
+
else:
|
|
168
|
+
out.append({"id": w, "file": w if w.endswith(".js") else w + ".js",
|
|
169
|
+
"what": "(没登记,按文件名跑)", "covers": "", "default": False, "files": ""})
|
|
170
|
+
return out
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def git_out(args):
|
|
174
|
+
try:
|
|
175
|
+
r = subprocess.run(["git"] + args, cwd=ROOT, capture_output=True, text=True,
|
|
176
|
+
encoding="utf-8", errors="replace", timeout=60, creationflags=NO_WIN)
|
|
177
|
+
return (r.stdout or "") if r.returncode == 0 else ""
|
|
178
|
+
except Exception:
|
|
179
|
+
return ""
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def changed_paths():
|
|
183
|
+
# 提交钩子里只看已暂存的(快且准);手动跑 --changed 时退回工作区改动
|
|
184
|
+
out = git_out(["diff", "--cached", "--name-only", "--diff-filter=ACMR"])
|
|
185
|
+
if not out.strip():
|
|
186
|
+
out = git_out(["diff", "--name-only", "HEAD"]) + "\n" + git_out(["ls-files", "--others", "--exclude-standard"])
|
|
187
|
+
seen, keep = set(), []
|
|
188
|
+
for ln in out.splitlines():
|
|
189
|
+
p = ln.strip().replace("\\", "/")
|
|
190
|
+
if not p or p in seen:
|
|
191
|
+
continue
|
|
192
|
+
seen.add(p)
|
|
193
|
+
keep.append(p)
|
|
194
|
+
return keep
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def glob_hit(g, p):
|
|
198
|
+
g = (g or "").strip()
|
|
199
|
+
if not g:
|
|
200
|
+
return False
|
|
201
|
+
if g.endswith("*"):
|
|
202
|
+
return p.startswith(g[:-1])
|
|
203
|
+
if g.endswith("/"):
|
|
204
|
+
return p.startswith(g)
|
|
205
|
+
return p == g
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def probes_for(paths):
|
|
209
|
+
return [r for r in registry() if any(glob_hit(g, p) for g in r["files"].split() for p in paths)]
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def node_bin():
|
|
213
|
+
"""找 node:NODE_BIN 环境变量 → PATH 里的 node / node.exe → 配置里的 nodeCandidates。
|
|
214
|
+
不写死任何盘符路径:换机器只改 kit.config.json 的 nodeCandidates。"""
|
|
215
|
+
cands = [os.environ.get("NODE_BIN"), "node", "node.exe"]
|
|
216
|
+
cands += list(CFG.get("nodeCandidates") or [])
|
|
217
|
+
for c in cands:
|
|
218
|
+
if not c:
|
|
219
|
+
continue
|
|
220
|
+
exe = shutil.which(c) or c
|
|
221
|
+
try:
|
|
222
|
+
r = subprocess.run([exe, "-v"], capture_output=True, text=True, timeout=20, creationflags=NO_WIN)
|
|
223
|
+
if r.returncode == 0:
|
|
224
|
+
return exe
|
|
225
|
+
except Exception:
|
|
226
|
+
continue
|
|
227
|
+
return None
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def probe_argv(node, path):
|
|
231
|
+
"""探针执行器:默认 node <file>;kit.config.json 里配 probeCommand 可换解释器或加参数。
|
|
232
|
+
模板里 {node} {python} {file} 会被替换,路径按空格切分(带空格的路径请自己加引号)。"""
|
|
233
|
+
if not PROBE_CMD:
|
|
234
|
+
return [node, path]
|
|
235
|
+
cmd = (PROBE_CMD.replace("{node}", node or "node")
|
|
236
|
+
.replace("{python}", sys.executable or "python")
|
|
237
|
+
.replace("{file}", path))
|
|
238
|
+
parts = []
|
|
239
|
+
for p in shlex.split(cmd, posix=False):
|
|
240
|
+
parts.append(p.strip('"').strip("'"))
|
|
241
|
+
return parts or [node, path]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def collect():
|
|
245
|
+
files, seen = [], set()
|
|
246
|
+
for pat in SYNTAX_GLOBS:
|
|
247
|
+
for p in sorted(glob.glob(os.path.join(ROOT, pat), recursive=True)):
|
|
248
|
+
if not os.path.isfile(p) or p in seen:
|
|
249
|
+
continue
|
|
250
|
+
seen.add(p)
|
|
251
|
+
files.append(p)
|
|
252
|
+
return files
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
SCRIPT_RE = re.compile(r"<script\b([^>]*)>(.*?)</script>", re.S | re.I)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def check_inline_builtin(node, idx_path):
|
|
259
|
+
"""内置解析:抽出每个无 src 的 <script> 体,落临时文件后 node --check。
|
|
260
|
+
先按 CommonJS 试,失败再按 ESM 试——老页面是脚本,新页面可能带 import。"""
|
|
261
|
+
try:
|
|
262
|
+
with open(idx_path, encoding="utf-8", errors="replace") as f:
|
|
263
|
+
src = f.read()
|
|
264
|
+
except Exception as e:
|
|
265
|
+
return ["读不到内联页面 %s:%s" % (os.path.relpath(idx_path, ROOT), e)], 0, 0
|
|
266
|
+
blocks = []
|
|
267
|
+
for m in SCRIPT_RE.finditer(src):
|
|
268
|
+
attrs = (m.group(1) or "").lower()
|
|
269
|
+
if "src=" in attrs:
|
|
270
|
+
continue
|
|
271
|
+
tm = re.search(r"type\s*=\s*[\"']([^\"']+)[\"']", attrs)
|
|
272
|
+
if tm and ("javascript" not in tm.group(1) and "module" not in tm.group(1)):
|
|
273
|
+
continue
|
|
274
|
+
body = m.group(2).strip()
|
|
275
|
+
if len(body) < 8:
|
|
276
|
+
continue
|
|
277
|
+
blocks.append(body)
|
|
278
|
+
fails = []
|
|
279
|
+
for i, body in enumerate(blocks):
|
|
280
|
+
good, last = False, ""
|
|
281
|
+
for ext in (".js", ".mjs"):
|
|
282
|
+
fd, tmp = tempfile.mkstemp(suffix=ext, dir=TMPDIR)
|
|
283
|
+
os.close(fd)
|
|
284
|
+
try:
|
|
285
|
+
with open(tmp, "w", encoding="utf-8") as f:
|
|
286
|
+
f.write(body)
|
|
287
|
+
r = subprocess.run([node, "--check", tmp], capture_output=True, text=True,
|
|
288
|
+
encoding="utf-8", errors="replace", timeout=60, creationflags=NO_WIN)
|
|
289
|
+
if r.returncode == 0:
|
|
290
|
+
good = True
|
|
291
|
+
break
|
|
292
|
+
tail = [x for x in (r.stderr or "").strip().splitlines() if x.strip()]
|
|
293
|
+
last = tail[-1][:140] if tail else ""
|
|
294
|
+
except Exception as e:
|
|
295
|
+
last = str(e)[:140]
|
|
296
|
+
finally:
|
|
297
|
+
try:
|
|
298
|
+
os.unlink(tmp)
|
|
299
|
+
except Exception:
|
|
300
|
+
pass
|
|
301
|
+
if not good:
|
|
302
|
+
fails.append("内联脚本第 %d 段解析失败:%s" % (i + 1, last))
|
|
303
|
+
return fails, len(blocks), len(blocks) - len(fails)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def check_inline(node, INLINE=None):
|
|
307
|
+
if INLINE is None:
|
|
308
|
+
INLINE = INLINE_LIST[0] if INLINE_LIST else None
|
|
309
|
+
if not INLINE or not INLINE.get("file"):
|
|
310
|
+
return [], 0
|
|
311
|
+
idx = os.path.join(ROOT, INLINE["file"])
|
|
312
|
+
if not os.path.exists(idx):
|
|
313
|
+
return ["内联页面不存在:%s" % INLINE["file"]], 0
|
|
314
|
+
parser = (INLINE.get("parser") or "").strip()
|
|
315
|
+
if parser and os.path.exists(os.path.join(ROOT, parser)):
|
|
316
|
+
r = subprocess.run([node, os.path.join(ROOT, parser), idx], capture_output=True, text=True,
|
|
317
|
+
encoding="utf-8", errors="replace", timeout=120, creationflags=NO_WIN)
|
|
318
|
+
tail = (r.stdout or "").strip().splitlines()
|
|
319
|
+
bad = 0
|
|
320
|
+
for ln in tail:
|
|
321
|
+
if ln.startswith("scripts=") and "bad=" in ln:
|
|
322
|
+
try:
|
|
323
|
+
bad = int(ln.rsplit("bad=", 1)[1])
|
|
324
|
+
except Exception:
|
|
325
|
+
bad = 0
|
|
326
|
+
fails = []
|
|
327
|
+
if bad or r.returncode != 0:
|
|
328
|
+
fails.append("内联脚本 %d 段解析失败" % (bad or -1))
|
|
329
|
+
for ln in tail[:4]:
|
|
330
|
+
fails.append(" " + ln[:160])
|
|
331
|
+
say("内联脚本(外挂解析器):%s" % (tail[-1] if tail else "(无输出)"))
|
|
332
|
+
return fails, 1
|
|
333
|
+
fails, total, good = check_inline_builtin(node, idx)
|
|
334
|
+
say("内联脚本:scripts=%d ok=%d bad=%d" % (total, good, total - good))
|
|
335
|
+
return fails, total
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def main():
|
|
339
|
+
node = node_bin()
|
|
340
|
+
if not node:
|
|
341
|
+
print(TAG + "verify FAIL: 找不到 node(可用 NODE_BIN=... 指定)", flush=True)
|
|
342
|
+
return 1
|
|
343
|
+
fails = []
|
|
344
|
+
chpaths = []
|
|
345
|
+
if CHANGED:
|
|
346
|
+
chpaths = changed_paths()
|
|
347
|
+
if not chpaths:
|
|
348
|
+
print(TAG + "changed: 没有改动,跳过", flush=True)
|
|
349
|
+
return 0
|
|
350
|
+
files = [os.path.join(ROOT, p) for p in chpaths
|
|
351
|
+
if p.endswith((".js", ".mjs")) and os.path.exists(os.path.join(ROOT, p))]
|
|
352
|
+
for p in [x for x in chpaths if x.endswith(".py") and os.path.exists(os.path.join(ROOT, x))]:
|
|
353
|
+
try:
|
|
354
|
+
r = subprocess.run([sys.executable, "-m", "py_compile", os.path.join(ROOT, p)],
|
|
355
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace",
|
|
356
|
+
timeout=90, creationflags=NO_WIN)
|
|
357
|
+
if r.returncode != 0:
|
|
358
|
+
tail = (r.stderr or "").strip().splitlines()
|
|
359
|
+
fails.append("%s: %s" % (p, tail[-1][:180] if tail else "py_compile 失败"))
|
|
360
|
+
except Exception as e:
|
|
361
|
+
fails.append("%s: %s" % (p, e))
|
|
362
|
+
say("本次改动:%d 个文件(代码 %d)" % (len(chpaths), len(files)))
|
|
363
|
+
else:
|
|
364
|
+
files = collect()
|
|
365
|
+
if not files:
|
|
366
|
+
say("syntaxGlobs 没有匹配到文件(检查 kit.config.json)")
|
|
367
|
+
for p in files:
|
|
368
|
+
try:
|
|
369
|
+
r = subprocess.run([node, "--check", p], capture_output=True, text=True,
|
|
370
|
+
encoding="utf-8", errors="replace", timeout=60, creationflags=NO_WIN)
|
|
371
|
+
except Exception as e:
|
|
372
|
+
fails.append("%s: %s" % (os.path.relpath(p, ROOT), e))
|
|
373
|
+
continue
|
|
374
|
+
if r.returncode != 0:
|
|
375
|
+
first = [x for x in (r.stderr or "").strip().splitlines() if x.strip()][:2]
|
|
376
|
+
fails.append("%s: %s" % (os.path.relpath(p, ROOT), " ".join(first)[:200]))
|
|
377
|
+
say("语法:%d 个文件 · %d 个失败" % (len(files), len(fails)))
|
|
378
|
+
|
|
379
|
+
inline_fails, inline_total = [], 0
|
|
380
|
+
for _t in INLINE_LIST:
|
|
381
|
+
_f, _n = check_inline(node, _t)
|
|
382
|
+
inline_fails.extend(_f)
|
|
383
|
+
inline_total += _n
|
|
384
|
+
fails.extend(inline_fails)
|
|
385
|
+
|
|
386
|
+
probe_ok = 0
|
|
387
|
+
if WITH_PROBES or CHANGED:
|
|
388
|
+
picked = pick_probes()
|
|
389
|
+
if CHANGED:
|
|
390
|
+
hits = probes_for(chpaths)
|
|
391
|
+
picked = [r for r in hits if r["default"]] or hits
|
|
392
|
+
if len(hits) > len(picked):
|
|
393
|
+
say("(另有 %d 个非默认探针也覆盖这些文件,提交时不跑;要全跑用 --probes=all)" % (len(hits) - len(picked)))
|
|
394
|
+
if PROBE_SEL not in ("default", "all") and picked:
|
|
395
|
+
say("点名的探针:%s" % ", ".join(x["id"] for x in picked))
|
|
396
|
+
for pr in picked:
|
|
397
|
+
name = pr["file"]
|
|
398
|
+
path = os.path.join(ROOT, CFG.get("probeDir", ".probe"), name)
|
|
399
|
+
tag = "%s(%s)" % (pr["id"], pr["what"]) if pr["what"] else pr["id"]
|
|
400
|
+
if not os.path.exists(path):
|
|
401
|
+
fails.append("%s 文件不存在:%s" % (pr["id"], os.path.relpath(path, ROOT)))
|
|
402
|
+
continue
|
|
403
|
+
try:
|
|
404
|
+
r = subprocess.run(probe_argv(node, path), capture_output=True, text=True,
|
|
405
|
+
encoding="utf-8", errors="replace", timeout=240, cwd=ROOT,
|
|
406
|
+
creationflags=NO_WIN)
|
|
407
|
+
except subprocess.TimeoutExpired:
|
|
408
|
+
fails.append("%s 超时(%s)" % (pr["id"], name))
|
|
409
|
+
continue
|
|
410
|
+
out = (r.stdout or "") + (r.stderr or "")
|
|
411
|
+
if "FATAL" in out or r.returncode != 0:
|
|
412
|
+
first = out.strip().splitlines()[0][:160] if out.strip() else "no output"
|
|
413
|
+
fails.append("%s 挂了:%s" % (pr["id"], first))
|
|
414
|
+
continue
|
|
415
|
+
mres = re.findall(r"RESULT (\{.*\})", out)
|
|
416
|
+
verdict = None
|
|
417
|
+
if mres:
|
|
418
|
+
try:
|
|
419
|
+
verdict = json.loads(mres[-1]).get("ok")
|
|
420
|
+
except Exception:
|
|
421
|
+
verdict = None
|
|
422
|
+
if verdict is False:
|
|
423
|
+
fails.append("%s 断言失败(探针自己报了 ok=false)" % pr["id"])
|
|
424
|
+
continue
|
|
425
|
+
if verdict is True:
|
|
426
|
+
probe_ok += 1
|
|
427
|
+
say("探针 %s ok" % tag)
|
|
428
|
+
continue
|
|
429
|
+
if "errs=[]" in out:
|
|
430
|
+
probe_ok += 1
|
|
431
|
+
say("探针 %s ok" % tag)
|
|
432
|
+
elif "errs=" in out:
|
|
433
|
+
fails.append("%s 页面有 JS 报错(%s)" % (pr["id"], name))
|
|
434
|
+
else:
|
|
435
|
+
probe_ok += 1
|
|
436
|
+
say("探针 %s 跑完(没 errs 字段,按退出码判定)" % tag)
|
|
437
|
+
|
|
438
|
+
if fails:
|
|
439
|
+
print(TAG + "verify FAIL(%d 项)" % len(fails), flush=True)
|
|
440
|
+
for f in fails[:12]:
|
|
441
|
+
print(TAG + " - " + f, flush=True)
|
|
442
|
+
return 1
|
|
443
|
+
if CHANGED:
|
|
444
|
+
print(TAG + "verify ok: 改动 %d 个文件通过(探针 %d 个)"
|
|
445
|
+
% (len(files) + len([x for x in chpaths if x.endswith(".py")]), probe_ok), flush=True)
|
|
446
|
+
return 0
|
|
447
|
+
tail_probe = ""
|
|
448
|
+
if WITH_PROBES:
|
|
449
|
+
tail_probe = ",%d 个探针通过(登记表 %d 条)" % (probe_ok, len(registry()))
|
|
450
|
+
tail_inline = ",内联脚本 %d 段" % inline_total if inline_total else ""
|
|
451
|
+
print(TAG + "verify ok: %d 个文件语法通过%s%s" % (len(files), tail_inline, tail_probe), flush=True)
|
|
452
|
+
return 0
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
if __name__ == "__main__":
|
|
456
|
+
sys.exit(main())
|
package/check.bat
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
rem dsh-ops-kit self check. Double-click this file, or run: check.bat
|
|
3
|
+
rem ASCII only on purpose: .bat with Chinese breaks under the OEM code page.
|
|
4
|
+
setlocal
|
|
5
|
+
chcp 65001 >nul 2>&1
|
|
6
|
+
cd /d "%~dp0"
|
|
7
|
+
|
|
8
|
+
set "NODE_EXE="
|
|
9
|
+
for %%P in (node.exe) do if not defined NODE_EXE if exist "%%~$PATH:P" set "NODE_EXE=%%~$PATH:P"
|
|
10
|
+
if not defined NODE_EXE if exist "D:\nodejs\node.exe" set "NODE_EXE=D:\nodejs\node.exe"
|
|
11
|
+
if not defined NODE_EXE if exist "%ProgramFiles%\nodejs\node.exe" set "NODE_EXE=%ProgramFiles%\nodejs\node.exe"
|
|
12
|
+
if not defined NODE_EXE if exist "%LOCALAPPDATA%\Programs\nodejs\node.exe" set "NODE_EXE=%LOCALAPPDATA%\Programs\nodejs\node.exe"
|
|
13
|
+
|
|
14
|
+
if not defined NODE_EXE (
|
|
15
|
+
echo [kit] node.exe not found.
|
|
16
|
+
echo [kit] Install Node 20+ or tell this file where it is: set NODE_EXE=D:\path\to\node.exe
|
|
17
|
+
if not defined KIT_NOPAUSE pause
|
|
18
|
+
exit /b 2
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
echo [kit] node = %NODE_EXE%
|
|
22
|
+
echo.
|
|
23
|
+
"%NODE_EXE%" "scripts\rename-package.mjs" --check
|
|
24
|
+
if errorlevel 1 goto fail
|
|
25
|
+
"%NODE_EXE%" "scripts\selfcheck.mjs"
|
|
26
|
+
if errorlevel 1 goto fail
|
|
27
|
+
echo.
|
|
28
|
+
echo [kit] OK - selfcheck green
|
|
29
|
+
if not defined KIT_NOPAUSE pause
|
|
30
|
+
exit /b 0
|
|
31
|
+
|
|
32
|
+
:fail
|
|
33
|
+
echo.
|
|
34
|
+
echo [kit] FAILED - read the lines above
|
|
35
|
+
if not defined KIT_NOPAUSE pause
|
|
36
|
+
exit /b 1
|
package/cordis.patch.yml
ADDED
package/docs/PLUGIN.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# 两种形态:skill 与 dsh 插件包
|
|
2
|
+
|
|
3
|
+
同一份目录既是 **skill**(模型按描述想起它、加载纪律文本),又是 **dsh bundle**(装进 profile 后多了两个工具,schema 每次请求都进模型视野)。两种形态共用 `bin/` 里的同一套脚本,没有第二份实现。
|
|
4
|
+
|
|
5
|
+
## 1 · 当 skill 用(零安装)
|
|
6
|
+
|
|
7
|
+
把整个目录拷进任意 skills 目录,名字就是目录名,`SKILL.md` 在根上:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
node scripts/sync-skill.mjs # 默认同步到 <repo>/.claude/skills/dsh-ops-kit
|
|
11
|
+
node scripts/sync-skill.mjs <目标目录>
|
|
12
|
+
node scripts/sync-skill.mjs --check # 只比对,治两份副本漂移
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
skill 只是「文本 + 命令」,`bin/` 里的脚本仍由人/模型手动调;换台机器只需拷目录 + 一份 `kit.config.json`。
|
|
16
|
+
|
|
17
|
+
## 2 · 当 dsh 插件包用(bundle)
|
|
18
|
+
|
|
19
|
+
包形态在 `package.json` 里:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
"exports": { ".": "./dsh/index.js" },
|
|
23
|
+
"dsh": { "bundle": { "patch": "./cordis.patch.yml" } }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- `dsh/index.js` 导出 `name` / `inject = ['tools']` / `apply(ctx, config)`,在 apply 里用 `ctx.effect` 注册两个工具:
|
|
27
|
+
- `kit_dream`:跑 `bin/dream.mjs` 的五个模式(daily / weekly / card / after-deploy / status),默认 dry-run;
|
|
28
|
+
- `kit_verify`:跑 `bin/verify.py`(语法 + 内联脚本 + 探针),可选 `probes` / `changed` / `quiet`。
|
|
29
|
+
- 工具只是转发:规则全在 `bin/` 里,插件不含业务逻辑,也没有一条会自己执行的动作——不调用就什么都不发生。
|
|
30
|
+
- `cordis.patch.yml` 只有一行 insert,`config` 里可以给 `configPath` 指定默认配置路径。
|
|
31
|
+
- `locale/*.json` 提供插件面板的标题/描述,`icon.svg` 是图标(原创,随包分发)。
|
|
32
|
+
|
|
33
|
+
### 怎么装(**本仓库 intentionally 不做**,装到本机 or not 由用户决定)
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
plugin_manager action=install_bundle target=<本包的绝对路径> # 装进当前 profile
|
|
37
|
+
plugin_manager action=remove_bundle id=dsh-ops-kit # 卸掉
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
或者发布后按名字装:`npm publish` 之后由市场/`plugin_manager` 按包名解析。发布前必须改四处,否则两处名字对不上会装不上:
|
|
41
|
+
|
|
42
|
+
| 要改的 | 位置 |
|
|
43
|
+
|---|---|
|
|
44
|
+
| 包名 | `package.json` 的 `name`(建议带 scope,如 `@you/dsh-ops-kit`) |
|
|
45
|
+
| 补丁行 name | `cordis.patch.yml` 里 `name:` 必须与包名逐字一致 |
|
|
46
|
+
| `id` | `cordis.patch.yml` 的 `id`,profile 里唯一即可 |
|
|
47
|
+
| 展示文案 | `locale/en.json`、`locale/zh.json` 的 `meta.title` / `meta.description` |
|
|
48
|
+
|
|
49
|
+
## 3 · 不装也能验(改完必跑)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
node scripts/test-plugin.mjs # 假 ctx 加载 dsh/index.js:断言两个工具注册成功 + 夹具上 exit=0
|
|
53
|
+
node scripts/selfcheck.mjs # 13 项:语法 / 样例配置 / 无盘符路径 / 夹具 daily / 夹具 verify / 0 条防呆 / 无配置不写文件 / 实例配置被 gitignore / 插件自测 / 包名四处一致 / 发布必需文件
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`test-plugin.mjs` 就是「不装进 dsh 也能证明它符合插件形态」的那道验证:它用假 `ctx`(`tools.register` + `effect`)调 `apply`,再把工具真跑一遍。
|
|
57
|
+
|
|
58
|
+
## 4 · 边界
|
|
59
|
+
|
|
60
|
+
- 本仓库不把 kit 装进 `~/.dsh`(不写 profile、不写全局 skills 目录);要装是用户的一次显式动作。
|
|
61
|
+
- 装成 bundle 后改动对所有会话生效,且替换已装包要重启宿主;只想要纪律文本时用 skill 形态即可。
|
|
62
|
+
- 两种形态的纪律是同一份 `SKILL.md`,别只更新一份。
|
|
63
|
+
|
|
64
|
+
## 4.5 发布报 403:要 2FA 或带 bypass 的 token
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
npm error 403 Forbidden - PUT https://registry.npmjs.org/@scope%2fname
|
|
68
|
+
npm error Two-factor authentication or granular access token with bypass 2fa enabled is required
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
这不是权限或名字问题(`npm view` 的 404 只是「还没发布成功」)。npmjs 对**发布**强制两步验证,两条路:
|
|
72
|
+
|
|
73
|
+
1. **现取验证码**(最省事):`npm publish --registry=https://registry.npmjs.org --access public --otp=123456`,6 位码 30 秒一换,过期就重取。
|
|
74
|
+
2. **建 granular token 并勾 Bypass 2FA**:npmjs → Access Tokens → Granular Access Token → 权限 Read and write、scope 选包所在 scope、勾 bypass → 写进用户级 .npmrc:
|
|
75
|
+
`//registry.npmjs.org/:_authToken=<token>`。**token 等于密码,不要贴进对话、不要进 git。**
|
|
76
|
+
|
|
77
|
+
账号没开 2FA 时先开(发布必须有),否则永远 403。
|
|
78
|
+
|
|
79
|
+
## 5. 发布前检查(谁按名字装,靠这一步)
|
|
80
|
+
|
|
81
|
+
形态验证已经做完,剩下的是发布手续。按顺序,前两项机械,后两项只有维护者能做:
|
|
82
|
+
|
|
83
|
+
| # | 项 | 状态 | 怎么做 |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| 1 | 包内文件齐(含 LICENSE / CHANGELOG) | 已过 | `npm pack --dry-run` 应出现 18 个文件 |
|
|
86
|
+
| 2 | 解包后自检 | 已过 | 解开 tarball 直接跑 `node package/scripts/selfcheck.mjs`(不依赖仓库、不依赖 bash) |
|
|
87
|
+
| 3 | 包名与 scope | **待定** | 裸名 `dsh-ops-kit` 目前 registry 里是 404(空闲),但会被抢;建议改成 `@<scope>/dsh-ops-kit`——改时`package.json` 的 name 与 `cordis.patch.yml` 的 `name` / `id` 必须同时改,selfcheck 第 1 步会拦不一致 |
|
|
88
|
+
| 4 | 发布凭据 | **待办** | `npm whoami` 现在是 `need auth`;`npm adduser`(或写 `~/.npmrc` 的 `_authToken`) |
|
|
89
|
+
|
|
90
|
+
发出去以后还有两步验收(做完才算「按名字装」成立):
|
|
91
|
+
|
|
92
|
+
1. `npm view <name> version` 能看到刚发的版本号;
|
|
93
|
+
2. 干净目录 `npm i <name>` → 面板 `install_bundle target=<该 node_modules 里的包目录>` → 出现 `kit_dream` / `kit_verify` 两个工具。
|
|
94
|
+
|
|
95
|
+
**本仓库不做这两步的任一步**:不 `npm publish`、不写 `~/.npmrc`、不安装到本机。发布是维护者的动作,不是 agent 的。
|