forked from goodnightzsj/codex-session-cloner
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcodex-session-toolkit.ps1
More file actions
98 lines (84 loc) · 3.93 KB
/
Copy pathcodex-session-toolkit.ps1
File metadata and controls
98 lines (84 loc) · 3.93 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
# Codex Session Toolkit launcher (Windows)
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $PassthroughArgs
)
$ErrorActionPreference = "Stop"
$packageName = "codex_session_toolkit"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$venvDir = if ($env:VENV_DIR) { $env:VENV_DIR } else { Join-Path $scriptDir ".venv" }
$venvScriptsDir = Join-Path $venvDir "Scripts"
$venvPython = Join-Path $venvScriptsDir "python.exe"
$installedExe = Join-Path $venvScriptsDir "codex-session-toolkit.exe"
$installedCmd = Join-Path $venvScriptsDir "codex-session-toolkit.cmd"
$srcDir = Join-Path $scriptDir "src"
$packageDir = Join-Path $srcDir $packageName
$launchMode = if ($env:CST_LAUNCH_MODE) { $env:CST_LAUNCH_MODE } elseif ($env:CSC_LAUNCH_MODE) { $env:CSC_LAUNCH_MODE } else { "auto" }
$isGitWorktree = (Test-Path (Join-Path $scriptDir ".git")) -and (Test-Path $packageDir)
function Resolve-PythonCommand {
if ($env:PYTHON_BIN) { return ,@($env:PYTHON_BIN) }
if (Test-Path $venvPython) { return ,@($venvPython) }
if (Get-Command "python" -ErrorAction SilentlyContinue) { return ,@("python") }
if (Get-Command "py" -ErrorAction SilentlyContinue) { return ,@("py", "-3") }
if (Get-Command "python3" -ErrorAction SilentlyContinue) { return ,@("python3") }
return $null
}
function Invoke-InstalledLauncher {
if (Test-Path $installedExe) {
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host " Codex Session Toolkit - Launcher (Local Venv)" -ForegroundColor Cyan
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host ">> $installedExe $($PassthroughArgs -join ' ')" -ForegroundColor DarkGray
& $installedExe @PassthroughArgs
exit $LASTEXITCODE
}
if (Test-Path $installedCmd) {
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host " Codex Session Toolkit - Launcher (Local Venv)" -ForegroundColor Cyan
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host ">> $installedCmd $($PassthroughArgs -join ' ')" -ForegroundColor DarkGray
& $installedCmd @PassthroughArgs
exit $LASTEXITCODE
}
}
Set-Location $scriptDir
if ($launchMode -eq "installed") {
Invoke-InstalledLauncher
}
if ($launchMode -eq "auto" -and -not $isGitWorktree) {
Invoke-InstalledLauncher
}
if (-not (Test-Path $packageDir)) {
Invoke-InstalledLauncher
Write-Host "Error: cannot find package source at $packageDir" -ForegroundColor Red
Write-Host "Tip: run .\install.ps1 first, or keep the src\ tree intact." -ForegroundColor Yellow
exit 1
}
$pyCmd = Resolve-PythonCommand
if (-not $pyCmd) {
Write-Host "Error: Python not found. Install Python 3 first." -ForegroundColor Red
Write-Host "Tip: after Python is ready, rerun .\install.ps1 ." -ForegroundColor Yellow
exit 127
}
$pythonExe = $pyCmd[0]
$pythonPreArgs = @()
if ($pyCmd.Length -gt 1) {
$pythonPreArgs = $pyCmd[1..($pyCmd.Length - 1)]
}
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host " Codex Session Toolkit - Launcher (Source Mode)" -ForegroundColor Cyan
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host "Python: $pythonExe $($pythonPreArgs -join ' ')" -ForegroundColor DarkGray
if ($pythonExe -eq $venvPython) {
Write-Host "Env: local isolated .venv" -ForegroundColor DarkGray
} else {
Write-Host "Env: system interpreter (tip: run .\install.ps1 to isolate dependencies)" -ForegroundColor DarkGray
}
Write-Host ">> $pythonExe $($pythonPreArgs -join ' ') -m $packageName $($PassthroughArgs -join ' ')" -ForegroundColor DarkGray
if ($env:PYTHONPATH) {
$env:PYTHONPATH = "$srcDir;$($env:PYTHONPATH)"
} else {
$env:PYTHONPATH = $srcDir
}
& $pythonExe @pythonPreArgs -m $packageName @PassthroughArgs
exit $LASTEXITCODE