lingshu-skill 5.24.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/README.md +1577 -1577
  3. package/SKILL-lite.md +59 -59
  4. package/SKILL-tiny.md +38 -38
  5. package/SKILL.md +405 -404
  6. package/cordis-plugin/lingshu-cron/plugin.js +15 -5
  7. package/package.json +52 -52
  8. package/scripts/_ci_env_probe.py +81 -0
  9. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +23 -22
  10. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +181 -0
  11. package/scripts/astrbot_plugin_lingshu/engine/README.md +1577 -1577
  12. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +59 -59
  13. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +38 -38
  14. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +405 -404
  15. package/scripts/astrbot_plugin_lingshu/engine/scripts/_ci_env_probe.py +81 -0
  16. package/scripts/astrbot_plugin_lingshu/engine/scripts/behavior_baseline.py +28 -0
  17. package/scripts/astrbot_plugin_lingshu/engine/scripts/bench.py +218 -190
  18. package/scripts/astrbot_plugin_lingshu/engine/scripts/check_pressure_sync.py +31 -0
  19. package/scripts/astrbot_plugin_lingshu/engine/scripts/check_tag.py +28 -0
  20. package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +43 -0
  21. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +74 -0
  22. package/scripts/astrbot_plugin_lingshu/engine/scripts/coverage_report.py +195 -0
  23. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +28 -0
  24. package/scripts/astrbot_plugin_lingshu/engine/scripts/make_icon.py +24 -0
  25. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_dialogue.py +221 -219
  26. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +10 -3
  27. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_build.py +31 -0
  28. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +28 -0
  29. package/scripts/astrbot_plugin_lingshu/engine/scripts/panels.py +470 -460
  30. package/scripts/astrbot_plugin_lingshu/engine/scripts/release.py +42 -0
  31. package/scripts/astrbot_plugin_lingshu/engine/scripts/safety.py +29 -1
  32. package/scripts/astrbot_plugin_lingshu/engine/scripts/safety_net.py +12 -0
  33. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +28 -0
  34. package/scripts/astrbot_plugin_lingshu/make_checksums.py +28 -0
  35. package/scripts/behavior_baseline.py +28 -0
  36. package/scripts/bench.py +218 -190
  37. package/scripts/check_pressure_sync.py +31 -0
  38. package/scripts/check_tag.py +28 -0
  39. package/scripts/check_version.py +47 -0
  40. package/scripts/cli.py +43 -0
  41. package/scripts/core.py +74 -0
  42. package/scripts/coverage_report.py +195 -0
  43. package/scripts/growth.py +28 -0
  44. package/scripts/make_icon.py +24 -0
  45. package/scripts/make_manifest.py +285 -254
  46. package/scripts/make_plugin_zip.py +28 -0
  47. package/scripts/mem_dialogue.py +221 -219
  48. package/scripts/memory.py +10 -3
  49. package/scripts/panel_build.py +31 -0
  50. package/scripts/panel_server.py +28 -0
  51. package/scripts/panels.py +470 -460
  52. package/scripts/release.py +42 -0
  53. package/scripts/run_tests.py +31 -0
  54. package/scripts/safety.py +29 -1
  55. package/scripts/safety_net.py +12 -0
  56. package/scripts/session_import.py +28 -0
  57. package/scripts/sync_engine.py +170 -139
  58. package/docs/npm-/345/217/221/345/270/203/350/257/264/346/230/216.md +0 -49
  59. package/docs/tgz-/345/256/211/350/243/205/350/257/264/346/230/216.md +0 -53
  60. package/docs//345/217/221/345/270/203/350/207/252/345/212/250/345/214/226.md +0 -54
  61. package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +0 -189
@@ -121,6 +121,20 @@ def do_bump(new_ver: str, title: str) -> int:
121
121
  print(f"[release] {rel} 没找到版本标记 {o!r},拒绝继续", file=sys.stderr)
122
122
  return 1
123
123
  p.write_bytes(b.replace(o, n, 1))
124
+ # 1b) SKILL-lite / SKILL-tiny 的 version 跟着走。
125
+ # 它们不触发"必须升版"(裁剪文档,正文可能长期不动),但头部的 version 若十年不动,
126
+ # 会让人误判"这份文档对得上引擎"。用字节级正则改,保 BOM 与原换行。
127
+ for rel in ("SKILL-lite.md", "SKILL-tiny.md"):
128
+ lp = ROOT / rel
129
+ if not lp.is_file():
130
+ continue
131
+ b = lp.read_bytes()
132
+ nb, cnt = re.subn(rb"^version:\s*[\d.]+",
133
+ f"version: {new_ver}".encode(), b, count=1, flags=re.M)
134
+ if cnt:
135
+ lp.write_bytes(nb)
136
+ print(f"[release] {rel} version → {new_ver}")
137
+
124
138
  # CHANGELOG 首节改写为新版本(占位,正文留空由维护者补)
125
139
  cl = ROOT / "CHANGELOG.md"
126
140
  t = cl.read_text(encoding="utf-8")
@@ -241,5 +255,33 @@ def main() -> int:
241
255
  return do_status()
242
256
 
243
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
+
244
285
  if __name__ == "__main__":
286
+ _ensure_utf8_stdout()
245
287
  sys.exit(main())
@@ -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:]))
package/scripts/safety.py CHANGED
@@ -324,10 +324,33 @@ def is_interactive() -> bool:
324
324
  return False
325
325
 
326
326
 
327
+ def require_token(action: str, given: str, expected: str, *, hint: str = "") -> None:
328
+ """破坏性操作的一次性确认码校验(与 confirm_destructive 同属 safety 的一套原语)。
329
+
330
+ 为什么不并进 y/N:这类操作要能被**程序 / AI 调用时强制显式写下指纹**,
331
+ 而那种场合 stdin 不是终端,交互提示根本不会出现。
332
+ 这样说清分工,比"两套逻辑各写各的"更难出错:
333
+ · confirm_destructive —— 有终端时的人机确认(--yes 或 y)
334
+ · require_token —— 任何场合都必须匹配的指纹
335
+
336
+ 不匹配抛 ValueError(调用方负责转成退出码)。
337
+ """
338
+ if not expected:
339
+ raise ValueError(f"[{action}] 缺少确认码基准(内部错误)")
340
+ if not given or str(given) != str(expected):
341
+ msg = (f"[{action}] 需显式确认:确认码不匹配"
342
+ f"(应为目标 id 的前 {len(str(expected))} 位)")
343
+ if hint:
344
+ msg += f"。{hint}"
345
+ raise ValueError(msg)
346
+
347
+
327
348
  def confirm_destructive(action: str, impact: str | list[str], *,
328
349
  assume_yes: bool = False,
329
350
  hint: str = "",
330
- stream=None) -> bool:
351
+ stream=None,
352
+ token: str = "",
353
+ expect_token: str = "") -> bool:
331
354
  """破坏性操作的统一确认。返回 True=可以继续,False=调用方应中止(或被取消)。
332
355
 
333
356
  参数:
@@ -343,6 +366,11 @@ def confirm_destructive(action: str, impact: str | list[str], *,
343
366
  for line in lines:
344
367
  print(f" - {line}", file=out)
345
368
 
369
+ # 指纹校验放在最前:设了 expect_token 就必须匹配,--yes 也绕不过。
370
+ # 这样"确认码"与"影响面提示"是同一处代码,不会出现某个入口忘了校验。
371
+ if expect_token:
372
+ require_token(action, token, expect_token, hint=hint)
373
+
346
374
  if assume_yes:
347
375
  print(f"[{action}] 已通过 --yes 确认。", file=out)
348
376
  if hint:
@@ -339,6 +339,13 @@ def guarded_write(reason: str, writer, names=None, allow_shrink=()) -> dict:
339
339
  report["error"] = f"写入异常已回滚:{err}"
340
340
  except Exception as rexc: # noqa: BLE001
341
341
  report["error"] = f"写入异常且回滚失败:{err} / {rexc}"
342
+ # 最危险的一档:写入出了问题、回滚也没成功 ⇒ 数据处于脏状态,
343
+ # 却只体现在返回值里。计一次数,让 doctor 的 swallowed 项能看见。
344
+ try:
345
+ import core as _c
346
+ _c.swallow("safety.rollback", rexc, where="safety_net.guarded_write")
347
+ except Exception: # noqa: BLE001
348
+ pass
342
349
  return report
343
350
  if _verify_enabled():
344
351
  v = verify(names, allow_shrink=allow_shrink)
@@ -352,4 +359,9 @@ def guarded_write(reason: str, writer, names=None, allow_shrink=()) -> dict:
352
359
  report["ok"] = True # 已回滚,数据一致
353
360
  except Exception as rexc: # noqa: BLE001
354
361
  report["issues"].append(f"回滚失败:{rexc}")
362
+ try:
363
+ import core as _c
364
+ _c.swallow("safety.rollback", rexc, where="safety_net.guarded_write")
365
+ except Exception: # noqa: BLE001
366
+ pass
355
367
  return report
@@ -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())
@@ -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 main(argv: list[str] | None = None) -> int:
132
- ap = argparse.ArgumentParser(description="灵枢:engine 副本同步与校验")
133
- ap.add_argument("--check", action="store_true", help="只校验一致性,不写文件")
134
- args = ap.parse_args(argv)
135
- return check() if args.check else sync()
136
-
137
-
138
- if __name__ == "__main__":
139
- sys.exit(main())
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
- ```