@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.
- package/LICENSE +201 -201
- package/NOTICE +48 -45
- package/README.md +1 -1
- package/THIRD-PARTY-FRONTEND.md +5266 -5266
- package/THIRD-PARTY-PYTHON-linux.md +174 -0
- package/THIRD-PARTY-PYTHON.md +176 -162
- package/THIRD-PARTY.md +323 -316
- package/apps/desktop/quotes.txt +56 -56
- package/bus/core.py +677 -671
- package/bus/loaders/channel_loader.py +64 -64
- package/bus/loaders/provider_loader.py +4 -7
- package/bus/loaders/skill_loader.py +46 -27
- package/bus/loaders/skill_md.py +9 -9
- package/bus/mcp_disabled.py +4 -6
- package/bus/quarantine.py +10 -13
- package/bus/registry.py +2315 -2284
- package/bus/skill_state.py +124 -124
- package/channels/cli_channel/handler.py +3 -3
- package/channels/cli_channel/manifest.yaml +5 -5
- package/channels/dingtalk_channel/handler.py +32 -32
- package/channels/dingtalk_channel/manifest.yaml +12 -12
- package/channels/feishu_channel/handler.py +33 -33
- package/channels/feishu_channel/manifest.yaml +12 -12
- package/channels/qq_bot_channel/__init__.py +1 -1
- package/channels/qq_bot_channel/handler.py +24 -24
- package/channels/qq_bot_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/__init__.py +1 -1
- package/channels/telegram_channel/handler.py +21 -21
- package/channels/telegram_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/media.py +231 -231
- package/channels/textfmt.py +58 -58
- package/channels/wechat_channel/__init__.py +1 -1
- package/channels/wechat_channel/converter.py +1 -1
- package/channels/wechat_channel/handler.py +8 -8
- package/channels/wechat_channel/manifest.yaml +5 -5
- package/channels/wechat_channel/media.py +178 -178
- package/core/activity.py +753 -709
- package/core/agent_loop.py +7673 -7523
- package/core/allowlist.py +2 -3
- package/core/approval.py +36 -26
- package/core/approval_timeout.py +256 -228
- package/core/artifacts.py +3 -3
- package/core/attachment_gc.py +21 -0
- package/core/auto_review.py +2 -2
- package/core/browser/cdp.py +5 -2
- package/core/browser/discover.py +55 -19
- package/core/browser/session.py +4 -4
- package/core/cache_break_detector.py +97 -0
- package/core/cache_breakpoints.py +103 -0
- package/core/cache_policies.py +255 -0
- package/core/cancellation.py +3 -3
- package/core/channel_configs.py +3 -3
- package/core/channel_turns.py +13 -13
- package/core/child_approval.py +2 -3
- package/core/code_intel.py +11 -11
- package/core/command_policy.py +13 -7
- package/core/computer/annotate.py +231 -11
- package/core/computer/capture.py +140 -1
- package/core/computer/guard.py +7 -4
- package/core/computer/input.py +452 -26
- package/core/computer/session.py +563 -381
- package/core/computer/tools.py +2170 -928
- package/core/computer/uia.py +100 -1
- package/core/computer/watch.py +1 -1
- package/core/computer/win32.py +302 -7
- package/core/config_requirements.py +205 -205
- package/core/cron/runner.py +4 -4
- package/core/daily_log.py +2 -2
- package/core/dedup.py +2 -2
- package/core/egress_channels.py +326 -0
- package/core/egress_gate.py +96 -8
- package/core/egress_preapproved.py +59 -3
- package/core/endpoint.py +141 -141
- package/core/events.py +17 -8
- package/core/extension.py +2 -2
- package/core/file_history.py +15 -15
- package/core/file_tools.py +3 -3
- package/core/github_config.py +1 -1
- package/core/group_digest.py +3 -4
- package/core/group_minutes.py +5 -5
- package/core/group_reply.py +24 -0
- package/core/groups.py +5 -9
- package/core/hooks.py +15 -15
- package/core/i18n.py +2 -2
- package/core/ice/canary.py +3 -3
- package/core/ice/net_heuristics.py +2 -2
- package/core/im_routing.py +3 -3
- package/core/image_input.py +183 -43
- package/core/inbound.py +3 -3
- package/core/jobs.py +6 -6
- package/core/last_good.py +150 -150
- package/core/leaf_md.py +3 -3
- package/core/llm_errors.py +37 -28
- package/core/mail_config.py +2 -2
- package/core/memory/compressor.py +8 -8
- package/core/memory/manager.py +30 -45
- package/core/memory/session_memory.py +1 -2
- package/core/memory/short_term.py +4 -4
- package/core/memory_extract.py +1 -1
- package/core/memory_organize.py +8 -8
- package/core/memory_store.py +7 -9
- package/core/memory_transfer.py +2 -2
- package/core/model_capabilities.py +2 -2
- package/core/model_configs.py +219 -68
- package/core/model_profiles.py +333 -0
- package/core/modes.py +12 -11
- package/core/net_proxy.py +3 -3
- package/core/pipeline/scheduler.py +48 -43
- package/core/pipeline/stage.py +3 -0
- package/core/pipeline/stages/agent_loop.py +36 -15
- package/core/pipeline/stages/group_reply.py +22 -20
- package/core/pipeline/stages/post_process.py +7 -7
- package/core/pipeline/stages/pre_process.py +369 -77
- package/core/prompt_assembler.py +13 -4
- package/core/recycle.py +227 -16
- package/core/response_language.py +1 -1
- package/core/retention.py +2 -2
- package/core/rg.py +4 -3
- package/core/security.py +26 -8
- package/core/services.py +8 -8
- package/core/session_model.py +3 -5
- package/core/session_pool.py +35 -5
- package/core/session_recap.py +40 -3
- package/core/session_workspace.py +2 -3
- package/core/settings_baseline.py +2 -2
- package/core/settings_transfer.py +25 -1
- package/core/shell.py +52 -20
- package/core/side_call.py +3 -3
- package/core/skill_config.py +164 -0
- package/core/skill_factory.py +2 -2
- package/core/skill_guidance.py +2 -4
- package/core/skill_index.py +3 -4
- package/core/skill_settings.py +1 -1
- package/core/skill_sources.py +7 -7
- package/core/ssh_config.py +129 -0
- package/core/state_registry.py +67 -5
- package/core/subagent.py +28 -5
- package/core/subagent_defs.py +3 -3
- package/core/summarizer.py +4 -5
- package/core/tasks_notify.py +6 -6
- package/core/tiers.py +2 -2
- package/core/todos.py +1 -1
- package/core/token_calibrator.py +1 -4
- package/core/tool_outcome.py +108 -108
- package/core/touched_files.py +1 -1
- package/core/trace.py +12 -3
- package/core/unlock.py +4 -4
- package/core/update_tui.py +184 -158
- package/core/updater.py +5 -3
- package/core/version.py +14 -14
- package/core/vision_budget.py +235 -0
- package/core/web_cache.py +152 -152
- package/core/web_request.py +474 -0
- package/core/window_estimate.py +1 -1
- package/core/workspace.py +56 -26
- package/crannia_tray.py +278 -278
- package/licenses/GPL-3.0.txt +619 -619
- package/licenses/LGPL-2.1.txt +502 -502
- package/licenses/LGPL-3.0.txt +165 -165
- package/licenses/MIT-chat-on-wechat.txt +18 -18
- package/licenses/MIT-deepseek-harness.txt +21 -21
- package/licenses/Molio-LICENSE.txt +44 -44
- package/locales/en.json +1876 -1762
- package/main.py +154 -154
- package/mcpx/client.py +12 -1
- package/mcpx/manager.py +530 -522
- package/mcpx/servers/web_search.py +5 -13
- package/package.json +15 -23
- package/providers/anthropic/client.py +35 -33
- package/providers/base.py +13 -13
- package/providers/cache_policies.json +294 -0
- package/providers/cost_table.json +3779 -3779
- package/providers/lmstudio/client.py +2 -2
- package/providers/model_capabilities.json +6665 -6665
- package/providers/model_profiles.json +629 -0
- package/providers/ollama/client.py +2 -2
- package/providers/openai_compat.py +37 -16
- package/providers/openrouter/client.py +2 -2
- package/providers/qwen/__init__.py +1 -1
- package/providers/qwen/client.py +2 -2
- package/providers/qwen/manifest.yaml +16 -16
- package/providers/rate_limiter.py +2 -2
- package/providers/siliconflow/client.py +2 -2
- package/providers/validation.py +171 -171
- package/providers/vision_profiles.json +89 -0
- package/providers/window_table.json +8909 -8909
- package/requirements.txt +59 -51
- package/sbom-linux-x64.json +4580 -0
- package/sbom.json +4600 -4413
- package/skills/diagram/SKILL.md +47 -0
- package/skills/diagram/__init__.py +1 -0
- package/skills/diagram/handler.py +294 -0
- package/skills/diagram/layout.py +174 -0
- package/skills/diagram/manifest.yaml +106 -0
- package/skills/diagram/mermaid.py +170 -0
- package/skills/diagram/svg.py +223 -0
- package/skills/entertainment/SKILL.md +35 -35
- package/skills/entertainment/__init__.py +1 -1
- package/skills/entertainment/handler.py +91 -91
- package/skills/entertainment/manifest.yaml +26 -26
- package/skills/file_parser/GUIDANCE.md +10 -10
- package/skills/file_parser/handler.py +33 -11
- package/skills/github/SKILL.md +32 -32
- package/skills/github/__init__.py +1 -1
- package/skills/mail_parser/SKILL.md +68 -68
- package/skills/mail_parser/__init__.py +1 -1
- package/skills/mail_parser/handler.py +1 -1
- package/skills/media_gen/GUIDANCE.md +19 -19
- package/skills/media_gen/SKILL.md +43 -43
- package/skills/media_gen/__init__.py +1 -1
- package/skills/media_gen/handler.py +1 -1
- package/skills/media_gen/manifest.yaml +93 -93
- package/skills/netops/SKILL.md +45 -0
- package/skills/netops/__init__.py +1 -0
- package/skills/netops/handler.py +418 -0
- package/skills/netops/manifest.yaml +118 -0
- package/skills/office_parser/_excel_io.py +3 -3
- package/skills/office_parser/handler.py +2 -2
- package/skills/office_parser/ppt_tools.py +1 -1
- package/skills/office_parser/pptx_export/console_encoding.py +27 -27
- package/skills/office_parser/pptx_export/resource_paths.py +88 -88
- package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -12
- package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
- package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -288
- package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -388
- package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -818
- package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -345
- package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -14
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -186
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -781
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/utils.py +40 -21
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -1267
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -155
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -101
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -236
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -257
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -136
- package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -44
- package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -129
- package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +20 -20
- package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -21
- package/skills/office_parser/references/layout_library.md +816 -816
- package/skills/office_parser/references/ppt-master/LICENSE +21 -21
- package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -474
- package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -1002
- package/skills/office_parser/references/ppt-master/references/strategist.md +880 -880
- package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -402
- package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -240
- package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -106
- package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -37
- package/skills/office_parser/references/spec_lock.md +235 -235
- package/skills/office_parser/soffice.py +68 -68
- package/skills/office_parser/word_tools.py +3 -3
- package/skills/ssh/SKILL.md +81 -0
- package/skills/ssh/__init__.py +1 -0
- package/skills/ssh/handler.py +609 -0
- package/skills/ssh/manifest.yaml +182 -0
- package/tui/crannia.cmd +134 -134
- package/tui/crannia.sh +82 -0
- package/tui/crannia_tui/__init__.py +1 -1
- package/tui/crannia_tui/app.py +240 -17
- package/tui/crannia_tui/app.tcss +21 -0
- package/tui/crannia_tui/clipboard.py +78 -10
- package/tui/crannia_tui/commands.py +37 -0
- package/tui/crannia_tui/events.py +6 -0
- package/tui/crannia_tui/i18n.py +164 -164
- package/tui/crannia_tui/locales/en.json +32 -7
- package/tui/crannia_tui/paths.py +4 -1
- package/tui/crannia_tui/profile.py +178 -169
- package/tui/crannia_tui/settings.py +134 -134
- package/tui/crannia_tui/setup.py +44 -5
- package/tui/crannia_tui/ui.py +156 -16
- package/tui/crannia_tui/update.py +393 -389
- package/vendor/ripgrep/COPYING.txt +3 -3
- package/vendor/ripgrep/LICENSE-MIT.txt +21 -21
- package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -13
- package/vendor/ripgrep/README.md +30 -14
- package/vendor/ripgrep/UNLICENSE.txt +24 -24
- package/vendor/ripgrep/linux-x64/rg +0 -0
- package/vendor/ripgrep/package-source.json +15 -16
- package/web/__main__.py +12 -15
- package/web/server.py +8481 -8594
- package/web/static/img/channel-telegram.svg +1 -1
- package/web/static/img/channel-wechat.svg +1 -1
- package/web/templates/logs.html +49 -49
- 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)
|