@hfyjq/crannia 1.1.1 → 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 -7523
  39. package/core/allowlist.py +2 -3
  40. package/core/approval.py +36 -26
  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 +15 -15
  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 +3 -3
  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 +37 -28
  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 +369 -77
  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 -1762
  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 +32 -7
  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
@@ -0,0 +1,129 @@
1
+ # -*- coding: utf-8 -*-
2
+ """SSH 凭据与主机密钥的唯一读取口。
3
+
4
+ 私钥路径 / 口令 / 密码都不进工具参数;回执里只出现条目名与主机。
5
+
6
+ ## 两个存储
7
+
8
+ 1. 凭据 —— 设置页 `skill_configs.ssh`(`config.fields` 在
9
+ `skills/ssh/manifest.yaml`,口令与密码是 `format: password` /
10
+ `x-secret: true`),外加 `CRANNIA_SSH_KEY` 环境变量作为私钥路径的兜底。
11
+ 形状(`entries` 命名条目 + `active`,旧的单条形状也认):
12
+
13
+ {"active": "pi", "entries": {"pi": {"key_path": "...", "user": "pi",
14
+ "passphrase": "...", "password": "...",
15
+ "sudo_password": "..."}}}
16
+
17
+ 2. 主机密钥 —— `data/runtime/ssh/known_hosts`,框架自己的一份。
18
+ 决定 4(`出网权限重构-设计-2026-11-26.md §12`):不写用户的
19
+ `~/.ssh/known_hosts` —— 那是用户的文件,框架未经允许不该动它。
20
+ 读的时候两份都读(用户已经手动连过的主机直接能用);写的只有自己那份。
21
+
22
+ ## 优先级
23
+
24
+ 设置页 > 环境变量(只对私钥路径)。读不到 = 未配置(fail-closed:
25
+ `skills/ssh` 的回执会给"去设置页填"的路线)。
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import json
31
+ import os
32
+ from pathlib import Path
33
+ from typing import Optional
34
+
35
+ __all__ = ["SCOPE", "ENV_KEY", "load", "resolve", "resolve_entry",
36
+ "known_hosts_path", "add_known_host"]
37
+
38
+ _SETTINGS_PATH = Path("data/settings.json")
39
+ SCOPE = "ssh"
40
+ ENV_KEY = "CRANNIA_SSH_KEY"
41
+
42
+ #: 框架自己的 known_hosts(决定 4:不碰 `~/.ssh/known_hosts`)。
43
+ _KNOWN_HOSTS = Path("data/runtime/ssh/known_hosts")
44
+
45
+
46
+ def load(path: Optional[Path] = None) -> dict:
47
+ p = path or _SETTINGS_PATH
48
+ try:
49
+ if not p.exists():
50
+ return {}
51
+ raw = json.loads(p.read_text(encoding="utf-8"))
52
+ except Exception as exc: # noqa: BLE001
53
+ print("[ssh] cannot read settings (%s) - treated as unconfigured" % type(exc).__name__)
54
+ return {}
55
+ cfg = (raw.get("skill_configs") or {}).get(SCOPE) or {}
56
+ return cfg if isinstance(cfg, dict) else {}
57
+
58
+
59
+ def resolve_entry(key_name: str = "") -> dict:
60
+ """选中的那一条凭据,原样返回(含 `name` / `source`)。没有就空 dict。
61
+
62
+ `key_name` 命中 `entries` 里的名字;不填用 `active` 或第一条。
63
+ 旧形状(顶层的 `key_path`)当一条名叫 `default` 的条目。
64
+ 环境变量只在私钥路径上兜底 —— 密码类的东西不走环境变量
65
+ (它们会出现在进程环境里,比设置页更不该躺在那儿)。
66
+ """
67
+ cfg = load()
68
+ entries = cfg.get("entries")
69
+ chosen: dict = {}
70
+ source = ""
71
+ if isinstance(entries, dict) and entries:
72
+ name = str(key_name or cfg.get("active") or "").strip()
73
+ if name and name in entries and isinstance(entries[name], dict):
74
+ chosen = dict(entries[name])
75
+ source = name
76
+ else:
77
+ first_name, first_val = next(iter(entries.items()))
78
+ if isinstance(first_val, dict):
79
+ chosen, source = dict(first_val), str(first_name)
80
+ elif cfg.get("key_path"):
81
+ # 旧的单条形状
82
+ chosen, source = dict(cfg), "default"
83
+ if not chosen:
84
+ env = os.environ.get(ENV_KEY, "").strip()
85
+ if env:
86
+ chosen, source = {"key_path": env}, "env"
87
+ if chosen:
88
+ chosen["name"] = source or "default"
89
+ chosen["source"] = source or "default"
90
+ return chosen
91
+
92
+
93
+ def resolve(key_name: str = "") -> tuple[str, str, str]:
94
+ """兼容旧调用:返回 `(私钥路径, 口令, 条目名)`;没有就空串。"""
95
+ e = resolve_entry(key_name)
96
+ return (str(e.get("key_path") or ""), str(e.get("passphrase") or ""),
97
+ str(e.get("name") or ""))
98
+
99
+
100
+ def known_hosts_path() -> Path:
101
+ """框架自己的 known_hosts 路径(唯一一处)。"""
102
+ return _KNOWN_HOSTS
103
+
104
+
105
+ def add_known_host(line: str) -> bool:
106
+ """把一行 known_hosts 记进框架自己的表。已经在了返回 `False`(幂等)。
107
+
108
+ 形状校验是窄的:`host keytype base64`,至少三段,且类型以已知前缀开头。
109
+ 这样调用方(审批结算)就不会因为一个坏载荷把整份文件写坏 ——
110
+ 那是"用户点了信任、下次还问"查不出因的那类故障。
111
+ """
112
+ text = " ".join(str(line or "").split())
113
+ if not text or len(text) > 4096:
114
+ return False
115
+ parts = text.split(" ")
116
+ if len(parts) < 3:
117
+ return False
118
+ if not parts[1].startswith(("ssh-", "ecdsa-", "sk-", "rsa-")):
119
+ return False
120
+ p = _KNOWN_HOSTS
121
+ p.parent.mkdir(parents=True, exist_ok=True)
122
+ try:
123
+ if p.exists() and text in p.read_text(encoding="utf-8").splitlines():
124
+ return False
125
+ except OSError:
126
+ pass
127
+ with p.open("a", encoding="utf-8") as f:
128
+ f.write(text + "\n")
129
+ return True
@@ -295,6 +295,13 @@ SESSION_SCOPED: Tuple[SessionState, ...] = (
295
295
  "后台记忆抽取的三格(游标/节流计数/last_turn_at)+ 在飞标志。"
296
296
  "不清:新一段对话继承上一段的节流计数(早抽或晚抽几轮)与旧游标 —— "
297
297
  "游标靠指纹失配兜底,但 `last_turn_at` 是旧时刻(冷闸会误判『冷』)"),
298
+ SessionState(
299
+ "session_recap", "core/session_recap.py::_LAST_RECAP", "purge_session",
300
+ _lazy("core.session_recap", "forget"),
301
+ "本会话上一次给出自动回顾的时刻(防「那一轮没跑完 ⇒ 每句话都回顾」)。"
302
+ "不清的后果:新一段对话的 `last_turn_at` 也被清了(同一条 purge),"
303
+ "所以通常无害;但若不清,这一格会跟着会话键留下来,"
304
+ "让新对话在 `last_turn_at` 前进之前被旧时刻压住(该给回顾时不给)"),
298
305
  # 这两条是「授权」,不是「数据」 ——
299
306
  # `/clear` 对它们做的是回收权限,不是丢东西。
300
307
  SessionState(
@@ -524,6 +531,12 @@ SESSION_SCOPED_BY_OTHER: Tuple[SessionState, ...] = (
524
531
  SessionState(
525
532
  "pending_egress", "core/pipeline/scheduler.py::PipelineScheduler._pending_egress",
526
533
  "同上", note="同 pending_cross_zone(出网审批)"),
534
+ SessionState(
535
+ "pending_ssh_hostkey",
536
+ "core/pipeline/scheduler.py::PipelineScheduler._pending_ssh_hostkey",
537
+ "同上(同一套派发/结算代码)",
538
+ note="SSH 主机密钥信任 - 自己一格(被审批物是指纹,不是目标授权)。"
539
+ "不清:下一句话会被当成对上一个指纹的回答"),
527
540
  SessionState(
528
541
  "pending_write_outside",
529
542
  "core/pipeline/scheduler.py::PipelineScheduler._pending_write_outside",
@@ -631,11 +644,16 @@ SESSION_SCOPED_BY_OTHER: Tuple[SessionState, ...] = (
631
644
  # `_profile_only` 已删:它是"新会话只带画像、不带 facts"的两档开关,
632
645
  # 而画像/facts 两段现在整段删除(只剩会话笔记),它没有可区分的对象了。
633
646
  # census 会把"过期登记"报出来。
634
- # SessionPool 2 格
647
+ # SessionPool 3 格(原 2 格 + 模型指纹缓存)
635
648
  SessionState(
636
649
  "_loaded", "core/session_pool.py::SessionPool._loaded",
637
650
  "SessionPool.new_session 用新 (sid, msgs) 覆盖",
638
651
  note="它是'这个 key 认不认识'的缓存 —— 判据不能只看它(磁盘上还有绑定表)"),
652
+ SessionState(
653
+ "_loaded_model", "core/session_pool.py::SessionPool._loaded_model",
654
+ "get_or_create 命中时按当前 provider 重新算指纹,不一致则连同 _loaded 一起失效",
655
+ note="只是 _loaded 那份消息按哪个模型窗口装载的标记,不是'这一段用什么模型'。"
656
+ "真正的会话模型在 core/session_model.py,两者不可混"),
639
657
  # 这里不能再加一格 `_model_overrides`(`SessionPool` 的会话模型覆盖):
640
658
  # 那是一条死路(`/model` 往里写、全仓没有读者),保留它就是让
641
659
  # 「这一段用什么模型」有两个看起来都对的地方(`core/session_model.py`
@@ -873,10 +891,10 @@ PROCESS_SHARED: Tuple[ProcessState, ...] = (
873
891
  ProcessState(
874
892
  "_creds", "core/model_configs.py::_creds",
875
893
  "`core/model_configs._LOCK` 护着(与 `_cache` **同一把锁、同一次原子写**)",
876
- "★ 凭据账本的内存镜像(`data/runtime/provider_credentials.json`)——"
877
- "**单独一个文件**(配置可以随便看/导出,凭据不行)。"
878
- "⚠️ 它也是**不是**真相源。★ 与 `_cache` **必须同进同出**:两个文件各写一次,"
879
- "而哪一次失败都只出声、不回滚(本次运行内是真的)。"
894
+ "★ 模型 api 的内存镜像(D6 单文件后与 `_cache` **同一份** "
895
+ "`data/runtime/model_configs.json` 的 `api` 字段)。"
896
+ "⚠️ 内存层仍分离:条目出模块时不带 `api`(导出结构上拿不到明文)。"
897
+ "⚠️ 它也不是真相源。★ 与 `_cache` 一次原子写,写失败只出声、不回滚。"
880
898
  "⚠️ 那个文件同时在 `core/security.py::DEFAULT_FORBIDDEN_PATHS` 里 ——"
881
899
  "**改动它的落点时两处都要改**"),
882
900
  ProcessState(
@@ -893,6 +911,12 @@ PROCESS_SHARED: Tuple[ProcessState, ...] = (
893
911
  "★ 失效判据挂在 `updated_at` 上(不是「记得清」):用户改了那条配置 ⇒ 下一轮重建。"
894
912
  "⚠️ `/clear` **不清它** —— 它是**进程级的缓存**,与哪一段对话无关"
895
913
  "(清了只是多几次 import)"),
914
+ ProcessState(
915
+ "_SCAN_CACHE", "core/computer/input.py::_SCAN_CACHE",
916
+ "无锁:只在 _scan_of 里写,而两边写进去的是同一个值"
917
+ "(MapVirtualKey 对同一个虚拟键恒定),没有可以分叉的事实",
918
+ "虚拟键码到 scan code 的缓存。"
919
+ "/clear 不清它,它是进程级的系统常量,与哪一段对话无关。"),
896
920
  ProcessState(
897
921
  "_ST", "core/session_model.py::_ST",
898
922
  "★ **无锁**:只在 `_short_term()` 里写一次(首次拿到单例后就一直命中),"
@@ -925,6 +949,17 @@ PROCESS_SHARED: Tuple[ProcessState, ...] = (
925
949
  ProcessState(
926
950
  "_declared", "core/tool_output_kind.py::_declared",
927
951
  "装载期写入(_note_output_kind),运行期只读", "同 registered_stages"),
952
+ ProcessState(
953
+ "_DECLARED", "core/egress_channels.py::_DECLARED",
954
+ "装载期写入(manifest 的 egress 段 -> declare()),运行期只读",
955
+ "出网能力表的技能那一半(框架那一半是静态的 FRAMEWORK_CHANNELS)。"
956
+ "与 tool_output_kind._declared 同形同命:进程级声明,"
957
+ "/clear 不该碰它,也不进 purge_session"),
958
+ ProcessState(
959
+ "_ROUTE_BY_FAMILY", "core/egress_channels.py::_ROUTE_BY_FAMILY",
960
+ "模块导入期从 DENY_ROUTES 派生,运行期只读",
961
+ "派生表(不是状态)- 登记它是因为 census 按「模块级 dict」扫;"
962
+ "它有读者(route_of_family / deny_message)"),
928
963
  ProcessState(
929
964
  "_stats", "core/auto_review.py::_stats",
930
965
  "无锁;只在 `_auto_review_gate` 那条派发路上加一笔(六个通道各在自己的线程里跑)",
@@ -1089,6 +1124,13 @@ PROCESS_SHARED: Tuple[ProcessState, ...] = (
1089
1124
  "★ 与 `bus/core.py::_env_warned` **同形同命**(并发下最多重算一次字符串 ⇒ 无害)。"
1090
1125
  "它是给回执用的一句话('为什么这台机器上用不了回收站'),"
1091
1126
  "⚠️ 不许当成判据 —— 判据是 `available()`。`/clear` 不清它"),
1127
+ ProcessState(
1128
+ "_xdg_error", "core/recycle.py::_xdg_error",
1129
+ "**无锁 warn-once 字符串**:Linux 那半在 `_xdg_available()` 失败时写一次"
1130
+ "(同一句 `global`)",
1131
+ "★ 与 `_load_error` 同形同命(并发下最多重算一次字符串 ⇒ 无害)。"
1132
+ "它是给回执用的一句话('Linux 上为什么建不了回收站目录'),"
1133
+ "⚠️ 不许当成判据 —— 判据是 `available()`。`/clear` 不清它"),
1092
1134
  # 这两格不是会话级:没有 session_id 键,而且 `/clear` 不该碰它们 ——
1093
1135
  # 碰了就把挂在那个循环上的 MCP 连接一起掐了。所以归这边。
1094
1136
  ProcessState(
@@ -1205,6 +1247,26 @@ PROCESS_SHARED: Tuple[ProcessState, ...] = (
1205
1247
  "★ **必须是同一份**:`pre_process` 占位、`post_process` 落账、"
1206
1248
  "调度器轮末放位 —— 分成两份就是「占位写 A、落账写 B」,两边都看不出错,"
1207
1249
  "而平台重投照样被挡。进程级,`/clear` 不清(`core/dedup.clear()` 的注释)"),
1250
+ ProcessState(
1251
+ "_vision_warned", "core/computer/tools.py::_vision_warned",
1252
+ "只增不减的集合;无锁(并发最坏是多打一行控制台)",
1253
+ "★ 噪声抑制账本:'这个模型的视觉能力没有记录'每个模型只喊一次。"
1254
+ "进程级,与哪条会话无关;`/clear` 不清(清了只会多喊一遍)"),
1255
+ ProcessState(
1256
+ "_CACHE", "core/vision_budget.py::_CACHE",
1257
+ "★ **一把模块内锁(`_LOCK`)** —— 读与写都在锁内(`_read_json` / `_model_config`)",
1258
+ "★ 表文件的 (mtime, 内容) 缓存,按绝对路径键。进程级只读缓存;"
1259
+ "`reset_cache()` 给测试用,运行期不清"),
1260
+ ProcessState(
1261
+ "policy_cache", "core/cache_policies.py::_CACHE",
1262
+ "★ **一把模块内可重入锁(`_LOCK`)** —— 读与写都在锁内(`_read_table` / `_model_config`)",
1263
+ "★ 策略表与 config.yaml 的 (mtime, 内容) 缓存,按绝对路径键。"
1264
+ "进程级只读缓存;`reset_cache()` 给测试用,运行期不清"),
1265
+ ProcessState(
1266
+ "model_profile_cache", "core/model_profiles.py::_CACHE",
1267
+ "★ **一把模块内可重入锁(`_LOCK`)** —— 读与写都在锁内(`_read_table`)",
1268
+ "★ 模型能力差异表的 (mtime, 内容) 缓存,按绝对路径键。"
1269
+ "进程级只读缓存;`reset_cache()` 给测试用,运行期不清"),
1208
1270
  )
1209
1271
 
1210
1272
 
package/core/subagent.py CHANGED
@@ -346,6 +346,23 @@ def _sanitize_report(text: str) -> str:
346
346
  return text
347
347
 
348
348
 
349
+ def _child_thinking(snapshot, provider):
350
+ """子的思考档:同模型完全照父(前缀同源),跨模型才按子画像回落。"""
351
+ parent = tiers.current_spec(snapshot.session_id).thinking
352
+ child_model = str(getattr(provider, "_model", "") or "")
353
+ if not child_model or child_model == getattr(snapshot, "model", ""):
354
+ return parent
355
+ from core import model_profiles as _profiles
356
+ efforts = _profiles.resolve(
357
+ str(getattr(provider, "_provider_name", "") or ""),
358
+ child_model).thinking.get("efforts") or []
359
+ if parent is None or not isinstance(parent, str):
360
+ return parent
361
+ if parent in efforts:
362
+ return parent
363
+ return efforts[0] if efforts else None
364
+
365
+
349
366
  def run_child(*, snapshot, assistant_msg: dict, task: str, provider,
350
367
  max_turns: int, readonly_mode: bool = False,
351
368
  emit: Callable | None = None,
@@ -446,7 +463,7 @@ def run_child(*, snapshot, assistant_msg: dict, task: str, provider,
446
463
  system=snapshot.system, tools=snapshot.tools,
447
464
  force=force, threshold=_FORCE_RATIO)
448
465
  except Exception as exc: # noqa: BLE001 —— 压缩失败不该弄挂子这一趟
449
- print(f"[subagent] 上下文压缩失败({type(exc).__name__}: {exc})")
466
+ print(f"[subagent] context compression failed ({type(exc).__name__}: {exc})")
450
467
  return None
451
468
  return new if done else None
452
469
 
@@ -476,10 +493,10 @@ def run_child(*, snapshot, assistant_msg: dict, task: str, provider,
476
493
  _tools=snapshot.tools,
477
494
  _system=snapshot.system,
478
495
  # 第四个必须同源的 —— 思考模式进提示缓存键
479
- # (五项 cacheSafeParams 之一),子要是按自己的默认
480
- # 发,第一条请求的前缀就从最前面断了,fork 那台机器白搭。
481
- # 取自同一个会话的档(`snapshot.session_id`),不是另读一次设置。
482
- thinking=tiers.current_spec(snapshot.session_id).thinking,
496
+ # (五项 cacheSafeParams 之一)。同模型时逐字沿用父档,
497
+ # fork 那台机器才不白搭;跨模型时父那档可能子模型不认,
498
+ # 才按子画像回落(这时前缀本来就不共享,不损失缓存)。
499
+ thinking=_child_thinking(snapshot, provider),
483
500
  _emit=None, # v0:子的轮次事件不进父的时间线(轮号会串)
484
501
  # 任务级取消令牌:取消一个后台子 agent
485
502
  # 只停它,不动父那一轮(会话级 `is_cancelled` 仍在)。
@@ -511,7 +528,13 @@ def run_child(*, snapshot, assistant_msg: dict, task: str, provider,
511
528
  text = EMPTY_OUTPUT
512
529
  # `WB5`:回父之前先"去毒"(确定性那半永远跑,见 `_sanitize_report`)
513
530
  text = _sanitize_report(text)
531
+ # 回报带上实际用的模型:父拿到结果时才知道这段是谁说的,
532
+ # 跨模型 fork 的前缀假设也才能被外部判定(同模型才同前缀)。
533
+ _child_model = str(getattr(provider, "_model", "") or "")
534
+ _same_model = (_child_model == getattr(snapshot, "model", _child_model))
514
535
  return {"success": True, "output": text, "tokens": tokens,
536
+ "model": _child_model,
537
+ "same_model_as_parent": _same_model,
515
538
  "note": "子 agent 的过程、工具输出与推理都没有回传,只有上面这段话"}
516
539
 
517
540
 
@@ -84,7 +84,7 @@ def agent_roots() -> list[Path]:
84
84
  from core import plugin_packages
85
85
  roots.extend(plugin_packages.agents_dirs())
86
86
  except Exception as exc: # noqa: BLE001
87
- print("[subagent] 读取插件包失败:%s: %s" % (type(exc).__name__, exc))
87
+ print("[subagent] read plugin packs failed: %s: %s" % (type(exc).__name__, exc))
88
88
  out: list[Path] = []
89
89
  seen: set[str] = set()
90
90
  for r in roots:
@@ -112,14 +112,14 @@ def _parse(path: Path) -> Optional[SubagentDef]:
112
112
  import yaml
113
113
  meta = yaml.safe_load(m.group(1))
114
114
  except Exception: # noqa: BLE001
115
- print("[subagent] 跳过 %s:frontmatter 无法解析" % path)
115
+ print("[subagent] skipping %s: frontmatter unparsable" % path)
116
116
  return None
117
117
  if not isinstance(meta, dict):
118
118
  return None
119
119
 
120
120
  name = str(meta.get("name") or path.stem).strip()
121
121
  if not _NAME_RE.match(name):
122
- print("[subagent] 跳过 %s:名字不合法(%r)" % (path, name))
122
+ print("[subagent] skipping %s: invalid name (%r)" % (path, name))
123
123
  return None
124
124
  description = str(meta.get("description") or "").strip()
125
125
 
@@ -78,7 +78,7 @@ def load_cached(key: str) -> Optional[str]:
78
78
  data = json.loads(p.read_text(encoding="utf-8"))
79
79
  except Exception as e:
80
80
  # 出声但继续 —— 缓存是加速器,不是正确性的一部分(判据 ②)。
81
- print(f"[summarizer] 缓存读不动({type(e).__name__}: {e})—— 按没缓存算")
81
+ print(f"[summarizer] cache read failed ({type(e).__name__}: {e}) - treating as no cache")
82
82
  return None
83
83
  text = data.get("text") if isinstance(data, dict) else None
84
84
  if isinstance(text, str) and text.strip():
@@ -104,7 +104,7 @@ def save_cached(key: str, text: str) -> None:
104
104
  os.replace(tmp, final)
105
105
  _evict()
106
106
  except Exception as e:
107
- print(f"[summarizer] 缓存写不下去({type(e).__name__}: {e})—— 这次不缓存")
107
+ print(f"[summarizer] cache write failed ({type(e).__name__}: {e}) - not caching this time")
108
108
 
109
109
 
110
110
  def _evict() -> None:
@@ -197,7 +197,7 @@ def iterative_summarize(
197
197
  merge_batch_size, _model)
198
198
  _hit = load_cached(_key)
199
199
  if _hit is not None:
200
- print(f"[summarizer] 命中缓存({_key[:12]}…)—— **0 次 LLM 调用**")
200
+ print(f"[summarizer] cache hit ({_key[:12]}...) - 0 LLM calls")
201
201
  return _hit
202
202
  _result = _summarize_uncached(
203
203
  chunks, llm_client, summary_prompt,
@@ -224,8 +224,7 @@ def _summarize_uncached(
224
224
  _budget = _single_call_char_budget(llm_client)
225
225
  _total_chars = sum(len(c.get("text", "")) for c in chunks)
226
226
  if _budget and _total_chars <= _budget:
227
- print(f"[summarizer] 文档 {_total_chars:,} 字符 ≤ 单次预算 {_budget:,} "
228
- f"—— 一次调用完成(跳过 map-reduce)")
227
+ print(f"[summarizer] document {_total_chars:,} chars <= single-call budget {_budget:,} - done in one call (map-reduce skipped)")
229
228
  return _summarize_single(
230
229
  llm_client,
231
230
  system_prompt=summary_prompt,
@@ -197,14 +197,14 @@ def _default_deliver(session: MessageSession, text: str) -> None:
197
197
  from core.cron.runner import resolve_channel
198
198
  ch = resolve_channel(session.platform)
199
199
  if ch is None:
200
- print("[tasks] 后台回报投不出去:%s 通道没在跑" % session.platform)
200
+ print("[tasks] background report not deliverable: %s channel not running" % session.platform)
201
201
  return
202
202
  #: 回执契约:只有 `True` 才算送达(见 `channels/base.py::send`)。
203
203
  #: 同一条判据在 `cron/runner.py::_deliver`;两处都是"没声张的成功"的入口。
204
204
  if asyncio.run(ch.send(session, text[:4000])) is not True:
205
- print("[tasks] 后台回报投递失败:%s 通道报告未送达" % session.platform)
205
+ print("[tasks] background report delivery failed: %s channel reported undelivered" % session.platform)
206
206
  except Exception as exc: # noqa: BLE001
207
- print("[tasks] 后台回报投递失败(%s: %s)"
207
+ print("[tasks] background report delivery failed (%s: %s)"
208
208
  % (type(exc).__name__, exc))
209
209
 
210
210
 
@@ -288,10 +288,10 @@ def _run_turn(key: str, item: dict, scheduler, deliver) -> None:
288
288
  try:
289
289
  deliver(event.session, text or "")
290
290
  except Exception as exc: # noqa: BLE001
291
- print("[tasks] 后台轮回复投递失败(%s: %s)"
291
+ print("[tasks] background turn reply delivery failed (%s: %s)"
292
292
  % (type(exc).__name__, exc))
293
293
  except Exception as exc: # noqa: BLE001
294
- print("[tasks] 后台通知起轮失败(%s: %s)"
294
+ print("[tasks] background notification turn start failed (%s: %s)"
295
295
  % (type(exc).__name__, exc))
296
296
  finally:
297
297
  with _lock:
@@ -333,7 +333,7 @@ def _dispatcher() -> None:
333
333
  try:
334
334
  dispatch_once()
335
335
  except Exception as exc: # noqa: BLE001
336
- print("[tasks] 通知调度失败(%s: %s)" % (type(exc).__name__, exc))
336
+ print("[tasks] notification dispatch failed (%s: %s)" % (type(exc).__name__, exc))
337
337
 
338
338
 
339
339
  def install(scheduler, deliver: Optional[Callable] = None,
package/core/tiers.py CHANGED
@@ -515,7 +515,7 @@ def current_level(session_id: str = "") -> int:
515
515
  level = configured_level()
516
516
  _frozen[key] = level
517
517
  # 出声(一次会话一行):改档是冷启动这件事得看得见。
518
- print("[tier] 投入档 %d(%s)—— 本会话冻结" % (level, TIERS[level].name))
518
+ print("[tier] effort level %d (%s) - frozen for this session" % (level, TIERS[level].name))
519
519
  return level
520
520
 
521
521
 
@@ -594,7 +594,7 @@ def set_level(session_id: str, level: int) -> None:
594
594
  key = session_id or ""
595
595
  with _freeze_lock:
596
596
  _frozen[key] = int(level)
597
- print("[tier] 投入档 → %d(%s)—— 本会话,**不落盘**"
597
+ print("[tier] effort level -> %d (%s) - this session only, not persisted"
598
598
  % (int(level), TIERS[int(level)].name))
599
599
 
600
600
 
package/core/todos.py CHANGED
@@ -180,7 +180,7 @@ def todo_write(todos=None) -> dict:
180
180
 
181
181
  _todos[session_id] = items
182
182
  in_progress = sum(1 for it in items if it["status"] == "in_progress")
183
- print("[todo] %d 项(%d 进行中)session=%s"
183
+ print("[todo] %d items (%d in progress) session=%s"
184
184
  % (len(items), in_progress, session_id or "-"))
185
185
  return {
186
186
  "success": True,
@@ -141,10 +141,7 @@ class TokenCalibrator:
141
141
  scheme = entry.get("scheme")
142
142
  if scheme != self.ESTIMATOR_SCHEME:
143
143
  print(
144
- f"[calibrator] 丢弃 {self._provider} 的旧样本 "
145
- f"({entry.get('samples')} 个, ema={entry.get('ema')}, "
146
- f"scheme={scheme!r} != {self.ESTIMATOR_SCHEME}): "
147
- f"估算器口径变了,旧样本是另一个量的样本"
144
+ f"[calibrator] discarding old samples for {self._provider} ({entry.get('samples')}, ema={entry.get('ema')}, scheme={scheme!r} != {self.ESTIMATOR_SCHEME}): estimator scheme changed, old samples measured a different quantity"
148
145
  )
149
146
  return False
150
147
  self._ema = float(entry.get("ema", 1.0))