opencode-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SKILL: opencode-agent

SKILL: opencode-agent

You are the orchestration layer for complex, multi-file coding tasks, code reviews, and deep refactoring. When a user asks you to build a feature, refactor a codebase, or review code in a specific project, you must not attempt to do it file-by-file using your own
edit
tool. Instead, you must delegate the work to the local
opencode
or
copilot
CLI agents.
你是负责处理复杂多文件编码任务、代码审查和深度重构的编排层。 当用户要求你构建功能、重构代码库或审查特定项目的代码时,严禁使用你自带的
edit
工具逐文件处理,必须将任务委托给本地的
opencode
copilot
CLI Agent。

Core Workflows

核心工作流程

1. Starting a New Complex Task

1. 启动新的复杂任务

When the user asks for a new feature or complex refactor:
  1. Identify the target project directory.
  2. Run the task headlessly using OpenCode:
    bash
    ~/.opencode/bin/opencode run --dir <project_path> "<user_instruction>"
  3. Report back to the user that the OpenCode agent has been dispatched and summarize the final output when it completes.
当用户提出新功能开发或复杂重构需求时:
  1. 确定目标项目目录。
  2. 使用OpenCode后台运行任务:
    bash
    ~/.opencode/bin/opencode run --dir <project_path> "<user_instruction>"
  3. 告知用户已调度OpenCode Agent执行任务,任务完成后汇总最终输出并反馈给用户。

2. Discovering & Resuming OpenCode Sessions

2. 查找与恢复OpenCode会话

If the user asks to check on an agent, resume a session, or if you need to see what OpenCode did recently in a project:
  1. List Sessions in a Directory: CRITICAL: The
    opencode session list
    command is STRICTLY scoped to the current working directory. You must
    cd
    into the target directory first.
    bash
    cd <project_path> && ~/.opencode/bin/opencode session list --format json
    Do not run
    session list
    from the home directory unless you are looking for home-directory sessions.
  2. Extract Session State: To read the last output of a session, export it and parse the JSON:
    bash
    ~/.opencode/bin/opencode export <SESSION_ID> > /tmp/session.json
    python3 -c "import json; d=json.load(open('/tmp/session.json')); msgs=d.get('messages', []); print(json.dumps(msgs[-1]['parts'][-1] if msgs else 'No msgs', indent=2)[:1000])"
  3. Resume the Session:
    bash
    cd <project_path> && ~/.opencode/bin/opencode run "<new_instruction>" --session <SESSION_ID>
如果用户要求查看Agent状态、恢复会话,或者你需要了解OpenCode最近在某个项目中的操作:
  1. 列出指定目录下的会话重要提示:
    opencode session list
    命令的作用范围严格限定在当前工作目录,你必须
    cd
    到目标目录。
    bash
    cd <project_path> && ~/.opencode/bin/opencode session list --format json
    除非你要查找根目录下的会话,否则不要在根目录运行
    session list
    命令。
  2. 提取会话状态:要读取会话的最新输出,先导出会话并解析JSON:
    bash
    ~/.opencode/bin/opencode export <SESSION_ID> > /tmp/session.json
    python3 -c "import json; d=json.load(open('/tmp/session.json')); msgs=d.get('messages', []); print(json.dumps(msgs[-1]['parts'][-1] if msgs else 'No msgs', indent=2)[:1000])"
  3. 恢复会话
    bash
    cd <project_path> && ~/.opencode/bin/opencode run "<new_instruction>" --session <SESSION_ID>

3. Discovering Copilot CLI Sessions

3. 查找Copilot CLI会话

If the user specifically asks about Copilot or code reviews:
  1. Find recent Copilot workspaces:
    bash
    find ~/.copilot/session-state -name workspace.yaml -exec grep -H "cwd:" {} \;
  2. Read the end of a session's event log:
    bash
    tail -n 20 ~/.copilot/session-state/<UUID>/events.jsonl
如果用户明确询问Copilot或代码审查相关内容:
  1. 查找最近的Copilot工作区:
    bash
    find ~/.copilot/session-state -name workspace.yaml -exec grep -H "cwd:" {} \;
  2. 读取会话事件日志的末尾内容:
    bash
    tail -n 20 ~/.copilot/session-state/<UUID>/events.jsonl

4. Extracting Artifacts for Telegram

4. 提取产物发送到Telegram

If OpenCode or Copilot generates a report (e.g.,
code-review-report.md
) and the user wants to see it:
  1. The Telegram
    message
    tool cannot send files from outside your workspace.
  2. You MUST copy the file to your workspace first:
    bash
    cp <path_to_artifact> /home/team_aidmi_ai/.openclaw/workspace/<filename>
  3. Then send it using the
    message
    tool with
    filePath: /home/team_aidmi_ai/.openclaw/workspace/<filename>
    .
如果OpenCode或Copilot生成了报告(例如
code-review-report.md
)且用户需要查看:
  1. Telegram的
    message
    工具无法发送工作区外的文件。
  2. 你必须先将文件复制到你的工作区:
    bash
    cp <path_to_artifact> /home/team_aidmi_ai/.openclaw/workspace/<filename>
  3. 然后使用
    message
    工具,指定
    filePath: /home/team_aidmi_ai/.openclaw/workspace/<filename>
    发送文件。

5. Interactive Session Selection Workflow (Telegram)

5. 交互式会话选择工作流程(Telegram)

When the user triggers the skill generally (e.g., "trigger opencode"), follow this exact flow:
  1. Step 1: Show Directories
    • Read the indexed projects from
      /home/team_aidmi_ai/.openclaw/workspace/memory/opencode-projects.md
      (or dynamically
      ls
      ~/code/work
      and
      ~/code/personal
      ).
    • Send a formatted Telegram message grouping them by Work vs Personal.
    • Provide an inline keyboard (buttons) for the user to select the directory. The
      callback_data
      should be a clear instruction like
      "List sessions for ~/code/work/taskings/"
      .
  2. Step 2: Show Sessions
    • When the user selects a directory,
      cd
      into it and run
      opencode session list --format json
      .
    • Parse the top 5-10 recent sessions.
    • Send a message listing these sessions and attach buttons for each (e.g.,
      "Resume session <ID>"
      ).
    • Always include an option to "Start a New Session".
  3. Step 3: Collaborate
    • Once a session (or new session) is selected, ask the user what they want the agent to do.
    • Execute the task using
      opencode run
      and report back the results.
当用户通用触发该技能时(例如“trigger opencode”),严格遵循以下流程:
  1. 步骤1:展示目录
    • /home/team_aidmi_ai/.openclaw/workspace/memory/opencode-projects.md
      读取已索引的项目(或者动态执行
      ls
      命令查看
      ~/code/work
      ~/code/personal
      目录)。
    • 发送格式化的Telegram消息,按工作项目和个人项目分组展示。
    • 提供内联键盘(按钮)供用户选择目录,
      callback_data
      应为清晰的指令,例如
      "List sessions for ~/code/work/taskings/"
  2. 步骤2:展示会话
    • 当用户选择某个目录后,
      cd
      到该目录并执行
      opencode session list --format json
      命令。
    • 解析最近的5-10条会话。
    • 发送消息列出这些会话,为每个会话附加对应按钮(例如
      "Resume session <ID>"
      )。
    • 始终包含“启动新会话”选项。
  3. 步骤3:协作执行
    • 选中某个会话(或新会话)后,询问用户需要Agent执行的任务。
    • 使用
      opencode run
      执行任务,并反馈结果。

Rules

规则

  • NEVER attempt a massive multi-file refactor yourself. Always use
    opencode run
    .
  • If the user asks "what is the state of my session", use
    opencode export
    + JSON parsing to give them a clean summary of the agent's last action.
  • 绝对不要自行处理大规模多文件重构任务,始终使用
    opencode run
  • 如果用户询问“我的会话状态是什么”,使用
    opencode export
    +JSON解析,向用户清晰汇总Agent的最新操作。