tabby-agentdeck 1.0.0 → 1.1.1

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.
@@ -0,0 +1,108 @@
1
+ # AgentDeck 자동 업데이트 — Tabby 가 **꺼진 뒤에** 설치하고 다시 띄운다.
2
+ #
3
+ # powershell -NoProfile -ExecutionPolicy Bypass -File agentdeck-update.ps1 `
4
+ # -Version 1.1.1 -PluginsDir "<APPDATA>\tabby\plugins" -TabbyExe "<...>\Tabby.exe"
5
+ #
6
+ # 왜 밖에서 도나 — 두 가지 때문이다.
7
+ # 1. **돌고 있는 플러그인은 자기를 갈아끼울 수 없다.** Tabby 는 기동할 때 `dist/index.js` 를 한 번
8
+ # 읽어 메모리에 올린다. 그 뒤 디스크를 바꿔도 돌고 있는 코드는 옛것 그대로다.
9
+ # 2. **Windows 는 로드된 파일을 잡고 있다.** Tabby 가 떠 있는 동안 npm 이 그 폴더를 지우려 들면
10
+ # EPERM/EBUSY 로 반쯤 지운 채 실패할 수 있다 — 플러그인이 깨진 상태로 남는 것이 가장 나쁘다.
11
+ #
12
+ # 그래서 순서가 이렇다: Tabby 종료를 기다린다 → 설치한다 → 다시 띄운다.
13
+ # 이 스크립트는 **패키지 밖(임시 폴더)에서** 실행돼야 한다. 자기가 사는 폴더를 npm 이
14
+ # 통째로 갈아엎기 때문이다 (`update.service.ts` 가 임시 폴더로 복사해 띄운다).
15
+ param(
16
+ [Parameter(Mandatory = $true)][string]$Version,
17
+ [Parameter(Mandatory = $true)][string]$PluginsDir,
18
+ [Parameter(Mandatory = $true)][string]$TabbyExe,
19
+ [string]$LogFile = '',
20
+ # Tabby 가 꺼지기를 기다리는 최대 시간(초). 넘으면 설치하지 않고 그냥 끝낸다 —
21
+ # 떠 있는 상태로 설치하면 반쯤 지워진 플러그인이 남는다
22
+ [int]$WaitSeconds = 60
23
+ )
24
+
25
+ $ErrorActionPreference = 'Stop'
26
+ $pkg = 'tabby-agentdeck'
27
+
28
+ if (-not $LogFile) {
29
+ $LogFile = Join-Path $env:LOCALAPPDATA 'tabby-agentdeck\update.log'
30
+ }
31
+ $logDir = Split-Path -Parent $LogFile
32
+ if ($logDir -and -not (Test-Path $logDir)) {
33
+ New-Item -ItemType Directory -Force -Path $logDir | Out-Null
34
+ }
35
+
36
+ function Write-Log ([string]$msg) {
37
+ $line = '{0} {1}' -f (Get-Date -Format 'yyyy-MM-ddTHH:mm:ss'), $msg
38
+ Add-Content -Path $LogFile -Value $line -Encoding UTF8
39
+ }
40
+
41
+ # 로그는 지난 실행을 덮지 않고 쌓되, 커지면 한 번 잘라낸다 (실패를 나중에 읽을 수 있어야 한다)
42
+ try {
43
+ if ((Test-Path $LogFile) -and ((Get-Item $LogFile).Length -gt 512KB)) {
44
+ Move-Item -Force $LogFile "$LogFile.1"
45
+ }
46
+ } catch { }
47
+
48
+ Write-Log "=== update 시작 version=$Version pluginsDir=$PluginsDir"
49
+
50
+ # ── 1) Tabby 가 꺼지기를 기다린다 ────────────────────────────────────────────
51
+ # 우리를 띄운 그 Tabby 가 곧 자기를 닫는다. 자식 프로세스(gpu·renderer)까지 다 내려가야
52
+ # 파일 잠금이 풀리므로 이름으로 전부 센다.
53
+ $waited = 0
54
+ while ($true) {
55
+ $alive = @(Get-Process -Name 'Tabby' -ErrorAction SilentlyContinue)
56
+ if ($alive.Count -eq 0) { break }
57
+ if ($waited -ge $WaitSeconds) {
58
+ Write-Log "FAIL Tabby 가 ${WaitSeconds}초 안에 꺼지지 않았다 (남은 프로세스 $($alive.Count)개) — 설치하지 않는다"
59
+ exit 2
60
+ }
61
+ Start-Sleep -Milliseconds 500
62
+ $waited += 0.5
63
+ }
64
+ Write-Log "Tabby 종료 확인 (${waited}초 대기)"
65
+ # 핸들이 완전히 풀릴 여유를 조금 더 준다
66
+ Start-Sleep -Milliseconds 800
67
+
68
+ # ── 2) 설치 ─────────────────────────────────────────────────────────────────
69
+ # Tabby 의 플러그인 설치와 같은 방식이다 — `plugins/package.json` 에 의존성으로 적히고
70
+ # `plugins/node_modules` 아래로 풀린다. `--prefix` 로 그 폴더를 가리킨다.
71
+ $npm = (Get-Command npm.cmd -ErrorAction SilentlyContinue)
72
+ if (-not $npm) { $npm = (Get-Command npm -ErrorAction SilentlyContinue) }
73
+ if (-not $npm) {
74
+ Write-Log 'FAIL npm 을 찾지 못했다 (PATH 에 node/npm 이 없다)'
75
+ # npm 이 없어도 Tabby 는 다시 띄워 준다 — 사람의 창을 빼앗은 채 끝내면 안 된다
76
+ Write-Log '설치를 건너뛰고 Tabby 를 다시 띄운다'
77
+ } else {
78
+ Write-Log "npm=$($npm.Source)"
79
+ # `$args` 는 PowerShell 자동 변수다 — 이름을 겹치면 조용히 이상하게 돈다
80
+ $npmArgs = @('install', '--prefix', $PluginsDir, '--no-audit', '--no-fund', "$pkg@$Version")
81
+ try {
82
+ $out = & $npm.Source @npmArgs 2>&1
83
+ $code = $LASTEXITCODE
84
+ foreach ($line in $out) { Write-Log "npm| $line" }
85
+ if ($code -eq 0) {
86
+ Write-Log "OK 설치 완료 $pkg@$Version"
87
+ } else {
88
+ Write-Log "FAIL npm exit=$code — 옛 버전이 그대로 남아 있을 수 있다"
89
+ }
90
+ } catch {
91
+ Write-Log "FAIL npm 실행 예외: $($_.Exception.Message)"
92
+ }
93
+ }
94
+
95
+ # ── 3) 다시 띄운다 ──────────────────────────────────────────────────────────
96
+ # 설치가 실패했어도 반드시 띄운다. 업데이트를 고르느라 터미널을 잃는 일은 없어야 한다.
97
+ try {
98
+ if (Test-Path $TabbyExe) {
99
+ Start-Process -FilePath $TabbyExe
100
+ Write-Log "Tabby 재시작: $TabbyExe"
101
+ } else {
102
+ Write-Log "FAIL Tabby 실행파일을 찾지 못했다: $TabbyExe"
103
+ }
104
+ } catch {
105
+ Write-Log "FAIL Tabby 재시작 예외: $($_.Exception.Message)"
106
+ }
107
+
108
+ Write-Log '=== update 끝'