Initial commit
This commit is contained in:
12
.claude-plugin/plugin.json
Normal file
12
.claude-plugin/plugin.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "ai-runtime-toolkit",
|
||||||
|
"description": "AI Runtime工具装备系统,支持8个内部专业工具和10+个外部CLI工具的整合管理",
|
||||||
|
"version": "0.0.0-2025.11.28",
|
||||||
|
"author": {
|
||||||
|
"name": "CodeConscious",
|
||||||
|
"email": "ai@example.com"
|
||||||
|
},
|
||||||
|
"skills": [
|
||||||
|
"./skills/toolkit"
|
||||||
|
]
|
||||||
|
}
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# ai-runtime-toolkit
|
||||||
|
|
||||||
|
AI Runtime工具装备系统,支持8个内部专业工具和10+个外部CLI工具的整合管理
|
||||||
272
plugin.lock.json
Normal file
272
plugin.lock.json
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
{
|
||||||
|
"$schema": "internal://schemas/plugin.lock.v1.json",
|
||||||
|
"pluginId": "gh:Dwsy/ai-runtime:ai-runtime-toolkit",
|
||||||
|
"normalized": {
|
||||||
|
"repo": null,
|
||||||
|
"ref": "refs/tags/v20251128.0",
|
||||||
|
"commit": "2ff36c79d114394c88916b03aab091515bca2612",
|
||||||
|
"treeHash": "52d1eb326fb536ae27308ddc77a3068c833746f0d65adba135d363f22dcfda58",
|
||||||
|
"generatedAt": "2025-11-28T10:10:27.147683Z",
|
||||||
|
"toolVersion": "publish_plugins.py@0.2.0"
|
||||||
|
},
|
||||||
|
"origin": {
|
||||||
|
"remote": "git@github.com:zhongweili/42plugin-data.git",
|
||||||
|
"branch": "master",
|
||||||
|
"commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390",
|
||||||
|
"repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data"
|
||||||
|
},
|
||||||
|
"manifest": {
|
||||||
|
"name": "ai-runtime-toolkit",
|
||||||
|
"description": "AI Runtime工具装备系统,支持8个内部专业工具和10+个外部CLI工具的整合管理"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"path": "README.md",
|
||||||
|
"sha256": "c9309d6ea2d8bc160847eb25993aa119480615e864b30398dfcf39604ce4b032"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": ".claude-plugin/plugin.json",
|
||||||
|
"sha256": "9db985ee0b307471395d843aeb61e081b4852b7fc9e6f11004355161eb64f33d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover-toolkit.py",
|
||||||
|
"sha256": "9ab0385a396c38d191a49a95dfb43c2f7c3ff320f6e3a57e18c9a448788ac837"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/EXTERNAL-TOOLS.md",
|
||||||
|
"sha256": "3f475448e26ff9fe66616c1d0f54f685ab9056d9477c193e1c2cf14a7505cbcf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/SKILL.md",
|
||||||
|
"sha256": "875cfaa8537c86f1d365417a1464b5602534fafb1cb1f5280939045cb8dd6246"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/EXTERNAL-TOOLS-SKILL.md",
|
||||||
|
"sha256": "bf86b0d0d8bd4d80806f9f74b73de264201750174673356980acfb4fc1bcf2f6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/registry.md",
|
||||||
|
"sha256": "6a0074dc2ef48e2ead010f45dd68269e07d87fe8b7f988e524a57c3a67c33b10"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/discovery.py",
|
||||||
|
"sha256": "00d47b6163191ebbe2810a9e44ec096f6573b9acdd34e83655add295232f612e"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/__init__.py",
|
||||||
|
"sha256": "4a32fa1e95335246e5ea37c6764584308313470a6c4b7265aa949ba225d46d42"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/cli.py",
|
||||||
|
"sha256": "ee033a3039e2348a02cbf431dff772d04d6b645bd19160c703d978a6ec4a490f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/__main__.py",
|
||||||
|
"sha256": "fe0edead9a7015205645310fdc4c058be7875e7575314329db6d7ba35a3e967f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/config/__init__.py",
|
||||||
|
"sha256": "b05e9f58b2ecda1175d24178320a93c31fbf6ed9bed01f25d1348b25ab541c70"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/config/external_tools.yaml",
|
||||||
|
"sha256": "600fb1a05b9c168e6590180bf38851d4a2f49f8184dd15b7926bda71567f0a7c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/formatters/__init__.py",
|
||||||
|
"sha256": "02b4f277506cf1eb097f27311847fa815672192d2cff30cb1106ead9f57b44ca"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/formatters/table.py",
|
||||||
|
"sha256": "03414d296f37f4774ff7d7106a4b963cbd63b84f276b64d1132a308c415d0d13"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/formatters/json.py",
|
||||||
|
"sha256": "86ef938c68f2e58d1e4a12198df074dcbc57c65a0d41ee902618477911715705"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/formatters/base.py",
|
||||||
|
"sha256": "574330b61747299c600b341fda14e7303efa78ac7047d3370a026fcaca1418e6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/models/__init__.py",
|
||||||
|
"sha256": "23b839d8080e92ddd79397a2ae7c03fbd3abf9ebbfe6148cac737ed4555cbd78"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/models/tool.py",
|
||||||
|
"sha256": "74b20e242780a9145ca4e46dee096a6279a1a0b8657408135aaf7b4ac54e802d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/detectors/internal.py",
|
||||||
|
"sha256": "e23ae22474c1fa6bf2b3dd4751531699303a4eca2ae198bd21d88145aa4e12e0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/detectors/__init__.py",
|
||||||
|
"sha256": "8a9b3b536b9e79bfd2ae4344b94114f56e0e8bd3d09d0ef81b17263cb699d822"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/detectors/external.py",
|
||||||
|
"sha256": "fc6cb9ab6ada22531d3a9e1368912a24aa5e99144477518742acd265abb4807f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/discover/detectors/base.py",
|
||||||
|
"sha256": "6d2556e21b5ee9062f721e64f4268472678e00bb648e9660c08ea6ca19a5f5c3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/python/analysis/code-stats.py",
|
||||||
|
"sha256": "86faa62352ebde4b8673f0e8a379b82847074f3d475d6938731f9d3625b6aadb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/python/analysis/dependency-analyzer.meta.yml",
|
||||||
|
"sha256": "0995c7096cf0d1155dfee60e6b8a8337badc8748a8cc7e85f527151fa3b63562"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/python/analysis/dependency-analyzer.py",
|
||||||
|
"sha256": "71f52653661b2e1aab3ba8809fe5be47ee0ad731804f958f12cb3340fb3833f2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/python/analysis/code-stats.meta.yml",
|
||||||
|
"sha256": "09018917a4a5f5526e53c3c28e136e3c146ea81f558c9c095cbbf50750624c1f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/references/core/toolkit-philosophy.md",
|
||||||
|
"sha256": "24d4cd3c4f150a0a8d5148ec09fe32c2c37e214f255cac184ca47bea1e9f29de"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/references/guides/quickstart.md",
|
||||||
|
"sha256": "18d05457a492169beebe64114253b1945ec7faa99958f4054500450189259d0d"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/STRUCTURE-REFACTORING.md",
|
||||||
|
"sha256": "db5ac5f1dfe1aea45c499ded7c27b5d6ee1b7a1a353afeea46f0f091769a35f9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/tools/external/zoxide.md",
|
||||||
|
"sha256": "b95dd76aab08d899f63aeeca124db001371286085a54b843924c3168d17031b3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/tools/external/jq.md",
|
||||||
|
"sha256": "f480e1354588de70f4c95aea5d70637597a7548def90530f82b9be07ec498919"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/tools/external/bat.md",
|
||||||
|
"sha256": "e6b14424adbbc0609655f320a4ccf0f71e3e5a0e9f3c8667a3c2b18f2a18be3e"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/tools/external/ripgrep.md",
|
||||||
|
"sha256": "374bcb296780eb0f2a500415208f0402a2c0a9a5c884a774bf3d8368eb9e5b82"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/tools/external/eza.md",
|
||||||
|
"sha256": "6405e70192fc49abd1ed2db70eb77f5fc90f2ea0c0c202c5dd9c6eede7719443"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/tools/external/fzf.md",
|
||||||
|
"sha256": "1c9abb63ca4bf7b0ff8f22ad06d03f143ebbc8e361f22a5509c55c1642a17752"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/references/internal-tools.md",
|
||||||
|
"sha256": "09f092eca8b34c4532249022f4fd436d56960166a3b9ecebeb0af36e143f2f47"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/references/external-tools.md",
|
||||||
|
"sha256": "b9b652b55a088685abc872f13006b70dce66c1f855d47c5f54f72d0740936630"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/guides/external-integration.md",
|
||||||
|
"sha256": "3c6160680003884eb09bd52b9eeaa0285470e1c73515cc22a2f9158c5915a4af"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/guides/creating-tools.md",
|
||||||
|
"sha256": "b6b2a9dce58874d9833a0f4a7733a8f19405b49c31384ef1f38e853a44e6d49b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/guides/quickstart.md",
|
||||||
|
"sha256": "ec4fe6f220ce63163bcbfbaa9985f80331995ac914b459aaee84002840135855"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/docs/concepts/toolkit-philosophy.md",
|
||||||
|
"sha256": "cecfb1f90fe9156bd64a75e258569b94d3f7893674e284b1ac3ac478eb006ae6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/bash/analysis/analyze-logs.sh",
|
||||||
|
"sha256": "59faf1c5703f0f05edca756c6a13476368265a9cede2d55ef5c33f8def3f5562"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/bash/analysis/analyze-logs.meta.yml",
|
||||||
|
"sha256": "716ed357901f1688fc8bc0b151f26e740e9c1d441a420a30e69927104ff953fe"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/bash/system/check-service.sh",
|
||||||
|
"sha256": "fc4964db0ab04ff11569b481606e0361bde48f787dcc70e850ea627fb1cec005"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/bash/system/check-disk.meta.yml",
|
||||||
|
"sha256": "45bf55131155467eaa91e2c88ac149fd2d88d64a41d15c6d7a14057d2ab84900"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/bash/system/check-disk.sh",
|
||||||
|
"sha256": "2f686303b1c77de50c29c20e2b34b10e0c3ddeff7a029c33a14898e1bcad408c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/bash/system/check-service.meta.yml",
|
||||||
|
"sha256": "8466c3857221be287b0303f4fea3607b69be5ddb9efb795fd899ece7163c933b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/README.md",
|
||||||
|
"sha256": "1f76df936700ee756087b7f1c91215059ab9464d0095597257aac6b33faf7658"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/api-testing/xh.meta.yml",
|
||||||
|
"sha256": "4999f7e9157953bd5e533f5d04f4f05aa876d6c7e14d67944469c3f80532b8cd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/navigation/zoxide.meta.yml",
|
||||||
|
"sha256": "f22ab43620f4231fc5cdb916b5f580506f0e3a053e14457359b631fbc573ed48"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/data-processing/jq.meta.yml",
|
||||||
|
"sha256": "af718ac48a1f77a66ff9f255ffccf5292cddb78edcc9c83f8803f382e63a473a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/code-search/ripgrep.meta.yml",
|
||||||
|
"sha256": "2144b6c1d0875d1287178377d3612a9227f7985a0d4427e5c18eb7a3d0a4d380"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/search/fzf.meta.yml",
|
||||||
|
"sha256": "5f0b0b282e2418c33e827a00d523b64d5b91366beb6d5e098c12de5e1debae56"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/git-tools/delta.meta.yml",
|
||||||
|
"sha256": "014393f41ca99efaa09d0c0cda38bdcb37fedf7a9f2ea9a4953d10e75d2fe348"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/shell-enhancement/starship.meta.yml",
|
||||||
|
"sha256": "953de8d0f3f6f5ae1fb63d407c6a44cbbeb24f368360890212a983e68a1fac4b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/file-listing/eza.meta.yml",
|
||||||
|
"sha256": "47471057614816a28bafa0ca5c467ba4950d3c71d9f226ecb4813bcb3102356a"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/file-viewer/bat.meta.yml",
|
||||||
|
"sha256": "c883525fd61786482110cf8675395bf264f5422ec489bca215151b47def75322"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/external/file-search/fd.meta.yml",
|
||||||
|
"sha256": "2eb5f968873bc3bdb4f1444b0b1c91d5daa768448e59b02051047af059ddd95f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "skills/toolkit/node/api/test-api.js",
|
||||||
|
"sha256": "64b796eb0d97d310c4ea2b3cfcaa57efce47dceeb94d68e634ba2806bf36a6bb"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dirSha256": "52d1eb326fb536ae27308ddc77a3068c833746f0d65adba135d363f22dcfda58"
|
||||||
|
},
|
||||||
|
"security": {
|
||||||
|
"scannedAt": null,
|
||||||
|
"scannerVersion": null,
|
||||||
|
"flags": []
|
||||||
|
}
|
||||||
|
}
|
||||||
174
skills/toolkit/EXTERNAL-TOOLS-SKILL.md
Normal file
174
skills/toolkit/EXTERNAL-TOOLS-SKILL.md
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
---
|
||||||
|
name: external-tools-skill
|
||||||
|
description: 外部CLI工具装备系统,支持10+个成熟CLI工具的深度整合,包括fzf、ripgrep、jq等,提供模糊搜索、代码查找、JSON处理等高级功能
|
||||||
|
license: MIT
|
||||||
|
version: 2.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 外部工具装备系统
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
外部工具装备系统遵循"**整合 > 创造**"的核心理念,通过深度整合成熟的CLI工具,为AI Runtime提供强大的外部能力扩展。系统支持10+个经过社区验证的工具,无需重复造轮子。
|
||||||
|
|
||||||
|
## 核心能力
|
||||||
|
|
||||||
|
### 工具生态
|
||||||
|
- **基础必备**: fzf、eza、bat、ripgrep、zoxide、jq
|
||||||
|
- **搜索增强**: fd、ripgrep的高性能代码搜索
|
||||||
|
- **数据处理**: jq的强大JSON处理能力
|
||||||
|
- **界面优化**: 美化文件列表、语法高亮、智能跳转
|
||||||
|
|
||||||
|
### 深度整合
|
||||||
|
- **自动检测**: 系统自动发现已安装的工具
|
||||||
|
- **元数据管理**: 标准化的工具描述和参数定义
|
||||||
|
- **统一接口**: 通过discover-toolkit.py统一调用
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 安装推荐工具
|
||||||
|
|
||||||
|
**macOS**:
|
||||||
|
```bash
|
||||||
|
brew install fzf eza zoxide fd bat ripgrep jq
|
||||||
|
```
|
||||||
|
|
||||||
|
**Ubuntu/Debian**:
|
||||||
|
```bash
|
||||||
|
sudo apt-get install fzf ripgrep jq bat
|
||||||
|
```
|
||||||
|
|
||||||
|
### 基本使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 进入工具装备目录
|
||||||
|
cd .ai-runtime/toolkit
|
||||||
|
|
||||||
|
# 查看外部工具
|
||||||
|
python3 discover-toolkit.py list --external
|
||||||
|
|
||||||
|
# 检查安装状态
|
||||||
|
python3 discover-toolkit.py check-external
|
||||||
|
```
|
||||||
|
|
||||||
|
## 推荐工具详解
|
||||||
|
|
||||||
|
### 基础必备工具
|
||||||
|
|
||||||
|
#### fzf - 模糊查找器
|
||||||
|
```bash
|
||||||
|
# 交互式文件选择
|
||||||
|
find . -name "*.py" | fzf
|
||||||
|
|
||||||
|
# 历史命令搜索
|
||||||
|
history | fzf
|
||||||
|
```
|
||||||
|
|
||||||
|
#### eza - 现代化ls
|
||||||
|
```bash
|
||||||
|
# 美化文件列表
|
||||||
|
eza -la
|
||||||
|
|
||||||
|
# 树状结构显示
|
||||||
|
eza -T
|
||||||
|
```
|
||||||
|
|
||||||
|
#### bat - 语法高亮cat
|
||||||
|
```bash
|
||||||
|
# 带语法高亮的代码查看
|
||||||
|
bat script.py
|
||||||
|
|
||||||
|
# 与fzf结合使用
|
||||||
|
find . -name "*.md" | fzf | xargs bat
|
||||||
|
```
|
||||||
|
|
||||||
|
#### ripgrep - 极速搜索
|
||||||
|
```bash
|
||||||
|
# 递归搜索代码
|
||||||
|
rg "TODO|FIXME"
|
||||||
|
|
||||||
|
# 搜索特定文件类型
|
||||||
|
rg "function" --type py
|
||||||
|
```
|
||||||
|
|
||||||
|
#### zoxide - 智能跳转
|
||||||
|
```bash
|
||||||
|
# 跳转到常用目录
|
||||||
|
z project-name
|
||||||
|
|
||||||
|
# 查看权重统计
|
||||||
|
zoxide query
|
||||||
|
```
|
||||||
|
|
||||||
|
#### jq - JSON处理器
|
||||||
|
```bash
|
||||||
|
# 格式化JSON
|
||||||
|
cat data.json | jq '.'
|
||||||
|
|
||||||
|
# 提取字段
|
||||||
|
cat package.json | jq '.dependencies | keys[]'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 渐进式披露文档
|
||||||
|
|
||||||
|
### 工具详解
|
||||||
|
- **[fzf使用指南](../docs/tools/external/fzf.md)** - 模糊查找器的完整指南
|
||||||
|
- **[eza使用指南](../docs/tools/external/eza.md)** - 现代化文件列表工具
|
||||||
|
- **[bat使用指南](../docs/tools/external/bat.md)** - 语法高亮文件查看器
|
||||||
|
- **[ripgrep使用指南](../docs/tools/external/ripgrep.md)** - 高性能代码搜索工具
|
||||||
|
- **[zoxide使用指南](../docs/tools/external/zoxide.md)** - 智能目录跳转工具
|
||||||
|
- **[jq使用指南](../docs/tools/external/jq.md)** - JSON命令行处理器
|
||||||
|
|
||||||
|
### 整合指南
|
||||||
|
- **[外部工具整合详解](../docs/guides/external-integration.md)** - 如何整合更多第三方工具
|
||||||
|
|
||||||
|
## 使用场景
|
||||||
|
|
||||||
|
### 代码开发
|
||||||
|
```bash
|
||||||
|
# 搜索代码模式
|
||||||
|
rg "class.*Test" src/
|
||||||
|
|
||||||
|
# 交互式文件选择和查看
|
||||||
|
find src/ -name "*.py" | fzf | xargs bat
|
||||||
|
|
||||||
|
# 智能目录跳转
|
||||||
|
z projects/my-api
|
||||||
|
```
|
||||||
|
|
||||||
|
### 数据处理
|
||||||
|
```bash
|
||||||
|
# 处理API响应
|
||||||
|
curl -s http://api.example.com/data | jq '.items[] | select(.active == true)'
|
||||||
|
|
||||||
|
# 日志分析
|
||||||
|
cat app.log | rg "ERROR" | jq -R 'fromjson?' 2>/dev/null || cat app.log | rg "ERROR"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 系统管理
|
||||||
|
```bash
|
||||||
|
# 美化文件列表
|
||||||
|
eza -la --git
|
||||||
|
|
||||||
|
# 快速文件预览
|
||||||
|
bat /etc/hosts
|
||||||
|
|
||||||
|
# 历史命令搜索
|
||||||
|
history | fzf | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
## 相关系统
|
||||||
|
|
||||||
|
- **[工具装备总览](SKILL.md)** - 完整的工具装备系统
|
||||||
|
- **[内部工具详解](../docs/references/internal-tools.md)** - AI Runtime自主创建的工具
|
||||||
|
- **[宪法文档](../.ai-runtime/constitution.md)** - 治理原则和约束
|
||||||
|
|
||||||
|
## 版本信息
|
||||||
|
|
||||||
|
- **版本**: 2.0.0
|
||||||
|
- **工具数量**: 10+个外部CLI工具
|
||||||
|
- **最后更新**: 2025-11-14
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*基于 anthropics/skills 渐进式披露架构设计*
|
||||||
70
skills/toolkit/EXTERNAL-TOOLS.md
Normal file
70
skills/toolkit/EXTERNAL-TOOLS.md
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
---
|
||||||
|
name: external-tools-index
|
||||||
|
description: 外部CLI工具索引 - 提供快速访问所有外部工具文档的入口
|
||||||
|
version: 2.0.0
|
||||||
|
last_updated: 2025-11-14
|
||||||
|
---
|
||||||
|
|
||||||
|
# 外部工具装备系统
|
||||||
|
|
||||||
|
[](EXTERNAL-TOOLS-SKILL.md)
|
||||||
|
|
||||||
|
本文件提供外部CLI工具的快速导航。**核心理念**: **整合 > 创造**
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 进入工具装备目录
|
||||||
|
cd .ai-runtime/toolkit
|
||||||
|
|
||||||
|
# 查看所有外部工具
|
||||||
|
python3 discover-toolkit.py list --external
|
||||||
|
|
||||||
|
# 搜索工具
|
||||||
|
python3 discover-toolkit.py search 'search'
|
||||||
|
|
||||||
|
# 查看工具详情
|
||||||
|
python3 discover-toolkit.py show fzf
|
||||||
|
```
|
||||||
|
|
||||||
|
## 工具分类索引
|
||||||
|
|
||||||
|
### 基础必备 ⭐⭐⭐⭐⭐
|
||||||
|
| 工具 | 用途 | 详细文档 |
|
||||||
|
|-----|-----|---------|
|
||||||
|
| [fzf](../docs/tools/external/fzf.md) | 模糊查找 | 交互式选择和搜索 |
|
||||||
|
| [eza](../docs/tools/external/eza.md) | 文件列表 | 现代化ls替代品 |
|
||||||
|
| [bat](../docs/tools/external/bat.md) | 文件查看 | 语法高亮cat替代品 |
|
||||||
|
| [ripgrep](../docs/tools/external/ripgrep.md) | 代码搜索 | 极速递归搜索 |
|
||||||
|
| [zoxide](../docs/tools/external/zoxide.md) | 目录跳转 | AI驱动的cd |
|
||||||
|
| [jq](../docs/tools/external/jq.md) | JSON处理 | 命令行JSON处理器 |
|
||||||
|
|
||||||
|
## 安装指南
|
||||||
|
|
||||||
|
### 一键安装(macOS)
|
||||||
|
```bash
|
||||||
|
brew install fzf eza zoxide fd bat ripgrep jq
|
||||||
|
```
|
||||||
|
|
||||||
|
### 一键安装(Ubuntu/Debian)
|
||||||
|
```bash
|
||||||
|
sudo apt-get install fzf ripgrep jq bat
|
||||||
|
# 其他工具见详细文档
|
||||||
|
```
|
||||||
|
|
||||||
|
## 相关资源
|
||||||
|
|
||||||
|
- **[外部工具技能](EXTERNAL-TOOLS-SKILL.md)** - 核心功能和使用指南
|
||||||
|
- **[工具装备总览](registry.md)** - 完整的工具装备系统
|
||||||
|
- **[外部工具整合详解](../docs/guides/external-integration.md)** - 如何添加更多工具
|
||||||
|
- **[完整历史文档](external-tools-complete.md)** - 完整的外部工具文档(83行)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**总工具数**: 10+ 个外部CLI工具
|
||||||
|
**最后更新**: 2025-11-14
|
||||||
|
**文档版本**: 2.0.0 (基于anthropics/skills模式重构)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*基于anthropics/skills项目的文档组织模式 | 采用渐进式披露设计原则*
|
||||||
139
skills/toolkit/SKILL.md
Normal file
139
skills/toolkit/SKILL.md
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
---
|
||||||
|
name: ai-runtime-toolkit
|
||||||
|
description: AI Runtime工具装备系统,支持8个内部专业工具和10+个外部CLI工具的整合管理,提供工具发现、执行和配置功能,遵循整合优于创造的设计理念
|
||||||
|
license: MIT
|
||||||
|
version: 2.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# AI Runtime 工具装备系统
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
工具装备是AI Runtime的**外置能力扩展系统**,遵循"**整合 > 创造**"的核心理念,通过智能整合成熟的CLI工具和自主创建的专业工具,实现认知能力的有效扩展。
|
||||||
|
|
||||||
|
## 核心能力
|
||||||
|
|
||||||
|
### 双重工具体系
|
||||||
|
- **内部工具**: AI Runtime自主创建的专业工具(8个)
|
||||||
|
- **外部工具**: 深度整合的成熟CLI工具(10+个)
|
||||||
|
|
||||||
|
### 智能发现系统
|
||||||
|
- 自动工具检测和注册
|
||||||
|
- 元数据驱动的管理机制
|
||||||
|
- 命令行和编程接口双重支持
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### 查看所有工具
|
||||||
|
```bash
|
||||||
|
# 进入工具装备目录
|
||||||
|
cd toolkit
|
||||||
|
|
||||||
|
# 查看所有工具
|
||||||
|
python3 discover-toolkit.py list
|
||||||
|
|
||||||
|
# 查看外部工具
|
||||||
|
python3 discover-toolkit.py list --external
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用工具
|
||||||
|
```bash
|
||||||
|
# 查看工具详情
|
||||||
|
python3 discover-toolkit.py show SERVICE-CHECK-001
|
||||||
|
|
||||||
|
# 运行工具
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o deps.json
|
||||||
|
|
||||||
|
# 搜索工具
|
||||||
|
python3 discover-toolkit.py search monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
## 工具分类
|
||||||
|
|
||||||
|
### 内部工具(自主创建)
|
||||||
|
- **Python工具**: 依赖分析器、代码统计器、图形生成器、报告生成器
|
||||||
|
- **Bash工具**: 服务健康检查器、日志分析器、磁盘健康检查器
|
||||||
|
- **Node.js工具**: API测试工具
|
||||||
|
|
||||||
|
### 外部工具(深度整合)
|
||||||
|
- **基础必备**: fzf、eza、bat、ripgrep、zoxide、jq
|
||||||
|
- **搜索增强**: fd、ripgrep
|
||||||
|
- **数据处理**: jq
|
||||||
|
- **界面优化**: fzf、eza、bat、starship
|
||||||
|
|
||||||
|
## 渐进式披露文档架构
|
||||||
|
|
||||||
|
基于 anthropics/skills 设计,按需加载详细信息:
|
||||||
|
|
||||||
|
### 核心理念
|
||||||
|
- **[工具哲学](references/core/toolkit-philosophy.md)** - 设计理念、分类体系和发展策略
|
||||||
|
|
||||||
|
### 使用指南
|
||||||
|
- **[快速开始](references/guides/quickstart.md)** - 10分钟上手工具装备系统
|
||||||
|
|
||||||
|
### 详细参考
|
||||||
|
- **[内部工具详解](../docs/references/internal-tools.md)** - 8个自主创建工具的详细说明
|
||||||
|
- **[外部工具集成](../docs/references/external-tools.md)** - 10+个CLI工具的整合指南
|
||||||
|
|
||||||
|
### 开发指南
|
||||||
|
- **[创建新工具](../docs/guides/creating-tools.md)** - 工具开发流程和最佳实践
|
||||||
|
- **[外部工具整合](../docs/guides/external-integration.md)** - 整合第三方CLI工具
|
||||||
|
|
||||||
|
## 设计理念
|
||||||
|
|
||||||
|
### 整合优于创造
|
||||||
|
- **成熟工具**: 使用经过社区验证的CLI工具
|
||||||
|
- **专注专业**: 每个工具只做一件事,做到极致
|
||||||
|
- **认知卸载**: 直接使用,无需重复开发
|
||||||
|
|
||||||
|
### 元数据驱动
|
||||||
|
- **.meta.yml**: 工具元数据标准格式
|
||||||
|
- **自动发现**: 基于文件系统结构自动注册
|
||||||
|
- **类型安全**: 明确的工具分类和版本管理
|
||||||
|
|
||||||
|
## 使用场景
|
||||||
|
|
||||||
|
### 代码分析
|
||||||
|
```bash
|
||||||
|
# 分析项目依赖
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o deps.json
|
||||||
|
|
||||||
|
# 生成代码统计
|
||||||
|
python3 discover-toolkit.py run code-stats src/ -o stats.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### 系统监控
|
||||||
|
```bash
|
||||||
|
# 检查服务健康
|
||||||
|
python3 discover-toolkit.py run service-check http://localhost:3000
|
||||||
|
|
||||||
|
# 分析日志文件
|
||||||
|
python3 discover-toolkit.py run log-analyzer /var/log/app.log --level ERROR
|
||||||
|
```
|
||||||
|
|
||||||
|
### 数据处理
|
||||||
|
```bash
|
||||||
|
# 处理JSON数据
|
||||||
|
cat data.json | jq '.items[] | select(.status == "active")'
|
||||||
|
|
||||||
|
# 搜索代码
|
||||||
|
rg "TODO|FIXME" src/
|
||||||
|
```
|
||||||
|
|
||||||
|
## 相关系统
|
||||||
|
|
||||||
|
- **[宪法文档](../.ai-runtime/constitution.md)** - 治理原则和约束
|
||||||
|
- **[记忆系统](../memory/)** - 分层记忆管理
|
||||||
|
- **[认知记录](../cognition/)** - 分析洞察和探索报告
|
||||||
|
- **[命令系统](../commands/)** - 运行时命令和交互
|
||||||
|
|
||||||
|
## 版本信息
|
||||||
|
|
||||||
|
- **版本**: 2.0.0
|
||||||
|
- **内部工具**: 8个
|
||||||
|
- **外部工具**: 10+个
|
||||||
|
- **最后更新**: 2025-11-14
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*基于 anthropics/skills 渐进式披露架构设计*
|
||||||
88
skills/toolkit/bash/analysis/analyze-logs.meta.yml
Normal file
88
skills/toolkit/bash/analysis/analyze-logs.meta.yml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
tool_id: BASH-ANALYZE-LOGS-002
|
||||||
|
tool_name: "日志分析器"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
语言: bash
|
||||||
|
文件: analyze-logs.sh
|
||||||
|
复杂度: level-2
|
||||||
|
创建日期: 2025-11-14
|
||||||
|
作者: CodeConscious
|
||||||
|
|
||||||
|
用途分类:
|
||||||
|
- DATA # 数据分析
|
||||||
|
- MONITOR # 监控诊断
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "分析日志文件,按级别过滤、时间范围筛选、模式匹配和错误统计"
|
||||||
|
详细: |
|
||||||
|
支持功能:
|
||||||
|
- 按日志级别统计(ERROR/WARN/INFO/DEBUG)
|
||||||
|
- 按关键词模式搜索(正则表达式)
|
||||||
|
- 错误模式识别(超时、连接错误、内存问题)
|
||||||
|
- 统计汇总和建议生成
|
||||||
|
- 支持时间范围筛选(需要日志包含日期)
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- "分析生产环境错误日志,找到崩溃原因"
|
||||||
|
- "统计API接口错误频率和类型分布"
|
||||||
|
- "监控服务健康状况,识别异常模式"
|
||||||
|
- "排查性能问题,定位慢请求和超时"
|
||||||
|
- "验证修复效果,比较修复前后的日志"
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
命令: "bash analyze-logs.sh <日志文件> [模式] [级别] [日期范围]"
|
||||||
|
参数:
|
||||||
|
日志文件: "日志文件路径(必需)"
|
||||||
|
模式: "要搜索的正则表达式(可选)"
|
||||||
|
级别: "日志级别: ERROR/WARN/INFO/DEBUG(默认: INFO)"
|
||||||
|
日期范围: "日期范围, 如: 2025-11-01~2025-11-14(可选,需要日志包含日期)"
|
||||||
|
示例:
|
||||||
|
- "分析应用日志: bash analyze-logs.sh /var/log/app.log"
|
||||||
|
- "搜索错误: bash analyze-logs.sh /var/log/app.log 'timeout|error' ERROR"
|
||||||
|
- "按时间筛选: bash analyze-logs.sh /var/log/app.log 'database' WARN 2025-11-01~2025-11-07"
|
||||||
|
|
||||||
|
依赖要求:
|
||||||
|
系统命令:
|
||||||
|
- bash: 支持bash 4.0+
|
||||||
|
- awk: 文本处理
|
||||||
|
- grep: 模式匹配
|
||||||
|
- wc: 计数
|
||||||
|
- du: 文件大小
|
||||||
|
|
||||||
|
输入输出:
|
||||||
|
输入:
|
||||||
|
- 类型: 文本文件
|
||||||
|
- 格式: 任意日志格式(支持自定义分析)
|
||||||
|
- 示例: |
|
||||||
|
2025-11-14 10:30:00 [INFO] User login successful
|
||||||
|
2025-11-14 10:30:01 [ERROR] Database connection timeout
|
||||||
|
2025-11-14 10:30:02 [WARN] High memory usage: 85%
|
||||||
|
输出:
|
||||||
|
- stdout: 统计摘要、错误分析、建议
|
||||||
|
- 格式: 人类可读文本 + 颜色高亮
|
||||||
|
|
||||||
|
上次使用:
|
||||||
|
时间: 2025-11-14 11:00:00
|
||||||
|
用途: "分析auth-service崩溃日志,找到连接池配置问题"
|
||||||
|
结果: "成功识别47次超时错误,12次连接数过多错误,定位到连接池不足问题"
|
||||||
|
满意度: 0.95
|
||||||
|
|
||||||
|
相关工具:
|
||||||
|
- 前置工具: 无
|
||||||
|
- 互补工具:
|
||||||
|
- toolkit/bash/system/check-service.sh(服务健康检查)
|
||||||
|
- toolkit/python/analysis/analyze_logs.py(复杂日志解析)
|
||||||
|
- 替代工具:
|
||||||
|
- grep + wc(手动统计)
|
||||||
|
|
||||||
|
维护记录:
|
||||||
|
2025-11-14:
|
||||||
|
- 初始创建
|
||||||
|
- 支持级别统计、模式匹配、错误模式识别
|
||||||
|
2025-11-15:
|
||||||
|
- 添加时间范围筛选功能(实验性)
|
||||||
|
- 优化颜色输出
|
||||||
|
TODO:
|
||||||
|
- 支持JSON日志格式解析
|
||||||
|
- 添加图表可视化(ASCII)
|
||||||
|
- 支持日志文件压缩格式(.gz)
|
||||||
171
skills/toolkit/bash/analysis/analyze-logs.sh
Executable file
171
skills/toolkit/bash/analysis/analyze-logs.sh
Executable file
@@ -0,0 +1,171 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 日志分析器 - 从日志文件中提取和分析信息
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
LOG_FILE="${1:-}"
|
||||||
|
PATTERN="${2:-}"
|
||||||
|
LEVEL="${3:-INFO}"
|
||||||
|
DATE_RANGE="${4:-}"
|
||||||
|
|
||||||
|
# 颜色输出
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# 帮助信息
|
||||||
|
usage() {
|
||||||
|
echo "📝 日志分析器"
|
||||||
|
echo ""
|
||||||
|
echo "使用: $0 <日志文件> [模式] [级别] [日期范围]"
|
||||||
|
echo ""
|
||||||
|
echo "参数:"
|
||||||
|
echo " 日志文件 日志文件路径 (必需)"
|
||||||
|
echo " 模式 要搜索的正则表达式 (可选)"
|
||||||
|
echo " 级别 日志级别: ERROR/WARN/INFO/DEBUG (默认: INFO)"
|
||||||
|
echo " 日期范围 日期范围, 如: 2025-11-01~2025-11-14 (可选)"
|
||||||
|
echo ""
|
||||||
|
echo "示例:"
|
||||||
|
echo " $0 /var/log/app.log"
|
||||||
|
echo " $0 /var/log/app.log 'timeout|error' ERROR"
|
||||||
|
echo " $0 /var/log/app.log 'database' WARN 2025-11-01~2025-11-07"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查参数
|
||||||
|
if [ -z "$LOG_FILE" ]; then
|
||||||
|
echo "❌ 错误: 请提供日志文件路径"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$LOG_FILE" ]; then
|
||||||
|
echo "❌ 错误: 文件不存在: $LOG_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "📝 日志分析器"
|
||||||
|
echo "=========================================="
|
||||||
|
echo "文件: ${BLUE}$LOG_FILE${NC}"
|
||||||
|
echo "大小: $(du -h "$LOG_FILE" | cut -f1)"
|
||||||
|
echo "行数: $(wc -l < "$LOG_FILE")"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
# 按级别过滤
|
||||||
|
echo ""
|
||||||
|
echo "📊 按级别统计:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
ERROR_COUNT=$(grep -c "ERROR" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
WARN_COUNT=$(grep -c "WARN" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
INFO_COUNT=$(grep -c "INFO" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
DEBUG_COUNT=$(grep -c "DEBUG" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
|
||||||
|
echo -e " ${RED}ERROR${NC}: $ERROR_COUNT"
|
||||||
|
echo -e " ${YELLOW}WARN${NC}: $WARN_COUNT"
|
||||||
|
echo -e " ${GREEN}INFO${NC}: $INFO_COUNT"
|
||||||
|
echo -e " ${BLUE}DEBUG${NC}: $DEBUG_COUNT"
|
||||||
|
|
||||||
|
# 展示特定级别的日志
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "📋 ${LEVEL} 级别日志 (前10条):"
|
||||||
|
echo "=========================================="
|
||||||
|
grep "$LEVEL" "$LOG_FILE" | head -10
|
||||||
|
|
||||||
|
# 模式匹配
|
||||||
|
if [ -n "$PATTERN" ]; then
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "🔍 匹配模式 '${PATTERN}':"
|
||||||
|
echo "=========================================="
|
||||||
|
MATCH_COUNT=$(grep -c "$PATTERN" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
echo "匹配数量: $MATCH_COUNT"
|
||||||
|
echo ""
|
||||||
|
echo "示例:"
|
||||||
|
grep "$PATTERN" "$LOG_FILE" | head -5
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 时间范围
|
||||||
|
check_date_range() {
|
||||||
|
if [ -n "$DATE_RANGE" ]; then
|
||||||
|
START_DATE=$(echo "$DATE_RANGE" | cut -d'~' -f1)
|
||||||
|
END_DATE=$(echo "$DATE_RANGE" | cut -d'~' -f2)
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "📅 时间范围 $START_DATE ~ $END_DATE:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
# 简单的日期过滤(假设日志包含日期)
|
||||||
|
awk -v start="$START_DATE" -v end="$END_DATE" '
|
||||||
|
$0 >= start && $0 <= end {
|
||||||
|
print $0
|
||||||
|
}' "$LOG_FILE" | head -10
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_date_range
|
||||||
|
|
||||||
|
# 常见错误模式分析
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "⚠️ 常见错误模式分析:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
# 超时错误
|
||||||
|
TIMEOUT_COUNT=$(grep -c "timeout\|Timeout\|TIMEOUT" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
if [ "$TIMEOUT_COUNT" -gt 0 ]; then
|
||||||
|
echo -e "⏱️ 超时错误: ${RED}$TIMEOUT_COUNT${NC}次"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 连接错误
|
||||||
|
CONN_ERROR_COUNT=$(grep -c "connection refused\|Connection refused\|ECONNREFUSED" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
if [ "$CONN_ERROR_COUNT" -gt 0 ]; then
|
||||||
|
echo -e "🔗 连接错误: ${RED}$CONN_ERROR_COUNT${NC}次"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 内存错误
|
||||||
|
MEMORY_ERROR_COUNT=$(grep -c "OutOfMemory\|memory\|Memory" "$LOG_FILE" 2>/dev/null || echo "0")
|
||||||
|
if [ "$MEMORY_ERROR_COUNT" -gt 0 ]; then
|
||||||
|
echo -e "🧠 内存问题: ${RED}$MEMORY_ERROR_COUNT${NC}次"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 总结
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "📊 统计总结:"
|
||||||
|
echo "=========================================="
|
||||||
|
echo "总错误数: $((ERROR_COUNT + WARN_COUNT))"
|
||||||
|
echo "关键错误数: $ERROR_COUNT"
|
||||||
|
|
||||||
|
if [ -n "$PATTERN" ]; then
|
||||||
|
echo "模式'$PATTERN'匹配: $MATCH_COUNT 次"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "💡 建议:"
|
||||||
|
echo "=========================================="
|
||||||
|
if [ "$ERROR_COUNT" -gt 10 ]; then
|
||||||
|
echo " - ⚠️ ERROR数量较多,建议立即调查"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TIMEOUT_COUNT" -gt 5 ]; then
|
||||||
|
echo " - ⚠️ 频繁超时,检查网络或服务响应"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$CONN_ERROR_COUNT" -gt 3 ]; then
|
||||||
|
echo " - ⚠️ 连接问题,验证服务状态和配置"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$ERROR_COUNT" -le 5 ] && [ "$WARN_COUNT" -le 10 ]; then
|
||||||
|
echo " - ✅ 日志健康状况良好"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "日志分析完成"
|
||||||
|
echo "=========================================="
|
||||||
86
skills/toolkit/bash/system/check-disk.meta.yml
Normal file
86
skills/toolkit/bash/system/check-disk.meta.yml
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
tool_id: BASH-CHECK-DISK-003
|
||||||
|
tool_name: "磁盘健康检查器"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
语言: bash
|
||||||
|
文件: check-disk.sh
|
||||||
|
复杂度: level-2
|
||||||
|
创建日期: 2025-11-14
|
||||||
|
作者: CodeConscious
|
||||||
|
|
||||||
|
用途分类:
|
||||||
|
- MONITOR # 监控诊断
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "检查磁盘空间、inode使用和健康状态,提供详细的分析和建议"
|
||||||
|
详细: |
|
||||||
|
支持功能:
|
||||||
|
- 磁盘空间使用检查(总容量、已使用、可用)
|
||||||
|
- Inode使用检查(总数、已使用、可用)
|
||||||
|
- 使用阈值警报(可配置阈值,默认80%)
|
||||||
|
- 文件系统类型检测(ext4, xfs等)
|
||||||
|
- 挂载点和访问权限检查
|
||||||
|
- 性能指标分析(大文件 vs 小文件占比)
|
||||||
|
- 智能建议生成(基于检查结果)
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- "监控服务器磁盘空间,预防空间不足导致的服务中断"
|
||||||
|
- "检查日志目录磁盘使用情况,规划日志轮转策略"
|
||||||
|
- '诊断"No space left on device"错误的根本原因'
|
||||||
|
- "定期检查系统健康状态,识别潜在问题"
|
||||||
|
- "在扩容前评估当前磁盘使用情况"
|
||||||
|
- "排查inode耗尽问题(大量小文件导致)"
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
命令: "bash check-disk.sh [路径] [阈值]"
|
||||||
|
参数:
|
||||||
|
路径: "要检查的磁盘路径(默认: /)"
|
||||||
|
阈值: "空间使用警报阈值百分比(默认: 80%,1-100之间)"
|
||||||
|
示例:
|
||||||
|
- "检查根目录(阈值80%): bash check-disk.sh"
|
||||||
|
- "检查/home(阈值85%): bash check-disk.sh /home 85"
|
||||||
|
- "检查/var/log(阈值90%): bash check-disk.sh /var/log 90"
|
||||||
|
|
||||||
|
依赖要求:
|
||||||
|
系统命令:
|
||||||
|
- bash: 4.0+
|
||||||
|
- df: 磁盘使用情况
|
||||||
|
- du: 文件大小
|
||||||
|
- find: 文件查找
|
||||||
|
- awk: 文本处理
|
||||||
|
- sort: 排序
|
||||||
|
|
||||||
|
输入输出:
|
||||||
|
输入:
|
||||||
|
- 无(从文件系统自动获取)
|
||||||
|
输出:
|
||||||
|
- stdout: 彩色格式化报告(空间使用、inode、警报、建议)
|
||||||
|
- 退出码:
|
||||||
|
- 0: 磁盘健康
|
||||||
|
- 1: 有警报
|
||||||
|
- 2: 严重问题
|
||||||
|
|
||||||
|
上次使用:
|
||||||
|
时间: 2024-11-14 11:30:00
|
||||||
|
用途: "检查服务器根目录磁盘空间,发现/var/log占用过大"
|
||||||
|
结果: "成功识别日志目录占用85%,建议清理旧日志后立即恢复20%空间"
|
||||||
|
满意度: 0.93
|
||||||
|
|
||||||
|
相关工具:
|
||||||
|
- 前置工具: 无
|
||||||
|
- 互补工具:
|
||||||
|
- toolkit/bash/analysis/analyze-logs.sh(日志分析)
|
||||||
|
- toolkit/bash/system/check-service.sh(服务健康)
|
||||||
|
- 替代工具:
|
||||||
|
- df -h(手动检查)
|
||||||
|
- ncdu(交互式磁盘使用分析)
|
||||||
|
|
||||||
|
维护记录:
|
||||||
|
2025-11-14:
|
||||||
|
- 初始创建
|
||||||
|
- 支持空间和inode检查
|
||||||
|
- 添加性能指标分析
|
||||||
|
TODO:
|
||||||
|
- 支持磁盘健康度检测(S.M.A.R.T.)
|
||||||
|
- 添加磁盘I/O性能测试
|
||||||
|
- 支持磁盘温度监测
|
||||||
246
skills/toolkit/bash/system/check-disk.sh
Executable file
246
skills/toolkit/bash/system/check-disk.sh
Executable file
@@ -0,0 +1,246 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 磁盘健康检查器 - 检查磁盘空间、inode使用和健康状态
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DISK_PATH="${1:-/}"
|
||||||
|
THRESHOLD="${2:-80}"
|
||||||
|
|
||||||
|
# 颜色输出
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# 帮助信息
|
||||||
|
usage() {
|
||||||
|
echo "💾 磁盘健康检查器"
|
||||||
|
echo ""
|
||||||
|
echo "使用: $0 [路径] [阈值]"
|
||||||
|
echo ""
|
||||||
|
echo "参数:"
|
||||||
|
echo " 路径 要检查的磁盘路径 (默认: /)"
|
||||||
|
echo " 阈值 空间使用警报阈值百分比 (默认: 80%)"
|
||||||
|
echo ""
|
||||||
|
echo "示例:"
|
||||||
|
echo " $0 # 检查根目录,阈值80%"
|
||||||
|
echo " $0 /home 85 # 检查/home目录,阈值85%"
|
||||||
|
echo " $0 /var/log 90 # 检查日志目录,阈值90%"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查参数
|
||||||
|
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查路径是否存在
|
||||||
|
if [ ! -d "$DISK_PATH" ]; then
|
||||||
|
echo "❌ 错误: 路径不存在: $DISK_PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 数字验证
|
||||||
|
if ! [[ "$THRESHOLD" =~ ^[0-9]+$ ]] || [ "$THRESHOLD" -lt 1 ] || [ "$THRESHOLD" -gt 100 ]; then
|
||||||
|
echo "❌ 错误: 阈值必须是1-100之间的数字"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "💾 磁盘健康检查器"
|
||||||
|
echo "=========================================="
|
||||||
|
echo "检查路径: ${BLUE}$DISK_PATH${NC}"
|
||||||
|
echo "警报阈值: ${THRESHOLD}%"
|
||||||
|
echo "=========================================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 获取磁盘使用情况
|
||||||
|
DISK_INFO=$(df -h "$DISK_PATH" | tail -1)
|
||||||
|
DISK_DEVICE=$(echo "$DISK_INFO" | awk '{print $1}')
|
||||||
|
DISK_SIZE=$(echo "$DISK_INFO" | awk '{print $2}')
|
||||||
|
DISK_USED=$(echo "$DISK_INFO" | awk '{print $3}')
|
||||||
|
DISK_AVAIL=$(echo "$DISK_INFO" | awk '{print $4}')
|
||||||
|
DISK_USAGE_PERCENT=$(echo "$DISK_INFO" | awk '{print $5}' | sed 's/%//')
|
||||||
|
|
||||||
|
echo "📊 磁盘使用概况:"
|
||||||
|
echo "=========================================="
|
||||||
|
echo -e "设备: ${CYAN}$DISK_DEVICE${NC}"
|
||||||
|
echo -e "总容量: ${BLUE}$DISK_SIZE${NC}"
|
||||||
|
echo -e "已使用: ${YELLOW}$DISK_USED${NC}"
|
||||||
|
echo -e "可用: ${GREEN}$DISK_AVAIL${NC}"
|
||||||
|
|
||||||
|
# 使用百分比颜色标记
|
||||||
|
if [ "$DISK_USAGE_PERCENT" -gt 90 ]; then
|
||||||
|
USAGE_COLOR="$RED"
|
||||||
|
STATUS="🔴 严重"
|
||||||
|
elif [ "$DISK_USAGE_PERCENT" -gt "$THRESHOLD" ]; then
|
||||||
|
USAGE_COLOR="$YELLOW"
|
||||||
|
STATUS="🟡 警告"
|
||||||
|
else
|
||||||
|
USAGE_COLOR="$GREEN"
|
||||||
|
STATUS="🟢 正常"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "使用率: ${USAGE_COLOR}${DISK_USAGE_PERCENT}%${NC} $STATUS"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# inode检查
|
||||||
|
echo "=========================================="
|
||||||
|
echo "📂 Inode使用概况:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
INODE_INFO=$(df -i "$DISK_PATH" | tail -1)
|
||||||
|
INODE_USED_PERCENT=$(echo "$INODE_INFO" | awk '{print $5}' | sed 's/%//')
|
||||||
|
INODE_TOTAL=$(echo "$INODE_INFO" | awk '{print $2}')
|
||||||
|
INODE_USED=$(echo "$INODE_INFO" | awk '{print $3}')
|
||||||
|
INODE_AVAIL=$(echo "$INODE_INFO" | awk '{print $4}')
|
||||||
|
|
||||||
|
echo -e "总数: ${BLUE}$INODE_TOTAL${NC}"
|
||||||
|
echo -e "已使用: ${YELLOW}$INODE_USED${NC}"
|
||||||
|
echo -e "可用: ${GREEN}$INODE_AVAIL${NC}"
|
||||||
|
|
||||||
|
# Inode百分比颜色
|
||||||
|
if [ "$INODE_USED_PERCENT" -gt 90 ]; then
|
||||||
|
INODE_COLOR="$RED"
|
||||||
|
INODE_STATUS="🔴 严重"
|
||||||
|
elif [ "$INODE_USED_PERCENT" -gt "$THRESHOLD" ]; then
|
||||||
|
INODE_COLOR="$YELLOW"
|
||||||
|
INODE_STATUS="🟡 警告"
|
||||||
|
else
|
||||||
|
INODE_COLOR="$GREEN"
|
||||||
|
INODE_STATUS="🟢 正常"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "使用率: ${INODE_COLOR}${INODE_USED_PERCENT}%${NC} $INODE_STATUS"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 详细信息检测
|
||||||
|
echo "=========================================="
|
||||||
|
echo "🔍 详细信息:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
# 文件系统类型
|
||||||
|
FS_TYPE=$(df -T "$DISK_PATH" | tail -1 | awk '{print $2}')
|
||||||
|
echo -e "文件系统类型: ${CYAN}$FS_TYPE${NC}"
|
||||||
|
|
||||||
|
# 挂载点
|
||||||
|
MOUNT_POINT=$(df "$DISK_PATH" | tail -1 | awk '{print $NF}')
|
||||||
|
echo -e "挂载点: ${BLUE}$MOUNT_POINT${NC}"
|
||||||
|
|
||||||
|
# 可读写性检测
|
||||||
|
if [ -w "$DISK_PATH" ]; then
|
||||||
|
RW_STATUS="${GREEN}可读写${NC}"
|
||||||
|
else
|
||||||
|
RW_STATUS="${RED}只读${NC}"
|
||||||
|
fi
|
||||||
|
echo -e "访问权限: $RW_STATUS"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 警报检查
|
||||||
|
echo "=========================================="
|
||||||
|
echo "🚨 警报检查:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
ALERT_COUNT=0
|
||||||
|
|
||||||
|
if [ "$DISK_USAGE_PERCENT" -gt 90 ]; then
|
||||||
|
echo -e "⚠️ 磁盘使用率过高: ${RED}${DISK_USAGE_PERCENT}%${NC}"
|
||||||
|
((ALERT_COUNT++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$DISK_USAGE_PERCENT" -gt "$THRESHOLD" ]; then
|
||||||
|
echo -e "⚠️ 磁盘使用率超过阈值": "${DISK_USAGE_PERCENT}% > ${THRESHOLD}%"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$INODE_USED_PERCENT" -gt 90 ]; then
|
||||||
|
echo -e "⚠️ Inode使用率过高: ${RED}${INODE_USED_PERCENT}%${NC}"
|
||||||
|
((ALERT_COUNT++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$INODE_USED_PERCENT" -gt "$THRESHOLD" ]; then
|
||||||
|
echo -e "⚠️ Inode使用率超过阈值": "${INODE_USED_PERCENT}% > ${THRESHOLD}%"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -w "$DISK_PATH" ]; then
|
||||||
|
echo -e "⚠️ ${YELLOW}磁盘为只读状态${NC}"
|
||||||
|
((ALERT_COUNT++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "📈 性能指标:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
# 检查磁盘是被大量小文件填满还是少数大文件
|
||||||
|
echo "按大小排序的顶级目录:"
|
||||||
|
du -h "$DISK_PATH" 2>/dev/null | sort -hr | head -5 | while read -r size path; do
|
||||||
|
echo -e " ${YELLOW}$size${NC}\t$path"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "按数量排序的顶级目录:"
|
||||||
|
find "$DISK_PATH" -maxdepth 2 -type d 2>/dev/null | head -10 | while read -r dir; do
|
||||||
|
count=$(find "$dir" -maxdepth 1 -type f 2>/dev/null | wc -l)
|
||||||
|
if [ "$count" -gt 100 ]; then
|
||||||
|
echo -e " ${YELLOW}$count${NC}个文件\t$dir"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "💡 建议:"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
if [ "$ALERT_COUNT" -gt 0 ]; then
|
||||||
|
echo "🚨 发现 $ALERT_COUNT 个问题需要处理:"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ "$DISK_USAGE_PERCENT" -gt 90 ]; then
|
||||||
|
echo " 磁盘使用率超过90%:"
|
||||||
|
echo " - 建议立即清理日志文件(/var/log)"
|
||||||
|
echo " - 检查临时文件(/tmp)"
|
||||||
|
echo " - 考虑扩容或迁移数据"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$INODE_USED_PERCENT" -gt 90 ]; then
|
||||||
|
echo " Inode使用率高:"
|
||||||
|
echo " - 通常由大量小文件导致"
|
||||||
|
echo " - 检查并清理临时文件"
|
||||||
|
echo " - 查找并删除空文件"
|
||||||
|
echo " - 可能是邮件队列或缓存文件过多"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -w "$DISK_PATH" ]; then
|
||||||
|
echo " 磁盘只读:"
|
||||||
|
echo " - 检查文件系统错误(fsck)"
|
||||||
|
echo " - 可能是磁盘故障或挂载问题"
|
||||||
|
echo " - 需要root权限检查和修复"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "✅ 磁盘健康状况良好"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ "$DISK_USAGE_PERCENT" -lt 70 ]; then
|
||||||
|
echo " - 使用率充足,暂无扩容需求"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$INODE_USED_PERCENT" -lt 70 ]; then
|
||||||
|
echo " - Inode充足,无小文件问题"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo " 💡 建议定期运行此工具监控磁盘状态"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "磁盘检查完成"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
exit 0
|
||||||
80
skills/toolkit/bash/system/check-service.meta.yml
Normal file
80
skills/toolkit/bash/system/check-service.meta.yml
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
tool_id: SERVICE-CHECK-001
|
||||||
|
tool_name: "服务健康检查器"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
语言: bash
|
||||||
|
文件: check-service.sh
|
||||||
|
复杂度: level-1
|
||||||
|
创建日期: 2025-11-14
|
||||||
|
作者: CodeConscious
|
||||||
|
|
||||||
|
用途分类:
|
||||||
|
- MONITOR # 监控诊断
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "检查服务健康状态(HTTP/数据库/Redis)"
|
||||||
|
详细: |
|
||||||
|
支持多种服务类型的健康检查:
|
||||||
|
- HTTP服务:检查 /health 端点
|
||||||
|
- 数据库:PostgreSQL连接检查
|
||||||
|
- Redis:连接和ping测试
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- "部署后验证服务是否正常启动"
|
||||||
|
- "诊断服务不可访问问题"
|
||||||
|
- "CI/CD流程中的健康检查"
|
||||||
|
- "定期监控服务状态"
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
命令: "bash check-service.sh [服务名] [检查类型] [超时时间]"
|
||||||
|
参数:
|
||||||
|
服务名: "要检查的服务名称(用于显示)"
|
||||||
|
检查类型:
|
||||||
|
- http: "HTTP健康检查"
|
||||||
|
- db/database: "数据库连接检查"
|
||||||
|
- redis: "Redis连接检查"
|
||||||
|
超时时间: "秒(默认:5秒)"
|
||||||
|
示例:
|
||||||
|
- "检查HTTP服务: bash check-service.sh auth-service http"
|
||||||
|
- "检查数据库: bash check-service.sh db-service db"
|
||||||
|
- "检查Redis: bash check-service.sh cache redis"
|
||||||
|
|
||||||
|
依赖要求:
|
||||||
|
系统命令:
|
||||||
|
- curl: "HTTP客户端"
|
||||||
|
- jq: "JSON解析(可选)"
|
||||||
|
- pg_isready: "PostgreSQL客户端"
|
||||||
|
- redis-cli: "Redis客户端"
|
||||||
|
环境变量:
|
||||||
|
- DB_HOST: "数据库主机(默认:localhost)"
|
||||||
|
- DB_PORT: "数据库端口(默认:5432)"
|
||||||
|
- DB_NAME: "数据库名"
|
||||||
|
- DB_USER: "数据库用户"
|
||||||
|
- REDIS_HOST: "Redis主机(默认:localhost)"
|
||||||
|
- REDIS_PORT: "Redis端口(默认:6379)"
|
||||||
|
|
||||||
|
输入输出:
|
||||||
|
输入:
|
||||||
|
- 无(从环境变量读取配置)
|
||||||
|
输出:
|
||||||
|
- stdout: "人类可读的检查结果"
|
||||||
|
- 退出码:
|
||||||
|
- 0: 所有检查通过
|
||||||
|
- 1: 检查失败
|
||||||
|
- 其他: 参数错误
|
||||||
|
|
||||||
|
上次使用:
|
||||||
|
时间: 2025-11-14 16:45:00
|
||||||
|
用途: "验证auth-service修复后状态"
|
||||||
|
结果: "服务健康,响应时间45ms"
|
||||||
|
满意度: 0.9
|
||||||
|
|
||||||
|
相关工具:
|
||||||
|
- 前置工具: 无
|
||||||
|
- 互补工具:
|
||||||
|
- toolkit/python/analysis/analyze_logs.py(详细日志分析)
|
||||||
|
- toolkit/bash/system/check-disk.sh(磁盘空间检查)
|
||||||
|
|
||||||
|
维护记录:
|
||||||
|
2025-11-14:
|
||||||
|
- 初始创建
|
||||||
76
skills/toolkit/bash/system/check-service.sh
Normal file
76
skills/toolkit/bash/system/check-service.sh
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Service Health Checker
|
||||||
|
# 检查服务健康状态,支持HTTP、数据库、Redis
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SERVICE_NAME="${1:-auth-service}"
|
||||||
|
CHECK_TYPE="${2:-http}"
|
||||||
|
TIMEOUT="${3:-5}"
|
||||||
|
|
||||||
|
echo "🔍 检查服务健康状态"
|
||||||
|
echo "服务: $SERVICE_NAME"
|
||||||
|
echo "检查类型: $CHECK_TYPE"
|
||||||
|
echo "超时: ${TIMEOUT}s"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
case $CHECK_TYPE in
|
||||||
|
http)
|
||||||
|
# HTTP健康检查
|
||||||
|
URL="http://localhost:3000/health"
|
||||||
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time "$TIMEOUT" "$URL" 2>/dev/null || echo "000")
|
||||||
|
|
||||||
|
if [ "$STATUS" = "200" ]; then
|
||||||
|
echo "✅ HTTP服务正常 (状态码: 200)"
|
||||||
|
curl -s --max-time 2 "$URL" | jq '.' 2>/dev/null || echo " (无法解析JSON响应)"
|
||||||
|
else
|
||||||
|
echo "❌ HTTP服务异常 (状态码: $STATUS)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
db|database)
|
||||||
|
# 数据库连接检查
|
||||||
|
if [ -f ".env" ]; then
|
||||||
|
source .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
DB_HOST="${DB_HOST:-localhost}"
|
||||||
|
DB_PORT="${DB_PORT:-5432}"
|
||||||
|
DB_NAME="${DB_NAME:-myapp}"
|
||||||
|
DB_USER="${DB_USER:-postgres}"
|
||||||
|
|
||||||
|
if pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -t "$TIMEOUT" >/dev/null 2>&1; then
|
||||||
|
echo "✅ 数据库连接正常"
|
||||||
|
echo " Host: $DB_HOST:$DB_PORT"
|
||||||
|
echo " Database: $DB_NAME"
|
||||||
|
else
|
||||||
|
echo "❌ 数据库连接失败"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
redis)
|
||||||
|
# Redis连接检查
|
||||||
|
REDIS_HOST="${REDIS_HOST:-localhost}"
|
||||||
|
REDIS_PORT="${REDIS_PORT:-6379}"
|
||||||
|
|
||||||
|
if redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping >/dev/null 2>&1; then
|
||||||
|
echo "✅ Redis连接正常"
|
||||||
|
echo " Host: $REDIS_HOST:$REDIS_PORT"
|
||||||
|
else
|
||||||
|
echo "❌ Redis连接失败"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "❌ 未知的检查类型: $CHECK_TYPE"
|
||||||
|
echo "支持的类型: http, db, redis"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "=========================================="
|
||||||
|
echo "✅ 所有检查通过"
|
||||||
|
exit 0
|
||||||
52
skills/toolkit/discover-toolkit.py
Normal file
52
skills/toolkit/discover-toolkit.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Toolkit Discovery and Management Tool for AI-Runtime
|
||||||
|
|
||||||
|
该工具用于发现、查询和管理 ai-runtime 的工具装备系统。
|
||||||
|
|
||||||
|
功能:
|
||||||
|
- 列出所有内部工具(ai-runtime创建的工具)
|
||||||
|
- 检测外部CLI工具(fzf, eza, fd等)
|
||||||
|
- 按语言/用途过滤工具
|
||||||
|
- 智能工具推荐
|
||||||
|
- 显示工具详情和使用方法
|
||||||
|
- JSON格式输出支持
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
python3 discover-toolkit.py list # 列出所有内部工具
|
||||||
|
python3 discover-toolkit.py list --external # 仅显示外部工具
|
||||||
|
python3 discover-toolkit.py list --include-external # 显示所有工具
|
||||||
|
python3 discover-toolkit.py show TOOL_ID # 显示工具详情
|
||||||
|
python3 discover-toolkit.py recommend "分析日志" # 推荐工具
|
||||||
|
python3 discover-toolkit.py search json # 搜索工具
|
||||||
|
python3 discover-toolkit.py run tool-id [args] # 运行工具
|
||||||
|
|
||||||
|
架构:
|
||||||
|
使用模块化设计,包含以下组件:
|
||||||
|
- detectors/ : 工具检测器(内部/外部)
|
||||||
|
- models/ : 数据模型(Tool, InternalTool, ExternalTool)
|
||||||
|
- formatters/ : 输出格式化器(表格/JSON)
|
||||||
|
- config/ : 配置文件
|
||||||
|
|
||||||
|
旧版本备份:discover-toolkit.py.old(单文件实现)
|
||||||
|
新版本:模块化包结构(discover/)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# 将 discover 包添加到路径
|
||||||
|
toolkit_root = Path(__file__).parent
|
||||||
|
sys.path.insert(0, str(toolkit_root))
|
||||||
|
|
||||||
|
from discover.cli import ToolkitCLI
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""主函数 - 调用 discover 包"""
|
||||||
|
cli = ToolkitCLI(toolkit_root)
|
||||||
|
sys.exit(cli.run())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
36
skills/toolkit/discover/__init__.py
Normal file
36
skills/toolkit/discover/__init__.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
"""
|
||||||
|
Toolkit Discovery Package
|
||||||
|
|
||||||
|
A modular toolkit discovery and management system for ai-runtime.
|
||||||
|
"""
|
||||||
|
|
||||||
|
__version__ = "2.0.0"
|
||||||
|
__author__ = "AI-Runtime Team"
|
||||||
|
|
||||||
|
from .discovery import ToolkitDiscovery
|
||||||
|
from .models import Tool, InternalTool, ExternalTool, ToolMetadata
|
||||||
|
from .detectors import ToolDetector, InternalToolDetector, ExternalToolDetector
|
||||||
|
from .formatters import ToolFormatter, TableFormatter, JsonFormatter
|
||||||
|
from .cli import ToolkitCLI
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
# Main classes
|
||||||
|
'ToolkitDiscovery',
|
||||||
|
'ToolkitCLI',
|
||||||
|
|
||||||
|
# Models
|
||||||
|
'Tool',
|
||||||
|
'InternalTool',
|
||||||
|
'ExternalTool',
|
||||||
|
'ToolMetadata',
|
||||||
|
|
||||||
|
# Detectors
|
||||||
|
'ToolDetector',
|
||||||
|
'InternalToolDetector',
|
||||||
|
'ExternalToolDetector',
|
||||||
|
|
||||||
|
# Formatters
|
||||||
|
'ToolFormatter',
|
||||||
|
'TableFormatter',
|
||||||
|
'JsonFormatter',
|
||||||
|
]
|
||||||
8
skills/toolkit/discover/__main__.py
Normal file
8
skills/toolkit/discover/__main__.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
"""
|
||||||
|
Entry point for python -m discover
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .cli import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
230
skills/toolkit/discover/cli.py
Normal file
230
skills/toolkit/discover/cli.py
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
"""
|
||||||
|
CLI Interface for Toolkit Discovery
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
from .discovery import ToolkitDiscovery
|
||||||
|
|
||||||
|
|
||||||
|
class ToolkitCLI:
|
||||||
|
"""Toolkit Discovery CLI Interface"""
|
||||||
|
|
||||||
|
def __init__(self, toolkit_root: Path):
|
||||||
|
self.toolkit_root = toolkit_root
|
||||||
|
self.discovery = ToolkitDiscovery(toolkit_root)
|
||||||
|
|
||||||
|
def run(self, args=None):
|
||||||
|
"""运行CLI"""
|
||||||
|
parser = self._create_parser()
|
||||||
|
parsed_args = parser.parse_args(args)
|
||||||
|
|
||||||
|
if not parsed_args.command:
|
||||||
|
parser.print_help()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
return self._execute_command(parsed_args)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ 错误: {e}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def _create_parser(self) -> argparse.ArgumentParser:
|
||||||
|
"""创建参数解析器"""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="工具包发现和管理工具",
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
epilog="""
|
||||||
|
示例:
|
||||||
|
python -m discover list # 列出所有工具
|
||||||
|
python -m discover list --lang python # 列出Python工具
|
||||||
|
python -m discover list --external # 仅显示外部工具
|
||||||
|
python -m discover show SERVICE-CHECK-001 # 查看工具详情
|
||||||
|
python -m discover recommend '分析日志' # 推荐工具
|
||||||
|
python -m discover search json # 搜索工具
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
subparsers = parser.add_subparsers(dest="command", help="可用命令")
|
||||||
|
|
||||||
|
# list 命令
|
||||||
|
self._add_list_parser(subparsers)
|
||||||
|
|
||||||
|
# show 命令
|
||||||
|
self._add_show_parser(subparsers)
|
||||||
|
|
||||||
|
# run 命令
|
||||||
|
self._add_run_parser(subparsers)
|
||||||
|
|
||||||
|
# recommend 命令
|
||||||
|
self._add_recommend_parser(subparsers)
|
||||||
|
|
||||||
|
# search 命令
|
||||||
|
self._add_search_parser(subparsers)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def _add_list_parser(self, subparsers):
|
||||||
|
"""添加list命令"""
|
||||||
|
list_parser = subparsers.add_parser("list", help="列出所有工具")
|
||||||
|
list_parser.add_argument("--lang", help="按语言过滤 (bash/python/node)")
|
||||||
|
list_parser.add_argument("--purpose", help="按用途过滤 (DATA/CODE/TEST/BUILD/MONITOR/DOC)")
|
||||||
|
list_parser.add_argument("--query", help="按名称或描述搜索")
|
||||||
|
list_parser.add_argument("--json", action="store_true", help="JSON格式输出")
|
||||||
|
list_parser.add_argument("--external", action="store_true", help="仅显示外部工具")
|
||||||
|
list_parser.add_argument("--include-external", action="store_true", help="包含外部工具")
|
||||||
|
|
||||||
|
def _add_show_parser(self, subparsers):
|
||||||
|
"""添加show命令"""
|
||||||
|
show_parser = subparsers.add_parser("show", help="显示工具详情")
|
||||||
|
show_parser.add_argument("tool", help="工具ID或名称")
|
||||||
|
|
||||||
|
def _add_run_parser(self, subparsers):
|
||||||
|
"""添加run命令"""
|
||||||
|
run_parser = subparsers.add_parser("run", help="运行工具")
|
||||||
|
run_parser.add_argument("tool", help="工具ID或名称")
|
||||||
|
run_parser.add_argument("args", nargs=argparse.REMAINDER, help="工具参数")
|
||||||
|
|
||||||
|
def _add_recommend_parser(self, subparsers):
|
||||||
|
"""添加recommend命令"""
|
||||||
|
recommend_parser = subparsers.add_parser("recommend", help="推荐工具")
|
||||||
|
recommend_parser.add_argument("task", help="任务描述")
|
||||||
|
|
||||||
|
def _add_search_parser(self, subparsers):
|
||||||
|
"""添加search命令"""
|
||||||
|
search_parser = subparsers.add_parser("search", help="搜索工具")
|
||||||
|
search_parser.add_argument("keyword", help="搜索关键词")
|
||||||
|
|
||||||
|
def _execute_command(self, args) -> int:
|
||||||
|
"""执行命令"""
|
||||||
|
if args.command == "list":
|
||||||
|
return self._cmd_list(args)
|
||||||
|
elif args.command == "show":
|
||||||
|
return self._cmd_show(args)
|
||||||
|
elif args.command == "run":
|
||||||
|
return self._cmd_run(args)
|
||||||
|
elif args.command == "recommend":
|
||||||
|
return self._cmd_recommend(args)
|
||||||
|
elif args.command == "search":
|
||||||
|
return self._cmd_search(args)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _cmd_list(self, args) -> int:
|
||||||
|
"""执行list命令"""
|
||||||
|
# 判断输出格式
|
||||||
|
format_type = "json" if args.json else "table"
|
||||||
|
|
||||||
|
# 获取工具列表
|
||||||
|
if args.external:
|
||||||
|
tools = self.discovery.external_tools
|
||||||
|
elif args.include_external:
|
||||||
|
tools = self.discovery.all_tools
|
||||||
|
else:
|
||||||
|
tools = self.discovery.internal_tools
|
||||||
|
|
||||||
|
# 过滤内部工具
|
||||||
|
if not args.external:
|
||||||
|
tools = self.discovery.filter_tools(
|
||||||
|
lang=args.lang,
|
||||||
|
purpose=args.purpose,
|
||||||
|
query=args.query
|
||||||
|
)
|
||||||
|
|
||||||
|
# 输出
|
||||||
|
output = self.discovery.format_tools(tools, format_type=format_type)
|
||||||
|
print(output)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _cmd_show(self, args) -> int:
|
||||||
|
"""执行show命令"""
|
||||||
|
tool = self.discovery.find_tool(args.tool)
|
||||||
|
if not tool:
|
||||||
|
print(f"❌ 未找到工具: {args.tool}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
print(self.discovery.format_tool(tool))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _cmd_run(self, args) -> int:
|
||||||
|
"""执行run命令"""
|
||||||
|
# 注意: 这里简化处理,实际应该直接从文件执行
|
||||||
|
# 为了保持向后兼容,这里直接调用工具文件
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
tool = self.discovery.find_tool(args.tool)
|
||||||
|
if not tool:
|
||||||
|
print(f"❌ 未找到工具: {args.tool}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
# 检查是否有tool_file(仅内部工具有)
|
||||||
|
if not hasattr(tool, 'tool_file') or not tool.tool_file:
|
||||||
|
print(f"❌ 外部工具无法直接运行: {args.tool}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
tool_path = self.toolkit_root / tool.tool_file
|
||||||
|
if not tool_path.exists():
|
||||||
|
print(f"❌ 工具文件不存在: {tool_path}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
print(f"🚀 运行工具: {tool.tool_name}")
|
||||||
|
print(f"📁 文件: {tool.tool_file}")
|
||||||
|
print(f"⏳ 正在执行...")
|
||||||
|
print("=" * 70)
|
||||||
|
|
||||||
|
try:
|
||||||
|
cmd = [str(tool_path)] + args.args
|
||||||
|
result = subprocess.run(cmd, capture_output=False)
|
||||||
|
print("=" * 70)
|
||||||
|
print(f"✅ 执行完成 (退出码: {result.returncode})")
|
||||||
|
return result.returncode
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ 执行失败: {e}")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def _cmd_recommend(self, args) -> int:
|
||||||
|
"""执行recommend命令"""
|
||||||
|
tools = self.discovery.recommend_tools(args.task)
|
||||||
|
|
||||||
|
if not tools:
|
||||||
|
print(f"💡 未找到匹配的工具,尝试使用更通用的关键词搜索")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
print(f"\n🔍 为任务 '{args.task}' 推荐工具:")
|
||||||
|
print("=" * 70)
|
||||||
|
|
||||||
|
for i, tool in enumerate(tools[:5], 1):
|
||||||
|
print(f"\n{i}. {tool.tool_name}")
|
||||||
|
print(f" ID: {tool.tool_id}")
|
||||||
|
print(f" 语言: {tool.language}")
|
||||||
|
print(f" 描述: {tool.description[:60]}...")
|
||||||
|
|
||||||
|
print("\n" + "=" * 70)
|
||||||
|
print("💡 使用: show <tool-id> 查看详情")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _cmd_search(self, args) -> int:
|
||||||
|
"""执行search命令"""
|
||||||
|
tools = self.discovery.search_tools(args.keyword)
|
||||||
|
|
||||||
|
if not tools:
|
||||||
|
print(f"⚠️ 未找到包含 '{args.keyword}' 的工具")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
print(f"\n🔍 搜索 '{args.keyword}' 找到 {len(tools)} 个结果:")
|
||||||
|
for tool in tools:
|
||||||
|
print(f" • {tool.tool_name} ({tool.tool_id}) - {tool.description[:50]}...")
|
||||||
|
print()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""主函数"""
|
||||||
|
toolkit_root = Path(__file__).parent.parent
|
||||||
|
cli = ToolkitCLI(toolkit_root)
|
||||||
|
sys.exit(cli.run())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
13
skills/toolkit/discover/config/__init__.py
Normal file
13
skills/toolkit/discover/config/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
Configuration management for toolkit discovery
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
CONFIG_ROOT = Path(__file__).parent
|
||||||
|
EXTERNAL_TOOLS_CONFIG = CONFIG_ROOT / "external_tools.yaml"
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'CONFIG_ROOT',
|
||||||
|
'EXTERNAL_TOOLS_CONFIG'
|
||||||
|
]
|
||||||
113
skills/toolkit/discover/config/external_tools.yaml
Normal file
113
skills/toolkit/discover/config/external_tools.yaml
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# External Tool Configurations
|
||||||
|
# 外部工具配置信息,与代码分离便于维护
|
||||||
|
|
||||||
|
tools:
|
||||||
|
- tool_id: "EXT-FZF-001"
|
||||||
|
tool_name: "fzf (Fuzzy Finder)"
|
||||||
|
command: "fzf"
|
||||||
|
description: "命令行模糊查找器,用于交互式选择"
|
||||||
|
category: "搜索/交互"
|
||||||
|
use_cases:
|
||||||
|
- "文件名查找"
|
||||||
|
- "历史命令搜索"
|
||||||
|
- "Git分支切换"
|
||||||
|
install_guide: "brew install fzf (macOS) / apt-get install fzf (Ubuntu)"
|
||||||
|
|
||||||
|
- tool_id: "EXT-EZA-001"
|
||||||
|
tool_name: "eza (Modern ls)"
|
||||||
|
command: "eza"
|
||||||
|
description: "现代化的ls替代品,带彩色输出和图标"
|
||||||
|
category: "文件列表"
|
||||||
|
use_cases:
|
||||||
|
- "查看文件列表"
|
||||||
|
- "树形结构显示"
|
||||||
|
- "Git状态查看"
|
||||||
|
install_guide: "brew install eza"
|
||||||
|
|
||||||
|
- tool_id: "EXT-ZOXIDE-001"
|
||||||
|
tool_name: "zoxide (Smart cd)"
|
||||||
|
command: "zoxide"
|
||||||
|
description: "智能目录跳转工具,学习访问习惯"
|
||||||
|
category: "目录导航"
|
||||||
|
use_cases:
|
||||||
|
- "快速跳转目录"
|
||||||
|
- "访问频率学习"
|
||||||
|
install_guide: "curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh"
|
||||||
|
|
||||||
|
- tool_id: "EXT-FD-001"
|
||||||
|
tool_name: "fd (Simple find)"
|
||||||
|
command: "fd"
|
||||||
|
description: "简单友好的find替代品"
|
||||||
|
category: "文件搜索"
|
||||||
|
use_cases:
|
||||||
|
- "查找文件"
|
||||||
|
- "忽略.gitignore搜索"
|
||||||
|
- "执行操作"
|
||||||
|
install_guide: "brew install fd"
|
||||||
|
|
||||||
|
- tool_id: "EXT-RG-001"
|
||||||
|
tool_name: "ripgrep (rg)"
|
||||||
|
command: "rg"
|
||||||
|
description: "极速代码搜索工具"
|
||||||
|
category: "代码搜索"
|
||||||
|
use_cases:
|
||||||
|
- "搜索代码"
|
||||||
|
- "显示上下文"
|
||||||
|
- "统计匹配数"
|
||||||
|
install_guide: "brew install ripgrep"
|
||||||
|
|
||||||
|
- tool_id: "EXT-BAT-001"
|
||||||
|
tool_name: "bat (cat with syntax)"
|
||||||
|
command: "bat"
|
||||||
|
description: "带语法高亮的cat替代品"
|
||||||
|
category: "文件查看"
|
||||||
|
use_cases:
|
||||||
|
- "查看代码文件"
|
||||||
|
- "分页查看"
|
||||||
|
- "Git修改查看"
|
||||||
|
install_guide: "brew install bat"
|
||||||
|
|
||||||
|
- tool_id: "EXT-JQ-001"
|
||||||
|
tool_name: "jq (JSON processor)"
|
||||||
|
command: "jq"
|
||||||
|
description: "JSON数据的命令行处理器"
|
||||||
|
category: "数据处理"
|
||||||
|
use_cases:
|
||||||
|
- "JSON美化"
|
||||||
|
- "字段提取"
|
||||||
|
- "数据过滤"
|
||||||
|
- "格式转换"
|
||||||
|
install_guide: "brew install jq"
|
||||||
|
|
||||||
|
- tool_id: "EXT-XH-001"
|
||||||
|
tool_name: "xh (HTTP client)"
|
||||||
|
command: "xh"
|
||||||
|
description: "友好的HTTP客户端,替代curl"
|
||||||
|
category: "API测试"
|
||||||
|
use_cases:
|
||||||
|
- "发送HTTP请求"
|
||||||
|
- "API测试"
|
||||||
|
- "文件下载"
|
||||||
|
install_guide: "brew install xh"
|
||||||
|
|
||||||
|
- tool_id: "EXT-DELTA-001"
|
||||||
|
tool_name: "delta (Git diff美化)"
|
||||||
|
command: "delta"
|
||||||
|
description: "Git diff的美化工具"
|
||||||
|
category: "Git工具"
|
||||||
|
use_cases:
|
||||||
|
- "查看Git diff"
|
||||||
|
- "语法高亮"
|
||||||
|
- "行号显示"
|
||||||
|
install_guide: "brew install git-delta"
|
||||||
|
|
||||||
|
- tool_id: "EXT-STEAMSHIP-001"
|
||||||
|
tool_name: "starship (Shell提示符)"
|
||||||
|
command: "starship"
|
||||||
|
description: "快速、可定制、智能的Shell提示符"
|
||||||
|
category: "Shell增强"
|
||||||
|
use_cases:
|
||||||
|
- "显示Git状态"
|
||||||
|
- "显示Python版本"
|
||||||
|
- "显示目录"
|
||||||
|
install_guide: "curl -sS https://starship.rs/install.sh | sh"
|
||||||
13
skills/toolkit/discover/detectors/__init__.py
Normal file
13
skills/toolkit/discover/detectors/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
Tool Detectors Module
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .base import ToolDetector
|
||||||
|
from .internal import InternalToolDetector
|
||||||
|
from .external import ExternalToolDetector
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'ToolDetector',
|
||||||
|
'InternalToolDetector',
|
||||||
|
'ExternalToolDetector'
|
||||||
|
]
|
||||||
51
skills/toolkit/discover/detectors/base.py
Normal file
51
skills/toolkit/discover/detectors/base.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
"""
|
||||||
|
Base detector interface for toolkit discovery
|
||||||
|
"""
|
||||||
|
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Any
|
||||||
|
from ..models import Tool
|
||||||
|
|
||||||
|
|
||||||
|
class ToolDetector(ABC):
|
||||||
|
"""抽象基类:工具检测器"""
|
||||||
|
|
||||||
|
def __init__(self, root_path: Path):
|
||||||
|
self.root = root_path
|
||||||
|
self._tools = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tools(self) -> List[Tool]:
|
||||||
|
"""获取检测到的工具列表"""
|
||||||
|
return self._tools
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def detect(self) -> List[Tool]:
|
||||||
|
"""
|
||||||
|
检测工具
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Tool]: 检测到的工具列表
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def find_tool(self, name_or_id: str) -> Tool:
|
||||||
|
"""
|
||||||
|
查找工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name_or_id: 工具名称或ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tool: 找到的工具
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ToolDetectorError: 如果工具未找到
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
"""刷新工具列表"""
|
||||||
|
self._tools = self.detect()
|
||||||
129
skills/toolkit/discover/detectors/external.py
Normal file
129
skills/toolkit/discover/detectors/external.py
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
"""
|
||||||
|
External Tool Detector - 检测系统已安装的外部CLI工具
|
||||||
|
"""
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional, Dict, Any
|
||||||
|
from .base import ToolDetector
|
||||||
|
from ..models import ExternalTool, ToolMetadata
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalToolDetector(ToolDetector):
|
||||||
|
"""外部工具检测器
|
||||||
|
|
||||||
|
从external/目录扫描.meta.yml文件来发现外部工具配置
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, root_path: Path):
|
||||||
|
super().__init__(root_path)
|
||||||
|
self._external_dir = root_path / "external"
|
||||||
|
|
||||||
|
def detect(self) -> List[ExternalTool]:
|
||||||
|
"""
|
||||||
|
扫描external/目录检测外部工具
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[ExternalTool]: 检测到的外部工具列表
|
||||||
|
"""
|
||||||
|
self._tools = []
|
||||||
|
|
||||||
|
# 扫描external目录下的所有.meta.yml文件
|
||||||
|
if self._external_dir.exists():
|
||||||
|
for meta_file in self._external_dir.rglob("*.meta.yml"):
|
||||||
|
tool = self._parse_meta_file(meta_file)
|
||||||
|
if tool:
|
||||||
|
self._tools.append(tool)
|
||||||
|
|
||||||
|
return self._tools
|
||||||
|
|
||||||
|
def _parse_meta_file(self, meta_file: Path) -> Optional[ExternalTool]:
|
||||||
|
"""解析外部工具的meta.yml文件"""
|
||||||
|
try:
|
||||||
|
content = yaml.safe_load(meta_file.read_text(encoding='utf-8'))
|
||||||
|
if not content:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 获取基本信息
|
||||||
|
basic_info = content.get("基本信息", {})
|
||||||
|
tool_type = basic_info.get("类型", "external")
|
||||||
|
|
||||||
|
# 只处理external类型的工具
|
||||||
|
if tool_type != "external":
|
||||||
|
return None
|
||||||
|
|
||||||
|
command = basic_info.get("命令", "")
|
||||||
|
if not command:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 检测是否已安装
|
||||||
|
command_name = command.split()[0]
|
||||||
|
is_installed = shutil.which(command_name) is not None
|
||||||
|
tool_path = shutil.which(command_name)
|
||||||
|
|
||||||
|
# 创建metadata
|
||||||
|
metadata = ToolMetadata(
|
||||||
|
tool_id=content.get("tool_id", "unknown"),
|
||||||
|
tool_name=content.get("tool_name", "未命名工具"),
|
||||||
|
description=content.get("功能描述", {}).get("简介", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
# 获取功能描述
|
||||||
|
func_desc = content.get("功能描述", {})
|
||||||
|
|
||||||
|
# 获取快速开始信息
|
||||||
|
quick_start = content.get("快速开始", {})
|
||||||
|
|
||||||
|
return ExternalTool(
|
||||||
|
metadata=metadata,
|
||||||
|
command=command,
|
||||||
|
category=basic_info.get("类别", "unknown"),
|
||||||
|
use_cases=content.get("使用场景", []),
|
||||||
|
install_guide=quick_start.get("安装", ""),
|
||||||
|
installed=is_installed,
|
||||||
|
path=tool_path
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# 静默失败单个工具的检测
|
||||||
|
return None
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
"""刷新工具列表"""
|
||||||
|
# 重新扫描external目录
|
||||||
|
super().refresh()
|
||||||
|
|
||||||
|
def find_tool(self, name_or_id: str) -> Optional[ExternalTool]:
|
||||||
|
"""
|
||||||
|
查找外部工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name_or_id: 工具名称或ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
ExternalTool: 找到的工具,如果未找到返回None
|
||||||
|
"""
|
||||||
|
# 先尝试精确匹配
|
||||||
|
for tool in self._tools:
|
||||||
|
if tool.tool_id == name_or_id or tool.tool_name == name_or_id:
|
||||||
|
return tool
|
||||||
|
|
||||||
|
# 尝试模糊匹配(名称包含)
|
||||||
|
matches = [t for t in self._tools if name_or_id.lower() in t.tool_name.lower()]
|
||||||
|
|
||||||
|
if len(matches) == 1:
|
||||||
|
return matches[0]
|
||||||
|
elif len(matches) > 1:
|
||||||
|
# 不打印,由调用者处理
|
||||||
|
return None
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_uninstalled_tools(self) -> List[ExternalTool]:
|
||||||
|
"""获取未安装的工具列表"""
|
||||||
|
return [t for t in self._tools if not t.installed]
|
||||||
|
|
||||||
|
def get_installed_tools(self) -> List[ExternalTool]:
|
||||||
|
"""获取已安装的工具列表"""
|
||||||
|
return [t for t in self._tools if t.installed]
|
||||||
137
skills/toolkit/discover/detectors/internal.py
Normal file
137
skills/toolkit/discover/detectors/internal.py
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
"""
|
||||||
|
Internal Tool Detector - 检测AI-runtime内部创建的工具
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import yaml
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Dict, Any, Optional
|
||||||
|
from .base import ToolDetector
|
||||||
|
from ..models import InternalTool, ToolMetadata
|
||||||
|
|
||||||
|
|
||||||
|
class InternalToolDetector(ToolDetector):
|
||||||
|
"""内部工具检测器"""
|
||||||
|
|
||||||
|
def detect(self) -> List[InternalTool]:
|
||||||
|
"""
|
||||||
|
扫描工具包目录检测内部工具
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[InternalTool]: 检测到的内部工具列表
|
||||||
|
"""
|
||||||
|
self._tools = []
|
||||||
|
|
||||||
|
# 加载registry.md(暂时跳过详细解析)
|
||||||
|
registry_file = self.root / "registry.md"
|
||||||
|
if registry_file.exists():
|
||||||
|
# 这里可以扩展registry解析逻辑
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 扫描所有语言目录
|
||||||
|
for lang_dir in self.root.iterdir():
|
||||||
|
if lang_dir.is_dir() and not lang_dir.name.startswith('.') and lang_dir.name != 'discover':
|
||||||
|
self._scan_language_directory(lang_dir)
|
||||||
|
|
||||||
|
return self._tools
|
||||||
|
|
||||||
|
def _scan_language_directory(self, lang_dir: Path):
|
||||||
|
"""扫描语言目录下的工具"""
|
||||||
|
for meta_file in lang_dir.rglob("*.meta.yml"):
|
||||||
|
try:
|
||||||
|
tool = self._parse_meta_file(meta_file)
|
||||||
|
if tool:
|
||||||
|
self._tools.append(tool)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ 解析失败 {meta_file}: {e}", file=sys.stderr)
|
||||||
|
|
||||||
|
def _parse_meta_file(self, meta_file: Path) -> Optional[InternalTool]:
|
||||||
|
"""解析元数据文件"""
|
||||||
|
try:
|
||||||
|
content = yaml.safe_load(meta_file.read_text(encoding='utf-8'))
|
||||||
|
if not content:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 获取工具文件
|
||||||
|
tool_file = self._find_tool_file(meta_file)
|
||||||
|
|
||||||
|
# 解析基本信息
|
||||||
|
basic_info = content.get("基本信息", {})
|
||||||
|
|
||||||
|
# 创建metadata
|
||||||
|
metadata = ToolMetadata(
|
||||||
|
tool_id=content.get("tool_id", "unknown"),
|
||||||
|
tool_name=content.get("tool_name", "未命名工具"),
|
||||||
|
description=content.get("功能描述", {}).get("简介", ""),
|
||||||
|
purpose=content.get("用途分类", [])
|
||||||
|
)
|
||||||
|
|
||||||
|
# 解析上次使用信息
|
||||||
|
last_use = content.get("上次使用", {})
|
||||||
|
if last_use:
|
||||||
|
metadata.satisfaction = last_use.get("满意度", 0.0)
|
||||||
|
|
||||||
|
return InternalTool(
|
||||||
|
metadata=metadata,
|
||||||
|
meta_file=str(meta_file.relative_to(self.root)),
|
||||||
|
tool_file=str(tool_file.relative_to(self.root)) if tool_file else None,
|
||||||
|
language=basic_info.get("语言", "unknown"),
|
||||||
|
file=basic_info.get("文件", "unknown"),
|
||||||
|
complexity=basic_info.get("复杂度", "unknown"),
|
||||||
|
usage=content.get("使用方法", {}),
|
||||||
|
full_meta=content
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ 警告: 解析元数据文件失败 {meta_file}: {e}", file=sys.stderr)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _find_tool_file(self, meta_file: Path) -> Optional[Path]:
|
||||||
|
"""查找与meta文件对应的工具文件"""
|
||||||
|
possible_extensions = ['.sh', '.py', '.js', '.ts', '.java', '.go', '.rs']
|
||||||
|
|
||||||
|
for ext in possible_extensions:
|
||||||
|
possible_file = meta_file.with_suffix(ext)
|
||||||
|
if possible_file.exists():
|
||||||
|
return possible_file
|
||||||
|
|
||||||
|
# 如果没找到,尝试与meta文件同名(去掉.meta部分)
|
||||||
|
name_without_meta = meta_file.stem.replace('.meta', '')
|
||||||
|
for ext in possible_extensions:
|
||||||
|
possible_file = meta_file.parent / f"{name_without_meta}{ext}"
|
||||||
|
if possible_file.exists():
|
||||||
|
return possible_file
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def find_tool(self, name_or_id: str) -> Optional[InternalTool]:
|
||||||
|
"""
|
||||||
|
查找内部工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name_or_id: 工具名称或ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
InternalTool: 找到的工具,如果未找到返回None
|
||||||
|
"""
|
||||||
|
# 先尝试精确匹配
|
||||||
|
for tool in self._tools:
|
||||||
|
if tool.tool_id == name_or_id or tool.tool_name == name_or_id:
|
||||||
|
return tool
|
||||||
|
|
||||||
|
# 尝试模糊匹配(名称包含)
|
||||||
|
matches = [t for t in self._tools if name_or_id.lower() in t.tool_name.lower()]
|
||||||
|
|
||||||
|
if len(matches) == 1:
|
||||||
|
return matches[0]
|
||||||
|
elif len(matches) > 1:
|
||||||
|
print(f"⚠️ 找到多个匹配工具:")
|
||||||
|
for i, tool in enumerate(matches[:5], 1):
|
||||||
|
print(f" {i}. {tool.tool_name} ({tool.tool_id})")
|
||||||
|
return None
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
"""刷新工具列表"""
|
||||||
|
super().refresh()
|
||||||
222
skills/toolkit/discover/discovery.py
Normal file
222
skills/toolkit/discover/discovery.py
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
"""
|
||||||
|
Main Discovery Orchestrator - 协调内部和外部工具检测
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional
|
||||||
|
from .detectors import InternalToolDetector, ExternalToolDetector
|
||||||
|
from .models import Tool, InternalTool, ExternalTool
|
||||||
|
from .formatters import ToolFormatter, TableFormatter, JsonFormatter
|
||||||
|
|
||||||
|
|
||||||
|
class ToolkitDiscovery:
|
||||||
|
"""工具包发现主类 - 协调所有检测器"""
|
||||||
|
|
||||||
|
def __init__(self, toolkit_root: Path):
|
||||||
|
self.root = toolkit_root
|
||||||
|
self.internal_detector = InternalToolDetector(toolkit_root)
|
||||||
|
self.external_detector = ExternalToolDetector(toolkit_root)
|
||||||
|
|
||||||
|
# 格式化器
|
||||||
|
self.table_formatter = TableFormatter()
|
||||||
|
self.json_formatter = JsonFormatter()
|
||||||
|
|
||||||
|
# 初始化时加载所有工具
|
||||||
|
self.refresh()
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
"""刷新所有工具列表"""
|
||||||
|
self.internal_detector.refresh()
|
||||||
|
self.external_detector.refresh()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def internal_tools(self) -> List[InternalTool]:
|
||||||
|
"""获取内部工具列表"""
|
||||||
|
return self.internal_detector.tools
|
||||||
|
|
||||||
|
@property
|
||||||
|
def external_tools(self) -> List[ExternalTool]:
|
||||||
|
"""获取外部工具列表"""
|
||||||
|
return self.external_detector.tools
|
||||||
|
|
||||||
|
@property
|
||||||
|
def all_tools(self) -> List[Tool]:
|
||||||
|
"""获取所有工具列表"""
|
||||||
|
return self.internal_tools + self.external_tools
|
||||||
|
|
||||||
|
def list_tools(
|
||||||
|
self,
|
||||||
|
internal_only: bool = False,
|
||||||
|
external_only: bool = False
|
||||||
|
) -> List[Tool]:
|
||||||
|
"""
|
||||||
|
列出工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
internal_only: 仅返回内部工具
|
||||||
|
external_only: 仅返回外部工具
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Tool]: 工具列表
|
||||||
|
"""
|
||||||
|
if internal_only:
|
||||||
|
return self.internal_tools
|
||||||
|
elif external_only:
|
||||||
|
return self.external_tools
|
||||||
|
else:
|
||||||
|
return self.all_tools
|
||||||
|
|
||||||
|
def find_tool(self, name_or_id: str) -> Optional[Tool]:
|
||||||
|
"""
|
||||||
|
查找工具(同时搜索内部和外部)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name_or_id: 工具名称或ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tool: 找到的工具,如果未找到返回None
|
||||||
|
"""
|
||||||
|
# 先搜索内部工具
|
||||||
|
tool = self.internal_detector.find_tool(name_or_id)
|
||||||
|
if tool:
|
||||||
|
return tool
|
||||||
|
|
||||||
|
# 再搜索外部工具
|
||||||
|
tool = self.external_detector.find_tool(name_or_id)
|
||||||
|
if tool:
|
||||||
|
return tool
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def filter_tools(
|
||||||
|
self,
|
||||||
|
lang: Optional[str] = None,
|
||||||
|
purpose: Optional[str] = None,
|
||||||
|
query: Optional[str] = None
|
||||||
|
) -> List[InternalTool]:
|
||||||
|
"""
|
||||||
|
过滤内部工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
lang: 按语言过滤
|
||||||
|
purpose: 按用途过滤
|
||||||
|
query: 按名称或描述搜索
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[InternalTool]: 过滤后的内部工具列表
|
||||||
|
"""
|
||||||
|
tools = self.internal_tools
|
||||||
|
|
||||||
|
if lang:
|
||||||
|
tools = [t for t in tools if t.language == lang]
|
||||||
|
|
||||||
|
if purpose:
|
||||||
|
tools = [t for t in tools if purpose in t.metadata.purpose]
|
||||||
|
|
||||||
|
if query:
|
||||||
|
query_lower = query.lower()
|
||||||
|
tools = [
|
||||||
|
t for t in tools
|
||||||
|
if query_lower in t.tool_name.lower() or query_lower in t.description.lower()
|
||||||
|
]
|
||||||
|
|
||||||
|
return tools
|
||||||
|
|
||||||
|
def search_tools(self, keyword: str) -> List[Tool]:
|
||||||
|
"""
|
||||||
|
搜索工具(内部和外部)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
keyword: 搜索关键词
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[Tool]: 匹配的工具列表
|
||||||
|
"""
|
||||||
|
keyword_lower = keyword.lower()
|
||||||
|
|
||||||
|
# 搜索内部工具
|
||||||
|
internal_matches = [
|
||||||
|
t for t in self.internal_tools
|
||||||
|
if (keyword_lower in t.tool_name.lower() or
|
||||||
|
keyword_lower in t.description.lower())
|
||||||
|
]
|
||||||
|
|
||||||
|
# 搜索外部工具
|
||||||
|
external_matches = [
|
||||||
|
t for t in self.external_tools
|
||||||
|
if (keyword_lower in t.tool_name.lower() or
|
||||||
|
keyword_lower in t.description.lower() or
|
||||||
|
keyword_lower in t.category.lower())
|
||||||
|
]
|
||||||
|
|
||||||
|
return internal_matches + external_matches
|
||||||
|
|
||||||
|
def recommend_tools(self, task_description: str) -> List[InternalTool]:
|
||||||
|
"""
|
||||||
|
根据任务描述推荐工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task_description: 任务描述
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[InternalTool]: 推荐的工具列表(按匹配度排序)
|
||||||
|
"""
|
||||||
|
keywords = task_description.lower().split()
|
||||||
|
|
||||||
|
# 简单的推荐算法:匹配关键词数量
|
||||||
|
scores = {}
|
||||||
|
for tool in self.internal_tools:
|
||||||
|
score = 0
|
||||||
|
tool_text = (
|
||||||
|
tool.tool_name + ' ' +
|
||||||
|
tool.description + ' ' +
|
||||||
|
' '.join(tool.metadata.purpose)
|
||||||
|
).lower()
|
||||||
|
|
||||||
|
for keyword in keywords:
|
||||||
|
if keyword in tool_text:
|
||||||
|
score += 1
|
||||||
|
|
||||||
|
if score > 0:
|
||||||
|
scores[tool] = score
|
||||||
|
|
||||||
|
# 按分数排序
|
||||||
|
sorted_tools = sorted(scores.items(), key=lambda x: x[1], reverse=True)
|
||||||
|
|
||||||
|
return [tool for tool, _ in sorted_tools[:5]] # 返回前5个
|
||||||
|
|
||||||
|
def format_tools(
|
||||||
|
self,
|
||||||
|
tools: List[Tool],
|
||||||
|
format_type: str = 'table'
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
格式化工具列表
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tools: 工具列表
|
||||||
|
format_type: 格式类型 ('table' 或 'json')
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 格式化后的字符串
|
||||||
|
"""
|
||||||
|
if format_type == 'json':
|
||||||
|
return self.json_formatter.format(tools)
|
||||||
|
else:
|
||||||
|
return self.table_formatter.format(tools)
|
||||||
|
|
||||||
|
def format_tool(self, tool: Tool, format_type: str = 'table') -> str:
|
||||||
|
"""
|
||||||
|
格式化单个工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tool: 工具对象
|
||||||
|
format_type: 格式类型 ('table' 或 'json')
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 格式化后的字符串
|
||||||
|
"""
|
||||||
|
if format_type == 'json':
|
||||||
|
return self.json_formatter.format_single(tool)
|
||||||
|
else:
|
||||||
|
return self.table_formatter.format_single(tool)
|
||||||
13
skills/toolkit/discover/formatters/__init__.py
Normal file
13
skills/toolkit/discover/formatters/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
Output Formatters Module
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .base import ToolFormatter
|
||||||
|
from .table import TableFormatter
|
||||||
|
from .json import JsonFormatter
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'ToolFormatter',
|
||||||
|
'TableFormatter',
|
||||||
|
'JsonFormatter'
|
||||||
|
]
|
||||||
37
skills/toolkit/discover/formatters/base.py
Normal file
37
skills/toolkit/discover/formatters/base.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
"""
|
||||||
|
Abstract base class for tool formatters
|
||||||
|
"""
|
||||||
|
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import List
|
||||||
|
from ..models import Tool
|
||||||
|
|
||||||
|
|
||||||
|
class ToolFormatter(ABC):
|
||||||
|
"""抽象基类:工具输出格式化器"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def format(self, tools: List[Tool]) -> str:
|
||||||
|
"""
|
||||||
|
格式化工具列表
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tools: 工具列表
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 格式化后的字符串
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def format_single(self, tool: Tool) -> str:
|
||||||
|
"""
|
||||||
|
格式化单个工具
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tool: 工具对象
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 格式化后的字符串
|
||||||
|
"""
|
||||||
|
pass
|
||||||
67
skills/toolkit/discover/formatters/json.py
Normal file
67
skills/toolkit/discover/formatters/json.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
"""
|
||||||
|
JSON Formatter - JSON格式输出
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
from typing import List
|
||||||
|
from .base import ToolFormatter
|
||||||
|
from ..models import Tool, InternalTool, ExternalTool
|
||||||
|
|
||||||
|
|
||||||
|
class JsonFormatter(ToolFormatter):
|
||||||
|
"""JSON格式化器"""
|
||||||
|
|
||||||
|
def format(self, tools: List[Tool]) -> str:
|
||||||
|
"""格式化工具列表为JSON"""
|
||||||
|
result = []
|
||||||
|
for tool in tools:
|
||||||
|
result.append(self._tool_to_dict(tool))
|
||||||
|
return json.dumps(result, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
def format_single(self, tool: Tool) -> str:
|
||||||
|
"""格式化单个工具为JSON"""
|
||||||
|
return json.dumps(self._tool_to_dict(tool), indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
def _tool_to_dict(self, tool: Tool) -> dict:
|
||||||
|
"""将工具对象转换为字典"""
|
||||||
|
# 基础信息
|
||||||
|
data = {
|
||||||
|
"tool_id": tool.tool_id,
|
||||||
|
"tool_name": tool.tool_name,
|
||||||
|
"description": tool.description
|
||||||
|
}
|
||||||
|
|
||||||
|
# 内部工具特有信息
|
||||||
|
if isinstance(tool, InternalTool):
|
||||||
|
data.update({
|
||||||
|
"type": "internal",
|
||||||
|
"language": tool.language,
|
||||||
|
"file": tool.file,
|
||||||
|
"complexity": tool.complexity,
|
||||||
|
"meta_file": tool.meta_file,
|
||||||
|
"tool_file": tool.tool_file,
|
||||||
|
"purpose": tool.metadata.purpose,
|
||||||
|
"usage": tool.usage
|
||||||
|
})
|
||||||
|
|
||||||
|
if tool.metadata.satisfaction > 0:
|
||||||
|
data["satisfaction"] = tool.metadata.satisfaction
|
||||||
|
|
||||||
|
# 外部工具特有信息
|
||||||
|
elif isinstance(tool, ExternalTool):
|
||||||
|
data.update({
|
||||||
|
"type": "external",
|
||||||
|
"command": tool.command,
|
||||||
|
"category": tool.category,
|
||||||
|
"use_cases": tool.use_cases,
|
||||||
|
"install_guide": tool.install_guide,
|
||||||
|
"installed": tool.installed
|
||||||
|
})
|
||||||
|
|
||||||
|
if tool.path:
|
||||||
|
data["path"] = tool.path
|
||||||
|
|
||||||
|
if tool.metadata.version != "1.0.0":
|
||||||
|
data["version"] = tool.metadata.version
|
||||||
|
|
||||||
|
return data
|
||||||
178
skills/toolkit/discover/formatters/table.py
Normal file
178
skills/toolkit/discover/formatters/table.py
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
"""
|
||||||
|
Table Formatter - 表格格式输出
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import List, Any
|
||||||
|
from .base import ToolFormatter
|
||||||
|
from ..models import Tool, InternalTool, ExternalTool
|
||||||
|
|
||||||
|
|
||||||
|
class TableFormatter(ToolFormatter):
|
||||||
|
"""表格格式化器"""
|
||||||
|
|
||||||
|
def format(self, tools: List[Tool]) -> str:
|
||||||
|
"""格式化工具列表为表格"""
|
||||||
|
if not tools:
|
||||||
|
return "⚠️ 未找到匹配的工具\n"
|
||||||
|
|
||||||
|
# 分离内部工具和外部工具
|
||||||
|
internal = [t for t in tools if isinstance(t, InternalTool)]
|
||||||
|
external = [t for t in tools if isinstance(t, ExternalTool)]
|
||||||
|
|
||||||
|
output = []
|
||||||
|
|
||||||
|
# 内部工具
|
||||||
|
if internal:
|
||||||
|
output.append(self._format_internal_tools(internal))
|
||||||
|
|
||||||
|
# 外部工具
|
||||||
|
if external:
|
||||||
|
if internal:
|
||||||
|
output.append("")
|
||||||
|
output.append(self._format_external_tools(external))
|
||||||
|
|
||||||
|
return "\n".join(output) + "\n"
|
||||||
|
|
||||||
|
def _format_internal_tools(self, tools: List[InternalTool]) -> str:
|
||||||
|
"""格式化内部工具"""
|
||||||
|
lines = [
|
||||||
|
f"📦 找到 {len(tools)} 个内部工具:",
|
||||||
|
"=" * 110,
|
||||||
|
f"{'名称':<25} {'ID':<25} {'语言':<8} {'用途':<15} {'描述':<30}",
|
||||||
|
"-" * 110
|
||||||
|
]
|
||||||
|
|
||||||
|
for tool in tools:
|
||||||
|
purposes = ",".join(tool.metadata.purpose)[:13]
|
||||||
|
desc = tool.description[:28]
|
||||||
|
lines.append(
|
||||||
|
f"{tool.tool_name:<25} {tool.tool_id:<25} {tool.language:<8} {purposes:<15} {desc:<30}"
|
||||||
|
)
|
||||||
|
|
||||||
|
lines.append("=" * 110)
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
def _format_external_tools(self, tools: List[ExternalTool]) -> str:
|
||||||
|
"""格式化外部工具"""
|
||||||
|
lines = [
|
||||||
|
f"🌟 找到 {len(tools)} 个外部工具:",
|
||||||
|
"=" * 100,
|
||||||
|
f"{'名称':<25} {'ID':<20} {'分类':<12} {'安装状态':<10} {'描述':<30}",
|
||||||
|
"-" * 100
|
||||||
|
]
|
||||||
|
|
||||||
|
for tool in tools:
|
||||||
|
status = tool.status
|
||||||
|
desc = tool.description[:30]
|
||||||
|
lines.append(
|
||||||
|
f"{tool.tool_name:<25} {tool.tool_id:<20} {tool.category:<12} {status:<10} {desc:<30}"
|
||||||
|
)
|
||||||
|
|
||||||
|
lines.append("=" * 100)
|
||||||
|
lines.extend([
|
||||||
|
"",
|
||||||
|
"💡 提示: 使用 --external 仅显示外部工具",
|
||||||
|
"💡 提示: 外部工具是系统级的CLI工具,需单独安装"
|
||||||
|
])
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
def format_single(self, tool: Tool) -> str:
|
||||||
|
"""格式化单个工具详情"""
|
||||||
|
if isinstance(tool, InternalTool):
|
||||||
|
return self._format_internal_tool(tool)
|
||||||
|
elif isinstance(tool, ExternalTool):
|
||||||
|
return self._format_external_tool(tool)
|
||||||
|
else:
|
||||||
|
return self._format_generic_tool(tool)
|
||||||
|
|
||||||
|
def _format_internal_tool(self, tool: InternalTool) -> str:
|
||||||
|
"""格式化内部工具详情"""
|
||||||
|
lines = [
|
||||||
|
"",
|
||||||
|
"=" * 70,
|
||||||
|
f"📦 {tool.tool_name}",
|
||||||
|
"=" * 70,
|
||||||
|
f"ID: {tool.tool_id}",
|
||||||
|
f"语言: {tool.language}",
|
||||||
|
f"文件: {tool.file}",
|
||||||
|
f"复杂度: {tool.complexity}",
|
||||||
|
f"用途: {', '.join(tool.metadata.purpose)}",
|
||||||
|
"",
|
||||||
|
"📋 描述:",
|
||||||
|
f" {tool.description}",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
|
||||||
|
if tool.usage:
|
||||||
|
lines.append("🚀 使用方法:")
|
||||||
|
if '命令' in tool.usage:
|
||||||
|
lines.append(f" 命令: {tool.usage['命令']}")
|
||||||
|
if '参数' in tool.usage:
|
||||||
|
lines.append(" 参数:")
|
||||||
|
for param, desc in tool.usage['参数'].items():
|
||||||
|
lines.append(f" - {param}: {desc}")
|
||||||
|
if '示例' in tool.usage:
|
||||||
|
lines.append(" 示例:")
|
||||||
|
for example in tool.usage.get('示例', [])[:3]:
|
||||||
|
lines.append(f" • {example}")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
if tool.metadata.satisfaction > 0:
|
||||||
|
lines.extend([
|
||||||
|
"📊 使用统计:",
|
||||||
|
f" 满意度: {tool.metadata.satisfaction}/1.0",
|
||||||
|
""
|
||||||
|
])
|
||||||
|
|
||||||
|
lines.extend([
|
||||||
|
"📂 文件位置:",
|
||||||
|
f" 元数据: {tool.meta_file}",
|
||||||
|
f"{'=' * 70}",
|
||||||
|
""
|
||||||
|
])
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
def _format_external_tool(self, tool: ExternalTool) -> str:
|
||||||
|
"""格式化外部工具详情"""
|
||||||
|
lines = [
|
||||||
|
"",
|
||||||
|
"=" * 70,
|
||||||
|
f"🌟 {tool.tool_name}",
|
||||||
|
"=" * 70,
|
||||||
|
f"ID: {tool.tool_id}",
|
||||||
|
f"分类: {tool.category}",
|
||||||
|
f"命令: {tool.command}",
|
||||||
|
f"状态: {tool.status}",
|
||||||
|
"",
|
||||||
|
"📋 描述:",
|
||||||
|
f" {tool.description}",
|
||||||
|
"",
|
||||||
|
"💡 使用场景:",
|
||||||
|
]
|
||||||
|
|
||||||
|
for use_case in tool.use_cases:
|
||||||
|
lines.append(f" • {use_case}")
|
||||||
|
|
||||||
|
lines.extend([
|
||||||
|
"",
|
||||||
|
"📥 安装指南:",
|
||||||
|
f" {tool.install_guide}",
|
||||||
|
""
|
||||||
|
])
|
||||||
|
|
||||||
|
if tool.path:
|
||||||
|
lines.extend([
|
||||||
|
"📂 安装路径:",
|
||||||
|
f" {tool.path}",
|
||||||
|
""
|
||||||
|
])
|
||||||
|
|
||||||
|
lines.append(f"{'=' * 70}\n")
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
def _format_generic_tool(self, tool: Tool) -> str:
|
||||||
|
"""格式化通用工具详情"""
|
||||||
|
return f"\n{'=' * 70}\n📦 {tool.tool_name} ({tool.tool_id})\n{'=' * 70}\n 描述: {tool.description}\n{'=' * 70}\n\n"
|
||||||
13
skills/toolkit/discover/models/__init__.py
Normal file
13
skills/toolkit/discover/models/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
Data models for toolkit discovery system
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .tool import Tool, InternalTool, ExternalTool, ToolUsage, ToolMetadata
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'Tool',
|
||||||
|
'InternalTool',
|
||||||
|
'ExternalTool',
|
||||||
|
'ToolUsage',
|
||||||
|
'ToolMetadata'
|
||||||
|
]
|
||||||
107
skills/toolkit/discover/models/tool.py
Normal file
107
skills/toolkit/discover/models/tool.py
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
"""
|
||||||
|
数据模型:工具和元数据定义
|
||||||
|
"""
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Dict, List, Any, Optional
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ToolUsage:
|
||||||
|
"""工具使用信息"""
|
||||||
|
command: str
|
||||||
|
task: str
|
||||||
|
trigger: str
|
||||||
|
expected: str
|
||||||
|
|
||||||
|
execution_status: str = "unknown"
|
||||||
|
output_files: List[str] = field(default_factory=list)
|
||||||
|
key_findings: Dict[str, Any] = field(default_factory=dict)
|
||||||
|
satisfaction: float = 0.0
|
||||||
|
duration: float = 0.0
|
||||||
|
|
||||||
|
followup_actions: List[str] = field(default_factory=list)
|
||||||
|
lessons_learned: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ToolMetadata:
|
||||||
|
"""工具元数据基类"""
|
||||||
|
tool_id: str
|
||||||
|
tool_name: str
|
||||||
|
description: str
|
||||||
|
purpose: List[str] = field(default_factory=list)
|
||||||
|
last_used: Optional[datetime] = None
|
||||||
|
satisfaction: float = 0.0
|
||||||
|
|
||||||
|
related_tools: Dict[str, List[str]] = field(default_factory=dict)
|
||||||
|
maintenance_notes: Dict[str, Any] = field(default_factory=dict)
|
||||||
|
version: str = "1.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Tool:
|
||||||
|
"""工具基类"""
|
||||||
|
metadata: ToolMetadata
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tool_id(self) -> str:
|
||||||
|
return self.metadata.tool_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tool_name(self) -> str:
|
||||||
|
return self.metadata.tool_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self) -> str:
|
||||||
|
return self.metadata.description
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class InternalTool(Tool):
|
||||||
|
"""内部工具(AI-runtime创建的工具)"""
|
||||||
|
meta_file: str
|
||||||
|
tool_file: Optional[str]
|
||||||
|
language: str
|
||||||
|
file: str
|
||||||
|
complexity: str
|
||||||
|
|
||||||
|
usage: Dict[str, Any] = field(default_factory=dict)
|
||||||
|
full_meta: Optional[Dict[str, Any]] = None
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
if not isinstance(self.metadata, ToolMetadata):
|
||||||
|
self.metadata = ToolMetadata(
|
||||||
|
tool_id=self.tool_id,
|
||||||
|
tool_name=self.tool_name,
|
||||||
|
description=self.description,
|
||||||
|
purpose=self.metadata.get("purpose", []) if isinstance(self.metadata, dict) else self.metadata.purpose
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ExternalTool(Tool):
|
||||||
|
"""外部工具(第三方CLI工具)"""
|
||||||
|
command: str
|
||||||
|
category: str
|
||||||
|
use_cases: List[str]
|
||||||
|
install_guide: str
|
||||||
|
|
||||||
|
installed: bool = False
|
||||||
|
path: Optional[str] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self) -> str:
|
||||||
|
"""获取安装状态"""
|
||||||
|
return "✅ 已安装" if self.installed else "❌ 未安装"
|
||||||
|
|
||||||
|
|
||||||
|
class ToolDetectorError(Exception):
|
||||||
|
"""工具检测异常"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToolFormatError(Exception):
|
||||||
|
"""工具格式化异常"""
|
||||||
|
pass
|
||||||
86
skills/toolkit/docs/STRUCTURE-REFACTORING.md
Normal file
86
skills/toolkit/docs/STRUCTURE-REFACTORING.md
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Documentation Restructuring Plan
|
||||||
|
|
||||||
|
## Problem
|
||||||
|
Two documentation files are too large:
|
||||||
|
- `registry.md`: 1,089 lines
|
||||||
|
- `EXTERNAL-TOOLS.md`: 547 lines
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
Split into smaller, focused files using `@path/to/file.md` import feature discovered from deepwiki.
|
||||||
|
|
||||||
|
## New Structure
|
||||||
|
|
||||||
|
### EXTERNAL-TOOLS.md → Split (547 lines)
|
||||||
|
|
||||||
|
**Main index**: `EXTERNAL-TOOLS.md` (with @imports)
|
||||||
|
|
||||||
|
```
|
||||||
|
docs/external-tools/
|
||||||
|
├── 00-index.md # Overview & TOC
|
||||||
|
├── essential/ # 基础必备(7个工具)
|
||||||
|
│ ├── fzf.md # 模糊查找
|
||||||
|
│ ├── eza.md # 文件列表
|
||||||
|
│ ├── zoxide.md # 目录导航
|
||||||
|
│ ├── fd.md # 文件搜索
|
||||||
|
│ ├── bat.md # 文件查看
|
||||||
|
│ ├── ripgrep.md # 代码搜索
|
||||||
|
│ └── starship.md # Shell提示符
|
||||||
|
├── advanced/ # 进阶推荐(3个工具)
|
||||||
|
│ ├── jq.md # JSON处理
|
||||||
|
│ ├── zellij.md # 终端复用
|
||||||
|
│ └── procs.md # 进程查看
|
||||||
|
└── expert/ # 专家级(2个工具)
|
||||||
|
├── just.md # 任务运行器
|
||||||
|
└── hyperfine.md # 性能测试
|
||||||
|
```
|
||||||
|
|
||||||
|
### registry.md → Split (1,089 lines)
|
||||||
|
|
||||||
|
**Main index**: `registry.md` (with @imports)
|
||||||
|
|
||||||
|
```
|
||||||
|
docs/registry/
|
||||||
|
├── 00-overview.md # Philosophy & concepts
|
||||||
|
├── 01-quickstart.md # Quick start guide
|
||||||
|
├── 02-tool-categories.md # Category explanations
|
||||||
|
├── 03-external-integration.md # External tools philosophy
|
||||||
|
├── 04-creating-tools.md # How to create tools
|
||||||
|
├── TOC.md # Table of contents
|
||||||
|
└── internal-tools/ # Individual tool docs
|
||||||
|
├── service-checker.md
|
||||||
|
├── dependency-analyzer.md
|
||||||
|
├── code-stats.md
|
||||||
|
└── api-tester.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## Implementation Strategy
|
||||||
|
|
||||||
|
1. **Phase 1**: Create new `docs/` directory structure
|
||||||
|
2. **Phase 2**: Split EXTERNAL-TOOLS.md (easier, 547 lines)
|
||||||
|
3. **Phase 3**: Split registry.md (larger, 1,089 lines)
|
||||||
|
4. **Phase 4**: Update main index files with @imports
|
||||||
|
5. **Phase 5**: Test and verify
|
||||||
|
|
||||||
|
## Key Benefits
|
||||||
|
|
||||||
|
✅ **Better maintainability** - Each tool/file is self-contained
|
||||||
|
✅ **Faster loading** - AI assistant can load only needed sections
|
||||||
|
✅ **Easier updates** - Modify individual tools without affecting others
|
||||||
|
✅ **Clear organization** - Hierarchical structure by category
|
||||||
|
✅ **Reusable** - Individual tool docs can be referenced elsewhere
|
||||||
|
|
||||||
|
## Import Usage Example
|
||||||
|
|
||||||
|
New `EXTERNAL-TOOLS.md`:
|
||||||
|
```markdown
|
||||||
|
# External Tools
|
||||||
|
|
||||||
|
@docs/external-tools/00-index.md
|
||||||
|
|
||||||
|
## Essential Tools
|
||||||
|
|
||||||
|
@docs/external-tools/essential/fzf.md
|
||||||
|
@docs/external-tools/essential/eza.md
|
||||||
|
@docs/external-tools/essential/zoxide.md
|
||||||
|
# ...etc
|
||||||
|
```
|
||||||
78
skills/toolkit/docs/concepts/toolkit-philosophy.md
Normal file
78
skills/toolkit/docs/concepts/toolkit-philosophy.md
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
---
|
||||||
|
name: toolkit-philosophy
|
||||||
|
description: 工具装备系统的核心理念和设计哲学
|
||||||
|
category: concept
|
||||||
|
version: 1.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 工具装备系统 - 核心理念
|
||||||
|
|
||||||
|
## 类比:外置能力扩展
|
||||||
|
|
||||||
|
像人类记得自己有哪些工具、这些工具能做什么一样,我们维护一个**工具装备系统**。
|
||||||
|
|
||||||
|
工具是我们的**外置能力扩展**:
|
||||||
|
- 用锤子钉钉子(无需重新发明锤子)
|
||||||
|
- 用螺丝刀拧螺丝(无需重新发明螺丝刀)
|
||||||
|
- 选择正确的工具 → 更高效地解决问题 → 避免重复造轮子
|
||||||
|
|
||||||
|
```
|
||||||
|
工具装备系统 = 工具仓库 + 使用记忆 + 分类索引 + 创建流程
|
||||||
|
```
|
||||||
|
|
||||||
|
## 关键原则
|
||||||
|
|
||||||
|
### 1. 整合 > 创造
|
||||||
|
|
||||||
|
**核心理念**:不要重复造轮子
|
||||||
|
|
||||||
|
**原因**:
|
||||||
|
1. **成熟稳定**: 如 `fzf`, `eza`, `fd` 等工具经过数千小时打磨
|
||||||
|
2. **社区支持**: 庞大的用户群和完善的文档
|
||||||
|
3. **专注专业**: 每个工具只做一件事,做到极致
|
||||||
|
4. **认知卸载**: 直接使用,无需维护
|
||||||
|
|
||||||
|
**类比**:就像人类不会自己打造锤子,而是从五金店购买。
|
||||||
|
|
||||||
|
### 2. 工具分类体系
|
||||||
|
|
||||||
|
工具按**语言**分类:
|
||||||
|
- `bash/` - Shell脚本工具
|
||||||
|
- `python/` - Python工具
|
||||||
|
- `node/` - Node.js工具
|
||||||
|
|
||||||
|
工具按**用途**分类:
|
||||||
|
- `CODE` - 代码相关
|
||||||
|
- `DATA` - 数据分析
|
||||||
|
- `TEST` - 测试
|
||||||
|
- `BUILD` - 构建
|
||||||
|
- `MONITOR` - 监控
|
||||||
|
- `DOC` - 文档
|
||||||
|
|
||||||
|
工具按**复杂度**分类:
|
||||||
|
- `level-1` - 1-5行,简单命令
|
||||||
|
- `level-2` - 6-20行,简单脚本
|
||||||
|
- `level-3` - 21-50行,中等复杂度
|
||||||
|
- `level-4` - 50+行或系统级工具
|
||||||
|
|
||||||
|
### 3. 自我完善
|
||||||
|
|
||||||
|
工具装备系统**持续演进**:
|
||||||
|
- 识别重复任务 → 自动化
|
||||||
|
- 识别模式 → 提取通用工具
|
||||||
|
- 使用反馈 → 改进工具
|
||||||
|
- 社区工具 → 整合而非重复
|
||||||
|
|
||||||
|
## 设计目标
|
||||||
|
|
||||||
|
✅ **可发现性** - 快速找到合适的工具
|
||||||
|
✅ **可维护性** - 独立文件,清晰分类
|
||||||
|
✅ **可扩展性** - 轻松添加新工具
|
||||||
|
✅ **一致性** - 统一元数据格式(.meta.yml)
|
||||||
|
✅ **可靠性** - 工具检测和验证
|
||||||
|
|
||||||
|
## 相关文档
|
||||||
|
|
||||||
|
- **快速开始**: `@docs/guides/quickstart.md`
|
||||||
|
- **工具分类**: `@docs/references/tool-categories.md`
|
||||||
|
- **创建工具**: `@docs/guides/creating-tools.md`
|
||||||
406
skills/toolkit/docs/guides/creating-tools.md
Normal file
406
skills/toolkit/docs/guides/creating-tools.md
Normal file
@@ -0,0 +1,406 @@
|
|||||||
|
---
|
||||||
|
name: creating-tools-guide
|
||||||
|
description: 在AI Runtime工具装备系统中创建新工具的完整指南
|
||||||
|
category: guide
|
||||||
|
version: 1.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 如何创造新工具 - 完整指南
|
||||||
|
|
||||||
|
## 创造新工具的流程
|
||||||
|
|
||||||
|
### 步骤1: 识别需求
|
||||||
|
|
||||||
|
在创造新工具之前,先问自己:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
✅ 这个需求是否真实存在?
|
||||||
|
- 是否已经重复执行某个任务超过3次?
|
||||||
|
- 是否花费了超过1小时的手动操作?
|
||||||
|
|
||||||
|
✅ 是否有现有工具可以解决?
|
||||||
|
- 检查: python3 discover-toolkit.py search "关键词"
|
||||||
|
- 检查: 外部工具是否可用?
|
||||||
|
|
||||||
|
✅ 这个工具是否对其他人也有价值?
|
||||||
|
- 不只是解决一次性问题
|
||||||
|
- 可能是可复用的模式
|
||||||
|
|
||||||
|
✅ 复杂度是否适合工具化?
|
||||||
|
- level-1 (1-5行): 简单命令别名
|
||||||
|
- level-2 (6-20行): 简单脚本
|
||||||
|
- level-3 (21-50行): 中等复杂度
|
||||||
|
- level-4 (50+行): 系统级工具
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤2: 选择工具类型
|
||||||
|
|
||||||
|
根据需求选择合适的工具类型:
|
||||||
|
|
||||||
|
#### 选项A: Shell脚本工具 (bash/)
|
||||||
|
|
||||||
|
**适用场景**:
|
||||||
|
- 系统管理任务
|
||||||
|
- 文件操作
|
||||||
|
- 命令编排
|
||||||
|
- 快速原型
|
||||||
|
|
||||||
|
**优点**:
|
||||||
|
- 无需额外依赖
|
||||||
|
- 启动速度快
|
||||||
|
- 与系统紧密集成
|
||||||
|
|
||||||
|
**示例**:
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# bash/monitor/check-disk.sh
|
||||||
|
echo "检查磁盘空间..."
|
||||||
|
df -h | grep -E '^/dev/' | awk '$5 > 80 {print "警告: " $0}'
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 选项B: Python工具 (python/)
|
||||||
|
|
||||||
|
**适用场景**:
|
||||||
|
- 复杂逻辑
|
||||||
|
- 数据处理
|
||||||
|
- 结构化输出
|
||||||
|
- 需要库支持
|
||||||
|
|
||||||
|
**优点**:
|
||||||
|
- 强大的标准库
|
||||||
|
- 跨平台
|
||||||
|
- 易于测试
|
||||||
|
- 类型安全(可选)
|
||||||
|
|
||||||
|
**示例**:
|
||||||
|
```python
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# python/analysis/dependency-analyzer.py
|
||||||
|
"""
|
||||||
|
分析项目依赖关系
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def analyze_dependencies(project_path):
|
||||||
|
"""分析依赖"""
|
||||||
|
# 实现逻辑
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
analyze_dependencies(sys.argv[1])
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 选项C: Node.js工具 (node/)
|
||||||
|
|
||||||
|
**适用场景**:
|
||||||
|
- API测试
|
||||||
|
- Web相关工具
|
||||||
|
- JavaScript生态
|
||||||
|
|
||||||
|
**优点**:
|
||||||
|
- 丰富的npm包
|
||||||
|
- 异步I/O
|
||||||
|
- 适合网络操作
|
||||||
|
|
||||||
|
**示例**:
|
||||||
|
```javascript
|
||||||
|
// node/api/test-api.js
|
||||||
|
const http = require('http');
|
||||||
|
|
||||||
|
function testApi(baseUrl) {
|
||||||
|
http.get(`${baseUrl}/health`, (res) => {
|
||||||
|
console.log('API响应:', res.statusCode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤3: 创建工具和元数据
|
||||||
|
|
||||||
|
#### 示例:创建一个日志分析工具
|
||||||
|
|
||||||
|
**1. 创建工具脚本**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# bash/analysis/analyze-logs-v2.sh
|
||||||
|
#!/bin/bash
|
||||||
|
# 分析日志文件,提取错误和警告
|
||||||
|
|
||||||
|
LOG_FILE="$1"
|
||||||
|
echo "=== 日志分析开始 ==="
|
||||||
|
echo "分析文件: $LOG_FILE"
|
||||||
|
|
||||||
|
# 统计ERROR数量
|
||||||
|
echo "ERROR数量:"
|
||||||
|
grep -c "ERROR" "$LOG_FILE" || echo "0"
|
||||||
|
|
||||||
|
# 统计WARN数量
|
||||||
|
echo "WARN数量:"
|
||||||
|
grep -c "WARN" "$LOG_FILE" || echo "0"
|
||||||
|
|
||||||
|
echo "=== 日志分析完成 ==="
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. 创建元数据文件**
|
||||||
|
|
||||||
|
在相同目录创建 `.meta.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# bash/analysis/analyze-logs-v2.meta.yml
|
||||||
|
tool_id: BASH-ANALYZE-LOGS-V2-001
|
||||||
|
tool_name: "日志分析器V2"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
语言: bash
|
||||||
|
文件: analyze-logs-v2.sh
|
||||||
|
复杂度: level-2
|
||||||
|
创建日期: 2025-11-14
|
||||||
|
作者: YourName
|
||||||
|
|
||||||
|
用途分类:
|
||||||
|
- DATA # 数据分析
|
||||||
|
- MONITOR # 监控诊断
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "分析日志文件,提取错误和警告统计"
|
||||||
|
详细: |
|
||||||
|
支持功能:
|
||||||
|
- 统计ERROR数量
|
||||||
|
- 统计WARN数量
|
||||||
|
- 显示分析摘要
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- "分析应用日志,识别错误模式"
|
||||||
|
- "监控日志文件,统计错误频率"
|
||||||
|
- "生成日志分析报告"
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
命令: "bash analyze-logs-v2.sh <日志文件>"
|
||||||
|
参数:
|
||||||
|
日志文件: "要分析的日志文件路径"
|
||||||
|
示例:
|
||||||
|
- "分析单个日志: bash analyze-logs-v2.sh app.log"
|
||||||
|
|
||||||
|
依赖要求:
|
||||||
|
系统命令:
|
||||||
|
- grep: "用于搜索日志内容"
|
||||||
|
- wc: "用于统计行数"
|
||||||
|
环境变量: 无
|
||||||
|
|
||||||
|
输入输出:
|
||||||
|
输入:
|
||||||
|
- 日志文件(纯文本格式)
|
||||||
|
输出:
|
||||||
|
- stdout: 分析结果
|
||||||
|
- 退出码: 0(成功),非0(错误)
|
||||||
|
|
||||||
|
维护记录:
|
||||||
|
2025-11-14:
|
||||||
|
- 初始创建
|
||||||
|
- 实现ERROR和WARN统计
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤4: 测试工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 赋予执行权限
|
||||||
|
chmod +x bash/analysis/analyze-logs-v2.sh
|
||||||
|
|
||||||
|
# 2. 创建测试日志
|
||||||
|
cat > test.log << 'EOF'
|
||||||
|
INFO: Starting application
|
||||||
|
INFO: Processing request #1
|
||||||
|
WARN: Timeout on request #1
|
||||||
|
ERROR: Failed to connect to database
|
||||||
|
INFO: Retrying...
|
||||||
|
ERROR: Database connection failed
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 3. 运行工具测试
|
||||||
|
bash bash/analysis/analyze-logs-v2.sh test.log
|
||||||
|
|
||||||
|
# 期望输出:
|
||||||
|
# === 日志分析开始 ===
|
||||||
|
# 分析文件: test.log
|
||||||
|
# ERROR数量: 2
|
||||||
|
# WARN数量: 1
|
||||||
|
# === 日志分析完成 ===
|
||||||
|
|
||||||
|
# 4. 删除测试文件
|
||||||
|
rm test.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤5: 注册和验证
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 验证工具被检测到
|
||||||
|
python3 discover-toolkit.py list | grep LOGS-V2
|
||||||
|
|
||||||
|
# 查看工具详细信息
|
||||||
|
python3 discover-toolkit.py show BASH-ANALYZE-LOGS-V2-001
|
||||||
|
|
||||||
|
# 搜索相关工具
|
||||||
|
python3 discover-toolkit.py search log
|
||||||
|
|
||||||
|
# 推荐工具(应该推荐我们的新工具)
|
||||||
|
python3 discover-toolkit.py recommend "分析日志"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤6: 文档和分享
|
||||||
|
|
||||||
|
**1. 创建工具文档**
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# docs/tools/internal/analyze-logs-v2.md
|
||||||
|
---
|
||||||
|
name: analyze-logs-v2
|
||||||
|
description: 分析日志文件,统计错误和警告
|
||||||
|
---
|
||||||
|
|
||||||
|
# 日志分析器V2
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
快速分析日志文件,统计错误和警告数量
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
```bash
|
||||||
|
bash bash/analysis/analyze-logs-v2.sh <日志文件>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
```bash
|
||||||
|
bash bash/analysis/analyze-logs-v2.sh app.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## 输出
|
||||||
|
```
|
||||||
|
=== 日志分析开始 ===
|
||||||
|
分析文件: app.log
|
||||||
|
ERROR数量: 5
|
||||||
|
WARN数量: 12
|
||||||
|
=== 日志分析完成 ===
|
||||||
|
```
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. 更新主文档**
|
||||||
|
|
||||||
|
如果这是重要工具,考虑添加到 `@docs/guides/quickstart.md`
|
||||||
|
|
||||||
|
## 工具质量检查清单
|
||||||
|
|
||||||
|
在发布工具之前,请检查:
|
||||||
|
|
||||||
|
### 功能检查
|
||||||
|
- [ ] 工具完成预期任务
|
||||||
|
- [ ] 处理边界情况(空输入、错误输入)
|
||||||
|
- [ ] 错误处理友好
|
||||||
|
- [ ] 输出清晰可读
|
||||||
|
|
||||||
|
### 代码质量
|
||||||
|
- [ ] 代码有注释
|
||||||
|
- [ ] 遵循语言规范
|
||||||
|
- [ ] 变量命名清晰
|
||||||
|
- [ ] 没有重复代码
|
||||||
|
|
||||||
|
### 元数据检查
|
||||||
|
- [ ] 填写完整的.meta.yml
|
||||||
|
- [ ] ID格式正确(LANG-CATEGORY-NAME-001)
|
||||||
|
- [ ] 包含使用示例
|
||||||
|
- [ ] 标记了依赖项
|
||||||
|
|
||||||
|
### 测试验证
|
||||||
|
- [ ] 本地测试通过
|
||||||
|
- [ ] discover-toolkit能检测到
|
||||||
|
- [ ] show命令显示正确
|
||||||
|
- [ ] 搜索能找到
|
||||||
|
|
||||||
|
### 文档检查
|
||||||
|
- [ ] 创建了工具文档
|
||||||
|
- [ ] 更新相关索引
|
||||||
|
- [ ] 添加了使用示例
|
||||||
|
|
||||||
|
## 常见错误
|
||||||
|
|
||||||
|
### 1. 权限错误
|
||||||
|
```bash
|
||||||
|
chmod +x script.sh # 记得添加执行权限
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 缺少shebang
|
||||||
|
```bash
|
||||||
|
#!/bin/bash # Bash脚本
|
||||||
|
#!/usr/bin/env python3 # Python脚本
|
||||||
|
#!/usr/bin/env node # Node.js脚本
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 路径错误
|
||||||
|
使用相对路径(相对于toolkit根目录):
|
||||||
|
```yaml
|
||||||
|
# 正确
|
||||||
|
文件: python/analysis/my-tool.py
|
||||||
|
|
||||||
|
# 错误(绝对路径)
|
||||||
|
文件: /Users/.../toolkit/python/analysis/my-tool.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. YAML格式错误
|
||||||
|
```bash
|
||||||
|
# 验证YAML语法
|
||||||
|
python3 -c "import yaml; yaml.safe_load(open('meta.yml'))"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 高级:工具模板
|
||||||
|
|
||||||
|
可以使用工具模板快速创建新工具:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 复制模板
|
||||||
|
cp templates/tool-template.sh bash/category/my-tool.sh
|
||||||
|
cp templates/template.meta.yml bash/category/my-tool.meta.yml
|
||||||
|
|
||||||
|
# 修改内容
|
||||||
|
nano bash/category/my-tool.sh
|
||||||
|
nano bash/category/my-tool.meta.yml
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
bash bash/category/my-tool.sh
|
||||||
|
python3 discover-toolkit.py show MY-TOOL-001
|
||||||
|
```
|
||||||
|
|
||||||
|
## 获取帮助
|
||||||
|
|
||||||
|
如果遇到困难:
|
||||||
|
|
||||||
|
1. **查看现有工具**: `python3 discover-toolkit.py list`
|
||||||
|
2. **查看示例元文件**: `cat bash/*/*.meta.yml`
|
||||||
|
3. **查看创建指南**: `@docs/guides/creating-tools.md`
|
||||||
|
4. **检查外部工具**: `@docs/guides/external-integration.md`
|
||||||
|
|
||||||
|
## 贡献工具
|
||||||
|
|
||||||
|
如果想贡献工具到AI Runtime:
|
||||||
|
|
||||||
|
1. **Fork仓库**: 创建自己的分支
|
||||||
|
2. **创建工具**: 按照本指南
|
||||||
|
3. **测试验证**: 确保工具正常工作
|
||||||
|
4. **提交PR**: 包含工具说明和使用场景
|
||||||
|
5. **审查合并**: 等待review和merge
|
||||||
|
|
||||||
|
## 工具版本管理
|
||||||
|
|
||||||
|
为工具添加版本信息:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# 在.meta.yml中添加
|
||||||
|
版本信息:
|
||||||
|
当前版本: "1.0.0"
|
||||||
|
发布日期: "2025-11-14"
|
||||||
|
更新日志:
|
||||||
|
- "1.0.0: 初始发布"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**最后更新**: 2025-11-14
|
||||||
|
**指南版本**: 1.0.0
|
||||||
|
**维护者**: CodeConscious
|
||||||
261
skills/toolkit/docs/guides/external-integration.md
Normal file
261
skills/toolkit/docs/guides/external-integration.md
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
---
|
||||||
|
name: external-integration
|
||||||
|
description: 外部CLI工具整合指南 - 为什么和如何整合第三方工具
|
||||||
|
category: guide
|
||||||
|
version: 1.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 外部工具整合指南
|
||||||
|
|
||||||
|
## 核心理念:不要重复造轮子
|
||||||
|
|
||||||
|
**关键洞见**:我们的工具装备系统**不排斥**使用优秀的第三方CLI工具。事实上,**整合**这些工具比重新创建它们更明智。
|
||||||
|
|
||||||
|
## 为什么整合外部工具?
|
||||||
|
|
||||||
|
### 1. 成熟稳定
|
||||||
|
工具如 `fzf`, `eza`, `fd`, `bat`, `ripgrep` 等经过:
|
||||||
|
- **数千小时**的社区打磨
|
||||||
|
- **复杂场景**的实战测试
|
||||||
|
- **性能优化**到极致
|
||||||
|
- **跨平台**兼容性验证
|
||||||
|
|
||||||
|
### 2. 社区支持
|
||||||
|
- **庞大的用户群**: 数万到数十万用户
|
||||||
|
- **完善的文档**: README、教程、博客文章、视频
|
||||||
|
- **活跃的维护**: 定期更新、bug修复、新功能
|
||||||
|
- **丰富的生态**: 插件、扩展、集成方案
|
||||||
|
|
||||||
|
### 3. 专注专业
|
||||||
|
**Unix哲学**: 每个工具只做一件事,做到极致
|
||||||
|
- **fzf**: 模糊查找,不搞别的
|
||||||
|
- **eza**: 文件列表,专注显示
|
||||||
|
- **bat**: 文件查看,语法高亮
|
||||||
|
- **fd**: 文件搜索,快速简单
|
||||||
|
- **ripgrep**: 代码搜索,极速递归
|
||||||
|
|
||||||
|
### 4. 认知卸载
|
||||||
|
- **直接使用**: 无需重新实现
|
||||||
|
- **无需维护**: 交给社区维护者
|
||||||
|
- **最佳实践**: 吸收社区智慧
|
||||||
|
- **专注核心**: 把精力放在AI Runtime的独特价值上
|
||||||
|
|
||||||
|
**类比**:就像人类不会自己打造锤子,而是从五金店购买。
|
||||||
|
|
||||||
|
## 推荐的外部工具
|
||||||
|
|
||||||
|
### 基础必备(建议全部安装)
|
||||||
|
|
||||||
|
| 工具 | 用途 | 关键优势 | 安装难度 |
|
||||||
|
|-----|-----|---------|--------|
|
||||||
|
| **fzf** | 模糊查找 | 交互式、快速、易集成 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **eza** | 文件列表 | 美观、Git集成、快速 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **zoxide** | 目录跳转 | AI驱动、学习路径 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **fd** | 文件搜索 | 简单、快速、忽略.gitignore | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **bat** | 文件查看 | 语法高亮、Git集成 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **ripgrep** | 代码搜索 | 极速、递归、Git感知 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **jq** | JSON处理 | 命令行处理JSON | ⭐⭐⭐⭐ |
|
||||||
|
|
||||||
|
### 进阶推荐(根据需求选择)
|
||||||
|
|
||||||
|
| 工具 | 用途 | 适用场景 |
|
||||||
|
|-----|-----|---------|
|
||||||
|
| **zellij** | 终端复用 | 替代tmux, 现代体验 |
|
||||||
|
| **starship** | Shell提示符 | 美观, Git/语言版本显示 |
|
||||||
|
| **delta** | Git diff美化 | 查看Git变更体验 |
|
||||||
|
| **xh** | HTTP客户端 | API测试, 替代curl |
|
||||||
|
| **just** | 任务运行器 | 替代make, 简洁语法 |
|
||||||
|
| **hyperfine** | 性能基准测试 | 命令性能对比 |
|
||||||
|
|
||||||
|
## 整合策略
|
||||||
|
|
||||||
|
### 策略1: 直接使用
|
||||||
|
|
||||||
|
在AI Runtime脚本中直接调用外部工具:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在 bash/process-logs.sh 中
|
||||||
|
# 使用 ripgrep 搜索日志
|
||||||
|
echo "搜索错误..."
|
||||||
|
rg "ERROR|CRITICAL" /var/log/app/ --no-ignore-vcs -A 2 -B 2
|
||||||
|
|
||||||
|
# 使用 bat 显示结果
|
||||||
|
bat --paging=never /tmp/analysis-result.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### 策略2: 工具检测
|
||||||
|
|
||||||
|
在运行时检测工具是否可用:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 在 discover-toolkit.py 中
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
def check_tools():
|
||||||
|
"""检测关键外部工具是否安装"""
|
||||||
|
tools = ['fzf', 'eza', 'fd', 'bat', 'rg']
|
||||||
|
missing = []
|
||||||
|
|
||||||
|
for tool in tools:
|
||||||
|
if not shutil.which(tool):
|
||||||
|
missing.append(tool)
|
||||||
|
|
||||||
|
if missing:
|
||||||
|
print(f"❌ 缺少工具: {', '.join(missing)}")
|
||||||
|
print("💡 安装: brew install {' '.join(missing)}")
|
||||||
|
else:
|
||||||
|
print("✅ 所有关键工具已安装")
|
||||||
|
```
|
||||||
|
|
||||||
|
### 策略3: 交互式增强
|
||||||
|
|
||||||
|
使用 fzf 提供交互式体验:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在 runtime-scripts/explore.sh 中
|
||||||
|
# 使用 fzf 选择文件
|
||||||
|
FILE=$(fd .py | fzf --preview 'bat --color=always --line-range :50 {}')
|
||||||
|
echo "处理文件: $FILE"
|
||||||
|
|
||||||
|
# 使用 fzf 选择目录
|
||||||
|
DIR=$(fd --type d | fzf)
|
||||||
|
cd "$DIR"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 策略4: 优雅降级
|
||||||
|
|
||||||
|
工具不存在时的备选方案:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# script-with-fallback.sh
|
||||||
|
|
||||||
|
# 首选使用 eza
|
||||||
|
if command -v eza &> /dev/null; then
|
||||||
|
eza --long --git
|
||||||
|
# 否则使用 ls
|
||||||
|
else
|
||||||
|
ls -lah
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
## 在ai-runtime中的实际应用
|
||||||
|
|
||||||
|
### 示例1: 文件探索
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# runtime-explore.sh
|
||||||
|
|
||||||
|
# 1. 使用 fd 查找所有Python文件
|
||||||
|
FILES=$(fd .py)
|
||||||
|
|
||||||
|
# 2. 使用 fzf 交互式选择
|
||||||
|
FILE=$(echo "$FILES" | fzf \
|
||||||
|
--preview 'bat --color=always --line-range :50 {}' \
|
||||||
|
--preview-window='right:50%:hidden' \
|
||||||
|
--bind='?:toggle-preview')
|
||||||
|
|
||||||
|
# 3. 使用 bat 显示文件内容
|
||||||
|
echo "=== 开始分析: $FILE ==="
|
||||||
|
bat "$FILE" | head -50
|
||||||
|
```
|
||||||
|
|
||||||
|
### 示例2: 日志分析
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# analyze-logs.sh
|
||||||
|
|
||||||
|
# 1. 使用 ripgrep 快速搜索
|
||||||
|
rg "ERROR|WARN" /var/log/app/ \
|
||||||
|
--no-ignore-vcs \
|
||||||
|
-A 2 -B 2 \
|
||||||
|
--line-number \
|
||||||
|
> /tmp/errors.txt
|
||||||
|
|
||||||
|
# 2. 使用 bat 美观显示
|
||||||
|
bat --theme=OneHalfDark /tmp/errors.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
### 示例3: 项目导航
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# smart-navigate.sh
|
||||||
|
|
||||||
|
# 使用 zoxide 跳转到最近访问的项目
|
||||||
|
# 如果 zoxide 可用
|
||||||
|
if command -v zoxide &> /dev/null; then
|
||||||
|
z myproject
|
||||||
|
else
|
||||||
|
# 否则使用 cd
|
||||||
|
cd ~/projects/myproject
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
## 安装检查脚本
|
||||||
|
|
||||||
|
创建检查脚本,在系统初始化时验证关键工具:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# check-tools.sh
|
||||||
|
|
||||||
|
echo "🔍 检查关键外部工具..."
|
||||||
|
echo "================================"
|
||||||
|
|
||||||
|
TOOLS=("fzf" "eza" "zoxide" "fd" "bat" "rg" "jq")
|
||||||
|
|
||||||
|
for tool in "${TOOLS[@]}"; do
|
||||||
|
if command -v "$tool" &> /dev/null; then
|
||||||
|
echo "✅ $tool 已安装 ($(which $tool))"
|
||||||
|
else
|
||||||
|
echo "❌ $tool 未安装"
|
||||||
|
|
||||||
|
case $tool in
|
||||||
|
fzf)
|
||||||
|
echo " 💡 安装: brew install fzf"
|
||||||
|
;;
|
||||||
|
eza)
|
||||||
|
echo " 💡 安装: brew install eza"
|
||||||
|
;;
|
||||||
|
zoxide)
|
||||||
|
echo " 💡 安装: curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh"
|
||||||
|
;;
|
||||||
|
fd)
|
||||||
|
echo " 💡 安装: brew install fd"
|
||||||
|
;;
|
||||||
|
bat)
|
||||||
|
echo " 💡 安装: brew install bat"
|
||||||
|
;;
|
||||||
|
rg)
|
||||||
|
echo " 💡 安装: brew install ripgrep"
|
||||||
|
;;
|
||||||
|
jq)
|
||||||
|
echo " 💡 安装: brew install jq"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "================================"
|
||||||
|
echo "💡 一键安装所有: brew install fzf eza zoxide fd bat ripgrep jq"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
**整合是明智选择**:
|
||||||
|
✅ 节省开发时间
|
||||||
|
✅ 利用社区智慧
|
||||||
|
✅ 专注核心功能
|
||||||
|
✅ 更好的用户体验
|
||||||
|
|
||||||
|
**渐进式策略**:
|
||||||
|
1. **首先**: 检测工具是否存在
|
||||||
|
2. **其次**: 优雅降级(如果工具缺失)
|
||||||
|
3. **再次**: 增强体验(如果工具存在)
|
||||||
|
4. **最终**: 完全依赖(确信工具已安装)
|
||||||
|
|
||||||
|
## 参考资源
|
||||||
|
|
||||||
|
- **外部工具完整参考**: `@docs/references/external-tools.md`
|
||||||
|
- **外部工具详情**: `@docs/tools/external/{tool-name}.md`
|
||||||
|
- **快速开始**: `@docs/guides/quickstart.md`
|
||||||
127
skills/toolkit/docs/guides/quickstart.md
Normal file
127
skills/toolkit/docs/guides/quickstart.md
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
---
|
||||||
|
name: quickstart
|
||||||
|
description: 工具装备系统快速入门指南
|
||||||
|
category: guide
|
||||||
|
version: 1.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 工具装备系统 - 快速开始
|
||||||
|
|
||||||
|
## 发现和使用工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 进入工具装备目录
|
||||||
|
cd .ai-runtime/toolkit
|
||||||
|
|
||||||
|
# 查看所有可用工具
|
||||||
|
python3 discover-toolkit.py list
|
||||||
|
|
||||||
|
# 查看所有可用工具(包含外部工具)
|
||||||
|
python3 discover-toolkit.py list --include-external
|
||||||
|
|
||||||
|
# 仅查看外部工具
|
||||||
|
python3 discover-toolkit.py list --external
|
||||||
|
|
||||||
|
# 查看特定工具详情
|
||||||
|
python3 discover-toolkit.py show SERVICE-CHECK-001
|
||||||
|
|
||||||
|
# 搜索相关工具(模糊匹配)
|
||||||
|
python3 discover-toolkit.py search health
|
||||||
|
|
||||||
|
# 推荐适合任务的工具
|
||||||
|
python3 discover-toolkit.py recommend "检查数据库连接"
|
||||||
|
|
||||||
|
# 直接运行工具
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o report.json
|
||||||
|
|
||||||
|
# 查看工具使用历史(如果有)
|
||||||
|
python3 discover-toolkit.py history
|
||||||
|
```
|
||||||
|
|
||||||
|
## 可用的工具
|
||||||
|
|
||||||
|
### 内部工具(AI-Runtime创建)
|
||||||
|
|
||||||
|
| 工具名称 | ID | 语言 | 用途 | 描述 |
|
||||||
|
|---------|-----|------|-----|------|
|
||||||
|
| **服务健康检查器** | SERVICE-CHECK-001 | bash | MONITOR | 检查HTTP服务、数据库、Redis的健康状态 |
|
||||||
|
| **依赖分析器** | PY-DEPENDENCY-ANALYZER-001 | python | CODE,DATA | 分析Python/JavaScript项目的依赖关系 |
|
||||||
|
| **代码统计器** | PY-CODE-STATS-004 | python | CODE,DATA | 分析代码库统计信息 |
|
||||||
|
| **日志分析器** | BASH-ANALYZE-LOGS-002 | bash | DATA,MONITOR | 分析日志文件 |
|
||||||
|
| **磁盘健康检查器** | BASH-CHECK-DISK-003 | bash | MONITOR | 检查磁盘空间和使用情况 |
|
||||||
|
|
||||||
|
#### 服务健康检查器
|
||||||
|
- **文件**: `bash/system/check-service.sh`
|
||||||
|
- **用途**: 检查HTTP服务、数据库、Redis的健康状态
|
||||||
|
- **使用**: `bash check-service.sh <服务名> <类型> [超时]`
|
||||||
|
- **类型**: http, db/database, redis
|
||||||
|
- **示例**:
|
||||||
|
```bash
|
||||||
|
bash check-service.sh auth-service http
|
||||||
|
bash check-service.sh db-service db
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 依赖分析器
|
||||||
|
- **文件**: `python/analysis/dependency-analyzer.py`
|
||||||
|
- **用途**: 分析Python/JavaScript项目的依赖关系,生成可视化报告
|
||||||
|
- **使用**: `python3 dependency-analyzer.py [项目目录] -o report.json`
|
||||||
|
- **支持**: requirements.txt, package.json
|
||||||
|
- **功能**: 依赖解析、安全风险检测、报告生成
|
||||||
|
- **示例**:
|
||||||
|
```bash
|
||||||
|
python3 dependency-analyzer.py
|
||||||
|
python3 dependency-analyzer.py /path/to/project
|
||||||
|
python3 dependency-analyzer.py . -o report.json
|
||||||
|
```
|
||||||
|
|
||||||
|
#### API测试工具
|
||||||
|
- **文件**: `node/api/test-api.js`
|
||||||
|
- **用途**: 测试RESTful API端点
|
||||||
|
- **使用**: `node test-api.js [base-url]`
|
||||||
|
- **示例**:
|
||||||
|
```bash
|
||||||
|
node test-api.js http://localhost:3000
|
||||||
|
```
|
||||||
|
|
||||||
|
## 工具使用流程
|
||||||
|
|
||||||
|
### 场景1:探索新项目
|
||||||
|
```bash
|
||||||
|
# 1. 查看项目结构
|
||||||
|
python3 discover-toolkit.py list
|
||||||
|
|
||||||
|
# 2. 分析项目依赖
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o deps.json
|
||||||
|
|
||||||
|
# 3. 检查服务健康(如果适用)
|
||||||
|
bash bash/system/check-service.sh myapp http
|
||||||
|
```
|
||||||
|
|
||||||
|
### 场景2:排查问题
|
||||||
|
```bash
|
||||||
|
# 1. 搜索相关工具
|
||||||
|
python3 discover-toolkit.py search log
|
||||||
|
|
||||||
|
# 2. 分析日志
|
||||||
|
bash bash/analysis/analyze-logs.sh /path/to/logs --level ERROR
|
||||||
|
|
||||||
|
# 3. 检查磁盘空间
|
||||||
|
bash bash/system/check-disk.sh /
|
||||||
|
```
|
||||||
|
|
||||||
|
### 场景3:常规监控
|
||||||
|
```bash
|
||||||
|
# 1. 检查所有服务
|
||||||
|
for service in auth db cache; do
|
||||||
|
bash bash/system/check-service.sh $service http
|
||||||
|
done
|
||||||
|
|
||||||
|
# 2. 生成健康报告
|
||||||
|
python3 discover-toolkit.py recommend "health check"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 下一步学习
|
||||||
|
|
||||||
|
- **查看完整参考**: `@docs/references/internal-tools.md`
|
||||||
|
- **了解外部工具**: `@docs/external-integration.md`
|
||||||
|
- **学习如何创建工具**: `@docs/guides/creating-tools.md`
|
||||||
194
skills/toolkit/docs/references/external-tools.md
Normal file
194
skills/toolkit/docs/references/external-tools.md
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
---
|
||||||
|
name: external-tools-reference
|
||||||
|
description: 完整的外部CLI工具参考指南 - 包含所有工具的安装、配置和使用示例
|
||||||
|
---
|
||||||
|
|
||||||
|
# 外部工具完整参考指南
|
||||||
|
|
||||||
|
**核心理念**: **整合 > 创造**
|
||||||
|
|
||||||
|
外部CLI工具是**成熟的、社区验证的**工具,我们**不应重新实现**,而应直接集成到ai-runtime工具装备系统中。
|
||||||
|
|
||||||
|
## 工具分类
|
||||||
|
|
||||||
|
### 基础必备(所有用户都应安装)
|
||||||
|
|
||||||
|
这些工具提供**日常开发**的核心功能,建议**优先安装**。
|
||||||
|
|
||||||
|
| 工具 | ID | 用途 | 安装难度 | 推荐度 |
|
||||||
|
|-----|-----|-----|---------|-------|
|
||||||
|
| [fzf](../tools/external/fzf.md) | EXT-FZF-001 | 模糊查找和交互 | ⭐ 简单 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| [eza](../tools/external/eza.md) | EXT-EZA-001 | 文件列表(替代ls) | ⭐ 简单 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| [zoxide](../tools/external/zoxide.md) | EXT-ZOXIDE-001 | 智能目录跳转 | ⭐ 简单 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| [fd](../tools/external/fd.md) | EXT-FD-001 | 文件搜索(替代find) | ⭐ 简单 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| [bat](../tools/external/bat.md) | EXT-BAT-001 | 文件查看(替代cat) | ⭐ 简单 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| [ripgrep](../tools/external/ripgrep.md) | EXT-RG-001 | 代码搜索(替代grep) | ⭐ 简单 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| starship | EXT-STEAMSHIP-001 | Shell提示符 | ⭐ 简单 | ⭐⭐⭐⭐ |
|
||||||
|
|
||||||
|
### 进阶推荐(提升效率)
|
||||||
|
|
||||||
|
| 工具 | ID | 用途 | 推荐度 |
|
||||||
|
|-----|-----|-----|-------|
|
||||||
|
| [jq](../tools/external/jq.md) | EXT-JQ-001 | JSON查询和处理 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| zellij | EXT-ZELLIJ-001 | 终端复用(替代tmux) | ⭐⭐⭐⭐ |
|
||||||
|
| procs | EXT-PROCS-001 | 进程查看(替代ps) | ⭐⭐⭐⭐ |
|
||||||
|
|
||||||
|
### 专家级(特定场景)
|
||||||
|
|
||||||
|
| 工具 | ID | 用途 | 推荐度 |
|
||||||
|
|-----|-----|-----|-------|
|
||||||
|
| just | EXT-JUST-001 | 任务运行器(替代make) | ⭐⭐⭐⭐ |
|
||||||
|
| hyperfine | EXT-HYPERFINE-001 | 性能基准测试 | ⭐⭐⭐⭐ |
|
||||||
|
| delta | EXT-DELTA-001 | Git diff美化 | ⭐⭐⭐⭐ |
|
||||||
|
| xh | EXT-XH-001 | HTTP客户端(替代curl) | ⭐⭐⭐⭐ |
|
||||||
|
|
||||||
|
## 一键安装脚本
|
||||||
|
|
||||||
|
### macOS (使用Homebrew)
|
||||||
|
```bash
|
||||||
|
brew install fzf eza zoxide fd bat ripgrep jq just hyperfine git-delta xh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
# 基础工具
|
||||||
|
sudo apt-get install fzf ripgrep jq
|
||||||
|
|
||||||
|
# eza(需要添加源)
|
||||||
|
sudo apt-get install -y gpg wget
|
||||||
|
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/gierens.gpg
|
||||||
|
echo "deb http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y eza
|
||||||
|
|
||||||
|
# zoxide
|
||||||
|
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
|
||||||
|
|
||||||
|
# fd
|
||||||
|
sudo apt-get install fd-find
|
||||||
|
ln -s $(which fdfind) ~/.local/bin/fd
|
||||||
|
|
||||||
|
# bat
|
||||||
|
sudo apt-get install bat
|
||||||
|
|
||||||
|
# just
|
||||||
|
cargo install just
|
||||||
|
|
||||||
|
# hyperfine
|
||||||
|
cargo install hyperfine
|
||||||
|
```
|
||||||
|
|
||||||
|
## 个人工具箱建议
|
||||||
|
|
||||||
|
### 最小工具箱(4个)⭐
|
||||||
|
适合新手,提供基础文件和导航功能:
|
||||||
|
```bash
|
||||||
|
fzf + eza + zoxide + fd
|
||||||
|
```
|
||||||
|
|
||||||
|
### 完整工具箱(10个)⭐⭐
|
||||||
|
适合日常开发,覆盖90%场景:
|
||||||
|
```bash
|
||||||
|
fzf + eza + zoxide + fd + bat + ripgrep + starship + jq + xh + delta
|
||||||
|
```
|
||||||
|
|
||||||
|
### 终极工具箱(15+个)⭐⭐⭐
|
||||||
|
适合高级用户和工具链爱好者:
|
||||||
|
```bash
|
||||||
|
所有上面工具 + zellij + just + hyperfine + procs + ...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 整合到ai-runtime
|
||||||
|
|
||||||
|
### 1. 在discover-toolkit.py中添加检测
|
||||||
|
|
||||||
|
扩展discover-toolkit.py,使其能够检测系统已安装的CLI工具:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 在discover-toolkit.py中添加
|
||||||
|
EXTERNAL_TOOLS = {
|
||||||
|
'fzf': {'category': 'search', 'priority': 'essential'},
|
||||||
|
'eza': {'category': 'file-listing', 'priority': 'essential'},
|
||||||
|
'zoxide': {'category': 'navigation', 'priority': 'essential'},
|
||||||
|
# ...
|
||||||
|
}
|
||||||
|
|
||||||
|
def detect_external_tools():
|
||||||
|
"""检测已安装的外部工具"""
|
||||||
|
installed = []
|
||||||
|
for tool, meta in EXTERNAL_TOOLS.items():
|
||||||
|
if shutil.which(tool):
|
||||||
|
installed.append({
|
||||||
|
'name': tool,
|
||||||
|
'category': meta['category'],
|
||||||
|
'priority': meta['priority'],
|
||||||
|
'installed': True
|
||||||
|
})
|
||||||
|
return installed
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 在脚本中使用
|
||||||
|
|
||||||
|
示例:在runtime-explore.sh中
|
||||||
|
```bash
|
||||||
|
# 使用fzf选择文件
|
||||||
|
FILE=$(fd .py | fzf --preview 'bat -n --color=always {}')
|
||||||
|
read_file_content "$FILE"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 配置检查
|
||||||
|
|
||||||
|
在系统初始化时检查关键工具是否安装:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# check-tools.sh
|
||||||
|
for tool in fzf eza zoxide fd bat rg jq; do
|
||||||
|
if ! command -v $tool &> /dev/null; then
|
||||||
|
echo "❌ $tool 未安装 - 运行: brew install $tool"
|
||||||
|
else
|
||||||
|
echo "✅ $tool 已安装 ($(which $tool))"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
## 维护策略
|
||||||
|
|
||||||
|
### 定期检查
|
||||||
|
建议**每月**检查一次:
|
||||||
|
- 工具是否有新版本发布
|
||||||
|
- 安全漏洞通告
|
||||||
|
- 社区推荐变化
|
||||||
|
|
||||||
|
### 更新策略
|
||||||
|
|
||||||
|
- **基础工具**(fzf, eza, zoxide, fd): 建议**始终使用最新版**
|
||||||
|
- **进阶工具**(jq, bat, ripgrep): 根据**需求更新**
|
||||||
|
- **专家工具**(zellij, just): 有**新功能**时再更新
|
||||||
|
|
||||||
|
### 废弃管理
|
||||||
|
|
||||||
|
- 记录工具替代关系(如ripgrep → grep)
|
||||||
|
- 在元数据中标记"replaced_by"
|
||||||
|
- 保持向后兼容
|
||||||
|
|
||||||
|
## 参考资源
|
||||||
|
|
||||||
|
- [fzf文档](https://github.com/junegunn/fzf)
|
||||||
|
- [eza文档](https://github.com/eza-community/eza)
|
||||||
|
- [zoxide文档](https://github.com/ajeetdsouza/zoxide)
|
||||||
|
- [bat文档](https://github.com/sharkdp/bat)
|
||||||
|
- [ripgrep文档](https://github.com/BurntSushi/ripgrep)
|
||||||
|
- [jq文档](https://github.com/jqlang/jq)
|
||||||
|
|
||||||
|
## 相关文档
|
||||||
|
|
||||||
|
- 查看工具详情: `@docs/tools/external/fzf.md`
|
||||||
|
- 查看创建工具指南: `@docs/guides/creating-tools.md`
|
||||||
|
- 查看工具分类说明: `@docs/references/tool-categories.md`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**最后更新**: 2025-11-14
|
||||||
|
**下次审查**: 2025-12-14
|
||||||
|
**维护者**: CodeConscious
|
||||||
|
**状态**: Active
|
||||||
298
skills/toolkit/docs/references/internal-tools.md
Normal file
298
skills/toolkit/docs/references/internal-tools.md
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
---
|
||||||
|
name: internal-tools-reference
|
||||||
|
description: AI Runtime内部工具完整参考 - 包含所有内部创建的工具详细信息
|
||||||
|
category: reference
|
||||||
|
version: 1.0.0
|
||||||
|
---
|
||||||
|
|
||||||
|
# 内部工具完整参考
|
||||||
|
|
||||||
|
**最后更新**: 2025-11-14
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 工具概览
|
||||||
|
|
||||||
|
AI Runtime工具装备系统包含以下**内部创建的工具**(按语言分类):
|
||||||
|
|
||||||
|
### Python工具 (python/)
|
||||||
|
|
||||||
|
| 工具名称 | ID | 用途 | 复杂度 | 文件位置 |
|
||||||
|
|---------|-----|-----|--------|----------|
|
||||||
|
| **依赖关系分析器** | PY-DEPENDENCY-ANALYZER-001 | CODE,DATA | level-3 | python/analysis/dependency-analyzer.py |
|
||||||
|
| **代码统计器** | PY-CODE-STATS-004 | CODE,DATA | level-2 | python/analysis/code-stats.py |
|
||||||
|
| **图形生成器** | PY-GRAPH-GENERATOR-002 | DATA,VISUAL | level-3 | python/graph/generate-graph.py |
|
||||||
|
| **报告生成器** | PY-REPORT-GENERATOR-005 | DOC,REPORT | level-3 | python/report/generate-report.py |
|
||||||
|
|
||||||
|
#### PY-DEPENDENCY-ANALYZER-001 依赖关系分析器
|
||||||
|
|
||||||
|
**元文件**: `python/analysis/dependency-analyzer.meta.yml`
|
||||||
|
|
||||||
|
**用途**: 分析Python/JavaScript项目的依赖关系,生成可视化报告
|
||||||
|
|
||||||
|
**功能特性**:
|
||||||
|
- 解析Python requirements.txt
|
||||||
|
- 解析JavaScript package.json
|
||||||
|
- 识别安全风险
|
||||||
|
- 生成Markdown报告
|
||||||
|
- 导出JSON格式
|
||||||
|
|
||||||
|
**使用方法**:
|
||||||
|
```bash
|
||||||
|
# 分析当前目录
|
||||||
|
python3 python/analysis/dependency-analyzer.py
|
||||||
|
|
||||||
|
# 分析指定项目
|
||||||
|
python3 python/analysis/dependency-analyzer.py /path/to/project
|
||||||
|
|
||||||
|
# 保存JSON报告
|
||||||
|
python3 python/analysis/dependency-analyzer.py . -o report.json
|
||||||
|
|
||||||
|
# 详细输出
|
||||||
|
python3 python/analysis/dependency-analyzer.py -v
|
||||||
|
```
|
||||||
|
|
||||||
|
**依赖要求**:
|
||||||
|
- Python >= 3.8
|
||||||
|
- 无第三方依赖(仅标准库)
|
||||||
|
|
||||||
|
**输入输出**:
|
||||||
|
- 输入: requirements.txt, package.json
|
||||||
|
- 输出: Markdown报告到stdout, JSON到文件(如果指定-o)
|
||||||
|
|
||||||
|
**上次使用**:
|
||||||
|
- 时间: 2025-11-14 10:30:00
|
||||||
|
- 用途: 分析ai-runtime项目依赖
|
||||||
|
- 满意度: 0.92
|
||||||
|
|
||||||
|
#### PY-CODE-STATS-004 代码统计器
|
||||||
|
|
||||||
|
**元文件**: `python/analysis/code-stats.meta.yml`
|
||||||
|
|
||||||
|
**用途**: 分析代码库统计信息,包括行数、函数、类、注释率和代码健康指标
|
||||||
|
|
||||||
|
**功能特性**:
|
||||||
|
- 统计代码行数(LOC)
|
||||||
|
- 统计函数和类数量
|
||||||
|
- 计算注释率
|
||||||
|
- 识别代码质量问题(长函数、复杂文件)
|
||||||
|
|
||||||
|
**使用方法**:
|
||||||
|
```bash
|
||||||
|
# 统计当前目录
|
||||||
|
python3 python/analysis/code-stats.py
|
||||||
|
|
||||||
|
# 统计指定目录
|
||||||
|
python3 python/analysis/code-stats.py src/
|
||||||
|
|
||||||
|
# 详细输出
|
||||||
|
python3 python/analysis/code-stats.py -v
|
||||||
|
```
|
||||||
|
|
||||||
|
**上次使用**:
|
||||||
|
- 时间: 2025-11-14 11:15:00
|
||||||
|
- 用途: 统计项目代码规模
|
||||||
|
- 满意度: 0.88
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Bash工具 (bash/)
|
||||||
|
|
||||||
|
| 工具名称 | ID | 用途 | 复杂度 | 文件位置 |
|
||||||
|
|---------|-----|-----|--------|----------|
|
||||||
|
| **服务健康检查器** | SERVICE-CHECK-001 | MONITOR | level-1 | bash/system/check-service.sh |
|
||||||
|
| **日志分析器** | BASH-ANALYZE-LOGS-002 | DATA,MONITOR | level-2 | bash/analysis/analyze-logs.sh |
|
||||||
|
| **磁盘健康检查器** | BASH-CHECK-DISK-003 | MONITOR | level-2 | bash/system/check-disk.sh |
|
||||||
|
|
||||||
|
#### SERVICE-CHECK-001 服务健康检查器
|
||||||
|
|
||||||
|
**元文件**: `bash/system/check-service.meta.yml`
|
||||||
|
|
||||||
|
**用途**: 检查HTTP服务、数据库、Redis的健康状态
|
||||||
|
|
||||||
|
**功能特性**:
|
||||||
|
- HTTP服务健康检查(/health端点)
|
||||||
|
- PostgreSQL数据库连接检查
|
||||||
|
- Redis连接和ping测试
|
||||||
|
- 可配置超时
|
||||||
|
|
||||||
|
**使用方法**:
|
||||||
|
```bash
|
||||||
|
# 检查HTTP服务
|
||||||
|
bash bash/system/check-service.sh auth-service http
|
||||||
|
|
||||||
|
# 检查数据库
|
||||||
|
bash bash/system/check-service.sh db-service db
|
||||||
|
|
||||||
|
# 检查Redis
|
||||||
|
bash bash/system/check-service.sh cache redis
|
||||||
|
|
||||||
|
# 自定义超时(10秒)
|
||||||
|
bash bash/system/check-service.sh myapp http 10
|
||||||
|
```
|
||||||
|
|
||||||
|
**依赖要求**:
|
||||||
|
- curl(HTTP检查)
|
||||||
|
- pg_isready(PostgreSQL检查)
|
||||||
|
- redis-cli(Redis检查)
|
||||||
|
|
||||||
|
**环境变量**:
|
||||||
|
- DB_HOST (默认: localhost)
|
||||||
|
- DB_PORT (默认: 5432)
|
||||||
|
- DB_NAME
|
||||||
|
- DB_USER
|
||||||
|
- REDIS_HOST (默认: localhost)
|
||||||
|
- REDIS_PORT (默认: 6379)
|
||||||
|
|
||||||
|
**上次使用**:
|
||||||
|
- 时间: 2025-11-14 16:45:00
|
||||||
|
- 用途: 验证auth-service修复后状态
|
||||||
|
- 满意度: 0.9
|
||||||
|
|
||||||
|
#### BASH-ANALYZE-LOGS-002 日志分析器
|
||||||
|
|
||||||
|
**元文件**: `bash/analysis/analyze-logs.meta.yml`
|
||||||
|
|
||||||
|
**用途**: 分析日志文件,按级别过滤、时间范围筛选、模式匹配和错误统计
|
||||||
|
|
||||||
|
**功能特性**:
|
||||||
|
- 按日志级别过滤(ERROR, WARN, INFO, DEBUG)
|
||||||
|
- 时间范围筛选
|
||||||
|
- 模式匹配
|
||||||
|
- 错误统计
|
||||||
|
- 生成摘要报告
|
||||||
|
|
||||||
|
**使用方法**:
|
||||||
|
```bash
|
||||||
|
# 分析日志并统计ERROR
|
||||||
|
bash bash/analysis/analyze-logs.sh /var/log/app.log --level ERROR
|
||||||
|
|
||||||
|
# 分析最近1小时的日志
|
||||||
|
bash bash/analysis/analyze-logs.sh /var/log/app.log --since "1 hour ago"
|
||||||
|
|
||||||
|
# 搜索特定模式
|
||||||
|
bash bash/analysis/analyze-logs.sh /var/log/app.log --pattern "connection failed"
|
||||||
|
```
|
||||||
|
|
||||||
|
**上次使用**:
|
||||||
|
- 时间: 2025-11-14 14:20:00
|
||||||
|
- 用途: 分析生产环境错误日志
|
||||||
|
- 满意度: 0.85
|
||||||
|
|
||||||
|
#### BASH-CHECK-DISK-003 磁盘健康检查器
|
||||||
|
|
||||||
|
**元文件**: `bash/system/check-disk.meta.yml`
|
||||||
|
|
||||||
|
**用途**: 检查磁盘空间、inode使用和健康状态,提供详细的分析和建议
|
||||||
|
|
||||||
|
**功能特性**:
|
||||||
|
- 磁盘空间使用检查(总容量、已使用、可用)
|
||||||
|
- Inode使用检查
|
||||||
|
- 使用阈值警报(可配置,默认80%)
|
||||||
|
- 文件系统类型检测
|
||||||
|
- 挂载点和权限检查
|
||||||
|
- 性能指标分析
|
||||||
|
- 智能建议生成
|
||||||
|
|
||||||
|
**使用方法**:
|
||||||
|
```bash
|
||||||
|
# 检查根目录(阈值80%)
|
||||||
|
bash bash/system/check-disk.sh /
|
||||||
|
|
||||||
|
# 检查日志目录自定义阈值(90%)
|
||||||
|
bash bash/system/check-disk.sh /var/log 90
|
||||||
|
|
||||||
|
# 检查所有挂载点
|
||||||
|
bash bash/system/check-disk.sh --all
|
||||||
|
```
|
||||||
|
|
||||||
|
**上次使用**:
|
||||||
|
- 时间: 2025-11-14 13:30:00
|
||||||
|
- 用途: 预防性检查服务器磁盘空间
|
||||||
|
- 满意度: 0.87
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Node.js工具 (node/)
|
||||||
|
|
||||||
|
| 工具名称 | ID | 用途 | 复杂度 | 文件位置 |
|
||||||
|
|---------|-----|-----|--------|----------|
|
||||||
|
| **API测试工具** | NODE-API-TESTER-001 | TEST,API | level-2 | node/api/test-api.js |
|
||||||
|
|
||||||
|
#### NODE-API-TESTER-001 API测试工具
|
||||||
|
|
||||||
|
**元文件**: `node/api/test-api.meta.yml`
|
||||||
|
|
||||||
|
**用途**: 测试RESTful API端点
|
||||||
|
|
||||||
|
**功能特性**:
|
||||||
|
- HTTP GET/POST/PUT/DELETE请求
|
||||||
|
- JSON请求体支持
|
||||||
|
- 响应验证
|
||||||
|
- 批量测试
|
||||||
|
|
||||||
|
**使用方法**:
|
||||||
|
```bash
|
||||||
|
# 测试API健康检查
|
||||||
|
node node/api/test-api.js http://localhost:3000
|
||||||
|
|
||||||
|
# 测试指定端点
|
||||||
|
node node/api/test-api.js http://localhost:3000/api/users
|
||||||
|
|
||||||
|
# POST测试(需要修改脚本)
|
||||||
|
node node/api/test-api.js post http://localhost:3000/api/users '{"name":"test"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**依赖要求**:
|
||||||
|
- Node.js 14+
|
||||||
|
- npm包: axios, chalk, commander(根据实际实现)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 工具分类说明
|
||||||
|
|
||||||
|
### 按语言分类
|
||||||
|
|
||||||
|
| 语言 | 工具数量 | 主要用途 |
|
||||||
|
|-----|---------|---------|
|
||||||
|
| **python** | 4 | 代码分析、数据处理、报告生成 |
|
||||||
|
| **bash** | 3 | 系统监控、日志分析、服务检查 |
|
||||||
|
| **node** | 1 | API测试、网络操作 |
|
||||||
|
|
||||||
|
### 按复杂度分类
|
||||||
|
|
||||||
|
| 复杂度 | 数量 | 说明 |
|
||||||
|
|--------|-----|------|
|
||||||
|
| **level-1** | 1-5行 | 简单命令别名 |
|
||||||
|
| **level-2** | 6-20行 | 简单脚本(4个工具) |
|
||||||
|
| **level-3** | 21-50行 | 中等复杂度(3个工具) |
|
||||||
|
| **level-4** | 50+行 | 系统级工具(1个工具) |
|
||||||
|
|
||||||
|
### 按用途分类
|
||||||
|
|
||||||
|
| 用途 | 工具数量 | 代表工具 |
|
||||||
|
|-----|---------|---------|
|
||||||
|
| **CODE** | 3 | 依赖分析器、代码统计器 |
|
||||||
|
| **DATA** | 3 | 依赖分析器、日志分析器 |
|
||||||
|
| **MONITOR** | 3 | 服务检查、磁盘检查、日志分析 |
|
||||||
|
| **TEST** | 1 | API测试工具 |
|
||||||
|
| **API** | 1 | API测试工具 |
|
||||||
|
| **VISUAL** | 1 | 图形生成器 |
|
||||||
|
| **REPORT** | 1 | 报告生成器 |
|
||||||
|
| **DOC** | 2 | 报告生成器 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 维护信息
|
||||||
|
|
||||||
|
**最后审查**: 2025-11-14
|
||||||
|
**下次审查**: 2025-12-14
|
||||||
|
**维护者**: CodeConscious
|
||||||
|
**状态**: Active
|
||||||
|
|
||||||
|
## 相关文档
|
||||||
|
|
||||||
|
- **快速开始指南**: `@docs/guides/quickstart.md`
|
||||||
|
- **创建工具指南**: `@docs/guides/creating-tools.md`
|
||||||
|
- **外部工具整合**: `@docs/guides/external-integration.md`
|
||||||
|
- **工具分类说明**: `@docs/references/tool-categories.md`
|
||||||
64
skills/toolkit/docs/tools/external/bat.md
vendored
Normal file
64
skills/toolkit/docs/tools/external/bat.md
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
---
|
||||||
|
name: bat
|
||||||
|
description: 带语法高亮的cat替代品
|
||||||
|
category: essential
|
||||||
|
tool_id: EXT-BAT-001
|
||||||
|
---
|
||||||
|
|
||||||
|
# bat (cat with syntax) ⭐⭐⭐⭐⭐
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
语法高亮的文件查看
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew install bat
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
sudo apt-get install bat
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置 (添加到 ~/.bashrc)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
alias cat='bat -p'
|
||||||
|
alias catn='bat'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看文件(有语法高亮)
|
||||||
|
bat app.py
|
||||||
|
|
||||||
|
# 分页查看(保留高亮)
|
||||||
|
bat -p app.py | less -R
|
||||||
|
|
||||||
|
# 查看Git修改
|
||||||
|
bat -d app.py
|
||||||
|
|
||||||
|
# 查看行号
|
||||||
|
bat -n app.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常用选项
|
||||||
|
|
||||||
|
- `-p` -- 纯文本模式(无分页)
|
||||||
|
- `-n` -- 显示行号
|
||||||
|
- `-d` -- 显示Git diff
|
||||||
|
- `-l` -- 指定语言
|
||||||
|
- `--theme` -- 选择主题
|
||||||
|
|
||||||
|
## 与其他工具集成
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 与fzf集成
|
||||||
|
fd .py | fzf --preview 'bat --color=always {}'
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
bat /var/log/system.log
|
||||||
|
```
|
||||||
60
skills/toolkit/docs/tools/external/eza.md
vendored
Normal file
60
skills/toolkit/docs/tools/external/eza.md
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
name: eza
|
||||||
|
description: 现代化的ls替代品,带彩色输出和图标
|
||||||
|
category: essential
|
||||||
|
tool_id: EXT-EZA-001
|
||||||
|
---
|
||||||
|
|
||||||
|
# eza (Modern ls) ⭐⭐⭐⭐⭐
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
现代化文件列表,替代传统ls命令
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew install eza
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
sudo apt-get install -y gpg wget
|
||||||
|
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/gierens.gpg
|
||||||
|
echo "deb http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y eza
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置 (添加到 ~/.bashrc)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
alias ll='eza -lah'
|
||||||
|
alias ls='eza'
|
||||||
|
alias tree='eza --tree --level=2'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 详细列表
|
||||||
|
ll
|
||||||
|
|
||||||
|
# Git状态
|
||||||
|
ll --git
|
||||||
|
|
||||||
|
# 树形结构
|
||||||
|
tree
|
||||||
|
|
||||||
|
# 显示图标
|
||||||
|
eza --icons
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常用选项
|
||||||
|
|
||||||
|
- `-l` -- 长格式
|
||||||
|
- `-a` -- 显示隐藏文件
|
||||||
|
- `-h` -- 人性化大小
|
||||||
|
- `-g` -- 显示Git状态
|
||||||
|
- `--tree` -- 树形视图
|
||||||
|
- `--icons` -- 显示文件图标
|
||||||
81
skills/toolkit/docs/tools/external/fzf.md
vendored
Normal file
81
skills/toolkit/docs/tools/external/fzf.md
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
---
|
||||||
|
name: fzf
|
||||||
|
description: 命令行模糊查找工具 - 用于交互式搜索和选择
|
||||||
|
category: essential
|
||||||
|
tool_id: EXT-FZF-001
|
||||||
|
---
|
||||||
|
|
||||||
|
# fzf (Fuzzy Finder) ⭐⭐⭐⭐⭐
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
命令行模糊查找,革命性交互体验
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew install fzf
|
||||||
|
$(brew --prefix)/opt/fzf/install # 安装键盘快捷键
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
sudo apt-get install fzf
|
||||||
|
```
|
||||||
|
|
||||||
|
## 基础使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 文件名查找
|
||||||
|
find . -type f | fzf
|
||||||
|
|
||||||
|
# 历史命令
|
||||||
|
history | fzf
|
||||||
|
|
||||||
|
# Git分支
|
||||||
|
git branch | fzf
|
||||||
|
|
||||||
|
# 进程kill
|
||||||
|
ps aux | fzf | awk '{print $2}' | xargs kill
|
||||||
|
```
|
||||||
|
|
||||||
|
## 进阶配置 (添加到 ~/.bashrc)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用Ctrl-R搜索历史
|
||||||
|
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:wrap"
|
||||||
|
|
||||||
|
# 使用Ctrl-T搜索文件
|
||||||
|
export FZF_CTRL_T_COMMAND="fd --type f --hidden --follow --exclude .git"
|
||||||
|
export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always {}'"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 在ai-runtime中的建议
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 集成到discover-toolkit.py
|
||||||
|
# 当选择工具时,使用fzf进行交互式选择
|
||||||
|
python3 discover-toolkit.py list | fzf --height 40%
|
||||||
|
```
|
||||||
|
|
||||||
|
## 为什么我们不应重新实现
|
||||||
|
|
||||||
|
- 7000+ stars on GitHub,社区验证
|
||||||
|
- 性能优化到极致
|
||||||
|
- 支持多种Shell和OS
|
||||||
|
- 生态丰富(vim插件、tmux集成等)
|
||||||
|
|
||||||
|
**类比**:就像人类不会自己打造锤子,而是从五金店购买。
|
||||||
|
|
||||||
|
## 快速验证
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 检查是否安装
|
||||||
|
which fzf
|
||||||
|
|
||||||
|
# 验证版本
|
||||||
|
fzf --version
|
||||||
|
|
||||||
|
# 测试基本功能
|
||||||
|
ls | fzf
|
||||||
|
```
|
||||||
94
skills/toolkit/docs/tools/external/jq.md
vendored
Normal file
94
skills/toolkit/docs/tools/external/jq.md
vendored
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
---
|
||||||
|
name: jq
|
||||||
|
description: JSON数据的命令行处理器 - 查询、过滤和转换JSON
|
||||||
|
category: advanced
|
||||||
|
tool_id: EXT-JQ-001
|
||||||
|
---
|
||||||
|
|
||||||
|
# jq (JSON Processor) ⭐⭐⭐⭐⭐
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
命令行JSON查询、过滤和转换工具
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew install jq
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
sudo apt-get install jq
|
||||||
|
```
|
||||||
|
|
||||||
|
## 基础使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 美化打印
|
||||||
|
cat data.json | jq '.'
|
||||||
|
|
||||||
|
# 提取字段
|
||||||
|
cat api.json | jq '.users[0].name'
|
||||||
|
|
||||||
|
# 数组长度
|
||||||
|
cat data.json | jq '.items | length'
|
||||||
|
|
||||||
|
# 过滤
|
||||||
|
cat logs.json | jq '.[] | select(.level == "ERROR")'
|
||||||
|
|
||||||
|
# 转换
|
||||||
|
cat data.json | jq '{new_name: .old_name, count: .items | length}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 在ai-runtime中的使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 分析JSON格式的认知记录
|
||||||
|
jq '.entries[] | select(.type == "ERROR")' .ai-runtime/memory/episodic/timeline.json
|
||||||
|
|
||||||
|
# 发现工具统计显示
|
||||||
|
python3 discover-toolkit.py list --json | jq '.[] | {tool: .tool_name, lang: .language}'
|
||||||
|
|
||||||
|
# 提取依赖分析结果
|
||||||
|
python3 dependency-analyzer.py . -o report.json | jq '.vulnerabilities'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常用操作
|
||||||
|
|
||||||
|
### 数组操作
|
||||||
|
```bash
|
||||||
|
# 映射
|
||||||
|
cat data.json | jq 'map(.value * 2)'
|
||||||
|
|
||||||
|
# 过滤
|
||||||
|
cat data.json | jq 'map(select(.active == true))'
|
||||||
|
|
||||||
|
# 排序
|
||||||
|
cat data.json | jq 'sort_by(.date)'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 对象操作
|
||||||
|
```bash
|
||||||
|
# 添加字段
|
||||||
|
cat data.json | jq '. + {new_field: "value"}'
|
||||||
|
|
||||||
|
# 删除字段
|
||||||
|
cat data.json | jq 'del(.old_field)'
|
||||||
|
|
||||||
|
# 合并对象
|
||||||
|
cat data1.json data2.json | jq -s 'add'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 高级技巧
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 条件判断
|
||||||
|
cat config.json | jq '.env.WIN_VERBOSE = if .debug then "true" else "false" end'
|
||||||
|
|
||||||
|
# 管道操作
|
||||||
|
cat data.json | jq '.items[] | select(.price > 100) | .name'
|
||||||
|
|
||||||
|
# 变量赋值
|
||||||
|
cat data.json | jq 'first(.items[] | select(.id == "123")) as $item | $item.price'
|
||||||
|
```
|
||||||
68
skills/toolkit/docs/tools/external/ripgrep.md
vendored
Normal file
68
skills/toolkit/docs/tools/external/ripgrep.md
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
name: ripgrep
|
||||||
|
description: 极速代码搜索工具(rg)- grep的现代化替代品
|
||||||
|
category: essential
|
||||||
|
tool_id: EXT-RG-001
|
||||||
|
---
|
||||||
|
|
||||||
|
# ripgrep (rg) ⭐⭐⭐⭐⭐
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
极速代码搜索,默认递归搜索且遵守.gitignore
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew install ripgrep
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
sudo apt-get install ripgrep
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置
|
||||||
|
```bash
|
||||||
|
# 添加到 ~/.bashrc
|
||||||
|
alias grep='rg'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 搜索Python文件中的TODO
|
||||||
|
rg "TODO" -g "*.py"
|
||||||
|
|
||||||
|
# 显示上下文(3行)
|
||||||
|
rg -A 3 -B 3 "def function_name" app.py
|
||||||
|
|
||||||
|
# 统计匹配数
|
||||||
|
rg --count "import"
|
||||||
|
|
||||||
|
# 搜索并打开文件
|
||||||
|
rg "TODO" --files-with-matches | fzf | xargs bat
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常用选项
|
||||||
|
|
||||||
|
- `-i` -- 忽略大小写
|
||||||
|
- `-g` -- 文件模式匹配(glob)
|
||||||
|
- `-A NUM` -- 显示匹配后NUM行
|
||||||
|
- `-B NUM` -- 显示匹配前NUM行
|
||||||
|
- `-C NUM` -- 显示匹配前后各NUM行
|
||||||
|
- `--count` -- 统计匹配数
|
||||||
|
- `--files-with-matches` -- 只显示包含匹配的文件名
|
||||||
|
|
||||||
|
## 技巧
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 搜索并替换(预览)
|
||||||
|
rg "old_function" -S | fzf
|
||||||
|
|
||||||
|
# 指定编码
|
||||||
|
rg --encoding utf8 "pattern"
|
||||||
|
|
||||||
|
# 与fzf集成
|
||||||
|
rg "" --files-with-matches | fzf --preview 'rg --color=always "" {}'
|
||||||
|
```
|
||||||
75
skills/toolkit/docs/tools/external/zoxide.md
vendored
Normal file
75
skills/toolkit/docs/tools/external/zoxide.md
vendored
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
---
|
||||||
|
name: zoxide
|
||||||
|
description: 智能目录跳转工具(z)- cd的AI驱动替代品
|
||||||
|
category: essential
|
||||||
|
tool_id: EXT-ZOXIDE-001
|
||||||
|
---
|
||||||
|
|
||||||
|
# zoxide (Smart cd) ⭐⭐⭐⭐⭐
|
||||||
|
|
||||||
|
## 用途
|
||||||
|
智能目录跳转,学习访问习惯,基于频率和最近访问时间
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
### 所有平台(推荐)
|
||||||
|
```bash
|
||||||
|
curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
|
||||||
|
```
|
||||||
|
|
||||||
|
或者使用包管理器:
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew install zoxide
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
sudo apt-get install zoxide
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置
|
||||||
|
|
||||||
|
添加到 `~/.bashrc`:
|
||||||
|
```bash
|
||||||
|
eval "$(zoxide init bash)"
|
||||||
|
alias cd='z'
|
||||||
|
alias cdi='zi'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 第一次需要完整路径
|
||||||
|
cd ~/projects/ai-runtime
|
||||||
|
|
||||||
|
# 之后只需(zoxide会学习)
|
||||||
|
z ai-runtime
|
||||||
|
|
||||||
|
# 查看访问频率
|
||||||
|
z --list | head
|
||||||
|
|
||||||
|
# 交互式选择
|
||||||
|
zi
|
||||||
|
|
||||||
|
# 跳转到包含'proj'的目录
|
||||||
|
z proj
|
||||||
|
|
||||||
|
# 跳转到包含'ai'和'time'的目录
|
||||||
|
z ai time
|
||||||
|
```
|
||||||
|
|
||||||
|
## 常用命令
|
||||||
|
|
||||||
|
- `z --list` -- 显示访问目录列表
|
||||||
|
- `z --list | head` -- 显示最近访问的目录
|
||||||
|
- `z -i` -- 交互式跳转(同`zi`)
|
||||||
|
- `z -e` -- 显示最高匹配目录
|
||||||
|
|
||||||
|
## 特性
|
||||||
|
|
||||||
|
- **智能学习**:基于访问频率和最近访问时间
|
||||||
|
- **模糊匹配**:支持部分匹配
|
||||||
|
- **跨Shell**:支持bash, zsh, fish等
|
||||||
|
- **快速跳转**:通常比手动输入路径更快
|
||||||
139
skills/toolkit/external/README.md
vendored
Normal file
139
skills/toolkit/external/README.md
vendored
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
# 外部工具装备目录 (External Toolkit)
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
external/
|
||||||
|
├── search/ # 搜索工具
|
||||||
|
│ └── fzf.meta.yml # 模糊查找器
|
||||||
|
├── navigation/ # 导航工具
|
||||||
|
│ └── zoxide.meta.yml # 智能目录跳转
|
||||||
|
├── file-search/ # 文件搜索工具
|
||||||
|
│ └── fd.meta.yml # find替代品
|
||||||
|
├── code-search/ # 代码搜索工具
|
||||||
|
│ └── ripgrep.meta.yml # 极速代码搜索
|
||||||
|
├── file-listing/ # 文件列表工具
|
||||||
|
│ └── eza.meta.yml # 现代化ls
|
||||||
|
├── file-viewer/ # 文件查看工具
|
||||||
|
│ └── bat.meta.yml # 语法高亮cat
|
||||||
|
├── data-processing/ # 数据处理工具
|
||||||
|
│ └── jq.meta.yml # JSON处理器
|
||||||
|
├── api-testing/ # API测试工具
|
||||||
|
│ └── xh.meta.yml # HTTP客户端
|
||||||
|
├── git-tools/ # Git工具
|
||||||
|
│ └── delta.meta.yml # diff美化
|
||||||
|
└── shell-enhancement/ # Shell增强工具
|
||||||
|
└── starship.meta.yml # Shell提示符
|
||||||
|
```
|
||||||
|
|
||||||
|
## 设计理念
|
||||||
|
|
||||||
|
### 简化元数据
|
||||||
|
|
||||||
|
外部工具(如fzf, ripgrep, bat等)是广为人知的CLI工具,它们:
|
||||||
|
|
||||||
|
1. **已预训练** - 大语言模型通常已了解这些常用工具,无需详细文档
|
||||||
|
2. **动态帮助** - 可使用 `command --help` 或 `man command` 获取最新信息
|
||||||
|
3. **避免重复** - 不重复官方文档,保持元数据简洁
|
||||||
|
|
||||||
|
### 元数据结构
|
||||||
|
|
||||||
|
每个外部工具仅需一个 `.meta.yml` 文件,包含:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
tool_id: EXT-FZF-001
|
||||||
|
tool_name: "fzf (Fuzzy Finder)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: fzf
|
||||||
|
类别: search
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "命令行模糊查找器,用于交互式选择"
|
||||||
|
详细: "常用工具,支持交互式模糊搜索。使用 'fzf --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 文件名模糊查找
|
||||||
|
- 历史命令搜索
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install fzf"
|
||||||
|
帮助命令: "fzf --help"
|
||||||
|
常用示例:
|
||||||
|
- "find . -type f | fzf"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
|
```
|
||||||
|
|
||||||
|
## 与内部工具的区别
|
||||||
|
|
||||||
|
| 特性 | 内部工具 (Internal) | 外部工具 (External) |
|
||||||
|
|------|-------------------|-------------------|
|
||||||
|
| 位置 | `bash/`, `python/`, `node/` | `external/` |
|
||||||
|
| 实现 | AI Runtime创建的工具脚本 | 系统级CLI工具 |
|
||||||
|
| 元数据 | 详细(包含完整描述、参数、示例) | 简化(模型已知工具) |
|
||||||
|
| 检测 | 检查工具文件exists | 使用 `shutil.which()` |
|
||||||
|
| 示例 | `dependency-analyzer.py` | `fzf`, `ripgrep`, `bat` |
|
||||||
|
|
||||||
|
## 检测机制
|
||||||
|
|
||||||
|
`ExternalToolDetector` 扫描 `external/` 目录:
|
||||||
|
|
||||||
|
1. **递归扫描** - 查找所有 `.meta.yml` 文件
|
||||||
|
2. **类型过滤** - 只处理 `基本信息.类型 == "external"`
|
||||||
|
3. **安装检测** - 使用 `shutil.which()` 检查命令是否可用
|
||||||
|
4. **运行时检测** - 每次运行都重新检测,获取最新状态
|
||||||
|
|
||||||
|
## 使用方式
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd .ai-runtime/toolkit
|
||||||
|
|
||||||
|
# 列出所有外部工具
|
||||||
|
python3 discover-toolkit.py list --external
|
||||||
|
|
||||||
|
# 显示外部工具详情
|
||||||
|
python3 discover-toolkit.py show fzf
|
||||||
|
|
||||||
|
# 搜索包含'search'的外部工具
|
||||||
|
python3 discover-toolkit.py search search --external
|
||||||
|
|
||||||
|
# 查看所有工具(内部 + 外部)
|
||||||
|
python3 discover-toolkit.py list
|
||||||
|
```
|
||||||
|
|
||||||
|
## 新增外部工具
|
||||||
|
|
||||||
|
添加新外部工具只需:
|
||||||
|
|
||||||
|
1. 在 `external/<category>/` 创建 `tool-name.meta.yml`
|
||||||
|
2. 填写基本信息(ID、名称、命令、类别)
|
||||||
|
3. 提供使用场景和快速开始
|
||||||
|
4. (可选)添加检测状态占位符
|
||||||
|
|
||||||
|
无需修改代码,自动检测加载。
|
||||||
|
|
||||||
|
## 已安装的外部工具
|
||||||
|
|
||||||
|
当前检测到的外部CLI工具(9个):
|
||||||
|
|
||||||
|
- ✅ **fzf** - 模糊查找
|
||||||
|
- ✅ **eza** - 现代化ls
|
||||||
|
- ✅ **zoxide** - 智能cd
|
||||||
|
- ✅ **fd** - 文件搜索
|
||||||
|
- ✅ **ripgrep (rg)** - 代码搜索
|
||||||
|
- ✅ **bat** - 语法高亮查看器
|
||||||
|
- ✅ **jq** - JSON处理器
|
||||||
|
- ✅ **xh** - HTTP客户端
|
||||||
|
- ✅ **delta** - Git diff美化
|
||||||
|
- ❌ **starship** - Shell提示符(未安装)
|
||||||
|
|
||||||
|
## 优势
|
||||||
|
|
||||||
|
✅ **统一结构** - 内部/外部工具都使用 `.meta.yml` 文件
|
||||||
|
✅ **简化维护** - 外部工具不重复文档
|
||||||
|
✅ **动态检测** - 实时检测安装状态
|
||||||
|
✅ **分类清晰** - 按功能分类,便于查找
|
||||||
|
✅ **易于扩展** - 添加新工具只需创建元文件
|
||||||
26
skills/toolkit/external/api-testing/xh.meta.yml
vendored
Normal file
26
skills/toolkit/external/api-testing/xh.meta.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
tool_id: EXT-XH-001
|
||||||
|
tool_name: "xh (HTTP client)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: xh
|
||||||
|
类别: api-testing
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "友好的HTTP客户端,替代curl"
|
||||||
|
详细: "现代HTTP客户端,语法友好且输出美观。使用 'xh --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 发送HTTP请求
|
||||||
|
- API测试
|
||||||
|
- 文件下载
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install xh"
|
||||||
|
帮助命令: "xh --help"
|
||||||
|
常用示例:
|
||||||
|
- "xh http://api.example.com"
|
||||||
|
- "xh post http://api.example.com/data name=test"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
28
skills/toolkit/external/code-search/ripgrep.meta.yml
vendored
Normal file
28
skills/toolkit/external/code-search/ripgrep.meta.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
tool_id: EXT-RG-001
|
||||||
|
tool_name: "ripgrep (rg)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: rg
|
||||||
|
类别: code-search
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "极速代码搜索工具"
|
||||||
|
详细: "默认递归搜索且遵守.gitignore的快速搜索工具。使用 'rg --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 搜索代码
|
||||||
|
- 显示上下文
|
||||||
|
- 统计匹配数
|
||||||
|
- 正则表达式搜索
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install ripgrep"
|
||||||
|
帮助命令: "rg --help"
|
||||||
|
常用示例:
|
||||||
|
- "rg 'TODO'"
|
||||||
|
- "rg -n 'function'"
|
||||||
|
- "rg -C 3 'error'"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
27
skills/toolkit/external/data-processing/jq.meta.yml
vendored
Normal file
27
skills/toolkit/external/data-processing/jq.meta.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
tool_id: EXT-JQ-001
|
||||||
|
tool_name: "jq (JSON processor)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: jq
|
||||||
|
类别: data-processing
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "JSON数据的命令行处理器"
|
||||||
|
详细: "解析、过滤、转换JSON数据。使用 'jq --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- JSON美化
|
||||||
|
- 字段提取
|
||||||
|
- 数据过滤
|
||||||
|
- 格式转换
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install jq"
|
||||||
|
帮助命令: "jq --help"
|
||||||
|
常用示例:
|
||||||
|
- 'cat data.json | jq "."'
|
||||||
|
- 'jq ".name" data.json'
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已 installed: true
|
||||||
28
skills/toolkit/external/file-listing/eza.meta.yml
vendored
Normal file
28
skills/toolkit/external/file-listing/eza.meta.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
tool_id: EXT-EZA-001
|
||||||
|
tool_name: "eza (Modern ls)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: eza
|
||||||
|
类别: file-listing
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "现代化的ls替代品,带彩色输出和图标"
|
||||||
|
详细: "增强的文件列表工具,支持Git集成。使用 'eza --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 查看文件列表
|
||||||
|
- 树形结构显示
|
||||||
|
- Git状态查看
|
||||||
|
- 文件图标显示
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install eza"
|
||||||
|
帮助命令: "eza --help"
|
||||||
|
常用示例:
|
||||||
|
- "eza --long --git"
|
||||||
|
- "eza --tree --level=2"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
|
版本: "0.18"
|
||||||
26
skills/toolkit/external/file-search/fd.meta.yml
vendored
Normal file
26
skills/toolkit/external/file-search/fd.meta.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
tool_id: EXT-FD-001
|
||||||
|
tool_name: "fd (Simple find)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: fd
|
||||||
|
类别: file-search
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "简单友好的find替代品"
|
||||||
|
详细: "忽略.gitignore的快速文件搜索工具。使用 'fd --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 查找文件
|
||||||
|
- 忽略.gitignore搜索
|
||||||
|
- 执行操作
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install fd"
|
||||||
|
帮助命令: "fd --help"
|
||||||
|
常用示例:
|
||||||
|
- "fd '.py$'"
|
||||||
|
- "fd test"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
26
skills/toolkit/external/file-viewer/bat.meta.yml
vendored
Normal file
26
skills/toolkit/external/file-viewer/bat.meta.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
tool_id: EXT-BAT-001
|
||||||
|
tool_name: "bat (cat with syntax)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: bat
|
||||||
|
类别: file-viewer
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "带语法高亮的cat替代品"
|
||||||
|
详细: "支持语法高亮和Git集成的文件查看工具。使用 'bat --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 查看代码文件
|
||||||
|
- 分页查看
|
||||||
|
- Git修改查看
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install bat"
|
||||||
|
帮助命令: "bat --help"
|
||||||
|
常用示例:
|
||||||
|
- "bat file.py"
|
||||||
|
- "bat -p file.txt" # 纯文本模式(无分页)
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
26
skills/toolkit/external/git-tools/delta.meta.yml
vendored
Normal file
26
skills/toolkit/external/git-tools/delta.meta.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
tool_id: EXT-DELTA-001
|
||||||
|
tool_name: "delta (Git diff美化)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: delta
|
||||||
|
类别: git-tools
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "Git diff的美化工具"
|
||||||
|
详细: "为Git diff提供语法高亮和行号显示。使用 'delta --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 查看Git diff
|
||||||
|
- 语法高亮
|
||||||
|
- 行号显示
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install git-delta"
|
||||||
|
帮助命令: "delta --help"
|
||||||
|
常用示例:
|
||||||
|
- 配置到git: "git config --global pager.diff delta"
|
||||||
|
- "git diff"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
26
skills/toolkit/external/navigation/zoxide.meta.yml
vendored
Normal file
26
skills/toolkit/external/navigation/zoxide.meta.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
tool_id: EXT-ZOXIDE-001
|
||||||
|
tool_name: "zoxide (Smart cd)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: zoxide
|
||||||
|
类别: navigation
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "智能目录跳转工具,学习访问习惯"
|
||||||
|
详细: "AI驱动的cd命令替代品。使用 'zoxide --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 快速跳转目录
|
||||||
|
- 访问频率学习
|
||||||
|
- 路径自动补全
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh"
|
||||||
|
帮助命令: "zoxide --help"
|
||||||
|
常用示例:
|
||||||
|
- "z myproject"
|
||||||
|
- "z foo bar" # 匹配包含foo和bar的路径
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
30
skills/toolkit/external/search/fzf.meta.yml
vendored
Normal file
30
skills/toolkit/external/search/fzf.meta.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
tool_id: EXT-FZF-001
|
||||||
|
tool_name: "fzf (Fuzzy Finder)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: fzf
|
||||||
|
类别: search
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "命令行模糊查找器,用于交互式选择"
|
||||||
|
详细: "常用工具,支持交互式模糊搜索。使用 'fzf --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 文件名模糊查找
|
||||||
|
- 历史命令搜索
|
||||||
|
- Git分支切换
|
||||||
|
- 交互式选择
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "brew install fzf (macOS) / apt-get install fzf (Ubuntu)"
|
||||||
|
帮助命令: "fzf --help"
|
||||||
|
常用示例:
|
||||||
|
- "find . -type f | fzf"
|
||||||
|
- "history | fzf"
|
||||||
|
- "git branch | fzf"
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true # 根据discover-toolkit.py检测结果
|
||||||
|
版本: "0.45"
|
||||||
|
路径: "/opt/homebrew/bin/fzf"
|
||||||
27
skills/toolkit/external/shell-enhancement/starship.meta.yml
vendored
Normal file
27
skills/toolkit/external/shell-enhancement/starship.meta.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
tool_id: EXT-STEAMSHIP-001
|
||||||
|
tool_name: "starship (Shell提示符)"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
类型: external
|
||||||
|
命令: starship
|
||||||
|
类别: shell-enhancement
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "快速、可定制、智能的Shell提示符"
|
||||||
|
详细: "跨Shell的提示符增强工具。使用 'starship --help' 获取详细信息。"
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- 显示Git状态
|
||||||
|
- 显示Python版本
|
||||||
|
- 显示目录
|
||||||
|
- Shell美化
|
||||||
|
|
||||||
|
快速开始:
|
||||||
|
安装: "curl -sS https://starship.rs/install.sh | sh"
|
||||||
|
帮助命令: "starship --help"
|
||||||
|
常用示例:
|
||||||
|
- "starship prompt"
|
||||||
|
- 配置到Shell配置文件
|
||||||
|
|
||||||
|
检测状态:
|
||||||
|
已安装: true
|
||||||
312
skills/toolkit/node/api/test-api.js
Normal file
312
skills/toolkit/node/api/test-api.js
Normal file
@@ -0,0 +1,312 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API测试工具
|
||||||
|
* 用于测试RESTful API端点,支持多种请求方式和断言
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const Table = require('cli-table3');
|
||||||
|
|
||||||
|
class APITester {
|
||||||
|
constructor(baseURL = 'http://localhost:3000') {
|
||||||
|
this.baseURL = baseURL;
|
||||||
|
this.results = [];
|
||||||
|
this.passed = 0;
|
||||||
|
this.failed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送HTTP请求
|
||||||
|
*/
|
||||||
|
async request(method, endpoint, options = {}) {
|
||||||
|
const url = `${this.baseURL}${endpoint}`;
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...options.headers,
|
||||||
|
},
|
||||||
|
body: options.body ? JSON.stringify(options.body) : undefined,
|
||||||
|
timeout: options.timeout || 5000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
|
const responseBody = await response.text();
|
||||||
|
|
||||||
|
let parsedBody;
|
||||||
|
try {
|
||||||
|
parsedBody = JSON.parse(responseBody);
|
||||||
|
} catch {
|
||||||
|
parsedBody = responseBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
headers: response.headers.raw(),
|
||||||
|
body: parsedBody,
|
||||||
|
rawBody: responseBody,
|
||||||
|
duration,
|
||||||
|
url,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message,
|
||||||
|
duration: Date.now() - startTime,
|
||||||
|
url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送GET请求
|
||||||
|
*/
|
||||||
|
async get(endpoint, options = {}) {
|
||||||
|
return this.request('GET', endpoint, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送POST请求
|
||||||
|
*/
|
||||||
|
async post(endpoint, body, options = {}) {
|
||||||
|
return this.request('POST', endpoint, { body, ...options });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送PUT请求
|
||||||
|
*/
|
||||||
|
async put(endpoint, body, options = {}) {
|
||||||
|
return this.request('PUT', endpoint, { body, ...options });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送DELETE请求
|
||||||
|
*/
|
||||||
|
async delete(endpoint, options = {}) {
|
||||||
|
return this.request('DELETE', endpoint, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行测试用例
|
||||||
|
*/
|
||||||
|
async runTest(name, testFn) {
|
||||||
|
console.log(`\n${chalk.blue('▶')} Running: ${chalk.bold(name)}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await testFn();
|
||||||
|
this.passed++;
|
||||||
|
this.results.push({ name, status: 'PASS', ...result });
|
||||||
|
console.log(` ${chalk.green('✓')} PASS`);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
this.failed++;
|
||||||
|
this.results.push({ name, status: 'FAIL', error: error.message });
|
||||||
|
console.log(` ${chalk.red('✗')} FAIL`);
|
||||||
|
console.log(` ${chalk.gray('Error:')} ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断言状态码
|
||||||
|
*/
|
||||||
|
assertStatus(response, expectedStatus) {
|
||||||
|
if (!response.success) {
|
||||||
|
throw new Error(`请求失败: ${response.error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status !== expectedStatus) {
|
||||||
|
throw new Error(`状态码不匹配: 期望 ${expectedStatus}, 实际 ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断言响应包含某个字段
|
||||||
|
*/
|
||||||
|
assertHas(response, path) {
|
||||||
|
if (!response.success) {
|
||||||
|
throw new Error(`请求失败: ${response.error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const keys = path.split('.');
|
||||||
|
let current = response.body;
|
||||||
|
|
||||||
|
for (const key of keys) {
|
||||||
|
if (current === null || current === undefined || !(key in current)) {
|
||||||
|
throw new Error(`响应中缺少字段: ${path}`);
|
||||||
|
}
|
||||||
|
current = current[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断言响应时间
|
||||||
|
*/
|
||||||
|
assertDuration(response, maxMs) {
|
||||||
|
if (response.duration > maxMs) {
|
||||||
|
throw new Error(`响应时间超时: ${response.duration}ms > ${maxMs}ms`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印测试总结
|
||||||
|
*/
|
||||||
|
printSummary() {
|
||||||
|
console.log('\n' + '='.repeat(60));
|
||||||
|
console.log(chalk.bold('📊 测试总结'));
|
||||||
|
console.log('='.repeat(60));
|
||||||
|
|
||||||
|
const total = this.passed + this.failed;
|
||||||
|
const passRate = total > 0 ? (this.passed / total * 100).toFixed(1) : 0;
|
||||||
|
|
||||||
|
// 结果概览
|
||||||
|
console.log(`\n总测试数: ${total}`);
|
||||||
|
console.log(chalk.green(` ✓ 通过: ${this.passed}`));
|
||||||
|
console.log(chalk.red(` ✗ 失败: ${this.failed}`));
|
||||||
|
console.log(` 通过率: ${passRate}%`);
|
||||||
|
|
||||||
|
// 详细结果表格
|
||||||
|
if (this.results.length > 0) {
|
||||||
|
console.log('\n详细结果:');
|
||||||
|
const table = new Table({
|
||||||
|
head: ['Test Name', 'Status', 'Duration', 'Status Code'],
|
||||||
|
style: { head: ['cyan'] },
|
||||||
|
});
|
||||||
|
|
||||||
|
this.results.forEach((result) => {
|
||||||
|
const statusColor = result.status === 'PASS' ? chalk.green : chalk.red;
|
||||||
|
const duration = result.duration ? `${result.duration}ms` : '-';
|
||||||
|
const statusCode = result.statusCode || '-';
|
||||||
|
|
||||||
|
table.push([
|
||||||
|
result.name,
|
||||||
|
statusColor(result.status),
|
||||||
|
duration,
|
||||||
|
statusCode,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(table.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 建议
|
||||||
|
if (this.failed > 0) {
|
||||||
|
console.log(chalk.yellow('\n💡 建议:'));
|
||||||
|
console.log(' - 检查API服务是否运行');
|
||||||
|
console.log(' - 验证测试数据和配置');
|
||||||
|
console.log(' - 查看详细的错误日志');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n' + '='.repeat(60));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出JSON报告
|
||||||
|
*/
|
||||||
|
exportReport(filename = 'api-test-report.json') {
|
||||||
|
const report = {
|
||||||
|
summary: {
|
||||||
|
total: this.passed + this.failed,
|
||||||
|
passed: this.passed,
|
||||||
|
failed: this.failed,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
},
|
||||||
|
results: this.results,
|
||||||
|
};
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
fs.writeFileSync(filename, JSON.stringify(report, null, 2));
|
||||||
|
console.log(`\n💾 报告已导出: ${filename}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CLI 接口
|
||||||
|
async function main() {
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const baseURL = args[0] || process.env.API_BASE_URL || 'http://localhost:3000';
|
||||||
|
|
||||||
|
console.log(chalk.bold.blue('🚀 API测试工具'));
|
||||||
|
console.log(`Base URL: ${chalk.gray(baseURL)}`);
|
||||||
|
console.log('='.repeat(60));
|
||||||
|
|
||||||
|
const tester = new APITester(baseURL);
|
||||||
|
|
||||||
|
// 示例测试套件
|
||||||
|
try {
|
||||||
|
// 测试1: 健康检查
|
||||||
|
await tester.runTest('健康检查端点', async () => {
|
||||||
|
const response = await tester.get('/health');
|
||||||
|
tester.assertStatus(response, 200);
|
||||||
|
tester.assertDuration(response, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 测试2: 用户注册
|
||||||
|
await tester.runTest('用户注册', async () => {
|
||||||
|
const response = await tester.post('/api/auth/register', {
|
||||||
|
email: 'test@example.com',
|
||||||
|
password: 'Test@123',
|
||||||
|
});
|
||||||
|
tester.assertStatus(response, 201);
|
||||||
|
tester.assertHas(response, 'user.id');
|
||||||
|
tester.assertHas(response, 'token.accessToken');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 测试3: 用户登录
|
||||||
|
await tester.runTest('用户登录', async () => {
|
||||||
|
const response = await tester.post('/api/auth/login', {
|
||||||
|
email: 'test@example.com',
|
||||||
|
password: 'Test@123',
|
||||||
|
});
|
||||||
|
tester.assertStatus(response, 200);
|
||||||
|
const token = tester.assertHas(response, 'token.accessToken');
|
||||||
|
return { token };
|
||||||
|
});
|
||||||
|
|
||||||
|
// 测试4: 访问受保护资源
|
||||||
|
await tester.runTest('访问受保护资源', async () => {
|
||||||
|
// 先登录获取token(这里简化,实际应该传递)
|
||||||
|
const loginRes = await tester.post('/api/auth/login', {
|
||||||
|
email: 'test@example.com',
|
||||||
|
password: 'Test@123',
|
||||||
|
});
|
||||||
|
const token = loginRes.body.token.accessToken;
|
||||||
|
|
||||||
|
const response = await tester.get('/api/user/profile', {
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
tester.assertStatus(response, 200);
|
||||||
|
tester.assertHas(response, 'user.email');
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(chalk.red('\n测试执行中断:'), error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印总结
|
||||||
|
tester.printSummary();
|
||||||
|
|
||||||
|
// 导出报告
|
||||||
|
tester.exportReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行
|
||||||
|
if (require.main === module) {
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error(chalk.red('致命错误:'), error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { APITester };
|
||||||
95
skills/toolkit/python/analysis/code-stats.meta.yml
Normal file
95
skills/toolkit/python/analysis/code-stats.meta.yml
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
tool_id: PY-CODE-STATS-004
|
||||||
|
tool_name: "代码统计器"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
语言: python
|
||||||
|
文件: code-stats.py
|
||||||
|
复杂度: level-3
|
||||||
|
创建日期: 2025-11-14
|
||||||
|
作者: CodeConscious
|
||||||
|
|
||||||
|
用途分类:
|
||||||
|
- CODE # 代码分析
|
||||||
|
- DATA # 数据统计
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "分析代码库统计信息,包括行数、函数、类、注释率和代码健康度评分"
|
||||||
|
详细: |
|
||||||
|
支持功能:
|
||||||
|
- 多语言支持(Python, JavaScript, TypeScript, Java, C/C++, Shell)
|
||||||
|
- 统计行数、代码行、注释行、空行
|
||||||
|
- 统计函数、类、导入语句数量
|
||||||
|
- 按文件类型分组统计
|
||||||
|
- 代码复杂度评分(0-100)
|
||||||
|
- 代码健康度评分(基于注释率、文件大小、函数密度)
|
||||||
|
- 生成详细分析报告和建议
|
||||||
|
- 支持JSON格式输出
|
||||||
|
- 支持报告保存到文件
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- "评估新项目代码库规模和复杂度"
|
||||||
|
- "代码审查前了解整体质量状况"
|
||||||
|
- "重构前识别需要改进的模块(大文件、低注释率)"
|
||||||
|
- "定期监控代码健康度变化趋势"
|
||||||
|
- "技术债务评估和量化"
|
||||||
|
- "团队间代码质量对比"
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
命令: "python3 code-stats.py [项目路径] [选项]"
|
||||||
|
参数:
|
||||||
|
project_path: "项目路径(默认:当前目录)"
|
||||||
|
--json: "JSON格式输出"
|
||||||
|
-o, --output: "输出报告到文件"
|
||||||
|
示例:
|
||||||
|
- "分析当前目录: python3 code-stats.py ."
|
||||||
|
- "分析指定项目: python3 code-stats.py /path/to/project"
|
||||||
|
- "JSON格式输出: python3 code-stats.py . --json"
|
||||||
|
- "保存报告: python3 code-stats.py . -o report.md"
|
||||||
|
|
||||||
|
依赖要求:
|
||||||
|
python版本: ">=3.8"
|
||||||
|
依赖包: # 无第三方依赖,只使用标准库
|
||||||
|
- argparse: "标准库"
|
||||||
|
- json: "标准库"
|
||||||
|
- pathlib: "标准库"
|
||||||
|
- re: "标准库"
|
||||||
|
|
||||||
|
输入输出:
|
||||||
|
输入:
|
||||||
|
- 类型: 目录(递归扫描)
|
||||||
|
- 格式: 源代码文件
|
||||||
|
- 忽略: .git, __pycache__, node_modules, venv等
|
||||||
|
输出:
|
||||||
|
- stdout: 详细统计报告(按文件类型、健康度评分、建议)
|
||||||
|
- JSON: 结构化数据(使用--json参数)
|
||||||
|
- 文件: Markdown报告(使用-o参数)
|
||||||
|
|
||||||
|
上次使用:
|
||||||
|
时间: 2025-11-14 11:45:00
|
||||||
|
用途: "分析ai-runtime项目代码库,评估项目规模和质量"
|
||||||
|
结果: |
|
||||||
|
识别出25个文件,总代码行数约50000行
|
||||||
|
注释率12%(符合质量标准>10%)
|
||||||
|
代码复杂度评分:中等
|
||||||
|
识别出3个较大文件(>500行,建议拆分)
|
||||||
|
满意度: 0.94
|
||||||
|
|
||||||
|
相关工具:
|
||||||
|
- 前置工具: 无
|
||||||
|
- 互补工具:
|
||||||
|
- toolkit/python/analysis/dependency-analyzer.py(依赖分析)
|
||||||
|
- toolkit/bash/analysis/analyze-logs.sh(日志分析)
|
||||||
|
- 替代工具:
|
||||||
|
- cloc(专业代码统计工具)
|
||||||
|
- wc -l(简单行数统计)
|
||||||
|
|
||||||
|
维护记录:
|
||||||
|
2025-11-14:
|
||||||
|
- 初始创建
|
||||||
|
- 支持多语言(Python, JavaScript, Java, C/C++, Shell)
|
||||||
|
- 实现复杂度评分和健康度评分
|
||||||
|
TODO:
|
||||||
|
- 支持更多语言(Go, Rust, Ruby)
|
||||||
|
- 添加复杂度圈数(Cyclomatic Complexity)计算
|
||||||
|
- 支持代码重复率检测
|
||||||
|
- 添加与上次统计的对比功能
|
||||||
363
skills/toolkit/python/analysis/code-stats.py
Normal file
363
skills/toolkit/python/analysis/code-stats.py
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
代码统计器 - 分析代码库统计信息,包括行数、函数、类、注释率等
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, List, Any
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
class CodeStats:
|
||||||
|
def __init__(self, project_path: Path):
|
||||||
|
self.project_path = Path(project_path)
|
||||||
|
self.stats: Dict[str, Any] = {
|
||||||
|
'files': 0,
|
||||||
|
'total_lines': 0,
|
||||||
|
'code_lines': 0,
|
||||||
|
'comment_lines': 0,
|
||||||
|
'blank_lines': 0,
|
||||||
|
'functions': 0,
|
||||||
|
'classes': 0,
|
||||||
|
'imports': 0,
|
||||||
|
'by_extension': {}
|
||||||
|
}
|
||||||
|
|
||||||
|
def analyze_file(self, file_path: Path) -> Dict[str, Any]:
|
||||||
|
"""分析单个文件"""
|
||||||
|
file_stats = {
|
||||||
|
'lines': 0,
|
||||||
|
'code': 0,
|
||||||
|
'comments': 0,
|
||||||
|
'blank': 0,
|
||||||
|
'functions': 0,
|
||||||
|
'classes': 0,
|
||||||
|
'imports': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
content = file_path.read_text(encoding='utf-8')
|
||||||
|
lines = content.splitlines()
|
||||||
|
|
||||||
|
in_block_comment = False
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
file_stats['lines'] += 1
|
||||||
|
stripped = line.strip()
|
||||||
|
|
||||||
|
# 空行
|
||||||
|
if not stripped:
|
||||||
|
file_stats['blank'] += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 块注释检测
|
||||||
|
if '/*' in stripped and not in_block_comment:
|
||||||
|
in_block_comment = True
|
||||||
|
file_stats['comments'] += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
if in_block_comment:
|
||||||
|
file_stats['comments'] += 1
|
||||||
|
if '*/' in stripped:
|
||||||
|
in_block_comment = False
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 行注释
|
||||||
|
if stripped.startswith('#') or stripped.startswith('//'):
|
||||||
|
file_stats['comments'] += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
if '#' in stripped and not stripped.startswith('"') and not stripped.startswith("'"):
|
||||||
|
file_stats['comments'] += 1
|
||||||
|
file_stats['code'] += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 代码行
|
||||||
|
file_stats['code'] += 1
|
||||||
|
|
||||||
|
# 函数/类检测
|
||||||
|
if 'def ' in line and 'class ' not in line:
|
||||||
|
file_stats['functions'] += 1
|
||||||
|
elif 'class ' in line:
|
||||||
|
file_stats['classes'] += 1
|
||||||
|
elif 'import ' in line or 'from ' in line:
|
||||||
|
file_stats['imports'] += 1
|
||||||
|
|
||||||
|
return file_stats
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ 警告: 无法读取文件 {file_path}: {e}", file=sys.stderr)
|
||||||
|
return file_stats
|
||||||
|
|
||||||
|
def analyze_directory(self, directory: Path):
|
||||||
|
"""递归分析目录"""
|
||||||
|
ignore_patterns = {
|
||||||
|
'.git', '.svn', '.hg', '__pycache__', 'node_modules',
|
||||||
|
'venv', 'env', '.venv', 'dist', 'build', '*.egg-info'
|
||||||
|
}
|
||||||
|
|
||||||
|
for item in directory.iterdir():
|
||||||
|
# 忽略模式
|
||||||
|
if any(pattern in str(item) for pattern in ignore_patterns):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if item.is_dir():
|
||||||
|
self.analyze_directory(item)
|
||||||
|
elif item.is_file():
|
||||||
|
# 支持的文件类型
|
||||||
|
supported_ext = {'.py', '.js', '.ts', '.java', '.cpp', '.c', '.h', '.sh'}
|
||||||
|
ext = item.suffix.lower()
|
||||||
|
|
||||||
|
if ext in supported_ext:
|
||||||
|
file_stats = self.analyze_file(item)
|
||||||
|
|
||||||
|
# 更新全局统计
|
||||||
|
self.stats['files'] += 1
|
||||||
|
self.stats['total_lines'] += file_stats['lines']
|
||||||
|
self.stats['code_lines'] += file_stats['code']
|
||||||
|
self.stats['comment_lines'] += file_stats['comments']
|
||||||
|
self.stats['blank_lines'] += file_stats['blank']
|
||||||
|
self.stats['functions'] += file_stats['functions']
|
||||||
|
self.stats['classes'] += file_stats['classes']
|
||||||
|
self.stats['imports'] += file_stats['imports']
|
||||||
|
|
||||||
|
# 按扩展名分组
|
||||||
|
if ext not in self.stats['by_extension']:
|
||||||
|
self.stats['by_extension'][ext] = {
|
||||||
|
'files': 0,
|
||||||
|
'lines': 0,
|
||||||
|
'code': 0,
|
||||||
|
'comments': 0,
|
||||||
|
'blank': 0,
|
||||||
|
'functions': 0,
|
||||||
|
'classes': 0,
|
||||||
|
'imports': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
ext_stats = self.stats['by_extension'][ext]
|
||||||
|
ext_stats['files'] += 1
|
||||||
|
ext_stats['lines'] += file_stats['lines']
|
||||||
|
ext_stats['code'] += file_stats['code']
|
||||||
|
ext_stats['comments'] += file_stats['comments']
|
||||||
|
ext_stats['blank'] += file_stats['blank']
|
||||||
|
ext_stats['functions'] += file_stats['functions']
|
||||||
|
ext_stats['classes'] += file_stats['classes']
|
||||||
|
ext_stats['imports'] += file_stats['imports']
|
||||||
|
|
||||||
|
def calculate_complexity_score(self) -> float:
|
||||||
|
"""计算代码复杂度分数"""
|
||||||
|
if self.stats['files'] == 0:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
# 基于以下几个因素:
|
||||||
|
# 1. 平均文件大小
|
||||||
|
avg_file_size = self.stats['total_lines'] / self.stats['files']
|
||||||
|
size_score = min(avg_file_size / 500, 1.0) # 超过500行/文件扣分
|
||||||
|
|
||||||
|
# 2. 注释率
|
||||||
|
comment_ratio = self.stats['comment_lines'] / max(self.stats['total_lines'], 1)
|
||||||
|
comment_score = 1.0 if comment_ratio > 0.1 else 0.5 # 注释率过低扣分
|
||||||
|
|
||||||
|
# 3. 函数密度
|
||||||
|
func_density = self.stats['functions'] / max(self.stats['files'], 1)
|
||||||
|
func_score = min(func_density / 20, 1.0) # 函数过多扣分
|
||||||
|
|
||||||
|
# 综合评分(0-100)
|
||||||
|
complexity = (size_score + comment_score + func_score) / 3 * 100
|
||||||
|
return min(complexity, 100.0)
|
||||||
|
|
||||||
|
def print_report(self):
|
||||||
|
"""打印分析报告"""
|
||||||
|
print("📊 代码统计报告")
|
||||||
|
print("=" * 60)
|
||||||
|
print(f"项目路径: {self.project_path}")
|
||||||
|
print("=" * 60)
|
||||||
|
print()
|
||||||
|
|
||||||
|
if self.stats['files'] == 0:
|
||||||
|
print("⚠️ 未找到支持的代码文件")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 总体统计
|
||||||
|
print("📁 总体统计:")
|
||||||
|
print("-" * 60)
|
||||||
|
print(f"文件总数: {self.stats['files']:,}")
|
||||||
|
print(f"总行数: {self.stats['total_lines']:,}")
|
||||||
|
print(f"代码行数: {self.stats['code_lines']:,} ({self.stats['code_lines']/self.stats['total_lines']*100:.1f}%)")
|
||||||
|
print(f"注释行数: {self.stats['comment_lines']:,} ({self.stats['comment_lines']/self.stats['total_lines']*100:.1f}%)")
|
||||||
|
print(f"空行行数: {self.stats['blank_lines']:,} ({self.stats['blank_lines']/self.stats['total_lines']*100:.1f}%)")
|
||||||
|
print()
|
||||||
|
print(f"函数总数: {self.stats['functions']:,}")
|
||||||
|
print(f"类总数: {self.stats['classes']:,}")
|
||||||
|
print(f"导入语句: {self.stats['imports']:,}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
# 复杂度评分
|
||||||
|
complexity = self.calculate_complexity_score()
|
||||||
|
if complexity < 50:
|
||||||
|
complexity_color = "\033[92m" # 绿色
|
||||||
|
complexity_level = "低"
|
||||||
|
elif complexity < 75:
|
||||||
|
complexity_color = "\033[93m" # 黄色
|
||||||
|
complexity_level = "中等"
|
||||||
|
else:
|
||||||
|
complexity_color = "\033[91m" # 红色
|
||||||
|
complexity_level = "高"
|
||||||
|
|
||||||
|
print(f"代码复杂度: {complexity_color}{complexity:.1f} ({complexity_level})\033[0m")
|
||||||
|
print()
|
||||||
|
|
||||||
|
# 按文件类型统计
|
||||||
|
if self.stats['by_extension']:
|
||||||
|
print("📂 按文件类型统计:")
|
||||||
|
print("-" * 60)
|
||||||
|
print(f"{'类型':<10} {'文件数':>10} {'总行数':>12} {'代码行':>12} {'注释':>10} {'函数':>10} {'类':>8}")
|
||||||
|
print("-" * 60)
|
||||||
|
|
||||||
|
for ext, stats in sorted(self.stats['by_extension'].items()):
|
||||||
|
print(f"{ext:<10} {stats['files']:>10,} {stats['lines']:>12,} {stats['code']:>12,} "
|
||||||
|
f"{stats['comments']:>10,} {stats['functions']:>10,} {stats['classes']:>8,}")
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
|
# 健康评分
|
||||||
|
health_score = 0
|
||||||
|
health_issues = []
|
||||||
|
|
||||||
|
# 注释率健康度
|
||||||
|
comment_ratio = self.stats['comment_lines'] / max(self.stats['total_lines'], 1)
|
||||||
|
if comment_ratio >= 0.1:
|
||||||
|
health_score += 25
|
||||||
|
else:
|
||||||
|
health_issues.append(f"注释率偏低 ({comment_ratio*100:.1f}%,建议>10%)")
|
||||||
|
|
||||||
|
# 文件大小健康度
|
||||||
|
avg_file_size = self.stats['total_lines'] / self.stats['files']
|
||||||
|
if avg_file_size <= 300:
|
||||||
|
health_score += 25
|
||||||
|
elif avg_file_size <= 500:
|
||||||
|
health_score += 15
|
||||||
|
else:
|
||||||
|
health_issues.append(f"平均文件大小偏大 ({avg_file_size:.0f}行,建议<300)")
|
||||||
|
|
||||||
|
# 空白行健康度
|
||||||
|
blank_ratio = self.stats['blank_lines'] / max(self.stats['total_lines'], 1)
|
||||||
|
if 0.05 <= blank_ratio <= 0.2:
|
||||||
|
health_score += 25
|
||||||
|
else:
|
||||||
|
health_issues.append(f"空白行比例异常 ({blank_ratio*100:.1f}%)")
|
||||||
|
|
||||||
|
# 函数分布健康度
|
||||||
|
avg_funcs_per_file = self.stats['functions'] / self.stats['files']
|
||||||
|
if avg_funcs_per_file <= 15:
|
||||||
|
health_score += 25
|
||||||
|
else:
|
||||||
|
health_issues.append(f"平均函数数偏高 ({avg_funcs_per_file:.1f}个/文件)")
|
||||||
|
|
||||||
|
print("🏥 代码健康度:")
|
||||||
|
print("-" * 60)
|
||||||
|
print(f"健康评分: {health_score}/100")
|
||||||
|
|
||||||
|
if health_issues:
|
||||||
|
print()
|
||||||
|
print("⚠️ 发现的问题:")
|
||||||
|
for issue in health_issues:
|
||||||
|
print(f" - {issue}")
|
||||||
|
else:
|
||||||
|
print("✅ 代码健康状况良好")
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
|
# 建议
|
||||||
|
print("💡 建议:")
|
||||||
|
print("-" * 60)
|
||||||
|
|
||||||
|
if comment_ratio < 0.1:
|
||||||
|
print(" - 增加代码注释,提高可维护性")
|
||||||
|
|
||||||
|
if avg_file_size > 500:
|
||||||
|
print(" - 考虑拆分大文件,遵循单一职责原则")
|
||||||
|
|
||||||
|
if len(self.stats['by_extension']) > 5:
|
||||||
|
print(" - 项目包含多种语言,注意依赖管理")
|
||||||
|
elif len(self.stats['by_extension']) == 1:
|
||||||
|
print(" - 单一语言项目,结构清晰")
|
||||||
|
|
||||||
|
if self.stats['classes'] > 0:
|
||||||
|
avg_methods_per_class = self.stats['functions'] / max(self.stats['classes'], 1)
|
||||||
|
if avg_methods_per_class > 20:
|
||||||
|
print(" - 类的职责可能过重,考虑拆分类")
|
||||||
|
|
||||||
|
if health_score >= 80:
|
||||||
|
print(" - ✅ 代码质量良好,继续保持")
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("=" * 60)
|
||||||
|
print("代码统计完成")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='代码统计器 - 分析代码库统计信息',
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
epilog="""
|
||||||
|
示例:
|
||||||
|
python3 code-stats.py . # 分析当前目录
|
||||||
|
python3 code-stats.py /path/to/project # 分析指定项目
|
||||||
|
python3 code-stats.py . --json # JSON格式输出
|
||||||
|
python3 code-stats.py . --output report.md # 保存报告
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'project_path',
|
||||||
|
nargs='?',
|
||||||
|
default='.',
|
||||||
|
help='项目路径(默认:当前目录)'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--json',
|
||||||
|
action='store_true',
|
||||||
|
help='JSON格式输出'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-o', '--output',
|
||||||
|
help='输出报告到文件'
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if not os.path.exists(args.project_path):
|
||||||
|
print(f"❌ 错误: 路径不存在: {args.project_path}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
analyzer = CodeStats(args.project_path)
|
||||||
|
analyzer.analyze_directory(Path(args.project_path))
|
||||||
|
|
||||||
|
if args.json:
|
||||||
|
import json
|
||||||
|
print(json.dumps(analyzer.stats, indent=2))
|
||||||
|
elif args.output:
|
||||||
|
# 重定向输出到文件
|
||||||
|
with open(args.output, 'w', encoding='utf-8') as f:
|
||||||
|
old_stdout = sys.stdout
|
||||||
|
sys.stdout = f
|
||||||
|
try:
|
||||||
|
analyzer.print_report()
|
||||||
|
finally:
|
||||||
|
sys.stdout = old_stdout
|
||||||
|
print(f"✅ 报告已保存: {args.output}")
|
||||||
|
else:
|
||||||
|
analyzer.print_report()
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
90
skills/toolkit/python/analysis/dependency-analyzer.meta.yml
Normal file
90
skills/toolkit/python/analysis/dependency-analyzer.meta.yml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
tool_id: PY-DEPENDENCY-ANALYZER-001
|
||||||
|
tool_name: "依赖关系分析器"
|
||||||
|
|
||||||
|
基本信息:
|
||||||
|
语言: python
|
||||||
|
文件: dependency-analyzer.py
|
||||||
|
复杂度: level-3
|
||||||
|
创建日期: 2025-11-14
|
||||||
|
作者: CodeConscious
|
||||||
|
|
||||||
|
用途分类:
|
||||||
|
- CODE # 代码分析
|
||||||
|
- DATA # 数据提取
|
||||||
|
|
||||||
|
功能描述:
|
||||||
|
简介: "分析Python/JavaScript项目的依赖关系,生成可视化报告"
|
||||||
|
详细: |
|
||||||
|
支持功能:
|
||||||
|
- Python: 解析requirements.txt,提取依赖包和版本约束
|
||||||
|
- JavaScript: 解析package.json,提取dependencies/devDependencies
|
||||||
|
- 问题检测: 识别安全风险和已知漏洞
|
||||||
|
- 可视化报告: Markdown格式的人类可读报告
|
||||||
|
- JSON导出: 结构化数据,便于后续处理
|
||||||
|
|
||||||
|
使用场景:
|
||||||
|
- "分析新项目的依赖复杂度"
|
||||||
|
- "检查依赖安全风险"
|
||||||
|
- "生成项目依赖文档"
|
||||||
|
- "重构前评估依赖影响"
|
||||||
|
- "团队间共享依赖清单"
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
命令: "python3 dependency-analyzer.py [项目目录] [选项]"
|
||||||
|
参数:
|
||||||
|
project_dir: "项目目录路径(默认:当前目录)"
|
||||||
|
-o, --output: "输出JSON报告到指定文件"
|
||||||
|
-v, --verbose: "详细输出"
|
||||||
|
示例:
|
||||||
|
- "分析当前目录: python3 dependency-analyzer.py"
|
||||||
|
- "分析指定项目: python3 dependency-analyzer.py /path/to/project"
|
||||||
|
- "保存JSON报告: python3 dependency-analyzer.py . -o report.json"
|
||||||
|
- "详细输出: python3 dependency-analyzer.py -v"
|
||||||
|
|
||||||
|
依赖要求:
|
||||||
|
python版本: ">=3.8"
|
||||||
|
依赖包: # 无第三方依赖,只使用标准库
|
||||||
|
- json: "标准库"
|
||||||
|
- argparse: "标准库"
|
||||||
|
- pathlib: "标准库"
|
||||||
|
- typing: "标准库"
|
||||||
|
|
||||||
|
输入输出:
|
||||||
|
输入:
|
||||||
|
- requirements.txt: "Python依赖列表"
|
||||||
|
- package.json: "Node.js依赖配置"
|
||||||
|
输出:
|
||||||
|
- stdout: "Markdown格式的可视化报告"
|
||||||
|
- JSON文件: "结构化数据"
|
||||||
|
|
||||||
|
上次使用:
|
||||||
|
时间: 2025-11-14 10:30:00
|
||||||
|
用途: "分析ai-runtime项目依赖"
|
||||||
|
结果: |
|
||||||
|
发现项目使用Node.js + Python混合技术栈
|
||||||
|
识别出3个潜在安全风险
|
||||||
|
生成了详细的依赖报告
|
||||||
|
满意度: 0.92
|
||||||
|
|
||||||
|
相关工具:
|
||||||
|
- 前置工具: 无
|
||||||
|
- 互补工具:
|
||||||
|
- toolkit/python/analysis/analyze_logs.py(日志分析)
|
||||||
|
- toolkit/python/report/generate-report.py(报告生成)
|
||||||
|
- 替代工具:
|
||||||
|
- npm audit(仅JS)
|
||||||
|
- pip check(仅Python)
|
||||||
|
|
||||||
|
维护记录:
|
||||||
|
2025-11-14:
|
||||||
|
- 初始创建
|
||||||
|
- 支持Python requirements.txt解析
|
||||||
|
- 支持Node.js package.json解析
|
||||||
|
- 实现JSON和Markdown输出
|
||||||
|
2025-11-15:
|
||||||
|
- 添加安全问题检查(常见漏洞)
|
||||||
|
- 优化报告格式
|
||||||
|
TODO:
|
||||||
|
- 支持Go mod分析
|
||||||
|
- 支持Rust Cargo.toml分析
|
||||||
|
- 添加依赖图可视化(Graphviz)
|
||||||
218
skills/toolkit/python/analysis/dependency-analyzer.py
Normal file
218
skills/toolkit/python/analysis/dependency-analyzer.py
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
依赖关系分析器
|
||||||
|
分析Python/JavaScript项目的依赖关系,生成可视化报告
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, List, Set, Any
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
class DependencyAnalyzer:
|
||||||
|
def __init__(self, project_root: Path):
|
||||||
|
self.root = project_root
|
||||||
|
self.dependencies: Dict[str, Any] = {}
|
||||||
|
self.issues: List[str] = []
|
||||||
|
|
||||||
|
def analyze_python(self) -> Dict[str, Any]:
|
||||||
|
"""分析Python项目依赖"""
|
||||||
|
try:
|
||||||
|
if not (self.root / "requirements.txt").exists():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"language": "python",
|
||||||
|
"dependencies": [],
|
||||||
|
"issues": []
|
||||||
|
}
|
||||||
|
|
||||||
|
# 读取requirements.txt
|
||||||
|
req_file = self.root / "requirements.txt"
|
||||||
|
lines = req_file.read_text().splitlines()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith("#"):
|
||||||
|
# 简单解析:django>=3.0, pandas==1.5.0
|
||||||
|
if "==" in line:
|
||||||
|
name, version = line.split("==", 1)
|
||||||
|
result["dependencies"].append({
|
||||||
|
"name": name,
|
||||||
|
"constraint": "==",
|
||||||
|
"version": version,
|
||||||
|
"type": "exact"
|
||||||
|
})
|
||||||
|
elif ">=" in line:
|
||||||
|
name, version = line.split(">=", 1)
|
||||||
|
result["dependencies"].append({
|
||||||
|
"name": name,
|
||||||
|
"constraint": ">=",
|
||||||
|
"version": version,
|
||||||
|
"type": "minimum"
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
result["dependencies"].append({
|
||||||
|
"name": line,
|
||||||
|
"constraint": None,
|
||||||
|
"version": None,
|
||||||
|
"type": "any"
|
||||||
|
})
|
||||||
|
|
||||||
|
# 检查常见安全问题
|
||||||
|
for dep in result["dependencies"]:
|
||||||
|
name = dep["name"].lower()
|
||||||
|
if name in ["django", "flask"]:
|
||||||
|
result["issues"].append(f"⚠️ Web框架: {name},建议检查是否为最新版本")
|
||||||
|
if name == "requests":
|
||||||
|
result["issues"].append(f"ℹ️ HTTP库: {name},考虑使用内置的httpx")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"language": "python",
|
||||||
|
"error": str(e),
|
||||||
|
"dependencies": []
|
||||||
|
}
|
||||||
|
|
||||||
|
def analyze_javascript(self) -> Dict[str, Any]:
|
||||||
|
"""分析JavaScript/Node.js项目依赖"""
|
||||||
|
try:
|
||||||
|
if not (self.root / "package.json").exists():
|
||||||
|
return {}
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"language": "javascript",
|
||||||
|
"dependencies": [],
|
||||||
|
"issues": []
|
||||||
|
}
|
||||||
|
|
||||||
|
# 读取package.json
|
||||||
|
package_file = self.root / "package.json"
|
||||||
|
package = json.loads(package_file.read_text())
|
||||||
|
|
||||||
|
# 合并dependencies和devDependencies
|
||||||
|
all_deps = {}
|
||||||
|
all_deps.update(package.get("dependencies", {}))
|
||||||
|
all_deps.update(package.get("devDependencies", {}))
|
||||||
|
|
||||||
|
for name, version in all_deps.items():
|
||||||
|
result["dependencies"].append({
|
||||||
|
"name": name,
|
||||||
|
"version": version,
|
||||||
|
"type": "exact" if version.startswith("^") or version.startswith("~") else "range"
|
||||||
|
})
|
||||||
|
|
||||||
|
# 检查常见安全问题
|
||||||
|
for dep in result["dependencies"]:
|
||||||
|
name = dep["name"].lower()
|
||||||
|
if name == "lodash":
|
||||||
|
result["issues"].append(f"⚠️ lodash有已知漏洞,建议使用原生JS方法")
|
||||||
|
if name == "express":
|
||||||
|
result["issues"].append(f"⚠️ Express: {name},建议使用helmet增强安全")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"language": "javascript",
|
||||||
|
"error": str(e),
|
||||||
|
"dependencies": []
|
||||||
|
}
|
||||||
|
|
||||||
|
def visualize_report(self, results: Dict[str, Any]):
|
||||||
|
"""生成可视化报告"""
|
||||||
|
print("# 📦 依赖关系分析报告")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
for lang, data in results.items():
|
||||||
|
if not data or "error" in data:
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"\n## {lang.upper()} 项目")
|
||||||
|
print("-" * 60)
|
||||||
|
|
||||||
|
deps = data.get("dependencies", [])
|
||||||
|
print(f"\n依赖总数: {len(deps)}")
|
||||||
|
|
||||||
|
if deps:
|
||||||
|
print("\n### 依赖清单")
|
||||||
|
print("| 包名 | 版本 | 类型 |")
|
||||||
|
print("|------|------|------|")
|
||||||
|
for dep in deps[:20]: # 只显示前20个
|
||||||
|
name = dep.get("name", "unknown")
|
||||||
|
version = dep.get("version", "latest")
|
||||||
|
dep_type = dep.get("type", "unknown")
|
||||||
|
print(f"| {name} | {version} | {dep_type} |")
|
||||||
|
|
||||||
|
if len(deps) > 20:
|
||||||
|
print(f"| ... | ... | ... |")
|
||||||
|
print(f"| <font color='gray'>共 {len(deps)} 个依赖</font> | | |")
|
||||||
|
|
||||||
|
issues = data.get("issues", [])
|
||||||
|
if issues:
|
||||||
|
print("\n### ⚠️ 发现的问题")
|
||||||
|
for issue in issues:
|
||||||
|
print(f"- {issue}")
|
||||||
|
else:
|
||||||
|
print("\n### ✅ 未发现明显问题")
|
||||||
|
|
||||||
|
def save_json(self, results: Dict[str, Any], output_path: Path):
|
||||||
|
"""保存JSON格式的详细报告"""
|
||||||
|
output_path.write_text(json.dumps(results, indent=2, ensure_ascii=False))
|
||||||
|
print(f"\n💾 JSON报告已保存: {output_path}")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description="依赖关系分析器")
|
||||||
|
parser.add_argument("project_dir", nargs="?", default=".", help="项目目录路径")
|
||||||
|
parser.add_argument("-o", "--output", help="输出JSON报告到文件")
|
||||||
|
parser.add_argument("-v", "--verbose", action="store_true", help="详细输出")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
project_path = Path(args.project_dir)
|
||||||
|
if not project_path.exists():
|
||||||
|
print(f"❌ 错误: 目录不存在: {project_path}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("🔍 分析项目依赖关系...")
|
||||||
|
print(f"项目路径: {project_path.absolute()}")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
analyzer = DependencyAnalyzer(project_path)
|
||||||
|
|
||||||
|
# 分析Python
|
||||||
|
python_results = analyzer.analyze_python()
|
||||||
|
|
||||||
|
# 分析JavaScript
|
||||||
|
js_results = analyzer.analyze_javascript()
|
||||||
|
|
||||||
|
# 生成报告
|
||||||
|
all_results = {
|
||||||
|
"python": python_results,
|
||||||
|
"javascript": js_results,
|
||||||
|
"metadata": {
|
||||||
|
"analyzed_at": "2025-11-14T10:00:00Z",
|
||||||
|
"tool_version": "1.0.0",
|
||||||
|
"analyzer": "CodeConscious"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
analyzer.visualize_report(all_results)
|
||||||
|
|
||||||
|
# 保存JSON报告
|
||||||
|
if args.output:
|
||||||
|
output_path = Path(args.output)
|
||||||
|
analyzer.save_json(all_results, output_path)
|
||||||
|
else:
|
||||||
|
# 默认保存到报告目录
|
||||||
|
report_dir = project_path / "reports"
|
||||||
|
report_dir.mkdir(exist_ok=True)
|
||||||
|
analyzer.save_json(all_results, report_dir / "dependency-report.json")
|
||||||
|
|
||||||
|
print("\n✅ 分析完成!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
187
skills/toolkit/references/core/toolkit-philosophy.md
Normal file
187
skills/toolkit/references/core/toolkit-philosophy.md
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
# 工具装备系统设计哲学
|
||||||
|
|
||||||
|
## 核心理念
|
||||||
|
|
||||||
|
### 整合优于创造 (Integration over Creation)
|
||||||
|
|
||||||
|
**为什么选择整合?**
|
||||||
|
1. **成熟稳定**: 经过数千小时的社区打磨和实际使用验证
|
||||||
|
2. **社区支持**: 庞大的用户群、完善的文档和活跃的维护
|
||||||
|
3. **专注专业**: 每个工具只做一件事,并做到极致
|
||||||
|
4. **认知卸载**: 无需重复实现,直接使用成熟解决方案
|
||||||
|
|
||||||
|
**实际案例**:
|
||||||
|
- 使用 `ripgrep` 而非重新实现代码搜索
|
||||||
|
- 使用 `jq` 而非创建自定义JSON处理器
|
||||||
|
- 使用 `fzf` 而非开发模糊查找界面
|
||||||
|
|
||||||
|
### 元数据驱动架构
|
||||||
|
|
||||||
|
**设计原则**:
|
||||||
|
- **声明式配置**: 通过 `.meta.yml` 文件描述工具能力
|
||||||
|
- **自动发现**: 基于文件系统结构自动注册工具
|
||||||
|
- **类型安全**: 明确的工具分类、版本和依赖管理
|
||||||
|
|
||||||
|
**元数据标准**:
|
||||||
|
```yaml
|
||||||
|
name: SERVICE-CHECK-001
|
||||||
|
description: HTTP服务健康检查工具
|
||||||
|
language: bash
|
||||||
|
category: MONITOR
|
||||||
|
complexity: level-2
|
||||||
|
dependencies: [curl]
|
||||||
|
parameters:
|
||||||
|
- name: url
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
description: 要检查的服务URL
|
||||||
|
```
|
||||||
|
|
||||||
|
### 渐进式披露设计
|
||||||
|
|
||||||
|
受 anthropics/skills 项目启发,采用分层文档结构:
|
||||||
|
|
||||||
|
1. **SKILL.md**: 核心入口,包含基本概念和快速开始
|
||||||
|
2. **references/**: 详细参考文档,按需加载
|
||||||
|
3. **README.md**: 索引和导航,指向具体文档
|
||||||
|
|
||||||
|
## 工具分类体系
|
||||||
|
|
||||||
|
### 复杂度分层
|
||||||
|
|
||||||
|
| 级别 | 代码行数 | 特点 | 示例 |
|
||||||
|
|-----|---------|------|------|
|
||||||
|
| Level-1 | 1-5行 | 简单命令封装 | 基础系统调用 |
|
||||||
|
| Level-2 | 6-20行 | 参数处理和错误处理 | 服务检查、文件操作 |
|
||||||
|
| Level-3 | 21-50行 | 复杂逻辑和数据处理 | 依赖分析、报告生成 |
|
||||||
|
| Level-4 | 50+行 | 完整应用程序 | API测试框架 |
|
||||||
|
|
||||||
|
### 功能分类
|
||||||
|
|
||||||
|
| 分类 | 用途 | 示例工具 |
|
||||||
|
|-----|-----|---------|
|
||||||
|
| **CODE** | 代码处理和分析 | 依赖分析器、代码统计器 |
|
||||||
|
| **DATA** | 数据处理和转换 | 依赖分析器、JSON处理器 |
|
||||||
|
| **TEST** | 测试和验证 | API测试工具、数据验证器 |
|
||||||
|
| **BUILD** | 构建和部署 | 构建脚本、部署检查器 |
|
||||||
|
| **MONITOR** | 监控和诊断 | 服务检查器、日志分析器 |
|
||||||
|
| **DOC** | 文档处理 | 文档生成器、格式转换器 |
|
||||||
|
|
||||||
|
### 语言选择策略
|
||||||
|
|
||||||
|
**Bash工具**:
|
||||||
|
- 系统级操作(文件、进程、网络)
|
||||||
|
- 轻量级文本处理
|
||||||
|
- 调用现有CLI工具的胶水代码
|
||||||
|
|
||||||
|
**Python工具**:
|
||||||
|
- 复杂数据处理和分析
|
||||||
|
- 需要丰富标准库的功能
|
||||||
|
- 跨平台兼容性要求
|
||||||
|
|
||||||
|
**Node.js工具**:
|
||||||
|
- Web/API相关操作
|
||||||
|
- 需要npm生态系统的工具
|
||||||
|
- 现代JavaScript开发栈集成
|
||||||
|
|
||||||
|
## 开发工作流
|
||||||
|
|
||||||
|
### 工具创建流程
|
||||||
|
|
||||||
|
1. **需求识别**: 识别重复3次以上的任务
|
||||||
|
2. **复杂度评估**: 确定合适的复杂度级别
|
||||||
|
3. **语言选择**: 根据任务特点选择编程语言
|
||||||
|
4. **模板应用**: 使用相应模板快速创建
|
||||||
|
5. **元数据编写**: 创建 `.meta.yml` 描述文件
|
||||||
|
6. **测试验证**: 通过 `discover-toolkit.py` 测试
|
||||||
|
7. **文档编写**: 添加使用说明和示例
|
||||||
|
|
||||||
|
### 质量保证
|
||||||
|
|
||||||
|
**代码质量**:
|
||||||
|
- 错误处理和边界情况覆盖
|
||||||
|
- 输入验证和参数检查
|
||||||
|
- 清晰的错误消息和退出码
|
||||||
|
|
||||||
|
**文档质量**:
|
||||||
|
- 完整的参数说明
|
||||||
|
- 实际使用示例
|
||||||
|
- 常见问题和故障排除
|
||||||
|
|
||||||
|
**集成质量**:
|
||||||
|
- 正确的元数据格式
|
||||||
|
- 合理的依赖声明
|
||||||
|
- 向后兼容性保证
|
||||||
|
|
||||||
|
## 生态系统扩展
|
||||||
|
|
||||||
|
### 外部工具整合策略
|
||||||
|
|
||||||
|
**选择标准**:
|
||||||
|
- **社区活跃度**: GitHub stars、最近提交频率
|
||||||
|
- **跨平台支持**: 支持主流操作系统
|
||||||
|
- **许可证兼容**: MIT/BSD/Apache等宽松许可证
|
||||||
|
- **维护状态**: 积极维护,无重大安全问题
|
||||||
|
|
||||||
|
**整合深度**:
|
||||||
|
- **Level-1**: 简单命令别名和参数传递
|
||||||
|
- **Level-2**: 错误处理和输出格式化
|
||||||
|
- **Level-3**: 高级功能封装和定制选项
|
||||||
|
|
||||||
|
### 版本管理和兼容性
|
||||||
|
|
||||||
|
**语义版本**: 遵循 SemVer 规范
|
||||||
|
- **MAJOR**: 不兼容的API变更
|
||||||
|
- **MINOR**: 向后兼容的新功能
|
||||||
|
- **PATCH**: 向后兼容的bug修复
|
||||||
|
|
||||||
|
**兼容性保证**:
|
||||||
|
- 工具接口的向后兼容
|
||||||
|
- 元数据格式的稳定性
|
||||||
|
- 升级路径的明确说明
|
||||||
|
|
||||||
|
## 性能和效率
|
||||||
|
|
||||||
|
### 资源使用优化
|
||||||
|
|
||||||
|
**启动时间**: 工具应该在2秒内启动
|
||||||
|
**内存使用**: 避免不必要的内存占用
|
||||||
|
**磁盘I/O**: 合理使用缓存和临时文件
|
||||||
|
|
||||||
|
### 并发和并行
|
||||||
|
|
||||||
|
**设计考虑**:
|
||||||
|
- 工具是否支持并发执行
|
||||||
|
- 共享资源的正确处理
|
||||||
|
- 输出的线程安全性
|
||||||
|
|
||||||
|
**实现策略**:
|
||||||
|
- 无状态设计优先
|
||||||
|
- 显式的并发控制
|
||||||
|
- 资源锁的合理使用
|
||||||
|
|
||||||
|
## 监控和维护
|
||||||
|
|
||||||
|
### 健康检查
|
||||||
|
|
||||||
|
**自动监控**:
|
||||||
|
- 工具可用性检查
|
||||||
|
- 性能指标收集
|
||||||
|
- 错误率统计
|
||||||
|
|
||||||
|
**维护任务**:
|
||||||
|
- 定期更新外部工具
|
||||||
|
- 清理过时工具
|
||||||
|
- 优化性能瓶颈
|
||||||
|
|
||||||
|
### 演进策略
|
||||||
|
|
||||||
|
**持续改进**:
|
||||||
|
- 用户反馈收集和分析
|
||||||
|
- 性能指标监控
|
||||||
|
- 新需求和功能的评估
|
||||||
|
|
||||||
|
**弃用管理**:
|
||||||
|
- 明确的弃用时间表
|
||||||
|
- 迁移路径说明
|
||||||
|
- 向后兼容性保证
|
||||||
295
skills/toolkit/references/guides/quickstart.md
Normal file
295
skills/toolkit/references/guides/quickstart.md
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
# 工具装备系统快速开始指南
|
||||||
|
|
||||||
|
## 10分钟上手工具装备系统
|
||||||
|
|
||||||
|
### 前置条件
|
||||||
|
|
||||||
|
**系统要求**:
|
||||||
|
- Python 3.8+
|
||||||
|
- Bash shell
|
||||||
|
- 基本CLI工具(curl, grep, find等)
|
||||||
|
|
||||||
|
**推荐安装**:
|
||||||
|
```bash
|
||||||
|
# macOS
|
||||||
|
brew install fzf eza zoxide fd bat ripgrep jq
|
||||||
|
|
||||||
|
# Ubuntu/Debian
|
||||||
|
sudo apt-get install fzf ripgrep jq bat
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第一步:环境检查
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 进入工具装备目录
|
||||||
|
cd .ai-runtime/toolkit
|
||||||
|
|
||||||
|
# 检查Python环境
|
||||||
|
python3 --version
|
||||||
|
|
||||||
|
# 检查discover-toolkit工具
|
||||||
|
python3 discover-toolkit.py --help
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第二步:查看可用工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看所有工具概览
|
||||||
|
python3 discover-toolkit.py list
|
||||||
|
|
||||||
|
# 查看内部工具
|
||||||
|
python3 discover-toolkit.py list --internal
|
||||||
|
|
||||||
|
# 查看外部工具
|
||||||
|
python3 discover-toolkit.py list --external
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第三步:使用工具
|
||||||
|
|
||||||
|
#### 基础用法
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看工具详情
|
||||||
|
python3 discover-toolkit.py show SERVICE-CHECK-001
|
||||||
|
|
||||||
|
# 运行服务健康检查
|
||||||
|
python3 discover-toolkit.py run service-check http://localhost:3000
|
||||||
|
|
||||||
|
# 运行依赖分析
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o deps.json
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 实际场景示例
|
||||||
|
|
||||||
|
**场景1: 项目代码分析**
|
||||||
|
```bash
|
||||||
|
# 分析当前项目的依赖关系
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o project-deps.json
|
||||||
|
|
||||||
|
# 查看结果
|
||||||
|
cat project-deps.json | jq '.summary'
|
||||||
|
```
|
||||||
|
|
||||||
|
**场景2: 日志文件分析**
|
||||||
|
```bash
|
||||||
|
# 分析应用日志,查找错误
|
||||||
|
python3 discover-toolkit.py run log-analyzer /var/log/app.log --level ERROR --since "1 hour ago"
|
||||||
|
|
||||||
|
# 生成错误统计报告
|
||||||
|
python3 discover-toolkit.py run log-analyzer /var/log/app.log --stats --output error-stats.json
|
||||||
|
```
|
||||||
|
|
||||||
|
**场景3: API测试**
|
||||||
|
```bash
|
||||||
|
# 测试REST API端点
|
||||||
|
python3 discover-toolkit.py run api-test http://api.example.com/users --method GET
|
||||||
|
|
||||||
|
# 测试POST请求
|
||||||
|
python3 discover-toolkit.py run api-test http://api.example.com/users \
|
||||||
|
--method POST \
|
||||||
|
--data '{"name": "test user"}' \
|
||||||
|
--headers "Content-Type: application/json"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第四步:外部工具集成
|
||||||
|
|
||||||
|
#### 安装检查
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 检查外部工具安装状态
|
||||||
|
python3 discover-toolkit.py check-external
|
||||||
|
|
||||||
|
# 安装缺失的工具(macOS示例)
|
||||||
|
brew install fzf eza bat ripgrep
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 实际使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用ripgrep搜索代码(比grep快10倍以上)
|
||||||
|
rg "TODO|FIXME" src/
|
||||||
|
|
||||||
|
# 使用fzf进行交互式选择
|
||||||
|
find src/ -name "*.py" | fzf
|
||||||
|
|
||||||
|
# 使用bat查看带语法高亮的代码
|
||||||
|
bat src/main.py
|
||||||
|
|
||||||
|
# 使用eza美化文件列表
|
||||||
|
eza -la src/
|
||||||
|
|
||||||
|
# 使用jq处理JSON数据
|
||||||
|
cat package.json | jq '.dependencies'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第五步:创建自定义工具
|
||||||
|
|
||||||
|
#### 快速创建Bash工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用模板创建新工具
|
||||||
|
cp templates/tool-template.sh bash/custom/my-tool.sh
|
||||||
|
cp templates/meta-template.yml bash/custom/my-tool.meta.yml
|
||||||
|
|
||||||
|
# 编辑工具脚本
|
||||||
|
nano bash/custom/my-tool.sh
|
||||||
|
|
||||||
|
# 编辑元数据
|
||||||
|
nano bash/custom/my-tool.meta.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 元数据示例
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: MY-TOOL-001
|
||||||
|
description: 我的自定义工具
|
||||||
|
language: bash
|
||||||
|
category: UTILITY
|
||||||
|
complexity: level-2
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
- name: input
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
description: 输入文件路径
|
||||||
|
|
||||||
|
- name: output
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
description: 输出文件路径(可选)
|
||||||
|
|
||||||
|
examples:
|
||||||
|
- description: 基本用法
|
||||||
|
command: python3 discover-toolkit.py run my-tool input.txt
|
||||||
|
|
||||||
|
- description: 指定输出
|
||||||
|
command: python3 discover-toolkit.py run my-tool input.txt -o output.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试新工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 验证工具注册
|
||||||
|
python3 discover-toolkit.py show MY-TOOL-001
|
||||||
|
|
||||||
|
# 测试运行
|
||||||
|
python3 discover-toolkit.py run my-tool test-input.txt
|
||||||
|
|
||||||
|
# 查看帮助
|
||||||
|
python3 discover-toolkit.py help MY-TOOL-001
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第六步:高级用法
|
||||||
|
|
||||||
|
#### 批量操作
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 批量检查多个服务
|
||||||
|
echo "http://api1.example.com
|
||||||
|
http://api2.example.com
|
||||||
|
http://db.example.com:5432" | \
|
||||||
|
while read url; do
|
||||||
|
echo "Checking $url..."
|
||||||
|
python3 discover-toolkit.py run service-check "$url"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 脚本集成
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
# CI/CD 集成脚本示例
|
||||||
|
|
||||||
|
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
TOOLKIT_DIR="$PROJECT_ROOT/.ai-runtime/toolkit"
|
||||||
|
|
||||||
|
cd "$TOOLKIT_DIR"
|
||||||
|
|
||||||
|
# 代码质量检查
|
||||||
|
echo "=== 代码质量检查 ==="
|
||||||
|
python3 discover-toolkit.py run code-stats src/ --format json > code-stats.json
|
||||||
|
|
||||||
|
# 依赖安全检查
|
||||||
|
echo "=== 依赖安全检查 ==="
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . --security-check > security-report.json
|
||||||
|
|
||||||
|
# 生成综合报告
|
||||||
|
echo "=== 生成报告 ==="
|
||||||
|
python3 discover-toolkit.py run report-generator \
|
||||||
|
--code-stats code-stats.json \
|
||||||
|
--security security-report.json \
|
||||||
|
--output ci-report.html
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 监控和告警
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 定期健康检查
|
||||||
|
while true; do
|
||||||
|
echo "$(date): Health check..."
|
||||||
|
python3 discover-toolkit.py run service-check http://localhost:3000 > /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Service down! Sending alert..."
|
||||||
|
# 发送告警逻辑
|
||||||
|
fi
|
||||||
|
sleep 300 # 5分钟检查一次
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
## 故障排除
|
||||||
|
|
||||||
|
### 常见问题
|
||||||
|
|
||||||
|
**工具未找到**
|
||||||
|
```bash
|
||||||
|
# 检查工具是否存在
|
||||||
|
python3 discover-toolkit.py list | grep <tool-name>
|
||||||
|
|
||||||
|
# 检查元数据文件
|
||||||
|
find . -name "*.meta.yml" | xargs grep <tool-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
**运行时错误**
|
||||||
|
```bash
|
||||||
|
# 查看详细错误信息
|
||||||
|
python3 discover-toolkit.py run <tool-name> --verbose
|
||||||
|
|
||||||
|
# 检查依赖
|
||||||
|
python3 discover-toolkit.py show <tool-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
**外部工具不可用**
|
||||||
|
```bash
|
||||||
|
# 检查安装
|
||||||
|
which <external-tool>
|
||||||
|
|
||||||
|
# 重新检测
|
||||||
|
python3 discover-toolkit.py check-external
|
||||||
|
```
|
||||||
|
|
||||||
|
### 获取帮助
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 通用帮助
|
||||||
|
python3 discover-toolkit.py --help
|
||||||
|
|
||||||
|
# 工具特定帮助
|
||||||
|
python3 discover-toolkit.py help <tool-name>
|
||||||
|
|
||||||
|
# 搜索相关工具
|
||||||
|
python3 discover-toolkit.py search <keyword>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 下一步
|
||||||
|
|
||||||
|
完成这个快速开始指南后,你可以:
|
||||||
|
|
||||||
|
1. **深入学习**: 查看 [references/internal-tools.md](internal-tools.md) 了解所有内部工具
|
||||||
|
2. **扩展技能**: 阅读 [references/external-tools.md](external-tools.md) 掌握更多CLI工具
|
||||||
|
3. **开发工具**: 参考 [references/creating-tools.md](creating-tools.md) 创建自己的工具
|
||||||
|
4. **优化工作流**: 将工具集成到你的开发和部署流程中
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*这个指南应该在10分钟内完成。如果遇到问题,请查看详细文档或寻求帮助。*
|
||||||
91
skills/toolkit/registry.md
Normal file
91
skills/toolkit/registry.md
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
---
|
||||||
|
name: toolkit-registry
|
||||||
|
description: AI Runtime工具装备系统主索引和注册表
|
||||||
|
category: registry
|
||||||
|
version: 2.0.0
|
||||||
|
last_updated: 2025-11-14
|
||||||
|
---
|
||||||
|
|
||||||
|
# AI Runtime 工具装备系统 - 主索引
|
||||||
|
|
||||||
|
[](SKILL.md)
|
||||||
|
|
||||||
|
## 快速导航
|
||||||
|
|
||||||
|
### 🎯 核心功能
|
||||||
|
- **8个内部工具**: Python/Bash/Node.js专业工具
|
||||||
|
- **10+个外部工具**: 深度整合的成熟CLI工具
|
||||||
|
- **智能发现**: 自动工具检测和元数据管理
|
||||||
|
|
||||||
|
### 🚀 快速开始
|
||||||
|
新手从这里开始,10分钟上手:
|
||||||
|
**[快速开始指南](references/guides/quickstart.md)**
|
||||||
|
|
||||||
|
### 🛠️ 工具分类
|
||||||
|
|
||||||
|
#### 内部工具(自主创建)
|
||||||
|
按语言分类的专业工具:
|
||||||
|
|
||||||
|
**[Python工具详解](../docs/references/internal-tools.md)**
|
||||||
|
- 依赖分析器、代码统计器、图形生成器、报告生成器
|
||||||
|
|
||||||
|
**[Bash工具详解](../docs/references/internal-tools.md)**
|
||||||
|
- 服务健康检查器、日志分析器、磁盘健康检查器
|
||||||
|
|
||||||
|
**[Node.js工具详解](../docs/references/internal-tools.md)**
|
||||||
|
- API测试工具
|
||||||
|
|
||||||
|
#### 外部工具(深度整合)
|
||||||
|
推荐的CLI工具生态:
|
||||||
|
|
||||||
|
**[外部工具详解](../docs/references/external-tools.md)**
|
||||||
|
- fzf、eza、bat、ripgrep、zoxide、jq等
|
||||||
|
|
||||||
|
### 📖 开发指南
|
||||||
|
|
||||||
|
#### 工具开发
|
||||||
|
**[创建新工具](../docs/guides/creating-tools.md)**
|
||||||
|
- 工具开发流程和最佳实践
|
||||||
|
|
||||||
|
#### 外部整合
|
||||||
|
**[外部工具整合](../docs/guides/external-integration.md)**
|
||||||
|
- 如何整合第三方CLI工具
|
||||||
|
|
||||||
|
### 📚 设计理念
|
||||||
|
**[工具哲学](references/core/toolkit-philosophy.md)**
|
||||||
|
- 设计原则、分类体系和发展策略
|
||||||
|
|
||||||
|
## 基本用法
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 进入工具装备目录
|
||||||
|
cd .ai-runtime/toolkit
|
||||||
|
|
||||||
|
# 查看所有工具
|
||||||
|
python3 discover-toolkit.py list
|
||||||
|
|
||||||
|
# 查看工具详情
|
||||||
|
python3 discover-toolkit.py show SERVICE-CHECK-001
|
||||||
|
|
||||||
|
# 运行工具
|
||||||
|
python3 discover-toolkit.py run dependency-analyzer . -o deps.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## 系统状态
|
||||||
|
|
||||||
|
**版本**: 2.0.0
|
||||||
|
**内部工具**: 8个
|
||||||
|
**外部工具**: 10+个
|
||||||
|
**文档**: 6个核心文档
|
||||||
|
**最后更新**: 2025-11-14
|
||||||
|
|
||||||
|
## 详细文档
|
||||||
|
|
||||||
|
**[SKILL.md](SKILL.md)** - 工具装备系统核心功能
|
||||||
|
**[EXTERNAL-TOOLS-SKILL.md](EXTERNAL-TOOLS-SKILL.md)** - 外部工具专项技能
|
||||||
|
**[references/core/toolkit-philosophy.md](references/core/toolkit-philosophy.md)** - 工具哲学和设计理念
|
||||||
|
**[references/guides/quickstart.md](references/guides/quickstart.md)** - 快速开始指南
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*基于 anthropics/skills 渐进式披露架构设计 | 整合优于创造*
|
||||||
Reference in New Issue
Block a user