@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
@@ -1,93 +1,93 @@
1
- kind: skill
2
- name: media_gen
3
- version: "0.1.0"
4
- draft: false
5
- load_strategy: on_demand
6
- description: "生图 —— 厂商直连(OpenAI 兼容 /images/generations),产出直接进聊天区"
7
- # 技能页卡片上那句短简介,与 `description` 分开。
8
- summary: "图视频拓展"
9
-
10
- # 契约声明。
11
- # · `api` 只在破坏性变更时 +1(加能力不算);
12
- # · `requires` 里的每个名字都是 `core/capabilities.py` 的 `CAPABILITIES` 里的一项,
13
- # 缺一项就不装载,并说清缺什么(不半残)。
14
- api: 1
15
- requires:
16
- - artifacts
17
- - artifacts.inline # 产物记录带 `inline`:大图给下载行而不是硬塞 <img>
18
- - workspace # 落点走 primary_output_dir(本 skill 唯一的写路径口径)
19
-
20
- # 配置需求(与上面那根轴不同:`requires` 缺了不装载,这个缺了照样装,
21
- # 只是医生报 WARN、工具失败带 `/config media_gen` 路线)。
22
- requires_config:
23
- - media_gen
24
-
25
- # 本技能的工具不需要自动模式再判一遍:
26
- # · 它写的文件在工作区里、可逆、一次一个;
27
- # · 花费是用户自己的事,弹窗拦不住任何真风险,只会让"画张图"每次都停一下。
28
- # 没有这一行的话,每调一次都过分类器(要花钱的 token),而且会被
29
- # `test_auto_review` 当场点名(它要求每个走到第 ④ 层的工具做过决定)。
30
- review_input: none
31
-
32
- # 配置不在这里:凭据在 `data/media_gen_credentials.json`(不进 settings.json,
33
- # 也不进导出包)。这里只声明"有哪些条目、字段长什么样"给界面用。
34
- settings:
35
- # 整份配置住在这个文件里,所以凭据天然不进 `settings.json`(导出也不带走)。
36
- # 路径相对仓库根;`core/skill_settings.py` 是读写它的唯一入口(校验 + 打码 + 原子写)。
37
- storage: data/media_gen_credentials.json
38
- type: object
39
- properties:
40
- default:
41
- type: string
42
- title: 默认条目
43
- description: 不指定 entry 时用哪一条。
44
- entries:
45
- type: object
46
- title: 配置条目
47
- description: 键是条目名;值见下面三个字段。
48
- additionalProperties:
49
- type: object
50
- properties:
51
- type:
52
- type: string
53
- title: 类型
54
- enum: [vendor, local]
55
- default: vendor
56
- description: "vendor = 厂商直连(走 /images/generations);local = 本机 SD WebUI(走 /sdapi/v1/txt2img,只允许回环地址)"
57
- base_url:
58
- type: string
59
- title: 请求地址
60
- description: 请填写至API根
61
- model:
62
- type: string
63
- title: 模型名
64
- api_key:
65
- type: string
66
- title: API Key
67
- format: password
68
- x-secret: true # 声明为敏感:界面打码、不进 settings.json
69
-
70
- tools:
71
- - name: generate_image
72
- permission: write
73
- destructive: false
74
- output_kind: structured
75
- description: >
76
- 生成一张图片并保存到工作区(产出的图会直接显示在聊天里)。
77
- 需要先在生图配置里建一条(地址 + 模型名 + API Key)。
78
- 一次只生一张;要几张就调几次。提示词写清楚画面内容,
79
- 英文通常更稳。只用它来"从无到有画一张"——读图、改图、识别不走这里。
80
- inputSchema:
81
- $schema: "https://json-schema.org/draft/2020-12/schema"
82
- type: object
83
- properties:
84
- prompt:
85
- type: string
86
- description: "画面描述(要画什么、风格、构图)"
87
- size:
88
- type: string
89
- description: "尺寸,如 1024x1024 或 2K;不填用服务默认"
90
- entry:
91
- type: string
92
- description: "用哪一条配置;不填用默认那条"
93
- required: [prompt]
1
+ kind: skill
2
+ name: media_gen
3
+ version: "0.1.0"
4
+ draft: false
5
+ load_strategy: on_demand
6
+ description: "生图 —— 厂商直连(OpenAI 兼容 /images/generations),产出直接进聊天区"
7
+ # 技能页卡片上那句短简介,与 `description` 分开。
8
+ summary: "图视频拓展"
9
+
10
+ # 契约声明。
11
+ # · `api` 只在破坏性变更时 +1(加能力不算);
12
+ # · `requires` 里的每个名字都是 `core/capabilities.py` 的 `CAPABILITIES` 里的一项,
13
+ # 缺一项就不装载,并说清缺什么(不半残)。
14
+ api: 1
15
+ requires:
16
+ - artifacts
17
+ - artifacts.inline # 产物记录带 `inline`:大图给下载行而不是硬塞 <img>
18
+ - workspace # 落点走 primary_output_dir(本 skill 唯一的写路径口径)
19
+
20
+ # 配置需求(与上面那根轴不同:`requires` 缺了不装载,这个缺了照样装,
21
+ # 只是医生报 WARN、工具失败带 `/config media_gen` 路线)。
22
+ requires_config:
23
+ - media_gen
24
+
25
+ # 本技能的工具不需要自动模式再判一遍:
26
+ # · 它写的文件在工作区里、可逆、一次一个;
27
+ # · 花费是用户自己的事,弹窗拦不住任何真风险,只会让"画张图"每次都停一下。
28
+ # 没有这一行的话,每调一次都过分类器(要花钱的 token),而且会被
29
+ # `test_auto_review` 当场点名(它要求每个走到第 ④ 层的工具做过决定)。
30
+ review_input: none
31
+
32
+ # 配置不在这里:凭据在 `data/media_gen_credentials.json`(不进 settings.json,
33
+ # 也不进导出包)。这里只声明"有哪些条目、字段长什么样"给界面用。
34
+ settings:
35
+ # 整份配置住在这个文件里,所以凭据天然不进 `settings.json`(导出也不带走)。
36
+ # 路径相对仓库根;`core/skill_settings.py` 是读写它的唯一入口(校验 + 打码 + 原子写)。
37
+ storage: data/media_gen_credentials.json
38
+ type: object
39
+ properties:
40
+ default:
41
+ type: string
42
+ title: 默认条目
43
+ description: 不指定 entry 时用哪一条。
44
+ entries:
45
+ type: object
46
+ title: 配置条目
47
+ description: 键是条目名;值见下面三个字段。
48
+ additionalProperties:
49
+ type: object
50
+ properties:
51
+ type:
52
+ type: string
53
+ title: 类型
54
+ enum: [vendor, local]
55
+ default: vendor
56
+ description: "vendor = 厂商直连(走 /images/generations);local = 本机 SD WebUI(走 /sdapi/v1/txt2img,只允许回环地址)"
57
+ base_url:
58
+ type: string
59
+ title: 请求地址
60
+ description: 请填写至API根
61
+ model:
62
+ type: string
63
+ title: 模型名
64
+ api_key:
65
+ type: string
66
+ title: API Key
67
+ format: password
68
+ x-secret: true # 声明为敏感:界面打码、不进 settings.json
69
+
70
+ tools:
71
+ - name: generate_image
72
+ permission: write
73
+ destructive: false
74
+ output_kind: structured
75
+ description: >
76
+ 生成一张图片并保存到工作区(产出的图会直接显示在聊天里)。
77
+ 需要先在生图配置里建一条(地址 + 模型名 + API Key)。
78
+ 一次只生一张;要几张就调几次。提示词写清楚画面内容,
79
+ 英文通常更稳。只用它来"从无到有画一张"——读图、改图、识别不走这里。
80
+ inputSchema:
81
+ $schema: "https://json-schema.org/draft/2020-12/schema"
82
+ type: object
83
+ properties:
84
+ prompt:
85
+ type: string
86
+ description: "画面描述(要画什么、风格、构图)"
87
+ size:
88
+ type: string
89
+ description: "尺寸,如 1024x1024 或 2K;不填用服务默认"
90
+ entry:
91
+ type: string
92
+ description: "用哪一条配置;不填用默认那条"
93
+ required: [prompt]
@@ -0,0 +1,45 @@
1
+ ---
2
+ name: netops
3
+ description: Structured, cross-platform network diagnostics — local interfaces, routing table, DNS records, port reachability, and HTTP/TLS probes with a single JSON envelope. Use when the user asks to inspect network configuration, diagnose connectivity, check DNS, test whether a port is open, or probe an HTTP endpoint. Read-only; does not replace run_command for arbitrary commands.
4
+ metadata:
5
+ kind: skill
6
+ loader: manifest.yaml
7
+ tools: net_ifaces, net_routes, net_dns, net_ports, net_http_probe
8
+ ---
9
+
10
+ # 网络诊断(netops)
11
+
12
+ 把日常排障里"同一个命令在不同机器输出不同"的那部分做成统一回执。
13
+ **只读诊断**,不改配置、不发写请求。
14
+
15
+ ## 什么时候用
16
+
17
+ - 看网卡 / IP / 网关 / 速率 ⇒ `net_ifaces`
18
+ - 跨网段不通、怀疑路由写错 ⇒ `net_routes`(先看路由,再 tracert)
19
+ - 域名解析 / TTL / CNAME ⇒ `net_dns`
20
+ - 某主机端口通不通 ⇒ `net_ports`(给明确列表,不扫网段)
21
+ - HTTP 状态 / 重定向 / 证书 / 安全头 ⇒ `net_http_probe`
22
+
23
+ ## 什么时候不用
24
+
25
+ - 用户要**跑任意命令**(ping 连续发包、traceroute 完整路径、tcpdump 抓包)⇒
26
+ 用 `run_command` 或 `computer`,本工具集只做结构化归一化
27
+ - 要**改配置 / 登录远端** ⇒ SSH skill(单独配置)或 run_command
28
+
29
+ ## 回执
30
+
31
+ 所有工具返回同一形状:
32
+
33
+ ```json
34
+ {"success": true, "tool": "net_ports", "data": {...},
35
+ "error": "", "duration_ms": 123, "truncated": false}
36
+ ```
37
+
38
+ `error` 非空即失败;`truncated=true` 表示结果被截断(端口最多 64 个)。
39
+ 每次调用自动进框架审计日志。
40
+
41
+ ## 边界
42
+
43
+ - 完全权限解禁对这些工具没有额外意义——它们本来就只读
44
+ - `net_http_probe` 走 httpx(不做写请求),证书取不到时回执里给原因,不静默
45
+ - `net_dns` 在 dnspython 缺失时降级为系统解析(无 TTL),回执标 `degraded`
@@ -0,0 +1 @@
1
+ """网络诊断脚手架 —— 内部工具集(技能页不显示)。"""
@@ -0,0 +1,418 @@
1
+ # -*- coding: utf-8 -*-
2
+ """网络诊断脚手架 —— 把命令输出归一化成 LLM 能稳定消费的 JSON。
3
+
4
+ 为什么不是直接跑命令:同一个 ping/traceroute/dig,Windows 与 Linux 的命令名、
5
+ 参数、输出格式都不同。模型手搓会得到三种结果。这里吃掉平台差异,
6
+ 输出统一 envelope;裸命令仍可走 run_command,本工具集是增量而非替代。
7
+
8
+ 依赖:psutil/httpx 已在 requirements;DNS 完整查询用 dnspython(ISC)。
9
+ 只做只读诊断。写操作(SSH/配置)不在这里。
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import ipaddress
15
+ import re
16
+ import socket
17
+ import subprocess
18
+ import sys
19
+ import time
20
+ from concurrent.futures import ThreadPoolExecutor, as_completed
21
+ from typing import Any
22
+
23
+ __all__ = ["init", "net_ifaces", "net_routes", "net_dns", "net_ports",
24
+ "net_http_probe"]
25
+
26
+ DEFAULT_TIMEOUT = 3.0
27
+ MAX_PORTS = 64
28
+ MAX_BODY = 32 * 1024
29
+
30
+
31
+ #: 由 `bus` 在装载时注入。
32
+ _guard = None
33
+
34
+
35
+ def init(security_guard=None) -> None:
36
+ global _guard
37
+ _guard = security_guard
38
+
39
+
40
+ def _audit(channel: str, target: str, action: str, verdict: str = "") -> None:
41
+ """写一行 EGRESS 审计(诊断类也要留痕 —— 决定 7:只审计、不弹窗)。"""
42
+ if _guard is None:
43
+ return
44
+ try:
45
+ _guard.record_egress(channel, target, action, "auto", verdict)
46
+ except Exception as exc: # noqa: BLE001
47
+ print(f"[netops] audit write failed ({type(exc).__name__}: {exc})")
48
+
49
+
50
+ def _ok(tool: str, data: dict, started: float, **extra) -> dict:
51
+ out = {"success": True, "tool": tool, "data": data, "error": "",
52
+ "duration_ms": int((time.monotonic() - started) * 1000)}
53
+ out.update(extra)
54
+ return out
55
+
56
+
57
+ def _err(tool: str, msg: str, started: float, **extra) -> dict:
58
+ out = {"success": False, "tool": tool, "data": {}, "error": msg,
59
+ "duration_ms": int((time.monotonic() - started) * 1000)}
60
+ out.update(extra)
61
+ return out
62
+
63
+
64
+ def _addr(nic: Any) -> str:
65
+ return str(getattr(nic, "address", "") or "")
66
+
67
+
68
+ # 工具
69
+
70
+ def net_ifaces() -> dict:
71
+ """网卡配置 —— Windows ipconfig / Linux ip addr 的统一形状。"""
72
+ t0 = time.monotonic()
73
+ try:
74
+ import psutil
75
+ addrs = psutil.net_if_addrs()
76
+ stats = psutil.net_if_stats()
77
+ out = []
78
+ for name, nics in addrs.items():
79
+ v4 = [_addr(n) for n in nics
80
+ if getattr(n, "family", None) == socket.AF_INET]
81
+ v6 = [_addr(n) for n in nics
82
+ if getattr(n, "family", None) == socket.AF_INET6]
83
+ mac = next((_addr(n) for n in nics
84
+ if getattr(n, "family", None) == getattr(psutil, "AF_LINK", -1)
85
+ or "MAC" in str(getattr(n, "family", ""))), "")
86
+ masks = [str(getattr(n, "netmask", "") or "")
87
+ for n in nics if getattr(n, "family", None) == socket.AF_INET]
88
+ st = stats.get(name)
89
+ out.append({
90
+ "name": name, "ipv4": v4, "ipv6": v6,
91
+ "netmask": masks[0] if masks else "", "mac": mac,
92
+ "is_up": bool(getattr(st, "isup", False)),
93
+ "speed_mbps": int(getattr(st, "speed", 0) or 0),
94
+ "mtu": int(getattr(st, "mtu", 0) or 0),
95
+ })
96
+ return _ok("net_ifaces", {"interfaces": out}, t0)
97
+ except Exception as exc: # noqa: BLE001
98
+ return _err("net_ifaces", "%s: %s" % (type(exc).__name__, exc), t0)
99
+
100
+
101
+ def net_routes() -> dict:
102
+ """路由表 —— psutil 没有路由 API,只能按平台解析系统命令/文件。
103
+
104
+ 路由是跨网段排障的关键(tracert 断在第一跳之外时,多半是路由写错),
105
+ 所以值得胶一层,而不是让模型分别记 route print / ip route。
106
+ """
107
+ t0 = time.monotonic()
108
+ try:
109
+ if sys.platform.startswith("linux"):
110
+ rows = _linux_routes()
111
+ elif sys.platform == "win32":
112
+ rows = _windows_routes()
113
+ else:
114
+ rows = _bsd_routes()
115
+ default = next((r for r in rows if r["dest"] in ("0.0.0.0", "::/0")), None)
116
+ return _ok("net_routes", {
117
+ "routes": rows,
118
+ "default_gateway": default["next_hop"] if default else "",
119
+ }, t0)
120
+ except Exception as exc: # noqa: BLE001
121
+ return _err("net_routes", "%s: %s" % (type(exc).__name__, exc), t0)
122
+
123
+
124
+ def _hex_ip(s: str) -> str:
125
+ try:
126
+ b = bytes.fromhex(s.strip())
127
+ if len(b) == 4:
128
+ return str(ipaddress.IPv4Address(b))
129
+ except Exception: # noqa: BLE001
130
+ pass
131
+ return s
132
+
133
+
134
+ def _linux_routes() -> list[dict]:
135
+ # /proc/net/route: iface dest mask gw flags refcnt use metric ...(hex 小端 IP)
136
+ rows = []
137
+ for line in open("/proc/net/route", encoding="utf-8", errors="replace").read().splitlines()[1:]:
138
+ f = line.split()
139
+ if len(f) < 8:
140
+ continue
141
+ dest_hex, mask_hex, gw_hex = f[1], f[2], f[3]
142
+ try:
143
+ mask_int = int(mask_hex, 16)
144
+ prefix = mask_int.bit_count()
145
+ except Exception: # noqa: BLE001
146
+ prefix = 0
147
+ rows.append({
148
+ "dest": "%s/%d" % (_hex_ip(dest_hex), prefix),
149
+ "next_hop": _hex_ip(gw_hex), "iface": f[0], "metric": int(f[6] or 0),
150
+ })
151
+ return rows
152
+
153
+
154
+ def _windows_routes() -> list[dict]:
155
+ out = subprocess.run(
156
+ ["route", "print", "0.0.0.0"], capture_output=True, text=True,
157
+ timeout=DEFAULT_TIMEOUT, errors="replace")
158
+ rows = []
159
+ for line in out.stdout.splitlines():
160
+ f = line.split()
161
+ # Windows 表:目标 掩码 网关 接口 跃点;只认以 IP 开头的行
162
+ if len(f) >= 5 and re.match(r"^\d+\.\d+\.\d+\.\d+", f[0]):
163
+ rows.append({"dest": f[0], "next_hop": f[2],
164
+ "iface": f[3], "metric": int(f[4] or 0)})
165
+ return rows
166
+
167
+
168
+ def _bsd_routes() -> list[dict]:
169
+ out = subprocess.run(["netstat", "-rn", "-f", "inet"],
170
+ capture_output=True, text=True,
171
+ timeout=DEFAULT_TIMEOUT, errors="replace")
172
+ rows = []
173
+ for line in out.stdout.splitlines():
174
+ f = line.split()
175
+ if len(f) >= 2 and re.match(r"^\d+\.\d+\.\d+\.\d+", f[0]):
176
+ rows.append({"dest": f[0], "next_hop": f[1],
177
+ "iface": f[-1], "metric": 0})
178
+ return rows
179
+
180
+
181
+ def net_dns(name: str, record_type: str = "A", timeout_s: float = 3.0) -> dict:
182
+ """DNS 查询 —— dig/nslookup 输出不一致,这里给统一 answer/TTL。
183
+
184
+ dnspython 缺失时降级到标准库(只给地址,无 TTL/类型链),并在回执里说清。
185
+ """
186
+ t0 = time.monotonic()
187
+ host = str(name or "").strip()
188
+ rtype = str(record_type or "A").strip().upper()
189
+ if not host:
190
+ return _err("net_dns", "name 不能为空", t0)
191
+ _audit("dns", host, "resolve")
192
+ try:
193
+ import dns.resolver
194
+ r = dns.resolver.Resolver()
195
+ r.timeout = float(timeout_s)
196
+ r.lifetime = float(timeout_s)
197
+ answers = []
198
+ try:
199
+ resp = r.resolve(host, rtype)
200
+ ttl = int(getattr(resp.rrset, "ttl", 0) or 0)
201
+ answers = [{"type": rtype, "value": str(x), "ttl": ttl} for x in resp]
202
+ canonical = str(getattr(resp, "canonical_name", "") or host)
203
+ except dns.resolver.NXDOMAIN:
204
+ return _ok("net_dns", {"name": host, "type": rtype,
205
+ "answers": [], "status": "NXDOMAIN"}, t0)
206
+ except dns.resolver.NoAnswer:
207
+ canonical = host
208
+ return _ok("net_dns", {
209
+ "name": host, "type": rtype, "answers": answers,
210
+ "canonical": canonical, "resolver": str(r.nameservers[0]),
211
+ "status": "OK" if answers else "NO_ANSWER",
212
+ }, t0)
213
+ except ImportError:
214
+ try:
215
+ infos = socket.getaddrinfo(host, None, family=socket.AF_UNSPEC)
216
+ vals = sorted({x[4][0] for x in infos})
217
+ return _ok("net_dns", {
218
+ "name": host, "type": rtype,
219
+ "answers": [{"type": "ADDR", "value": v, "ttl": 0} for v in vals],
220
+ "resolver": "system", "status": "OK",
221
+ "degraded": "dnspython 未装:无 TTL/记录类型,只有解析地址",
222
+ }, t0)
223
+ except Exception as exc: # noqa: BLE001
224
+ return _err("net_dns", "解析失败:%s" % exc, t0)
225
+ except Exception as exc: # noqa: BLE001
226
+ return _err("net_dns", "%s: %s" % (type(exc).__name__, exc), t0)
227
+
228
+
229
+ def net_ports(host: str, ports: Any = None, timeout_s: float = 1.5,
230
+ max_workers: int = 16) -> dict:
231
+ """给定端口列表的连通性 —— 并发 + 超时 + 统一回执。
232
+
233
+ 只探测用户给的端口,不做网段扫描;nc 被 deny 档拦,正好由这里提供正规路。
234
+ """
235
+ t0 = time.monotonic()
236
+ target = str(host or "").strip()
237
+ if not target:
238
+ return _err("net_ports", "host 不能为空", t0)
239
+ if isinstance(ports, str):
240
+ parts = re.split(r"[,\s]+", ports.strip())
241
+ else:
242
+ parts = [str(p) for p in (ports or [])]
243
+ nums = []
244
+ for p in parts:
245
+ try:
246
+ n = int(p)
247
+ except (TypeError, ValueError):
248
+ continue
249
+ if 1 <= n <= 65535 and n not in nums:
250
+ nums.append(n)
251
+ if not nums:
252
+ return _err("net_ports", "没有有效端口(1–65535)", t0)
253
+ _audit("tcp", target, "ports:%d" % len(nums))
254
+ if len(nums) > MAX_PORTS:
255
+ nums = nums[:MAX_PORTS]
256
+ truncated = True
257
+ else:
258
+ truncated = False
259
+
260
+ def probe(port: int) -> dict:
261
+ try:
262
+ with socket.create_connection((target, port), timeout=float(timeout_s)):
263
+ return {"port": port, "open": True, "service": ""}
264
+ except OSError:
265
+ return {"port": port, "open": False, "service": ""}
266
+
267
+ results = []
268
+ with ThreadPoolExecutor(max_workers=max(1, min(32, int(max_workers)))) as ex:
269
+ futs = {ex.submit(probe, p): p for p in nums}
270
+ for fut in as_completed(futs):
271
+ try:
272
+ results.append(fut.result())
273
+ except Exception: # noqa: BLE001
274
+ results.append({"port": futs[fut], "open": False, "service": ""})
275
+ results.sort(key=lambda r: r["port"])
276
+ return _ok("net_ports", {"host": target, "results": results}, t0,
277
+ truncated=truncated)
278
+
279
+
280
+ def _cert_fields(der: bytes) -> dict:
281
+ """一张 DER 证书的三个字段(cryptography 解;解不开返回空表)。"""
282
+ try:
283
+ from cryptography import x509
284
+ c = x509.load_der_x509_certificate(der)
285
+ return {
286
+ "subject": c.subject.rfc4514_string(),
287
+ "issuer": c.issuer.rfc4514_string(),
288
+ "not_before": c.not_valid_before_utc.isoformat(),
289
+ "not_after": c.not_valid_after_utc.isoformat(),
290
+ }
291
+ except Exception: # noqa: BLE001
292
+ return {}
293
+
294
+
295
+ def _tls_report(host: str, port: int, timeout: float) -> dict:
296
+ """TLS 明细:版本 / 叶子证书 / 链条 / 校验失败原因。
297
+
298
+ 请求本身仍然 verify=True(这里不提供关闭开关)。
299
+ 校验失败时另开一条不校验的诊断连接取链,并在回执里标注来源。
300
+ """
301
+ import ssl
302
+
303
+ out: dict = {}
304
+
305
+ def _chain_of(sock) -> list:
306
+ try:
307
+ certs = sock.get_verified_chain() or []
308
+ except Exception: # noqa: BLE001
309
+ return []
310
+ rows = []
311
+ for c in certs:
312
+ try:
313
+ der = c.public_bytes(ssl.ENCODING_DER)
314
+ except Exception: # noqa: BLE001
315
+ continue
316
+ row = _cert_fields(der)
317
+ if row:
318
+ rows.append(row)
319
+ return rows
320
+
321
+ try:
322
+ ctx = ssl.create_default_context()
323
+ with socket.create_connection((host, int(port)), timeout=timeout) as raw:
324
+ with ctx.wrap_socket(raw, server_hostname=host) as sock:
325
+ cert = sock.getpeercert() or {}
326
+ out.update({
327
+ "version": sock.version() or "",
328
+ "issuer": dict(x[0] for x in cert.get("issuer", ())),
329
+ "not_after": cert.get("notAfter", ""),
330
+ "not_before": cert.get("notBefore", ""),
331
+ "subject_alt_names": [v for _, v in
332
+ cert.get("subjectAltName", ())],
333
+ })
334
+ chain = _chain_of(sock)
335
+ if chain:
336
+ out["chain"] = chain
337
+ else:
338
+ out["chain_incomplete"] = True
339
+ return out
340
+ except ssl.SSLCertVerificationError as exc:
341
+ out["verify_error"] = {
342
+ "code": int(getattr(exc, "verify_code", 0) or 0),
343
+ "message": str(getattr(exc, "verify_message", "") or exc),
344
+ }
345
+ except Exception as exc: # noqa: BLE001
346
+ out["error"] = "%s: %s" % (type(exc).__name__, exc)
347
+ return out
348
+
349
+ # 校验失败了:另开一条不校验的连接取链 —— 只为诊断展示,请求仍是 verify=True。
350
+ try:
351
+ ctx2 = ssl._create_unverified_context()
352
+ with socket.create_connection((host, int(port)), timeout=timeout) as raw:
353
+ with ctx2.wrap_socket(raw, server_hostname=host) as sock:
354
+ chain = _chain_of(sock)
355
+ if chain:
356
+ out["chain"] = chain
357
+ out["chain_note"] = "证书链取自一次不校验的诊断连接(仅用于展示)"
358
+ except Exception: # noqa: BLE001
359
+ pass
360
+ return out
361
+
362
+
363
+ def _proxy_report() -> dict:
364
+ """这一跳实际走的代理档(地址打码)。
365
+
366
+ mode 是设置里的三档(system / direct / manual);effective 是这一刻
367
+ 真正走的东西(打码后的地址,或 direct)。
368
+ """
369
+ try:
370
+ from core import net_proxy as _np
371
+ d = _np.describe()
372
+ eff = str(d.get("effective") or "")
373
+ return {"mode": d.get("mode") or "", "effective": bool(eff and eff != "direct"),
374
+ "effective_url": eff, "source": d.get("source") or "",
375
+ "hint": d.get("hint") or ""}
376
+ except Exception as exc: # noqa: BLE001
377
+ return {"error": "%s: %s" % (type(exc).__name__, exc)}
378
+
379
+
380
+ def net_http_probe(url: str, timeout_s: float = 8.0) -> dict:
381
+ """HTTP 探针 —— 状态码/重定向链/TLS 有效期/安全头。
382
+
383
+ 比 curl 包一层好在:输出结构化、异常统一、跨平台一致;curl 在 deny 档。
384
+ """
385
+ t0 = time.monotonic()
386
+ u = str(url or "").strip()
387
+ if not u.lower().startswith(("http://", "https://")):
388
+ return _err("net_http_probe", "url 必须以 http:// 或 https:// 开头", t0)
389
+ from core.egress_gate import host_of
390
+ _audit("http", host_of(u) or u, "probe")
391
+ try:
392
+ import httpx
393
+ # 代理跟随设置页那一档(全仓造客户端的地方都经过 core/net_proxy)。
394
+ from core import net_proxy as _np
395
+ with _np.httpx_client(httpx.Client, url=u, timeout=float(timeout_s),
396
+ follow_redirects=True, verify=True) as client:
397
+ resp = client.get(u)
398
+ chain = [{"status": h.status_code, "url": str(h.headers.get("location", ""))}
399
+ for h in resp.history]
400
+ sec_headers = {k: v for k, v in resp.headers.items()
401
+ if k.lower() in ("content-security-policy",
402
+ "strict-transport-security",
403
+ "x-content-type-options",
404
+ "x-frame-options", "referrer-policy")}
405
+ tls: dict = {}
406
+ if u.lower().startswith("https://"):
407
+ tls = _tls_report(httpx.URL(u).host, 443, float(timeout_s))
408
+ return _ok("net_http_probe", {
409
+ "url": u, "status": resp.status_code,
410
+ "final_url": str(resp.url), "redirects": chain,
411
+ "http_version": resp.http_version,
412
+ "security_headers": sec_headers, "tls": tls,
413
+ "proxy": _proxy_report(),
414
+ "latency_ms": int((time.monotonic() - t0) * 1000),
415
+ "body_preview": resp.text[:512] if len(resp.text) <= MAX_BODY else "",
416
+ }, t0)
417
+ except Exception as exc: # noqa: BLE001
418
+ return _err("net_http_probe", "%s: %s" % (type(exc).__name__, exc), t0)