command-execution

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Command Execution Guidelines

命令执行指南

This is a strict guideline. Follow these rules exactly.
Guidelines for AI agents when executing commands and running scripts.

这是一份严格的指南。 请严格遵守以下规则。
本指南用于指导AI Agent执行命令与运行脚本的操作。

Core Rules

核心规则

1. Never Run Project Tools on the Host Machine

1. 永远不要在宿主机器上运行项目工具

The host machine stays pristine. All project tools (pnpm, npm, python, pip, pytest, cargo, etc.) live inside devcontainers. Never install packages, run builds, or execute project commands directly on the host.
If you need to run something in a project, use the devcontainer:
bash
undefined
宿主机器必须保持纯净。 所有项目工具(pnpm、npm、python、pip、pytest、cargo等)都应在devcontainers内部运行。永远不要直接在宿主机器上安装依赖包、执行构建操作或者运行项目命令。
如果你需要在项目中运行命令,请使用devcontainer:
bash
undefined

✅ Correct: execute inside the container

✅ 正确:在容器内部执行

docker exec -it <container_name> pnpm install docker exec -it <container_name> pnpm build docker exec -it <container_name> pytest
docker exec -it <container_name> pnpm install docker exec -it <container_name> pnpm build docker exec -it <container_name> pytest

❌ NEVER: run project tools on the host

❌ 严禁:在宿主机器上运行项目工具

pnpm install # installs to host, pollutes system pip install requests # modifies host Python npm run build # uses host Node version, may differ from container

**Exceptions** (tools that are OK on the host):
- `git` — version control is host-level
- `docker` / `docker compose` — managing containers
- `gh` — GitHub CLI for repo operations
- `npx skills` — skill installation (doesn't modify project deps)
- File operations (`cat`, `ls`, `grep`, `find`, etc.)

**When working across multiple projects from outside containers**, limit yourself to reading files, git operations, and docker commands. If you need to build/test/install, exec into the container.
pnpm install # 安装到宿主机器,污染系统环境 pip install requests # 修改宿主机器的Python环境 npm run build # 使用宿主机器的Node版本,可能与容器内版本不一致

**例外情况**(允许在宿主机器上运行的工具):
- `git` — 版本控制属于宿主级操作
- `docker` / `docker compose` — 用于管理容器
- `gh` — 用于代码库操作的GitHub CLI
- `npx skills` — skill安装(不会修改项目依赖)
- 文件操作命令(`cat`、`ls`、`grep`、`find`等)

**当你需要在容器外处理多个项目时,仅允许进行文件读取、git操作和docker命令。如果你需要执行构建/测试/安装操作,请进入容器内执行。**

2. Use Project's Developer API

2. 使用项目的开发者API

Always use root
package.json
scripts:
bash
undefined
始终使用根目录下
package.json
中定义的脚本:
bash
undefined

✅ Correct

✅ 正确

pnpm lint pnpm provision:dev pnpm build:frontend
pnpm lint pnpm provision:dev pnpm build:frontend

❌ Wrong

❌ 错误

cd infrastructure && npx cdk deploy cd frontend && npm run build

**Why**: Root scripts are the developer API. Bypassing them means the API can break without anyone noticing.
cd infrastructure && npx cdk deploy cd frontend && npm run build

**原因**:根目录脚本就是开发者API。绕过这些脚本执行命令会导致API出现问题却无人察觉。

2. Never Use
cd

2. 永远不要使用
cd
命令

bash
undefined
bash
undefined

❌ Wrong

❌ 错误

cd infrastructure && pnpm synth
cd infrastructure && pnpm synth

✅ Correct

✅ 正确

pnpm synth:dev
pnpm synth:dev

✅ Or use working_dir parameter

✅ 或者使用working_dir参数

execute_bash(command="pnpm synth", working_dir="infrastructure")

**Why**: `cd` doesn't persist. Use root scripts or `working_dir` parameter.
execute_bash(command="pnpm synth", working_dir="infrastructure")

**原因**:`cd`命令的效果不会持久化。请使用根目录脚本或者`working_dir`参数。

3. Discover Scripts First

3. 先查看可用脚本

bash
undefined
bash
undefined

Check available scripts

查看可用的脚本

cat package.json | grep -A 50 '"scripts"'

Look for: `lint`, `test`, `build`, `provision:*`, `deploy:*`

---
cat package.json | grep -A 50 '"scripts"'

查找包含以下关键词的脚本:`lint`、`test`、`build`、`provision:*`、`deploy:*`

---

Installation

安装依赖

bash
undefined
bash
undefined

✅ Workspace root (shared)

✅ 工作区根目录(共享依赖)

pnpm add -D -w eslint
pnpm add -D -w eslint

✅ Specific workspace

✅ 指定工作区

pnpm add -D eslint --filter frontend
pnpm add -D eslint --filter frontend

❌ Wrong

❌ 错误

cd frontend && pnpm add eslint

---
cd frontend && pnpm add eslint

---

When Direct Execution is Necessary

必须直接执行命令的情况

  1. Check if root script exists first
  2. Use
    working_dir
    parameter if available
  3. Document why you're not using root scripts

  1. 首先检查是否存在对应的根目录脚本
  2. 如果支持的话使用
    working_dir
    参数
  3. 记录你不使用根目录脚本的原因

Summary

总结

Golden Rules:
  1. ✅ Use root
    package.json
    scripts (the developer API)
  2. ✅ Never use
    cd
    in commands
  3. ✅ Check available scripts first
  4. ✅ Use
    working_dir
    parameter for direct execution
Remember: Root scripts are the project's public API. Bypassing them breaks the contract.

黄金规则:
  1. ✅ 使用根目录
    package.json
    脚本(即开发者API)
  2. ✅ 永远不要在命令中使用
    cd
  3. ✅ 首先查看可用的脚本
  4. ✅ 直接执行命令时使用
    working_dir
    参数
注意:根目录脚本是项目的公开API。绕过它们会打破约定。

Progressive Improvement

持续改进

If the developer corrects a behavior that this skill should have prevented, suggest a specific amendment to this skill to prevent the same correction in the future.
如果开发者纠正了本skill本应避免的行为,请提出针对本skill的具体修改建议,避免未来再出现相同的问题。