-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
266 lines (216 loc) · 9.37 KB
/
install.ps1
File metadata and controls
266 lines (216 loc) · 9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# install.ps1 - Installs the AI tools in this repository to the user
# environment. This is the PowerShell equivalent of `install.sh`.
#
# Copies agent files, skill files, and instruction files from the repository
# into the specified install path (default: ~/.copilot).
#
# Usage:
# .\install.ps1 -h
# .\install.ps1 -i "C:\Users\me\.copilot"
# Stop on any error so failures don't go unnoticed.
$ErrorActionPreference = "Stop"
# Resolve the absolute path to this script's directory and the repo root.
$script:ScriptDir = Split-Path -Parent (Resolve-Path $MyInvocation.MyCommand.Path).ProviderPath
$script:RepoDir = Split-Path -Parent $script:ScriptDir
# Exit codes used by all functions.
$script:R_SUCCESS = 0
$script:R_FAILURE = 1
# Default installation target directory.
$script:DefaultInstallPath = Join-Path $env:USERPROFILE ".copilot"
# ================================= Logging ================================== #
# Writes a log message to the console.
function __log {
param([string]$level, [string]$message)
Write-Host "[$level] $message"
}
# Convenience wrapper for info-level log messages.
function __log_info {
param([string]$message)
__log -level "INFO" -message $message
}
# Convenience wrapper for error-level log messages.
function __log_error {
param([string]$message)
__log -level "ERROR" -message $message
}
# ============================ Main Installation ============================= #
# Finds all agent markdown files (matching "*.*agent*.md") in the repo's
# `agents/` directory and copies them into the install path, preserving
# relative directory structure.
function __install_agents {
param([string]$install_path)
# Ensure the destination agents directory exists.
$agents_dst = Join-Path $install_path "agents"
if (-not (Test-Path $agents_dst)) {
New-Item -ItemType Directory -Path $agents_dst -Force | Out-Null
}
# Verify the source directory exists in the repo.
$agents_src = Join-Path $script:RepoDir "agents"
if (-not (Test-Path $agents_src)) {
__log_error "Agents source directory not found: $agents_src"
return $script:R_FAILURE
}
# Resolve to a full path so substring operations against FullName work.
$agents_src = (Resolve-Path $agents_src).ProviderPath
# Copy each agent file, creating subdirectories as needed.
$agent_count = 0
$agent_files = Get-ChildItem -Path $agents_src -Recurse -File -Filter "*.*agent*.md"
foreach ($agent_file in $agent_files) {
$agent_rel = $agent_file.FullName.Substring($agents_src.Length + 1)
$agent_dst = Join-Path $agents_dst $agent_rel
$agent_dst_dir = Split-Path -Parent $agent_dst
if (-not (Test-Path $agent_dst_dir)) {
New-Item -ItemType Directory -Path $agent_dst_dir -Force | Out-Null
}
Copy-Item -Path $agent_file.FullName -Destination $agent_dst -Force
__log_info "Installed agent `"$($agent_file.Name)`" to: $agent_dst"
$agent_count++
}
__log_info "Installed $agent_count agents to: $agents_dst"
return $script:R_SUCCESS
}
# Finds all skill-related files (SKILL.md descriptors, .py implementations,
# and template.*.md templates) in the repo's `skills/` directory and copies
# them into the install path, preserving relative directory structure.
function __install_skills {
param([string]$install_path)
# Ensure the destination skills directory exists.
$skills_dst = Join-Path $install_path "skills"
if (-not (Test-Path $skills_dst)) {
New-Item -ItemType Directory -Path $skills_dst -Force | Out-Null
}
# Verify the source directory exists in the repo.
$skills_src = Join-Path $script:RepoDir "skills"
if (-not (Test-Path $skills_src)) {
__log_error "Skills source directory not found: $skills_src"
return $script:R_FAILURE
}
# Resolve to a full path so substring operations against FullName work.
$skills_src = (Resolve-Path $skills_src).ProviderPath
# Copy each skill file. We count SKILL.md files separately so the summary
# reflects the number of skills (not individual files).
$skill_count = 0
$skill_files = Get-ChildItem -Path $skills_src -Recurse -File |
Where-Object {
$_.Name -like "*SKILL*.md" -or
$_.Name -like "template.*.md" -or
$_.Name -eq "requirements.txt" -or
$_.Extension -eq ".py"
}
foreach ($skill_file in $skill_files) {
$skill_rel = $skill_file.FullName.Substring($skills_src.Length + 1)
$skill_dst = Join-Path $skills_dst $skill_rel
$skill_dst_dir = Split-Path -Parent $skill_dst
if (-not (Test-Path $skill_dst_dir)) {
New-Item -ItemType Directory -Path $skill_dst_dir -Force | Out-Null
}
Copy-Item -Path $skill_file.FullName -Destination $skill_dst -Force
__log_info "Installed skill file `"$skill_rel`" to: $skill_dst"
# Only count SKILL.md files towards the skill total.
if ($skill_file.Name -like "*SKILL*.md") {
$skill_count++
}
}
__log_info "Installed $skill_count skills to: $skills_dst"
return $script:R_SUCCESS
}
# Finds all instruction markdown files (matching "*.*instruction*.md") in the
# repo's `instructions/` directory and copies them into the install path,
# preserving relative directory structure.
function __install_instructions {
param([string]$install_path)
# Ensure the destination instructions directory exists.
$insts_dst = Join-Path $install_path "instructions"
if (-not (Test-Path $insts_dst)) {
New-Item -ItemType Directory -Path $insts_dst -Force | Out-Null
}
# Verify the source directory exists in the repo.
$insts_src = Join-Path $script:RepoDir "instructions"
if (-not (Test-Path $insts_src)) {
__log_error "Instructions source directory not found: $insts_src"
return $script:R_FAILURE
}
# Resolve to a full path so substring operations against FullName work.
$insts_src = (Resolve-Path $insts_src).ProviderPath
# Copy each instruction file, creating subdirectories as needed.
$inst_count = 0
$inst_files = Get-ChildItem -Path $insts_src -Recurse -File -Filter "*.*instruction*.md"
foreach ($inst_file in $inst_files) {
$inst_rel = $inst_file.FullName.Substring($insts_src.Length + 1)
$inst_dst = Join-Path $insts_dst $inst_rel
$inst_dst_dir = Split-Path -Parent $inst_dst
if (-not (Test-Path $inst_dst_dir)) {
New-Item -ItemType Directory -Path $inst_dst_dir -Force | Out-Null
}
Copy-Item -Path $inst_file.FullName -Destination $inst_dst -Force
__log_info "Installed instruction `"$($inst_file.Name)`" to: $inst_dst"
$inst_count++
}
__log_info "Installed $inst_count instructions to: $insts_dst"
return $script:R_SUCCESS
}
# Prints the usage/help text for this script.
function __show_usage {
Write-Host "Usage: install.ps1 [OPTIONS]"
Write-Host ""
Write-Host "Options:"
Write-Host " -h, -Help Show this help message and exit."
Write-Host " -i, -InstallPath PATH Path to install the tools (default: `"$script:DefaultInstallPath`")."
}
# ================================== Main ==================================== #
# Main entry point. Parses arguments, then installs agents, skills, and
# instructions in sequence. Returns a non-zero exit code on failure.
function __main {
param(
[Alias("h")]
[switch]$help,
[Alias("i")]
[string]$install_path
)
if ($help) {
__show_usage
return $script:R_SUCCESS
}
# Fall back to the default install path if none was provided.
$target_path = if ($install_path) { $install_path } else { $script:DefaultInstallPath }
__log_info "Installing tools to: $target_path"
# Install each component in order; bail on first failure.
$result = __install_agents -install_path $target_path
if ($result -ne $script:R_SUCCESS) {
__log_error "Failed to install agents."
return $result
}
$result = __install_skills -install_path $target_path
if ($result -ne $script:R_SUCCESS) {
__log_error "Failed to install skills."
return $result
}
$result = __install_instructions -install_path $target_path
if ($result -ne $script:R_SUCCESS) {
__log_error "Failed to install instructions."
return $result
}
# Set up the Python virtual environment for skills.
$setup_venv = Join-Path $script:ScriptDir "setup-venv.ps1"
if (Test-Path $setup_venv) {
__log_info "Setting up Python virtual environment..."
& powershell -File $setup_venv -i $target_path
if ($LASTEXITCODE -ne 0) {
__log_error "Failed to set up virtual environment."
return $script:R_FAILURE
}
}
# Install the aliases file for easier skill invocation, if it exists.
$aliases_src = Join-Path (Join-Path $script:RepoDir "scripts") "aliases.ps1"
if (Test-Path $aliases_src) {
$aliases_dst = Join-Path $target_path "aliases.ps1"
Copy-Item -Path $aliases_src -Destination $aliases_dst -Force
__log_info "Installed aliases file to: $aliases_dst"
} else {
__log_error "Alias source file not found (`"$aliases_src`"). Skipping."
}
return $script:R_SUCCESS
}
# Invoke `__main` with all script arguments and exit with its return value.
$main_retval = __main @args
exit $main_retval