lingshu-skill 5.25.0 → 5.28.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 +137 -0
- package/README.md +1577 -1577
- package/SKILL-lite.md +59 -59
- package/SKILL-tiny.md +38 -38
- package/SKILL.md +405 -405
- package/cordis-plugin/lingshu-cron/plugin.js +15 -5
- package/package.json +52 -52
- package/scripts/_ci_env_probe.py +81 -0
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +16 -16
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +137 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1577 -1577
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +59 -59
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +38 -38
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +405 -405
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_ci_env_probe.py +81 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/behavior_baseline.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/bench.py +218 -190
- package/scripts/astrbot_plugin_lingshu/engine/scripts/check_pressure_sync.py +31 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/check_tag.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/coverage_report.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/make_icon.py +24 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_build.py +31 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/release.py +28 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +28 -0
- package/scripts/astrbot_plugin_lingshu/make_checksums.py +28 -0
- package/scripts/behavior_baseline.py +28 -0
- package/scripts/bench.py +218 -190
- package/scripts/check_pressure_sync.py +31 -0
- package/scripts/check_tag.py +28 -0
- package/scripts/check_version.py +31 -0
- package/scripts/coverage_report.py +28 -0
- package/scripts/growth.py +28 -0
- package/scripts/make_icon.py +24 -0
- package/scripts/make_manifest.py +285 -254
- package/scripts/make_plugin_zip.py +28 -0
- package/scripts/panel_build.py +31 -0
- package/scripts/panel_server.py +28 -0
- package/scripts/release.py +28 -0
- package/scripts/run_tests.py +31 -0
- package/scripts/session_import.py +28 -0
- package/scripts/sync_engine.py +170 -139
- package/docs/npm-/345/217/221/345/270/203/350/257/264/346/230/216.md +0 -49
- package/docs/tgz-/345/256/211/350/243/205/350/257/264/346/230/216.md +0 -53
- package/docs//345/217/221/345/270/203/350/207/252/345/212/250/345/214/226.md +0 -54
- package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +0 -201
package/scripts/release.py
CHANGED
|
@@ -255,5 +255,33 @@ def main() -> int:
|
|
|
255
255
|
return do_status()
|
|
256
256
|
|
|
257
257
|
|
|
258
|
+
def _ensure_utf8_stdout() -> None:
|
|
259
|
+
"""把 stdout/stderr 切到 UTF-8,避免 Windows 控制台(cp1252/cp936)编不了中文就崩。
|
|
260
|
+
|
|
261
|
+
CI 的 windows-latest stdout 是 cp1252:脚本一 print 中文就 UnicodeEncodeError
|
|
262
|
+
直接退出(实测 sync_engine.py / make_checksums.py 都因此挂过,Ubuntu 同期正常)。
|
|
263
|
+
这不是业务 bug,是"中文输出 + 非 UTF-8 控制台"的必然结果。
|
|
264
|
+
"""
|
|
265
|
+
for name in ("stdout", "stderr"):
|
|
266
|
+
stream = getattr(sys, name, None)
|
|
267
|
+
fn = getattr(stream, "reconfigure", None)
|
|
268
|
+
if callable(fn):
|
|
269
|
+
try:
|
|
270
|
+
fn(encoding="utf-8", errors="replace")
|
|
271
|
+
continue
|
|
272
|
+
except (OSError, ValueError, AttributeError):
|
|
273
|
+
pass
|
|
274
|
+
try:
|
|
275
|
+
import io
|
|
276
|
+
buf = getattr(stream, "buffer", None)
|
|
277
|
+
if buf is not None:
|
|
278
|
+
setattr(sys, name,
|
|
279
|
+
io.TextIOWrapper(buf, encoding="utf-8", errors="replace",
|
|
280
|
+
line_buffering=True))
|
|
281
|
+
except Exception: # noqa: BLE001
|
|
282
|
+
pass
|
|
283
|
+
|
|
284
|
+
|
|
258
285
|
if __name__ == "__main__":
|
|
286
|
+
_ensure_utf8_stdout()
|
|
259
287
|
sys.exit(main())
|
package/scripts/run_tests.py
CHANGED
|
@@ -123,5 +123,36 @@ def main(argv: list[str]) -> int:
|
|
|
123
123
|
return 0
|
|
124
124
|
|
|
125
125
|
|
|
126
|
+
def _ensure_utf8_stdout() -> None:
|
|
127
|
+
"""把 stdout/stderr 切到 UTF-8,避免 Windows 控制台(cp1252/cp936)编不了中文就崩。
|
|
128
|
+
|
|
129
|
+
为什么必须有:CI 的 windows-latest stdout 是 cp1252,脚本一 print 中文就
|
|
130
|
+
UnicodeEncodeError 直接退出(实测 sync_engine.py 因此挂掉,Ubuntu 同期正常)。
|
|
131
|
+
这不是业务 bug,是"中文输出 + 非 UTF-8 控制台"的必然结果。
|
|
132
|
+
|
|
133
|
+
reconfigure 不可用(3.6 及更早 / 被替换过的流)时静默跳过,绝不因此再崩。
|
|
134
|
+
"""
|
|
135
|
+
for name in ("stdout", "stderr"):
|
|
136
|
+
stream = getattr(sys, name, None)
|
|
137
|
+
fn = getattr(stream, "reconfigure", None)
|
|
138
|
+
if callable(fn):
|
|
139
|
+
try:
|
|
140
|
+
fn(encoding="utf-8", errors="replace")
|
|
141
|
+
continue
|
|
142
|
+
except (OSError, ValueError, AttributeError):
|
|
143
|
+
pass
|
|
144
|
+
# 退路:包一层 UTF-8 writer(errors=replace,坏字符变 ?,不打断程序)
|
|
145
|
+
try:
|
|
146
|
+
import io
|
|
147
|
+
buf = getattr(stream, "buffer", None)
|
|
148
|
+
if buf is not None:
|
|
149
|
+
setattr(sys, name,
|
|
150
|
+
io.TextIOWrapper(buf, encoding="utf-8", errors="replace",
|
|
151
|
+
line_buffering=True))
|
|
152
|
+
except Exception: # noqa: BLE001
|
|
153
|
+
pass
|
|
154
|
+
|
|
155
|
+
|
|
126
156
|
if __name__ == "__main__":
|
|
157
|
+
_ensure_utf8_stdout()
|
|
127
158
|
sys.exit(main(sys.argv[1:]))
|
|
@@ -732,5 +732,33 @@ def main(argv=None) -> int:
|
|
|
732
732
|
return 0 if report.get("ok") else 1
|
|
733
733
|
|
|
734
734
|
|
|
735
|
+
def _ensure_utf8_stdout() -> None:
|
|
736
|
+
"""把 stdout/stderr 切到 UTF-8,避免 Windows 控制台(cp1252/cp936)编不了中文就崩。
|
|
737
|
+
|
|
738
|
+
CI 的 windows-latest stdout 是 cp1252:脚本一 print 中文就 UnicodeEncodeError
|
|
739
|
+
直接退出(实测 sync_engine.py / make_checksums.py 都因此挂过,Ubuntu 同期正常)。
|
|
740
|
+
这不是业务 bug,是"中文输出 + 非 UTF-8 控制台"的必然结果。
|
|
741
|
+
"""
|
|
742
|
+
for name in ("stdout", "stderr"):
|
|
743
|
+
stream = getattr(sys, name, None)
|
|
744
|
+
fn = getattr(stream, "reconfigure", None)
|
|
745
|
+
if callable(fn):
|
|
746
|
+
try:
|
|
747
|
+
fn(encoding="utf-8", errors="replace")
|
|
748
|
+
continue
|
|
749
|
+
except (OSError, ValueError, AttributeError):
|
|
750
|
+
pass
|
|
751
|
+
try:
|
|
752
|
+
import io
|
|
753
|
+
buf = getattr(stream, "buffer", None)
|
|
754
|
+
if buf is not None:
|
|
755
|
+
setattr(sys, name,
|
|
756
|
+
io.TextIOWrapper(buf, encoding="utf-8", errors="replace",
|
|
757
|
+
line_buffering=True))
|
|
758
|
+
except Exception: # noqa: BLE001
|
|
759
|
+
pass
|
|
760
|
+
|
|
761
|
+
|
|
735
762
|
if __name__ == "__main__":
|
|
763
|
+
_ensure_utf8_stdout()
|
|
736
764
|
sys.exit(main())
|
package/scripts/sync_engine.py
CHANGED
|
@@ -1,139 +1,170 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""engine 副本同步:根 scripts/*.py ↔ scripts/astrbot_plugin_lingshu/engine/scripts/*.py。
|
|
4
|
-
|
|
5
|
-
AstrBot 桥接插件内置一份核心引擎副本(engine/scripts/)。两边内容必须一致,
|
|
6
|
-
否则用户装插件得到旧核心。历史教训:CRLF 差异会让"裸 sha256 比较"全部误报,
|
|
7
|
-
因此本脚本按「换行归一化(CRLF→LF)后逐字比较」为准。
|
|
8
|
-
|
|
9
|
-
**文档副本也归这里管**(v3.47):插件里还随包发 SKILL.md / README / CHANGELOG /
|
|
10
|
-
docs,以前从没人同步,实测插件里躺着一份 v2.87 的 SKILL.md(主仓库已 v3.47,差
|
|
11
|
-
60 个版本)——AstrBot 用户看到的说明书是半年前的。现在它们与 .py 一起校验。
|
|
12
|
-
|
|
13
|
-
用法:
|
|
14
|
-
python scripts/sync_engine.py # 把根目录的 .py 与文档同步到 engine 副本
|
|
15
|
-
python scripts/sync_engine.py --check # 只校验一致性,不一致退出码 1(CI/pre-commit 用)
|
|
16
|
-
"""
|
|
17
|
-
from __future__ import annotations
|
|
18
|
-
|
|
19
|
-
import argparse
|
|
20
|
-
import shutil
|
|
21
|
-
import sys
|
|
22
|
-
from pathlib import Path
|
|
23
|
-
|
|
24
|
-
ROOT = Path(__file__).resolve().parent.parent
|
|
25
|
-
SRC = ROOT / "scripts"
|
|
26
|
-
DST = ROOT / "scripts" / "astrbot_plugin_lingshu" / "engine" / "scripts"
|
|
27
|
-
ENGINE = ROOT / "scripts" / "astrbot_plugin_lingshu" / "engine"
|
|
28
|
-
|
|
29
|
-
# 不参与同步的辅助脚本(桥接侧用不到 / 依赖仓库根的其他文件)
|
|
30
|
-
# 注意:panel_server.py **不在此列**(v3.47 B 方案)。插件 README 的「打开面板 → 拓展商店
|
|
31
|
-
# 一键导出」流程要求 `engine/scripts/panel_server.py` 真的存在;它只依赖标准库 + 同目录
|
|
32
|
-
# 的 brain/panels/growth,`ASSETS` 按 `__file__` 的父父目录解析,正好指向 engine/assets。
|
|
33
|
-
# 以前把它跳过,插件里就只剩一份跑不起来的面板产物。
|
|
34
|
-
# run_tests.py 是开发期跑测入口(v3.54),桥接侧不需要,不进副本。
|
|
35
|
-
SKIP = {"sync_engine.py", "make_manifest.py", "make_checksums.py",
|
|
36
|
-
"check_version.py", "make_plugin_zip.py", "run_tests.py"}
|
|
37
|
-
|
|
38
|
-
# 随插件发布的文件副本(路径相对仓库根,保持同名同目录)。
|
|
39
|
-
# assets/panel.html 是 panel_src 的构建产物:`panel_build.py --check` 保证源码↔产物一致,
|
|
40
|
-
# 这里再保证「主仓库产物 ↔ 插件副本一致」——两道闸合起来,插件里的面板不会再停在旧代。
|
|
41
|
-
DOC_FILES = [
|
|
42
|
-
"SKILL.md", "SKILL-lite.md", "SKILL-tiny.md", "README.md", "CHANGELOG.md",
|
|
43
|
-
"docs/panel-api.md", "docs/commands.md", "docs/mechanics.md", "docs/models.md",
|
|
44
|
-
"docs/recovery.md", "assets/panel.html",
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def _norm(text: str) -> str:
|
|
49
|
-
return text.replace("\r\n", "\n").replace("\r", "\n")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def _read(p: Path) -> str:
|
|
53
|
-
return p.read_text(encoding="utf-8-sig")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def sources() -> list[Path]:
|
|
57
|
-
return sorted(p for p in SRC.glob("*.py") if p.name not in SKIP and not p.name.startswith("test_"))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def sync() -> int:
|
|
61
|
-
DST.mkdir(parents=True, exist_ok=True)
|
|
62
|
-
changed = 0
|
|
63
|
-
for src in sources():
|
|
64
|
-
dst = DST / src.name
|
|
65
|
-
if dst.exists() and _norm(_read(dst)) == _norm(_read(src)):
|
|
66
|
-
continue
|
|
67
|
-
shutil.copy2(src, dst)
|
|
68
|
-
changed += 1
|
|
69
|
-
# 反向清理:副本里有、根目录已删掉的脚本一并移除,避免僵尸核心
|
|
70
|
-
removed = 0
|
|
71
|
-
keep = {p.name for p in sources()}
|
|
72
|
-
for dst in sorted(DST.glob("*.py")):
|
|
73
|
-
if dst.name not in keep:
|
|
74
|
-
dst.unlink()
|
|
75
|
-
removed += 1
|
|
76
|
-
# 文档副本:主仓库有就同步过去,主仓库删了就同步删掉(不给插件留过期页面)
|
|
77
|
-
doc_changed = doc_removed = 0
|
|
78
|
-
for rel in DOC_FILES:
|
|
79
|
-
src, dst = ROOT / rel, ENGINE / rel
|
|
80
|
-
if not src.is_file():
|
|
81
|
-
if dst.exists():
|
|
82
|
-
dst.unlink()
|
|
83
|
-
doc_removed += 1
|
|
84
|
-
continue
|
|
85
|
-
if dst.exists() and _norm(_read(dst)) == _norm(_read(src)):
|
|
86
|
-
continue
|
|
87
|
-
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
88
|
-
shutil.copy2(src, dst)
|
|
89
|
-
doc_changed += 1
|
|
90
|
-
print(f"[sync] engine 副本已同步:脚本 更新 {changed} 个 / 清理 {removed} 个;"
|
|
91
|
-
f"文档 更新 {doc_changed} 个 / 清理 {doc_removed} 个")
|
|
92
|
-
return 0
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def check() -> int:
|
|
96
|
-
bad = []
|
|
97
|
-
names = {p.name for p in sources()}
|
|
98
|
-
for src in sources():
|
|
99
|
-
dst = DST / src.name
|
|
100
|
-
if not dst.exists():
|
|
101
|
-
bad.append(f"{src.name}: 副本缺失")
|
|
102
|
-
continue
|
|
103
|
-
if _norm(_read(dst)) != _norm(_read(src)):
|
|
104
|
-
bad.append(f"{src.name}: 内容不一致(换行归一化后)")
|
|
105
|
-
for dst in sorted(DST.glob("*.py")):
|
|
106
|
-
if dst.name not in names:
|
|
107
|
-
bad.append(f"{dst.name}: 副本多出僵尸文件(根目录已删除)")
|
|
108
|
-
doc_checked = 0
|
|
109
|
-
for rel in DOC_FILES:
|
|
110
|
-
src, dst = ROOT / rel, ENGINE / rel
|
|
111
|
-
if not src.is_file():
|
|
112
|
-
if dst.exists():
|
|
113
|
-
bad.append(f"{rel}: 主仓库已删除,但副本还在")
|
|
114
|
-
continue
|
|
115
|
-
doc_checked += 1
|
|
116
|
-
if not dst.exists():
|
|
117
|
-
bad.append(f"{rel}: 文档副本缺失")
|
|
118
|
-
elif _norm(_read(dst)) != _norm(_read(src)):
|
|
119
|
-
bad.append(f"{rel}: 文档副本过期(内容与主仓库不一致)")
|
|
120
|
-
if bad:
|
|
121
|
-
print("[sync] engine 副本与根 scripts / 文档不一致:", file=sys.stderr)
|
|
122
|
-
for b in bad:
|
|
123
|
-
print(f" - {b}", file=sys.stderr)
|
|
124
|
-
print("运行 python scripts/sync_engine.py 修复。", file=sys.stderr)
|
|
125
|
-
return 1
|
|
126
|
-
print(f"[sync] OK:engine 副本 {len(names)} 个脚本 + {doc_checked} 个文档"
|
|
127
|
-
f"与根目录一致(换行归一化后)")
|
|
128
|
-
return 0
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""engine 副本同步:根 scripts/*.py ↔ scripts/astrbot_plugin_lingshu/engine/scripts/*.py。
|
|
4
|
+
|
|
5
|
+
AstrBot 桥接插件内置一份核心引擎副本(engine/scripts/)。两边内容必须一致,
|
|
6
|
+
否则用户装插件得到旧核心。历史教训:CRLF 差异会让"裸 sha256 比较"全部误报,
|
|
7
|
+
因此本脚本按「换行归一化(CRLF→LF)后逐字比较」为准。
|
|
8
|
+
|
|
9
|
+
**文档副本也归这里管**(v3.47):插件里还随包发 SKILL.md / README / CHANGELOG /
|
|
10
|
+
docs,以前从没人同步,实测插件里躺着一份 v2.87 的 SKILL.md(主仓库已 v3.47,差
|
|
11
|
+
60 个版本)——AstrBot 用户看到的说明书是半年前的。现在它们与 .py 一起校验。
|
|
12
|
+
|
|
13
|
+
用法:
|
|
14
|
+
python scripts/sync_engine.py # 把根目录的 .py 与文档同步到 engine 副本
|
|
15
|
+
python scripts/sync_engine.py --check # 只校验一致性,不一致退出码 1(CI/pre-commit 用)
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import shutil
|
|
21
|
+
import sys
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
25
|
+
SRC = ROOT / "scripts"
|
|
26
|
+
DST = ROOT / "scripts" / "astrbot_plugin_lingshu" / "engine" / "scripts"
|
|
27
|
+
ENGINE = ROOT / "scripts" / "astrbot_plugin_lingshu" / "engine"
|
|
28
|
+
|
|
29
|
+
# 不参与同步的辅助脚本(桥接侧用不到 / 依赖仓库根的其他文件)
|
|
30
|
+
# 注意:panel_server.py **不在此列**(v3.47 B 方案)。插件 README 的「打开面板 → 拓展商店
|
|
31
|
+
# 一键导出」流程要求 `engine/scripts/panel_server.py` 真的存在;它只依赖标准库 + 同目录
|
|
32
|
+
# 的 brain/panels/growth,`ASSETS` 按 `__file__` 的父父目录解析,正好指向 engine/assets。
|
|
33
|
+
# 以前把它跳过,插件里就只剩一份跑不起来的面板产物。
|
|
34
|
+
# run_tests.py 是开发期跑测入口(v3.54),桥接侧不需要,不进副本。
|
|
35
|
+
SKIP = {"sync_engine.py", "make_manifest.py", "make_checksums.py",
|
|
36
|
+
"check_version.py", "make_plugin_zip.py", "run_tests.py"}
|
|
37
|
+
|
|
38
|
+
# 随插件发布的文件副本(路径相对仓库根,保持同名同目录)。
|
|
39
|
+
# assets/panel.html 是 panel_src 的构建产物:`panel_build.py --check` 保证源码↔产物一致,
|
|
40
|
+
# 这里再保证「主仓库产物 ↔ 插件副本一致」——两道闸合起来,插件里的面板不会再停在旧代。
|
|
41
|
+
DOC_FILES = [
|
|
42
|
+
"SKILL.md", "SKILL-lite.md", "SKILL-tiny.md", "README.md", "CHANGELOG.md",
|
|
43
|
+
"docs/panel-api.md", "docs/commands.md", "docs/mechanics.md", "docs/models.md",
|
|
44
|
+
"docs/recovery.md", "assets/panel.html",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _norm(text: str) -> str:
|
|
49
|
+
return text.replace("\r\n", "\n").replace("\r", "\n")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _read(p: Path) -> str:
|
|
53
|
+
return p.read_text(encoding="utf-8-sig")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def sources() -> list[Path]:
|
|
57
|
+
return sorted(p for p in SRC.glob("*.py") if p.name not in SKIP and not p.name.startswith("test_"))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def sync() -> int:
|
|
61
|
+
DST.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
changed = 0
|
|
63
|
+
for src in sources():
|
|
64
|
+
dst = DST / src.name
|
|
65
|
+
if dst.exists() and _norm(_read(dst)) == _norm(_read(src)):
|
|
66
|
+
continue
|
|
67
|
+
shutil.copy2(src, dst)
|
|
68
|
+
changed += 1
|
|
69
|
+
# 反向清理:副本里有、根目录已删掉的脚本一并移除,避免僵尸核心
|
|
70
|
+
removed = 0
|
|
71
|
+
keep = {p.name for p in sources()}
|
|
72
|
+
for dst in sorted(DST.glob("*.py")):
|
|
73
|
+
if dst.name not in keep:
|
|
74
|
+
dst.unlink()
|
|
75
|
+
removed += 1
|
|
76
|
+
# 文档副本:主仓库有就同步过去,主仓库删了就同步删掉(不给插件留过期页面)
|
|
77
|
+
doc_changed = doc_removed = 0
|
|
78
|
+
for rel in DOC_FILES:
|
|
79
|
+
src, dst = ROOT / rel, ENGINE / rel
|
|
80
|
+
if not src.is_file():
|
|
81
|
+
if dst.exists():
|
|
82
|
+
dst.unlink()
|
|
83
|
+
doc_removed += 1
|
|
84
|
+
continue
|
|
85
|
+
if dst.exists() and _norm(_read(dst)) == _norm(_read(src)):
|
|
86
|
+
continue
|
|
87
|
+
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
88
|
+
shutil.copy2(src, dst)
|
|
89
|
+
doc_changed += 1
|
|
90
|
+
print(f"[sync] engine 副本已同步:脚本 更新 {changed} 个 / 清理 {removed} 个;"
|
|
91
|
+
f"文档 更新 {doc_changed} 个 / 清理 {doc_removed} 个")
|
|
92
|
+
return 0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def check() -> int:
|
|
96
|
+
bad = []
|
|
97
|
+
names = {p.name for p in sources()}
|
|
98
|
+
for src in sources():
|
|
99
|
+
dst = DST / src.name
|
|
100
|
+
if not dst.exists():
|
|
101
|
+
bad.append(f"{src.name}: 副本缺失")
|
|
102
|
+
continue
|
|
103
|
+
if _norm(_read(dst)) != _norm(_read(src)):
|
|
104
|
+
bad.append(f"{src.name}: 内容不一致(换行归一化后)")
|
|
105
|
+
for dst in sorted(DST.glob("*.py")):
|
|
106
|
+
if dst.name not in names:
|
|
107
|
+
bad.append(f"{dst.name}: 副本多出僵尸文件(根目录已删除)")
|
|
108
|
+
doc_checked = 0
|
|
109
|
+
for rel in DOC_FILES:
|
|
110
|
+
src, dst = ROOT / rel, ENGINE / rel
|
|
111
|
+
if not src.is_file():
|
|
112
|
+
if dst.exists():
|
|
113
|
+
bad.append(f"{rel}: 主仓库已删除,但副本还在")
|
|
114
|
+
continue
|
|
115
|
+
doc_checked += 1
|
|
116
|
+
if not dst.exists():
|
|
117
|
+
bad.append(f"{rel}: 文档副本缺失")
|
|
118
|
+
elif _norm(_read(dst)) != _norm(_read(src)):
|
|
119
|
+
bad.append(f"{rel}: 文档副本过期(内容与主仓库不一致)")
|
|
120
|
+
if bad:
|
|
121
|
+
print("[sync] engine 副本与根 scripts / 文档不一致:", file=sys.stderr)
|
|
122
|
+
for b in bad:
|
|
123
|
+
print(f" - {b}", file=sys.stderr)
|
|
124
|
+
print("运行 python scripts/sync_engine.py 修复。", file=sys.stderr)
|
|
125
|
+
return 1
|
|
126
|
+
print(f"[sync] OK:engine 副本 {len(names)} 个脚本 + {doc_checked} 个文档"
|
|
127
|
+
f"与根目录一致(换行归一化后)")
|
|
128
|
+
return 0
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _ensure_utf8_stdout() -> None:
|
|
132
|
+
"""把 stdout/stderr 切到 UTF-8,避免 Windows 控制台(cp1252/cp936)编不了中文就崩。
|
|
133
|
+
|
|
134
|
+
为什么必须有:CI 的 windows-latest stdout 是 cp1252,脚本一 print 中文就
|
|
135
|
+
UnicodeEncodeError 直接退出(实测 sync_engine.py 因此挂掉,Ubuntu 同期正常)。
|
|
136
|
+
这不是业务 bug,是"中文输出 + 非 UTF-8 控制台"的必然结果。
|
|
137
|
+
|
|
138
|
+
reconfigure 不可用(3.6 及更早 / 被替换过的流)时静默跳过,绝不因此再崩。
|
|
139
|
+
"""
|
|
140
|
+
for name in ("stdout", "stderr"):
|
|
141
|
+
stream = getattr(sys, name, None)
|
|
142
|
+
fn = getattr(stream, "reconfigure", None)
|
|
143
|
+
if callable(fn):
|
|
144
|
+
try:
|
|
145
|
+
fn(encoding="utf-8", errors="replace")
|
|
146
|
+
continue
|
|
147
|
+
except (OSError, ValueError, AttributeError):
|
|
148
|
+
pass
|
|
149
|
+
# 退路:包一层 UTF-8 writer(errors=replace,坏字符变 ?,不打断程序)
|
|
150
|
+
try:
|
|
151
|
+
import io
|
|
152
|
+
buf = getattr(stream, "buffer", None)
|
|
153
|
+
if buf is not None:
|
|
154
|
+
setattr(sys, name,
|
|
155
|
+
io.TextIOWrapper(buf, encoding="utf-8", errors="replace",
|
|
156
|
+
line_buffering=True))
|
|
157
|
+
except Exception: # noqa: BLE001
|
|
158
|
+
pass
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def main(argv: list[str] | None = None) -> int:
|
|
162
|
+
ap = argparse.ArgumentParser(description="灵枢:engine 副本同步与校验")
|
|
163
|
+
ap.add_argument("--check", action="store_true", help="只校验一致性,不写文件")
|
|
164
|
+
args = ap.parse_args(argv)
|
|
165
|
+
return check() if args.check else sync()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
_ensure_utf8_stdout()
|
|
170
|
+
sys.exit(main())
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# 灵枢 npm 发布说明(维护者)
|
|
2
|
-
|
|
3
|
-
## 原理:为什么发 npm 后不用再改市场
|
|
4
|
-
|
|
5
|
-
awesome-dsh-plugin 目录站会**自动检测**插件的仓库:
|
|
6
|
-
- 仓库是 npm 包 → 市场 install 自动变成 `dsh plugin add lingshu-skill@版本`
|
|
7
|
-
- 仓库不是 npm 包 → 回退到 `github:owner/repo` 源码安装(需要 git + 连 GitHub,国内常失败)
|
|
8
|
-
|
|
9
|
-
灵枢之前没发 npm,所以市场条目是 `github:` 源码安装,你朋友装时才报 `git 不是内部命令` / `ECONNREFUSED`。**发一次 npm 后目录站自动改成 npm 包名,以后每次发版只要 publish 新版本,不用再动市场条目。**
|
|
10
|
-
|
|
11
|
-
## 一次性准备(已完成,在仓库里)
|
|
12
|
-
|
|
13
|
-
- `package.json`:`name: lingshu-skill`、`files` 白名单(只含发布文件)、`scripts.prepack`(publish 前跑 `npm_prepack.py`)
|
|
14
|
-
- `scripts/npm_prepack.py`:sync engine 副本 + 清 pycache,保证包里 engine 完整且无垃圾
|
|
15
|
-
- `.npmignore`:兜底排除本地数据(files 白名单优先级更高,主要靠 prepack 清理)
|
|
16
|
-
|
|
17
|
-
验证过 `npm pack`:132 文件,必需文件齐全、engine 49 文件无缓存、tests 0、cordis-plugin 11。
|
|
18
|
-
|
|
19
|
-
## 发布步骤(你操作)
|
|
20
|
-
|
|
21
|
-
```powershell
|
|
22
|
-
# 1. 一次性:登录 npm(有账号就直接 login,没有先去 npmjs.com 注册)
|
|
23
|
-
npm login
|
|
24
|
-
|
|
25
|
-
# 2. 确认包名没被占、版本比已发布的大
|
|
26
|
-
npm view lingshu-skill version # 若 404 = 首次发布,正常
|
|
27
|
-
|
|
28
|
-
# 3. 在仓库根发布(prepack 会自动跑,不用手动 sync)
|
|
29
|
-
npm publish
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
发布后:
|
|
33
|
-
- npm 上出现 `lingshu-skill@3.74.0`(或你当时的版本)
|
|
34
|
-
- 目录站**下次抓取**(约每天一次,市场另有 1 小时缓存)自动把 install 改成 npm 包名
|
|
35
|
-
- 你朋友在插件市场点安装 → pnpm 从 npm registry 下 tgz,**不需要 git、不需要连 GitHub**
|
|
36
|
-
|
|
37
|
-
## 注意
|
|
38
|
-
|
|
39
|
-
- **每次发版**:改代码 → 升 SKILL.md/package.json 版本 → CHANGELOG → `npm publish`。市场自动跟随,不用手改目录站。
|
|
40
|
-
- **包名 `lingshu-skill` 已注册归你**:别人不能再占。首次 publish 后确认 `npm view lingshu-skill version` 返回你的版本。
|
|
41
|
-
- **别把 token 写进包**:`.npmignore` + files 白名单已排除 config.json/.env;发布前 `npm pack --dry-run` 再扫一眼最稳。
|
|
42
|
-
- **国内网络**:npm registry 国内可达(你朋友装别的插件就是走 npm),所以没问题。
|
|
43
|
-
|
|
44
|
-
## 首次发布踩过的两个坑(2026-11-22)
|
|
45
|
-
|
|
46
|
-
1. **token 少了 `npm_` 前缀**:从 npm 网页复制 token 时漏了开头 `npm_`,`.npmrc` 里是 `_p2P3...`(37 字符)→ `npm whoami` 401。完整 token 必须以 `npm_` 开头、约 40+ 字符。修复:`npm config set //registry.npmjs.org/:_authToken "npm_完整token"`(用引号,别漏前缀)。
|
|
47
|
-
2. **whoami 成功 ≠ 能发布**:`npm whoami` 只需读权限(返回用户名即通过),但 `npm publish` 要求 **Bypass 2FA 的 Granular Token**。普通 token 或无 bypass 的 granular token 会让 publish 报 `E403 ... Two-factor authentication or granular access token with bypass 2fa enabled is required`。生成 token 时**必须勾选 "Bypass two-factor authentication"**,权限给 `lingshu-skill` 的 Read and write。
|
|
48
|
-
3. **别用 `npm publish --otp`**:账号没开 2FA 时 `--otp` 无效,照样 403。走 bypass token 最直接。
|
|
49
|
-
4. **token 一旦贴到聊天/日志即泄露**:立即去 npmjs.com → Access Tokens → Revoke,重新生成。绝不把 token 发给任何人或 AI。
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# 灵枢 tgz 直链安装(给网络受限 / 没装 git 的用户)
|
|
2
|
-
|
|
3
|
-
## 背景
|
|
4
|
-
|
|
5
|
-
灵枢在 DSH 插件市场的条目写的是 `github:` 源码安装:
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
install: dsh plugin --profile web add github:Q2667671398/lingshu-skill
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
这要求 pnpm 调用 `git` clone GitHub 仓库。国内直连 GitHub 常 `ECONNREFUSED`,
|
|
12
|
-
没装 git 的机器报 `git 不是内部或外部命令`——都装不上。别的插件能装是因为它们
|
|
13
|
-
是 npm 版本号或 tgz 直链,pnpm 下压缩包即可,不需要 git。
|
|
14
|
-
|
|
15
|
-
## 解法:tgz 直链
|
|
16
|
-
|
|
17
|
-
把灵枢打成 npm 格式的 tgz,挂到 GitHub Release,市场条目改成 tgz 直链:
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
install: dsh plugin add https://github.com/Q2667671398/lingshu-skill/releases/download/v3.72.0/lingshu-skill-3.72.0.tgz
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
pnpm/npm 下载解压即可,**不需要 git、不需要 clone GitHub**。
|
|
24
|
-
|
|
25
|
-
## 打包(发布者操作)
|
|
26
|
-
|
|
27
|
-
```powershell
|
|
28
|
-
$py = "D:\ServBay\packages\python\current\python.exe"
|
|
29
|
-
& $py scripts\make_dsh_tgz.py
|
|
30
|
-
# 产出 lingshu-skill-<version>.tgz(仓库根,已 gitignore)
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
脚本会先跑 `sync_engine.sync()` 生成 `engine/` 副本(已从 git 移除、但插件运行
|
|
34
|
-
需要),再按 manifest 发布文件 + engine 全目录打成顶层 `package/` 的 tgz。
|
|
35
|
-
实测 v3.72.0:116 文件 / 1538 KB,`npm install <tgz>` 可直接装、结构正确。
|
|
36
|
-
|
|
37
|
-
## 上传到 GitHub Release
|
|
38
|
-
|
|
39
|
-
1. 在 GitHub 建 Release `vX.Y`(tag 已存在的可直接用),把 `.tgz` 作为附件上传;
|
|
40
|
-
2. 拿到直链:`https://github.com/Q2667671398/lingshu-skill/releases/download/vX.Y/lingshu-skill-X.Y.0.tgz`;
|
|
41
|
-
3. 更新插件市场目录站(`dsh-plugin-catalog` 的 `plugins.json`)里灵枢条目:
|
|
42
|
-
- `install` 改成上面的 tgz 直链命令
|
|
43
|
-
- 或 `npm`/`version` 留空、`install` 用 tgz(对齐 `dsh-pnpm-build-control` 的写法)
|
|
44
|
-
|
|
45
|
-
## 用户侧(你朋友)
|
|
46
|
-
|
|
47
|
-
市场里点安装即可,命令变成下载 tgz——不用装 git、不用连 GitHub。
|
|
48
|
-
|
|
49
|
-
如果暂时改不了市场条目,也可以手动装:
|
|
50
|
-
|
|
51
|
-
```powershell
|
|
52
|
-
dsh plugin --profile desktop add <tgz直链或本地路径>
|
|
53
|
-
```
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# 发版自动化(release.py)
|
|
2
|
-
|
|
3
|
-
把台账第四节的发布流程串成命令,**守住"版本必须升、检查必须全绿"的门禁**,不再靠人肉记步骤。
|
|
4
|
-
|
|
5
|
-
## 三条命令
|
|
6
|
-
|
|
7
|
-
```powershell
|
|
8
|
-
$py = "D:\ServBay\packages\python\current\python.exe"
|
|
9
|
-
cd E:\丁厚同\文档\程序\灵枢-skill
|
|
10
|
-
|
|
11
|
-
# 看现状:本地版本 / 线上 latest / 是否可发
|
|
12
|
-
& $py scripts\release.py status
|
|
13
|
-
|
|
14
|
-
# 1)升版本(X.Y):自动改四处版本 + CHANGELOG 首节 + 重生成派生文件 + 全套验证
|
|
15
|
-
& $py scripts\release.py bump 3.84 "一句话主题"
|
|
16
|
-
|
|
17
|
-
# 2)发布:校验版本一致+检查全绿 → npm publish → 轮询 registry 到可见
|
|
18
|
-
& $py scripts\release.py publish
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## 各命令细节
|
|
22
|
-
|
|
23
|
-
- **bump `<X.Y>` `[标题]`**:
|
|
24
|
-
- 拒绝非 X.Y 格式、拒绝新版本 ≤ 当前版本;
|
|
25
|
-
- 改 `SKILL.md` / `package.json`(X.Y.0) / `README.md` / `CHANGELOG.md` 首节;
|
|
26
|
-
- 按依赖序重生成 `sync_engine` → `make_checksums` → `make_manifest`;
|
|
27
|
-
- 跑六项检查 + 行为基线 + 全量测试,**全绿才成功**(任一红即退出码 1)。
|
|
28
|
-
- 不做 git 提交/tag/push。
|
|
29
|
-
- **publish `[--wait 分钟]`**:
|
|
30
|
-
- 先跑全套验证;`npm whoami` 确认登录;确认本地版本 > 线上 latest(防 E409 重发);
|
|
31
|
-
- `npm publish` 后轮询 registry(绕本机 npm 缓存)直到 `latest` == 本地版本——**npm staged 窗口最多 ~17 分钟**,脚本默认等 20 分钟。
|
|
32
|
-
- **status**:打印本地/线上版本与"是否可发"。
|
|
33
|
-
|
|
34
|
-
## 两条铁律(脚本替你守)
|
|
35
|
-
|
|
36
|
-
1. **新文件必须先 `git add`**:`manifest --check` 会拒绝未入库的发布范围内文件(如新脚本自己)。先 `git add` 新文件再 bump,脚本不替你决定哪些文件入库。
|
|
37
|
-
2. **tag/push 不做**:按用户决定,脚本不含 git 提交/tag/push;发版后如需提交,仍按"一个版本一个提交"手工做(提交时排除 `tests/test_*.py` 本地测试文件)。
|
|
38
|
-
|
|
39
|
-
## 典型发版流程(建议顺序)
|
|
40
|
-
|
|
41
|
-
```powershell
|
|
42
|
-
# 1) 改完功能代码(先别提交版本文件)
|
|
43
|
-
# 2) 升版本 + 重生成 + 全套验证(bump 会改 SKILL/package/README/CHANGELOG/manifest)
|
|
44
|
-
& $py scripts\release.py bump 3.84 "主题"
|
|
45
|
-
# 3) 全绿后,把功能代码 + 版本文件一起提交(一个版本一个提交)
|
|
46
|
-
git add -A
|
|
47
|
-
git commit -m "feat: v3.84 主题"
|
|
48
|
-
# 4) 发布到 npm(等 staged 可见)
|
|
49
|
-
& $py scripts\release.py publish
|
|
50
|
-
# 5) 同步 DSH 副本 + 重启插件(脚本不做)
|
|
51
|
-
powershell -ExecutionPolicy Bypass -File scripts\update_dsh_copy.ps1 -Profile desktop
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
> tag/push 按用户决定不做;提交时排除 `tests/test_*.py` 本地测试文件。
|