What This Skill Does (and Doesn't)
YES: Organize existing files, find duplicates, analyze disk usage, batch rename/move, clean up clutter
NO: Open files, create files/folders, copy files, extract archives, basic file browsing — use standard file operations for those
This is a power tool for reorganization, not a replacement for basic file commands.
Path Security (Non-Negotiable)
- - Canonicalize ALL paths before any operation: resolve
.., ~, symlinks, then validate - After canonicalization, reject if path is outside user's home or explicitly allowed directories
- NEVER follow symlinks during traversal — report them as "symlink to X, skipped" and let user decide
- Block these paths absolutely:
/, /etc, /var, /usr, /System, /Library, C:\Windows, INLINECODE9 - Paths containing
.. after canonicalization = reject with explanation
Fast Path vs Safe Path
Fast path (1-9 files): Execute immediately with brief confirmation: "Move 3 files to Archive? [Y/n]"
Safe path (10+ files): Create manifest, show summary, require explicit "yes" or review
This prevents confirmation fatigue for simple operations while protecting bulk actions.
Trash Handling
- - Use the operating system's native trash:
trash CLI on macOS/Linux, Recycle Bin API on Windows - If OS trash unavailable, move to
~/.local/share/file-organizer-trash/ with metadata sidecar - Metadata sidecar (JSON): original path, deletion timestamp, operation ID — NOT path-in-filename
- Never permanently delete without explicit "permanently delete" or "empty trash" command
Undo System
- - Every operation creates an undo record in INLINECODE13
- Record contains: operation type, source paths, destination paths, checksums of moved files
- "Undo last" reverses the most recent operation using the record
- Undo records expire after 30 days — warn user before expiry
- NO shell scripts for undo — JSON metadata only, executed by the agent
Symlink Policy
- - During directory traversal: skip symlinks, report them separately
- "This folder contains 12 symlinks pointing outside — review before proceeding?"
- Never follow symlinks automatically — they're a classic attack vector
- User can explicitly request "follow symlinks" but must confirm each external target
Duplicate Detection (Scalable)
- - Phase 1: Group by exact size (instant, no I/O)
- Phase 2: Hash first 4KB of same-size files (fast filter)
- Phase 3: Full hash only for files matching phase 2
- For >10,000 files, require confirmation: "This will take ~15 minutes. Proceed?"
- Cache hashes in
~/.local/share/file-organizer/hash-cache.db (SQLite) with mtime invalidation
Bulk Operations
- - Batch rename: Preview ALL transformations if <50 files, first/last 10 if more, always show total count
- Batch move: Verify destination has space before starting, atomic per-file with rollback on error
- Progress: Update every 5% or 30 seconds, whichever is less frequent — not per-file spam
- Error handling: On ANY error, stop, report what succeeded/failed, offer "continue skipping errors" or "rollback completed"
Organization Proposals
- - Analyze directory contents FIRST, then propose: "80% images, 15% videos, 5% docs — organize by date or type?"
- Always show concrete examples: "vacation-photo.jpg → 2024/06-June/vacation-photo.jpg"
- Preserve original filenames unless user requests rename pattern
- Create
.file-organizer-manifest.json in destination documenting the reorganization for future reference
Size Analysis
- - Top consumers by directory, not individual files — users think in folders
- Flag known safe-to-delete: nodemodules, pycache, .gradle, build/, target/, Pods/
- Calculate actual vs apparent size (sparse files, hardlinks)
- For cleanup suggestions, always state recoverability: "Deleting nodemodules: fully recoverable with npm install"
Platform Specifics
- - macOS: Respect .app bundles (they're directories), use
trash via Homebrew if available - Windows: Use long path prefix
\\?\ for paths >260 chars, use shell API for Recycle Bin - Linux: XDG trash spec (
~/.local/share/Trash/), handle different filesystem capabilities
Limits and Failures
- - Refuse operations on >100,000 files without explicit override: "This affects 250K files. Type 'I understand' to proceed"
- If manifest would exceed 10MB, paginate: "Showing batch 1 of 15 (page through with 'next')"
- Network drives: detect by response time, warn about reliability, suggest local copy first
- Disk full: check before starting, reserve 1% headroom, fail gracefully with partial completion report
该技能的功能(及限制)
可执行: 整理现有文件、查找重复项、分析磁盘使用情况、批量重命名/移动、清理杂乱文件
不可执行: 打开文件、创建文件/文件夹、复制文件、解压归档、基本文件浏览——这些请使用标准文件操作
这是一个用于重新组织的强力工具,而非基本文件命令的替代品。
路径安全(不可妥协)
- - 在任何操作前规范化所有路径:解析 ..、~、符号链接,然后验证
- 规范化后,若路径位于用户主目录或明确允许的目录之外则拒绝
- 遍历时绝不跟随符号链接——将其报告为符号链接指向 X,已跳过,由用户决定
- 绝对阻止以下路径:/、/etc、/var、/usr、/System、/Library、C:\Windows、C:\Program Files
- 规范化后包含 .. 的路径 = 拒绝并附上解释
快速路径与安全路径
快速路径(1-9个文件): 立即执行并附带简短确认:将3个文件移至归档?[Y/n]
安全路径(10个以上文件): 创建清单、显示摘要、要求明确输入yes或进行审查
这可在保护批量操作的同时,避免简单操作时的确认疲劳。
回收站处理
- - 使用操作系统的原生回收站:macOS/Linux 上使用 trash 命令行工具,Windows 上使用回收站 API
- 若操作系统回收站不可用,则移至 ~/.local/share/file-organizer-trash/ 并附带元数据侧车文件
- 元数据侧车文件(JSON格式):原始路径、删除时间戳、操作ID——而非将路径嵌入文件名
- 未经明确的永久删除或清空回收站命令,绝不执行永久删除
撤销系统
- - 每次操作在 ~/.local/share/file-organizer/undo/TIMESTAMP.json 中创建撤销记录
- 记录包含:操作类型、源路径、目标路径、已移动文件的校验和
- 撤销上一步利用记录逆转最近一次操作
- 撤销记录30天后过期——过期前向用户发出警告
- 撤销操作不使用 Shell 脚本——仅使用 JSON 元数据,由代理执行
符号链接策略
- - 目录遍历期间:跳过符号链接,单独报告
- 此文件夹包含12个指向外部的符号链接——是否继续前先审查?
- 绝不自动跟随符号链接——它们是经典的攻击向量
- 用户可明确请求跟随符号链接,但必须确认每个外部目标
重复检测(可扩展)
- - 阶段1:按精确大小分组(即时,无I/O操作)
- 阶段2:对相同大小的文件哈希前4KB(快速过滤)
- 阶段3:仅对匹配阶段2的文件进行完整哈希
- 对于超过10,000个文件,要求确认:此操作大约需要15分钟。是否继续?
- 在 ~/.local/share/file-organizer/hash-cache.db(SQLite)中缓存哈希,并依据修改时间进行失效处理
批量操作
- - 批量重命名: 若少于50个文件则预览所有转换,多于50个则预览前10个和后10个,始终显示总数
- 批量移动: 开始前验证目标位置有足够空间,按文件原子操作,出错时回滚
- 进度: 每完成5%或每30秒更新一次(取频率较低者)——而非每个文件都发送通知
- 错误处理: 出现任何错误时停止,报告成功/失败情况,提供跳过错误继续或回滚已完成操作选项
整理建议
- - 首先分析目录内容,然后提出建议:80%图片,15%视频,5%文档——按日期还是类型整理?
- 始终展示具体示例:vacation-photo.jpg → 2024/06-June/vacation-photo.jpg
- 除非用户要求重命名模式,否则保留原始文件名
- 在目标位置创建 .file-organizer-manifest.json 文件,记录本次整理以供将来参考
大小分析
- - 按目录而非单个文件查找最大占用者——用户以文件夹为单位思考
- 标记已知可安全删除的内容:nodemodules、pycache、.gradle、build/、target/、Pods/
- 计算实际大小与表观大小(稀疏文件、硬链接)
- 对于清理建议,始终说明可恢复性:删除 nodemodules:可通过 npm install 完全恢复
平台特定说明
- - macOS:尊重 .app 包(它们是目录),若可用则通过 Homebrew 使用 trash
- Windows:对超过260个字符的路径使用长路径前缀 \\?\,使用 Shell API 操作回收站
- Linux:遵循 XDG 回收站规范(~/.local/share/Trash/),处理不同文件系统的能力差异
限制与失败处理
- - 拒绝操作超过100,000个文件,除非用户明确覆盖:此操作影响25万个文件。请输入I understand以继续
- 若清单超过10MB,则分页显示:显示第1批,共15批(可通过next翻页)
- 网络驱动器:通过响应时间检测,警告可靠性问题,建议先复制到本地
- 磁盘已满:开始前检查,预留1%的余量,优雅地失败并附带部分完成报告