Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
443 lines (379 loc) · 18.1 KB
/
Copy pathinstall.ps1
File metadata and controls
443 lines (379 loc) · 18.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#Requires -Version 5.1
<#
.SYNOPSIS
Installs Simple Agent Session Manager for the current user (no admin required).
.DESCRIPTION
Registers a hidden Task Scheduler logon job, prints the VS Code keybinding
snippet, and starts the server. Does not require admin and does not edit
your VS Code config.
.PARAMETER Port
TCP port the dashboard listens on. Default: 3456.
.PARAMETER NoAutostart
Skip creating the autostart task (useful if you prefer to start the server
manually or via a different mechanism).
.PARAMETER Sources
Comma list of session sources to track: claude, codex, or both. Skips the
interactive picker. Example: -Sources claude,codex
.EXAMPLE
.\install.ps1
.\install.ps1 -Port 4000
.\install.ps1 -NoAutostart
.\install.ps1 -Sources claude,codex
#>
[CmdletBinding()]
param(
[int] $Port = 3456,
[switch]$NoAutostart,
[string]$Sources = ''
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# ─── Select-Sources ───────────────────────────────────────────────────────────
# Interactive arrow-key checkbox picker. Returns array of checked values.
function Select-Sources {
$items = @(
[pscustomobject]@{ Name = 'Claude Code'; Value = 'claude'; Checked = $true },
[pscustomobject]@{ Name = 'Codex'; Value = 'codex'; Checked = $false }
)
# Auto-detect Codex
if (Test-Path (Join-Path $HOME '.codex\sessions')) {
$items[1].Name = 'Codex (detected)'
}
$cursor = 0
$lineCount = $items.Count + 2 # header + items + hint
[Console]::CursorVisible = $false
try {
# Initial render
$startTop = [Console]::CursorTop
$redraw = $true
while ($true) {
if ($redraw) {
[Console]::SetCursorPosition(0, $startTop)
Write-Host " Which sessions should the dashboard track?" -ForegroundColor Cyan
for ($i = 0; $i -lt $items.Count; $i++) {
$check = if ($items[$i].Checked) { '[x]' } else { '[ ]' }
$caret = if ($i -eq $cursor) { '>' } else { ' ' }
$line = " $caret $check $($items[$i].Name) "
if ($i -eq $cursor) {
Write-Host $line -ForegroundColor Cyan
} else {
Write-Host $line
}
}
$uUp = [char]0x2191
$uDown = [char]0x2193
$uMid = [char]0x00B7
Write-Host " $uUp/$uDown move $uMid space toggle $uMid enter confirm" -ForegroundColor DarkGray
$redraw = $false
}
$key = [Console]::ReadKey($true)
switch ($key.Key) {
'UpArrow' {
$cursor = ($cursor - 1 + $items.Count) % $items.Count
$redraw = $true
}
'DownArrow' {
$cursor = ($cursor + 1) % $items.Count
$redraw = $true
}
'Spacebar' {
$items[$cursor].Checked = -not $items[$cursor].Checked
$redraw = $true
}
'Enter' {
$anyChecked = $false
foreach ($item in $items) {
if ($item.Checked) { $anyChecked = $true }
}
if ($anyChecked) {
# Move cursor past the rendered block so next output is clean
[Console]::SetCursorPosition(0, $startTop + $lineCount)
Write-Host ""
$result = @()
foreach ($item in $items) {
if ($item.Checked) { $result += $item.Value }
}
return $result
}
}
}
}
} finally {
[Console]::CursorVisible = $true
}
}
# ─── Set-ConfigSources ────────────────────────────────────────────────────────
# Writes sources = <value> into the [dashboard] section of config.ini.
function Set-ConfigSources {
param(
[string]$RepoDir,
[string]$Value
)
$cfg = Join-Path $RepoDir 'config.ini'
if (Test-Path $cfg) {
$lines = [System.IO.File]::ReadAllLines($cfg)
$newLines = [System.Collections.Generic.List[string]]::new()
$replaced = $false
$dashboardSeen = $false
foreach ($line in $lines) {
if ($line -match '^\s*\[dashboard\]') {
$newLines.Add($line)
$dashboardSeen = $true
continue
}
if (-not $replaced -and $line -match '^\s*sources\s*=') {
$newLines.Add("sources = $Value")
$replaced = $true
continue
}
# If we just passed [dashboard] and hit the next section header
# without having replaced yet, insert before the new section.
if ($dashboardSeen -and -not $replaced -and $line -match '^\s*\[') {
$newLines.Add("sources = $Value")
$replaced = $true
}
$newLines.Add($line)
}
# If [dashboard] was seen but no existing sources line and no next section
if ($dashboardSeen -and -not $replaced) {
$newLines.Add("sources = $Value")
}
# If [dashboard] wasn't seen at all, append the whole section
if (-not $dashboardSeen) {
$newLines.Add('[dashboard]')
$newLines.Add("sources = $Value")
}
# UTF-8 *without* BOM — the server reads config.ini as plain utf-8, and a
# BOM makes configparser reject the whole file (so every setting, including
# the sources we just wrote, would be silently ignored).
[System.IO.File]::WriteAllLines($cfg, $newLines, (New-Object System.Text.UTF8Encoding $false))
} else {
$newLines = [System.Collections.Generic.List[string]]::new()
$newLines.Add('[dashboard]')
$newLines.Add("sources = $Value")
# UTF-8 *without* BOM — the server reads config.ini as plain utf-8, and a
# BOM makes configparser reject the whole file (so every setting, including
# the sources we just wrote, would be silently ignored).
[System.IO.File]::WriteAllLines($cfg, $newLines, (New-Object System.Text.UTF8Encoding $false))
}
}
# ─── banner ───────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host " Simple Agent Session Manager - local installer" -ForegroundColor Cyan
Write-Host " A tiny, dependency-free, 100% local dashboard for your Claude Code sessions." -ForegroundColor DarkGray
Write-Host " Reads ~/.claude transcripts only. Binds to localhost. Sends nothing anywhere." -ForegroundColor DarkGray
Write-Host ""
# ─── locate repo ──────────────────────────────────────────────────────────────
$RepoDir = $PSScriptRoot
$ServerPy = Join-Path $RepoDir 'server.py'
if (-not (Test-Path $ServerPy)) {
Write-Host "ERROR: server.py not found next to this script ($ServerPy)." -ForegroundColor Red
Write-Host " Run install.ps1 from inside the cloned repository folder." -ForegroundColor Red
exit 1
}
Write-Host "[1/6] Repository: $RepoDir" -ForegroundColor Green
# ─── check python ─────────────────────────────────────────────────────────────
Write-Host "[2/6] Checking prerequisites..." -ForegroundColor Green
$PythonExe = $null
try {
$pyVersion = & python --version 2>&1
if ($LASTEXITCODE -eq 0) {
$PythonExe = 'python'
Write-Host " python : found ($pyVersion)" -ForegroundColor Green
}
} catch { }
if (-not $PythonExe) {
Write-Host ""
Write-Host "ERROR: 'python' was not found on your PATH." -ForegroundColor Red
Write-Host " Install Python 3.8+ from https://www.python.org/downloads/" -ForegroundColor Yellow
Write-Host " Make sure to tick 'Add Python to PATH' during setup." -ForegroundColor Yellow
Write-Host ""
exit 1
}
# Prefer pythonw for the hidden background launcher (no console window).
$PythonwExe = $null
$pythonwPath = Join-Path (Split-Path (Get-Command python -ErrorAction SilentlyContinue).Source) 'pythonw.exe'
if (Test-Path $pythonwPath) {
$PythonwExe = $pythonwPath
Write-Host " pythonw : found ($PythonwExe)" -ForegroundColor Green
} else {
Write-Host " pythonw : not found — will use python.exe with hidden window" -ForegroundColor Yellow
}
# ─── check claude CLI ─────────────────────────────────────────────────────────
try {
$claudeVersion = & claude --version 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " claude : found ($claudeVersion)" -ForegroundColor Green
} else {
throw "non-zero exit"
}
} catch {
Write-Host ""
Write-Host "WARNING: 'claude' CLI was not found on your PATH." -ForegroundColor Yellow
Write-Host " The dashboard is only useful with Claude Code installed." -ForegroundColor Yellow
Write-Host " Install it from: https://claude.ai/claude-code" -ForegroundColor Yellow
Write-Host " Continuing anyway..." -ForegroundColor Yellow
Write-Host ""
}
# ─── resolve session sources ──────────────────────────────────────────────────
Write-Host ""
Write-Host "[3/6] Session sources..." -ForegroundColor Green
$chosen = @()
# Validate any -Sources argument provided by the caller.
# @(...) forces an array so .Count is safe under Set-StrictMode even for a single value.
if ($Sources -ne '') {
$parts = @($Sources -split ',' | ForEach-Object { $_.Trim().ToLower() } | Where-Object { $_ -eq 'claude' -or $_ -eq 'codex' })
if ($parts.Count -gt 0) {
$chosen = $parts
}
}
if ($chosen.Count -gt 0) {
# -Sources was given and yielded valid values — skip the prompt
} elseif ([Console]::IsInputRedirected -or (-not [Environment]::UserInteractive)) {
$chosen = @('claude')
Write-Host " Non-interactive session — defaulting to: claude (picker skipped)." -ForegroundColor Yellow
} else {
$chosen = @(Select-Sources) # @() so a single-item pick stays an array
}
Set-ConfigSources $RepoDir ($chosen -join ',')
Write-Host (" Sources: {0} -> saved to config.ini" -f ($chosen -join ', ')) -ForegroundColor Green
# ─── autostart via Task Scheduler ──────────────────────────────────────────────
$TaskName = 'SimpleAgentSessionManager'
$LauncherExe = if ($PythonwExe) { $PythonwExe } else { $PythonExe }
if ($NoAutostart) {
Write-Host "[4/6] Skipping autostart (NoAutostart flag set)." -ForegroundColor Yellow
} else {
Write-Host "[4/6] Setting up autostart (Task Scheduler, at logon, auto-restart)..." -ForegroundColor Green
# Non-default port → persist as a user env var so the task inherits it at logon.
if ($Port -ne 3456) {
[Environment]::SetEnvironmentVariable('SASM_PORT', "$Port", 'User')
}
$me = "$env:USERDOMAIN\$env:USERNAME"
$taskXml = @"
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Description>Simple Agent Session Manager - local dashboard for Claude Code sessions. Starts hidden at logon.</Description>
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<Enabled>true</Enabled>
<UserId>$me</UserId>
</LogonTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>$me</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>true</Hidden>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT1M</Interval>
<Count>3</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>$LauncherExe</Command>
<Arguments>"$ServerPy"</Arguments>
<WorkingDirectory>$RepoDir</WorkingDirectory>
</Exec>
</Actions>
</Task>
"@
$taskXmlPath = Join-Path $env:TEMP 'sasm-task.xml'
$taskXml | Out-File -FilePath $taskXmlPath -Encoding Unicode
& schtasks /create /tn $TaskName /xml "$taskXmlPath" /f | Out-Null
Remove-Item $taskXmlPath -ErrorAction SilentlyContinue
if ($LASTEXITCODE -eq 0) {
Write-Host " Registered scheduled task '$TaskName' (runs hidden at every logon)." -ForegroundColor Green
Write-Host " It auto-restarts (up to 3x, 1 min apart) if it ever stops." -ForegroundColor Green
} else {
Write-Host " Could not register the task automatically (exit $LASTEXITCODE)." -ForegroundColor Yellow
Write-Host " You can still start it manually: python server.py" -ForegroundColor Yellow
}
}
# ─── VS Code keybinding snippet ───────────────────────────────────────────────
Write-Host ""
Write-Host "[5/6] VS Code keybinding snippet" -ForegroundColor Green
Write-Host " Add this to your keybindings.json (File > Preferences > Keyboard Shortcuts" -ForegroundColor Cyan
Write-Host " then click the '{}' icon in the top-right corner):" -ForegroundColor Cyan
Write-Host ""
Write-Host @"
{
"key": "ctrl+alt+d",
"command": "simpleBrowser.show",
"args": "http://localhost:$Port/?root=`${workspaceFolder}"
}
"@ -ForegroundColor White
Write-Host ""
Write-Host " Ctrl+Alt+D will open the dashboard scoped to the current" -ForegroundColor Cyan
Write-Host " workspace folder in VS Code's built-in Simple Browser." -ForegroundColor Cyan
# ─── optional terminal profile ────────────────────────────────────────────────
Write-Host ""
Write-Host " Optional — terminal profile for a manual start (settings.json):" -ForegroundColor Cyan
Write-Host ""
Write-Host @"
"terminal.integrated.profiles.windows": {
"Claude Dashboard": {
"source": "PowerShell",
"args": ["-NoProfile", "-Command",
"python '$ServerPy'; Read-Host 'Press Enter to close'"]
}
}
"@ -ForegroundColor White
# ─── start the server now ─────────────────────────────────────────────────────
Write-Host ""
Write-Host "[6/6] Starting the server now..." -ForegroundColor Green
$launcherExe = if ($PythonwExe) { $PythonwExe } else { $PythonExe }
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $launcherExe
$psi.Arguments = "`"$ServerPy`""
$psi.WorkingDirectory = $RepoDir
$psi.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$psi.CreateNoWindow = $true
$psi.UseShellExecute = $false
$psi.EnvironmentVariables['SASM_PORT'] = "$Port"
try {
$proc = [System.Diagnostics.Process]::Start($psi)
Write-Host " Server started (PID $($proc.Id))." -ForegroundColor Green
} catch {
Write-Host " Could not start server automatically: $_" -ForegroundColor Yellow
Write-Host " Start it manually: python server.py" -ForegroundColor Yellow
}
# ─── done ─────────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " Done — next steps" -ForegroundColor Cyan
Write-Host "══════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host " 1. Open http://localhost:$Port in your browser — it's running now." -ForegroundColor White
Write-Host ""
Write-Host " 2. Paste the keybinding snippet above into VS Code's keybindings.json" -ForegroundColor White
Write-Host " so Ctrl+Alt+D opens it scoped to whichever repo you have open." -ForegroundColor White
Write-Host ""
if (-not $NoAutostart) {
Write-Host " 3. It will start automatically at every Windows login via the" -ForegroundColor White
Write-Host " '$TaskName' scheduled task (hidden, auto-restarting)." -ForegroundColor White
Write-Host " To remove autostart, run: schtasks /delete /tn $TaskName /f" -ForegroundColor White
Write-Host ""
}
Write-Host " That's it. No dependencies, no cloud, no telemetry." -ForegroundColor DarkGray
Write-Host ""