-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
147 lines (131 loc) · 6.22 KB
/
Copy pathsetup.ps1
File metadata and controls
147 lines (131 loc) · 6.22 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
<#
.SYNOPSIS
Install and converge the repository-managed OpenCode configuration.
.DESCRIPTION
Copies tracked configuration, agents, data, commands, plugins, and skills into
the selected global config directory. Delegates approved component installs to
maintain.ps1, removes retired artifacts, configures optional machine integration,
and runs verification unless skipped. Existing private OpenCode and Supermemory
credential files are preserved.
.EXAMPLE
pwsh ./setup.ps1
.EXAMPLE
pwsh ./setup.ps1 -SkipRtk -SkipCodeGraph -SkipTests
#>
[CmdletBinding(SupportsShouldProcess)]
param(
[switch]$SkipRtk,
[switch]$SkipCodeGraph,
[switch]$SkipTests,
[switch]$SkipEnvironment,
[string]$ConfigDir = [IO.Path]::Combine($HOME, ".config", "opencode"),
[string]$CacheDir = [IO.Path]::Combine($HOME, ".cache", "opencode")
)
$ErrorActionPreference = "Stop"
$RepoDir = $PSScriptRoot
$manifest = Get-Content "$RepoDir\config\components.json" -Raw | ConvertFrom-Json
& "$RepoDir\scripts\ensure-bun.ps1" -WhatIf:$WhatIfPreference
function Copy-Tree([string]$Source, [string]$Destination) {
if (-not (Test-Path -LiteralPath $Source)) { return }
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
Copy-Item (Join-Path $Source "*") $Destination -Recurse -Force
}
function Set-BackgroundAgentEnvironment {
if ($IsWindows) {
[Environment]::SetEnvironmentVariable("OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS", "true", "User")
} else {
$environmentDir = Join-Path $HOME ".config\environment.d"
New-Item -ItemType Directory -Path $environmentDir -Force | Out-Null
Set-Content -LiteralPath (Join-Path $environmentDir "opencode.conf") -Value "OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS=true" -Encoding utf8
}
$env:OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS = "true"
}
function Copy-UniqueSkills {
$destination = Join-Path $ConfigDir "skills"
New-Item -ItemType Directory -Path $destination -Force | Out-Null
foreach ($name in @($manifest.retired.skills)) {
Remove-Item -LiteralPath (Join-Path $destination $name) -Recurse -Force -ErrorAction SilentlyContinue
}
$external = @(
(Join-Path $HOME ".agents\skills"),
(Join-Path $HOME ".claude\skills")
) | Where-Object { Test-Path -LiteralPath $_ }
$externalNames = @($external | ForEach-Object { Get-ChildItem -LiteralPath $_ -Directory | ForEach-Object Name } | Select-Object -Unique)
foreach ($name in $externalNames) {
Remove-Item -LiteralPath (Join-Path $destination $name) -Recurse -Force -ErrorAction SilentlyContinue
}
foreach ($item in Get-ChildItem -LiteralPath "$RepoDir\skills" -Directory) {
$target = Join-Path $destination $item.Name
if ($item.Name -in $externalNames) {
continue
}
New-Item -ItemType Directory -Path $target -Force | Out-Null
Copy-Item (Join-Path $item.FullName "*") $target -Recurse -Force
}
}
Write-Output "=== OpenCode setup ==="
New-Item -ItemType Directory -Path $ConfigDir -Force | Out-Null
$globalConfig = Join-Path $ConfigDir "opencode.jsonc"
if (-not (Test-Path -LiteralPath $globalConfig)) {
Copy-Item "$RepoDir\config\opencode.jsonc.example" $globalConfig
Write-Output "Created $globalConfig. Add credentials after setup."
}
Copy-Item "$RepoDir\config\tui.json" (Join-Path $ConfigDir "tui.json") -Force
Copy-Item "$RepoDir\config\oh-my-opencode-slim.json" (Join-Path $ConfigDir "oh-my-opencode-slim.json") -Force
Copy-Item "$RepoDir\config\AGENTS.md" (Join-Path $ConfigDir "AGENTS.md") -Force
& "$RepoDir\scripts\remove-headroom-opencode-pollution.ps1" -ConfigFile $globalConfig
$legacyJson = Join-Path $ConfigDir "opencode.json"
if (Test-Path -LiteralPath $legacyJson -PathType Leaf) {
& "$RepoDir\scripts\remove-headroom-opencode-pollution.ps1" -ConfigFile $legacyJson
try {
$legacy = Get-Content -LiteralPath $legacyJson -Raw | ConvertFrom-Json
$legacyKeys = @($legacy.PSObject.Properties | Where-Object {
$_.Name -ne '$schema' -and -not (
$_.Name -in 'provider', 'mcp' -and @($_.Value.PSObject.Properties).Count -eq 0
)
})
if ($legacyKeys.Count -eq 0) { Remove-Item -LiteralPath $legacyJson -Force }
} catch {}
}
Copy-Tree "$RepoDir\agents" (Join-Path $ConfigDir "agents")
Copy-Tree "$RepoDir\data" (Join-Path $ConfigDir "data")
Copy-Tree "$RepoDir\commands" (Join-Path $ConfigDir "commands")
$supermemory = Join-Path $ConfigDir "supermemory.jsonc"
if (-not (Test-Path -LiteralPath $supermemory)) {
Copy-Item "$RepoDir\config\supermemory.jsonc.example" $supermemory
}
foreach ($legacy in @("lazy-load.ts", "tokens-source.ts", "mem0-selfhost-patch.ts")) {
Remove-Item (Join-Path $ConfigDir "plugins\$legacy") -Force -ErrorAction SilentlyContinue
}
Remove-Item (Join-Path $ConfigDir "mem0-selfhost-patch.ts") -Force -ErrorAction SilentlyContinue
Remove-Item (Join-Path $ConfigDir "verify-patch.ts") -Force -ErrorAction SilentlyContinue
$excluded = @()
if ($SkipRtk) { $excluded += "rtk" }
if ($SkipCodeGraph) { $excluded += "codegraph" }
if ($excluded.Count) {
$selected = @($manifest.components | Where-Object { -not $_.optional -and -not $_.disabled -and $_.id -notin $excluded } | ForEach-Object id)
$apply = @("-NoProfile", "-File", "$RepoDir\maintain.ps1", "apply", "-Component", ($selected -join ','), "-ConfigDir", $ConfigDir, "-CacheDir", $CacheDir)
} else {
$selected = @($manifest.components | Where-Object { -not $_.optional -and -not $_.disabled } | ForEach-Object id)
$apply = @("-NoProfile", "-File", "$RepoDir\maintain.ps1", "apply", "-Component", ($selected -join ','), "-ConfigDir", $ConfigDir, "-CacheDir", $CacheDir)
}
& pwsh @apply
if ($LASTEXITCODE -ne 0) { throw "Component installation failed" }
Copy-UniqueSkills
if (-not $SkipCodeGraph) {
& codegraph install --yes
& codegraph telemetry off
}
if (-not $SkipRtk) {
if (Get-Command rtk -ErrorAction SilentlyContinue) {
& rtk init -g
Copy-Item "$RepoDir\plugins\rtk.ts" (Join-Path $ConfigDir "plugins\rtk.ts") -Force
}
}
if (-not $SkipEnvironment) { Set-BackgroundAgentEnvironment }
if (-not $SkipTests) {
& pwsh -NoProfile -File "$RepoDir\maintain.ps1" verify -ConfigDir $ConfigDir -CacheDir $CacheDir
if ($LASTEXITCODE -ne 0) { throw "Setup verification failed" }
}
Write-Output "=== Setup complete ==="
Write-Output "Add private credentials, restart terminal, then run: pwsh ./maintain.ps1 verify"