Features: - Ask user whether to configure CLAUDE.md - Support both user-level and project-level configuration - For project-level: prompt for target directory - Append content (never overwrite existing files) - Detect existing configuration to avoid duplicates - Auto-create project constitution section for new files Scripts updated: - install.sh (macOS/Linux) - install.ps1 (Windows PowerShell) Co-Authored-By: Claude <noreply@anthropic.com>
245 lines
8.5 KiB
PowerShell
245 lines
8.5 KiB
PowerShell
# Claude Code Skills 安装脚本 (Windows)
|
||
# 用法: irm https://git.let5see.xyz/let5see/skills/raw/main/install.ps1 | iex
|
||
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
$RepoUrl = "https://git.let5see.xyz/let5see/skills.git"
|
||
$TempDir = Join-Path $env:TEMP "skills-install-$(Get-Random)"
|
||
$SkillsDir = Join-Path $env:USERPROFILE ".claude\skills"
|
||
|
||
$ClaudeMdContent = @"
|
||
## Codex 协作配置
|
||
|
||
本项目使用 `codex-collab` skill 进行 Codex CLI 协作。
|
||
|
||
### 快速安装
|
||
|
||
```powershell
|
||
irm https://git.let5see.xyz/let5see/skills/raw/main/install.ps1 | iex
|
||
```
|
||
|
||
### 核心原则
|
||
|
||
**指导原则**:
|
||
- Codex 是协作伙伴,而非唯一真理来源
|
||
- 必须有独立思考,对 Codex 的建议保持批判性审视
|
||
- 通过辩论和讨论达成最优方案
|
||
|
||
**职责分工**:
|
||
- **Claude Code**:代码编写、文档编写、简单任务直接执行
|
||
- **Codex**:代码查找定位、逻辑梳理、代码审查、方案设计、问题诊断
|
||
|
||
**关键规范**:
|
||
- 查找/搜索任务 → 必须调用 Codex
|
||
- 方案设计阶段 → 使用 `sandbox="read-only"`
|
||
- 代码实现 → Claude Code 基于方案重写生产级代码
|
||
- 完成编码后 → 立即让 Codex 审查
|
||
|
||
### 详细文档
|
||
|
||
参考:`$env:USERPROFILE\.claude\skills\codex-collab\SKILL.md`
|
||
或在线查看:https://git.let5see.xyz/let5see/skills
|
||
|
||
---
|
||
"@
|
||
|
||
Write-Host "🚀 正在安装 Claude Code Skills..." -ForegroundColor Green
|
||
Write-Host ""
|
||
|
||
# 检查 git 是否安装
|
||
Write-Host "🔍 检查 Git..." -ForegroundColor Yellow
|
||
try {
|
||
$null = git --version
|
||
Write-Host " ✓ Git 已安装" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host " ✗ 未找到 Git,请先安装 Git: https://git-scm.com/download/win" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 创建临时目录
|
||
Write-Host "📦 下载 skills..." -ForegroundColor Yellow
|
||
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null
|
||
|
||
# 克隆仓库
|
||
try {
|
||
git clone "$RepoUrl" "$TempDir" --depth 1 --quiet
|
||
Write-Host " ✓ 下载完成" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host " ✗ 下载失败: $_" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 确保 skills 目录存在
|
||
New-Item -ItemType Directory -Path $SkillsDir -Force | Out-Null
|
||
|
||
# 复制所有 skills
|
||
Write-Host "📋 安装 skills..." -ForegroundColor Yellow
|
||
|
||
$skillDirs = Get-ChildItem -Path $TempDir -Directory
|
||
$installedCount = 0
|
||
|
||
foreach ($skillDir in $skillDirs) {
|
||
$skillName = $skillDir.Name
|
||
$skillMd = Join-Path $skillDir.FullName "SKILL.md"
|
||
|
||
if (Test-Path $skillMd) {
|
||
$destPath = Join-Path $SkillsDir $skillName
|
||
|
||
# 如果已存在,先删除
|
||
if (Test-Path $destPath) {
|
||
Remove-Item -Recurse -Force $destPath
|
||
}
|
||
|
||
Copy-Item -Recurse -Force $skillDir.FullName $destPath
|
||
Write-Host " ✓ $skillName" -ForegroundColor Green
|
||
$installedCount++
|
||
} else {
|
||
Write-Host " ⚠ 跳过 $skillName (缺少 SKILL.md)" -ForegroundColor Yellow
|
||
}
|
||
}
|
||
|
||
# 清理临时文件
|
||
Remove-Item -Recurse -Force $TempDir
|
||
|
||
Write-Host ""
|
||
Write-Host "✅ Skills 安装完成!" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "已安装 $installedCount 个 skills:" -ForegroundColor Cyan
|
||
|
||
Get-ChildItem -Path $SkillsDir -Directory | ForEach-Object {
|
||
Write-Host " - $($_.Name)" -ForegroundColor White
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "────────────────────────────────────────" -ForegroundColor Cyan
|
||
Write-Host "📝 是否要配置 Codex 协作规则到 CLAUDE.md?" -ForegroundColor Yellow
|
||
Write-Host ""
|
||
Write-Host "这将帮助 Claude Code 更好地与 Codex 协作。" -ForegroundColor Gray
|
||
Write-Host "不会被覆盖现有内容,只会追加配置。" -ForegroundColor Gray
|
||
Write-Host ""
|
||
Write-Host " [1] 用户级配置 (~/.claude/CLAUDE.md) - 所有项目生效" -ForegroundColor White
|
||
Write-Host " [2] 项目级配置 (./CLAUDE.md) - 仅当前项目生效" -ForegroundColor White
|
||
Write-Host " [0] 跳过配置" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "────────────────────────────────────────" -ForegroundColor Cyan
|
||
|
||
$choice = Read-Host "请选择 [0/1/2]"
|
||
|
||
switch ($choice) {
|
||
"1" {
|
||
# 用户级配置
|
||
$ClaudeMdPath = Join-Path $env:USERPROFILE ".claude\CLAUDE.md"
|
||
Write-Host ""
|
||
Write-Host "📄 写入用户级配置: $ClaudeMdPath" -ForegroundColor Cyan
|
||
|
||
# 创建目录(如果不存在)
|
||
$claudeDir = Split-Path $ClaudeMdPath -Parent
|
||
if (-not (Test-Path $claudeDir)) {
|
||
New-Item -ItemType Directory -Path $claudeDir -Force | Out-Null
|
||
}
|
||
|
||
# 检查文件是否已存在
|
||
if (Test-Path $ClaudeMdPath) {
|
||
# 检查是否已包含配置标记
|
||
$content = Get-Content $ClaudeMdPath -Raw
|
||
if ($content -match "## Codex 协作配置") {
|
||
Write-Host " ⚠ 检测到已存在 Codex 协作配置,跳过写入" -ForegroundColor Yellow
|
||
} else {
|
||
# 追加配置
|
||
Add-Content -Path $ClaudeMdPath -Value "`n$ClaudeMdContent"
|
||
Write-Host " ✓ 配置已追加到文件末尾" -ForegroundColor Green
|
||
}
|
||
} else {
|
||
# 创建新文件
|
||
$projectConstitution = @"
|
||
## 项目宪法遵循规则(最高优先级)
|
||
|
||
进入任何项目目录时,**必须首先**执行以下检查:
|
||
|
||
1. 检查项目根目录是否存在 `CLAUDE.md` 文件
|
||
2. 若存在,**完整阅读**该文件内容
|
||
3. 将其作为该项目的"宪法",严格遵循其中定义的所有规则
|
||
|
||
**优先级规则**:
|
||
- 项目级 `CLAUDE.md` > 本全局配置
|
||
- 若规则冲突,以项目级为准
|
||
|
||
"@
|
||
Set-Content -Path $ClaudeMdPath -Value "$projectConstitution`n$ClaudeMdContent"
|
||
Write-Host " ✓ 已创建新配置文件" -ForegroundColor Green
|
||
}
|
||
}
|
||
|
||
"2" {
|
||
# 项目级配置
|
||
Write-Host ""
|
||
$projectDirInput = Read-Host "请输入项目目录路径 (默认为当前目录)"
|
||
$projectDir = if ([string]::IsNullOrWhiteSpace($projectDirInput)) {
|
||
Get-Location
|
||
} else {
|
||
$projectDirInput
|
||
}
|
||
|
||
# 转换为绝对路径
|
||
$projectDir = (Resolve-Path $projectDir).Path
|
||
$ClaudeMdPath = Join-Path $projectDir "CLAUDE.md"
|
||
|
||
Write-Host ""
|
||
Write-Host "📄 写入项目级配置: $ClaudeMdPath" -ForegroundColor Cyan
|
||
|
||
# 检查目录是否存在
|
||
if (-not (Test-Path $projectDir)) {
|
||
Write-Host " ✗ 错误: 目录不存在: $projectDir" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
# 检查文件是否已存在
|
||
if (Test-Path $ClaudeMdPath) {
|
||
# 检查是否已包含配置标记
|
||
$content = Get-Content $ClaudeMdPath -Raw
|
||
if ($content -match "## Codex 协作配置") {
|
||
Write-Host " ⚠ 检测到已存在 Codex 协作配置,跳过写入" -ForegroundColor Yellow
|
||
} else {
|
||
# 追加配置
|
||
Add-Content -Path $ClaudeMdPath -Value "`n$ClaudeMdContent"
|
||
Write-Host " ✓ 配置已追加到文件末尾" -ForegroundColor Green
|
||
}
|
||
} else {
|
||
# 创建新文件
|
||
$projectConstitution = @"
|
||
## 项目宪法遵循规则(最高优先级)
|
||
|
||
进入任何项目目录时,**必须首先**执行以下检查:
|
||
|
||
1. 检查项目根目录是否存在 `CLAUDE.md` 文件
|
||
2. 若存在,**完整阅读**该文件内容
|
||
3. 将其作为该项目的"宪法",严格遵循其中定义的所有规则
|
||
|
||
**优先级规则**:
|
||
- 项目级 `CLAUDE.md` > 用户级配置
|
||
- 若规则冲突,以项目级为准
|
||
|
||
"@
|
||
Set-Content -Path $ClaudeMdPath -Value "$projectConstitution`n$ClaudeMdContent"
|
||
Write-Host " ✓ 已创建新配置文件" -ForegroundColor Green
|
||
}
|
||
}
|
||
|
||
"0" {
|
||
Write-Host ""
|
||
Write-Host "⏭ 跳过配置" -ForegroundColor Yellow
|
||
}
|
||
|
||
default {
|
||
Write-Host ""
|
||
Write-Host "⚠ 无效选择,跳过配置" -ForegroundColor Yellow
|
||
}
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "────────────────────────────────────────" -ForegroundColor Cyan
|
||
Write-Host "🎉 安装完成!" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "提示: 重启 Claude Code 以加载新的 skills" -ForegroundColor Yellow
|
||
Write-Host "────────────────────────────────────────" -ForegroundColor Cyan
|