refactor: 将 skill 文档移动到项目根目录

- 将 skill/SKILL.md 移动至根目录 SKILL.md
- 更新 build.py 中的路径配置
- 更新 openspec/config.yaml 中的文档位置说明
This commit is contained in:
2026-03-09 10:05:40 +08:00
parent 58093e0877
commit b2fb418a06
3 changed files with 3 additions and 3 deletions

156
SKILL.md Normal file
View File

@@ -0,0 +1,156 @@
---
name: lyxy-document-reader
description: 统一文档解析工具 - 将 DOCX、XLSX、PPTX、PDF、HTML/URL 转换为 Markdown。支持全文输出、字数统计、行数统计、标题提取、章节提取、正则搜索。当用户要求"读取/解析/打开文档"、上传 .docx/.xlsx/.pptx/.pdf/.html 文件、或提供 URL 时使用。
license: MIT
metadata:
version: "1.0"
author: lyxy
compatibility: Requires Python 3.11+. 优先使用 lyxy-runner-python skill 执行(自动管理依赖)。回退到主机 Python 时需手动安装依赖DOCX(docling unstructured markitdown pypandoc-binary python-docx markdownify chardet) / XLSX(docling unstructured markitdown pandas tabulate chardet) / PPTX(docling unstructured markitdown python-pptx markdownify chardet) / PDF(docling unstructured unstructured-paddleocr markitdown pypdf markdownify chardet) / HTML(trafilatura domscribe markitdown html2text beautifulsoup4 httpx chardet) / HTTP增强(pyppeteer selenium)
---
# 统一文档解析 Skill
将 DOCX、XLSX、PPTX、PDF、HTML 文件或 URL 网页内容解析为 Markdown 格式,支持多种查询模式。
## Purpose
**统一入口**:使用 `scripts/lyxy_document_reader.py` 作为统一的命令行入口,自动识别文件类型并执行解析。
**双路径执行**:此 skill 必须优先使用 **lyxy-runner-python skill** 执行脚本,该 skill 会自动管理 uv 隔离环境和依赖。当 lyxy-runner-python 不可用时,回退到主机 Python 环境执行。
**支持的文档类型**
- **DOCX**Word 文档
- **XLSX**Excel 表格
- **PPTX**PowerPoint 演示文稿
- **PDF**PDF 文档(支持 OCR
- **HTML/URL**HTML 文件或网页地址
## When to Use
任何需要读取或解析 Office 文档、PDF、HTML 文件、URL 网页内容的任务都应使用此 skill。
### 典型场景
- **文档转换**:将各类文档转换为可读的 Markdown 文本
- **文档元数据**:获取文档的字数、行数等信息
- **标题分析**:提取文档的标题结构
- **章节提取**:提取特定章节的内容
- **内容搜索**:在文档中搜索关键词或正则模式
### 触发词
- **中文**"读取/解析/打开 文档/Word/Excel/PPT/PDF/网页"
- **英文**"read/parse/extract document/docx/xlsx/pptx/pdf/html"
- **文件扩展名**`.docx``.xlsx``.pptx``.pdf``.html``.htm`
- **URL 模式**`http://``https://`
## Quick Reference
| 参数 | 说明 |
|------|------|
| (无参数) | 输出完整 Markdown 内容 |
| `-c` / `--count` | 字数统计 |
| `-l` / `--lines` | 行数统计 |
| `-t` / `--titles` | 提取所有标题1-6级 |
| `-tc <name>` | 提取指定标题的章节内容 |
| `-s <pattern>` | 正则表达式搜索 |
| `-n <num>` / `--context <num>` | 与 `-s` 配合指定上下文行数默认2 |
## Workflow
1. **检测执行环境**
- 优先检测 **lyxy-runner-python skill** 是否可用
- 可用 → 使用 uv 隔离环境执行
- 不可用 → 回退到主机 Python 环境
2. **识别文件类型**
- 根据文件扩展名自动选择对应的解析器
- URL 自动识别为 HTML/网页类型
3. **执行解析**
- 按优先级尝试多个解析器,直到成功
- DOCXdocling → unstructured → pypandoc → MarkItDown → python-docx → XML
- XLSXdocling → unstructured → MarkItDown → pandas → XML
- PPTXdocling → unstructured → MarkItDown → python-pptx → XML
- PDFdocling OCR → unstructured OCR → docling → unstructured → MarkItDown → pypdf
- HTMLtrafilatura → domscribe → MarkItDown → html2text
4. **输出结果**
- 返回 Markdown 格式内容或统计信息
### 基本语法
```bash
# 方式 1使用 lyxy-runner-python推荐
# lyxy-runner-python 会自动分析脚本依赖并使用 uv --with 安装
# AI 只需执行:
python scripts/lyxy_document_reader.py <文件路径或URL>
# 方式 2回退到主机 Python需要预先手动安装依赖
# 根据文档类型安装对应依赖后执行:
python scripts/lyxy_document_reader.py <文件路径或URL>
```
### 使用示例
```bash
# 读取 Word 文档
python scripts/lyxy_document_reader.py document.docx
# 解析网页内容
python scripts/lyxy_document_reader.py https://example.com
# 统计字数
python scripts/lyxy_document_reader.py document.docx -c
# 提取所有标题
python scripts/lyxy_document_reader.py document.docx -t
# 提取指定章节
python scripts/lyxy_document_reader.py document.docx -tc "第三章"
# 搜索内容
python scripts/lyxy_document_reader.py document.docx -s "关键词"
# 正则搜索
python scripts/lyxy_document_reader.py document.docx -s "\d{4}-\d{2}-\d{2}"
# 指定上下文行数
python scripts/lyxy_document_reader.py document.docx -s "关键词" -n 5
```
### 主机 Python 环境依赖安装
当 lyxy-runner-python 不可用时,需要根据文档类型手动安装依赖:
```bash
# DOCX 文档
pip install docling unstructured markitdown pypandoc-binary python-docx markdownify chardet
# XLSX 表格
pip install docling unstructured markitdown pandas tabulate chardet
# PPTX 演示文稿
pip install docling unstructured markitdown python-pptx markdownify chardet
# PDF 文档
pip install docling unstructured unstructured-paddleocr markitdown pypdf markdownify chardet
# HTML/URL 网页
pip install trafilatura domscribe markitdown html2text beautifulsoup4 httpx chardet
# 网页(需要 JS 渲染时,额外添加)
pip install pyppeteer selenium
# 安装所有文档类型支持
pip install docling unstructured unstructured-paddleocr markitdown pypandoc-binary python-docx python-pptx pandas tabulate pypdf markdownify trafilatura domscribe html2text beautifulsoup4 httpx pyppeteer selenium chardet
```
## 错误处理
| 错误信息 | 原因 | 解决 |
|---------|------|------|
| 错误: input_path 不能为空 | 未提供输入 | 提供 file_path 或 URL |
| 错误: 不支持的文件类型 | 无对应 reader | 检查文件扩展名 |
| 所有解析方法均失败 | 所有解析器失败 | 检查文件是否损坏 |
| 错误: 无效的正则表达式 | 正则语法错误 | 检查正则语法 |
| 错误: 未找到匹配 | 搜索无结果 | 检查搜索词或正则 |
| ModuleNotFoundError: No module named 'xxx' | 缺少依赖 | 使用 lyxy-runner-python 或 pip 安装对应依赖 |