# universal-file-processor

Adopt this skill: https://proskills.md/skills/other/lichaonetuser-universal-file-processor

Page: https://proskills.md/skills/other/lichaonetuser-universal-file-processor
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: SKILL.md
size: 10143
upstream: https://github.com/lichaonetuser/universal-file-processor/blob/HEAD/SKILL.md

````text
---
name: universal-file-processor
description: "大文件自动拆分处理技能 - 当文件超过模型处理能力时自动拆分并分批处理。AI可以自动调用此技能来处理大型Markdown文件、大型代码文件、批量数据集，以及优化长输出防止模型疲劳。"
homepage: "https://github.com/lichaonetuser/universal-file-processor"
metadata:
  {
    "openclaw":
      {
        "emoji": "🔄",
        "requires": { "bins": ["bash", "wc", "split", "cat", "sed", "awk"] },
        "install":
          [
            {
              "id": "download",
              "kind": "download",
              "url": "https://github.com/lichaonetuser/universal-file-processor/releases/latest/download/universal-file-processor.sh",
              "bins": ["universal-file-processor.sh"],
              "label": "Download universal-file-processor.sh",
            },
          ],
      },
  }
--- }

# Universal File Processor - 通用文件处理器

**Role / 角色**: OpenClaw Skill (OpenClaw技能)
**Version / 版本**: v1.0
**PM / PM**: lichaonetuser
**Category / 类别**: File Processing, Context Management, Output Optimization (文件处理、上下文管理、输出优化)

---

## 🔄 Overview / 概述

Universal File Processor是一个三合一的通用文件处理技能，整合了：
- ✅ **大文件输入处理**: 智能拆分大文件输入
- ✅ **大文件处理**: 分批处理大文件
- ✅ **防止输出疲劳**: 优化输出，避免模型疲劳

**核心功能**：
- 自动检测文件大小
- 智能拆分文件
- 分批处理
- 优化输出
- 结果整合

**适用场景**：
- 大型Markdown文件（>500行）
- 大型代码文件（>1000行）
- 长文档分析
- 批量数据处理
- 输出优化

---

## 🎯 Use When / 使用时机

**English**:
AI should first check the file size and line count by itself. Only when the AI determines that the file exceeds its processing capacity should it invoke this skill.

**中文**:
AI应该先自己检查文件大小和行数。只有当AI判断文件超过其处理能力时，才应该调用此技能。

**Correct Workflow / 正确流程**:

**English**:
```
User: "Analyze this file"
  ↓
AI: First checks file size and line count by itself
  ↓
AI: Determines if file is too large to process in one go
  ↓
If file is within limits:
  ↓
  AI: Processes file directly
  ↓
  AI: Returns results to user
  ↓
If file exceeds limits:
  ↓
  AI: Invokes universal-file-processor.sh
  ↓
Skill: Automatically checks file size
  ↓
Skill: Automatically splits file into parts
  ↓
AI: Processes each part sequentially
  ↓
AI: Merges results
  ↓
AI: Returns complete analysis to user
```

**中文**:
```
用户: "分析这个文件"
  ↓
AI: 先自己检查文件大小和行数
  ↓
AI: 判断文件是否太大无法一次性处理
  ↓
如果文件在限制内：
  ↓
  AI: 直接处理文件
  ↓
  AI: 返回结果给用户
  ↓
如果文件超过限制：
  ↓
  AI: 调用 universal-file-processor.sh
  ↓
  技能: 自动检查文件大小
  ↓
  技能: 自动拆分文件成多个部分
  ↓
  AI: 顺序处理每个部分
  ↓
  AI: 合并结果
  ↓
  AI: 返回完整分析给用户
```

**Key Decision Points / 关键决策点**:

**English**:
1. **First Check**: AI should first check file size and line count using standard tools (wc, ls, etc.)
2. **Self-Judgment**: AI should make its own decision about whether the file is too large
3. **Skill Invocation**: Only invoke this skill when AI determines it's necessary
4. **Fallback**: If the skill is not available, AI should still be able to process smaller files

**中文**:
1. **首先检查**: AI应该首先使用标准工具（wc、ls等）检查文件大小和行数
2. **自我判断**: AI应该自己判断文件是否太大
3. **技能调用**: 只有在AI认为必要时才调用此技能
4. **后备方案**: 如果技能不可用，AI仍然应该能够处理较小的文件

**Trigger Conditions / 触发条件**:

**English**:
AI should invoke this skill when:

1. **After Self-Check**: AI has checked the file and determined it exceeds limits
2. **Large File Detected**: File has >500 lines OR >50,000 characters OR estimated >30,000 tokens
3. **Batch Processing Needed**: User needs to process multiple large files
4. **Output Too Long**: AI's output exceeds 10,000 tokens and needs optimization
5. **Context Preservation**: AI needs to maintain context across multiple file parts

**中文**:
AI应该在以下情况调用此技能：

1. **自我检查后**: AI已经检查文件并确定超过限制
2. **检测到大文件**: 文件有>500行 或 >50,000字符 或估算>30,000 tokens
3. **需要批量处理**: 用户需要处理多个大文件
4. **输出过长**: AI的输出超过10,000 tokens需要优化
5. **需要上下文保留**: AI需要在多个文件部分之间保持上下文

**NOT Trigger / 不触发**:

**English**:
- Small files (<500 lines, <50KB, <30K tokens)
- Files that can be processed in one go
- When AI can handle the task without splitting

**中文**:
- 小文件（<500行，<50KB，<30K tokens）
- 可以一次性处理的文件
- AI可以不拆分就处理的任务

**Example Scenarios / 示例场景**:

**English**:
```
Scenario 1: Small file (100 lines)
User: "Analyze this file"
  ↓
AI: Checks file size: 100 lines, 5KB, ~2.5K tokens
  ↓
AI: File is within limits, no need to invoke skill
  ↓
AI: Processes file directly
  ↓
AI: Returns results to user

Scenario 2: Large file (1100 lines)
User: "Analyze this file"
  ↓
AI: Checks file size: 1100 lines, 85KB, ~42.5K tokens
  ↓
AI: File exceeds limits, need to invoke skill
  ↓
AI: Invokes universal-file-processor.sh
  ↓
Skill: Splits file into 4 parts
  ↓
AI: Processes each part
  ↓
AI: Merges results
  ↓
AI: Returns complete analysis to user
```

**中文**:
```
场景1: 小文件（100行）
用户: "分析这个文件"
  ↓
AI: 检查文件大小：100行，5KB，~2.5K tokens
  ↓
AI: 文件在限制内，不需要调用技能
  ↓
AI: 直接处理文件
  ↓
AI: 返回结果给用户

场景2: 大文件（1100行）
用户: "分析这个文件"
  ↓
AI: 检查文件大小：1100行，85KB，~42.5K tokens
  ↓
AI: 文件超过限制，需要调用技能
  ↓
AI: 调用 universal-file-processor.sh
  ↓
技能: 拆分文件成4个部分
  ↓
AI: 处理每个部分
  ↓
AI: 合并结果
  ↓
AI: 返回完整分析给用户
```

---

## 🚀 Quick Start / 快速开始

### Installation / 安装

```bash
# Clone the repository
git clone https://github.com/lichaonetuser/universal-file-processor.git

# Navigate to the skill directory
cd universal-file-processor

# Run installation script
./install.sh
```

### Basic Usage / 基本用法

```bash
# Check file size
./skill.sh check /path/to/file.md

# Split file
./skill.sh split /path/to/file.md

# Process file
./skill.sh process /path/to/file.md

# Optimize output
./skill.sh optimize /path/to/output.md

# Merge results
./skill.sh merge /tmp/universal-file-processor/file_*.md
```

---

## 📖 Features / 功能

### 1. Large File Input Processing / 大文件输入处理

**Description / 描述**: 智能拆分大文件输入

**Metrics / 指标**:
- Line count (行数)
- Character count (字符数)
- Estimated token count (估算token数)

**Usage / 用法**:
```bash
./universal-file-processor.sh check /path/to/file.md
```

**Output / 输出**:
```
📊 File Analysis: /path/to/file.md
  Lines: 1100
  Characters: 85000
  Estimated Tokens: ~42500
  Status: ⚠️  EXCEEDS_LIMIT (Recommended split)
  Suggested Strategy: chapter
```

---

### 2. Large File Processing / 大文件处理

**Description / 描述**: 分批处理大文件

**Split Strategies / 拆分策略**:

1. **By Chapter (按章节)**: 适用于Markdown文档
   ```bash
   ./universal-file-processor.sh split --strategy chapter /path/to/file.md
   ```

2. **By Lines (按行数)**: 适用于代码文件
   ```bash
   ./universal-file-processor.sh split --strategy lines --max-lines 300 /path/to/file.md
   ```

3. **By Tokens (按Token数)**: 精确控制token数
   ```bash
   ./universal-file-processor.sh split --strategy tokens --max-tokens 15000 /path/to/file.md
   ```

**Output / 输出**:
```
📦 Splitting file: /path/to/file.md
  Strategy: chapter
  Parts: 4
  Output: /tmp/universal-file-processor/file_001.md
          /tmp/universal-file-processor/file_002.md
          /tmp/universal-file-processor/file_003.md
          /tmp/universal-file-processor/file_004.md
✅ Split complete
```

---

### 3. Output Fatigue Prevention / 防止输出疲劳

**Description / 描述**: 优化输出，避免模型疲劳

**Features / 特性**:
- 智能分段输出
- 避免过长输出
- 保持逻辑连贯
- 优化token使用

**Usage / 用法**:
```bash
./universal-file-processor.sh optimize /path/to/output.md
```

**Output / 输出**:
```
🎯 Optimizing output: /path/to/output.md
  Original length: 5000 tokens
  Target length: 10000 tokens
  Reduction: 30%
  Strategy: smart-segmentation
  Optimized length: 3500 tokens
  Output: /tmp/universal-file-processor/optimized_output.md
✅ Optimization complete
```

---

## 🔧 OpenClaw Integration / OpenClaw集成

### 1. AI Auto-Detection / AI自动检测

**When AI needs to process a file / 当AI需要处理文件时**:

**English**:
```
User: "Analyze this 1100-line documentation file"
  ↓
AI: First checks file size and line count by itself
  ↓
AI: Determines file is too large to process in one go
  ↓
AI: Invokes universal-file-processor.sh
  ↓
Skill: Automatically checks file size
  ↓
Skill: Automatically splits file into parts
  ↓
AI: Processes each part sequentially
  ↓
AI: Merges results
  ↓
AI: Returns complete analysis to user
```

**中文**:
```
用户: "分析这个1100行的文档文件"
  ↓
AI: 先自己检查文件大小和行数
  ↓
AI: 判断文件是否太大无法一次性处理
  ↓
AI: 调用 universal-file-processor.sh
  ↓
技能: 自动检查文件大小
  ↓
技能: 自动拆分文件成多个部分
  ↓
AI: 顺序处理每个部分
````

## File: README.md
upstream: https://github.com/lichaonetuser/universal-file-processor/blob/HEAD/README.md

````text
# Universal File Processor

**通用文件处理器**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![OpenClaw Skill](https://img.shields.io/badge/OpenClaw-Skill-blue.svg)](https://github.com/openclaw/openclaw)
[![Version](https://img.shields.io/badge/Version-1.0-green.svg)](https://github.com/lichaonetuser/universal-file-processor)

**🌐 [English Version / 英文版本](https://github.com/lichaonetuser/universal-file-processor/blob/main/README_EN.md)**

---

## 📖 概述

通用文件处理器是一个为OpenClaw设计的综合文件处理技能，整合了三大强大功能：
- ✅ **大文件输入处理**: 智能拆分大文件输入
- ✅ **大文件处理**: 分批处理大文件
- ✅ **防止输出疲劳**: 优化输出，避免模型疲劳

**🤖 AI可以自动调用**: 这个技能可以被agent全程控制使用，无需人工干预。

---

## 🎯 为什么需要这个技能？

### 问题背景

在AI系统中处理大文件时，会遇到以下挑战：

1. **注意力衰减**: 模型处理较长文本时，对前面内容的注意力会减弱
2. **上下文丢失**: 跨文件引用和一致性检查容易出错
3. **结构混乱**: 没有清晰的分段标记时，模型难以保持逻辑连贯性
4. **输出疲劳**: 长输出会压倒模型和用户

### 解决方案

通用文件处理器通过以下方式解决这些挑战：

1. **智能检测**: 自动检测文件何时超过处理限制
2. **智能拆分**: 按逻辑块（章节、函数等）拆分文件
3. **分批处理**: 顺序处理各部分，同时保持上下文
4. **输出优化**: 减少token使用，防止疲劳

---

## 🤖 Agent自动调用

### 工作原理

通用文件处理器设计为可以被AI agent全程控制使用。当agent需要处理大文件时，它可以自动调用这个技能，无需人工干预。

### 自动化流程

```
用户: "分析这个1100行的文档文件"
  ↓
AI Agent: 检测到文件太大
  ↓
AI Agent: 自动调用 universal-file-processor.sh
  ↓
技能: 自动检查文件大小
  ↓
技能: 自动拆分文件成4个部分
  ↓
AI Agent: 顺序处理每个部分
  ↓
AI Agent: 合并结果
  ↓
AI Agent: 返回完整分析给用户
```

### Agent集成示例

```bash
# AI Agent自动调用技能

# 步骤1：检查文件大小
FILE_SIZE=$(./skill.sh check "$FILE_PATH")

# 步骤2：如果超过限制，拆分
if echo "$FILE_SIZE" | grep -q "EXCEEDS_LIMIT"; then
  ./skill.sh split "$FILE_PATH"
fi

# 步骤3：处理每个部分
for PART in /tmp/universal-file-processor/file_*.md; do
  # AI Agent处理每个部分
  process_part "$PART"
done

# 步骤4：优化输出
./skill.sh optimize "$OUTPUT_PATH"

# 步骤5：合并结果
./skill.sh merge /tmp/universal-file-processor/file_*.md
```

### Agent控制的优势

- ✅ **完全自动化**: 无需人工干预
- ✅ **智能决策**: Agent决定何时拆分
- ✅ **上下文保留**: Agent在各部分之间保持上下文
- ✅ **最优结果**: Agent确保质量和一致性

---

## 🎯 适用场景

### 1. 大型Markdown文件分析

**场景**: 你有一个1100行的文档文件需要分析。

**问题**: 文件太大，模型无法一次性处理，导致：
- 分析不完整
- 遗漏细节
- 理解不一致

**解决方案**: 使用通用文件处理器按章节拆分文件，处理每个部分，然后合并结果。

**示例**:
```bash
# 分析1100行的文档文件
./skill.sh process /path/to/docs.md
```

### 2. 大型代码文件重构

**场景**: 你需要重构一个1500行的C代码文件。

**问题**: 代码文件太大，难以：
- 理解整体结构
- 识别重构机会
- 保持文件一致性

**解决方案**: 按函数拆分文件，重构每个部分，然后合并结果。

**示例**:
```bash
# 重构1500行的C代码文件
./skill.sh process /path/to/code.c
```

### 3. 批量数据处理

**场景**: 你需要处理大型数据集（2MB的CSV文件）。

**问题**: 数据集太大，无法一次性处理，导致：
- 内存问题
- 处理超时
- 结果不完整

**解决方案**: 将数据集拆分成块，处理每个块，然后合并结果。

**示例**:
```bash
# 处理大型数据集
./skill.sh process /path/to/dataset.csv
```

### 4. 输出优化

**场景**: 模型生成了非常长的输出，需要优化。

**问题**: 长输出可能：
- 压倒用户
- 包含冗余信息
- 难以阅读

**解决方案**: 使用输出优化来分段和压缩输出。

**示例**:
```bash
# 优化长输出，防止疲劳
./skill.sh optimize /path/to/long-output.md
```

---

## 🚀 快速开始

### 安装

```bash
# 克隆仓库
git clone https://github.com/lichaonetuser/universal-file-processor.git

# 进入技能目录
cd universal-file-processor

# 运行安装脚本
./install.sh
```

---

## 📖 详细用法

### 1. 检查文件大小

**命令**: `./skill.sh check <file>`

**功能**: 检测文件大小，估算token数，判断是否需要拆分

**参数**:
- `<file>`: 要检查的文件路径

**输出**:
```
📊 File Analysis: /path/to/file.md
  Lines: 1100
  Characters: 85000
  Estimated Tokens: ~42500
  Status: ⚠️  EXCEEDS_LIMIT (Recommended split)
  Suggested Strategy: chapter
```

**使用场景**:
- 在处理文件前，先检查文件大小
- 判断是否需要拆分
- 选择合适的拆分策略

**示例**:
```bash
# 检查文件大小
./skill.sh check /path/to/file.md
```

### 2. 拆分文件

**命令**: `./skill.sh split <file>`

**功能**: 按默认策略拆分文件

**参数**:
- `<file>`: 要拆分的文件路径

**输出**:
```
📦 Splitting file: /path/to/file.md
  Strategy: chapter
  Parts: 4
  Output: /tmp/universal-file-processor/file_001.md
          /tmp/universal-file-processor/file_002.md
          /tmp/universal-file-processor/file_003.md
          /tmp/universal-file-processor/file_004.md
✅ Split complete
```

**使用场景**:
- 文件超过处理限制时
- 需要分批处理时
- 想要按逻辑块拆分时

**示例**:
```bash
# 拆分文件
./skill.sh split /path/to/file.md
```

### 3. 处理文件

**命令**: `./skill.sh process <file>`

**功能**: 自动检测并处理文件（如果需要会自动拆分）

**参数**:
- `<file>`: 要处理的文件路径

**输出**:
```
⚠️  File exceeds limits, splitting...
📦 Splitting file: /path/to/file.md
  Strategy: chapter
  Parts: 4
✅ Split complete
🔄 Processing 4 parts...
  Processing part 1/4: /tmp/universal-file-processor/file_001.md
    Lines: 275, Chars: 21250, Tokens: ~10625
  Processing part 2/4: /tmp/universal-file-processor/file_002.md
    Lines: 275, Chars: 21250, Tokens: ~10625
  Processing part 3/4: /tmp/universal-file-processor/file_003.md
    Lines: 275, Chars: 21250, Tokens: ~10625
  Processing part 4/4: /tmp/universal-file-processor/file_004.md
    Lines: 275, Chars: 21250, Tokens: ~10625
✅ Processing complete
💡 Next step: Merge results with: ./skill.sh merge /tmp/universal-file-processor/file_*.md
```

**使用场景**:
- 需要处理大文件时
- 不确定是否需要拆分时
- 想要自动化处理流程时

**示例**:
```bash
# 处理文件
./skill.sh process /path/to/file.md
```

### 4. 优化输出

**命令**: `./skill.sh optimize <file>`

**功能**: 优化输出，防止模型疲劳

**参数**:
- `<file>`: 要优化的文件路径

**输出**:
```
🎯 Optimizing output: /path/to/output.md
  Original length: 5000 tokens
  Target length: 10000 tokens
  Reduction: 30%
  Strategy: smart-segmentation
  Optimized length: 3500 tokens
  Output: /tmp/universal-file-processor/optimized_output.md
✅ Optimization complete
```

**使用场景**:
- 输出过长时
- 需要减少token使用时
- 想要提高输出质量时

**示例**:
```bash
# 优化输出
./skill.sh optimize /path/to/output.md
```

### 5. 合并结果

**命令**: `./skill.sh merge <pattern>`

**功能**: 合并处理后的结果

**参数**:
- `<pattern>`: 文件模式（例如：`/tmp/universal-file-processor/file_*.md`）

**输出**:
```
🔗 Merging results...
  Parts: 4
  Output: /tmp/universal-file-processor/merged_result.md
✅ Merge complete
```

**使用场景**:
- 处理完拆分后的文件后
- 需要合并结果时
- 想要得到完整输出时

**示例**:
```bash
# 合并结果
./skill.sh merge /tmp/universal-file-processor/file_*.md
```

---

## 🎯 功能特性

### 1. 大文件输入处理

- 自动检测文件大小（行数、字符数、token数）
- 智能判断是否需要拆分
- 支持多种拆分策略

### 2. 大文件处理

- 按章节拆分（适用于Markdown）
- 按行数拆分（适用于代码）
- 按token数拆分（精确控制）
- 分批处理，保持上下文连贯
- 自动合并结果

### 3. 防止输出疲劳

- 智能分段输出
- 避免过长输出
- 保持逻辑连贯
- 优化token使用

---

## ⚙️ 配置

编辑 `universal-file-processor.config` 来自定义设置：

```ini
# Token限制
token_limit=30000

# 行数限制
line_limit=500

# 字符限制
char_limit=50000

# 默认拆分策略
default_strategy=chapter

# 输出目录
output_dir=/tmp/universal-file-processor

# 模型上下文窗口
model_context_window=128000

# Token估算比例（每token字符数）
token_ratio=2.0

# 输出优化设置
output_optimization=true
max_output_tokens=10000
output_segment_size=2000
smart_segmentation=true
```

---

## 📊 性能

### 效率

- ✅ **智能检测**: 只在必要时拆分
- ✅ **优化拆分**: 最小化上下文丢失
- ✅ **并行处理**: 支持并行处理各部分
- ✅ **内存高效**: 低内存占用
- ✅ **输出优化**: 减少token使用

### 准确性

- ✅ **上下文保留**: 保持逻辑连贯性
- ✅ **一致结果**: 与单次处理相同输出
- ✅ **错误恢复**: 处理部分失败
- ✅ **疲劳预防**: 避免模型疲劳

---

## 📁 文件结构

```
universal-file-processor/
├── universal-file-processor.sh    # 主脚本
├── universal-file-processor.config # 配置文件
├── install.sh                     # 安装脚本
├── skill.sh                       # 技能实现脚本
├── SKILL.md                       # 技能元数据
├── README.md                      # 中文文档
├── README_EN.md                   # 英文文档
└── LICENSE                        # 许可证
```

---

## 🤝 贡献

欢迎贡献！请随时提交问题和拉取请求。

---

## 📄 许可证

MIT License - 详见LICENSE文件。

---

## 👤 作者

- **姓名**: lichaonetuser
- **GitHub**: [@lichaonetuser](https://github.com/lichaonetuser)

---

## 📞 支持

- **问题**: [GitHub Issues](https://github.com/lichaonetuser/universal-file-processor/issues)
- **讨论**: [GitHub Discussions](https://github.com/lichaonetuser/universal-file-processor/discussions)

---

**由 lichaonetuser 用 ❤️ 制作**
````
