用途:检测并移除不必要的包装(转发)函数。当用户要求删除冗余包装、在 plan refactor 发现因简单委托产生的重复后、想减少代码间接层,或询问“哪些函数只是委托给另一个函数”时使用;也可在写完新代码后自查是否意外累积了代理。
主要能力与模式:默认报告模式列出发现的包装函数,支持 md、json、text 输出;--dry-run 预览所有改动(调用点替换与定义删除);--fix 实际应用改动。相关命令 grep --semantic=proxy 可快速发现但不会自动修复,plan unwrap 用于采取行动。
判定条件:函数体为单个函数调用、参数是简单标识符(无表达式)、无控制流(if、match、let 等)时会被标记为可解包包装。默认排除 self 委托(如 self.items.length())与裸构造器包装,可用 --all,或单独用 --include-self、--include-bare 纳入。
用法示例: indexion plan unwrap --include='.mbt' <path> indexion plan unwrap --dry-run --include='.mbt' <path> indexion plan unwrap --fix --include='.mbt' <path> indexion plan unwrap --all --include='.mbt' <path> indexion plan unwrap --format=json --include='.mbt' <path> indexion plan unwrap -o=unwrap.md --include='.mbt' <path>
选项:--dry-run、--fix、--all、--include-self、--include-bare、--include=PATTERN(可重复)、--exclude=PATTERN(可重复)、--format(md/json/text,默认 md)、-o/--output、--specs-dir(默认 kgfs)。
建议流程:先用 grep --semantic=proxy 快速检查,再用 --dry-run 详细预览并逐个人工核对,确认后执行 --fix,最后运行测试(如 moon test --target native)并重跑 plan refactor 验证。
限制与注意:平台包装(如 FFI 包装或 @osenv_path 包装)是刻意的抽象层,不应误删;pub 包装若被外部包使用,删除属于破坏性变更,需先检查可见性。始终先 dry-run 再应用。具体平台支持、性能与收费信息暂未提供。