跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    中文English
    FRFlo

    Move Tool

    v1.1.0其他
    opencode-move-tool

    Single-operation code relocation tool for OpenCode agents — move code between files without copy-then-delete

    GitHub 星标

    3

    月装机量

    37

    近 7 天 9

    综合评分SCORE

    30.1

    生态多维模型

    最近提交

    2 个月前

    2026-05-25

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-move-tool@1.1.0"]
    }

    opencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。

    CI npm version License: MIT

    move — relocate complete code blocks inside an OpenCode worktree. Designed for agents that would otherwise copy code to a new location and then delete the original.

    The tool is intentionally narrow: it moves text safely. It does not update imports, exports, references, formatting, or surrounding code semantics.


    Installation

    Add opencode-move-tool to your OpenCode plugin configuration:

    // opencode.json or .opencode/opencode.json
    {
      "plugin": ["opencode-move-tool"]
    }
    

    Or use the CLI:

    opencode plugin opencode-move-tool
    

    OpenCode installs plugins automatically on startup — no manual npm install required.


    Usage

    Required workflow

    1. Read the source and destination files.
    2. Call move with dry_run=true.
    3. Review preview.removed_text and preview.inserted_text.
    4. Re-run the same call with dry_run=false.
    5. Update imports, exports, references, and formatting manually.
    6. Run diagnostics/tests.

    Move lines to another file

    move({
      source_file: "src/utils.ts",
      destination_file: "src/validation.ts",
      start_line: 42,
      end_line: 68,
      insert_mode: "append",
      dry_run: true,
    })
    

    Insert before or after a destination line

    move({
      source_file: "src/utils.ts",
      destination_file: "src/validation.ts",
      start_line: 42,
      end_line: 68,
      insert_mode: "before_line",
      insert_line: 12,
      dry_run: true,
    })
    

    insert_line is valid only with insert_mode="before_line" or insert_mode="after_line".

    Reorder within the same file

    move({
      source_file: "src/app.ts",
      destination_file: "src/app.ts",
      start_line: 120,
      end_line: 150,
      insert_mode: "after_line",
      insert_line: 45,
      dry_run: true,
    })
    

    Same-file insert_line uses the original file's line numbers. Inserting inside or adjacent to the moved range is rejected.


    Reference

    Arguments

    Argument Type Required Description
    source_file string Yes Source file inside the current worktree.
    destination_file string Yes Destination file inside the current worktree. Created on apply if missing.
    start_line number Yes 1-based inclusive source start line.
    end_line number No 1-based inclusive source end line. Defaults to start_line.
    insert_mode "append" | "prepend" | "after_line" | "before_line" No Destination placement. Defaults to append.
    insert_line number For after_line/before_line 1-based destination anchor line.
    adjust_indentation boolean No Defaults to false. Best-effort leading-whitespace adjustment.
    dry_run boolean No Defaults to true. Set false only after reviewing the preview.

    Defaults and constraints

    • dry_run defaults to true.
    • insert_mode defaults to append.
    • adjust_indentation defaults to false.
    • Paths must stay inside the current worktree. Absolute paths are allowed only inside the worktree.
    • Destination files may be created, but destination parents must resolve inside the worktree.
    • Cross-file writes use best-effort rollback, not a true filesystem transaction.

    When not to use

    • Do not use for partial-line edits.
    • Do not use to update imports or references.
    • Do not use when generating brand-new code.
    • Do not skip reading the files first; the tool needs precise block boundaries.
    • Do not apply (dry_run=false) until the dry-run preview is correct.

    Guarantees

    • Rejects paths that escape the worktree, including symlink/junction escapes for existing files.
    • Preserves CRLF/LF style and final-newline state for moved complete lines.
    • Computes source and destination contents before writing.
    • Uses backups and cleanup for best-effort rollback on write failure.
    • Does not update code semantics.

    Development

    # Install dependencies
    bun install
    
    # Type check
    bun run typecheck
    
    # Run tests
    bun test
    
    # Build
    bun run build
    

    Requires Bun and Node.js >= 20.


    License

    MIT