Skip to content

Instantly share code, notes, and snippets.

@Xxxdxs
Last active June 1, 2026 08:27
Show Gist options
  • Select an option

  • Save Xxxdxs/bba41bdcaade49ec4597a1e9dce66441 to your computer and use it in GitHub Desktop.

Select an option

Save Xxxdxs/bba41bdcaade49ec4597a1e9dce66441 to your computer and use it in GitHub Desktop.
Multi-Agent Skills Setup Script (install.ps1)
# install.ps1 — 声明式快速环境部署脚本
# 用法:
# 1. 本地初始化(无 Git 仓库链接):
# .\install.ps1
# 2. 克隆/拉取指定 Git 仓库:
# .\install.ps1 -RepoUrl "git@github.com:your-username/your-skills-repo.git"
param(
[Parameter(Mandatory=$false)]
[string]$RepoUrl = ""
)
$ErrorActionPreference = "Stop"
# 定义中央实体库与映射目标目录
$CentralDir = "$HOME\.agents\skills"
$Targets = @(
"$HOME\.codex\skills",
"$HOME\.claude\skills"
)
Write-Host "=== 开始执行多 Agent 技能库环境部署 ===" -ForegroundColor DarkCyan
# 1. 初始化或更新中央技能库
if (!(Test-Path $CentralDir)) {
if ($RepoUrl) {
Write-Host "[Git] 正在克隆中央技能库仓库到 $CentralDir..." -ForegroundColor Cyan
git clone $RepoUrl $CentralDir
} else {
Write-Host "[Local] 未指定仓库地址,正在本地初始化中央实体目录: $CentralDir..." -ForegroundColor Cyan
New-Item -Path $CentralDir -ItemType Directory | Out-Null
}
} else {
Write-Host "[Status] 中央技能实体目录已存在: $CentralDir" -ForegroundColor Green
if ($RepoUrl -and (Test-Path "$CentralDir\.git")) {
Write-Host "[Git] 正在从 Git 仓库拉取最新配置..." -ForegroundColor Cyan
git -C $CentralDir pull
}
}
# 2. 建立 Junction 映射关系
foreach ($Target in $Targets) {
Write-Host "----------------------------------------" -ForegroundColor Gray
Write-Host "[Setup] 正在配置映射目标: $Target" -ForegroundColor Cyan
if (Test-Path $Target) {
$Item = Get-Item $Target
# 判断旧路径是否是重解析点(Junction 或 Symlink)
if ($Item.Attributes -match "ReparsePoint") {
Write-Host "[Clean] 检测到已存在旧的联接映射,正在移除..." -ForegroundColor Yellow
Remove-Item $Target -Force
} else {
# 如果是普通的物理文件夹,为了安全,先进行重命名备份,防止数据丢失
$BackupName = "$(Split-Path $Target -Leaf)_backup_$(Get-Date -Format 'yyyyMMddHHmmss')"
$ParentDir = Split-Path $Target
$BackupPath = Join-Path $ParentDir $BackupName
Write-Host "[Backup] 检测到已存在物理文件夹,正在备份为: $BackupPath" -ForegroundColor Yellow
Rename-Item -Path $Target -NewName $BackupName
}
}
# 确保目标路径的父级文件夹存在(例如确保 .codex 或 .claude 存在)
$ParentDir = Split-Path $Target
if (!(Test-Path $ParentDir)) {
New-Item -Path $ParentDir -ItemType Directory | Out-Null
}
# 创建底层 Junction 联接
New-Item -ItemType Junction -Path $Target -Value $CentralDir | Out-Null
Write-Host "[Success] 成功建立底层重定向: $Target -> $CentralDir" -ForegroundColor Green
}
Write-Host "========================================" -ForegroundColor Gray
Write-Host "✔ 所有 Agent 技能库部署完毕,已实现单源同步!" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment