Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:26:08 +08:00
commit 8f22ddf339
295 changed files with 59710 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
# file.compare
Compare two files and generate detailed diff reports showing line-by-line differences
## Overview
**Purpose:** Compare two files and generate detailed diff reports showing line-by-line differences
**Command:** `/file/compare`
## Usage
### Basic Usage
```bash
python3 skills/file/compare/file_compare.py
```
### With Arguments
```bash
python3 skills/file/compare/file_compare.py \
--file_path_1 "value" \
--file_path_2 "value" \
--output_format_(optional) "value" \
--output-format json
```
## Inputs
- **file_path_1**
- **file_path_2**
- **output_format (optional)**
## Outputs
- **diff_report.json**
## Artifact Metadata
### Produces
- `diff-report`
## Permissions
- `filesystem:read`
## Implementation Notes
Use Python's difflib to compare files line by line. Support multiple output formats: - unified: Standard unified diff format - context: Context diff format - html: HTML diff with color coding - json: Structured JSON with line-by-line changes Include statistics: - Total lines added - Total lines removed - Total lines modified - Percentage similarity Handle binary files by detecting and reporting as non-text.
## Integration
This skill can be used in agents by including it in `skills_available`:
```yaml
name: my.agent
skills_available:
- file.compare
```
## Testing
Run tests with:
```bash
pytest skills/file/compare/test_file_compare.py -v
```
## Created By
This skill was generated by **meta.skill**, the skill creator meta-agent.
---
*Part of the Betty Framework*

View File

@@ -0,0 +1 @@
# Auto-generated package initializer for skills.

View File

@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""
file.compare - Compare two files and generate detailed diff reports showing line-by-line differences
Generated by meta.skill
"""
import os
import sys
import json
import yaml
from pathlib import Path
from typing import Dict, List, Any, Optional
from betty.config import BASE_DIR
from betty.logging_utils import setup_logger
logger = setup_logger(__name__)
class FileCompare:
"""
Compare two files and generate detailed diff reports showing line-by-line differences
"""
def __init__(self, base_dir: str = BASE_DIR):
"""Initialize skill"""
self.base_dir = Path(base_dir)
def execute(self, file_path_1: Optional[str] = None, file_path_2: Optional[str] = None, output_format_optional: Optional[str] = None) -> Dict[str, Any]:
"""
Execute the skill
Returns:
Dict with execution results
"""
try:
logger.info("Executing file.compare...")
# TODO: Implement skill logic here
# Implementation notes:
# Use Python's difflib to compare files line by line. Support multiple output formats: - unified: Standard unified diff format - context: Context diff format - html: HTML diff with color coding - json: Structured JSON with line-by-line changes Include statistics: - Total lines added - Total lines removed - Total lines modified - Percentage similarity Handle binary files by detecting and reporting as non-text.
# Placeholder implementation
result = {
"ok": True,
"status": "success",
"message": "Skill executed successfully"
}
logger.info("Skill completed successfully")
return result
except Exception as e:
logger.error(f"Error executing skill: {e}")
return {
"ok": False,
"status": "failed",
"error": str(e)
}
def main():
"""CLI entry point"""
import argparse
parser = argparse.ArgumentParser(
description="Compare two files and generate detailed diff reports showing line-by-line differences"
)
parser.add_argument(
"--file-path-1",
help="file_path_1"
)
parser.add_argument(
"--file-path-2",
help="file_path_2"
)
parser.add_argument(
"--output-format-optional",
help="output_format (optional)"
)
parser.add_argument(
"--output-format",
choices=["json", "yaml"],
default="json",
help="Output format"
)
args = parser.parse_args()
# Create skill instance
skill = FileCompare()
# Execute skill
result = skill.execute(
file_path_1=args.file_path_1,
file_path_2=args.file_path_2,
output_format_optional=args.output_format_optional,
)
# Output result
if args.output_format == "json":
print(json.dumps(result, indent=2))
else:
print(yaml.dump(result, default_flow_style=False))
# Exit with appropriate code
sys.exit(0 if result.get("ok") else 1)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,22 @@
name: file.compare
version: 0.1.0
description: Compare two files and generate detailed diff reports showing line-by-line
differences
inputs:
- file_path_1
- file_path_2
- output_format (optional)
outputs:
- diff_report.json
status: active
permissions:
- filesystem:read
entrypoints:
- command: /file/compare
handler: file_compare.py
runtime: python
description: Compare two files and generate detailed diff reports showing line-by-line
differences
artifact_metadata:
produces:
- type: diff-report

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""
Tests for file.compare
Generated by meta.skill
"""
import pytest
import sys
import os
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
from skills.file_compare import file_compare
class TestFileCompare:
"""Tests for FileCompare"""
def setup_method(self):
"""Setup test fixtures"""
self.skill = file_compare.FileCompare()
def test_initialization(self):
"""Test skill initializes correctly"""
assert self.skill is not None
assert self.skill.base_dir is not None
def test_execute_basic(self):
"""Test basic execution"""
result = self.skill.execute()
assert result is not None
assert "ok" in result
assert "status" in result
def test_execute_success(self):
"""Test successful execution"""
result = self.skill.execute()
assert result["ok"] is True
assert result["status"] == "success"
# TODO: Add more specific tests based on skill functionality
def test_cli_help(capsys):
"""Test CLI help message"""
sys.argv = ["file_compare.py", "--help"]
with pytest.raises(SystemExit) as exc_info:
file_compare.main()
assert exc_info.value.code == 0
captured = capsys.readouterr()
assert "Compare two files and generate detailed diff repor" in captured.out
if __name__ == "__main__":
pytest.main([__file__, "-v"])