setup-environment

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Environment Setup Skill

环境配置Skill

Automatically configure a new user's local development environment for App Factory.
自动为App Factory新用户配置本地开发环境。

When This Skill Applies

适用场景

  • User says
    /setup
    , "set me up", or "configure my environment"
  • User asks "how do I get started" or "what do I need to install"
  • First-time contributor onboarding
  • 用户输入/setup、“set me up”或“configure my environment”
  • 用户询问“我该如何开始”或“我需要安装什么”
  • 首次贡献者入职引导

Setup Procedure

配置流程

When triggered, execute the following checks in order. Skip tools that are already installed and at the correct version. Show a plan before executing any installations.
触发后,按顺序执行以下检查。跳过已安装且版本符合要求的工具。在执行任何安装操作前,先展示计划。

Phase 1: Core Requirements (BLOCKING)

阶段1:核心依赖(阻塞项)

These MUST pass before proceeding. If any fail, show the fix and stop.
这些必须通过才能继续。若有任何一项失败,显示修复方案并停止流程。

1.1 Node.js (>= 18.0.0)

1.1 Node.js (>= 18.0.0)

bash
node --version 2>/dev/null
  • PASS: Version >= 18.0.0
  • FAIL: Prompt user to install via
    brew install node
    (macOS),
    nvm install 18
    , or https://nodejs.org
bash
node --version 2>/dev/null

1.2 npm

1.2 npm

bash
npm --version 2>/dev/null
  • PASS: Any version (ships with Node.js)
  • FAIL: Reinstall Node.js
bash
npm --version 2>/dev/null
  • 通过:任意版本(随Node.js附带)
  • 失败:重新安装Node.js

1.3 Git

1.3 Git

bash
git --version 2>/dev/null
  • PASS: Any version 2.x+
  • FAIL:
    xcode-select --install
    (macOS) or
    sudo apt-get install git
    (Linux)
bash
git --version 2>/dev/null
  • 通过:任意2.x+版本
  • 失败:执行
    xcode-select --install
    (macOS)或
    sudo apt-get install git
    (Linux)

1.4 Claude Code CLI

1.4 Claude Code CLI

bash
claude --version 2>/dev/null
  • PASS: Any version
  • FAIL:
    npm install -g @anthropic-ai/claude-code
bash
claude --version 2>/dev/null
  • 通过:任意版本
  • 失败:执行
    npm install -g @anthropic-ai/claude-code

Phase 2: Repository Integrity

阶段2:代码仓库完整性

Verify the repo is intact and all 6 pipelines are present.
验证仓库是否完整,所有6条流水线是否存在。

2.1 Pipeline Directories

2.1 流水线目录

Check each directory exists and contains a CLAUDE.md:
app-factory/CLAUDE.md
website-pipeline/CLAUDE.md
dapp-factory/CLAUDE.md
agent-factory/CLAUDE.md
plugin-factory/CLAUDE.md
miniapp-pipeline/CLAUDE.md
  • PASS: All 6 exist
  • WARN: Missing pipelines (list which ones)
检查每个目录是否存在且包含CLAUDE.md文件:
app-factory/CLAUDE.md
website-pipeline/CLAUDE.md
dapp-factory/CLAUDE.md
agent-factory/CLAUDE.md
plugin-factory/CLAUDE.md
miniapp-pipeline/CLAUDE.md
  • 通过:全部6个目录均存在
  • 警告:列出缺失的流水线

2.2 Core Infrastructure

2.2 核心基础设施

Check these critical files/directories exist:
plugins/factory/commands/factory.md
scripts/local-run-proof/verify.mjs
scripts/factory_ready_check.sh
core/package.json
.claude/settings.json
.mcp.json
  • PASS: All present
  • WARN: List missing files with remediation
检查以下关键文件/目录是否存在:
plugins/factory/commands/factory.md
scripts/local-run-proof/verify.mjs
scripts/factory_ready_check.sh
core/package.json
.claude/settings.json
.mcp.json
  • 通过:全部存在
  • 警告:列出缺失文件及修复方案

Phase 3: Dependencies

阶段3:依赖项

3.1 Root npm Install

3.1 根目录npm安装

bash
undefined
bash
undefined

Check if node_modules exists

检查node_modules是否存在

ls node_modules/.package-lock.json 2>/dev/null

- **PASS**: node_modules exists and is populated
- **ACTION**: Run `npm install` at repository root (requires user approval)
ls node_modules/.package-lock.json 2>/dev/null

- **通过**:node_modules存在且已填充内容
- **操作**:在仓库根目录执行`npm install`(需用户批准)

3.2 Husky Git Hooks

3.2 Husky Git钩子

bash
ls .husky/_/husky.sh 2>/dev/null
  • PASS: Husky hooks installed
  • ACTION: Run
    npx husky install
    (requires user approval)
bash
ls .husky/_/husky.sh 2>/dev/null
  • 通过:已安装Husky钩子
  • 操作:执行
    npx husky install
    (需用户批准)

Phase 4: Environment Configuration

阶段4:环境配置

4.1 Environment Variables

4.1 环境变量

bash
undefined
bash
undefined

Check .env exists

检查.env是否存在

test -f .env

- **PASS**: .env exists
- **ACTION**: Copy from .env.example → .env, then prompt user to fill in ANTHROPIC_API_KEY
test -f .env

- **通过**:.env文件存在
- **操作**:从.env.example复制到.env,然后提示用户填写ANTHROPIC_API_KEY

4.2 MCP Server Configuration

4.2 MCP服务器配置

Check
.mcp.json
exists and
.claude/settings.json
has MCP servers enabled:
github, playwright, filesystem, context7, semgrep
  • PASS: Configuration files present and servers listed
  • WARN: Missing servers with instructions to enable
检查
.mcp.json
是否存在,且
.claude/settings.json
中已启用以下MCP服务器:
github, playwright, filesystem, context7, semgrep
  • 通过:配置文件存在且已列出所有服务器
  • 警告:列出缺失的服务器及启用说明

Phase 5: Optional Tools (Non-Blocking)

阶段5:可选工具(非阻塞项)

These improve the development experience but are not required.
这些工具可提升开发体验,但非必需。

5.1 watchman (for Expo/React Native hot reload)

5.1 watchman(用于Expo/React Native热重载)

bash
watchman --version 2>/dev/null
  • PASS: Installed
  • SKIP: Not installed (suggest
    brew install watchman
    on macOS)
  • Only relevant if user plans to use app-factory
bash
watchman --version 2>/dev/null
  • 通过:已安装
  • 跳过:未安装(建议macOS用户执行
    brew install watchman
  • 仅当用户计划使用app-factory时相关

5.2 Xcode Command Line Tools (macOS only)

5.2 Xcode命令行工具(仅macOS)

bash
xcode-select -p 2>/dev/null
  • PASS: Installed
  • SKIP: Not installed (suggest
    xcode-select --install
    )
  • Only relevant on macOS for iOS simulator preview
bash
xcode-select -p 2>/dev/null
  • 通过:已安装
  • 跳过:未安装(建议执行
    xcode-select --install
  • 仅对macOS用户的iOS模拟器预览功能相关

5.3 Development Tools Check

5.3 开发工具检查

Verify these work from root package.json scripts:
bash
npx eslint --version 2>/dev/null
npx prettier --version 2>/dev/null
npx tsc --version 2>/dev/null
  • PASS: All return versions
  • WARN: Missing tools (will be available after npm install)
验证仓库根目录package.json中的以下脚本可正常运行:
bash
npx eslint --version 2>/dev/null
npx prettier --version 2>/dev/null
npx tsc --version 2>/dev/null
  • 通过:全部返回版本信息
  • 警告:列出缺失工具(执行npm install后将可用)

Phase 6: Validation

阶段6:验证

Run the validation script to confirm everything:
bash
bash scripts/validate-setup.sh
运行验证脚本确认所有配置:
bash
bash scripts/validate-setup.sh

Output: Status Report

输出:状态报告

After all phases, display a summary table:
============================================================
  App Factory Environment Setup Report
============================================================

  Core Requirements:
    Node.js 18+          PASS  (v20.11.0)
    npm                  PASS  (v10.2.4)
    Git                  PASS  (v2.43.0)
    Claude Code CLI      PASS  (v1.x.x)

  Repository Integrity:
    app-factory          PASS
    website-pipeline     PASS
    dapp-factory         PASS
    agent-factory        PASS
    plugin-factory       PASS
    miniapp-pipeline     PASS
    Core infrastructure  PASS

  Dependencies:
    npm install          PASS
    Husky hooks          PASS

  Environment:
    .env file            PASS
    MCP servers          PASS  (5/5 configured)

  Optional Tools:
    watchman             SKIP  (not needed unless using app-factory)
    Xcode CLI Tools      PASS  (macOS)
    ESLint               PASS
    Prettier             PASS
    TypeScript           PASS

============================================================
  Result: READY

  You're all set! Next steps:
  1. Run /factory help to see available commands
  2. Run ./quickstart.sh for an interactive guide
  3. cd into any pipeline directory and run claude
============================================================
完成所有阶段后,显示汇总表格:
============================================================
  App Factory环境配置报告
============================================================

  核心依赖:
    Node.js 18+          通过  (v20.11.0)
    npm                  通过  (v10.2.4)
    Git                  通过  (v2.43.0)
    Claude Code CLI      通过  (v1.x.x)

  仓库完整性:
    app-factory          通过
    website-pipeline     通过
    dapp-factory         通过
    agent-factory        通过
    plugin-factory       通过
    miniapp-pipeline     通过
    核心基础设施          通过

  依赖项:
    npm install          通过
    Husky钩子            通过

  环境配置:
    .env文件            通过
    MCP服务器            通过  (已配置5/5)

  可选工具:
    watchman             跳过  (仅使用app-factory时需要)
    Xcode CLI工具        通过  (macOS)
    ESLint               通过
    Prettier             通过
    TypeScript           通过

============================================================
  结果:已就绪

  配置完成!下一步:
  1. 运行/factory help查看可用命令
  2. 执行./quickstart.sh获取交互式引导
  3. 进入任意流水线目录并运行claude
============================================================

Critical Rules

关键规则

  1. Show plan first - Never install anything without showing what will happen
  2. Require approval - Ask before running npm install or brew install
  3. Skip installed tools - Never reinstall something that's already at the right version
  4. Non-destructive - Never overwrite existing .env files (only create if missing)
  5. Parallel where safe - Version checks can run in parallel; installations must be sequential
  6. Respect invariants - All 8 App Factory invariants apply (no silent execution, mandatory approval, etc.)
  7. macOS awareness - Detect platform and adjust commands accordingly (brew vs apt)
  8. Graceful degradation - Optional tools failing should not block setup completion
  1. 先展示计划 - 未告知用户操作内容前,绝不执行任何安装
  2. 需用户批准 - 执行npm install或brew install前需征得用户同意
  3. 跳过已安装工具 - 绝不重新安装已符合版本要求的工具
  4. 非破坏性操作 - 绝不覆盖已存在的.env文件(仅在缺失时创建)
  5. 安全并行 - 版本检查可并行执行;安装操作必须按顺序进行
  6. 遵守约束 - 需遵循App Factory的8项约束(无静默执行、必须批准等)
  7. 适配macOS - 检测平台并调整命令(brew vs apt)
  8. 优雅降级 - 可选工具失败不应阻塞配置流程完成

Error Recovery

错误恢复

If any BLOCKING check fails:
  1. Show the specific error
  2. Provide the exact fix command
  3. Ask user to fix and re-run
    /setup
  4. Do NOT attempt to continue past blocking failures
If any OPTIONAL check fails:
  1. Mark as SKIP in the report
  2. Note what functionality is affected
  3. Continue with remaining checks
若任何阻塞项检查失败:
  1. 显示具体错误信息
  2. 提供精确的修复命令
  3. 请用户修复后重新运行/setup
  4. 绝不在阻塞项失败后继续流程
若任何可选项检查失败:
  1. 在报告中标记为“跳过”
  2. 注明受影响的功能
  3. 继续执行剩余检查