Folder Index
Maintain a lightweight index at ~/.config/folder-index.json to know where important things are without rescanning.
CODEBLOCK0
When user asks "where is X" or "find my project Y", check the index first. If not found, do targeted discovery then offer to add the result.
Discovery
When asked to find or index folders:
- - Scan likely locations: ~/projects, ~/Documents, ~/code, ~/dev, ~/work
- Detect projects by markers: .git, package.json, pubspec.yaml, Cargo.toml, go.mod, pyproject.toml, *.sln
- Stop at first marker (don't recurse into node_modules, vendor, build)
- Propose what was found, don't auto-add: "Found 8 projects in ~/code. Add to index?"
Path Security
- - Canonicalize paths (resolve
~, .., symlinks) before any operation - Reject system paths: /, /etc, /var, /usr, /System, /Library, C:\Windows, C:\Program Files
- Skip symlinks during traversal, report them separately
Destructive Operations
- - Use OS trash instead of permanent delete
- State recoverability: "nodemodules: recoverable with npm install"
- Build artifacts safe to delete: nodemodules, pycache, .gradle, build/, target/, Pods/, .next/
Platform Quirks
- - macOS: .DS_Store alone = effectively empty. Treat .app as single item.
- Windows: Paths >260 chars need
\\?\ prefix. - Network drives: Warn before bulk ops — may be slow or offline.
文件夹索引
在 ~/.config/folder-index.json 维护一个轻量级索引,无需重新扫描即可知晓重要内容的位置。
json
{
folders: [
{path: /Users/alex/projects/webapp, type: project, note: 主要客户项目}
]
}
当用户询问X在哪里或找到我的项目Y时,优先检查索引。若未找到,则进行定向发现并询问是否将结果添加至索引。
发现机制
当被要求查找或索引文件夹时:
- - 扫描常用位置:~/projects、~/Documents、~/code、~/dev、~/work
- 通过标记文件检测项目:.git、package.json、pubspec.yaml、Cargo.toml、go.mod、pyproject.toml、*.sln
- 遇到首个标记即停止(不递归进入node_modules、vendor、build目录)
- 仅展示发现结果,不自动添加:在~/code中发现8个项目。是否添加至索引?
路径安全
- - 在任何操作前规范化路径(解析~、..、符号链接)
- 拒绝系统路径:/、/etc、/var、/usr、/System、/Library、C:\Windows、C:\Program Files
- 遍历时跳过符号链接,单独报告
破坏性操作
- - 使用系统回收站而非永久删除
- 声明可恢复性:nodemodules:可通过npm install恢复
- 可安全删除的构建产物:nodemodules、pycache、.gradle、build/、target/、Pods/、.next/
平台特性
- - macOS: 仅含.DS_Store的文件夹视为空文件夹。将.app视为单个项目。
- Windows: 路径超过260字符需添加\\?\前缀。
- 网络驱动器: 批量操作前发出警告——可能速度较慢或处于离线状态。