-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall-codex.ps1
More file actions
187 lines (156 loc) · 4.74 KB
/
install-codex.ps1
File metadata and controls
187 lines (156 loc) · 4.74 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
param(
[Parameter(Mandatory = $false)]
[string]$PackageRoot = $PSScriptRoot,
[Parameter(Mandatory = $false)]
[string]$CodexHome = "",
[Parameter(Mandatory = $false)]
[string]$InstallRoot = "",
[Parameter(Mandatory = $false)]
[switch]$SkipPathUpdate,
[Parameter(Mandatory = $false)]
[switch]$Force
)
$ErrorActionPreference = "Stop"
$mcpName = "renderdoc-mcp"
$skillName = "renderdoc-mcp"
function Get-BackupPath
{
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
return "$Path.bak-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
}
function Replace-Or-Backup
{
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
if(-not (Test-Path $Path))
{
return
}
if($Force)
{
Remove-Item -Recurse -Force -LiteralPath $Path
return
}
$backupPath = Get-BackupPath -Path $Path
Move-Item -LiteralPath $Path -Destination $backupPath
Write-Host "Backed up $Path to $backupPath"
}
if(-not $CodexHome)
{
if($env:CODEX_HOME)
{
$CodexHome = $env:CODEX_HOME
}
else
{
$CodexHome = Join-Path $HOME ".codex"
}
}
if(-not $InstallRoot)
{
$InstallRoot = Join-Path (Join-Path $CodexHome "vendor_imports") $mcpName
}
$PackageRoot = (Resolve-Path $PackageRoot).Path
$CodexHome = [System.IO.Path]::GetFullPath($CodexHome)
$InstallRoot = [System.IO.Path]::GetFullPath($InstallRoot)
$requiredPaths = @(
(Join-Path $PackageRoot "bin\renderdoc-mcp.exe"),
(Join-Path $PackageRoot "bin\renderdoc-cli.exe"),
(Join-Path $PackageRoot "bin\renderdoc.json"),
(Join-Path $PackageRoot "skills\renderdoc-mcp\SKILL.md"),
(Join-Path $PackageRoot "skills\renderdoc-mcp\agents\openai.yaml")
)
foreach($path in $requiredPaths)
{
if(-not (Test-Path $path))
{
throw "Package is missing required content: $path"
}
}
New-Item -ItemType Directory -Path $CodexHome -Force | Out-Null
New-Item -ItemType Directory -Path (Join-Path $CodexHome "skills") -Force | Out-Null
New-Item -ItemType Directory -Path (Split-Path -Parent $InstallRoot) -Force | Out-Null
if(-not [string]::Equals($PackageRoot, $InstallRoot, [System.StringComparison]::OrdinalIgnoreCase))
{
Replace-Or-Backup -Path $InstallRoot
New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null
Copy-Item -Recurse -Force -Path (Join-Path $PackageRoot "*") -Destination $InstallRoot
}
$skillSource = Join-Path $InstallRoot "skills\$skillName"
$skillTarget = Join-Path (Join-Path $CodexHome "skills") $skillName
Replace-Or-Backup -Path $skillTarget
Copy-Item -Recurse -Force -LiteralPath $skillSource -Destination (Join-Path $CodexHome "skills")
$configPath = Join-Path $CodexHome "config.toml"
$serverCommand = Join-Path $InstallRoot "bin\renderdoc-mcp.exe"
$mcpSection = @(
"[mcp_servers.$mcpName]",
"command = '$serverCommand'",
"args = []"
) -join "`r`n"
$configContent = ""
if(Test-Path $configPath)
{
$configBackup = Get-BackupPath -Path $configPath
Copy-Item -Force $configPath $configBackup
Write-Host "Backed up $configPath to $configBackup"
$configContent = Get-Content -Path $configPath -Raw
}
$sectionPattern = "(?ms)^\[mcp_servers\.$([regex]::Escape($mcpName))\]\r?\n(?:.*\r?\n)*?(?=^\[|\z)"
if([regex]::IsMatch($configContent, $sectionPattern))
{
$updatedConfig = [regex]::Replace($configContent, $sectionPattern, $mcpSection + "`r`n")
}
else
{
if($configContent.Length -gt 0 -and -not $configContent.EndsWith("`n"))
{
$configContent += "`r`n"
}
if($configContent.Length -gt 0)
{
$configContent += "`r`n"
}
$updatedConfig = $configContent + $mcpSection + "`r`n"
}
Set-Content -Path $configPath -Value $updatedConfig -Encoding utf8
if(-not $SkipPathUpdate)
{
$binPath = Join-Path $InstallRoot "bin"
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$pathEntries = @()
if($userPath)
{
$pathEntries = $userPath -split ";" | Where-Object { $_.Trim() -ne "" }
}
$alreadyPresent = $false
foreach($entry in $pathEntries)
{
if([string]::Equals($entry.Trim(), $binPath, [System.StringComparison]::OrdinalIgnoreCase))
{
$alreadyPresent = $true
break
}
}
if(-not $alreadyPresent)
{
$pathEntries += $binPath
[Environment]::SetEnvironmentVariable("Path", ($pathEntries -join ";"), "User")
if($env:Path)
{
$env:Path = "$env:Path;$binPath"
}
else
{
$env:Path = $binPath
}
}
}
Write-Host "Installed package root: $InstallRoot"
Write-Host "Installed skill: $skillTarget"
Write-Host "Configured MCP server: $mcpName"
Write-Host "Restart Codex Desktop to pick up the new MCP server and skill."