agentroam 0.2.0-preview.7 → 0.2.0-preview.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -15
- package/bin/agentroam.mjs +10 -1
- package/bin/cli-progress.d.mts +9 -0
- package/bin/cli-progress.mjs +65 -0
- package/bin/desktop-download.mjs +69 -0
- package/bin/node-preflight.mjs +171 -0
- package/bin/node-runtime-policy.json +4 -0
- package/bin/runtime-policy.d.mts +5 -0
- package/bin/runtime-policy.mjs +37 -0
- package/dist/abort.js +25 -0
- package/dist/args.js +102 -3
- package/dist/cli.js +229 -33
- package/dist/cloudflared/bundled-asset.js +3 -2
- package/dist/cloudflared/manifest.js +2 -2
- package/dist/codex-desktop-command.js +70 -0
- package/dist/codex-desktop-force-stop.js +46 -0
- package/dist/codex-desktop-idle-guard.js +15 -0
- package/dist/codex-desktop-preflight.js +63 -0
- package/dist/codex-desktop-probe.js +152 -0
- package/dist/codex-desktop-setup.js +154 -0
- package/dist/codex-desktop-status.js +85 -0
- package/dist/codex-desktop-windows.js +122 -0
- package/dist/codex-runtime-manager.js +368 -0
- package/dist/codex-sharing.js +153 -0
- package/dist/codex-windows-backend-host.js +59 -0
- package/dist/codex-windows-backend.js +120 -0
- package/dist/desktop-authorization-prompt.js +84 -0
- package/dist/desktop-authorization.js +161 -0
- package/dist/device-pairing.js +170 -0
- package/dist/error-log.js +113 -0
- package/dist/instance-takeover.js +143 -0
- package/dist/local-desktop-url.js +8 -0
- package/dist/local-service-request.js +69 -0
- package/dist/native-runtime.js +68 -0
- package/dist/network.js +32 -3
- package/dist/node-runtime-manager.js +251 -0
- package/dist/opencode-runtime-manager.js +239 -0
- package/dist/platform-packages.js +16 -5
- package/dist/platform.js +6 -4
- package/dist/power/sleep-inhibitor.js +161 -0
- package/dist/runtime-manager.js +129 -19
- package/dist/service/launcher-cleanup.js +79 -0
- package/dist/service/macos-launch-agent.js +288 -0
- package/dist/service/runtime-state.js +43 -0
- package/dist/service/service-command.js +219 -0
- package/dist/service/service-controller.js +27 -0
- package/dist/service/service-files.js +78 -0
- package/dist/service/windows-service-host.js +59 -0
- package/dist/service/windows-task-service.js +289 -0
- package/dist/startup-lock.js +81 -0
- package/dist/tunnel/cloudflare-provider.js +4 -1
- package/dist/tunnel/public-readiness.js +76 -50
- package/dist/tunnel/relay-orchestrator.js +29 -9
- package/dist/unlock-service.js +105 -0
- package/dist/update/update-channel.js +38 -0
- package/dist/update/update-command.js +96 -0
- package/dist/update/update-install.js +34 -0
- package/dist/update/update-state.js +43 -0
- package/dist/update/update-worker.js +80 -0
- package/install/README.md +55 -0
- package/install/codex-shared-watchdog.sh +16 -0
- package/install/install-agentroam.ps1 +358 -0
- package/install/install-agentroam.sh +457 -0
- package/install/install-manifest.json +15 -0
- package/install/start-codex-desktop-shared.sh +152 -0
- package/package.json +13 -10
- package/dist/args.test.js +0 -27
- package/dist/cloudflared/bundled-asset.test.js +0 -76
- package/dist/cloudflared/installer.test.js +0 -95
- package/dist/native-runtime.test.js +0 -19
- package/dist/network.test.js +0 -20
- package/dist/pairing.js +0 -2
- package/dist/platform-packages.test.js +0 -75
- package/dist/platform.test.js +0 -3
- package/dist/port.test.js +0 -3
- package/dist/process-supervisor.test.js +0 -42
- package/dist/tunnel/cloudflare-provider.test.js +0 -33
- package/dist/tunnel/pinggy-provider.test.js +0 -40
- package/dist/tunnel/proxy-settings.test.js +0 -111
- package/dist/tunnel/public-readiness.test.js +0 -104
- package/dist/tunnel/relay-orchestrator.test.js +0 -72
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# AgentRoam bootstrap installers
|
|
2
|
+
|
|
3
|
+
These installers support macOS Apple Silicon and Windows x64. They install the newest published `preview` release by default (resolved from the npm dist-tag); pin an exact release with `AGENTROAM_VERSION=<x.y.z-preview.N>`. They reuse the active Node.js installation when it meets `>=22.22.0`, with no upper version bound. Otherwise they search NVM for the highest compatible version, then fall back to the verified private Node.js `22.22.0` runtime under the AgentRoam data directory. They then register and start the current-user AgentRoam background service. They never modify, replace, or uninstall system Node.js or global power settings.
|
|
4
|
+
|
|
5
|
+
## macOS Apple Silicon
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
curl -fsSL https://github.com/tclxqu-cao/team-agent/raw/main/packages/cli/install/install-agentroam.sh | sh
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The command installs the wrapper at `~/.local/bin/agentroam`. If that directory is not already in `PATH`, the installer prints the required shell setting without editing shell profiles.
|
|
12
|
+
|
|
13
|
+
## Windows x64
|
|
14
|
+
|
|
15
|
+
```powershell
|
|
16
|
+
irm https://github.com/tclxqu-cao/team-agent/raw/main/packages/cli/install/install-agentroam.ps1 | iex
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The command installs `%USERPROFILE%\.agentroam\bin\agentroam.cmd` and adds only that user directory to the user-level `PATH`. It does not require administrator access or change the machine-level `PATH`.
|
|
20
|
+
|
|
21
|
+
## Service behavior
|
|
22
|
+
|
|
23
|
+
Run the installer from the project directory AgentRoam should expose, or set `AGENTROAM_ROOT` explicitly. The current directory is accepted even when it is the home directory.
|
|
24
|
+
|
|
25
|
+
The installer registers and starts the service after Node, CLI, and `doctor` validation. When a previous AgentRoam user service is installed, the new CLI stops it, waits for its process and platform registration to exit, removes only the old service registration, and then registers the replacement. Session data, pairing state, managed runtimes, and logs remain in the data directory. While foreground AgentRoam or the service is running, it prevents idle system sleep but still allows the display to dim and turn off. Lid close, explicit sleep, hibernation, shutdown, and low-battery forced sleep remain controlled by the operating system.
|
|
26
|
+
|
|
27
|
+
On interactive terminals, `service install`, `start`, `status`, and `restart` print a scannable QR code beside the `Open:` URL. Piped or redirected output stays plain text, and `agentroam service install --no-qr` suppresses the code. `service url` always prints only the raw URL for scripting.
|
|
28
|
+
|
|
29
|
+
Use the installer for first installation, upgrades, and repair. Use these commands for routine control:
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
agentroam service start
|
|
33
|
+
agentroam service stop
|
|
34
|
+
agentroam service restart
|
|
35
|
+
agentroam service status
|
|
36
|
+
agentroam service url
|
|
37
|
+
agentroam service logs
|
|
38
|
+
agentroam service uninstall
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Data and updates
|
|
42
|
+
|
|
43
|
+
Set `AGENTROAM_DATA_DIR` before running either installer to override the default `~/.agentroam` data directory. Node is stored at `<data-dir>/runtimes/node/22.22.0`, and the launcher is stored at `<data-dir>/launcher/<version>`.
|
|
44
|
+
|
|
45
|
+
Each AgentRoam release pins its own Node patch. Updates happen by running the installer again (it resolves the newest published `preview`) or by installing a newer AgentRoam release; startup never follows a moving Node.js release channel.
|
|
46
|
+
|
|
47
|
+
To uninstall the wrapper, remove `~/.local/bin/agentroam` on macOS or `%USERPROFILE%\.agentroam\bin\agentroam.cmd` on Windows. The private runtime, launcher, session data, and configuration under the data directory are preserved until explicitly removed by the user.
|
|
48
|
+
|
|
49
|
+
## Optional desktop app
|
|
50
|
+
|
|
51
|
+
After CLI setup succeeds, interactive installers ask whether to download the desktop app. Answer `y` to download the matching macOS DMG or Windows installer into a unique folder under Downloads, verify its release-manifest SHA-256, and show the file. Open it to complete installation. Answer `n` or press Enter to keep using CLI only. Noninteractive runs skip the prompt.
|
|
52
|
+
|
|
53
|
+
Set `AGENTROAM_INSTALL_DESKTOP=yes` or `no` explicitly for automation. The Shell installer reads `/dev/tty`, so `curl ... | sh` remains interactive. A missing desktop artifact or failed download does not undo CLI installation. This requires a published CLI that includes `bin/desktop-download.mjs` and matching desktop release assets.
|
|
54
|
+
|
|
55
|
+
On macOS, the desktop app opens its own permission guide on first launch, even before connecting to a service. Screen Recording enables phone viewing; Accessibility enables keyboard and mouse control. Returning from System Settings rechecks permissions and resumes an enabled session. Restart the desktop app if macOS requires it. Desktop live publishing follows the selected CLI service, including its actual port. Windows desktop download is supported, but the current screen/input helper is macOS-only.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Copied to a stable private directory: upgrades must not invalidate this job.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
codex_bin="$1"
|
|
5
|
+
codex_home="$2"
|
|
6
|
+
shared_url="$3"
|
|
7
|
+
export CODEX_HOME="$codex_home"
|
|
8
|
+
export PATH="$4"
|
|
9
|
+
export CODEX_APP_SERVER_FORCE_CLI=0
|
|
10
|
+
export CODEX_APP_SERVER_WS_URL="$shared_url"
|
|
11
|
+
/bin/launchctl setenv CODEX_APP_SERVER_WS_URL "$shared_url"
|
|
12
|
+
/bin/launchctl setenv CODEX_APP_SERVER_FORCE_CLI 0
|
|
13
|
+
/bin/launchctl setenv CODEX_HOME "$codex_home"
|
|
14
|
+
# daemon start is idempotent; never stop or replace a live daemon.
|
|
15
|
+
cd "$5"
|
|
16
|
+
exec "$codex_bin" app-server daemon start
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
2
|
+
$ProgressPreference = "SilentlyContinue"
|
|
3
|
+
|
|
4
|
+
$NodeVersion = "22.22.0"
|
|
5
|
+
$MinimumNodeVersion = "22.22.0"
|
|
6
|
+
# 默认跟随 npm preview 最新标签;可用 $env:AGENTROAM_VERSION 钉精确版本
|
|
7
|
+
# 例如:$env:AGENTROAM_VERSION = "<x.y.z-preview.N>"; ./install-agentroam.ps1
|
|
8
|
+
$AgentRoamVersionRequest = if ($env:AGENTROAM_VERSION) { $env:AGENTROAM_VERSION } else { "preview" }
|
|
9
|
+
$AgentRoamVersion = "pending-version"
|
|
10
|
+
$NodeArchive = "node-v22.22.0-win-x64.zip"
|
|
11
|
+
$NodeSha256 = "c97fa376d2becdc8863fcd3ca2dd9a83a9f3468ee7ccf7a6d076ec66a645c77a"
|
|
12
|
+
$NodeUrl = "https://nodejs.org/dist/v22.22.0/$NodeArchive"
|
|
13
|
+
$NpmRegistry = "https://registry.npmjs.org"
|
|
14
|
+
$DataDir = if ($env:AGENTROAM_DATA_DIR) { $env:AGENTROAM_DATA_DIR } else { Join-Path $HOME ".agentroam" }
|
|
15
|
+
$NodeParent = Join-Path $DataDir "runtimes\node"
|
|
16
|
+
$NodeRoot = Join-Path $NodeParent $NodeVersion
|
|
17
|
+
$NodeLock = "$NodeRoot.lock"
|
|
18
|
+
$LauncherParent = Join-Path $DataDir "launcher"
|
|
19
|
+
$LauncherRoot = Join-Path $LauncherParent $AgentRoamVersion
|
|
20
|
+
$LauncherLock = "$LauncherRoot.lock"
|
|
21
|
+
$WrapperDir = Join-Path $HOME ".agentroam\bin"
|
|
22
|
+
$WrapperPath = Join-Path $WrapperDir "agentroam.cmd"
|
|
23
|
+
$ServiceRootExplicit = -not [string]::IsNullOrWhiteSpace($env:AGENTROAM_ROOT)
|
|
24
|
+
$ServiceRoot = if ($ServiceRootExplicit) { $env:AGENTROAM_ROOT } else { (Get-Location).Path }
|
|
25
|
+
if (-not (Test-Path -LiteralPath $ServiceRoot -PathType Container)) { throw "AgentRoam root is not a directory: $ServiceRoot" }
|
|
26
|
+
$ServiceRoot = [System.IO.Path]::GetFullPath($ServiceRoot).TrimEnd([System.IO.Path]::DirectorySeparatorChar)
|
|
27
|
+
New-Item -ItemType Directory -Force -Path $NodeParent, $LauncherParent, $WrapperDir | Out-Null
|
|
28
|
+
|
|
29
|
+
function Test-NodeVersion([string]$VersionText) {
|
|
30
|
+
if ($VersionText -notmatch '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$') { return $false }
|
|
31
|
+
try { return [Version]($VersionText.Split('+')[0]) -ge [Version]$MinimumNodeVersion } catch { return $false }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function Test-SupportedNode([string]$NodeBin) {
|
|
35
|
+
if (-not (Test-Path -LiteralPath $NodeBin -PathType Leaf)) { return $false }
|
|
36
|
+
try { return Test-NodeVersion ((& $NodeBin -p 'process.versions.node' 2>$null).Trim()) } catch { return $false }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function Get-NvmRoots {
|
|
40
|
+
$Candidates = @()
|
|
41
|
+
if ($env:NVM_HOME) { $Candidates += $env:NVM_HOME }
|
|
42
|
+
if ($env:APPDATA) { $Candidates += (Join-Path $env:APPDATA "nvm") }
|
|
43
|
+
$NvmCommand = Get-Command nvm.exe -ErrorAction SilentlyContinue
|
|
44
|
+
if ($NvmCommand) {
|
|
45
|
+
try {
|
|
46
|
+
$RootOutput = (& $NvmCommand.Source root 2>$null | Select-Object -Last 1)
|
|
47
|
+
if ($RootOutput) {
|
|
48
|
+
$RootText = $RootOutput.Trim()
|
|
49
|
+
if ($RootText -match '^[^:]+:\s+(.+)$') { $RootText = $Matches[1].Trim() }
|
|
50
|
+
$Candidates += $RootText
|
|
51
|
+
}
|
|
52
|
+
} catch {}
|
|
53
|
+
}
|
|
54
|
+
@($Candidates | Where-Object { $_ -and (Test-Path -LiteralPath $_ -PathType Container) } | Select-Object -Unique)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function Find-NvmNode {
|
|
58
|
+
$VersionMatches = foreach ($NvmRoot in (Get-NvmRoots)) {
|
|
59
|
+
foreach ($VersionDirectory in Get-ChildItem -LiteralPath $NvmRoot -Directory -ErrorAction SilentlyContinue) {
|
|
60
|
+
$Candidate = Join-Path $VersionDirectory.FullName "node.exe"
|
|
61
|
+
if (-not (Test-Path -LiteralPath $Candidate -PathType Leaf)) { continue }
|
|
62
|
+
try {
|
|
63
|
+
$VersionText = (& $Candidate -p 'process.versions.node' 2>$null).Trim()
|
|
64
|
+
if (Test-NodeVersion $VersionText) {
|
|
65
|
+
$Version = [Version]($VersionText.Split('+')[0])
|
|
66
|
+
[pscustomobject]@{ Path = $Candidate; Version = $Version }
|
|
67
|
+
}
|
|
68
|
+
} catch {}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
$Best = $VersionMatches | Sort-Object Version -Descending | Select-Object -First 1
|
|
72
|
+
if ($Best) { return $Best.Path }
|
|
73
|
+
return $null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function Test-ManagedNode {
|
|
77
|
+
$NodeBin = Join-Path $NodeRoot "node.exe"
|
|
78
|
+
$NpmCli = Join-Path $NodeRoot "node_modules\npm\bin\npm-cli.js"
|
|
79
|
+
if (-not (Test-Path -LiteralPath $NodeBin -PathType Leaf) -or -not (Test-Path -LiteralPath $NpmCli -PathType Leaf)) { return $false }
|
|
80
|
+
try { return (& $NodeBin --version 2>$null) -eq "v$NodeVersion" } catch { return $false }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function Enter-InstallLock([string]$Path) {
|
|
84
|
+
$Deadline = [DateTime]::UtcNow.AddMinutes(15)
|
|
85
|
+
while ($true) {
|
|
86
|
+
try {
|
|
87
|
+
$Stream = [System.IO.File]::Open($Path, [System.IO.FileMode]::CreateNew, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None)
|
|
88
|
+
$Bytes = [Text.Encoding]::UTF8.GetBytes("$PID`n$([DateTime]::UtcNow.ToString('o'))`n")
|
|
89
|
+
$Stream.Write($Bytes, 0, $Bytes.Length)
|
|
90
|
+
return $Stream
|
|
91
|
+
} catch [System.IO.IOException] {
|
|
92
|
+
if (Test-Path -LiteralPath $Path) {
|
|
93
|
+
$Age = [DateTime]::UtcNow - (Get-Item -LiteralPath $Path).LastWriteTimeUtc
|
|
94
|
+
if ($Age.TotalMinutes -gt 15) { Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue; continue }
|
|
95
|
+
}
|
|
96
|
+
if ([DateTime]::UtcNow -ge $Deadline) { throw "Timed out waiting for install lock $Path" }
|
|
97
|
+
Start-Sleep -Milliseconds 500
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
$SystemNode = Get-Command node.exe -ErrorAction SilentlyContinue
|
|
103
|
+
if ($env:AGENTROAM_BOOTSTRAP_TEST -eq "1" -and $env:AGENTROAM_FORCE_PRIVATE_NODE -eq "1") { $SystemNode = $null }
|
|
104
|
+
if ($SystemNode -and (Test-SupportedNode $SystemNode.Source)) {
|
|
105
|
+
$NodeBin = $SystemNode.Source
|
|
106
|
+
} else {
|
|
107
|
+
$NvmNode = if ($env:AGENTROAM_BOOTSTRAP_TEST -eq "1" -and $env:AGENTROAM_FORCE_PRIVATE_NODE -eq "1") { $null } else { Find-NvmNode }
|
|
108
|
+
if ($NvmNode) {
|
|
109
|
+
$NodeBin = $NvmNode
|
|
110
|
+
Write-Host "Using Node.js $(& $NodeBin --version) from NVM: $NodeBin"
|
|
111
|
+
} else {
|
|
112
|
+
if (-not (Test-ManagedNode)) {
|
|
113
|
+
$NodeLockHandle = Enter-InstallLock $NodeLock
|
|
114
|
+
try {
|
|
115
|
+
if (-not (Test-ManagedNode)) {
|
|
116
|
+
$TempRoot = Join-Path $NodeParent ".node-$NodeVersion-$PID-$([Guid]::NewGuid().ToString('N'))"
|
|
117
|
+
$ArchivePath = Join-Path $TempRoot $NodeArchive
|
|
118
|
+
$ExtractPath = Join-Path $TempRoot "extract"
|
|
119
|
+
New-Item -ItemType Directory -Force -Path $ExtractPath | Out-Null
|
|
120
|
+
try {
|
|
121
|
+
Write-Host "Downloading Node.js $NodeVersion..."
|
|
122
|
+
if ($env:AGENTROAM_NODE_ARCHIVE_FILE) {
|
|
123
|
+
Copy-Item -LiteralPath $env:AGENTROAM_NODE_ARCHIVE_FILE -Destination $ArchivePath
|
|
124
|
+
} else {
|
|
125
|
+
Invoke-WebRequest -UseBasicParsing -TimeoutSec 600 -Uri $NodeUrl -OutFile $ArchivePath
|
|
126
|
+
}
|
|
127
|
+
$ActualHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $ArchivePath).Hash.ToLowerInvariant()
|
|
128
|
+
if ($ActualHash -ne $NodeSha256) { throw "Node.js archive checksum mismatch" }
|
|
129
|
+
Expand-Archive -LiteralPath $ArchivePath -DestinationPath $ExtractPath -Force
|
|
130
|
+
$Entries = @(Get-ChildItem -LiteralPath $ExtractPath)
|
|
131
|
+
if ($Entries.Count -ne 1 -or $Entries[0].Name -ne "node-v$NodeVersion-win-x64") { throw "Unexpected Node.js archive layout" }
|
|
132
|
+
$Extracted = $Entries[0].FullName
|
|
133
|
+
$ExtractedNode = Join-Path $Extracted "node.exe"
|
|
134
|
+
$ExtractedNpm = Join-Path $Extracted "node_modules\npm\bin\npm-cli.js"
|
|
135
|
+
if (-not (Test-Path -LiteralPath $ExtractedNpm) -or (& $ExtractedNode --version) -ne "v$NodeVersion") { throw "Node.js runtime validation failed" }
|
|
136
|
+
Remove-Item -LiteralPath $NodeRoot -Recurse -Force -ErrorAction SilentlyContinue
|
|
137
|
+
Move-Item -LiteralPath $Extracted -Destination $NodeRoot
|
|
138
|
+
if (-not (Test-ManagedNode)) { throw "Node.js activation validation failed" }
|
|
139
|
+
} finally {
|
|
140
|
+
Remove-Item -LiteralPath $TempRoot -Recurse -Force -ErrorAction SilentlyContinue
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} finally {
|
|
144
|
+
$NodeLockHandle.Dispose()
|
|
145
|
+
Remove-Item -LiteralPath $NodeLock -Force -ErrorAction SilentlyContinue
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
$NodeBin = Join-Path $NodeRoot "node.exe"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if ($env:AGENTROAM_BOOTSTRAP_TEST -eq "1" -and $env:AGENTROAM_BOOTSTRAP_NODE_DISCOVERY_ONLY -eq "1") {
|
|
153
|
+
Write-Output $NodeBin
|
|
154
|
+
exit 0
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
$NodeDirectory = Split-Path -Parent $NodeBin
|
|
158
|
+
$NpmCandidates = @(
|
|
159
|
+
(Join-Path $NodeDirectory "node_modules\npm\bin\npm-cli.js"),
|
|
160
|
+
(Join-Path $NodeDirectory "..\node_modules\npm\bin\npm-cli.js")
|
|
161
|
+
)
|
|
162
|
+
$NpmCli = $NpmCandidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
|
|
163
|
+
if (-not $NpmCli) { throw "npm CLI was not found beside $NodeBin" }
|
|
164
|
+
|
|
165
|
+
# 解析 dist-tag → 精确版本(安装最总是最新发布)
|
|
166
|
+
if ($AgentRoamVersionRequest -notmatch '\d$') {
|
|
167
|
+
$Resolved = (& $NodeBin $NpmCli view "agentroam@$AgentRoamVersionRequest" version --registry $NpmRegistry 2>$null | Select-Object -Last 1)
|
|
168
|
+
if (-not $Resolved) { throw "could not resolve agentroam@$AgentRoamVersionRequest from $NpmRegistry" }
|
|
169
|
+
$AgentRoamVersion = ([string]$Resolved).Trim()
|
|
170
|
+
Write-Host "Installing AgentRoam $AgentRoamVersion (resolved from $AgentRoamVersionRequest)"
|
|
171
|
+
} else {
|
|
172
|
+
$AgentRoamVersion = $AgentRoamVersionRequest
|
|
173
|
+
}
|
|
174
|
+
$LauncherRoot = Join-Path $LauncherParent $AgentRoamVersion
|
|
175
|
+
$LauncherLock = "$LauncherRoot.lock"
|
|
176
|
+
$PackageSpec = "agentroam@$AgentRoamVersion"
|
|
177
|
+
$ExtraPackageSpecs = @()
|
|
178
|
+
if ($env:AGENTROAM_BOOTSTRAP_TEST -eq "1" -and $env:AGENTROAM_PACKAGE_SPEC) {
|
|
179
|
+
$PackageSpec = $env:AGENTROAM_PACKAGE_SPEC
|
|
180
|
+
if ($env:AGENTROAM_BOOTSTRAP_EXTRA_SPECS) { $ExtraPackageSpecs = @($env:AGENTROAM_BOOTSTRAP_EXTRA_SPECS.Split(';') | Where-Object { $_ }) }
|
|
181
|
+
}
|
|
182
|
+
$Entry = Join-Path $LauncherRoot "node_modules\agentroam\bin\agentroam.mjs"
|
|
183
|
+
|
|
184
|
+
$LauncherCheckSource = @'
|
|
185
|
+
const { readFileSync, statSync } = require("node:fs");
|
|
186
|
+
const { createHash } = require("node:crypto");
|
|
187
|
+
const { createRequire } = require("node:module");
|
|
188
|
+
const { dirname, resolve, sep } = require("node:path");
|
|
189
|
+
const [prefix, launcherVersion, minimumNodeVersion, target, mode] = process.argv.slice(process.argv[1] === "-" ? 2 : 1);
|
|
190
|
+
try {
|
|
191
|
+
const packageName = {
|
|
192
|
+
"darwin-arm64": "agentroam-runtime-darwin-arm64",
|
|
193
|
+
"windows-amd64": "agentroam-runtime-win32-x64",
|
|
194
|
+
}[target];
|
|
195
|
+
if (!packageName) throw new Error("Unsupported runtime target: " + target);
|
|
196
|
+
const launcherPath = resolve(prefix, "node_modules/agentroam/package.json");
|
|
197
|
+
const launcher = JSON.parse(readFileSync(launcherPath, "utf8"));
|
|
198
|
+
if (launcher.version !== launcherVersion) throw new Error("AgentRoam launcher version mismatch");
|
|
199
|
+
const version = launcher.optionalDependencies?.[packageName];
|
|
200
|
+
if (typeof version !== "string" || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {
|
|
201
|
+
throw new Error("Runtime dependency must use an exact version: " + packageName);
|
|
202
|
+
}
|
|
203
|
+
if (mode === "spec") {
|
|
204
|
+
console.log(packageName + "@" + version);
|
|
205
|
+
} else {
|
|
206
|
+
if (mode !== "verify") throw new Error("Unknown runtime validation mode: " + mode);
|
|
207
|
+
const launcherRequire = createRequire(launcherPath);
|
|
208
|
+
const manifestPath = launcherRequire.resolve(packageName + "/manifest.json");
|
|
209
|
+
const runtimeRoot = dirname(launcherRequire.resolve(packageName + "/runtime"));
|
|
210
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
211
|
+
const runtimePackage = JSON.parse(readFileSync(resolve(dirname(manifestPath), "package.json"), "utf8"));
|
|
212
|
+
if (runtimePackage.name !== packageName || runtimePackage.version !== version ||
|
|
213
|
+
manifest.packageVersion !== version || manifest.target !== target ||
|
|
214
|
+
manifest.schemaVersion !== 2 || manifest.minimumNodeVersion !== minimumNodeVersion ||
|
|
215
|
+
!manifest.nativeFiles || typeof manifest.nativeFiles !== "object" || Array.isArray(manifest.nativeFiles)) {
|
|
216
|
+
throw new Error("Invalid runtime manifest: " + manifestPath);
|
|
217
|
+
}
|
|
218
|
+
const nativeTarget = target === "darwin-arm64" ? "darwin-arm64" : "win32-x64";
|
|
219
|
+
for (const file of [
|
|
220
|
+
"node_modules/better-sqlite3/prebuilds/" + nativeTarget + ".node",
|
|
221
|
+
"node_modules/node-pty/prebuilds/" + nativeTarget + "/pty.node",
|
|
222
|
+
...(target === "darwin-arm64"
|
|
223
|
+
? ["node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper"]
|
|
224
|
+
: ["node_modules/node-pty/prebuilds/win32-x64/conpty.node",
|
|
225
|
+
"node_modules/node-pty/prebuilds/win32-x64/conpty/conpty.dll",
|
|
226
|
+
"node_modules/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe"]),
|
|
227
|
+
]) {
|
|
228
|
+
if (!manifest.nativeFiles[file]) throw new Error("Missing runtime native inventory: " + file);
|
|
229
|
+
}
|
|
230
|
+
for (const file of ["bin/agentroam.mjs"]) {
|
|
231
|
+
if (!statSync(resolve(dirname(launcherPath), file)).isFile()) throw new Error("Missing launcher file: " + file);
|
|
232
|
+
}
|
|
233
|
+
for (const file of ["ws-server.mjs", ".next/BUILD_ID"]) {
|
|
234
|
+
if (!statSync(resolve(runtimeRoot, file)).isFile()) throw new Error("Missing runtime file: " + file);
|
|
235
|
+
}
|
|
236
|
+
for (const [file, expectedHash] of Object.entries(manifest.nativeFiles)) {
|
|
237
|
+
const path = resolve(runtimeRoot, file);
|
|
238
|
+
if (!path.startsWith(runtimeRoot + sep) || !/^[a-f0-9]{64}$/.test(expectedHash)) {
|
|
239
|
+
throw new Error("Invalid runtime native inventory: " + file);
|
|
240
|
+
}
|
|
241
|
+
const actualHash = createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
242
|
+
if (actualHash !== expectedHash) throw new Error("Runtime native file checksum mismatch: " + file);
|
|
243
|
+
}
|
|
244
|
+
const runtimeRequire = createRequire(resolve(runtimeRoot, "package.json"));
|
|
245
|
+
for (const name of ["better-sqlite3", "node-pty"]) {
|
|
246
|
+
if (!runtimeRequire.resolve(name).startsWith(runtimeRoot + sep)) throw new Error("Missing runtime module: " + name);
|
|
247
|
+
}
|
|
248
|
+
const Database = runtimeRequire("better-sqlite3");
|
|
249
|
+
const database = new Database(":memory:");
|
|
250
|
+
try {
|
|
251
|
+
if (database.prepare("SELECT 1 AS ok").get()?.ok !== 1) throw new Error("SQLite runtime query failed");
|
|
252
|
+
} finally {
|
|
253
|
+
database.close();
|
|
254
|
+
}
|
|
255
|
+
if (typeof runtimeRequire("node-pty").spawn !== "function") throw new Error("Invalid PTY runtime module");
|
|
256
|
+
}
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error("AgentRoam runtime validation failed: " + error.message);
|
|
259
|
+
process.exitCode = 1;
|
|
260
|
+
}
|
|
261
|
+
'@
|
|
262
|
+
|
|
263
|
+
function Test-LauncherRuntime([string]$Prefix) {
|
|
264
|
+
try {
|
|
265
|
+
# Pipe JavaScript to Node so Windows PowerShell 5 does not strip its quotes.
|
|
266
|
+
$LauncherCheckSource | & $NodeBin - $Prefix $AgentRoamVersion $MinimumNodeVersion windows-amd64 verify 2>$null
|
|
267
|
+
return $LASTEXITCODE -eq 0
|
|
268
|
+
} catch { return $false }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function Test-Launcher {
|
|
272
|
+
return Test-LauncherRuntime $LauncherRoot
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (-not (Test-Launcher)) {
|
|
276
|
+
$LauncherLockHandle = Enter-InstallLock $LauncherLock
|
|
277
|
+
try {
|
|
278
|
+
if (-not (Test-Launcher)) {
|
|
279
|
+
$TempLauncher = Join-Path $LauncherParent ".launcher-$AgentRoamVersion-$PID-$([Guid]::NewGuid().ToString('N'))"
|
|
280
|
+
try {
|
|
281
|
+
$NpmArgs = @("install", "--no-audit", "--no-fund", "--registry", $NpmRegistry, "--prefix", $TempLauncher) + $ExtraPackageSpecs + @($PackageSpec)
|
|
282
|
+
& $NodeBin $NpmCli @NpmArgs
|
|
283
|
+
if ($LASTEXITCODE -ne 0) { throw "npm install failed with exit code $LASTEXITCODE" }
|
|
284
|
+
$RuntimeSpec = [string]($LauncherCheckSource | & $NodeBin - $TempLauncher $AgentRoamVersion $MinimumNodeVersion windows-amd64 spec)
|
|
285
|
+
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($RuntimeSpec)) { throw "AgentRoam runtime dependency validation failed" }
|
|
286
|
+
if (-not (Test-LauncherRuntime $TempLauncher)) {
|
|
287
|
+
Remove-Item -LiteralPath (Join-Path $TempLauncher "node_modules\agentroam-runtime-win32-x64") -Recurse -Force -ErrorAction SilentlyContinue
|
|
288
|
+
$RuntimeArgs = @("install", "--save-exact", "--include=optional", "--no-audit", "--no-fund", "--registry", $NpmRegistry, "--prefix", $TempLauncher, $RuntimeSpec.Trim())
|
|
289
|
+
& $NodeBin $NpmCli @RuntimeArgs
|
|
290
|
+
if ($LASTEXITCODE -ne 0) { throw "Required AgentRoam runtime install failed with exit code $LASTEXITCODE" }
|
|
291
|
+
}
|
|
292
|
+
$LauncherCheckSource | & $NodeBin - $TempLauncher $AgentRoamVersion $MinimumNodeVersion windows-amd64 verify
|
|
293
|
+
if ($LASTEXITCODE -ne 0) { throw "AgentRoam runtime validation failed; previous installation preserved" }
|
|
294
|
+
$PreviousLauncher = $null
|
|
295
|
+
if (Test-Path -LiteralPath $LauncherRoot) {
|
|
296
|
+
$PreviousLauncher = Join-Path $LauncherParent ".previous-$AgentRoamVersion-$([Guid]::NewGuid().ToString('N'))"
|
|
297
|
+
Move-Item -LiteralPath $LauncherRoot -Destination $PreviousLauncher
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
Move-Item -LiteralPath $TempLauncher -Destination $LauncherRoot
|
|
301
|
+
} catch {
|
|
302
|
+
if ($PreviousLauncher -and -not (Test-Path -LiteralPath $LauncherRoot)) {
|
|
303
|
+
Move-Item -LiteralPath $PreviousLauncher -Destination $LauncherRoot
|
|
304
|
+
}
|
|
305
|
+
throw
|
|
306
|
+
}
|
|
307
|
+
if ($PreviousLauncher) { Remove-Item -LiteralPath $PreviousLauncher -Recurse -Force }
|
|
308
|
+
} finally {
|
|
309
|
+
Remove-Item -LiteralPath $TempLauncher -Recurse -Force -ErrorAction SilentlyContinue
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
} finally {
|
|
313
|
+
$LauncherLockHandle.Dispose()
|
|
314
|
+
Remove-Item -LiteralPath $LauncherLock -Force -ErrorAction SilentlyContinue
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
$WrapperTemp = "$WrapperPath.$PID.tmp"
|
|
319
|
+
$WrapperContent = "@echo off`r`n`"$NodeBin`" `"$Entry`" %*`r`n"
|
|
320
|
+
[System.IO.File]::WriteAllText($WrapperTemp, $WrapperContent, [Text.Encoding]::ASCII)
|
|
321
|
+
Move-Item -LiteralPath $WrapperTemp -Destination $WrapperPath -Force
|
|
322
|
+
|
|
323
|
+
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
|
324
|
+
$PathParts = @($UserPath -split ";" | Where-Object { $_ })
|
|
325
|
+
if ($PathParts -notcontains $WrapperDir) {
|
|
326
|
+
$UpdatedPath = if ($UserPath) { "$UserPath;$WrapperDir" } else { $WrapperDir }
|
|
327
|
+
[Environment]::SetEnvironmentVariable("Path", $UpdatedPath, "User")
|
|
328
|
+
$env:Path = "$env:Path;$WrapperDir"
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
& $NodeBin $Entry doctor --data-dir $DataDir
|
|
332
|
+
if ($LASTEXITCODE -ne 0) { Write-Warning "Some component checks failed; continuing background service installation. Affected features may be unavailable. Run agentroam doctor to retry." }
|
|
333
|
+
if ($env:AGENTROAM_INSTALL_SKIP_SERVICE -eq "1") {
|
|
334
|
+
Write-Host "AgentRoam service registration skipped for isolated verification."
|
|
335
|
+
} else {
|
|
336
|
+
& $NodeBin $Entry service install --root $ServiceRoot --data-dir $DataDir --setup-codex-desktop
|
|
337
|
+
if ($LASTEXITCODE -ne 0) { throw "CLI installed, but the background service failed (exit $LASTEXITCODE). Run agentroam service logs, fix the error, then run agentroam service start and agentroam pair." }
|
|
338
|
+
}
|
|
339
|
+
Write-Host "`nAgentRoam $AgentRoamVersion installed: $WrapperPath"
|
|
340
|
+
Write-Host "Open a new terminal, then run: agentroam service status"
|
|
341
|
+
|
|
342
|
+
$DesktopChoice = if ($env:AGENTROAM_INSTALL_DESKTOP) { $env:AGENTROAM_INSTALL_DESKTOP } else { "ask" }
|
|
343
|
+
if ($env:AGENTROAM_INSTALL_SKIP_SERVICE -eq "1" -and $DesktopChoice -eq "ask") { $DesktopChoice = "no" }
|
|
344
|
+
if ($DesktopChoice -eq "ask") {
|
|
345
|
+
$DesktopChoice = "no"
|
|
346
|
+
if ([Environment]::UserInteractive -and -not [Console]::IsInputRedirected) {
|
|
347
|
+
try { $DesktopChoice = Read-Host "Download the desktop app for remote viewing and control? [y/N]" } catch { $DesktopChoice = "no" }
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if ($DesktopChoice -match '^(y|yes|是)$') {
|
|
351
|
+
$DesktopHelper = Join-Path $LauncherRoot "node_modules\agentroam\bin\desktop-download.mjs"
|
|
352
|
+
if (Test-Path -LiteralPath $DesktopHelper -PathType Leaf) {
|
|
353
|
+
& $NodeBin $DesktopHelper $AgentRoamVersion
|
|
354
|
+
if ($LASTEXITCODE -ne 0) { Write-Warning "CLI installation completed. You can retry the desktop download later." }
|
|
355
|
+
} else {
|
|
356
|
+
Write-Warning "This CLI version does not support desktop downloads. CLI installation completed; upgrade to retry."
|
|
357
|
+
}
|
|
358
|
+
} else { Write-Host "Desktop download skipped. CLI is ready to use." }
|