forked from Spacehunterz/Emergent-Learning-Framework_ELF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
445 lines (395 loc) · 17 KB
/
Copy pathinstall.ps1
File metadata and controls
445 lines (395 loc) · 17 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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# Emergent Learning Framework - Windows Installer
# Run with: PowerShell -ExecutionPolicy Bypass -File install.ps1 [options]
param(
[switch]$CoreOnly,
[switch]$NoDashboard,
[switch]$NoSwarm,
[switch]$All,
[switch]$Help
)
$ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage: install.ps1 [OPTIONS]"
Write-Host ""
Write-Host "Options:"
Write-Host " -CoreOnly Install only core (query system, hooks, golden rules)"
Write-Host " -NoDashboard Skip dashboard installation (skips visual UI at localhost:3000)"
Write-Host " -NoSwarm Skip swarm/conductor installation"
Write-Host " -All Install everything (default)"
Write-Host " -Help Show this help"
Write-Host ""
Write-Host "Components:"
Write-Host " Core: Query system, learning hooks, golden rules, CLAUDE.md"
Write-Host " Dashboard: React UI for monitoring (localhost:3000)"
Write-Host " Swarm: Multi-agent conductor, agent personas"
exit 0
}
# Default: install all
$InstallCore = $true
$InstallDashboard = -not $NoDashboard -and -not $CoreOnly
$InstallSwarm = -not $NoSwarm -and -not $CoreOnly
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Emergent Learning Framework Installer" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Estimated installation time: ~2 minutes" -ForegroundColor Cyan
Write-Host ""
Write-Host "Installation mode:"
Write-Host " Core: " -NoNewline; Write-Host "Yes" -ForegroundColor Green
Write-Host " Dashboard: " -NoNewline
if ($InstallDashboard) { Write-Host "Yes" -ForegroundColor Green } else { Write-Host "No" -ForegroundColor Yellow }
Write-Host " Swarm: " -NoNewline
if ($InstallSwarm) { Write-Host "Yes" -ForegroundColor Green } else { Write-Host "No" -ForegroundColor Yellow }
Write-Host ""
# Get paths
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ClaudeDir = Join-Path $env:USERPROFILE ".claude"
$EmergentLearningDir = Join-Path $ClaudeDir "emergent-learning"
$HooksDir = Join-Path $ClaudeDir "hooks"
$SettingsFile = Join-Path $ClaudeDir "settings.json"
# Check prerequisites
Write-Host "[Step 1/5] Checking prerequisites..." -ForegroundColor Yellow
# Check Python - prefer python3 if available
$pythonCmd = "python"
if (Get-Command python3 -ErrorAction SilentlyContinue) {
$pythonCmd = "python3"
$pythonVersion = python3 --version 2>&1
Write-Host " Python: $pythonVersion" -ForegroundColor Green
} elseif (Get-Command python -ErrorAction SilentlyContinue) {
$pythonCmd = "python"
$pythonVersion = python --version 2>&1
Write-Host " Python: $pythonVersion" -ForegroundColor Green
} else {
Write-Host " ERROR: Python not found. Please install Python 3.8+" -ForegroundColor Red
Write-Host " Fix: Install Python from https://python.org" -ForegroundColor Yellow
Write-Host " Then: Run this installer again" -ForegroundColor Yellow
exit 1
}
# Check Bun/Node (only if installing dashboard)
$hasBun = $false
if ($InstallDashboard) {
try {
$bunVersion = bun --version 2>&1
Write-Host " Bun: $bunVersion" -ForegroundColor Green
$hasBun = $true
} catch {
try {
$nodeVersion = node --version 2>&1
Write-Host " Node: $nodeVersion" -ForegroundColor Green
} catch {
Write-Host " ERROR: Neither Bun nor Node.js found (needed for dashboard)" -ForegroundColor Red
Write-Host " Fix option 1: Run with -NoDashboard to skip dashboard" -ForegroundColor Yellow
Write-Host " Fix option 2: Install Bun (https://bun.sh) or Node.js (https://nodejs.org)" -ForegroundColor Yellow
Write-Host " Then: Run this installer again" -ForegroundColor Yellow
exit 1
}
}
}
Write-Host ""
Write-Host "[OK] Prerequisites met" -ForegroundColor Green
Write-Host ""
Write-Host "[Step 2/5] Creating directory structure..." -ForegroundColor Yellow
# Create directories
$MemoryDir = Join-Path $EmergentLearningDir "memory"
$directories = @(
$ClaudeDir,
$EmergentLearningDir,
$MemoryDir,
(Join-Path $MemoryDir "failures"),
(Join-Path $MemoryDir "successes"),
(Join-Path $EmergentLearningDir "query"),
(Join-Path $EmergentLearningDir "ceo-inbox"),
$HooksDir,
(Join-Path $HooksDir "learning-loop")
)
if ($InstallSwarm) {
$AgentsDir = Join-Path $EmergentLearningDir "agents"
$directories += @(
$AgentsDir,
(Join-Path $AgentsDir "researcher"),
(Join-Path $AgentsDir "architect"),
(Join-Path $AgentsDir "skeptic"),
(Join-Path $AgentsDir "creative"),
(Join-Path $EmergentLearningDir "conductor")
)
}
foreach ($dir in $directories) {
if (-not (Test-Path $dir)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
}
}
Write-Host " Created directory structure (7 directories for core)" -ForegroundColor Green
# === CORE INSTALLATION ===
Write-Host ""
Write-Host "[Step 3/5] Installing core components..." -ForegroundColor Yellow
$srcDir = Join-Path (Join-Path $ScriptDir "src") "emergent-learning"
$srcQueryDir = Join-Path $srcDir "query"
$srcMemoryDir = Join-Path $srcDir "memory"
$dstQueryDir = Join-Path $EmergentLearningDir "query"
# Copy core files
Copy-Item -Path (Join-Path $srcQueryDir "query.py") -Destination (Join-Path $dstQueryDir "query.py") -Force
Copy-Item -Path (Join-Path $srcMemoryDir "golden-rules.md") -Destination (Join-Path $MemoryDir "golden-rules.md") -Force
Copy-Item -Path (Join-Path $srcMemoryDir "init_db.sql") -Destination (Join-Path $MemoryDir "init_db.sql") -Force
Write-Host " Copied query system" -ForegroundColor Green
# Copy hooks
$srcHooksDir = Join-Path $ScriptDir "src"
$hooksSource = Join-Path (Join-Path $srcHooksDir "hooks") "learning-loop"
$learningLoopDir = Join-Path $HooksDir "learning-loop"
Copy-Item -Path (Join-Path $hooksSource "*.py") -Destination $learningLoopDir -Force
Write-Host " Copied learning hooks" -ForegroundColor Green
# Copy scripts
$scriptsDst = Join-Path $EmergentLearningDir "scripts"
New-Item -ItemType Directory -Path $scriptsDst -Force | Out-Null
$scriptsSource = Join-Path $srcDir "scripts"
if (Test-Path $scriptsSource) {
Get-ChildItem -Path $scriptsSource -Filter "*.sh" -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $scriptsDst -Force
}
}
Write-Host " Copied recording scripts" -ForegroundColor Green
# Initialize database
$dbPath = Join-Path $MemoryDir "index.db"
$sqlFile = Join-Path $MemoryDir "init_db.sql"
if (-not (Test-Path $dbPath)) {
try {
sqlite3 $dbPath ".read $sqlFile" 2>&1 | Out-Null
Write-Host " Initialized database" -ForegroundColor Green
} catch {
& $pythonCmd (Join-Path $dstQueryDir "query.py") --validate 2>&1 | Out-Null
Write-Host " Initialized database via Python" -ForegroundColor Green
}
} else {
Write-Host " Database already exists (kept existing)" -ForegroundColor Yellow
}
# === SWARM INSTALLATION ===
if ($InstallSwarm) {
Write-Host ""
Write-Host "[Installing] Swarm components..." -ForegroundColor Yellow
# Copy conductor
$conductorSrc = Join-Path $srcDir "conductor"
$conductorDst = Join-Path $EmergentLearningDir "conductor"
Get-ChildItem -Path $conductorSrc -Filter "*.py" | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $conductorDst -Force
}
Get-ChildItem -Path $conductorSrc -Filter "*.sql" -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $conductorDst -Force
}
Write-Host " Copied conductor module" -ForegroundColor Green
# Copy agent personas
$srcAgentsDir = Join-Path $srcDir "agents"
$dstAgentsDir = Join-Path $EmergentLearningDir "agents"
$agents = @("researcher", "architect", "skeptic", "creative")
foreach ($agent in $agents) {
$agentSrc = Join-Path $srcAgentsDir $agent
$agentDst = Join-Path $dstAgentsDir $agent
if (Test-Path $agentSrc) {
Get-ChildItem -Path $agentSrc | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $agentDst -Force
}
}
}
Write-Host " Copied agent personas" -ForegroundColor Green
# Copy swarm command
$commandsDir = Join-Path $ClaudeDir "commands"
New-Item -ItemType Directory -Path $commandsDir -Force | Out-Null
$srcCommandsDir = Join-Path (Join-Path $ScriptDir "src") "commands"
$swarmCmd = Join-Path $srcCommandsDir "swarm.md"
if (Test-Path $swarmCmd) {
Copy-Item -Path $swarmCmd -Destination $commandsDir -Force
}
Write-Host " Copied /swarm command" -ForegroundColor Green
# Copy agent coordination plugin
$claudePluginsDir = Join-Path $ClaudeDir "plugins"
$pluginsDir = Join-Path $claudePluginsDir "agent-coordination"
$pluginsUtilsDir = Join-Path $pluginsDir "utils"
$pluginsHooksDir = Join-Path $pluginsDir "hooks"
New-Item -ItemType Directory -Path $pluginsUtilsDir -Force | Out-Null
New-Item -ItemType Directory -Path $pluginsHooksDir -Force | Out-Null
$srcPluginsDir = Join-Path (Join-Path $ScriptDir "src") "plugins"
$pluginSrc = Join-Path $srcPluginsDir "agent-coordination"
$pluginSrcUtils = Join-Path $pluginSrc "utils"
$pluginSrcHooks = Join-Path $pluginSrc "hooks"
if (Test-Path $pluginSrc) {
Get-ChildItem -Path $pluginSrcUtils -Filter "*.py" -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $pluginsUtilsDir -Force
}
Get-ChildItem -Path $pluginSrcHooks -Filter "*.py" -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $pluginsHooksDir -Force
}
Get-ChildItem -Path $pluginSrcHooks -Filter "*.json" -ErrorAction SilentlyContinue | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $pluginsHooksDir -Force
}
}
Write-Host " Copied agent coordination plugin" -ForegroundColor Green
}
# === DASHBOARD INSTALLATION ===
if ($InstallDashboard) {
Write-Host ""
Write-Host "[Installing] Dashboard..." -ForegroundColor Yellow
$dashboardSrc = Join-Path $srcDir "dashboard-app"
$dashboardDst = Join-Path $EmergentLearningDir "dashboard-app"
if (Test-Path $dashboardSrc) {
if (Test-Path $dashboardDst) {
Remove-Item -Path $dashboardDst -Recurse -Force
}
Copy-Item -Path $dashboardSrc -Destination $dashboardDst -Recurse
Write-Host " Copied dashboard" -ForegroundColor Green
# Install frontend dependencies
$frontendDir = Join-Path $dashboardDst "frontend"
if (Test-Path $frontendDir) {
Set-Location $frontendDir
if ($hasBun) {
bun install 2>&1 | Out-Null
} else {
npm install 2>&1 | Out-Null
}
Write-Host " Installed frontend dependencies" -ForegroundColor Green
}
# Install backend dependencies
$backendDir = Join-Path $dashboardDst "backend"
if (Test-Path $backendDir) {
pip install -q fastapi uvicorn aiofiles websockets 2>&1 | Out-Null
Write-Host " Installed backend dependencies" -ForegroundColor Green
}
Set-Location $ScriptDir
}
}
# === CHECK CLAUDE CODE ===
Write-Host ""
Write-Host "[Step 5/5] Checking optional components..." -ForegroundColor Yellow
try {
$claudeVersion = claude --version 2>&1
Write-Host " Claude Code: $claudeVersion" -ForegroundColor Green
} catch {
Write-Host " WARNING: Claude Code not found (optional for now)" -ForegroundColor Yellow
Write-Host " Note: ELF requires Claude Code to work. Install from: https://claude.ai/download" -ForegroundColor Yellow
Write-Host " Installation will continue, but ELF won't be functional until you install Claude Code." -ForegroundColor Yellow
}
# === CONFIGURE SETTINGS.JSON ===
Write-Host ""
Write-Host "[Step 4/5] Configuring Claude Code settings..." -ForegroundColor Yellow
Write-Host ""
Write-Host " About to modify settings.json:" -ForegroundColor Cyan
Write-Host " - Adding PreToolUse hook (runs before each task)"
Write-Host " - Adding PostToolUse hook (runs after each task)"
Write-Host " - Preserving your existing hooks (if any)"
Write-Host " - Creating backup at settings.json.backup"
Write-Host ""
$hookLearningLoop = Join-Path $HooksDir "learning-loop"
$preToolHook = Join-Path $hookLearningLoop "pre_tool_learning.py"
$postToolHook = Join-Path $hookLearningLoop "post_tool_learning.py"
# Backup existing settings if present
if (Test-Path $SettingsFile) {
$backupFile = Join-Path $ClaudeDir "settings.json.backup"
Copy-Item -Path $SettingsFile -Destination $backupFile -Force
Write-Host " Backed up existing settings to settings.json.backup" -ForegroundColor Green
}
$settings = @{}
if (Test-Path $SettingsFile) {
try {
$settings = Get-Content $SettingsFile -Raw | ConvertFrom-Json -AsHashtable
} catch {
$settings = @{}
}
}
if (-not $settings.ContainsKey("hooks")) {
$settings["hooks"] = @{}
}
# Create ELF hooks - use detected python command
$elfPreHook = @{
"matcher" = "Task"
"hooks" = @(
@{
"type" = "command"
"command" = "$pythonCmd `"$preToolHook`""
}
)
}
$elfPostHook = @{
"matcher" = "Task"
"hooks" = @(
@{
"type" = "command"
"command" = "$pythonCmd `"$postToolHook`""
}
)
}
# Merge with existing hooks (don't overwrite user's other hooks)
if (-not $settings["hooks"].ContainsKey("PreToolUse")) {
$settings["hooks"]["PreToolUse"] = @()
}
if (-not $settings["hooks"].ContainsKey("PostToolUse")) {
$settings["hooks"]["PostToolUse"] = @()
}
# Remove any existing ELF hooks (to avoid duplicates on reinstall)
# Only remove hooks where matcher="Task" AND command contains "learning-loop"
$settings["hooks"]["PreToolUse"] = @($settings["hooks"]["PreToolUse"] | Where-Object {
-not ($_.matcher -eq "Task" -and $_.hooks -and ($_.hooks | Where-Object { $_.command -like "*learning-loop*" }))
})
$settings["hooks"]["PostToolUse"] = @($settings["hooks"]["PostToolUse"] | Where-Object {
-not ($_.matcher -eq "Task" -and $_.hooks -and ($_.hooks | Where-Object { $_.command -like "*learning-loop*" }))
})
# Add ELF hooks using ArrayList to avoid nested array issues
[System.Collections.ArrayList]$preHooks = @($settings["hooks"]["PreToolUse"])
$preHooks.Add($elfPreHook) | Out-Null
$settings["hooks"]["PreToolUse"] = $preHooks
[System.Collections.ArrayList]$postHooks = @($settings["hooks"]["PostToolUse"])
$postHooks.Add($elfPostHook) | Out-Null
$settings["hooks"]["PostToolUse"] = $postHooks
# Write without BOM (UTF8 BOM can break JSON parsers)
$jsonContent = $settings | ConvertTo-Json -Depth 10
[System.IO.File]::WriteAllText($SettingsFile, $jsonContent, [System.Text.UTF8Encoding]::new($false))
Write-Host " Configured hooks (preserved existing hooks)" -ForegroundColor Green
# Validate settings.json
try {
Get-Content $SettingsFile -Raw | ConvertFrom-Json | Out-Null
Write-Host " [OK] settings.json validated" -ForegroundColor Green
} catch {
Write-Host " [ERROR] settings.json validation failed!" -ForegroundColor Red
Write-Host " Fix: Restore from backup: Copy-Item $ClaudeDir\settings.json.backup $SettingsFile" -ForegroundColor Yellow
Write-Host " Then: Run installer again" -ForegroundColor Yellow
exit 1
}
# === CLAUDE.MD ===
$claudeMdDst = Join-Path $ClaudeDir "CLAUDE.md"
$templatesDir = Join-Path $ScriptDir "templates"
$claudeMdSrc = Join-Path $templatesDir "CLAUDE.md.template"
if (-not (Test-Path $claudeMdDst)) {
if (Test-Path $claudeMdSrc) {
Copy-Item -Path $claudeMdSrc -Destination $claudeMdDst
Write-Host " Created CLAUDE.md" -ForegroundColor Green
}
} else {
Write-Host " CLAUDE.md exists (not overwritten)" -ForegroundColor Yellow
}
# === DONE ===
Write-Host ""
Write-Host "============================================" -ForegroundColor Green
Write-Host " Installation Complete!" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Green
Write-Host ""
Write-Host "Installed:"
Write-Host " [+] Core (query system, hooks, golden rules)" -ForegroundColor Green
if ($InstallDashboard) {
Write-Host " [+] Dashboard (localhost:3000)" -ForegroundColor Green
}
if ($InstallSwarm) {
Write-Host " [+] Swarm (conductor, agent personas)" -ForegroundColor Green
}
Write-Host ""
Write-Host "Next steps (copy-paste ready):"
Write-Host ""
Write-Host " # 1. Review your configuration:"
Write-Host " cat ~/.claude/CLAUDE.md"
Write-Host ""
if ($InstallDashboard) {
Write-Host " # 2. Start the dashboard:"
Write-Host " cd ~/.claude/emergent-learning/dashboard-app; ./run-dashboard.ps1"
Write-Host ""
}
Write-Host " # 3. Test the query system:"
Write-Host " python3 ~/.claude/emergent-learning/query/query.py --context"
Write-Host ""
Write-Host " # 4. Start using Claude Code (it will now query the building automatically!)"
Write-Host " claude"
Write-Host ""