t3mode 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/bundles/backend-host.cjs +74 -0
- package/dist/bundles/index.cjs +96 -0
- package/dist/bundles/main.cjs +31560 -0
- package/dist/bundles/main.cjs.map +1 -0
- package/dist/bundles/preload.cjs +129 -0
- package/dist/bundles/renderer.iife.js +2198 -0
- package/dist/bundles/update-helper.ps1 +143 -0
- package/dist/repair.cjs +32651 -0
- package/dist/t3mode.cjs +47600 -0
- package/package.json +35 -3
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Installs a T3 Code update after T3 Code quits, then puts the t3mode shim back.
|
|
2
|
+
# Started detached by the t3mode loader (packages/main/src/Updater.ts) from Electron's will-quit.
|
|
3
|
+
# 1. Wait for every T3 Code process to exit, stopping plugin tool servers that run its exe.
|
|
4
|
+
# 2. Run the downloaded installer silently, the way electron-updater does (--updated /S),
|
|
5
|
+
# and wait for that process.
|
|
6
|
+
# 3. Re-apply the shim with repair.cjs, run by T3 Code's own exe in Node mode.
|
|
7
|
+
# 4. After "Restart now", start T3 Code again with the arguments it had.
|
|
8
|
+
# It must not be T3 Code's exe itself: the installer replaces that exe while this script runs.
|
|
9
|
+
param(
|
|
10
|
+
[Parameter(Mandatory)] [int] $ParentPid,
|
|
11
|
+
[Parameter(Mandatory)] [string] $Installer,
|
|
12
|
+
[Parameter(Mandatory)] [string] $InstallDir,
|
|
13
|
+
[Parameter(Mandatory)] [string] $RepairJs,
|
|
14
|
+
[Parameter(Mandatory)] [string] $ShimJs,
|
|
15
|
+
[Parameter(Mandatory)] [string] $HomeDir,
|
|
16
|
+
[Parameter(Mandatory)] [string] $Log,
|
|
17
|
+
[string] $Version = "",
|
|
18
|
+
[string] $Relaunch = "0",
|
|
19
|
+
[string] $RelaunchArgs = "",
|
|
20
|
+
[string] $KeepUpdaterEnv = "0",
|
|
21
|
+
[string] $PluginFolders = ""
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
$ErrorActionPreference = "Stop"
|
|
25
|
+
|
|
26
|
+
function Write-Log([string] $Message) {
|
|
27
|
+
try {
|
|
28
|
+
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $Log) | Out-Null
|
|
29
|
+
Add-Content -LiteralPath $Log -Value ("{0} {1}" -f (Get-Date).ToString("o"), $Message)
|
|
30
|
+
} catch {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Windows command-line quoting: Start-Process joins arguments with spaces and quotes nothing.
|
|
34
|
+
function Format-Argument([string] $Value) {
|
|
35
|
+
if ($Value -ne "" -and $Value -notmatch '[\s"]') { return $Value }
|
|
36
|
+
$escaped = $Value -replace '(\\*)"', '$1$1\"' -replace '(\\+)$', '$1$1'
|
|
37
|
+
return '"' + $escaped + '"'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Get-T3Processes {
|
|
41
|
+
$prefix = $InstallDir.TrimEnd("\") + "\"
|
|
42
|
+
@(Get-Process -ErrorAction SilentlyContinue | Where-Object {
|
|
43
|
+
$_.Path -and $_.Path.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase)
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Plugin tool servers run T3 Code's exe, started by Claude or Codex, so they can outlive T3 Code
|
|
48
|
+
# and would hold the update. Stops every process of an exe in the install folder whose command
|
|
49
|
+
# line names a file under <home>\plugins\ or a linked plugin's folder (-PluginFolders, base64
|
|
50
|
+
# JSON), the same match as stopProcessesScript in packages/shared/src/ToolServers.ts.
|
|
51
|
+
# Get-Process has no CommandLine in Windows PowerShell 5.1.
|
|
52
|
+
function Stop-PluginProcesses {
|
|
53
|
+
try {
|
|
54
|
+
$prefix = $InstallDir.TrimEnd("\") + "\"
|
|
55
|
+
$folders = @((Join-Path $HomeDir "plugins").TrimEnd("\") + "\")
|
|
56
|
+
if ($PluginFolders) {
|
|
57
|
+
$json = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($PluginFolders))
|
|
58
|
+
# Windows PowerShell emits a JSON array as one object; foreach over it gets the items.
|
|
59
|
+
foreach ($folder in (ConvertFrom-Json $json)) { $folders += ([string] $folder).TrimEnd("\") + "\" }
|
|
60
|
+
}
|
|
61
|
+
$found = @(Get-CimInstance Win32_Process | Where-Object {
|
|
62
|
+
$p = $_
|
|
63
|
+
$p.ProcessId -ne $PID -and $p.ExecutablePath -and $p.CommandLine -and
|
|
64
|
+
$p.ExecutablePath.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase) -and
|
|
65
|
+
@($folders | Where-Object { $p.CommandLine.IndexOf($_, [StringComparison]::OrdinalIgnoreCase) -ge 0 }).Count -gt 0
|
|
66
|
+
})
|
|
67
|
+
if ($found.Count -eq 0) { return }
|
|
68
|
+
foreach ($p in $found) { Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue }
|
|
69
|
+
foreach ($p in $found) { Wait-Process -Id $p.ProcessId -Timeout 10 -ErrorAction SilentlyContinue }
|
|
70
|
+
Write-Log "Stopped $($found.Count) plugin process(es): $(($found | ForEach-Object { $_.ProcessId }) -join ', ')"
|
|
71
|
+
} catch {
|
|
72
|
+
Write-Log "Could not stop plugin processes: $_"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function Get-T3Exe {
|
|
77
|
+
Get-ChildItem -LiteralPath $InstallDir -Filter "*.exe" |
|
|
78
|
+
Where-Object { $_.Name -notlike "Uninstall*" } |
|
|
79
|
+
Select-Object -First 1
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
$mutex = New-Object System.Threading.Mutex($false, "Local\t3mode-update-helper")
|
|
83
|
+
if (-not $mutex.WaitOne(0)) {
|
|
84
|
+
Write-Log "Another update helper is running; this one stops."
|
|
85
|
+
exit 0
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
Write-Log "Update to $Version`: waiting for T3 Code (pid $ParentPid) to exit"
|
|
90
|
+
try { Wait-Process -Id $ParentPid -Timeout 120 -ErrorAction SilentlyContinue } catch {}
|
|
91
|
+
$deadline = (Get-Date).AddSeconds(120)
|
|
92
|
+
while ((Get-T3Processes).Count -gt 0) {
|
|
93
|
+
Stop-PluginProcesses
|
|
94
|
+
if ((Get-T3Processes).Count -eq 0) { break }
|
|
95
|
+
if ((Get-Date) -gt $deadline) {
|
|
96
|
+
Write-Log "T3 Code is still running after 2 minutes; the update is skipped until the next quit."
|
|
97
|
+
exit 1
|
|
98
|
+
}
|
|
99
|
+
Start-Sleep -Milliseconds 500
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Write-Log "Running $Installer"
|
|
103
|
+
$install = Start-Process -FilePath $Installer -ArgumentList "--updated", "/S" -Wait -PassThru -WindowStyle Hidden
|
|
104
|
+
Write-Log "Installer exited with code $($install.ExitCode)"
|
|
105
|
+
|
|
106
|
+
# Re-apply the shim whatever the installer did: a failed install may still have replaced app.asar.
|
|
107
|
+
$exe = Get-T3Exe
|
|
108
|
+
if (-not $exe) { throw "No T3 Code executable in $InstallDir after the install." }
|
|
109
|
+
$out = Join-Path $env:TEMP "t3mode-repair.out.txt"
|
|
110
|
+
$err = Join-Path $env:TEMP "t3mode-repair.err.txt"
|
|
111
|
+
$env:ELECTRON_RUN_AS_NODE = "1"
|
|
112
|
+
$repairArgs = @($RepairJs, $InstallDir, $ShimJs, $HomeDir) | ForEach-Object { Format-Argument $_ }
|
|
113
|
+
$repair = Start-Process -FilePath $exe.FullName -ArgumentList $repairArgs -Wait -PassThru -NoNewWindow `
|
|
114
|
+
-RedirectStandardOutput $out -RedirectStandardError $err
|
|
115
|
+
Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue
|
|
116
|
+
$output = ((Get-Content -LiteralPath $out, $err -ErrorAction SilentlyContinue) -join " ").Trim()
|
|
117
|
+
Write-Log "Shim repair exited with code $($repair.ExitCode): $output"
|
|
118
|
+
Remove-Item -LiteralPath $out, $err -ErrorAction SilentlyContinue
|
|
119
|
+
|
|
120
|
+
if ($Relaunch -eq "1") {
|
|
121
|
+
# The new launch decides for itself whether T3 Code's updater stays off.
|
|
122
|
+
if ($KeepUpdaterEnv -ne "1") { Remove-Item Env:T3CODE_DISABLE_AUTO_UPDATE -ErrorAction SilentlyContinue }
|
|
123
|
+
$arguments = @()
|
|
124
|
+
if ($RelaunchArgs) {
|
|
125
|
+
$json = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($RelaunchArgs))
|
|
126
|
+
# Windows PowerShell emits a JSON array as one object; foreach over it gets the items.
|
|
127
|
+
$items = ConvertFrom-Json $json
|
|
128
|
+
foreach ($item in $items) { $arguments += Format-Argument ([string] $item) }
|
|
129
|
+
}
|
|
130
|
+
Write-Log "Starting $($exe.FullName)"
|
|
131
|
+
if ($arguments.Count -gt 0) {
|
|
132
|
+
Start-Process -FilePath $exe.FullName -ArgumentList $arguments | Out-Null
|
|
133
|
+
} else {
|
|
134
|
+
Start-Process -FilePath $exe.FullName | Out-Null
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
Write-Log "Update helper done"
|
|
138
|
+
} catch {
|
|
139
|
+
Write-Log "Update helper failed: $_"
|
|
140
|
+
exit 1
|
|
141
|
+
} finally {
|
|
142
|
+
$mutex.ReleaseMutex()
|
|
143
|
+
}
|