opencode-1password-auth 1.0.7 → 1.0.9

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/setup.ps1 DELETED
@@ -1,636 +0,0 @@
1
- # OpenCode 1Password Auth Plugin - Setup Script
2
- # This script helps configure the environment variables needed for the plugin
3
-
4
- param(
5
- [switch]$Uninstall,
6
- [switch]$Audit,
7
- [switch]$UpdateConfig
8
- )
9
-
10
- # Colors for output
11
- function Write-Banner {
12
- Write-Host ""
13
- Write-Host "========================================" -ForegroundColor Cyan
14
- Write-Host " OpenCode 1Password Auth Setup" -ForegroundColor Cyan
15
- Write-Host "========================================" -ForegroundColor Cyan
16
- Write-Host ""
17
- }
18
-
19
- function Write-Success {
20
- param([string]$Message)
21
- Write-Host "[OK] " -ForegroundColor Green -NoNewline
22
- Write-Host $Message
23
- }
24
-
25
- function Write-Error {
26
- param([string]$Message)
27
- Write-Host "[ERROR] " -ForegroundColor Red -NoNewline
28
- Write-Host $Message
29
- }
30
-
31
- function Write-Info {
32
- param([string]$Message)
33
- Write-Host "[INFO] " -ForegroundColor Yellow -NoNewline
34
- Write-Host $Message
35
- }
36
-
37
- function Get-RegistryValue {
38
- param([string]$Name, [string]$Scope)
39
-
40
- if ($Scope -eq "Machine") {
41
- return [System.Environment]::GetEnvironmentVariable($Name, "Machine")
42
- } else {
43
- return [System.Environment]::GetEnvironmentVariable($Name, "User")
44
- }
45
- }
46
-
47
- function Set-RegistryValue {
48
- param([string]$Name, [string]$Value, [string]$Scope)
49
-
50
- try {
51
- [System.Environment]::SetEnvironmentVariable($Name, $Value, $Scope)
52
- return $true
53
- } catch {
54
- return $false
55
- }
56
- }
57
-
58
- function Remove-RegistryValue {
59
- param([string]$Name, [string]$Scope)
60
-
61
- try {
62
- [System.Environment]::SetEnvironmentVariable($Name, $null, $Scope)
63
- return $true
64
- } catch {
65
- return $false
66
- }
67
- }
68
-
69
- function Get-OpenCodeAuthJsonPath {
70
- $homeDir = if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:USERPROFILE }
71
- return "$homeDir/.local/share/opencode/auth.json"
72
- }
73
-
74
- function Get-OpenCodeConfigJsonPath {
75
- $homeDir = if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:USERPROFILE }
76
- return "$homeDir/.config/opencode/opencode.json"
77
- }
78
-
79
- function Update-ConfigFiles {
80
- param([string]$Token, [string]$ProvidersEnvId, [string]$McpsEnvId)
81
-
82
- $nodeModulesPath = Get-OpenCodeNodeModulesPath
83
- if (-not $nodeModulesPath) {
84
- Write-Error "Could not find @1password/sdk in any node_modules directory"
85
- return
86
- }
87
-
88
- $sdkPath = ($nodeModulesPath -replace '\\', '/') + "/@1password/sdk/dist/sdk.js"
89
-
90
- # Get provider secrets from 1Password
91
- Write-Info "Reading provider secrets from 1Password..."
92
-
93
- $script = @"
94
- const sdk = require('${sdkPath}');
95
-
96
- async function getSecrets() {
97
- const client = await sdk.createClient({
98
- auth: '${Token}',
99
- integrationName: 'opencode-1password-setup',
100
- integrationVersion: '1.0.0'
101
- });
102
-
103
- const providers = {};
104
- const { variables: providerVars } = await client.environments.getVariables('${ProvidersEnvId}');
105
- for (const v of providerVars) {
106
- if (v.value) providers[v.name] = v.value;
107
- }
108
-
109
- const mcps = {};
110
- if ('${McpsEnvId}') {
111
- const { variables: mcpVars } = await client.environments.getVariables('${McpsEnvId}');
112
- for (const v of mcpVars) {
113
- if (v.value) mcps[v.name] = v.value;
114
- }
115
- }
116
-
117
- console.log(JSON.stringify({ providers, mcps }));
118
- }
119
-
120
- getSecrets().catch(err => { console.error('FAILED:', err.message); process.exit(1); });
121
- "@
122
-
123
- $tempScript = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', '.js'
124
- $script | Out-File -FilePath $tempScript -Encoding UTF8 -NoNewline
125
-
126
- $result = & node $tempScript 2>&1 | Out-String
127
- Remove-Item $tempScript -ErrorAction SilentlyContinue
128
-
129
- if ($result -match "FAILED:") {
130
- Write-Error "Failed to read secrets from 1Password: $($result -replace 'FAILED:', '')"
131
- return
132
- }
133
-
134
- $secrets = $result | ConvertFrom-Json
135
-
136
- # Update auth.json
137
- $authJsonPath = Get-OpenCodeAuthJsonPath
138
- Write-Info "Updating auth.json..."
139
-
140
- if (Test-Path $authJsonPath) {
141
- $authContent = Get-Content $authJsonPath -Raw -Encoding UTF8
142
- $auth = $authContent | ConvertFrom-Json
143
-
144
- $modified = $false
145
- foreach ($providerId in $auth.PSObject.Properties.Name) {
146
- $authConfig = $auth.$providerId
147
- if ($authConfig.key -and -not $authConfig.key.StartsWith("{env:")) {
148
- $authConfig.key = "{env:$providerId}"
149
- $modified = $true
150
- Write-Success "Updated $providerId -> {env:$providerId}"
151
- }
152
- }
153
-
154
- if ($modified) {
155
- $auth | ConvertTo-Json -Depth 10 | Set-Content $authJsonPath -Encoding UTF8 -NoNewline
156
- Write-Success "auth.json updated"
157
- } else {
158
- Write-Info "auth.json already uses environment variable references"
159
- }
160
- } else {
161
- Write-Info "auth.json not found at $authJsonPath"
162
- }
163
-
164
- # Update opencode.json MCP config
165
- $configJsonPath = Get-OpenCodeConfigJsonPath
166
- Write-Info "Updating opencode.json MCP config..."
167
-
168
- if (Test-Path $configJsonPath) {
169
- $configContent = Get-Content $configJsonPath -Raw -Encoding UTF8
170
- $config = $configContent | ConvertFrom-Json
171
-
172
- $modified = $false
173
- if ($config.mcp) {
174
- foreach ($serverName in $config.mcp.PSObject.Properties.Name) {
175
- $serverConfig = $config.mcp.$serverName
176
- if ($serverConfig.environment) {
177
- foreach ($key in $serverConfig.environment.PSObject.Properties.Name) {
178
- $value = $serverConfig.environment.$key
179
- if ($value -and -not $value.StartsWith("{env:") -and -not $value.StartsWith("$")) {
180
- $serverConfig.environment.$key = "{env:$key}"
181
- $modified = $true
182
- Write-Success "Updated $serverName.$key -> {env:$key}"
183
- }
184
- }
185
- }
186
- }
187
- }
188
-
189
- if ($modified) {
190
- $config | ConvertTo-Json -Depth 10 | Set-Content $configJsonPath -Encoding UTF8 -NoNewline
191
- Write-Success "opencode.json updated"
192
- } else {
193
- Write-Info "opencode.json already uses environment variable references"
194
- }
195
- } else {
196
- Write-Info "opencode.json not found at $configJsonPath"
197
- }
198
- }
199
-
200
- function Get-OpenCodeNodeModulesPath {
201
- $paths = @(
202
- "$env:USERPROFILE\.cache\opencode\node_modules",
203
- "$env:USERPROFILE\.config\opencode\node_modules",
204
- "$env:APPDATA\opencode\node_modules"
205
- )
206
-
207
- foreach ($path in $paths) {
208
- if (Test-Path "$path\@1password\sdk") {
209
- return $path
210
- }
211
- }
212
- return $null
213
- }
214
-
215
- function Test-1PasswordConnection {
216
- param([string]$Token)
217
-
218
- try {
219
- $nodeModulesPath = Get-OpenCodeNodeModulesPath
220
-
221
- if (-not $nodeModulesPath) {
222
- Write-Error "Could not find @1password/sdk in any node_modules directory"
223
- return $false
224
- }
225
-
226
- $sdkPath = ($nodeModulesPath -replace '\\', '/') + "/@1password/sdk/dist/sdk.js"
227
-
228
- # Create a temporary Node.js script file
229
- $tempScript = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', '.js'
230
-
231
- $testScript = 'const sdk = require("' + $sdkPath + '");' + "`n" +
232
- 'async function test() {' + "`n" +
233
- ' const client = await sdk.createClient({' + "`n" +
234
- ' auth: "' + $Token + '",' + "`n" +
235
- ' integrationName: "opencode-1password-setup-test",' + "`n" +
236
- ' integrationVersion: "1.0.0"' + "`n" +
237
- ' });' + "`n" +
238
- ' console.log("SUCCESS");' + "`n" +
239
- '}' + "`n" +
240
- 'test().catch(err => { console.error("FAILED:", err.message); process.exit(1); });'
241
-
242
- $testScript | Out-File -FilePath $tempScript -Encoding UTF8 -NoNewline
243
-
244
- $result = & node $tempScript 2>&1
245
- Remove-Item $tempScript -ErrorAction SilentlyContinue
246
-
247
- return $result -match "SUCCESS"
248
- } catch {
249
- return $false
250
- }
251
- }
252
-
253
- function Get-1PasswordAudit {
254
- param([string]$Token, [string]$ConfigEnvId)
255
-
256
- try {
257
- $nodeModulesPath = Get-OpenCodeNodeModulesPath
258
-
259
- if (-not $nodeModulesPath) {
260
- Write-Error "Could not find @1password/sdk in any node_modules directory"
261
- return $null
262
- }
263
-
264
- $sdkPath = ($nodeModulesPath -replace '\\', '/') + "/@1password/sdk/dist/sdk.js"
265
-
266
- $script = 'const sdk = require("' + $sdkPath + '");' + "`n" +
267
- 'async function audit() {' + "`n" +
268
- ' const client = await sdk.createClient({' + "`n" +
269
- ' auth: "' + $Token + '",' + "`n" +
270
- ' integrationName: "opencode-1password-setup-test",' + "`n" +
271
- ' integrationVersion: "1.0.0"' + "`n" +
272
- ' });' + "`n" +
273
- ' const { variables: configVars } = await client.environments.getVariables("' + $ConfigEnvId + '");' + "`n" +
274
- ' const envIds = {};' + "`n" +
275
- ' for (const v of configVars) {' + "`n" +
276
- ' if (v.name.endsWith("_ENV_ID") && v.value) {' + "`n" +
277
- ' envIds[v.name] = v.value;' + "`n" +
278
- ' }' + "`n" +
279
- ' }' + "`n" +
280
- ' console.log(JSON.stringify(envIds));' + "`n" +
281
- '}' + "`n" +
282
- 'audit().catch(err => { console.error("FAILED:", err.message); process.exit(1); });'
283
-
284
- $tempScript = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', '.js'
285
- $script | Out-File -FilePath $tempScript -Encoding UTF8 -NoNewline
286
- $jsonResult = & node $tempScript 2>&1 | Out-String
287
- Remove-Item $tempScript -ErrorAction SilentlyContinue
288
- return $jsonResult | ConvertFrom-Json
289
- } catch {
290
- return $null
291
- }
292
- }
293
-
294
- function Show-AuditReport {
295
- param([string]$Token, [hashtable]$EnvIds)
296
-
297
- $nodeModulesPath = Get-OpenCodeNodeModulesPath
298
-
299
- Write-Host ""
300
- Write-Host "========================================" -ForegroundColor Cyan
301
- Write-Host " Configuration Audit Report" -ForegroundColor Cyan
302
- Write-Host "========================================" -ForegroundColor Cyan
303
- Write-Host ""
304
-
305
- # Display bootstrap environment IDs
306
- Write-Host "Bootstrap Environment References:" -ForegroundColor White
307
- Write-Host "--------------------------------"
308
-
309
- foreach ($key in $EnvIds.Keys) {
310
- Write-Host " $($key) = $($EnvIds[$key].Substring(0, 10))..." -ForegroundColor Gray
311
- }
312
- Write-Host ""
313
-
314
- # For each referenced environment, show its contents
315
- foreach ($key in $EnvIds.Keys) {
316
- $envId = $EnvIds[$key]
317
- $envName = ($key -replace 'OPENCODE_', '') -replace '_ENV_ID', ''
318
-
319
- Write-Host "$envName Environment:" -ForegroundColor White
320
- Write-Host "--------------------------------"
321
-
322
- try {
323
- # Use forward slashes to avoid JS escape sequence issues
324
- $sdkPath = ($nodeModulesPath -replace '\\', '/') + "/@1password/sdk/dist/sdk.js"
325
- $script = 'const sdk = require("' + $sdkPath + '");' + "`n" +
326
- 'async function read() {' + "`n" +
327
- ' const client = await sdk.createClient({' + "`n" +
328
- ' auth: "' + $Token + '",' + "`n" +
329
- ' integrationName: "opencode-1password-setup-test",' + "`n" +
330
- ' integrationVersion: "1.0.0"' + "`n" +
331
- ' });' + "`n" +
332
- ' const { variables } = await client.environments.getVariables("' + $envId + '");' + "`n" +
333
- ' for (const v of variables) {' + "`n" +
334
- ' const masked = v.value ? v.value.substring(0, 8) + "••••••••" : "(empty)";' + "`n" +
335
- ' console.log(v.name + "=" + masked);' + "`n" +
336
- ' }' + "`n" +
337
- '}' + "`n" +
338
- 'read().catch(err => { console.error("Error:", err.message); });'
339
-
340
- $tempScript = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', '.js'
341
- $script | Out-File -FilePath $tempScript -Encoding UTF8 -NoNewline
342
- $result = & node $tempScript 2>&1
343
- Remove-Item $tempScript -ErrorAction SilentlyContinue
344
- foreach ($line in $result) {
345
- if ($line -and $line -notmatch "^(Error|Error:)") {
346
- Write-Host " $line" -ForegroundColor Gray
347
- } elseif ($line -match "Error:") {
348
- Write-Host " $line" -ForegroundColor Red
349
- }
350
- }
351
- } catch {
352
- Write-Host " Could not read environment" -ForegroundColor Red
353
- }
354
- Write-Host ""
355
- }
356
- }
357
-
358
- # Main script execution
359
- Write-Banner
360
-
361
- if ($Uninstall) {
362
- # Uninstall mode
363
- Write-Host "Uninstall Mode" -ForegroundColor Yellow
364
- Write-Host "--------------" -ForegroundColor Yellow
365
- Write-Host ""
366
-
367
- $currentToken = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "Machine"
368
- $currentConfigId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "Machine"
369
-
370
- if (-not $currentToken -and -not $currentConfigId) {
371
- $currentToken = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "User"
372
- $currentConfigId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "User"
373
- }
374
-
375
- if (-not $currentToken -and -not $currentConfigId) {
376
- Write-Info "No environment variables found. Nothing to uninstall."
377
- exit 0
378
- }
379
-
380
- Write-Host "Found the following environment variables:" -ForegroundColor White
381
- if ($currentToken) { Write-Host " OP_SERVICE_ACCOUNT_TOKEN = $($currentToken.Substring(0, 8))..." -ForegroundColor Gray }
382
- if ($currentConfigId) { Write-Host " OP_CONFIG_ENV_ID = $($currentConfigId.Substring(0, 8))..." -ForegroundColor Gray }
383
- Write-Host ""
384
-
385
- $confirm = Read-Host "Remove these environment variables? (y/N)"
386
-
387
- if ($confirm -eq 'y' -or $confirm -eq 'Y') {
388
- $removed = 0
389
-
390
- if ($currentToken) {
391
- if (Remove-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "Machine") { $removed++ }
392
- if (Remove-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "User") { $removed++ }
393
- }
394
-
395
- if ($currentConfigId) {
396
- if (Remove-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "Machine") { $removed++ }
397
- if (Remove-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "User") { $removed++ }
398
- }
399
-
400
- Write-Success "Removed $removed environment variable(s)."
401
- Write-Info "Please restart any OpenCode sessions for changes to take effect."
402
- } else {
403
- Write-Info "Uninstall cancelled."
404
- }
405
-
406
- exit 0
407
- }
408
-
409
- if ($Audit) {
410
- # Audit mode
411
- Write-Host "Audit Mode" -ForegroundColor Yellow
412
- Write-Host "----------" -ForegroundColor Yellow
413
- Write-Host ""
414
-
415
- $token = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "Machine"
416
- $configId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "Machine"
417
-
418
- if (-not $token) {
419
- $token = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "User"
420
- $configId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "User"
421
- }
422
-
423
- if (-not $token -or -not $configId) {
424
- Write-Error "Environment variables not set. Run setup first."
425
- exit 1
426
- }
427
-
428
- Write-Info "Testing 1Password connection..."
429
-
430
- if (Test-1PasswordConnection -Token $token) {
431
- Write-Success "1Password connection successful!"
432
- } else {
433
- Write-Error "Failed to connect to 1Password. Check your service account token."
434
- exit 1
435
- }
436
-
437
- Write-Info "Reading configuration from 1Password..."
438
-
439
- $envIds = Get-1PasswordAudit -Token $token -ConfigEnvId $configId
440
-
441
- if ($envIds) {
442
- $hashtable = @{}
443
- foreach ($prop in $envIds.PSObject.Properties) {
444
- $hashtable[$prop.Name] = $prop.Value
445
- }
446
- Show-AuditReport -Token $token -EnvIds $hashtable
447
- } else {
448
- Write-Error "Failed to read bootstrap environment."
449
- exit 1
450
- }
451
-
452
- exit 0
453
- }
454
-
455
- if ($UpdateConfig) {
456
- # Update Config mode
457
- Write-Host "Update Config Mode" -ForegroundColor Yellow
458
- Write-Host "------------------" -ForegroundColor Yellow
459
- Write-Host ""
460
-
461
- $token = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "Machine"
462
- $configId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "Machine"
463
-
464
- if (-not $token) {
465
- $token = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "User"
466
- $configId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "User"
467
- }
468
-
469
- if (-not $token -or -not $configId) {
470
- Write-Error "Environment variables not set. Run setup first."
471
- exit 1
472
- }
473
-
474
- Write-Info "Testing 1Password connection..."
475
-
476
- if (Test-1PasswordConnection -Token $token) {
477
- Write-Success "1Password connection successful!"
478
- } else {
479
- Write-Error "Failed to connect to 1Password. Check your service account token."
480
- exit 1
481
- }
482
-
483
- Write-Info "Reading configuration from 1Password..."
484
-
485
- $envIds = Get-1PasswordAudit -Token $token -ConfigEnvId $configId
486
-
487
- if ($envIds) {
488
- $providersEnvId = $null
489
- $mcpsEnvId = $null
490
-
491
- foreach ($prop in $envIds.PSObject.Properties) {
492
- if ($prop.Name -eq "OPENCODE_PROVIDERS_ENV_ID") {
493
- $providersEnvId = $prop.Value
494
- } elseif ($prop.Name -eq "OPENCODE_MCPS_ENV_ID") {
495
- $mcpsEnvId = $prop.Value
496
- }
497
- }
498
-
499
- if ($providersEnvId) {
500
- Write-Info "Updating config files to use environment variables..."
501
- Update-ConfigFiles -Token $token -ProvidersEnvId $providersEnvId -McpsEnvId $mcpsEnvId
502
- Write-Success "Config update complete!"
503
- } else {
504
- Write-Error "Could not find OPENCODE_PROVIDERS_ENV_ID in bootstrap environment"
505
- exit 1
506
- }
507
- } else {
508
- Write-Error "Failed to read bootstrap environment."
509
- exit 1
510
- }
511
-
512
- exit 0
513
- }
514
-
515
- # Setup mode (default)
516
- Write-Host "Setup Mode" -ForegroundColor Yellow
517
- Write-Host "----------" -ForegroundColor Yellow
518
- Write-Host ""
519
-
520
- # Check existing values
521
- $existingToken = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "Machine"
522
- $existingConfigId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "Machine"
523
-
524
- if (-not $existingToken) {
525
- $existingToken = Get-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Scope "User"
526
- $existingConfigId = Get-RegistryValue -Name "OP_CONFIG_ENV_ID" -Scope "User"
527
- }
528
-
529
- $isUpdate = $existingToken -and $existingConfigId
530
-
531
- if ($isUpdate) {
532
- Write-Host "Found existing configuration:" -ForegroundColor White
533
- Write-Host " OP_SERVICE_ACCOUNT_TOKEN = $($existingToken.Substring(0, 8))..." -ForegroundColor Gray
534
- Write-Host " OP_CONFIG_ENV_ID = $($existingConfigId.Substring(0, 8))..." -ForegroundColor Gray
535
- Write-Host ""
536
-
537
- $confirm = Read-Host "Update existing values? (y/N)"
538
-
539
- if ($confirm -ne 'y' -and $confirm -ne 'Y') {
540
- Write-Info "Setup cancelled."
541
- exit 0
542
- }
543
- }
544
-
545
- # Prompt for new values
546
- Write-Host "Enter your 1Password credentials:" -ForegroundColor White
547
- Write-Host ""
548
-
549
- if (-not $isUpdate) {
550
- $token = Read-Host -AsSecureString " OP_SERVICE_ACCOUNT_TOKEN (service account token)"
551
- $token = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($token))
552
- } else {
553
- $token = Read-Host -AsSecureString " OP_SERVICE_ACCOUNT_TOKEN (leave blank to keep existing)"
554
- $token = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($token))
555
- if (-not $token) { $token = $existingToken }
556
- }
557
-
558
- if (-not $isUpdate) {
559
- $configId = Read-Host " OP_CONFIG_ENV_ID (bootstrap environment ID)"
560
- } else {
561
- $configId = Read-Host " OP_CONFIG_ENV_ID (leave blank to keep existing)"
562
- if (-not $configId) { $configId = $existingConfigId }
563
- }
564
-
565
- if (-not $token -or -not $configId) {
566
- Write-Error "Both token and config ID are required."
567
- exit 1
568
- }
569
-
570
- Write-Host ""
571
- Write-Host "Summary:" -ForegroundColor White
572
- Write-Host " OP_SERVICE_ACCOUNT_TOKEN = $($token.Substring(0, 8))..." -ForegroundColor Gray
573
- Write-Host " OP_CONFIG_ENV_ID = $($configId.Substring(0, 8))..." -ForegroundColor Gray
574
- Write-Host ""
575
-
576
- # Ask about scope
577
- Write-Host "Where should these be saved?" -ForegroundColor White
578
- Write-Host " [1] Current user only (no admin required)"
579
- Write-Host " [2] System-wide (requires administrator privileges)"
580
- $scopeChoice = Read-Host "Choice"
581
-
582
- if ($scopeChoice -eq "2") {
583
- $scope = "Machine"
584
- } else {
585
- $scope = "User"
586
- }
587
-
588
- Write-Host ""
589
- Write-Info "Saving to $scope scope..."
590
-
591
- if (Set-RegistryValue -Name "OP_SERVICE_ACCOUNT_TOKEN" -Value $token -Scope $scope) {
592
- Write-Success "Saved OP_SERVICE_ACCOUNT_TOKEN"
593
- } else {
594
- Write-Error "Failed to save OP_SERVICE_ACCOUNT_TOKEN"
595
- exit 1
596
- }
597
-
598
- if (Set-RegistryValue -Name "OP_CONFIG_ENV_ID" -Value $configId -Scope $scope) {
599
- Write-Success "Saved OP_CONFIG_ENV_ID"
600
- } else {
601
- Write-Error "Failed to save OP_CONFIG_ENV_ID"
602
- exit 1
603
- }
604
-
605
- Write-Host ""
606
- Write-Info "Testing 1Password connection..."
607
-
608
- if (Test-1PasswordConnection -Token $token) {
609
- Write-Success "1Password connection successful!"
610
- } else {
611
- Write-Error "Failed to connect to 1Password. Check your service account token."
612
- Write-Info "Environment variables were saved. You may need to restart your terminal."
613
- exit 1
614
- }
615
-
616
- Write-Info "Reading configuration..."
617
-
618
- $envIds = Get-1PasswordAudit -Token $token -ConfigEnvId $configId
619
-
620
- if ($envIds) {
621
- $hashtable = @{}
622
- foreach ($prop in $envIds.PSObject.Properties) {
623
- $hashtable[$prop.Name] = $prop.Value
624
- }
625
- Show-AuditReport -Token $token -EnvIds $hashtable
626
- }
627
-
628
- Write-Host ""
629
- Write-Success "Setup complete!"
630
- Write-Info "Restart OpenCode to activate the plugin."
631
- Write-Host ""
632
- Write-Host "Usage:" -ForegroundColor White
633
- Write-Host " ./setup.ps1 -Audit Show current configuration"
634
- Write-Host " ./setup.ps1 -UpdateConfig Update config files to use {env:VAR} references"
635
- Write-Host " ./setup.ps1 -Uninstall Remove environment variables"
636
- Write-Host ""