-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
225 lines (198 loc) · 8.02 KB
/
Copy pathsetup.ps1
File metadata and controls
225 lines (198 loc) · 8.02 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
#Requires -Version 7.0
<#
.SYNOPSIS
One-shot setup for Anya — GitHub Copilot for your browser.
.DESCRIPTION
Cross-platform PowerShell 7+ installer. Installs deps + builds both
projects, runs the bridge ping smoke test, and registers the Native
Messaging host for every detected Chromium browser (Edge, Chrome,
Chromium, Brave, Vivaldi, Arc).
Works on Windows, macOS, and Linux. For users without pwsh, an
equivalent setup.sh is provided.
.PARAMETER Browsers
One or more of: edge, chrome, chromium, brave, vivaldi, arc, all (default).
Forwarded to bridge\install.ps1.
.PARAMETER Quiet
Skip the interactive browser picker when multiple Chromium browsers are
detected (registers for all of them).
.PARAMETER SkipTest
Skip the bridge ping/pong smoke test.
.PARAMETER Uninstall
Remove every browser's registration + manifest, then exit.
#>
[CmdletBinding()]
param(
[string[]]$Browsers = @('all'),
[switch]$Quiet,
[switch]$SkipTest,
[switch]$Uninstall
)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $root
if (-not ($IsWindows -or $IsMacOS -or $IsLinux)) {
throw 'Unsupported OS — Anya supports Windows, macOS, and Linux.'
}
function Step($msg) { Write-Host "`n=== $msg ===" -ForegroundColor Cyan }
function Ok($msg) { Write-Host " OK $msg" -ForegroundColor Green }
function Info($msg) { Write-Host " $msg" -ForegroundColor DarkGray }
# Mirrors bridge/src/paths.ts so we can show the right log path in the summary.
function Get-AnyaDataDir {
if ($IsWindows) {
$base = $env:LOCALAPPDATA
if (-not $base) { $base = Join-Path $env:USERPROFILE 'AppData\Local' }
return Join-Path $base 'Anya'
} elseif ($IsMacOS) {
return Join-Path $HOME 'Library/Application Support/Anya'
} else {
$xdg = $env:XDG_DATA_HOME
if ($xdg) { return Join-Path $xdg 'Anya' }
return Join-Path $HOME '.local/share/Anya'
}
}
if ($Uninstall) {
Step 'Uninstalling Anya bridge'
Push-Location (Join-Path $root 'bridge')
try { & (Join-Path '.' 'uninstall.ps1') } finally { Pop-Location }
Ok 'Bridge unregistered. Remove the unpacked extension manually from your browser.'
return
}
# --- 0. Prereq check -------------------------------------------------------
Step 'Checking prerequisites'
$node = (& node --version) 2>$null
if (-not $node) { throw 'Node.js not found on PATH. Install Node 20+.' }
$major = [int](($node.TrimStart('v') -split '\.')[0])
if ($major -lt 20) { throw "Node $node is too old; need >= 20." }
Ok "Node $node"
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { throw 'npm not found on PATH.' }
Ok 'npm available'
$osLabel = if ($IsWindows) { 'Windows' } elseif ($IsMacOS) { 'macOS' } else { 'Linux' }
Ok "Detected OS: $osLabel (PowerShell $($PSVersionTable.PSVersion))"
# Track warnings for the summary — non-fatal issues that the user should fix.
$warnings = @()
# Copilot CLI presence + auth.
# The CLI has no `auth status` subcommand. Login is `copilot login`, and the
# token lands in (a) an env var, (b) the OS credential store, or (c) a plain
# text file under ~/.copilot/. Check all three rather than shelling out.
if (-not (Get-Command copilot -ErrorAction SilentlyContinue)) {
$warnings += 'Copilot CLI not found. Install: npm i -g @github/copilot'
Write-Host " ⚠ Copilot CLI not found — install: npm i -g @github/copilot" -ForegroundColor Yellow
} else {
$copilotVer = ''
try {
$verLine = (& copilot --version 2>$null | Select-Object -First 1)
if ($verLine -match '\d+\.\d+\.\d+') { $copilotVer = $Matches[0] }
} catch {}
$loggedIn = $false
# 1. Env var token (headless / CI flow).
foreach ($v in 'COPILOT_GITHUB_TOKEN','GH_TOKEN','GITHUB_TOKEN') {
if ([Environment]::GetEnvironmentVariable($v)) { $loggedIn = $true; break }
}
# 2. OS credential store. On Windows, `cmdkey /list` shows a
# `copilot-cli/<host>:<user>` target after a successful `copilot login`.
if (-not $loggedIn -and $IsWindows) {
try {
if ((cmdkey /list 2>$null | Select-String -Pattern 'copilot-cli/' -Quiet)) {
$loggedIn = $true
}
} catch {}
}
# 3. Plain text fallback file under the config dir.
if (-not $loggedIn) {
$cfgDir = if ($env:COPILOT_CONFIG_DIR) { $env:COPILOT_CONFIG_DIR } else { Join-Path $HOME '.copilot' }
if (Test-Path $cfgDir) {
$hit = Get-ChildItem -Path $cfgDir -Filter '*token*' -File -ErrorAction SilentlyContinue |
Select-Object -First 1
if ($hit) { $loggedIn = $true }
}
}
if ($loggedIn) {
Ok ("Copilot CLI {0}authenticated" -f $(if ($copilotVer) { "$copilotVer " } else { '' }))
} else {
$warnings += 'Copilot CLI found but not logged in. Run: copilot login'
Write-Host " ⚠ Copilot CLI not logged in — run 'copilot login'" -ForegroundColor Yellow
}
}
# playwright-cli
if (Get-Command playwright-cli -ErrorAction SilentlyContinue) {
$pwVer = (& playwright-cli --version 2>$null) ?? ''
Ok "playwright-cli $pwVer"
} else {
$warnings += 'playwright-cli not found. Install: npm i -g @playwright/cli'
Write-Host " ⚠ playwright-cli not found — install: npm i -g @playwright/cli" -ForegroundColor Yellow
}
# --- 1. Bridge -------------------------------------------------------------
Step 'Building bridge'
Push-Location (Join-Path $root 'bridge')
try {
if (-not (Test-Path node_modules)) {
Info 'npm install (bridge)...'
npm install --no-audit --no-fund | Out-Host
}
npm run build | Out-Host
Ok 'bridge built -> bridge/dist/host.js'
if (-not $SkipTest) {
Info 'Running ping/pong smoke test...'
npm test | Out-Host
Ok 'bridge ping/pong verified'
}
$regLabel = if ($IsWindows) { 'HKCU registry' } else { 'NativeMessagingHosts dirs' }
Step "Registering bridge with Chromium browsers ($regLabel)"
$installArgs = @{ Browsers = $Browsers }
if ($Quiet) { $installArgs['Quiet'] = $true }
& (Join-Path '.' 'install.ps1') @installArgs | Out-Host
Ok 'bridge registered as com.anya.bridge'
} finally {
Pop-Location
}
# --- 2. Extension ---------------------------------------------------------
Step 'Building extension'
Push-Location (Join-Path $root 'extension')
try {
if (-not (Test-Path node_modules)) {
Info 'npm install (extension)...'
npm install --no-audit --no-fund | Out-Host
}
npm run build | Out-Host
Ok 'extension built -> extension/dist/'
} finally {
Pop-Location
}
# --- 3. Done --------------------------------------------------------------
$extId = (Get-Content (Join-Path $root '.extension-id.txt') -Raw).Trim()
$distPath = Join-Path $root 'extension/dist'
$logPath = Join-Path (Get-AnyaDataDir) 'bridge.log'
Write-Host ''
Write-Host '=========================================================' -ForegroundColor Green
Write-Host ' Anya — github copilot for your browser. ready.' -ForegroundColor Green
Write-Host '=========================================================' -ForegroundColor Green
Write-Host ''
Write-Host ' Load the unpacked extension (one-time, in each browser):' -ForegroundColor Yellow
Write-Host ' Edge -> edge://extensions'
Write-Host ' Chrome -> chrome://extensions'
Write-Host ' Brave -> brave://extensions'
Write-Host ' Vivaldi -> vivaldi://extensions'
Write-Host ' Chromium -> chrome://extensions'
if ($IsWindows -or $IsMacOS) {
Write-Host ' Arc -> arc://extensions'
}
Write-Host ''
Write-Host ' 1. Toggle Developer mode (top-right or bottom-left)'
Write-Host " 2. Click Load unpacked -> $distPath"
Write-Host " 3. Confirm extension ID = $extId"
Write-Host ' 4. Pin the action icon, click it -> sidebar opens'
Write-Host ''
Write-Host ' Smoke test in the sidebar:' -ForegroundColor Yellow
Write-Host ' - Type ping -> should echo PONG (bridge handshake)'
Write-Host ' - Type a real prompt -> should stream Copilot output'
Write-Host ''
Write-Host " Logs: $logPath"
Write-Host ' Uninstall: ./setup.ps1 -Uninstall'
if ($warnings.Count -gt 0) {
Write-Host ''
Write-Host ' ⚠ Before using Anya, fix these:' -ForegroundColor Yellow
foreach ($w in $warnings) {
Write-Host " • $w" -ForegroundColor Yellow
}
}
Write-Host ''