lingshu-skill 5.32.0 → 5.37.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 (265) hide show
  1. package/CHANGELOG.md +4281 -4173
  2. package/README.md +1584 -1577
  3. package/SKILL-lite.md +59 -59
  4. package/SKILL-tiny.md +38 -38
  5. package/SKILL.md +356 -317
  6. package/assets/panel.html +6753 -5698
  7. package/cordis-plugin/lingshu-cron/plugin.js +1455 -1417
  8. package/cordis-plugin/lingshu-startup/context-fold.js +170 -0
  9. package/cordis-plugin/lingshu-startup/context-pressure.js +16 -0
  10. package/cordis-plugin/lingshu-startup/context-snapshot.js +176 -0
  11. package/cordis-plugin/lingshu-startup/plugin.js +499 -467
  12. package/docs/audit_notes//345/276/205/345/212/236-20261201-/351/235/242/346/235/277/344/270/245/346/237/245/344/270/216/345/256/241/350/256/241.md +162 -0
  13. package/docs/audit_notes//345/276/205/345/212/236-20261202-/351/235/242/346/235/277/344/272/244/344/272/222/344/270/216/346/225/260/346/215/256/345/245/221/347/272/246/345/256/241/350/256/241.md +92 -0
  14. package/docs/audit_notes//345/276/205/345/212/236/346/250/241/346/235/277.md +140 -0
  15. package/docs/commands.md +278 -247
  16. package/docs/mechanics.md +610 -610
  17. package/docs//345/276/205/345/212/236-20261201-/351/235/242/346/235/277/344/270/245/346/237/245/344/270/216/345/256/241/350/256/241.md +162 -0
  18. package/docs//345/276/205/345/212/236-20261202-/351/235/242/346/235/277/344/272/244/344/272/222/344/270/216/346/225/260/346/215/256/345/245/221/347/272/246/345/256/241/350/256/241.md +92 -0
  19. package/package.json +52 -52
  20. package/scripts/_scratch/_tmp_backup_race.py +70 -0
  21. package/scripts/_scratch/_tmp_cleanup_move.py +34 -0
  22. package/scripts/_scratch/_tmp_count_kinds.py +25 -0
  23. package/scripts/_scratch/_tmp_diag_paths.py +48 -0
  24. package/scripts/_scratch/_tmp_facts.py +63 -0
  25. package/scripts/_scratch/_tmp_find_copies.py +31 -0
  26. package/scripts/_scratch/_tmp_find_pin.py +29 -0
  27. package/scripts/_scratch/_tmp_fix_pin.py +36 -0
  28. package/scripts/_scratch/_tmp_fold_fixture.py +55 -0
  29. package/scripts/_scratch/_tmp_fold_test.mjs +81 -0
  30. package/scripts/_scratch/_tmp_inject_secs.py +30 -0
  31. package/scripts/_scratch/_tmp_kb_balance.py +159 -0
  32. package/scripts/_scratch/_tmp_lines.py +15 -0
  33. package/scripts/_scratch/_tmp_market_probe.py +13 -0
  34. package/scripts/_scratch/_tmp_move_partial.py +16 -0
  35. package/scripts/_scratch/_tmp_patch_b3.py +41 -0
  36. package/scripts/_scratch/_tmp_patch_b5.py +62 -0
  37. package/scripts/_scratch/_tmp_patch_crash_excl.py +24 -0
  38. package/scripts/_scratch/_tmp_patch_handoff.py +21 -0
  39. package/scripts/_scratch/_tmp_patch_ps1.py +25 -0
  40. package/scripts/_scratch/_tmp_patch_stat.py +27 -0
  41. package/scripts/_scratch/_tmp_patch_todo.py +25 -0
  42. package/scripts/_scratch/_tmp_patch_todo2.py +64 -0
  43. package/scripts/_scratch/_tmp_probe_session.py +51 -0
  44. package/scripts/_scratch/_tmp_style_probe.py +40 -0
  45. package/scripts/_scratch/_tmp_write_note.py +139 -0
  46. package/scripts/_scratch/_/346/235/245/346/272/220/350/256/260/345/275/225.txt +1 -0
  47. package/scripts/_scratch/asar_compaction/dsh-compaction-basic__lib__index.js +1044 -0
  48. package/scripts/_scratch/asar_compaction/dsh-compaction-tool-result-pruner__lib__index.js +194 -0
  49. package/scripts/_scratch/asar_compaction/dsh-compaction__lib__index.js +175 -0
  50. package/scripts/_scratch/asar_compaction/dsh-compaction__lib__types__tool-pairing.js +97 -0
  51. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__image-offload.js +47 -0
  52. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__index.js +40 -0
  53. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__project-message.js +37 -0
  54. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__brand.js +9 -0
  55. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__checkpoint.js +36 -0
  56. package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__types.js +10 -0
  57. package/scripts/_scratch/commit_msg_occ.txt +16 -0
  58. package/scripts/_scratch/commit_msg_struct.txt +16 -0
  59. package/scripts/_scratch/v5.34_changelog.txt +36 -0
  60. package/scripts/_sync_trae_cn.py +102 -34
  61. package/scripts/_tmp_add_s10.py +54 -0
  62. package/scripts/_tmp_add_s11.py +61 -0
  63. package/scripts/_tmp_add_s12.py +66 -0
  64. package/scripts/_tmp_add_s13.py +69 -0
  65. package/scripts/_tmp_add_s14.py +80 -0
  66. package/scripts/_tmp_add_s9.py +68 -0
  67. package/scripts/_tmp_cache_load.py +82 -0
  68. package/scripts/_tmp_clean_market.py +40 -0
  69. package/scripts/_tmp_clean_pruned.py +81 -0
  70. package/scripts/_tmp_cleanup_docs.py +39 -0
  71. package/scripts/_tmp_cmp_ranker.py +17 -0
  72. package/scripts/_tmp_dolater_note.py +35 -0
  73. package/scripts/_tmp_dust_why.py +27 -0
  74. package/scripts/_tmp_explicit_import.py +40 -0
  75. package/scripts/_tmp_extract_compaction.py +35 -0
  76. package/scripts/_tmp_extract_compaction2.py +63 -0
  77. package/scripts/_tmp_extract_compaction3.py +51 -0
  78. package/scripts/_tmp_extract_compaction4.py +54 -0
  79. package/scripts/_tmp_finalize_s14.py +39 -0
  80. package/scripts/_tmp_find_compaction.py +43 -0
  81. package/scripts/_tmp_fix_b4.py +22 -0
  82. package/scripts/_tmp_fix_cli76.py +26 -0
  83. package/scripts/_tmp_fix_docs.py +38 -0
  84. package/scripts/_tmp_fix_docs_b.py +46 -0
  85. package/scripts/_tmp_fix_docs_b2.py +22 -0
  86. package/scripts/_tmp_fix_i3.py +23 -0
  87. package/scripts/_tmp_fix_s10.py +83 -0
  88. package/scripts/_tmp_fix_s11.py +14 -0
  89. package/scripts/_tmp_fix_s9_status.py +19 -0
  90. package/scripts/_tmp_fix_shadow_sim.py +37 -0
  91. package/scripts/_tmp_fix_traits_value.py +41 -0
  92. package/scripts/_tmp_import_idem.py +106 -0
  93. package/scripts/_tmp_log_ack.py +45 -0
  94. package/scripts/_tmp_mark_batch.py +28 -0
  95. package/scripts/_tmp_mark_batch2.py +32 -0
  96. package/scripts/_tmp_mark_dolater.py +26 -0
  97. package/scripts/_tmp_mark_dolater2.py +31 -0
  98. package/scripts/_tmp_move_self.py +16 -0
  99. package/scripts/_tmp_occ_cli.py +22 -0
  100. package/scripts/_tmp_occ_link.py +108 -0
  101. package/scripts/_tmp_optimize_recall.py +54 -0
  102. package/scripts/_tmp_panel_audit.py +26 -0
  103. package/scripts/_tmp_patch_batch3.py +65 -0
  104. package/scripts/_tmp_patch_rrf.py +46 -0
  105. package/scripts/_tmp_patch_s2s3.py +80 -0
  106. package/scripts/_tmp_patch_s4.py +39 -0
  107. package/scripts/_tmp_patch_s7.py +43 -0
  108. package/scripts/_tmp_patch_s8.py +91 -0
  109. package/scripts/_tmp_patch_skill.py +17 -0
  110. package/scripts/_tmp_release_guard.py +57 -0
  111. package/scripts/_tmp_rerank_breaker.py +62 -0
  112. package/scripts/_tmp_s16.py +41 -0
  113. package/scripts/_tmp_scan_asar.py +41 -0
  114. package/scripts/_tmp_scan_asar2.py +37 -0
  115. package/scripts/_tmp_struct_docs.py +49 -0
  116. package/scripts/_tmp_sum_fallback.py +42 -0
  117. package/scripts/_tmp_sweep.py +81 -0
  118. package/scripts/_tmp_sync_check.py +69 -0
  119. package/scripts/_tmp_sync_tail.py +39 -0
  120. package/scripts/_tmp_todo_clean.py +67 -0
  121. package/scripts/_tmp_verify_copy.py +17 -0
  122. package/scripts/_tmp_wire_extras.py +93 -0
  123. package/scripts/_tmp_wire_hsum.py +34 -0
  124. package/scripts/_tmp_wire_occ_b5.py +40 -0
  125. package/scripts/_tmp_wire_ranker.py +13 -0
  126. package/scripts/_tmp_wire_shadow_timeline.py +45 -0
  127. package/scripts/anchor_retention.py +68 -0
  128. package/scripts/app_context.py +1160 -0
  129. package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +38 -22
  130. package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +4281 -4173
  131. package/scripts/astrbot_plugin_lingshu/engine/README.md +1584 -1577
  132. package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +59 -59
  133. package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +38 -38
  134. package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +356 -317
  135. package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +6753 -5698
  136. package/scripts/astrbot_plugin_lingshu/engine/docs/commands.md +278 -247
  137. package/scripts/astrbot_plugin_lingshu/engine/docs/mechanics.md +610 -610
  138. package/scripts/astrbot_plugin_lingshu/engine/scripts/_sync_trae_cn.py +102 -34
  139. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s10.py +54 -0
  140. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s11.py +61 -0
  141. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s12.py +66 -0
  142. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s13.py +69 -0
  143. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s14.py +80 -0
  144. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s9.py +68 -0
  145. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cache_load.py +82 -0
  146. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_market.py +40 -0
  147. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_pruned.py +81 -0
  148. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cleanup_docs.py +39 -0
  149. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cmp_ranker.py +17 -0
  150. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dolater_note.py +35 -0
  151. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dust_why.py +27 -0
  152. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_explicit_import.py +40 -0
  153. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction.py +35 -0
  154. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction2.py +63 -0
  155. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction3.py +51 -0
  156. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction4.py +54 -0
  157. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_finalize_s14.py +39 -0
  158. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_find_compaction.py +43 -0
  159. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_b4.py +22 -0
  160. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_cli76.py +26 -0
  161. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs.py +38 -0
  162. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b.py +46 -0
  163. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b2.py +22 -0
  164. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_i3.py +23 -0
  165. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s10.py +83 -0
  166. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s11.py +14 -0
  167. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s9_status.py +19 -0
  168. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_shadow_sim.py +37 -0
  169. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_traits_value.py +41 -0
  170. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_import_idem.py +106 -0
  171. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_log_ack.py +45 -0
  172. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch.py +28 -0
  173. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch2.py +32 -0
  174. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater.py +26 -0
  175. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater2.py +31 -0
  176. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_move_self.py +16 -0
  177. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_cli.py +22 -0
  178. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_link.py +108 -0
  179. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_optimize_recall.py +54 -0
  180. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_panel_audit.py +26 -0
  181. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_batch3.py +65 -0
  182. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_rrf.py +46 -0
  183. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s2s3.py +80 -0
  184. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s4.py +39 -0
  185. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s7.py +43 -0
  186. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s8.py +91 -0
  187. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_skill.py +17 -0
  188. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_release_guard.py +57 -0
  189. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_rerank_breaker.py +62 -0
  190. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_s16.py +41 -0
  191. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar.py +41 -0
  192. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar2.py +37 -0
  193. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_struct_docs.py +49 -0
  194. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sum_fallback.py +42 -0
  195. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sweep.py +81 -0
  196. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_check.py +69 -0
  197. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_tail.py +39 -0
  198. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_todo_clean.py +67 -0
  199. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_verify_copy.py +17 -0
  200. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_extras.py +93 -0
  201. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_hsum.py +34 -0
  202. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_occ_b5.py +40 -0
  203. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_ranker.py +13 -0
  204. package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_shadow_timeline.py +45 -0
  205. package/scripts/astrbot_plugin_lingshu/engine/scripts/anchor_retention.py +68 -0
  206. package/scripts/astrbot_plugin_lingshu/engine/scripts/app_context.py +1160 -0
  207. package/scripts/astrbot_plugin_lingshu/engine/scripts/bigfive.py +90 -0
  208. package/scripts/astrbot_plugin_lingshu/engine/scripts/brain.py +1 -1
  209. package/scripts/astrbot_plugin_lingshu/engine/scripts/check_docs.py +191 -0
  210. package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +940 -88
  211. package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +2468 -2406
  212. package/scripts/astrbot_plugin_lingshu/engine/scripts/coverage_report.py +5 -0
  213. package/scripts/astrbot_plugin_lingshu/engine/scripts/delivery.py +112 -0
  214. package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +41 -3
  215. package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +202 -23
  216. package/scripts/astrbot_plugin_lingshu/engine/scripts/gap_memory.py +186 -0
  217. package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +72 -8
  218. package/scripts/astrbot_plugin_lingshu/engine/scripts/hsum.py +206 -0
  219. package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_score.py +92 -7
  220. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +533 -60
  221. package/scripts/astrbot_plugin_lingshu/engine/scripts/memory_extras.py +200 -0
  222. package/scripts/astrbot_plugin_lingshu/engine/scripts/occ.py +190 -0
  223. package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +232 -142
  224. package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +2498 -2349
  225. package/scripts/astrbot_plugin_lingshu/engine/scripts/prepublish_tests.py +90 -0
  226. package/scripts/astrbot_plugin_lingshu/engine/scripts/release.py +326 -287
  227. package/scripts/astrbot_plugin_lingshu/engine/scripts/rss_ingest.py +181 -0
  228. package/scripts/astrbot_plugin_lingshu/engine/scripts/session_import.py +832 -764
  229. package/scripts/astrbot_plugin_lingshu/engine/scripts/shadow_memory.py +173 -0
  230. package/scripts/astrbot_plugin_lingshu/engine/scripts/style_check.py +220 -0
  231. package/scripts/astrbot_plugin_lingshu/engine/scripts/summarizer.py +343 -252
  232. package/scripts/astrbot_plugin_lingshu/engine/scripts/timeline.py +118 -0
  233. package/scripts/astrbot_plugin_lingshu/engine/scripts/watchdog.py +110 -0
  234. package/scripts/astrbot_plugin_lingshu/engine/scripts/web_research.py +125 -0
  235. package/scripts/bigfive.py +90 -0
  236. package/scripts/brain.py +1 -1
  237. package/scripts/check_docs.py +191 -0
  238. package/scripts/cli.py +940 -88
  239. package/scripts/core.py +2468 -2406
  240. package/scripts/coverage_report.py +5 -0
  241. package/scripts/delivery.py +112 -0
  242. package/scripts/dream.py +41 -3
  243. package/scripts/emotion.py +202 -23
  244. package/scripts/gap_memory.py +186 -0
  245. package/scripts/growth.py +72 -8
  246. package/scripts/hsum.py +206 -0
  247. package/scripts/mem_score.py +92 -7
  248. package/scripts/memory.py +533 -60
  249. package/scripts/memory_extras.py +200 -0
  250. package/scripts/occ.py +190 -0
  251. package/scripts/panel_server.py +232 -142
  252. package/scripts/persona.py +2498 -2349
  253. package/scripts/prepublish_tests.py +90 -0
  254. package/scripts/release.py +326 -287
  255. package/scripts/rss_ingest.py +181 -0
  256. package/scripts/run_tests.py +13 -0
  257. package/scripts/session_import.py +832 -764
  258. package/scripts/shadow_memory.py +173 -0
  259. package/scripts/style_check.py +220 -0
  260. package/scripts/summarizer.py +343 -252
  261. package/scripts/timeline.py +118 -0
  262. package/scripts/update_dsh_copy.ps1 +110 -107
  263. package/scripts/watchdog.py +110 -0
  264. package/scripts/web_research.py +125 -0
  265. package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +0 -370
@@ -1,287 +1,326 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """灵枢发版自动化(把台账第四节的发布流程串成一条命令)。
4
-
5
- 子命令
6
- ------
7
- python scripts/release.py bump <X.Y> ["小节标题"]
8
- 1) 校验新版本 > 当前版本;
9
- 2) 改四处版本:SKILL.md / package.json(X.Y.0) / README.md / CHANGELOG 首节占位;
10
- 3) 按依赖序重生成:sync_engine → make_checksums → make_manifest;
11
- 4) 跑六项检查 + 行为基线 + 全量测试,全绿才成功。
12
- 不做 git 提交/tag/push(用户明确不做 tag/push,提交仍按"一个版本一个提交"手工或另配)。
13
- 注意:若有新代码文件(如本脚本自己)尚未 git add,manifest --check 会拒绝——
14
- 这是既有门禁,先 git add 新文件再 bump,脚本不替你决定哪些文件入库。
15
-
16
- python scripts/release.py publish
17
- 1) 校验版本四处一致(check_version)+ 六项检查全绿;
18
- 2) npm whoami 确认登录;
19
- 3) 确认包版本比线上大(避免 E409 重复发);
20
- 4) npm publish;
21
- 5) 轮询 registry 直到 latest==本地版本(npm staged 窗口最多 ~17 分钟)。
22
- 不构建 tgz、不打 tag、不推 git。
23
-
24
- python scripts/release.py status
25
- 打印当前版本 / 线上 latest / 是否可发。
26
- """
27
- from __future__ import annotations
28
-
29
- import argparse
30
- import json
31
- import re
32
- import shutil
33
- import subprocess
34
- import sys
35
- import time
36
- import urllib.request
37
- from pathlib import Path
38
-
39
- ROOT = Path(__file__).resolve().parent.parent
40
- PY = sys.executable
41
- REGISTRY = "https://registry.npmjs.org"
42
- PKG_NAME = "lingshu-skill"
43
-
44
- CHECKS = [
45
- ("manifest", ["scripts/make_manifest.py", "--check"]),
46
- ("sync", ["scripts/sync_engine.py", "--check"]),
47
- ("panel", ["scripts/panel_build.py", "--check"]),
48
- ("checksums", ["scripts/astrbot_plugin_lingshu/make_checksums.py", "--check"]),
49
- ("version", ["scripts/check_version.py"]),
50
- ("pressure", ["scripts/check_pressure_sync.py"]),
51
- ]
52
- GENERATE = [
53
- ["scripts/sync_engine.py"],
54
- ["scripts/astrbot_plugin_lingshu/make_checksums.py"],
55
- ["scripts/make_manifest.py"],
56
- ]
57
-
58
-
59
- def _run(args: list, *, capture: bool = False) -> tuple[int, str]:
60
- cmd = [PY] + args
61
- r = subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True,
62
- encoding="utf-8", errors="replace")
63
- out = (r.stdout + r.stderr) if capture else ""
64
- if not capture:
65
- # 直接透传,用户能看见进度
66
- print(r.stdout, end="")
67
- if r.stderr:
68
- print(r.stderr, end="", file=sys.stderr)
69
- return r.returncode, out
70
-
71
-
72
- def cur_version() -> str:
73
- t = (ROOT / "SKILL.md").read_text(encoding="utf-8-sig")
74
- m = re.search(r"^version:\s*([\d.]+)", t, re.M)
75
- return m.group(1) if m else ""
76
-
77
-
78
- def _ver_tuple(v: str) -> tuple:
79
- return tuple(int(x) for x in re.findall(r"\d+", v))
80
-
81
-
82
- def registry_latest(timeout: int = 15) -> str | None:
83
- try:
84
- with urllib.request.urlopen(f"{REGISTRY}/{PKG_NAME}", timeout=timeout) as r:
85
- d = json.load(r)
86
- return str(d.get("dist-tags", {}).get("latest", "")) or None
87
- except Exception:
88
- return None
89
-
90
-
91
- def do_bump(new_ver: str, title: str) -> int:
92
- new_ver = new_ver.strip().lstrip("v")
93
- if not re.fullmatch(r"\d+\.\d+", new_ver):
94
- print(f"[release] 版本格式应为 X.Y,收到 {new_ver!r}", file=sys.stderr)
95
- return 1
96
- # semver 不允许前导零:npm 会把 4.01.0 规范化成 4.1.0 发布出去,
97
- # 而本地 package.json 仍写 4.01.0,publish 轮询 registry 就永远等不到
98
- # 4.01.0(v4.01 就这么卡死过一次)。在这里挡掉。
99
- _bad = [seg for seg in new_ver.split(".")
100
- if len(seg) > 1 and seg.startswith("0") and seg.isdigit()]
101
- if _bad:
102
- fixed = ".".join(str(int(s)) if s.isdigit() else s for s in new_ver.split("."))
103
- print(f"[release] 版本号 {new_ver} 含前导零段 {_bad}(semver 不允许),"
104
- f"请改用 {fixed}", file=sys.stderr)
105
- return 1
106
- old = cur_version()
107
- if _ver_tuple(new_ver) <= _ver_tuple(old):
108
- print(f"[release] 新版本 {new_ver} 必须大于当前 {old}", file=sys.stderr)
109
- return 1
110
-
111
- # 1) 改四处版本(bytes,保 BOM/换行原样)
112
- edits = [
113
- ("SKILL.md", f"version: {old}".encode(), f"version: {new_ver}".encode()),
114
- ("package.json", f'"version": "{old}.0"'.encode(), f'"version": "{new_ver}.0"'.encode()),
115
- ("README.md", f"**v{old}**".encode(), f"**v{new_ver}**".encode()),
116
- ]
117
- for rel, o, n in edits:
118
- p = ROOT / rel
119
- b = p.read_bytes()
120
- if o not in b:
121
- print(f"[release] {rel} 没找到版本标记 {o!r},拒绝继续", file=sys.stderr)
122
- return 1
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
-
138
- # CHANGELOG 首节改写为新版本(占位,正文留空由维护者补)
139
- cl = ROOT / "CHANGELOG.md"
140
- t = cl.read_text(encoding="utf-8")
141
- first = re.search(r"^## v[\d.]+([^)]*)", t, re.M)
142
- if not first:
143
- print("[release] CHANGELOG.md 找不到首节标题,拒绝继续", file=sys.stderr)
144
- return 1
145
- today = time.strftime("%Y-%m-%d")
146
- t = t[:first.start()] + f"## v{new_ver}({today})" + t[first.end():]
147
- cl.write_text(t, encoding="utf-8", newline="")
148
-
149
- # 2) 重生成派生文件
150
- print(f"[release] 版本 {old} → {new_ver};重生成派生文件...")
151
- for gen in GENERATE:
152
- code, _ = _run(gen)
153
- if code != 0:
154
- print(f"[release] 生成失败:{gen}", file=sys.stderr)
155
- return 1
156
-
157
- # 3) 验证
158
- return do_verify()
159
-
160
-
161
- def do_verify() -> int:
162
- bad = []
163
- for name, args in CHECKS:
164
- code, out = _run(args, capture=True)
165
- print(f" {name}: {'OK' if code == 0 else 'FAIL'}")
166
- if code != 0:
167
- bad.append(name)
168
- tail = (out or "").strip().splitlines()[-3:]
169
- for ln in tail:
170
- print(f" {ln}", file=sys.stderr)
171
- print("[release] 行为基线...")
172
- code, _ = _run(["scripts/behavior_baseline.py", "check"])
173
- print(f" baseline: {'OK' if code == 0 else 'FAIL'}")
174
- if code != 0:
175
- bad.append("baseline")
176
- print("[release] 全量测试...")
177
- code, out = _run(["scripts/run_tests.py"], capture=True)
178
- print(out.rstrip()[-400:] if out else "") # 透出末尾统计行
179
- print(f" tests: {'OK' if code == 0 else 'FAIL'}")
180
- if code != 0:
181
- bad.append("tests")
182
- # 失败时必须点名:否则发版日志只说"tests: FAIL",事后无法定位
183
- fails = [ln.strip() for ln in out.splitlines() if ln.strip().startswith("FAIL ")]
184
- for ln in fails[:10]:
185
- print(f" {ln}", file=sys.stderr)
186
- if bad:
187
- print(f"[release] 验证失败:{', '.join(bad)}", file=sys.stderr)
188
- return 1
189
- print("[release] 全部验证通过 ✔")
190
- return 0
191
-
192
-
193
- def do_publish(wait_minutes: int) -> int:
194
- # npm 版本是 X.Y.0(package.json),registry 的 latest 也是 X.Y.0——
195
- # 必须用这个格式比较;用 SKILL.md 的 X.Y 会永远匹配不上 staged 轮询目标。
196
- ver = json.loads((ROOT / "package.json").read_text(encoding="utf-8-sig"))["version"]
197
- if do_verify() != 0:
198
- return 1
199
- npm = shutil.which("npm") or shutil.which("npm.cmd")
200
- if not npm:
201
- print("[release] 找不到 npm 命令", file=sys.stderr)
202
- return 1
203
- who = subprocess.run([npm, "whoami"], cwd=ROOT, capture_output=True, text=True,
204
- encoding="utf-8", errors="replace").stdout.strip()
205
- if not who:
206
- print("[release] npm 未登录(npm whoami 无输出)", file=sys.stderr)
207
- return 1
208
- online = registry_latest()
209
- if online and _ver_tuple(online) >= _ver_tuple(ver):
210
- print(f"[release] 线上 latest={online} >= 本地 {ver},无需重复发布", file=sys.stderr)
211
- return 1
212
- print(f"[release] npm 发布 {PKG_NAME}@{ver}(登录用户 {who};线上 {online or '无'})...")
213
- r = subprocess.run([npm, "publish"], cwd=ROOT)
214
- if r.returncode != 0:
215
- print("[release] npm publish 失败", file=sys.stderr)
216
- return 1
217
- # staged 窗口轮询
218
- deadline = time.time() + wait_minutes * 60
219
- while time.time() < deadline:
220
- latest = registry_latest()
221
- if latest == ver:
222
- print(f"[release] 已可见:{PKG_NAME}@{latest}(latest)✔")
223
- return 0
224
- print(f" staged 窗口:latest={latest},等待可见(目标 {ver})...")
225
- time.sleep(20)
226
- print(f"[release] 超时({wait_minutes} 分钟)仍不可见,请手动查 registry", file=sys.stderr)
227
- return 1
228
-
229
-
230
- def do_status() -> int:
231
- ver = cur_version()
232
- online = registry_latest()
233
- pkg = json.loads((ROOT / "package.json").read_text(encoding="utf-8-sig"))["version"]
234
- print(f" 本地 SKILL: {ver} package.json: {pkg}")
235
- print(f" 线上 latest: {online or '查询失败'}")
236
- if online:
237
- print(" 可发布:" , "是" if _ver_tuple(ver) > _ver_tuple(online) else "否(线上已 >= 本地)")
238
- return 0
239
-
240
-
241
- def main() -> int:
242
- ap = argparse.ArgumentParser(description="灵枢发版自动化")
243
- sub = ap.add_subparsers(dest="action", required=True)
244
- p_bump = sub.add_parser("bump", help="升版本+重生成+验证")
245
- p_bump.add_argument("version", help="新版本 X.Y")
246
- p_bump.add_argument("title", nargs="?", default="", help="CHANGELOG 小节标题(可选)")
247
- p_pub = sub.add_parser("publish", help="校验后 npm publish 并等 staged 可见")
248
- p_pub.add_argument("--wait", type=int, default=20, help="staged 可见轮询最长分钟数(默认20)")
249
- sub.add_parser("status", help="查看本地/线上版本")
250
- args = ap.parse_args()
251
- if args.action == "bump":
252
- return do_bump(args.version, args.title)
253
- if args.action == "publish":
254
- return do_publish(getattr(args, "wait", 20))
255
- return do_status()
256
-
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
-
285
- if __name__ == "__main__":
286
- _ensure_utf8_stdout()
287
- sys.exit(main())
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """灵枢发版自动化(把台账第四节的发布流程串成一条命令)。
4
+
5
+ 子命令
6
+ ------
7
+ python scripts/release.py bump <X.Y> ["小节标题"]
8
+ 1) 校验新版本 > 当前版本;
9
+ 2) 改四处版本:SKILL.md / package.json(X.Y.0) / README.md / CHANGELOG 首节占位;
10
+ 3) 按依赖序重生成:sync_engine → make_checksums → make_manifest;
11
+ 4) 跑六项检查 + 行为基线 + 全量测试,全绿才成功。
12
+ 不做 git 提交/tag/push(用户明确不做 tag/push,提交仍按"一个版本一个提交"手工或另配)。
13
+ 注意:若有新代码文件(如本脚本自己)尚未 git add,manifest --check 会拒绝——
14
+ 这是既有门禁,先 git add 新文件再 bump,脚本不替你决定哪些文件入库。
15
+
16
+ python scripts/release.py publish
17
+ 1) 校验版本四处一致(check_version)+ 六项检查全绿;
18
+ 2) npm whoami 确认登录;
19
+ 3) 确认包版本比线上大(避免 E409 重复发);
20
+ 4) npm publish;
21
+ 5) 轮询 registry 直到 latest==本地版本(npm staged 窗口最多 ~17 分钟)。
22
+ 不构建 tgz、不打 tag、不推 git。
23
+
24
+ python scripts/release.py status
25
+ 打印当前版本 / 线上 latest / 是否可发。
26
+ """
27
+ from __future__ import annotations
28
+
29
+ import argparse
30
+ import json
31
+ import re
32
+ import shutil
33
+ import subprocess
34
+ import sys
35
+ import time
36
+ import urllib.request
37
+ from pathlib import Path
38
+
39
+ ROOT = Path(__file__).resolve().parent.parent
40
+ PY = sys.executable
41
+ REGISTRY = "https://registry.npmjs.org"
42
+ PKG_NAME = "lingshu-skill"
43
+
44
+ CHECKS = [
45
+ ("manifest", ["scripts/make_manifest.py", "--check"]),
46
+ ("sync", ["scripts/sync_engine.py", "--check"]),
47
+ ("panel", ["scripts/panel_build.py", "--check"]),
48
+ ("checksums", ["scripts/astrbot_plugin_lingshu/make_checksums.py", "--check"]),
49
+ ("version", ["scripts/check_version.py"]),
50
+ ("pressure", ["scripts/check_pressure_sync.py"]),
51
+ ]
52
+ GENERATE = [
53
+ ["scripts/sync_engine.py"],
54
+ ["scripts/astrbot_plugin_lingshu/make_checksums.py"],
55
+ ["scripts/make_manifest.py"],
56
+ ]
57
+
58
+
59
+ def _run(args: list, *, capture: bool = False) -> tuple[int, str]:
60
+ cmd = [PY] + args
61
+ r = subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True,
62
+ encoding="utf-8", errors="replace")
63
+ out = (r.stdout + r.stderr) if capture else ""
64
+ if not capture:
65
+ # 直接透传,用户能看见进度
66
+ print(r.stdout, end="")
67
+ if r.stderr:
68
+ print(r.stderr, end="", file=sys.stderr)
69
+ return r.returncode, out
70
+
71
+
72
+ def cur_version() -> str:
73
+ t = (ROOT / "SKILL.md").read_text(encoding="utf-8-sig")
74
+ m = re.search(r"^version:\s*([\d.]+)", t, re.M)
75
+ return m.group(1) if m else ""
76
+
77
+
78
+ def _ver_tuple(v: str) -> tuple:
79
+ return tuple(int(x) for x in re.findall(r"\d+", v))
80
+
81
+
82
+ def registry_latest(timeout: int = 15) -> str | None:
83
+ try:
84
+ with urllib.request.urlopen(f"{REGISTRY}/{PKG_NAME}", timeout=timeout) as r:
85
+ d = json.load(r)
86
+ return str(d.get("dist-tags", {}).get("latest", "")) or None
87
+ except Exception:
88
+ return None
89
+
90
+
91
+ def do_bump(new_ver: str, title: str) -> int:
92
+ new_ver = new_ver.strip().lstrip("v")
93
+ if not re.fullmatch(r"\d+\.\d+", new_ver):
94
+ print(f"[release] 版本格式应为 X.Y,收到 {new_ver!r}", file=sys.stderr)
95
+ return 1
96
+ # semver 不允许前导零:npm 会把 4.01.0 规范化成 4.1.0 发布出去,
97
+ # 而本地 package.json 仍写 4.01.0,publish 轮询 registry 就永远等不到
98
+ # 4.01.0(v4.01 就这么卡死过一次)。在这里挡掉。
99
+ _bad = [seg for seg in new_ver.split(".")
100
+ if len(seg) > 1 and seg.startswith("0") and seg.isdigit()]
101
+ if _bad:
102
+ fixed = ".".join(str(int(s)) if s.isdigit() else s for s in new_ver.split("."))
103
+ print(f"[release] 版本号 {new_ver} 含前导零段 {_bad}(semver 不允许),"
104
+ f"请改用 {fixed}", file=sys.stderr)
105
+ return 1
106
+ old = cur_version()
107
+ if _ver_tuple(new_ver) <= _ver_tuple(old):
108
+ print(f"[release] 新版本 {new_ver} 必须大于当前 {old}", file=sys.stderr)
109
+ return 1
110
+
111
+ # 1) 改四处版本(bytes,保 BOM/换行原样)
112
+ edits = [
113
+ ("SKILL.md", f"version: {old}".encode(), f"version: {new_ver}".encode()),
114
+ ("package.json", f'"version": "{old}.0"'.encode(), f'"version": "{new_ver}.0"'.encode()),
115
+ ("README.md", f"**v{old}**".encode(), f"**v{new_ver}**".encode()),
116
+ ]
117
+ for rel, o, n in edits:
118
+ p = ROOT / rel
119
+ b = p.read_bytes()
120
+ if o not in b:
121
+ print(f"[release] {rel} 没找到版本标记 {o!r},拒绝继续", file=sys.stderr)
122
+ return 1
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
+
138
+ # CHANGELOG 首节改写为新版本(占位,正文留空由维护者补)
139
+ cl = ROOT / "CHANGELOG.md"
140
+ t = cl.read_text(encoding="utf-8")
141
+ first = re.search(r"^## v[\d.]+([^)]*)", t, re.M)
142
+ if not first:
143
+ print("[release] CHANGELOG.md 找不到首节标题,拒绝继续", file=sys.stderr)
144
+ return 1
145
+ today = time.strftime("%Y-%m-%d")
146
+ t = t[:first.start()] + f"## v{new_ver}({today})" + t[first.end():]
147
+ cl.write_text(t, encoding="utf-8", newline="")
148
+
149
+ # 2) 重生成派生文件
150
+ print(f"[release] 版本 {old} → {new_ver};重生成派生文件...")
151
+ for gen in GENERATE:
152
+ code, _ = _run(gen)
153
+ if code != 0:
154
+ print(f"[release] 生成失败:{gen}", file=sys.stderr)
155
+ return 1
156
+
157
+ # 3) 验证
158
+ return do_verify()
159
+
160
+
161
+ def do_verify() -> int:
162
+ bad = []
163
+ for name, args in CHECKS:
164
+ code, out = _run(args, capture=True)
165
+ print(f" {name}: {'OK' if code == 0 else 'FAIL'}")
166
+ if code != 0:
167
+ bad.append(name)
168
+ tail = (out or "").strip().splitlines()[-3:]
169
+ for ln in tail:
170
+ print(f" {ln}", file=sys.stderr)
171
+ print("[release] 行为基线...")
172
+ code, _ = _run(["scripts/behavior_baseline.py", "check"])
173
+ print(f" baseline: {'OK' if code == 0 else 'FAIL'}")
174
+ if code != 0:
175
+ bad.append("baseline")
176
+ print("[release] 全量测试...")
177
+ code, out = _run(["scripts/run_tests.py"], capture=True)
178
+ print(out.rstrip()[-400:] if out else "") # 透出末尾统计行
179
+ print(f" tests: {'OK' if code == 0 else 'FAIL'}")
180
+ if code != 0:
181
+ bad.append("tests")
182
+ # 失败时必须点名:否则发版日志只说"tests: FAIL",事后无法定位
183
+ fails = [ln.strip() for ln in out.splitlines() if ln.strip().startswith("FAIL ")]
184
+ for ln in fails[:10]:
185
+ print(f" {ln}", file=sys.stderr)
186
+ if bad:
187
+ print(f"[release] 验证失败:{', '.join(bad)}", file=sys.stderr)
188
+ return 1
189
+ print("[release] 全部验证通过 ✔")
190
+ return 0
191
+
192
+
193
+ def _publish_preflight() -> int:
194
+ """发布前置守卫(§4 二-B 流程固化):发布物过期是最隐蔽的事故——
195
+ registry 上能看到新版本号,装下来却是旧代码。
196
+
197
+ 两道检查都是只读的(`--check` 不写文件):
198
+ 1. engine 副本(发布包里的派生脚本)
199
+ 2. 已安装副本(宿主实际加载的那份)
200
+ """
201
+ checks = (("scripts/sync_engine.py", "engine 副本"),
202
+ ("scripts/_sync_trae_cn.py", "已安装副本"))
203
+ for script, label in checks:
204
+ try:
205
+ rc, _ = _run([script, "--check"])
206
+ except Exception as exc: # noqa: BLE001
207
+ print(f"[release] 守卫执行失败({label}):{exc}", file=sys.stderr)
208
+ return 1
209
+ if rc != 0:
210
+ print(f"[release] 发布中止:{label}与源码不一致(差异见上)。"
211
+ "先跑对应同步脚本,再发布。", file=sys.stderr)
212
+ return 1
213
+ print("[release] 前置守卫通过:engine 副本与已安装副本都与源码一致")
214
+ return 0
215
+
216
+
217
+ def do_publish(wait_minutes: int) -> int:
218
+ # 发布前置守卫:副本过期就中止(只读检查,不写文件)
219
+ if _publish_preflight() != 0:
220
+ return 1
221
+ # npm 版本是 X.Y.0(package.json),registry 的 latest 也是 X.Y.0——
222
+ # 必须用这个格式比较;用 SKILL.md 的 X.Y 会永远匹配不上 staged 轮询目标。
223
+ ver = json.loads((ROOT / "package.json").read_text(encoding="utf-8-sig"))["version"]
224
+ if do_verify() != 0:
225
+ return 1
226
+ npm = shutil.which("npm") or shutil.which("npm.cmd")
227
+ if not npm:
228
+ print("[release] 找不到 npm 命令", file=sys.stderr)
229
+ return 1
230
+ who = subprocess.run([npm, "whoami"], cwd=ROOT, capture_output=True, text=True,
231
+ encoding="utf-8", errors="replace").stdout.strip()
232
+ if not who:
233
+ print("[release] npm 未登录(npm whoami 无输出)", file=sys.stderr)
234
+ return 1
235
+ online = registry_latest()
236
+ if online and _ver_tuple(online) >= _ver_tuple(ver):
237
+ print(f"[release] 线上 latest={online} >= 本地 {ver},无需重复发布", file=sys.stderr)
238
+ return 1
239
+ print(f"[release] npm 发布 {PKG_NAME}@{ver}(登录用户 {who};线上 {online or '无'})...")
240
+ r = subprocess.run([npm, "publish"], cwd=ROOT)
241
+ if r.returncode != 0:
242
+ print("[release] npm publish 失败", file=sys.stderr)
243
+ return 1
244
+ # staged 窗口轮询
245
+ deadline = time.time() + wait_minutes * 60
246
+ while time.time() < deadline:
247
+ latest = registry_latest()
248
+ if latest == ver:
249
+ print(f"[release] 已可见:{PKG_NAME}@{latest}(latest)✔")
250
+ return 0
251
+ print(f" staged 窗口:latest={latest},等待可见(目标 {ver})...")
252
+ time.sleep(20)
253
+ print(f"[release] 超时({wait_minutes} 分钟)仍不可见,请手动查 registry", file=sys.stderr)
254
+ return 1
255
+
256
+
257
+ def do_status() -> int:
258
+ ver = cur_version()
259
+ online = registry_latest()
260
+ pkg = json.loads((ROOT / "package.json").read_text(encoding="utf-8-sig"))["version"]
261
+ print(f" 本地 SKILL: {ver} package.json: {pkg}")
262
+ print(f" 线上 latest: {online or '查询失败'}")
263
+ if online:
264
+ print(" 可发布:" , "是" if _ver_tuple(ver) > _ver_tuple(online) else "否(线上已 >= 本地)")
265
+ return 0
266
+
267
+
268
+ def main() -> int:
269
+ ap = argparse.ArgumentParser(description="灵枢发版自动化")
270
+ sub = ap.add_subparsers(dest="action", required=True)
271
+ p_bump = sub.add_parser("bump", help="升版本+重生成+验证")
272
+ p_bump.add_argument("version", help="新版本 X.Y")
273
+ p_bump.add_argument("title", nargs="?", default="", help="CHANGELOG 小节标题(可选)")
274
+ p_pub = sub.add_parser("publish", help="校验后 npm publish 并等 staged 可见")
275
+ p_pub.add_argument("--wait", type=int, default=20, help="staged 可见轮询最长分钟数(默认20)")
276
+ # §4:bench --quick --check 接进发布流程(219s,只做可选深检,不默认跑)
277
+ p_pub.add_argument("--deep", action="store_true",
278
+ help="发布前额外跑 bench --quick --check(约 3-4 分钟的性能基线比对)")
279
+ sub.add_parser("status", help="查看本地/线上版本")
280
+ args = ap.parse_args()
281
+ if args.action == "bump":
282
+ return do_bump(args.version, args.title)
283
+ if args.action == "publish":
284
+ # §4:可选的性能深检(bench --quick --check 约 3-4 分钟),失败即中止发布。
285
+ # 不默认跑:219s 对每次发版太重,只在你想确认"没有性能回退"时加 --deep。
286
+ if getattr(args, "deep", False):
287
+ print("[release] --deep:先跑 bench --quick --check(性能基线比对)…")
288
+ rc, _ = _run(["scripts/bench.py", "--quick", "--check"])
289
+ if rc != 0:
290
+ print("[release] bench --quick --check 未通过,已中止发布", file=sys.stderr)
291
+ return 1
292
+ print("[release] 性能基线 OK")
293
+ return do_publish(getattr(args, "wait", 20))
294
+ return do_status()
295
+
296
+
297
+ def _ensure_utf8_stdout() -> None:
298
+ """把 stdout/stderr 切到 UTF-8,避免 Windows 控制台(cp1252/cp936)编不了中文就崩。
299
+
300
+ CI 的 windows-latest stdout 是 cp1252:脚本一 print 中文就 UnicodeEncodeError
301
+ 直接退出(实测 sync_engine.py / make_checksums.py 都因此挂过,Ubuntu 同期正常)。
302
+ 这不是业务 bug,是"中文输出 + 非 UTF-8 控制台"的必然结果。
303
+ """
304
+ for name in ("stdout", "stderr"):
305
+ stream = getattr(sys, name, None)
306
+ fn = getattr(stream, "reconfigure", None)
307
+ if callable(fn):
308
+ try:
309
+ fn(encoding="utf-8", errors="replace")
310
+ continue
311
+ except (OSError, ValueError, AttributeError):
312
+ pass
313
+ try:
314
+ import io
315
+ buf = getattr(stream, "buffer", None)
316
+ if buf is not None:
317
+ setattr(sys, name,
318
+ io.TextIOWrapper(buf, encoding="utf-8", errors="replace",
319
+ line_buffering=True))
320
+ except Exception: # noqa: BLE001
321
+ pass
322
+
323
+
324
+ if __name__ == "__main__":
325
+ _ensure_utf8_stdout()
326
+ sys.exit(main())