下载文件管理器
我构建了这个自动文件管理器,因为我厌倦了下载文件夹一团糟。它根据文件的类型和特定的命名模式对文件进行分类,将它们移动到有组织的子目录中。我将其设计为使用Agent Hooks集成与Kiro IDE无缝协作,因此文件一旦下载就会自动组织。
特性
- 自动组织:文件在添加到下载时会自动分类和移动
- 智能分类:按类型组织的文件(Dev、Zip、Media、Docs、Exe、Misc)
- 学术支持:我为带有“22102”、“作业”等模式的学术文件添加了特殊处理。(最初是为我的VIT课程设计的)
- Agent Hooks集成:使用Kiro的Agent Hooks自动触发
- MCP服务器支持:通过回退到标准方法增强了文件操作
- 交叉平台的:适用于Windows、macOS和Linux
文件类别
- 开发:编程文件(.py、.js、.ts、.html、.css、.json等)
- 压缩:存档文件(.zip、.rar、.7z、.tar.gz等)
- 媒体:图像、视频、音频(.jpg、.mp4、.mp3等)
- 文档:文档(.pdf、.docx、.xlsx、.csv等)
- 可执行文件:可执行文件(.exe、.msi、.dmg、.deb等)
- 学术的:学术档案(包含“22102”、“作业”、“实验室”等)
- 杂项:其他一切
快速开始
1.安装
cd downloads-organizer
npm install
npm run build2.初始化文件夹
npm run cli init3.整理文件
# Preview what would be organized
npm run cli organize --preview
# Actually organize files
npm run cli organize4.设置自动组织(代理挂钩)
在Kiro IDE中:
- 打开命令选项板(
Ctrl+Shift+P) - 搜索“打开Kiro Hook用户界面”
- 使用以下设置创建新挂钩:
- 名字:下载文件管理器 - 触发:文件系统更改 - 路径:您的下载文件夹路径 - 命令: node /path/to/downloads-organizer/dist/hooks/AgentHookHandler.js - 自动审批:是(无缝操作)
CLI命令
整理文件
# Organize all files in Downloads
npm run cli organize
# Preview organization without moving files
npm run cli organize --preview
# Use custom Downloads path
npm run cli organize --path /custom/downloads/path监视状态
# Show detailed status and statistics
npm run cli status配置管理
# Show current configuration
npm run cli config --show
# Set Downloads folder path
npm run cli config --set-path /new/downloads/path
# Add academic naming pattern
npm run cli config --add-pattern "Quiz"
# Enable/disable MCP server integration
npm run cli config --enable-mcp
npm run cli config --disable-mcp
# Reset to default configuration
npm run cli config --reset文件夹管理
# Initialize all category folders
npm run cli init
# Clean up empty folders
npm run cli cleanup自动监测
# Start watching Downloads folder
npm run cli watch
# Stop watching (from another terminal)
npm run cli watch --stopAgent Hook设置
方法1:使用Kiro Hook UI
- 访问钩子UI
- 按 Ctrl+Shift+P (Windows/Linux)或 Cmd+Shift+P (macOS) - 键入“打开Kiro Hook UI” - 按 Enter
- 创建新钩子
- 点击“创建新钩子” - 填写详细信息:
Name: Downloads File Organizer
Description: Automatically organize downloaded files by type and VIT patterns
Trigger: File Created
Watch Path: C:\Users\[YourUsername]\Downloads (Windows)
or ~/Downloads (macOS/Linux)
Prompt: A file has been created in the Downloads folder. Please organize this file by running the downloads organizer script to categorize it by type and VIT patterns. Execute: npm run cli -- 方法2:手动吊钩配置
在Kiro工作区中创建挂钩配置文件:
{
"name": "Downloads File Organizer",
"description": "Automatically organize downloaded files by type and VIT patterns",
"trigger": {
"type": "filesystem",
"path": "~/Downloads",
"events": ["create", "modify"],
"debounce": 2000
},
"action": {
"type": "command",
"command": "node",
"args": ["/path/to/downloads-organizer/dist/hooks/AgentHookHandler.js"],
"autoApprove": true
}
}MCP服务器集成
我集成了MCP(模型上下文协议)服务器来增强文件操作。以下是我推荐的服务器:
推荐的MCP服务器
- 文件操作MCP服务器
{
"mcpServers": {
"file-operations": {
"command": "npm",
"args": ["-y @smithery/cli install @bsmi021/mcp-file-operations-server --client claude"],
"disabled": false,
"autoApprove": ["moveFile", "createDirectory", "checkExists"]
}
}
}- 记录MCP服务器
{
"mcpServers": {
"logging": {
"command": "uvx",
"args": ["logging-mcp-server@latest"],
"disabled": false,
"autoApprove": ["log", "logError", "logInfo"]
}
}
}MCP设置说明
- 安装UV(Python包管理器)
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh- 在Kiro中配置MCP
- 创建/编辑 .kiro/settings/mcp.json 在您的工作空间中 - 添加上面的MCP服务器配置 - 重新启动Kiro或刷新MCP连接
- 验证MCP集成
npm run cli status
# Should show "MCP Available: ✅"配置
我让组织者高度可配置,这样你就可以根据自己的需求进行调整。
配置文件位置
- 视窗:
%USERPROFILE%\.downloads-organizer\config.json - macOS/Linux:
~/.downloads-organizer/config.json
配置选项
{
"downloadsPath": "~/Downloads",
"categories": [
{
"name": "Dev",
"folderName": "Dev",
"extensions": ["js", "py", "html", "css", ...]
}
],
"academicPatterns": ["22102", "Assignment", "Lab", "Exp", "SEM"],
"useMCP": true,
"autoApprove": false
}学术命名模式
我配置了组织者来识别这些学术模式(不区分大小写):
- 课程代码:
22102,CSE22102 - 任务类型:
Assignment,Assgn - 实验室工作:
Lab,Laboratory,Practical,Prac - 实验:
Experiment,Exp - 学期:
SEM
与这些模式匹配的文件被移动到 Academic 文件夹,无论其文件扩展名如何。
发展
我将这个项目设计为模块化和可测试的。我是这样组织的:
项目结构
downloads-organizer/
├── src/
│ ├── services/ # Core business logic
│ ├── interfaces/ # TypeScript interfaces
│ ├── types/ # Type definitions
│ ├── constants/ # Configuration constants
│ ├── hooks/ # Agent Hook handlers
│ ├── __tests__/ # Unit and integration tests
│ └── cli.ts # Command-line interface
├── dist/ # Compiled JavaScript
└── docs/ # Additional documentation开发命令
# Install dependencies
npm install
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Build project
npm run build
# Development mode with auto-rebuild
npm run dev
# Lint code
npm run lint
# Format code
npm run format运行测试
# Run all tests
npm test
# Run specific test file
npm test -- ExtensionMatcher.test.ts
# Run tests in watch mode
npm test -- --watch
# Run integration tests
npm test -- integration.test.ts故障排除
我在开发和使用过程中遇到了这些问题。以下是我找到的解决方案:
常见问题
- “找不到下载文件夹”
- 检查下载文件夹是否存在 - 验证配置中的路径: npm run cli config --show - 设置正确的路径: npm run cli config --set-path /correct/path
- “权限被拒绝”错误
- 必要时以提升的权限运行 - 检查文件/文件夹权限 - 确保文件未被其他应用程序使用
- Agent Hook未触发
- 验证钩子在Kiro hook UI中是否处于活动状态 - 检查吊钩配置和路径 - 查找Kiro输出面板中的错误
- MCP服务器不工作
- 安装紫外线: curl -LsSf https://astral.sh/uv/install.sh | sh - 检查中的MCP配置 .kiro/settings/mcp.json - MCP配置更改后重新启动Kiro
- 文件分类不正确
- 检查是否支持文件扩展名: npm run cli status - 验证VIT模式: npm run cli config --show - 预览测试: npm run cli organize --preview
调试模式
通过设置环境变量启用详细日志记录:
DEBUG=downloads-organizer npm run cli organize获取帮助
- 检查状态:
npm run cli status - 审查配置:
npm run cli config --show - 预览测试:
npm run cli organize --preview - 检查Kiro输出面板中的日志
- 运行集成测试:
npm test -- integration.test.ts
贡献
我欢迎捐款!以下是您可以提供帮助的方式:
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 进行更改并添加测试
- 运行测试:
npm test - 构建项目:
npm run build - 提交拉取请求
对于bug、功能请求或问题,请随时打开问题。
我为什么建造这个
我一直对下载文件夹变得混乱感到沮丧。作为一名学生,我的学术文件和随机下载的文件混杂在一起,开发文件到处都是,找到任何东西都是一场噩梦。因此,我构建了这个组织者,以便在文件下载后立即自动对所有内容进行排序。
学术模式识别是专门为我的课程设计的(最初是VIT模式),但我使其可配置,这样任何人都可以根据自己的需求进行调整。
许可证
MIT许可证-详见许可证文件
