terminal-execution

majiayu000 的头像作者 majiayu000

可靠的终端命令执行和输出捕获的最佳实践。运行 shell 命令时,尤其是在 WSL 等输出可能被截断或丢失的环境中,请使用此技能,以确保正确捕获和检查结果。

📖 中文导读:可靠的终端命令执行和输出捕获的最佳实践。运行 shell 命令时,尤其是在 WSL 等输出可能被截断或丢失的环境中,请使用此技能,以确保正确捕获和检查结果。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: terminal-execution description: Best practices for reliable terminal command execution and output capture. Use this skill when running shell commands, especially in environments like WSL where output might be truncated or lost, to ensure results are properly captured and inspected. metadata: short-description: Reliable command execution & output capture

Terminal Execution Guidelines

This skill defines the standard workflows for executing terminal commands to ensure reliability and visibility of outputs, particularly in complex environments like WSL.

1. Primary Execution Method

Always prioritize structured execution tools over raw terminal input when possible.

  1. Use execute_command: Call the execute_command tool from the terminal-runner MCP server. This provides the most reliable way to get exit codes and standard output programmatically.
  2. Fallback: If terminal-runner is unavailable, use the standard run_in_terminal tool.

2. Handling Missing Output (WSL/Complex Environments)

In some environments (like WSL), terminal output may not be returned to the agent context correctly, or it may be truncated. If you suspect output is missing:

File-Based Capture Workflow

  1. Prepare Directory: Ensure .tmp/copilot/ exists.
  2. Redirect Output: Run the command redirecting both stdout and stderr to a file.
  3. Read Result: Use file reading tools to inspect the output.

Common Patterns

Capture stdout and stderr:

some-command > .tmp/copilot/output.txt 2>&1

Capture and view live (if interactive):

some-command 2>&1 | tee .tmp/copilot/output.txt

Capture exit code separately:

some-command > .tmp/copilot/output.txt 2>&1; echo $? > .tmp/copilot/exit-code.txt

3. Best Practices

  • File Naming: Use descriptive names for capture files (e.g., .tmp/copilot/build-log.txt, .tmp/copilot/test-results.txt).
  • Cleanup: Periodically clean up the .tmp/copilot/ directory to avoid confusion with stale data.