@hfyjq/crannia 1.1.2 → 1.2.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 (306) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +48 -45
  3. package/README.md +1 -1
  4. package/THIRD-PARTY-FRONTEND.md +5266 -5266
  5. package/THIRD-PARTY-PYTHON-linux.md +174 -0
  6. package/THIRD-PARTY-PYTHON.md +176 -162
  7. package/THIRD-PARTY.md +323 -316
  8. package/apps/desktop/quotes.txt +56 -56
  9. package/bus/core.py +677 -671
  10. package/bus/loaders/channel_loader.py +64 -64
  11. package/bus/loaders/provider_loader.py +4 -7
  12. package/bus/loaders/skill_loader.py +46 -27
  13. package/bus/loaders/skill_md.py +9 -9
  14. package/bus/mcp_disabled.py +4 -6
  15. package/bus/quarantine.py +10 -13
  16. package/bus/registry.py +2315 -2284
  17. package/bus/skill_state.py +124 -124
  18. package/channels/cli_channel/handler.py +3 -3
  19. package/channels/cli_channel/manifest.yaml +5 -5
  20. package/channels/dingtalk_channel/handler.py +32 -32
  21. package/channels/dingtalk_channel/manifest.yaml +12 -12
  22. package/channels/feishu_channel/handler.py +33 -33
  23. package/channels/feishu_channel/manifest.yaml +12 -12
  24. package/channels/qq_bot_channel/__init__.py +1 -1
  25. package/channels/qq_bot_channel/handler.py +24 -24
  26. package/channels/qq_bot_channel/manifest.yaml +4 -4
  27. package/channels/telegram_channel/__init__.py +1 -1
  28. package/channels/telegram_channel/handler.py +21 -21
  29. package/channels/telegram_channel/manifest.yaml +4 -4
  30. package/channels/telegram_channel/media.py +231 -231
  31. package/channels/textfmt.py +58 -58
  32. package/channels/wechat_channel/__init__.py +1 -1
  33. package/channels/wechat_channel/converter.py +1 -1
  34. package/channels/wechat_channel/handler.py +8 -8
  35. package/channels/wechat_channel/manifest.yaml +5 -5
  36. package/channels/wechat_channel/media.py +178 -178
  37. package/core/activity.py +753 -709
  38. package/core/agent_loop.py +7673 -7522
  39. package/core/allowlist.py +2 -3
  40. package/core/approval.py +34 -24
  41. package/core/approval_timeout.py +256 -228
  42. package/core/artifacts.py +3 -3
  43. package/core/attachment_gc.py +21 -0
  44. package/core/auto_review.py +2 -2
  45. package/core/browser/cdp.py +5 -2
  46. package/core/browser/discover.py +55 -19
  47. package/core/browser/session.py +4 -4
  48. package/core/cache_break_detector.py +97 -0
  49. package/core/cache_breakpoints.py +103 -0
  50. package/core/cache_policies.py +255 -0
  51. package/core/cancellation.py +3 -3
  52. package/core/channel_configs.py +3 -3
  53. package/core/channel_turns.py +13 -13
  54. package/core/child_approval.py +2 -3
  55. package/core/code_intel.py +11 -11
  56. package/core/command_policy.py +13 -7
  57. package/core/computer/annotate.py +231 -11
  58. package/core/computer/capture.py +140 -1
  59. package/core/computer/guard.py +7 -4
  60. package/core/computer/input.py +452 -26
  61. package/core/computer/session.py +563 -381
  62. package/core/computer/tools.py +2170 -928
  63. package/core/computer/uia.py +100 -1
  64. package/core/computer/watch.py +1 -1
  65. package/core/computer/win32.py +302 -7
  66. package/core/config_requirements.py +205 -205
  67. package/core/cron/runner.py +4 -4
  68. package/core/daily_log.py +2 -2
  69. package/core/dedup.py +2 -2
  70. package/core/egress_channels.py +326 -0
  71. package/core/egress_gate.py +96 -8
  72. package/core/egress_preapproved.py +59 -3
  73. package/core/endpoint.py +141 -141
  74. package/core/events.py +17 -8
  75. package/core/extension.py +2 -2
  76. package/core/file_history.py +10 -10
  77. package/core/file_tools.py +3 -3
  78. package/core/github_config.py +1 -1
  79. package/core/group_digest.py +3 -4
  80. package/core/group_minutes.py +5 -5
  81. package/core/group_reply.py +24 -0
  82. package/core/groups.py +5 -9
  83. package/core/hooks.py +15 -15
  84. package/core/i18n.py +2 -2
  85. package/core/ice/canary.py +3 -3
  86. package/core/ice/net_heuristics.py +2 -2
  87. package/core/im_routing.py +2 -2
  88. package/core/image_input.py +183 -43
  89. package/core/inbound.py +3 -3
  90. package/core/jobs.py +6 -6
  91. package/core/last_good.py +150 -150
  92. package/core/leaf_md.py +3 -3
  93. package/core/llm_errors.py +36 -27
  94. package/core/mail_config.py +2 -2
  95. package/core/memory/compressor.py +8 -8
  96. package/core/memory/manager.py +30 -45
  97. package/core/memory/session_memory.py +1 -2
  98. package/core/memory/short_term.py +4 -4
  99. package/core/memory_extract.py +1 -1
  100. package/core/memory_organize.py +8 -8
  101. package/core/memory_store.py +7 -9
  102. package/core/memory_transfer.py +2 -2
  103. package/core/model_capabilities.py +2 -2
  104. package/core/model_configs.py +219 -68
  105. package/core/model_profiles.py +333 -0
  106. package/core/modes.py +12 -11
  107. package/core/net_proxy.py +3 -3
  108. package/core/pipeline/scheduler.py +48 -43
  109. package/core/pipeline/stage.py +3 -0
  110. package/core/pipeline/stages/agent_loop.py +36 -15
  111. package/core/pipeline/stages/group_reply.py +22 -20
  112. package/core/pipeline/stages/post_process.py +7 -7
  113. package/core/pipeline/stages/pre_process.py +360 -68
  114. package/core/prompt_assembler.py +13 -4
  115. package/core/recycle.py +227 -16
  116. package/core/response_language.py +1 -1
  117. package/core/retention.py +2 -2
  118. package/core/rg.py +4 -3
  119. package/core/security.py +26 -8
  120. package/core/services.py +8 -8
  121. package/core/session_model.py +3 -5
  122. package/core/session_pool.py +35 -5
  123. package/core/session_recap.py +40 -3
  124. package/core/session_workspace.py +2 -3
  125. package/core/settings_baseline.py +2 -2
  126. package/core/settings_transfer.py +25 -1
  127. package/core/shell.py +52 -20
  128. package/core/side_call.py +3 -3
  129. package/core/skill_config.py +164 -0
  130. package/core/skill_factory.py +2 -2
  131. package/core/skill_guidance.py +2 -4
  132. package/core/skill_index.py +3 -4
  133. package/core/skill_settings.py +1 -1
  134. package/core/skill_sources.py +7 -7
  135. package/core/ssh_config.py +129 -0
  136. package/core/state_registry.py +67 -5
  137. package/core/subagent.py +28 -5
  138. package/core/subagent_defs.py +3 -3
  139. package/core/summarizer.py +4 -5
  140. package/core/tasks_notify.py +6 -6
  141. package/core/tiers.py +2 -2
  142. package/core/todos.py +1 -1
  143. package/core/token_calibrator.py +1 -4
  144. package/core/tool_outcome.py +108 -108
  145. package/core/touched_files.py +1 -1
  146. package/core/trace.py +12 -3
  147. package/core/unlock.py +4 -4
  148. package/core/update_tui.py +184 -158
  149. package/core/updater.py +5 -3
  150. package/core/version.py +14 -14
  151. package/core/vision_budget.py +235 -0
  152. package/core/web_cache.py +152 -152
  153. package/core/web_request.py +474 -0
  154. package/core/window_estimate.py +1 -1
  155. package/core/workspace.py +56 -26
  156. package/crannia_tray.py +278 -278
  157. package/licenses/GPL-3.0.txt +619 -619
  158. package/licenses/LGPL-2.1.txt +502 -502
  159. package/licenses/LGPL-3.0.txt +165 -165
  160. package/licenses/MIT-chat-on-wechat.txt +18 -18
  161. package/licenses/MIT-deepseek-harness.txt +21 -21
  162. package/licenses/Molio-LICENSE.txt +44 -44
  163. package/locales/en.json +1876 -1755
  164. package/main.py +154 -154
  165. package/mcpx/client.py +12 -1
  166. package/mcpx/manager.py +530 -522
  167. package/mcpx/servers/web_search.py +5 -13
  168. package/package.json +15 -23
  169. package/providers/anthropic/client.py +35 -33
  170. package/providers/base.py +13 -13
  171. package/providers/cache_policies.json +294 -0
  172. package/providers/cost_table.json +3779 -3779
  173. package/providers/lmstudio/client.py +2 -2
  174. package/providers/model_capabilities.json +6665 -6665
  175. package/providers/model_profiles.json +629 -0
  176. package/providers/ollama/client.py +2 -2
  177. package/providers/openai_compat.py +37 -16
  178. package/providers/openrouter/client.py +2 -2
  179. package/providers/qwen/__init__.py +1 -1
  180. package/providers/qwen/client.py +2 -2
  181. package/providers/qwen/manifest.yaml +16 -16
  182. package/providers/rate_limiter.py +2 -2
  183. package/providers/siliconflow/client.py +2 -2
  184. package/providers/validation.py +171 -171
  185. package/providers/vision_profiles.json +89 -0
  186. package/providers/window_table.json +8909 -8909
  187. package/requirements.txt +59 -51
  188. package/sbom-linux-x64.json +4580 -0
  189. package/sbom.json +4600 -4413
  190. package/skills/diagram/SKILL.md +47 -0
  191. package/skills/diagram/__init__.py +1 -0
  192. package/skills/diagram/handler.py +294 -0
  193. package/skills/diagram/layout.py +174 -0
  194. package/skills/diagram/manifest.yaml +106 -0
  195. package/skills/diagram/mermaid.py +170 -0
  196. package/skills/diagram/svg.py +223 -0
  197. package/skills/entertainment/SKILL.md +35 -35
  198. package/skills/entertainment/__init__.py +1 -1
  199. package/skills/entertainment/handler.py +91 -91
  200. package/skills/entertainment/manifest.yaml +26 -26
  201. package/skills/file_parser/GUIDANCE.md +10 -10
  202. package/skills/file_parser/handler.py +33 -11
  203. package/skills/github/SKILL.md +32 -32
  204. package/skills/github/__init__.py +1 -1
  205. package/skills/mail_parser/SKILL.md +68 -68
  206. package/skills/mail_parser/__init__.py +1 -1
  207. package/skills/mail_parser/handler.py +1 -1
  208. package/skills/media_gen/GUIDANCE.md +19 -19
  209. package/skills/media_gen/SKILL.md +43 -43
  210. package/skills/media_gen/__init__.py +1 -1
  211. package/skills/media_gen/handler.py +1 -1
  212. package/skills/media_gen/manifest.yaml +93 -93
  213. package/skills/netops/SKILL.md +45 -0
  214. package/skills/netops/__init__.py +1 -0
  215. package/skills/netops/handler.py +418 -0
  216. package/skills/netops/manifest.yaml +118 -0
  217. package/skills/office_parser/_excel_io.py +3 -3
  218. package/skills/office_parser/handler.py +2 -2
  219. package/skills/office_parser/ppt_tools.py +1 -1
  220. package/skills/office_parser/pptx_export/console_encoding.py +27 -27
  221. package/skills/office_parser/pptx_export/resource_paths.py +88 -88
  222. package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -12
  223. package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
  224. package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -288
  225. package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -388
  226. package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -818
  227. package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -345
  228. package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -14
  229. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -1
  230. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -186
  231. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -781
  232. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
  233. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/utils.py +40 -21
  234. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -1
  235. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -1267
  236. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -155
  237. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -101
  238. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -236
  239. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -257
  240. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -136
  241. package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -44
  242. package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -129
  243. package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +20 -20
  244. package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -21
  245. package/skills/office_parser/references/layout_library.md +816 -816
  246. package/skills/office_parser/references/ppt-master/LICENSE +21 -21
  247. package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -474
  248. package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -1002
  249. package/skills/office_parser/references/ppt-master/references/strategist.md +880 -880
  250. package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -402
  251. package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -240
  252. package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -106
  253. package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -37
  254. package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -38
  255. package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -36
  256. package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -37
  257. package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -36
  258. package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -38
  259. package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -36
  260. package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -37
  261. package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -36
  262. package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -37
  263. package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -36
  264. package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -38
  265. package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -36
  266. package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -36
  267. package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -37
  268. package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -38
  269. package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -36
  270. package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -37
  271. package/skills/office_parser/references/spec_lock.md +235 -235
  272. package/skills/office_parser/soffice.py +68 -68
  273. package/skills/office_parser/word_tools.py +3 -3
  274. package/skills/ssh/SKILL.md +81 -0
  275. package/skills/ssh/__init__.py +1 -0
  276. package/skills/ssh/handler.py +609 -0
  277. package/skills/ssh/manifest.yaml +182 -0
  278. package/tui/crannia.cmd +134 -134
  279. package/tui/crannia.sh +82 -0
  280. package/tui/crannia_tui/__init__.py +1 -1
  281. package/tui/crannia_tui/app.py +240 -17
  282. package/tui/crannia_tui/app.tcss +21 -0
  283. package/tui/crannia_tui/clipboard.py +78 -10
  284. package/tui/crannia_tui/commands.py +37 -0
  285. package/tui/crannia_tui/events.py +6 -0
  286. package/tui/crannia_tui/i18n.py +164 -164
  287. package/tui/crannia_tui/locales/en.json +31 -6
  288. package/tui/crannia_tui/paths.py +4 -1
  289. package/tui/crannia_tui/profile.py +178 -169
  290. package/tui/crannia_tui/settings.py +134 -134
  291. package/tui/crannia_tui/setup.py +44 -5
  292. package/tui/crannia_tui/ui.py +156 -16
  293. package/tui/crannia_tui/update.py +393 -389
  294. package/vendor/ripgrep/COPYING.txt +3 -3
  295. package/vendor/ripgrep/LICENSE-MIT.txt +21 -21
  296. package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -13
  297. package/vendor/ripgrep/README.md +30 -14
  298. package/vendor/ripgrep/UNLICENSE.txt +24 -24
  299. package/vendor/ripgrep/linux-x64/rg +0 -0
  300. package/vendor/ripgrep/package-source.json +15 -16
  301. package/web/__main__.py +12 -15
  302. package/web/server.py +8481 -8594
  303. package/web/static/img/channel-telegram.svg +1 -1
  304. package/web/static/img/channel-wechat.svg +1 -1
  305. package/web/templates/logs.html +49 -49
  306. package/web/templates/models.html +46 -46
package/core/endpoint.py CHANGED
@@ -1,141 +1,141 @@
1
- """一个数据根只许一个后端:端点文件的读写、判活与清理。
2
-
3
- 写这份文件是因为"两个都装"(GUI 与 TUI 共用 `data/settings.json` 与同一个
4
- 数据根)需要一个双方都认的地址。共享数据根意味着两套安装必须接同一个后端;
5
- 而"谁是那个后端"由端点文件回答,不由"谁先启动"猜。
6
-
7
- 三条判据:
8
-
9
- 1. 写与删都只认自己那份。退出时按 pid 比对,文件已经被后来的进程换掉
10
- 就不删,否则后起的后端会失去自己的端点。
11
- 2. 判活以 HTTP 为准,不以 pid 为准。pid 还在不等于它在听;反过来,
12
- pid 复用会让"活着"误判成"死了"。pid 只用于清理坏文件时解释原因。
13
- 3. 不用 `os.kill(pid, 0)` 判活。Windows 上 `os.kill` 走
14
- `TerminateProcess`,判活会变成杀进程,即检测器改变了被测对象。
15
-
16
- 文件位置:`<数据根>/data/runtime/endpoint.json`。走 `data/runtime/` 而不是
17
- 数据根直属的 `runtime/`,与运行数据的既有口径一致(开发树里数据根就是仓库,
18
- 写 `runtime/` 会往源码目录里加东西)。
19
- """
20
-
21
- from __future__ import annotations
22
-
23
- import json
24
- import os
25
- import urllib.error
26
- import urllib.request
27
- from pathlib import Path
28
-
29
- NAME = "endpoint.json"
30
-
31
- #: 本机地址不走环境变量里的代理 —— 代理通常不该拦 127.0.0.1,
32
- #: 但 `http_proxy` 一设,urllib 默认就会去问它。
33
- _OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
34
-
35
-
36
- def endpoint_path(root: Path) -> Path:
37
- """端点文件的绝对路径。`root` 是数据根(`core.paths.data_root()`)。"""
38
- return Path(root) / "data" / "runtime" / NAME
39
-
40
-
41
- def write(root: Path, *, port: int, token: str, version: str,
42
- pid: int | None = None) -> Path:
43
- """原子写入端点文件,返回路径。
44
-
45
- "原子"是给读侧的:TUI 与壳会在本进程写到一半时来读,半截 JSON
46
- 会被判成"没有端点",于是它们各起一个后端 —— 正是这层要防的事。
47
- """
48
- path = endpoint_path(root)
49
- path.parent.mkdir(parents=True, exist_ok=True)
50
- data = {
51
- "port": int(port),
52
- "token": str(token),
53
- "pid": int(pid if pid is not None else os.getpid()),
54
- "version": str(version),
55
- }
56
- tmp = path.with_suffix(".json.tmp")
57
- tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2),
58
- encoding="utf-8")
59
- os.replace(tmp, path)
60
- return path
61
-
62
-
63
- def read(root: Path) -> dict | None:
64
- """读端点文件。读不到、坏 JSON、字段不像样 —— 一律返回 None。
65
-
66
- "没有端点"与"端点坏了"在这一层的处置相同:调用方当作没人,
67
- 然后自己起后端;`write()` 会把坏文件覆盖掉。
68
- """
69
- try:
70
- data = json.loads(endpoint_path(root).read_text(encoding="utf-8"))
71
- except (OSError, ValueError):
72
- return None
73
- if not isinstance(data, dict):
74
- return None
75
- try:
76
- port = int(data.get("port") or 0)
77
- pid = int(data.get("pid") or 0)
78
- except (TypeError, ValueError):
79
- return None
80
- token = str(data.get("token") or "")
81
- if not (0 < port < 65536) or not token or pid <= 0:
82
- return None
83
- return {
84
- "port": port,
85
- "token": token,
86
- "pid": pid,
87
- "version": str(data.get("version") or ""),
88
- }
89
-
90
-
91
- def clear(root: Path, *, pid: int | None = None) -> bool:
92
- """删端点文件。给了 `pid` 就只删自己那份(文件里的 pid 对得上才删)。
93
-
94
- 返回是否真的删了。删不掉不抛 —— 一个残留的坏文件由下一次 `probe()`
95
- 判死,再被 `write()` 覆盖;为此让进程退出时崩掉不值得。
96
- """
97
- path = endpoint_path(root)
98
- data = read(root)
99
- if data is None:
100
- try:
101
- path.unlink()
102
- return True
103
- except OSError:
104
- return False
105
- if pid is not None and data["pid"] != int(pid):
106
- return False
107
- try:
108
- path.unlink()
109
- return True
110
- except OSError:
111
- return False
112
-
113
-
114
- def probe(root: Path, timeout: float = 2.0) -> dict | None:
115
- """端点文件上真的有人应答吗?活着返回合并后的字典,否则 None。
116
-
117
- 返回 `{port, token, pid, version, status}`:`status` 是 `/api/status`
118
- 的响应体,版本握手与"框架起没起"都从它来。
119
-
120
- 超时给 2 秒:这是启动路径上的同步调用,宁可判"没活着"也不要卡住;
121
- 真正的连接失败(拒绝 / 超时 / 403)统一按"没人"处理 —— 调用方那时
122
- 会自己起后端,代价只是多一次冷启动。
123
- """
124
- data = read(root)
125
- if data is None:
126
- return None
127
- url = f"http://127.0.0.1:{data['port']}/api/status"
128
- req = urllib.request.Request(
129
- url, headers={"X-Crannia-Token": data["token"]})
130
- try:
131
- with _OPENER.open(req, timeout=timeout) as resp:
132
- if resp.status != 200:
133
- return None
134
- body = json.loads(resp.read().decode("utf-8"))
135
- except (urllib.error.URLError, OSError, ValueError):
136
- return None
137
- if not isinstance(body, dict):
138
- return None
139
- out = dict(data)
140
- out["status"] = body
141
- return out
1
+ """一个数据根只许一个后端:端点文件的读写、判活与清理。
2
+
3
+ 写这份文件是因为"两个都装"(GUI 与 TUI 共用 `data/settings.json` 与同一个
4
+ 数据根)需要一个双方都认的地址。共享数据根意味着两套安装必须接同一个后端;
5
+ 而"谁是那个后端"由端点文件回答,不由"谁先启动"猜。
6
+
7
+ 三条判据:
8
+
9
+ 1. 写与删都只认自己那份。退出时按 pid 比对,文件已经被后来的进程换掉
10
+ 就不删,否则后起的后端会失去自己的端点。
11
+ 2. 判活以 HTTP 为准,不以 pid 为准。pid 还在不等于它在听;反过来,
12
+ pid 复用会让"活着"误判成"死了"。pid 只用于清理坏文件时解释原因。
13
+ 3. 不用 `os.kill(pid, 0)` 判活。Windows 上 `os.kill` 走
14
+ `TerminateProcess`,判活会变成杀进程,即检测器改变了被测对象。
15
+
16
+ 文件位置:`<数据根>/data/runtime/endpoint.json`。走 `data/runtime/` 而不是
17
+ 数据根直属的 `runtime/`,与运行数据的既有口径一致(开发树里数据根就是仓库,
18
+ 写 `runtime/` 会往源码目录里加东西)。
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import json
24
+ import os
25
+ import urllib.error
26
+ import urllib.request
27
+ from pathlib import Path
28
+
29
+ NAME = "endpoint.json"
30
+
31
+ #: 本机地址不走环境变量里的代理 —— 代理通常不该拦 127.0.0.1,
32
+ #: 但 `http_proxy` 一设,urllib 默认就会去问它。
33
+ _OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
34
+
35
+
36
+ def endpoint_path(root: Path) -> Path:
37
+ """端点文件的绝对路径。`root` 是数据根(`core.paths.data_root()`)。"""
38
+ return Path(root) / "data" / "runtime" / NAME
39
+
40
+
41
+ def write(root: Path, *, port: int, token: str, version: str,
42
+ pid: int | None = None) -> Path:
43
+ """原子写入端点文件,返回路径。
44
+
45
+ "原子"是给读侧的:TUI 与壳会在本进程写到一半时来读,半截 JSON
46
+ 会被判成"没有端点",于是它们各起一个后端 —— 正是这层要防的事。
47
+ """
48
+ path = endpoint_path(root)
49
+ path.parent.mkdir(parents=True, exist_ok=True)
50
+ data = {
51
+ "port": int(port),
52
+ "token": str(token),
53
+ "pid": int(pid if pid is not None else os.getpid()),
54
+ "version": str(version),
55
+ }
56
+ tmp = path.with_suffix(".json.tmp")
57
+ tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2),
58
+ encoding="utf-8")
59
+ os.replace(tmp, path)
60
+ return path
61
+
62
+
63
+ def read(root: Path) -> dict | None:
64
+ """读端点文件。读不到、坏 JSON、字段不像样 —— 一律返回 None。
65
+
66
+ "没有端点"与"端点坏了"在这一层的处置相同:调用方当作没人,
67
+ 然后自己起后端;`write()` 会把坏文件覆盖掉。
68
+ """
69
+ try:
70
+ data = json.loads(endpoint_path(root).read_text(encoding="utf-8"))
71
+ except (OSError, ValueError):
72
+ return None
73
+ if not isinstance(data, dict):
74
+ return None
75
+ try:
76
+ port = int(data.get("port") or 0)
77
+ pid = int(data.get("pid") or 0)
78
+ except (TypeError, ValueError):
79
+ return None
80
+ token = str(data.get("token") or "")
81
+ if not (0 < port < 65536) or not token or pid <= 0:
82
+ return None
83
+ return {
84
+ "port": port,
85
+ "token": token,
86
+ "pid": pid,
87
+ "version": str(data.get("version") or ""),
88
+ }
89
+
90
+
91
+ def clear(root: Path, *, pid: int | None = None) -> bool:
92
+ """删端点文件。给了 `pid` 就只删自己那份(文件里的 pid 对得上才删)。
93
+
94
+ 返回是否真的删了。删不掉不抛 —— 一个残留的坏文件由下一次 `probe()`
95
+ 判死,再被 `write()` 覆盖;为此让进程退出时崩掉不值得。
96
+ """
97
+ path = endpoint_path(root)
98
+ data = read(root)
99
+ if data is None:
100
+ try:
101
+ path.unlink()
102
+ return True
103
+ except OSError:
104
+ return False
105
+ if pid is not None and data["pid"] != int(pid):
106
+ return False
107
+ try:
108
+ path.unlink()
109
+ return True
110
+ except OSError:
111
+ return False
112
+
113
+
114
+ def probe(root: Path, timeout: float = 2.0) -> dict | None:
115
+ """端点文件上真的有人应答吗?活着返回合并后的字典,否则 None。
116
+
117
+ 返回 `{port, token, pid, version, status}`:`status` 是 `/api/status`
118
+ 的响应体,版本握手与"框架起没起"都从它来。
119
+
120
+ 超时给 2 秒:这是启动路径上的同步调用,宁可判"没活着"也不要卡住;
121
+ 真正的连接失败(拒绝 / 超时 / 403)统一按"没人"处理 —— 调用方那时
122
+ 会自己起后端,代价只是多一次冷启动。
123
+ """
124
+ data = read(root)
125
+ if data is None:
126
+ return None
127
+ url = f"http://127.0.0.1:{data['port']}/api/status"
128
+ req = urllib.request.Request(
129
+ url, headers={"X-Crannia-Token": data["token"]})
130
+ try:
131
+ with _OPENER.open(req, timeout=timeout) as resp:
132
+ if resp.status != 200:
133
+ return None
134
+ body = json.loads(resp.read().decode("utf-8"))
135
+ except (urllib.error.URLError, OSError, ValueError):
136
+ return None
137
+ if not isinstance(body, dict):
138
+ return None
139
+ out = dict(data)
140
+ out["status"] = body
141
+ return out
package/core/events.py CHANGED
@@ -96,7 +96,10 @@ EVT_APPROVAL_REQUEST = "approval.request" # 有新的待审批:{request_id,
96
96
  EVT_APPROVAL_RESOLVED = "approval.resolved" # 已结算/已失效:{request_id,choice}
97
97
 
98
98
  # 异常
99
- EVT_RETRY = "retry" # 通用重试(仍未用;LLM 连接重试走下面那一对)
99
+ #
100
+ # `retry` 这个常量已删(2026-11-24,接线复核的 C 组):它从写下那天起零 emit 点,
101
+ # 唯一的重试通道是下面 `llm.retry` 那一对。删掉而不是留着,是判据本身的要求 ——
102
+ # 一个声明了却永远不会发生的事件类型,会让读事件流的人以为这条路上有东西。
100
103
  EVT_ERROR = "error" # 阶段抛异常
101
104
  EVT_RESYNC = "resync" # 客户端 seq 缺口过大,必须重建
102
105
 
@@ -357,7 +360,6 @@ DURABLE_TYPES: frozenset[str] = frozenset({
357
360
  EVT_SAY,
358
361
  EVT_TOOL_START,
359
362
  EVT_TOOL_END,
360
- EVT_RETRY,
361
363
  EVT_ERROR,
362
364
  # 审批:进 DURABLE_TYPES 是因为它们成对出现
363
365
  # (request/resolved)。落盘之后"有 request 无 resolved"是可检测的孤儿 ——
@@ -551,7 +553,11 @@ class _DurableWriter(threading.Thread):
551
553
  self._fp = None
552
554
  self._day = ""
553
555
  self.dropped = 0
554
- self._stop = threading.Event()
556
+ # 不能叫 `_stop`:那是 threading.Thread 的私有方法。3.11 的
557
+ # `join()` 会经由 `_wait_for_tstate_lock` 调它,被 Event 实例盖掉
558
+ # 之后 join 直接抛 TypeError —— 而那时正在收尾,队列里还剩事件。
559
+ # 3.12 起 threading 重写过,不再调这个方法,所以这个坑只在旧版踩得到。
560
+ self._stop_flag = threading.Event()
555
561
 
556
562
  def offer(self, ev: Event) -> None:
557
563
  if self._q.qsize() >= self.MAX_QUEUED:
@@ -560,14 +566,14 @@ class _DurableWriter(threading.Thread):
560
566
  self._q.put_nowait(ev)
561
567
 
562
568
  def stop(self) -> None:
563
- self._stop.set()
569
+ self._stop_flag.set()
564
570
  self._q.put_nowait(None)
565
571
 
566
572
  # -- thread body ------------------------------------------------
567
573
 
568
574
  def run(self) -> None:
569
575
  self._prune_old()
570
- # 注意:不要用 while not self._stop.is_set() 做循环条件。
576
+ # 注意:不要用 while not self._stop_flag.is_set() 做循环条件。
571
577
  # 那样 stop() 一置位就会立刻跳出,把队列里还没落盘的事件全丢掉。
572
578
  # 正确做法是靠哨兵值退出 —— Queue 是 FIFO 的,所以哨兵之前入队的
573
579
  # 事件必定已经处理完。
@@ -701,8 +707,11 @@ class EventBus:
701
707
  if writer is not None:
702
708
  writer.offer(ev)
703
709
  except Exception as exc: # noqa: BLE001 — 兜底是刻意的
710
+ # 不许写 `type(exc)`:本函数的参数就叫 `type`(事件类型串),
711
+ # Python 会先绑参数,`type` 是个 str,这句自己抛 TypeError,
712
+ # 兜底反而把 emit 的调用方弄挂(Pyright 照出来的)。
704
713
  print(f"[events] emit failed for {type!r}: "
705
- f"{type(exc).__name__}: {exc}")
714
+ f"{exc.__class__.__name__}: {exc}")
706
715
 
707
716
  def _get_writer(self) -> _DurableWriter | None:
708
717
  """懒启动落盘线程。没有 durable 事件就永远不启动。"""
@@ -883,7 +892,7 @@ def _emit_bg(evt_type: str, kind: str, session_key: str, ts: float,
883
892
  data["duration_ms"] = int((ts - started) * 1000)
884
893
  get_event_bus().emit(evt_type, session_key=session_key, **data)
885
894
  except Exception as exc: # noqa: BLE001
886
- print(f"[bg] {evt_type} 事件发不出去({type(exc).__name__}: {exc})")
895
+ print(f"[bg] {evt_type} event could not be sent ({type(exc).__name__}: {exc})")
887
896
 
888
897
 
889
898
  __all__ = [
@@ -893,7 +902,7 @@ __all__ = [
893
902
  "EVT_TASK_START", "EVT_TASK_END", "EVT_STEP_START", "EVT_STEP_END",
894
903
  "EVT_TURN_START", "EVT_TURN_END", "EVT_THINKING", "EVT_SAY",
895
904
  "EVT_TOOL_START", "EVT_TOOL_END", "EVT_DELTA",
896
- "EVT_RETRY", "EVT_ERROR", "EVT_RESYNC",
905
+ "EVT_ERROR", "EVT_RESYNC",
897
906
  "EVT_LLM_RETRY", "EVT_LLM_RETRY_OK",
898
907
  "EVT_APPROVAL_REQUEST", "EVT_APPROVAL_RESOLVED",
899
908
  "EVT_CONTEXT_STATE",
package/core/extension.py CHANGED
@@ -88,11 +88,11 @@ class StoreFacade:
88
88
  except FileNotFoundError:
89
89
  return self.version, {}
90
90
  except (OSError, ValueError) as exc:
91
- print("[skill-store] %s 读取失败(%s: %s),按空处理"
91
+ print("[skill-store] %s read failed (%s: %s), treating as empty"
92
92
  % (self.path, type(exc).__name__, exc))
93
93
  return self.version, {}
94
94
  if not isinstance(raw, dict):
95
- print("[skill-store] %s 不是对象,按空处理" % self.path)
95
+ print("[skill-store] %s is not an object, treating as empty" % self.path)
96
96
  return self.version, {}
97
97
  ver = raw.get("_version")
98
98
  # bool 是 int 的子类,需要单独排除。
@@ -227,10 +227,10 @@ def _make_room(incoming: int) -> int:
227
227
  total -= size
228
228
  removed += 1
229
229
  if removed:
230
- print("[file_history] 超过总空间上限 %d MiB,从最旧的开始清掉了 %d 份"
230
+ print("[file_history] over total space cap %d MiB, removed %d oldest"
231
231
  % (cap_mb, removed))
232
232
  except Exception as exc: # noqa: BLE001
233
- print("[file_history] 腾地方失败(不影响写入):%s: %s"
233
+ print("[file_history] make room failed (write unaffected): %s: %s"
234
234
  % (type(exc).__name__, exc))
235
235
  return removed
236
236
 
@@ -371,7 +371,7 @@ def _save_index(session_id: str, data: dict) -> None:
371
371
  json.dumps(data, ensure_ascii=False).encode("utf-8"),
372
372
  )
373
373
  except OSError as exc:
374
- print("[file_history] 轮次索引写失败(不影响写入):%s" % exc)
374
+ print("[file_history] turn index write failed (write unaffected): %s" % exc)
375
375
 
376
376
 
377
377
  def _record_version(session_id: str, path, version: int, turn: int) -> None:
@@ -382,7 +382,7 @@ def _record_version(session_id: str, path, version: int, turn: int) -> None:
382
382
  {"v": int(version), "turn": int(turn), "after": None})
383
383
  _save_index(session_id, idx)
384
384
  except Exception as exc: # noqa: BLE001
385
- print("[file_history] 轮次记账失败(不影响写入):%s" % exc)
385
+ print("[file_history] turn record failed (write unaffected): %s" % exc)
386
386
 
387
387
 
388
388
  def _sha256_file(p: Path) -> Optional[str]:
@@ -429,7 +429,7 @@ def snapshot_before(session_id: str, path, turn: int = 0) -> Optional[int]:
429
429
  # 不截断(截断出来的 diff 会撒谎:看起来像"只改了前半篇")
430
430
  #留一个标记,让界面上如实说"拿不到 diff"(判据 ③)。
431
431
  base.with_suffix(".big").write_bytes(b"")
432
- print("[file_history] %s 有 %d 字节 > 封顶 %d —— 只留标记,不存内容"
432
+ print("[file_history] %s has %d bytes > cap %d - marker only, content not stored"
433
433
  % (src.name, size, MAX_BYTES))
434
434
  _record_version(sid, str(path), version, turn)
435
435
  return version
@@ -443,7 +443,7 @@ def snapshot_before(session_id: str, path, turn: int = 0) -> Optional[int]:
443
443
  _record_version(sid, str(path), version, turn)
444
444
  return version
445
445
  except Exception as exc: # noqa: BLE001
446
- print("[file_history] 留档失败(不影响写入):%s: %s"
446
+ print("[file_history] archive failed (write unaffected): %s: %s"
447
447
  % (type(exc).__name__, exc))
448
448
  return None
449
449
 
@@ -580,7 +580,7 @@ def seal_turn(session_id: str, turn: int = 0) -> int:
580
580
  _save_index(sid, idx)
581
581
  return n
582
582
  except Exception as exc: # noqa: BLE001
583
- print("[file_history] 轮末封印失败(不影响本轮):%s" % exc)
583
+ print("[file_history] end-of-turn seal failed (turn unaffected): %s" % exc)
584
584
  return 0
585
585
 
586
586
 
@@ -952,9 +952,9 @@ def prune(days: Optional[int] = None, now: Optional[datetime] = None) -> int:
952
952
  # 保留期读不到时不提它,只报空间那一半。
953
953
  why = ("超过 %d 天" % days) if days is not None else None
954
954
  if why:
955
- print("[file_history] 清掉了 %d 份改前留档(%s / 或超过总空间上限)"
955
+ print("[file_history] removed %d version archives (%s / or over total space cap)"
956
956
  % (removed, why))
957
957
  else:
958
- print("[file_history] 清掉了 %d 份改前留档(保留期读不到,"
959
- "只按总空间上限削)" % removed)
958
+ print("[file_history] removed %d version archives (retention unreadable, "
959
+ "total space cap only)" % removed)
960
960
  return removed
@@ -283,7 +283,7 @@ def note_observed(path, session_id: str | None = None) -> None:
283
283
  _note_read(_sid() if session_id is None else session_id, Path(path))
284
284
  except Exception as exc: # noqa: BLE001
285
285
  # 记账失败不许影响读取本身(同 `security._note_touched` 的规矩)
286
- print("[observe] 读态记账失败(不影响本次读写):%s: %s"
286
+ print("[observe] read-state record failed (read/write unaffected): %s: %s"
287
287
  % (type(exc).__name__, exc))
288
288
 
289
289
 
@@ -811,7 +811,7 @@ def write_file(file_path: str = "", content=None) -> dict:
811
811
 
812
812
  _note_read(session_id, path) # 纪律 ②:写完把新 stat 记回去
813
813
  print("[file] write_file %s (%d bytes, %s)"
814
- % (_posix(path), len(data), "覆盖" if existed else "新建"))
814
+ % (_posix(path), len(data), "overwrite" if existed else "created"))
815
815
 
816
816
  lines = payload.count("\n") + (0 if payload.endswith("\n") or not payload else 1)
817
817
  out = {
@@ -1081,7 +1081,7 @@ def _finish_edit(file_path, path, session_id, new_text, enc, replaced_bytes,
1081
1081
 
1082
1082
  _note_read(session_id, path) # 纪律 ②
1083
1083
 
1084
- print("[file] edit_file %s (%d 处, %s)"
1084
+ print("[file] edit_file %s (%d places, %s)"
1085
1085
  % (_posix(path), n, _eol_name(used_eol or eol)))
1086
1086
 
1087
1087
  out = {
@@ -38,7 +38,7 @@ def load(path: Optional[Path] = None) -> dict:
38
38
  return {}
39
39
  raw = json.loads(p.read_text(encoding="utf-8"))
40
40
  except Exception as exc: # noqa: BLE001
41
- print("[github] 读不到设置里的令牌(%s)—— 视为未配置" % type(exc).__name__)
41
+ print("[github] cannot read token from settings (%s) - treated as unconfigured" % type(exc).__name__)
42
42
  return {}
43
43
  cfg = (raw.get("skill_configs") or {}).get(SCOPE) or {}
44
44
  return cfg if isinstance(cfg, dict) else {}
@@ -50,7 +50,7 @@ def _read() -> dict[str, dict]:
50
50
  except FileNotFoundError:
51
51
  return {}
52
52
  except Exception as exc: # noqa: BLE001
53
- print(f"[group_digest] 账本读不动({type(exc).__name__}: {exc})—— 按空账本走")
53
+ print(f"[group_digest] ledger unreadable ({type(exc).__name__}: {exc}) - treating as empty")
54
54
  return {}
55
55
  return raw if isinstance(raw, dict) else {}
56
56
 
@@ -112,8 +112,7 @@ def set(storage_id: str, *, group_id: str, items: list[dict]) -> None: # noqa:
112
112
  try:
113
113
  _write(data)
114
114
  except Exception as exc: # noqa: BLE001
115
- print(f"[group_digest] 账本写不进去({type(exc).__name__}: {exc})"
116
- f" —— 本次运行**仍然生效** '{sid}'")
115
+ print(f"[group_digest] ledger write failed ({type(exc).__name__}: {exc}) - still active for this run '{sid}'")
117
116
 
118
117
 
119
118
  def clear(storage_id: str) -> bool:
@@ -129,7 +128,7 @@ def clear(storage_id: str) -> bool:
129
128
  try:
130
129
  _write(data)
131
130
  except Exception as exc: # noqa: BLE001
132
- print(f"[group_digest] 账本写不进去({type(exc).__name__}: {exc})")
131
+ print(f"[group_digest] ledger write failed ({type(exc).__name__}: {exc})")
133
132
  return True
134
133
 
135
134
 
@@ -77,7 +77,7 @@ def _read() -> dict[str, dict]:
77
77
  except FileNotFoundError:
78
78
  return {}
79
79
  except Exception as exc: # noqa: BLE001
80
- print("[group_minutes] 账本读不动(%s: %s)—— 按空账本走"
80
+ print("[group_minutes] ledger unreadable (%s: %s) - treating as empty"
81
81
  % (type(exc).__name__, exc))
82
82
  return {}
83
83
  return raw if isinstance(raw, dict) else {}
@@ -298,17 +298,17 @@ def update_now(group: dict, storage_id: str, messages: list[dict],
298
298
  )
299
299
  text = parse_minutes(getattr(resp, "content", "") or "")
300
300
  except Exception as exc: # noqa: BLE001
301
- print("[group_minutes] 生成失败(%s: %s)—— 保留旧纪要"
301
+ print("[group_minutes] generation failed (%s: %s) - keeping previous minutes"
302
302
  % (type(exc).__name__, exc))
303
303
  return ""
304
304
  if not text:
305
- print("[group_minutes] 模型没有给出纪要 —— 保留旧纪要")
305
+ print("[group_minutes] model returned no minutes - keeping previous minutes")
306
306
  return ""
307
307
  try:
308
308
  set(storage_id, group_id=str((group or {}).get("id") or ""),
309
309
  text=text, turns=int(turn_no or 0))
310
310
  except Exception as exc: # noqa: BLE001
311
- print("[group_minutes] 落盘失败(%s: %s)" % (type(exc).__name__, exc))
311
+ print("[group_minutes] persist failed (%s: %s)" % (type(exc).__name__, exc))
312
312
  return ""
313
313
  return text
314
314
 
@@ -345,5 +345,5 @@ def spawn_update(group: dict, storage_id: str, messages: list[dict],
345
345
  t = threading.Thread(target=_run, name="group-minutes", daemon=True)
346
346
  t.start()
347
347
  except Exception as exc: # noqa: BLE001
348
- print("[group_minutes] 后台线程起不来(%s: %s)"
348
+ print("[group_minutes] background thread could not start (%s: %s)"
349
349
  % (type(exc).__name__, exc))
@@ -469,6 +469,30 @@ def member_reply_content(name: str, content: str) -> str:
469
469
  return "【%s】%s" % (name, str(content or "").strip())
470
470
 
471
471
 
472
+ #: 只给界面看的字段 —— 群历史走过四家供应商的 wire 之前要摘掉。
473
+ _UI_ONLY_FIELDS = frozenset({"kind", "speaker", "avatar", "artifacts",
474
+ "tokens", "model"})
475
+
476
+
477
+ def normalize_history(messages: list[dict]) -> list[dict]:
478
+ """群聊历史 → 所有供应商同形的副本。
479
+
480
+ 为什么需要它:四位成员可能各用一家模型,历史里混着上一家特有的字段
481
+ (`reasoning_content` / `tool_calls` / `model`)—— 这些对下一家没有意义,
482
+ 而"每条消息长什么样"应当只由群聊协议决定,不由上一位发言者的供应商决定。
483
+
484
+ 普通历史只留 `role` / `content`(content 原样,可能是图片块列表)。
485
+ 真的出现工具协议消息时退回"去掉界面字段后的透传" —— 剥掉
486
+ `tool_call_id` 会让 tool 结果变成悬空消息,那是另一种坏形状。
487
+ """
488
+ items = [m for m in (messages or []) if isinstance(m, dict)]
489
+ if any(m.get("role") == "tool" or m.get("tool_calls") for m in items):
490
+ return [{k: v for k, v in m.items() if k not in _UI_ONLY_FIELDS}
491
+ for m in items]
492
+ return [{"role": str(m.get("role") or ""),
493
+ "content": m.get("content", "")} for m in items]
494
+
495
+
472
496
  def strip_member_prefix(name: str, content: str) -> str:
473
497
  """给 GUI 用:把 `【名字】` 前缀剥掉(只剥自己那一层)。"""
474
498
  prefix = "【%s】" % (name or "")
package/core/groups.py CHANGED
@@ -99,7 +99,7 @@ def _read() -> dict[str, dict]:
99
99
  # 账本坏了,当没有群。判据同 `bus/mcp_disabled._read`:
100
100
  # 宁可让用户重建一个群,不可凭一个读不动的文件把界面上那 8 个头像
101
101
  # 渲染成半截(那看起来像"群还在,只是坏了")。
102
- print(f"[groups] 账本读不动({type(exc).__name__}: {exc})—— 按空账本走")
102
+ print(f"[groups] ledger unreadable ({type(exc).__name__}: {exc}) - treating as empty")
103
103
  return {}
104
104
  return raw if isinstance(raw, dict) else {}
105
105
 
@@ -384,8 +384,7 @@ def create(*, name: str = "", members=None, brief="",
384
384
  except Exception as exc: # noqa: BLE001
385
385
  # 写不进去也照样算建成了(本次运行内是真的)—— 同
386
386
  # `mcp_disabled.disable` 那条;但要说出来。
387
- print(f"[groups] 账本写不进去({type(exc).__name__}: {exc})"
388
- f" —— 本次运行**仍然有**这个群 '{gid}'")
387
+ print(f"[groups] ledger write failed ({type(exc).__name__}: {exc}) - group '{gid}' still present for this run")
389
388
  return dict(entry)
390
389
 
391
390
 
@@ -420,8 +419,7 @@ def update(gid: str, *, name=None, members=None, brief=None,
420
419
  try:
421
420
  _write(data)
422
421
  except Exception as exc: # noqa: BLE001
423
- print(f"[groups] 账本写不进去({type(exc).__name__}: {exc})"
424
- f" —— 本次运行**改动仍然生效** '{gid}'")
422
+ print(f"[groups] ledger write failed ({type(exc).__name__}: {exc}) - changes remain active for this run '{gid}'")
425
423
  return dict(next_entry)
426
424
 
427
425
 
@@ -479,8 +477,7 @@ def update_member(gid: str, index: int, *, name: str = "",
479
477
  try:
480
478
  _write(data)
481
479
  except Exception as exc: # noqa: BLE001
482
- print(f"[groups] 账本写不进去({type(exc).__name__}: {exc})"
483
- f" —— 本次运行**改动仍然生效** '{gid}'")
480
+ print(f"[groups] ledger write failed ({type(exc).__name__}: {exc}) - changes remain active for this run '{gid}'")
484
481
  return dict(next_entry)
485
482
 
486
483
 
@@ -501,8 +498,7 @@ def delete(gid: str) -> bool:
501
498
  try:
502
499
  _write(data)
503
500
  except Exception as exc: # noqa: BLE001
504
- print(f"[groups] 账本写不进去({type(exc).__name__}: {exc})"
505
- f" —— 本次运行**仍然删掉了** '{gid}'")
501
+ print(f"[groups] ledger write failed ({type(exc).__name__}: {exc}) - still deleted for this run '{gid}'")
506
502
  return True
507
503
 
508
504