-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
418 lines (364 loc) · 16.1 KB
/
install.ps1
File metadata and controls
418 lines (364 loc) · 16.1 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#Requires -Version 5.1
<#
.SYNOPSIS
Windows installer for mind-map.
.DESCRIPTION
Downloads the native Windows binary, configures MCP clients,
and optionally installs mind-map as a persistent service.
.PARAMETER Version
Install a specific release tag (e.g. v0.49). Defaults to the latest
release. Useful for testing prereleases without making them latest.
Equivalent env var: MINDMAP_VERSION
.EXAMPLE
irm https://github.com/aniongithub/mind-map/releases/latest/download/install.ps1 | iex
.EXAMPLE
# Pin a specific release. The piped form can't pass parameters directly,
# so set the env var first:
$env:MINDMAP_VERSION = "v0.49"
irm https://github.com/aniongithub/mind-map/releases/latest/download/install.ps1 | iex
#>
param(
[string]$Version = ""
)
# Resolve version from -Version or MINDMAP_VERSION env var. The env var is
# how the piped `irm | iex` form supplies a value, since parameters don't
# flow through a pipeline of strings. Explicit -Version wins if both set.
if (-not $Version -and $env:MINDMAP_VERSION) {
$Version = $env:MINDMAP_VERSION
}
# Auto-elevate to admin (needed for Windows Service installation). When we
# relaunch, propagate the version pin via the env var so the elevated
# process picks it up (param binding doesn't survive `irm | iex`). The
# elevated session also re-downloads install.ps1 itself; if a version is
# pinned, fetch the install.ps1 from that release tag too — the latest
# install.ps1 may not match the binary the user asked for.
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Requesting administrative privileges..." -ForegroundColor Yellow
if ($Version) {
# Versioned release: /releases/download/<tag>/install.ps1
$scriptUrl = "https://github.com/aniongithub/mind-map/releases/download/$Version/install.ps1"
} else {
# Convenience redirect to the latest release.
$scriptUrl = "https://github.com/aniongithub/mind-map/releases/latest/download/install.ps1"
}
$envPrefix = ""
if ($Version) {
# Set the env var inside the elevated session before running iex,
# so the re-downloaded script picks up the same pin.
$envPrefix = "`$env:MINDMAP_VERSION = '$Version'; "
}
Start-Process powershell.exe "-NoExit -NoProfile -ExecutionPolicy Bypass -Command `"& { ${envPrefix}irm '$scriptUrl' | iex }`"" -Verb RunAs
exit
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$Repo = "aniongithub/mind-map"
$InstallDir = "$env:LOCALAPPDATA\mind-map"
$BinaryPath = "$InstallDir\mind-map.exe"
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
function Write-Step { param([string]$Message) Write-Host "==> $Message" -ForegroundColor Cyan }
function Write-Ok { param([string]$Message) Write-Host " $([char]0x2713) $Message" -ForegroundColor Green }
function Write-Warn { param([string]$Message) Write-Host " $([char]0x26A0) $Message" -ForegroundColor Yellow }
# ---------------------------------------------------------------------------
# 1. Detect architecture
# ---------------------------------------------------------------------------
Write-Step "Detecting platform..."
$arch = if ([Environment]::Is64BitOperatingSystem) {
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" }
} else {
Write-Host "Error: 32-bit Windows is not supported." -ForegroundColor Red
exit 1
}
Write-Ok "windows-$arch"
# ---------------------------------------------------------------------------
# 2. Resolve version
# ---------------------------------------------------------------------------
if ($Version) {
Write-Step "Using pinned version: $Version"
$version = $Version
} else {
Write-Step "Checking latest version..."
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$version = $release.tag_name
Write-Ok "Latest version: $version"
}
# ---------------------------------------------------------------------------
# 3. Stop existing service before replacing binary
# ---------------------------------------------------------------------------
# Stop existing service before replacing binary (ignore errors if not installed)
if (Test-Path $BinaryPath) {
$ErrorActionPreference = "Continue"
& $BinaryPath service stop 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Ok "Stopped existing mind-map service"
}
$ErrorActionPreference = "Stop"
}
# ---------------------------------------------------------------------------
# 4. Download and install binary
# ---------------------------------------------------------------------------
Write-Step "Downloading mind-map-windows-$arch.exe..."
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
$artifact = "mind-map-windows-$arch.exe"
$tarball = "$artifact.tar.gz"
$downloadUrl = "https://github.com/$Repo/releases/download/$version/$tarball"
$tarballPath = "$env:TEMP\$tarball"
Invoke-WebRequest -Uri $downloadUrl -OutFile $tarballPath -UseBasicParsing
# Extract using tar (available on Windows 10+)
tar -xzf $tarballPath -C $InstallDir 2>&1 | Out-Null
# Rename platform-specific binary
if (Test-Path "$InstallDir\$artifact") {
Move-Item -Path "$InstallDir\$artifact" -Destination $BinaryPath -Force
}
Remove-Item $tarballPath -Force -ErrorAction SilentlyContinue
Write-Ok "Installed to $BinaryPath"
# Verify
try {
& $BinaryPath --help | Out-Null
Write-Ok "mind-map is working"
} catch {
Write-Warn "Binary installed but could not verify"
}
# Add to user PATH if not already there
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("PATH", "$InstallDir;$userPath", "User")
$env:PATH = "$InstallDir;$env:PATH"
Write-Ok "Added $InstallDir to user PATH"
}
# ---------------------------------------------------------------------------
# 5. Install SKILL.md for agent discovery
# ---------------------------------------------------------------------------
Write-Step "Installing SKILL.md for agent discovery..."
$SkillUrl = "https://raw.githubusercontent.com/$Repo/$version/SKILL.md"
$SkillDirs = @(
"$env:USERPROFILE\.copilot\skills\mind-map"
"$env:USERPROFILE\.claude\skills\mind-map"
"$env:USERPROFILE\.agents\skills\mind-map"
"$env:APPDATA\opencode\skills\mind-map"
)
foreach ($dir in $SkillDirs) {
try {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
Invoke-RestMethod -Uri $SkillUrl -OutFile "$dir\SKILL.md"
Write-Ok "$dir\SKILL.md"
} catch {
Write-Warn "Could not install to $dir"
}
}
# ---------------------------------------------------------------------------
# 6. Interactive: set up as a persistent service
# ---------------------------------------------------------------------------
$DefaultPort = "4242"
$DefaultWikiDir = "$env:ProgramData\mind-map\wiki"
$servicePort = $DefaultPort
function Test-PortAvailable {
param([int]$Port)
try {
$listener = [System.Net.Sockets.TcpClient]::new()
$listener.Connect("127.0.0.1", $Port)
$listener.Close()
return $false # connection succeeded — port is in use
} catch {
return $true # connection refused — port is free
}
}
Write-Host ""
$installService = Read-Host "Would you like to install mind-map as a persistent service? [y/N]"
if ($installService -match '^[Yy]$') {
# --- Port ---
if (-not (Test-PortAvailable -Port ([int]$DefaultPort))) {
Write-Warn "Port $DefaultPort is already in use."
}
while ($true) {
if (Test-PortAvailable -Port ([int]$DefaultPort)) {
$servicePort = Read-Host "Port [$DefaultPort] (enter nothing to auto-pick a free port)"
} else {
$servicePort = Read-Host "Enter a port (or nothing to auto-pick a free port)"
}
if ([string]::IsNullOrWhiteSpace($servicePort) -and -not (Test-PortAvailable -Port ([int]$DefaultPort))) {
# Auto-pick: scan from 8080 upward
$found = $false
for ($p = 8080; $p -le 8180; $p++) {
if (Test-PortAvailable -Port $p) {
$servicePort = "$p"
Write-Ok "Auto-selected port $servicePort"
$found = $true
break
}
}
if (-not $found) {
Write-Warn "Could not find a free port. Please enter one manually."
continue
}
}
if ([string]::IsNullOrWhiteSpace($servicePort)) { $servicePort = $DefaultPort }
if ($servicePort -notmatch '^\d+$') {
Write-Warn "Invalid port number."
continue
}
if (-not (Test-PortAvailable -Port ([int]$servicePort))) {
Write-Warn "Port $servicePort is already in use."
continue
}
break
}
$serviceWikiDir = Read-Host "Wiki directory [$DefaultWikiDir]"
if ([string]::IsNullOrWhiteSpace($serviceWikiDir)) { $serviceWikiDir = $DefaultWikiDir }
# Build service flags
$svcFlags = @("--addr", "127.0.0.1:$servicePort", "--dir", "$serviceWikiDir")
# Uninstall existing service if present (handles reinstall)
$ErrorActionPreference = "Continue"
& $BinaryPath service stop 2>&1 | Out-Null
& $BinaryPath service uninstall 2>&1 | Out-Null
$ErrorActionPreference = "Stop"
# Install and start the service (already running as admin)
& $BinaryPath service install @svcFlags
& $BinaryPath service start @svcFlags
Write-Host ""
$webUrl = "http://localhost:$servicePort"
Write-Host " Web UI: $webUrl" -ForegroundColor Cyan
Write-Host ""
Write-Host " Manage with: mind-map service status|stop|start|uninstall" -ForegroundColor DarkGray
}
# ---------------------------------------------------------------------------
# 7. Configure MCP clients
# ---------------------------------------------------------------------------
Write-Step "Configuring MCP clients..."
$mcpServerEntry = @{
type = "local"
command = $BinaryPath
args = @()
tools = @("*")
}
function Set-McpConfig {
param(
[string]$ConfigPath,
[string]$ClientName
)
try {
if (Test-Path $ConfigPath) {
$content = Get-Content -Raw $ConfigPath | ConvertFrom-Json
if (-not $content.mcpServers) {
$content | Add-Member -NotePropertyName "mcpServers" -NotePropertyValue ([PSCustomObject]@{})
}
if ($content.mcpServers.PSObject.Properties.Name -contains "mind-map") {
$content.mcpServers.PSObject.Properties.Remove("mind-map")
}
$content.mcpServers | Add-Member -NotePropertyName "mind-map" -NotePropertyValue ([PSCustomObject]$mcpServerEntry)
$content | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
Write-Ok "$ClientName — configured in $ConfigPath"
} else {
$dir = Split-Path $ConfigPath -Parent
if ($dir) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
$config = [PSCustomObject]@{
mcpServers = [PSCustomObject]@{
"mind-map" = [PSCustomObject]$mcpServerEntry
}
}
$config | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
Write-Ok "$ClientName — created $ConfigPath"
}
} catch {
Write-Warn "$ClientName — could not update $ConfigPath"
}
}
# Claude Code (CLI). Gate on .claude existing so we don't create a stray
# config file for users who don't actually have Claude Code installed.
if ((Test-Path "$env:USERPROFILE\.claude") -or (Test-Path "$env:USERPROFILE\.claude.json")) {
Set-McpConfig "$env:USERPROFILE\.claude.json" "Claude Code"
}
# Claude Desktop (separate product from Claude Code). Same "mcpServers" shape
# as Claude Code / Copilot / VS Code, different config path. We gate on the
# %APPDATA%\Claude directory existing — that's where the desktop app stores
# its state — so we don't drop a phantom config for users who haven't
# installed Claude Desktop.
$claudeDesktopDir = "$env:APPDATA\Claude"
if (Test-Path $claudeDesktopDir) {
Set-McpConfig "$claudeDesktopDir\claude_desktop_config.json" "Claude Desktop"
}
# GitHub Copilot (if .copilot dir exists)
if (Test-Path "$env:USERPROFILE\.copilot") {
Set-McpConfig "$env:USERPROFILE\.copilot\mcp-config.json" "GitHub Copilot"
}
# VS Code (if config dir exists)
$vscodeDir = "$env:APPDATA\Code\User"
if (Test-Path $vscodeDir) {
Set-McpConfig "$vscodeDir\mcp.json" "VS Code"
}
# Cursor (if installed)
if (Test-Path "$env:USERPROFILE\.cursor") {
Set-McpConfig "$env:USERPROFILE\.cursor\mcp.json" "Cursor"
}
# OpenCode (https://opencode.ai) — different config shape: top-level "mcp"
# (not "mcpServers"), command is an array, and entries carry "enabled": true.
# Primary path on Windows is %APPDATA%\opencode\opencode.json; the script also
# accepts the .jsonc variant if it's the file the user already has.
$openCodeEntry = [PSCustomObject]@{
type = "local"
command = @($BinaryPath)
enabled = $true
}
function Set-OpenCodeMcpConfig {
param([string]$ConfigPath)
try {
if (Test-Path $ConfigPath) {
$content = Get-Content -Raw $ConfigPath | ConvertFrom-Json
if (-not $content.mcp) {
$content | Add-Member -NotePropertyName "mcp" -NotePropertyValue ([PSCustomObject]@{})
}
if ($content.mcp.PSObject.Properties.Name -contains "mind-map") {
$content.mcp.PSObject.Properties.Remove("mind-map")
}
$content.mcp | Add-Member -NotePropertyName "mind-map" -NotePropertyValue $openCodeEntry
$content | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
Write-Ok "OpenCode — configured in $ConfigPath"
} else {
$dir = Split-Path $ConfigPath -Parent
if ($dir) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
$config = [PSCustomObject]@{
'$schema' = "https://opencode.ai/config.json"
mcp = [PSCustomObject]@{
"mind-map" = $openCodeEntry
}
}
$config | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
Write-Ok "OpenCode — created $ConfigPath"
}
} catch {
Write-Warn "OpenCode — could not update $ConfigPath"
}
}
$openCodeDir = "$env:APPDATA\opencode"
$openCodeJson = Join-Path $openCodeDir "opencode.json"
$openCodeJsonc = Join-Path $openCodeDir "opencode.jsonc"
$openCodeCfg = $null
if (Test-Path $openCodeJson) {
$openCodeCfg = $openCodeJson
} elseif (Test-Path $openCodeJsonc) {
$openCodeCfg = $openCodeJsonc
} elseif ((Test-Path $openCodeDir) -or (Get-Command opencode -ErrorAction SilentlyContinue)) {
$openCodeCfg = $openCodeJson
}
if ($openCodeCfg) {
Set-OpenCodeMcpConfig $openCodeCfg
}
# ---------------------------------------------------------------------------
# Done
# ---------------------------------------------------------------------------
Write-Host ""
if ($installService -match '^[Yy]$') {
Write-Host "Done! mind-map is running as a service." -ForegroundColor Green
} else {
Write-Host "Done! mind-map is ready to use." -ForegroundColor Green
Write-Host ""
Write-Host " Start the web UI: mind-map serve" -ForegroundColor DarkGray
}
Write-Host ""
Write-Host "To uninstall mind-map completely:" -ForegroundColor DarkGray
Write-Host " mind-map service uninstall # remove service (if installed)" -ForegroundColor DarkGray
Write-Host " Remove-Item -Recurse '$InstallDir' # remove binary" -ForegroundColor DarkGray
Write-Host " Remove-Item -Recurse '$env:USERPROFILE\.mind-map' # remove wiki data" -ForegroundColor DarkGray
Write-Host " Remove-Item -Recurse '$env:USERPROFILE\.copilot\skills\mind-map', '$env:USERPROFILE\.claude\skills\mind-map', '$env:USERPROFILE\.agents\skills\mind-map', '$env:APPDATA\opencode\skills\mind-map'" -ForegroundColor DarkGray