Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
296 lines (258 loc) · 11.1 KB
/
Copy pathinstall.ps1
File metadata and controls
296 lines (258 loc) · 11.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
param(
[string]$Repo = $env:RESONANT_REPO,
[string]$Ref = $(if ($env:RESONANT_REF) { $env:RESONANT_REF } else { "main" }),
[string]$ZipUrl = $env:RESONANT_ZIP_URL
)
$ErrorActionPreference = "Stop"
if (-not $Repo) {
$Repo = "Ajenee7773/Resonant-Agent"
}
$PiPackage = "@mariozechner/pi-coding-agent@0.69.0"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not $ScriptDir) {
$ScriptDir = (Get-Location).Path
}
$HarnessDir = Join-Path $ScriptDir "harness"
if ($env:RESONANT_HOME) {
$env:PI_HOME = $env:RESONANT_HOME
} else {
$env:PI_HOME = Join-Path $env:USERPROFILE ".resonant"
}
$PiHome = $env:PI_HOME
$PiAgentDir = Join-Path $PiHome "agent"
$PiWorkspaceDir = Join-Path $PiHome "workspace"
$AgentsSkillsDir = if ($env:AGENTS_SKILLS_DIR) { $env:AGENTS_SKILLS_DIR } else { Join-Path $PiAgentDir "skills" }
$PiAppDir = Join-Path $PiHome "app"
$PiBinDir = Join-Path $PiHome "bin"
$env:PI_CODING_AGENT_DIR = $PiAgentDir
function Write-Step($Message) {
Write-Host $Message
}
function Fail($Message) {
throw "ERROR: $Message"
}
function Copy-DirContents($Source, $Destination) {
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
if (Test-Path -LiteralPath $Source) {
Get-ChildItem -LiteralPath $Source -Force | Copy-Item -Destination $Destination -Recurse -Force
}
}
function Download-RepoIfNeeded {
if (Test-Path -LiteralPath $HarnessDir) {
return
}
Write-Step "Harness folder not found beside installer."
Write-Step "Assuming remote one-line install; downloading RESONANT release files..."
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("resonant-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Force -Path $tmp | Out-Null
$zip = Join-Path $tmp "resonant.zip"
if (-not $ZipUrl) {
$ZipUrl = "https://github.com/$Repo/archive/refs/heads/$Ref.zip"
}
Write-Step "Downloading $ZipUrl"
Invoke-WebRequest -Uri $ZipUrl -OutFile $zip
Expand-Archive -LiteralPath $zip -DestinationPath $tmp -Force
$found = Get-ChildItem -LiteralPath $tmp -Directory -Recurse -Filter "harness" | Select-Object -First 1
if (-not $found) {
Fail "Downloaded archive did not contain a harness/ directory."
}
$script:ScriptDir = Split-Path -Parent $found.FullName
$script:HarnessDir = $found.FullName
}
function Check-Node {
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
Fail "Node.js is required. Install Node.js 18 or newer from https://nodejs.org/en/download, then run this installer again."
}
$major = & node -e "process.stdout.write(process.versions.node.split('.')[0])"
if ([int]$major -lt 18) {
Fail "Node.js 18+ is required. Current version: $(node -v)"
}
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Fail "npm was not found on PATH. Reinstall Node.js 18 or newer from https://nodejs.org/en/download, then run this installer again."
}
}
function Check-File($Path, $Label) {
$script:HealthTotal += 1
if (Test-Path -LiteralPath $Path -PathType Leaf) {
$script:HealthPresent += 1
Write-Host "[OK] $Label"
} else {
Write-Host "[MISSING] $Label"
Write-Host "WARNING: $Label is missing. The agent may not boot correctly."
}
}
function Check-NonEmptyDir($Path, $Label) {
$script:HealthTotal += 1
if ((Test-Path -LiteralPath $Path -PathType Container) -and (Get-ChildItem -LiteralPath $Path -Force | Select-Object -First 1)) {
$script:HealthPresent += 1
Write-Host "[OK] $Label"
} else {
Write-Host "[MISSING] $Label"
Write-Host "WARNING: $Label is missing. The agent may not boot correctly."
}
}
Write-Step "RESONANT Agent installer"
Download-RepoIfNeeded
Write-Step "Checking Node.js..."
Check-Node
if ((Get-Command pi -ErrorAction SilentlyContinue) -and $env:RESONANT_FORCE_PI_INSTALL -ne "1") {
Write-Step "Pi runtime already found on PATH; leaving the existing global install untouched."
} else {
Write-Step "Installing Pi runtime: $PiPackage"
npm install -g $PiPackage
}
Write-Step "Creating directories..."
foreach ($dir in @(
"$PiAgentDir\extensions",
"$PiAgentDir\memory",
"$PiAgentDir\memories",
"$PiAgentDir\sessions",
"$PiWorkspaceDir\persona",
"$PiWorkspaceDir\rooms",
"$PiWorkspaceDir\input",
"$PiWorkspaceDir\output",
$AgentsSkillsDir,
$PiAppDir,
$PiBinDir
)) {
New-Item -ItemType Directory -Force -Path $dir | Out-Null
}
if ((Test-Path -LiteralPath (Join-Path $PiAppDir "package.json") -PathType Leaf) -and
$env:RESONANT_SKIP_PRE_UPGRADE_BACKUP -ne "1") {
Write-Step "Creating a safe pre-upgrade backup..."
& node (Join-Path $ScriptDir "scripts\create-pre-upgrade-backup.js")
if ($LASTEXITCODE -ne 0) {
Fail "The pre-upgrade backup failed. Existing application files were not replaced."
}
}
Write-Step "Copying harness files..."
if (Test-Path -LiteralPath "$HarnessDir\AGENTS.md") {
if (Test-Path -LiteralPath "$PiAgentDir\AGENTS.md") {
Copy-Item -LiteralPath "$PiAgentDir\AGENTS.md" -Destination "$PiAgentDir\AGENTS.md.bak.$(Get-Random)" -Force
}
Copy-Item -LiteralPath "$HarnessDir\AGENTS.md" -Destination "$PiAgentDir\AGENTS.md" -Force
}
foreach ($file in @("SOUL.md","CONSTITUTION.md","FOUNDATION.md","HEARTBEAT.md","MEMORY.md","MY-HARNESS.md","TOOLS.md","ROOMS.md","TRANSFER.md")) {
$src = Join-Path $HarnessDir $file
if (Test-Path -LiteralPath $src) {
Copy-Item -LiteralPath $src -Destination (Join-Path $PiAgentDir $file) -Force
}
}
if ((Test-Path -LiteralPath "$HarnessDir\settings.json") -and -not (Test-Path -LiteralPath "$PiAgentDir\settings.json")) {
Copy-Item -LiteralPath "$HarnessDir\settings.json" -Destination "$PiAgentDir\settings.json" -Force
}
$mergeSettingsScript = Join-Path $ScriptDir "scripts\merge-settings.js"
if (Test-Path -LiteralPath $mergeSettingsScript) {
& node $mergeSettingsScript (Join-Path $PiAgentDir "settings.json") (Join-Path $HarnessDir "settings.json")
if ($LASTEXITCODE -ne 0) {
Fail "Failed to merge settings.json."
}
}
if ((Test-Path -LiteralPath "$HarnessDir\heartbeat.json") -and -not (Test-Path -LiteralPath "$PiAgentDir\heartbeat.json")) {
Copy-Item -LiteralPath "$HarnessDir\heartbeat.json" -Destination "$PiAgentDir\heartbeat.json" -Force
}
if (-not (Test-Path -LiteralPath "$PiAgentDir\auth.json")) {
"{}" | Set-Content -Path "$PiAgentDir\auth.json" -Encoding UTF8
}
Copy-DirContents "$HarnessDir\boot" "$PiAgentDir\boot"
Copy-DirContents "$HarnessDir\extensions" "$PiAgentDir\extensions"
Copy-DirContents "$HarnessDir\memory" "$PiAgentDir\memory"
Copy-DirContents "$HarnessDir\persona" "$PiWorkspaceDir\persona"
Copy-DirContents "$HarnessDir\rooms" "$PiWorkspaceDir\rooms"
Copy-DirContents "$HarnessDir\workspace\input" "$PiWorkspaceDir\input"
Copy-DirContents "$HarnessDir\workspace\output" "$PiWorkspaceDir\output"
Copy-DirContents "$HarnessDir\skills" $AgentsSkillsDir
if (Test-Path -LiteralPath "$HarnessDir\os-skill") {
Copy-DirContents "$HarnessDir\os-skill" "$AgentsSkillsDir\resonant-os"
}
Write-Step "Copying RESONANT Agent launchers..."
Copy-DirContents "$ScriptDir\bridge" "$PiAppDir\bridge"
Copy-DirContents "$ScriptDir\core" "$PiAppDir\core"
Copy-DirContents "$ScriptDir\defaults" "$PiAppDir\defaults"
Copy-DirContents "$ScriptDir\interfaces" "$PiAppDir\interfaces"
Copy-DirContents "$ScriptDir\schemas" "$PiAppDir\schemas"
Copy-DirContents "$ScriptDir\scripts" "$PiAppDir\scripts"
Copy-DirContents "$ScriptDir\ui" "$PiAppDir\ui"
Copy-DirContents "$ScriptDir\heartbeat" "$PiAppDir\heartbeat"
Copy-DirContents "$ScriptDir\telegram" "$PiAppDir\telegram"
foreach ($file in @("install.bat","install.ps1","configure.bat","configure.ps1","start.bat","start.ps1","ui.bat","heartbeat-start.bat","heartbeat-start.ps1","telegram-setup.bat","telegram-start.bat","telegram-disconnect.bat","config.template.json","package.json","README.md","RELEASE.md","soul.json","version.json")) {
$src = Join-Path $ScriptDir $file
if (Test-Path -LiteralPath $src) {
Copy-Item -LiteralPath $src -Destination (Join-Path $PiAppDir $file) -Force
}
}
$psLauncher = @"
`$env:RESONANT_HOME = "$PiHome"
`$env:PI_HOME = "$PiHome"
`$env:PI_CODING_AGENT_DIR = "$PiAgentDir"
& "$PiAppDir\start.ps1" @args
"@
$psLauncher | Set-Content -Path (Join-Path $PiBinDir "resonant.ps1") -Encoding UTF8
$batLauncher = @"
@echo off
set "RESONANT_HOME=$PiHome"
set "PI_HOME=$PiHome"
set "PI_CODING_AGENT_DIR=$PiAgentDir"
call "$PiAppDir\start.bat" %*
"@
$batLauncher | Set-Content -Path (Join-Path $PiBinDir "resonant.bat") -Encoding ASCII
$psHeartbeatLauncher = @"
`$env:RESONANT_HOME = "$PiHome"
`$env:PI_HOME = "$PiHome"
`$env:PI_CODING_AGENT_DIR = "$PiAgentDir"
& "$PiAppDir\heartbeat-start.ps1" @args
"@
$psHeartbeatLauncher | Set-Content -Path (Join-Path $PiBinDir "resonant-heartbeat.ps1") -Encoding UTF8
$batHeartbeatLauncher = @"
@echo off
set "RESONANT_HOME=$PiHome"
set "PI_HOME=$PiHome"
set "PI_CODING_AGENT_DIR=$PiAgentDir"
call "$PiAppDir\heartbeat-start.bat" %*
"@
$batHeartbeatLauncher | Set-Content -Path (Join-Path $PiBinDir "resonant-heartbeat.bat") -Encoding ASCII
Write-Step "Checking pi command..."
if (Get-Command pi -ErrorAction SilentlyContinue) {
Write-Step "pi command is available."
} else {
Write-Step "pi command was not found on PATH after install."
Write-Step "Restart your terminal or add npm's global bin directory to PATH."
}
Write-Host ""
Write-Step "Health check:"
$script:HealthTotal = 0
$script:HealthPresent = 0
Check-File "$PiAgentDir\AGENTS.md" "~/.resonant/agent/AGENTS.md"
Check-File "$PiAgentDir\SOUL.md" "~/.resonant/agent/SOUL.md"
Check-File "$PiAgentDir\CONSTITUTION.md" "~/.resonant/agent/CONSTITUTION.md"
Check-File "$PiAgentDir\FOUNDATION.md" "~/.resonant/agent/FOUNDATION.md"
Check-File "$PiAgentDir\HEARTBEAT.md" "~/.resonant/agent/HEARTBEAT.md"
Check-File "$PiAgentDir\heartbeat.json" "~/.resonant/agent/heartbeat.json"
Check-File "$PiAgentDir\MEMORY.md" "~/.resonant/agent/MEMORY.md"
Check-File "$PiAgentDir\TOOLS.md" "~/.resonant/agent/TOOLS.md"
Check-File "$PiAgentDir\ROOMS.md" "~/.resonant/agent/ROOMS.md"
Check-File "$PiAgentDir\boot\BOOT.md" "~/.resonant/agent/boot/BOOT.md"
Check-File "$PiWorkspaceDir\persona\IDENTITY.md" "~/.resonant/workspace/persona/IDENTITY.md"
Check-File "$PiWorkspaceDir\persona\USER.md" "~/.resonant/workspace/persona/USER.md"
Check-NonEmptyDir "$PiWorkspaceDir\rooms" "~/.resonant/workspace/rooms/"
Check-File "$PiWorkspaceDir\input\README.md" "~/.resonant/workspace/input/README.md"
Check-File "$PiWorkspaceDir\output\README.md" "~/.resonant/workspace/output/README.md"
if ($HealthPresent -eq $HealthTotal) {
Write-Host "Health check: $HealthPresent/$HealthTotal files present. Ready to configure."
} else {
Write-Host "Health check: $HealthPresent/$HealthTotal files present. Issues found - check above."
}
Write-Host ""
Write-Step "RESONANT Agent installed."
Write-Step "Next steps:"
Write-Step " 1. Run $PiAppDir\configure.ps1"
Write-Step " 2. Start RESONANT Agent with: $PiAppDir\start.ps1"
Write-Step " 3. Optional launcher: $PiBinDir\resonant.ps1"
Write-Step " 4. Optional heartbeats: $PiAppDir\heartbeat-start.ps1"
Write-Step " 5. Edit $PiAgentDir\AGENTS.md to customize the resonant identity."
if ($env:RESONANT_SKIP_CONFIG_PROMPT -ne "1" -and (Test-Path -LiteralPath "$PiAppDir\configure.ps1")) {
$answer = Read-Host "Run configuration now? [Y/n]"
if (-not $answer -or $answer.ToLower() -ne "n") {
& "$PiAppDir\configure.ps1"
}
}