-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevshell.ps1
More file actions
250 lines (236 loc) · 9.91 KB
/
Copy pathdevshell.ps1
File metadata and controls
250 lines (236 loc) · 9.91 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
#Requires -Version 7.0
<#
.SYNOPSIS
HomeBase DevShell — DevReady product CLI. Prepares, verifies and maintains professional Windows workstations.
#>
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[ValidateSet('health', 'history', 'baseline', 'verify', 'install', 'doctor', 'status', 'reload', 'trace', 'help', 'version', 'init',
'privacy', 'browser', 'tor', 'vpn', 'metadata', 'clean-meta', 'opsec', 'audit')]
[string]$Command = 'help',
[Parameter(Position = 1)]
[string]$Argument,
[ValidateSet('Core', 'Full')]
[string]$Tier = 'Core',
[switch]$SkipTools,
[switch]$WithTools,
[switch]$Fix,
[switch]$Privacy,
[switch]$Apply,
[switch]$Strip,
[switch]$Json,
[ValidateSet('html')]
[string]$Export,
[string[]]$Sections,
[ValidateSet('Chrome', 'Edge', 'Firefox', 'All')]
[string]$Browser = 'All',
[int]$Last = 20
)
$ErrorActionPreference = 'Stop'
function Get-DevShellRepoRoot {
if ($env:HOMEBASE_DEVSHELL_ROOT -and (Test-Path (Join-Path $env:HOMEBASE_DEVSHELL_ROOT 'lib\HomeBasePaths.ps1'))) {
return $env:HOMEBASE_DEVSHELL_ROOT
}
if (-not [string]::IsNullOrWhiteSpace($PSScriptRoot) -and (Test-Path (Join-Path $PSScriptRoot 'lib\HomeBasePaths.ps1'))) {
return $PSScriptRoot
}
$ossDefault = Join-Path $env:USERPROFILE '.homebase\devshell'
if (Test-Path (Join-Path $ossDefault 'lib\HomeBasePaths.ps1')) { return $ossDefault }
throw 'HomeBase DevShell root not found. Set `$env:HOMEBASE_DEVSHELL_ROOT` or run from the repository.'
}
function Get-DevShellProductVersion {
param([string]$Root)
. (Join-Path $Root 'lib\DevShellProduct.ps1')
return Get-DevShellProductVersionFromRoot -RepoRoot $Root
}
function Show-DevShellHelp {
Write-Host @'
DevReady — HomeBase DevShell
Workstation readiness and privacy auditing for Windows + PowerShell 7
devshell health Unified dashboard (developer + privacy + browser + network)
devshell health -Json Machine-readable report
devshell health -Sections developer,privacy Subset of sections (faster)
devshell health -Export html HTML report in Logs folder
devshell history Privacy/configuration score trend
devshell baseline Save configuration baseline
devshell verify Compare current state to baseline
devready / devshell doctor Developer readiness (-Tier Core|Full, -Fix, -Json)
devshell install First-time setup (Core; -WithTools for winget stack)
devshell init Dry-run install plan
Advanced (frozen API — see docs/API-STABILITY.md):
devshell privacy | browser | vpn | tor | metadata | clean-meta
devshell help
'@ -ForegroundColor DarkGray
}
$repoRoot = Get-DevShellRepoRoot
if ($Command -in @('status', 'reload', 'trace', 'version')) {
. (Join-Path $repoRoot 'lib\HomeBasePaths.ps1')
. (Join-Path $repoRoot 'lib\WorkstationCommon.ps1')
. (Join-Path $repoRoot 'lib\ProfileEnvironment.ps1')
. (Join-Path $repoRoot 'lib\WorkstationOrchestrator.ps1')
. (Join-Path $repoRoot 'lib\WorkstationCommandRegistry.ps1')
. (Join-Path $repoRoot 'lib\WorkstationCapabilityObservability.ps1')
. (Join-Path $repoRoot 'lib\WorkstationEventCore.ps1')
. (Join-Path $repoRoot 'lib\WorkstationPlatformContract.ps1')
. (Join-Path $repoRoot 'lib\WorkstationExecutionTrace.ps1')
. (Join-Path $repoRoot 'lib\WorkstationCommandRouter.ps1')
. (Join-Path $repoRoot 'lib\WorkstationCapabilityExtensions.ps1')
. (Join-Path $repoRoot 'lib\WorkstationExtensionEventBridge.ps1')
. (Join-Path $repoRoot 'lib\WorkstationExtensionRuntime.ps1')
}
switch ($Command) {
'health' {
$healthArgs = @{ Tier = $Tier }
if ($Json) { $healthArgs['Json'] = $true }
if ($Export) { $healthArgs['Export'] = $Export }
if ($Sections) { $healthArgs['SectionFilter'] = $Sections }
if ($Argument) { $healthArgs['OutFile'] = $Argument }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-DevShellHealth.ps1') @healthArgs
exit $LASTEXITCODE
}
'history' {
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-DevShellHistory.ps1') -Last $Last
exit $LASTEXITCODE
}
'baseline' {
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-DevShellBaseline.ps1')
exit $LASTEXITCODE
}
'verify' {
$verifyArgs = @{}
if ($Json) { $verifyArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-DevShellVerify.ps1') @verifyArgs
exit $LASTEXITCODE
}
'install' {
if ($WithTools) {
& (Join-Path $repoRoot 'scripts\maintainer\install\Install-Workstation.ps1') -Force -SkipAdmin -SkipValidation
} else {
& (Join-Path $repoRoot 'scripts\maintainer\install\Install-Workstation.ps1') -Force -SkipSoftware -SkipAdmin -SkipValidation
}
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
'doctor' {
$doctorArgs = @{
Tier = $Tier
StartupBudgetMs = 650
}
if ($Fix) { $doctorArgs['Fix'] = $true }
if ($Privacy) { $doctorArgs['Privacy'] = $true }
if ($Json) { $doctorArgs['JsonOnly'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\install\Validate-Workstation.ps1') @doctorArgs
exit $LASTEXITCODE
}
'init' {
$planScript = Join-Path $repoRoot 'scripts\maintainer\install\Show-DevShellInitPlan.ps1'
$planArgs = @{}
if ($WithTools) { $planArgs['WithTools'] = $true }
elseif ($SkipTools) { $planArgs['SkipTools'] = $true }
else { $planArgs['SkipTools'] = $true }
& $planScript @planArgs
exit 0
}
'privacy' {
$privacyArgs = @{}
if ($Fix) { $privacyArgs['Fix'] = $true }
if ($Apply) { $privacyArgs['Apply'] = $true }
if ($Json) { $privacyArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-PrivacyAudit.ps1') @privacyArgs
exit $LASTEXITCODE
}
'audit' {
$target = if ($Argument) { $Argument } else { 'privacy' }
if ($target -eq 'privacy') {
$privacyArgs = @{}
if ($Fix) { $privacyArgs['Fix'] = $true }
if ($Apply) { $privacyArgs['Apply'] = $true }
if ($Json) { $privacyArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-PrivacyAudit.ps1') @privacyArgs
exit $LASTEXITCODE
}
Write-Host "Unknown audit: $target" -ForegroundColor Yellow
exit 1
}
'browser' {
$bArgs = @{ Browser = $Browser }
if ($Json) { $bArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-BrowserPrivacyAudit.ps1') @bArgs
exit $LASTEXITCODE
}
'tor' {
$tArgs = @{}
if ($Json) { $tArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-TorReadinessAudit.ps1') @tArgs
exit $LASTEXITCODE
}
'vpn' {
$vArgs = @{}
if ($Json) { $vArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-VpnAudit.ps1') @vArgs
exit $LASTEXITCODE
}
'clean-meta' {
if (-not $Argument) {
Write-Host 'Usage: devshell clean-meta <file>' -ForegroundColor Yellow
exit 1
}
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-MetadataToolkit.ps1') -Path $Argument -Strip
exit $LASTEXITCODE
}
'metadata' {
$metaArgs = @{}
if ($Argument) { $metaArgs['Path'] = $Argument }
if ($Strip) { $metaArgs['Strip'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-MetadataToolkit.ps1') @metaArgs
exit $LASTEXITCODE
}
'opsec' {
$oArgs = @{}
if ($Json) { $oArgs['Json'] = $true }
& (Join-Path $repoRoot 'scripts\maintainer\invoke\Invoke-OpsecCheck.ps1') @oArgs
exit $LASTEXITCODE
}
'status' {
Invoke-WorkstationProfile -RepositoryRoot $repoRoot -Force | Out-Null
$contract = Get-WorkstationPlatformContract
$ctx = Get-WorkstationExecutionContext
$product = Get-DevShellProductVersion -Root $repoRoot
Write-Host ''
Write-Host 'HomeBase DevShell' -ForegroundColor Cyan
Write-Host " Product: $product"
Write-Host " Platform: $($contract.ContractVersion) ($($contract.Lock.Status))"
Write-Host " Signed: $($contract.Lock.SignedAt)"
Write-Host ''
Write-Host 'Runtime' -ForegroundColor Cyan
Write-Host " Bootstrap: $($ctx.Bootstrap)"
Write-Host " Environment: $($ctx.Environment)"
Write-Host " Diagnostics: $($ctx.Diagnostics)"
Write-Host " Hints: $($ctx.Hints)"
Write-Host ''
}
'reload' {
Invoke-WorkstationProfile -RepositoryRoot $repoRoot -Force | Out-Null
$null = Invoke-WorkstationCommand -Name 'profile.reload'
Write-Host 'Profile stack reloaded.' -ForegroundColor Green
}
'trace' {
Invoke-WorkstationProfile -RepositoryRoot $repoRoot -Force | Out-Null
$trace = Get-WorkstationExecutionTrace
if ($trace -is [System.Array] -and $trace.Count -eq 1 -and $trace[0] -is [System.Array]) {
$trace = $trace[0]
}
if (-not $trace -or $trace.Count -eq 0) {
Write-Host 'No execution trace events recorded in this session.' -ForegroundColor DarkGray
break
}
$rows = if ($trace.Count -gt $Last) { $trace[($trace.Count - $Last)..($trace.Count - 1)] } else { $trace }
$rows | ForEach-Object { [PSCustomObject]$_ } | Format-Table Command, Layer, Capability, Status -AutoSize
}
'version' {
$contract = Get-WorkstationPlatformContract
$product = Get-DevShellProductVersion -Root $repoRoot
Write-Output "HomeBase DevShell $product · Platform Spec $($contract.ContractVersion) ($($contract.Lock.Status))"
}
default { Show-DevShellHelp }
}