-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
369 lines (331 loc) · 13.3 KB
/
install.ps1
File metadata and controls
369 lines (331 loc) · 13.3 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
<#
.SYNOPSIS
code-memory zero-clone installer (Windows PowerShell).
.DESCRIPTION
No `git clone` required. Installs the `code-memory` CLI via `uv`, drops
infra files into $HOME\.code-memory\, waits for Docker + Ollama,
pulls the bge-m3 embedding model (and optionally gemma2:9b for claim
extraction), and wires up the Claude Code plugin + MCP server.
Optionally installs the OpenCode plugin from npm.
Interactive by default. Pass -Yes to accept defaults; pass any -No*
switch to skip a step; pass -NonInteractive to refuse all prompts.
One-liner (interactive):
irm https://raw.githubusercontent.com/fmflurry/code-memory/main/install.ps1 | iex
Contributors hacking on the repo should still `git clone` and run
`scripts/install.ps1` instead.
.PARAMETER Yes
Accept default for every prompt (Claude=Y, OpenCode=N, claims=N).
.PARAMETER NonInteractive
Refuse all prompts; use defaults (same as -Yes but without confirmation).
.PARAMETER NoDocker
Skip starting FalkorDB + Qdrant via docker compose.
.PARAMETER NoOllama
Skip pulling bge-m3.
.PARAMETER NoClaude
Skip Claude Code marketplace + plugin registration.
.PARAMETER NoOpencode
Skip OpenCode plugin install from npm.
.PARAMETER NoMcp
Skip MCP server registration with Claude Code.
.PARAMETER NoClaims
Skip pulling gemma2:9b for claim extraction.
.PARAMETER WithClaims
Force-pull gemma2:9b without prompting.
.EXAMPLE
irm https://raw.githubusercontent.com/fmflurry/code-memory/main/install.ps1 | iex
.EXAMPLE
# Download then run with flags:
iwr https://raw.githubusercontent.com/fmflurry/code-memory/main/install.ps1 -OutFile install.ps1
./install.ps1 -NoOpencode -NoOllama
#>
[CmdletBinding()]
param(
[switch]$Yes,
[switch]$NonInteractive,
[switch]$NoDocker,
[switch]$NoOllama,
[switch]$NoClaude,
[switch]$NoOpencode,
[switch]$NoMcp,
[switch]$NoClaims,
[switch]$WithClaims
)
$ErrorActionPreference = 'Stop'
$RepoUrl = if ($env:CODEMEMORY_REPO_URL) { $env:CODEMEMORY_REPO_URL } else { 'https://github.com/fmflurry/code-memory' }
$RawUrl = if ($env:CODEMEMORY_RAW_URL) { $env:CODEMEMORY_RAW_URL } else { 'https://raw.githubusercontent.com/fmflurry/code-memory/main' }
$HomeDir = if ($env:CODEMEMORY_HOME) { $env:CODEMEMORY_HOME } else { Join-Path $HOME '.code-memory' }
$NpmPkg = if ($env:CODEMEMORY_OPENCODE_PKG) { $env:CODEMEMORY_OPENCODE_PKG } else { 'code-memory-opencode' }
function Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
function Ok($msg) { Write-Host "[ok] $msg" -ForegroundColor Green }
function Warn($msg) { Write-Host "[warn] $msg" -ForegroundColor Yellow }
function Err($msg) { Write-Host "[err] $msg" -ForegroundColor Red }
function Dim($msg) { Write-Host " $msg" -ForegroundColor DarkGray }
function Test-Cmd($name) { return [bool](Get-Command $name -ErrorAction SilentlyContinue) }
function Test-Interactive() {
if ($NonInteractive) { return $false }
# Read-Host targets console host. When invoked via `irm | iex`, the
# console host is still attached, so prompts work even though stdin is
# the script body.
try {
return [Environment]::UserInteractive -and ($Host.Name -ne 'Default Host')
} catch { return $false }
}
# Returns $true for yes, $false for no.
function Ask-YesNo([string]$Prompt, [string]$Default = 'Y') {
$hint = if ($Default -match '^[Yy]') { '[Y/n]' } else { '[y/N]' }
$defaultYes = $Default -match '^[Yy]'
if ($Yes -or -not (Test-Interactive)) { return $defaultYes }
Write-Host "? $Prompt $hint " -ForegroundColor Yellow -NoNewline
$ans = Read-Host
if ([string]::IsNullOrWhiteSpace($ans)) { return $defaultYes }
return ($ans -match '^[Yy]')
}
# Waits until a CLI is on PATH. Returns $true if present, $false if user skipped.
function Wait-ForCmd([string]$Cmd, [string]$Label, [string]$Url) {
while (-not (Test-Cmd $Cmd)) {
Warn "$Label not found."
Dim "Install from: $Url"
if (-not (Test-Interactive)) {
Warn "non-interactive: skipping $Label"
return $false
}
Write-Host "? Press Enter once installed (or type 'skip' to skip): " -ForegroundColor Yellow -NoNewline
$ans = Read-Host
if ($ans -eq 'skip') { return $false }
# Refresh PATH from machine + user so newly installed tools show up
# without restarting the shell.
$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' + `
[System.Environment]::GetEnvironmentVariable('Path','User')
}
return $true
}
# ---------- 1. uv ----------
Step "Ensuring uv is installed"
if (Test-Cmd 'uv') {
Ok "uv $(uv --version 2>$null)"
} else {
# Run uv installer in a child powershell so its `exit` cannot tear down
# the parent session (especially when this script itself was launched via
# `irm | iex`).
$uvInstaller = Join-Path ([System.IO.Path]::GetTempPath()) ("uv-install-{0}.ps1" -f ([guid]::NewGuid()))
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
Invoke-WebRequest -Uri 'https://astral.sh/uv/install.ps1' -OutFile $uvInstaller -UseBasicParsing
$psExe = (Get-Process -Id $PID).Path
if (-not $psExe) { $psExe = 'powershell.exe' }
& $psExe -NoProfile -ExecutionPolicy Bypass -File $uvInstaller
$uvExit = $LASTEXITCODE
if ($uvExit -ne 0) { throw "uv installer exited with code $uvExit" }
} catch {
Err "Failed to install uv: $($_.Exception.Message)"
Err "Install manually: winget install --id=astral-sh.uv -e then re-run."
exit 3
} finally {
Remove-Item $uvInstaller -ErrorAction SilentlyContinue
$ErrorActionPreference = $prevEAP
}
$env:Path = "$HOME\.local\bin;$HOME\.cargo\bin;$env:Path"
if (-not (Test-Cmd 'uv')) {
Err "uv installed but not on PATH; re-open shell and re-run."
exit 3
}
Ok "uv installed"
}
# ---------- 2. code-memory CLI ----------
Step "Installing code-memory CLI"
& uv tool install --force --from "git+$RepoUrl" flurryx-code-memory
if ($LASTEXITCODE -ne 0) { Err "uv tool install failed"; exit 1 }
$cliPath = (Get-Command code-memory -ErrorAction SilentlyContinue)
Ok "code-memory CLI: $($cliPath.Source)"
# ---------- 3. side files ----------
Step "Writing infra files to $HomeDir"
New-Item -ItemType Directory -Force -Path (Join-Path $HomeDir 'docker') | Out-Null
Invoke-WebRequest -Uri "$RawUrl/docker/docker-compose.yml" -OutFile (Join-Path $HomeDir 'docker/docker-compose.yml') -UseBasicParsing
Ok "wrote $HomeDir\docker\docker-compose.yml"
$envFile = Join-Path $HomeDir '.env'
if (-not (Test-Path $envFile)) {
Invoke-WebRequest -Uri "$RawUrl/.env.example" -OutFile $envFile -UseBasicParsing
Ok "wrote $envFile (from .env.example)"
} else {
Ok ".env already present (not overwritten)"
}
# ---------- 4. docker ----------
$doDocker = -not $NoDocker
if ($doDocker -and -not $Yes -and (Test-Interactive)) {
$doDocker = Ask-YesNo "Start FalkorDB + Qdrant via Docker?" "Y"
}
if ($doDocker) {
Step "Starting FalkorDB + Qdrant"
if (Wait-ForCmd 'docker' 'Docker Desktop' 'https://www.docker.com/products/docker-desktop') {
# ensure daemon up
& docker info *>$null
if ($LASTEXITCODE -ne 0) {
Warn "Docker CLI present but daemon not running. Start Docker Desktop."
if (Test-Interactive) {
Write-Host "? Press Enter once the daemon is up (or 'skip'): " -ForegroundColor Yellow -NoNewline
$ans = Read-Host
if ($ans -eq 'skip') { $doDocker = $false }
}
}
if ($doDocker) {
& docker compose -f (Join-Path $HomeDir 'docker/docker-compose.yml') --project-directory $HomeDir up -d
if ($LASTEXITCODE -ne 0) {
Warn "docker compose up failed"
} else {
Ok "containers up"
Dim "FalkorDB browser: http://localhost:3000"
Dim "Qdrant dashboard: http://localhost:6333/dashboard"
}
}
} else {
Warn "docker step skipped"
}
} else {
Warn "docker step skipped"
}
# ---------- 5. ollama ----------
$doOllama = -not $NoOllama
if ($doOllama -and -not $Yes -and (Test-Interactive)) {
$doOllama = Ask-YesNo "Pull embedding model via Ollama?" "Y"
}
if ($doOllama) {
Step "Embedding model (bge-m3)"
if (Wait-ForCmd 'ollama' 'Ollama' 'https://ollama.com/download/windows') {
& ollama list 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
try { Start-Process -FilePath 'ollama' -ArgumentList 'serve' -WindowStyle Hidden -ErrorAction Stop } catch {}
for ($i = 0; $i -lt 30; $i++) {
Start-Sleep -Seconds 1
& ollama list 2>$null | Out-Null
if ($LASTEXITCODE -eq 0) { break }
}
}
$models = (& ollama list 2>$null) -join "`n"
if ($models -match '(?m)^bge-m3(\s|:)') {
Ok "bge-m3 already present"
} else {
& ollama pull bge-m3
if ($LASTEXITCODE -eq 0) { Ok "bge-m3 pulled" } else { Warn "ollama pull bge-m3 returned exit $LASTEXITCODE" }
}
# optional gemma2:9b for claim extraction
$doClaims = $false
if ($WithClaims) {
$doClaims = $true
} elseif (-not $NoClaims) {
$doClaims = Ask-YesNo "Also pull gemma2:9b for user-claim extraction (~5.4 GB)?" "N"
}
if ($doClaims) {
$models2 = (& ollama list 2>$null) -join "`n"
if ($models2 -match '(?m)^gemma2:9b\s') {
Ok "gemma2:9b already present"
} else {
& ollama pull gemma2:9b
if ($LASTEXITCODE -eq 0) { Ok "gemma2:9b pulled" } else { Warn "ollama pull gemma2:9b returned exit $LASTEXITCODE" }
}
}
} else {
Warn "ollama step skipped"
}
} else {
Warn "ollama step skipped"
}
# ---------- 6. Claude Code ----------
$doClaude = -not $NoClaude
if ($doClaude -and -not $Yes -and (Test-Interactive)) {
$doClaude = Ask-YesNo "Install Claude Code plugin + MCP?" "Y"
}
if ($doClaude) {
if (-not (Test-Cmd 'claude')) {
Step "Installing Claude Code CLI"
$claudeInstaller = Join-Path ([System.IO.Path]::GetTempPath()) ("claude-install-{0}.ps1" -f ([guid]::NewGuid()))
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
Invoke-WebRequest -Uri 'https://claude.ai/install.ps1' -OutFile $claudeInstaller -UseBasicParsing
$psExe = (Get-Process -Id $PID).Path
if (-not $psExe) { $psExe = 'powershell.exe' }
& $psExe -NoProfile -ExecutionPolicy Bypass -File $claudeInstaller
if ($LASTEXITCODE -ne 0) { Warn "claude installer exited with code $LASTEXITCODE" }
} catch {
Warn "claude install failed: $($_.Exception.Message)"
} finally {
Remove-Item $claudeInstaller -ErrorAction SilentlyContinue
$ErrorActionPreference = $prevEAP
}
# Refresh PATH from machine + user so the freshly installed claude shim is visible.
$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' + `
[System.Environment]::GetEnvironmentVariable('Path','User') + ';' + `
"$HOME\.local\bin"
}
if (-not (Test-Cmd 'claude')) {
Warn "claude CLI still not found after install attempt — skipping Claude Code plugin"
Dim "Install manually: https://docs.anthropic.com/claude/docs/claude-code"
} else {
Step "Registering Claude Code plugin + MCP"
& claude plugin marketplace add $RepoUrl 2>$null
if ($LASTEXITCODE -ne 0) { Warn "marketplace add failed (may already be registered)" }
$pluginList = & claude plugin list 2>$null
if ($pluginList -match 'code-memory@code-memory') {
Ok "plugin already installed"
} else {
& claude plugin install code-memory@code-memory --scope user
if ($LASTEXITCODE -eq 0) { Ok "plugin installed" } else { Warn "plugin install failed" }
}
if (-not $NoMcp) {
$mcpList = & claude mcp list 2>$null
if ($mcpList -match '(?m)^\s*code-memory\s') {
Ok "MCP already registered"
} else {
& claude mcp add code-memory `
--scope user `
-e CODE_MEMORY_PROJECT=auto `
-- uvx --from "git+$RepoUrl" code-memory-mcp
if ($LASTEXITCODE -eq 0) { Ok "MCP registered (restart Claude Code to pick it up)" }
else { Warn "claude mcp add failed; see README §MCP server" }
}
}
}
} else {
Warn "Claude Code step skipped"
}
# ---------- 7. OpenCode ----------
$doOpencode = -not $NoOpencode -and ($Yes -or $false)
# OpenCode defaults to N — only prompt if not explicitly skipped.
if (-not $NoOpencode -and -not $Yes -and (Test-Interactive)) {
$doOpencode = Ask-YesNo "Install OpenCode plugin (npm global)?" "N"
} elseif ($Yes) {
$doOpencode = $false # -Yes accepts the default (N) for OpenCode
}
if ($doOpencode) {
Step "Installing OpenCode plugin"
if (-not (Test-Cmd 'npm')) {
Warn "npm not found — skipping. Install Node.js, then: npm i -g $NpmPkg ; code-memory-opencode-install"
} else {
& npm i -g $NpmPkg
if ($LASTEXITCODE -ne 0) {
Warn "npm install failed"
} elseif (Test-Cmd 'code-memory-opencode-install') {
& code-memory-opencode-install
} else {
Warn "$NpmPkg installed but code-memory-opencode-install not on PATH"
Warn "Add npm global bin to PATH (npm bin -g) and re-run: code-memory-opencode-install"
}
}
} else {
Warn "OpenCode step skipped"
}
# ---------- done ----------
Step "Done"
@"
Side files: $HomeDir\
CLI: $(if ($cliPath) { $cliPath.Source } else { 'code-memory (not on PATH)' })
Ingest a repo:
code-memory ingest C:\path\to\repo
Query:
code-memory retrieve "where is the auth middleware?"
Browse:
FalkorDB http://localhost:3000
Qdrant http://localhost:6333/dashboard
Edit defaults: $HomeDir\.env
"@ | Write-Host