@harness-reins/linux-x64 0.9.3 → 0.11.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/dist/reins/_internal/harness_reins/_build.txt +1 -1
- package/dist/reins/_internal/harness_reins/assets/skills/claude/SKILL.md +29 -0
- package/dist/reins/_internal/harness_reins/assets/skills/codex/SKILL.md +30 -1
- package/dist/reins/_internal/harness_reins/assets/skills/pi/SKILL.md +29 -0
- package/dist/reins/_internal/harness_reins/assets/skills/reference/SKILL.md +27 -37
- package/dist/reins/reins +0 -0
- package/package.json +1 -1
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/desktop-package-launch.py +0 -263
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/invoke-desktop-package.ps1 +0 -14
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/probe-desktop-launch.py +0 -217
- package/dist/reins/_internal/harness_reins/harness/codex/desktop/windows_assets/start-desktop-bridge.ps1 +0 -449
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/INSTALLER +0 -1
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/METADATA +0 -18
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/RECORD +0 -199
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/REQUESTED +0 -0
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/WHEEL +0 -5
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/direct_url.json +0 -1
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/entry_points.txt +0 -3
- package/dist/reins/_internal/harness_reins-0.9.3.dist-info/top_level.txt +0 -1
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"""Diagnose CreateProcess permissions without running any executable code.
|
|
2
|
-
|
|
3
|
-
The only child this probe can create starts suspended. It is never resumed and
|
|
4
|
-
is terminated through its returned process handle before the probe exits.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import argparse
|
|
8
|
-
import ctypes
|
|
9
|
-
from ctypes import wintypes
|
|
10
|
-
import json
|
|
11
|
-
import os
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
import subprocess
|
|
14
|
-
import sys
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
CREATE_SUSPENDED = 0x00000004
|
|
18
|
-
CREATE_UNICODE_ENVIRONMENT = 0x00000400
|
|
19
|
-
CREATE_NO_WINDOW = 0x08000000
|
|
20
|
-
STARTF_USESHOWWINDOW = 0x00000001
|
|
21
|
-
WAIT_OBJECT_0 = 0
|
|
22
|
-
WAIT_TIMEOUT = 258
|
|
23
|
-
WAIT_FAILED = 0xFFFFFFFF
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class STARTUPINFOW(ctypes.Structure):
|
|
27
|
-
_fields_ = [
|
|
28
|
-
("cb", wintypes.DWORD),
|
|
29
|
-
("lpReserved", wintypes.LPWSTR),
|
|
30
|
-
("lpDesktop", wintypes.LPWSTR),
|
|
31
|
-
("lpTitle", wintypes.LPWSTR),
|
|
32
|
-
("dwX", wintypes.DWORD),
|
|
33
|
-
("dwY", wintypes.DWORD),
|
|
34
|
-
("dwXSize", wintypes.DWORD),
|
|
35
|
-
("dwYSize", wintypes.DWORD),
|
|
36
|
-
("dwXCountChars", wintypes.DWORD),
|
|
37
|
-
("dwYCountChars", wintypes.DWORD),
|
|
38
|
-
("dwFillAttribute", wintypes.DWORD),
|
|
39
|
-
("dwFlags", wintypes.DWORD),
|
|
40
|
-
("wShowWindow", wintypes.WORD),
|
|
41
|
-
("cbReserved2", wintypes.WORD),
|
|
42
|
-
("lpReserved2", ctypes.POINTER(wintypes.BYTE)),
|
|
43
|
-
("hStdInput", wintypes.HANDLE),
|
|
44
|
-
("hStdOutput", wintypes.HANDLE),
|
|
45
|
-
("hStdError", wintypes.HANDLE),
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class PROCESS_INFORMATION(ctypes.Structure):
|
|
50
|
-
_fields_ = [
|
|
51
|
-
("hProcess", wintypes.HANDLE),
|
|
52
|
-
("hThread", wintypes.HANDLE),
|
|
53
|
-
("dwProcessId", wintypes.DWORD),
|
|
54
|
-
("dwThreadId", wintypes.DWORD),
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _kernel32():
|
|
59
|
-
kernel = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
60
|
-
kernel.GetCurrentProcess.argtypes = []
|
|
61
|
-
kernel.GetCurrentProcess.restype = wintypes.HANDLE
|
|
62
|
-
kernel.IsProcessInJob.argtypes = [
|
|
63
|
-
wintypes.HANDLE, wintypes.HANDLE, ctypes.POINTER(wintypes.BOOL)
|
|
64
|
-
]
|
|
65
|
-
kernel.IsProcessInJob.restype = wintypes.BOOL
|
|
66
|
-
kernel.CreateProcessW.argtypes = [
|
|
67
|
-
wintypes.LPCWSTR,
|
|
68
|
-
wintypes.LPWSTR,
|
|
69
|
-
ctypes.c_void_p,
|
|
70
|
-
ctypes.c_void_p,
|
|
71
|
-
wintypes.BOOL,
|
|
72
|
-
wintypes.DWORD,
|
|
73
|
-
ctypes.c_void_p,
|
|
74
|
-
wintypes.LPCWSTR,
|
|
75
|
-
ctypes.POINTER(STARTUPINFOW),
|
|
76
|
-
ctypes.POINTER(PROCESS_INFORMATION),
|
|
77
|
-
]
|
|
78
|
-
kernel.CreateProcessW.restype = wintypes.BOOL
|
|
79
|
-
kernel.GetPackageFullName.argtypes = [
|
|
80
|
-
wintypes.HANDLE, ctypes.POINTER(wintypes.DWORD), wintypes.LPWSTR
|
|
81
|
-
]
|
|
82
|
-
kernel.GetPackageFullName.restype = wintypes.LONG
|
|
83
|
-
kernel.TerminateProcess.argtypes = [wintypes.HANDLE, wintypes.UINT]
|
|
84
|
-
kernel.TerminateProcess.restype = wintypes.BOOL
|
|
85
|
-
kernel.WaitForSingleObject.argtypes = [wintypes.HANDLE, wintypes.DWORD]
|
|
86
|
-
kernel.WaitForSingleObject.restype = wintypes.DWORD
|
|
87
|
-
kernel.CloseHandle.argtypes = [wintypes.HANDLE]
|
|
88
|
-
kernel.CloseHandle.restype = wintypes.BOOL
|
|
89
|
-
return kernel
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def _error_text(code):
|
|
93
|
-
return ctypes.FormatError(code).strip()
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def _child_package_identity(kernel, handle):
|
|
97
|
-
"""Read the exact suspended child's package identity without resuming it."""
|
|
98
|
-
length = wintypes.DWORD()
|
|
99
|
-
status = int(kernel.GetPackageFullName(handle, ctypes.byref(length), None))
|
|
100
|
-
if status != 122 or not 1 < length.value <= 65536: # ERROR_INSUFFICIENT_BUFFER
|
|
101
|
-
return None, status
|
|
102
|
-
name = ctypes.create_unicode_buffer(length.value)
|
|
103
|
-
status = int(kernel.GetPackageFullName(handle, ctypes.byref(length), name))
|
|
104
|
-
if status:
|
|
105
|
-
return None, status
|
|
106
|
-
return name.value or None, status
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def _cleanup(kernel, child):
|
|
110
|
-
"""Terminate and close only the exact handles returned by CreateProcessW."""
|
|
111
|
-
errors = []
|
|
112
|
-
terminated = False
|
|
113
|
-
try:
|
|
114
|
-
terminate_error = 0
|
|
115
|
-
if not kernel.TerminateProcess(child.hProcess, 1):
|
|
116
|
-
terminate_error = ctypes.get_last_error()
|
|
117
|
-
wait_result = kernel.WaitForSingleObject(child.hProcess, 5000)
|
|
118
|
-
if wait_result == WAIT_OBJECT_0:
|
|
119
|
-
# A separate process may already have terminated this suspended
|
|
120
|
-
# child. A signaled process handle also establishes safe cleanup.
|
|
121
|
-
terminated = True
|
|
122
|
-
elif wait_result == WAIT_TIMEOUT:
|
|
123
|
-
errors.append("the suspended child did not exit within 5 seconds")
|
|
124
|
-
elif wait_result == WAIT_FAILED:
|
|
125
|
-
code = ctypes.get_last_error()
|
|
126
|
-
errors.append("waiting for termination failed: %s (%d)" % (_error_text(code), code))
|
|
127
|
-
else:
|
|
128
|
-
errors.append("unexpected process wait result: %d" % wait_result)
|
|
129
|
-
if terminate_error and not terminated:
|
|
130
|
-
errors.append("TerminateProcess failed: %s (%d)" % (_error_text(terminate_error), terminate_error))
|
|
131
|
-
finally:
|
|
132
|
-
for label, handle in (("thread", child.hThread), ("process", child.hProcess)):
|
|
133
|
-
if handle and not kernel.CloseHandle(handle):
|
|
134
|
-
code = ctypes.get_last_error()
|
|
135
|
-
errors.append("closing the %s handle failed: %s (%d)" % (label, _error_text(code), code))
|
|
136
|
-
if errors:
|
|
137
|
-
raise RuntimeError("cleanup of suspended probe PID %d failed: %s" % (child.dwProcessId, "; ".join(errors)))
|
|
138
|
-
return terminated
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
def probe(executable):
|
|
142
|
-
result = {
|
|
143
|
-
"executable": executable,
|
|
144
|
-
"can_create_suspended": False,
|
|
145
|
-
"native_error_code": 0,
|
|
146
|
-
"native_error_message": "",
|
|
147
|
-
"current_process_in_job": None,
|
|
148
|
-
"child_package_full_name": None,
|
|
149
|
-
"child_package_query_status": None,
|
|
150
|
-
"probe_resumed": False,
|
|
151
|
-
"cleanup_complete": True,
|
|
152
|
-
}
|
|
153
|
-
try:
|
|
154
|
-
kernel = _kernel32()
|
|
155
|
-
in_job = wintypes.BOOL()
|
|
156
|
-
if not kernel.IsProcessInJob(kernel.GetCurrentProcess(), None, ctypes.byref(in_job)):
|
|
157
|
-
code = ctypes.get_last_error()
|
|
158
|
-
raise OSError(code, "IsProcessInJob failed: " + _error_text(code))
|
|
159
|
-
result["current_process_in_job"] = bool(in_job.value)
|
|
160
|
-
startup = STARTUPINFOW()
|
|
161
|
-
startup.cb = ctypes.sizeof(startup)
|
|
162
|
-
startup.dwFlags = STARTF_USESHOWWINDOW
|
|
163
|
-
startup.wShowWindow = 0
|
|
164
|
-
child = PROCESS_INFORMATION()
|
|
165
|
-
command_line = ctypes.create_unicode_buffer(subprocess.list2cmdline([executable]))
|
|
166
|
-
try:
|
|
167
|
-
created = kernel.CreateProcessW(
|
|
168
|
-
executable,
|
|
169
|
-
command_line,
|
|
170
|
-
None,
|
|
171
|
-
None,
|
|
172
|
-
False,
|
|
173
|
-
CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW,
|
|
174
|
-
None, # Inherit the caller's environment without reading or printing it.
|
|
175
|
-
str(Path(executable).parent),
|
|
176
|
-
ctypes.byref(startup),
|
|
177
|
-
ctypes.byref(child),
|
|
178
|
-
)
|
|
179
|
-
if not created:
|
|
180
|
-
code = ctypes.get_last_error()
|
|
181
|
-
result["native_error_code"] = code
|
|
182
|
-
result["native_error_message"] = _error_text(code)
|
|
183
|
-
else:
|
|
184
|
-
result["can_create_suspended"] = True
|
|
185
|
-
name, status = _child_package_identity(kernel, child.hProcess)
|
|
186
|
-
result["child_package_full_name"] = name
|
|
187
|
-
result["child_package_query_status"] = status
|
|
188
|
-
finally:
|
|
189
|
-
# Inspect the out-parameter even when Python raises immediately
|
|
190
|
-
# after the native call has supplied the new child's handles.
|
|
191
|
-
if child.hProcess:
|
|
192
|
-
result["cleanup_complete"] = False
|
|
193
|
-
result["cleanup_complete"] = _cleanup(kernel, child)
|
|
194
|
-
return result, 0
|
|
195
|
-
except (Exception, KeyboardInterrupt) as error:
|
|
196
|
-
print("Suspended launch probe failed: %s" % (str(error) or type(error).__name__), file=sys.stderr)
|
|
197
|
-
return result, 1
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def main():
|
|
201
|
-
parser = argparse.ArgumentParser(description=__doc__)
|
|
202
|
-
parser.add_argument("executable", help="Absolute path to one Windows .exe file")
|
|
203
|
-
args = parser.parse_args()
|
|
204
|
-
if os.name != "nt":
|
|
205
|
-
parser.error("this diagnostic runs only on Windows")
|
|
206
|
-
if sys.version_info < (3, 9):
|
|
207
|
-
parser.error("Python 3.9 or newer is required")
|
|
208
|
-
executable = Path(args.executable)
|
|
209
|
-
if not executable.is_absolute() or executable.suffix.lower() != ".exe":
|
|
210
|
-
parser.error("executable must be an absolute .exe path")
|
|
211
|
-
result, returncode = probe(str(executable))
|
|
212
|
-
print(json.dumps(result, ensure_ascii=True))
|
|
213
|
-
return returncode
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if __name__ == "__main__":
|
|
217
|
-
sys.exit(main())
|
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
<#
|
|
2
|
-
Experimental opt-in: let Codex Desktop own a Reins-enabled App Server wrapper.
|
|
3
|
-
Close Codex Desktop yourself before starting. This script never stops an app.
|
|
4
|
-
-CheckOnly inspects paths and the Core version, then tests native GUI process
|
|
5
|
-
creation with its initial thread suspended. It immediately terminates only that
|
|
6
|
-
new probe process; it never runs GUI code, starts a server, or changes settings.
|
|
7
|
-
Requires the Windows-capable Reins installation and an authenticated profile.
|
|
8
|
-
Pass -Python from the Reins installation; no checkout or virtualenv is assumed.
|
|
9
|
-
-BridgeFile accepts a fixed absolute metadata path for the selected profile.
|
|
10
|
-
-PackageContext opts into the Windows package diagnostic launcher. Its token is
|
|
11
|
-
not guaranteed equivalent to normal app activation. No persistent settings change.
|
|
12
|
-
#>
|
|
13
|
-
[CmdletBinding()]
|
|
14
|
-
param(
|
|
15
|
-
[Parameter(Mandatory = $true)][string]$Python,
|
|
16
|
-
[string]$CodexHome = $(if ($env:CODEX_HOME) { $env:CODEX_HOME } else { Join-Path $env:USERPROFILE '.codex' }),
|
|
17
|
-
[string]$CodexBin,
|
|
18
|
-
[string]$CoreWrapper,
|
|
19
|
-
[string]$DesktopExe,
|
|
20
|
-
[string]$BridgeFile,
|
|
21
|
-
[switch]$PackageContext,
|
|
22
|
-
[switch]$CheckOnly
|
|
23
|
-
)
|
|
24
|
-
$ErrorActionPreference = 'Stop'
|
|
25
|
-
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
26
|
-
|
|
27
|
-
function Get-DesktopPackage {
|
|
28
|
-
if ($PSVersionTable.PSEdition -eq 'Desktop') {
|
|
29
|
-
return Get-AppxPackage -Name 'OpenAI.Codex' | Select-Object -First 1
|
|
30
|
-
}
|
|
31
|
-
# Some PowerShell 7 installations cannot load Appx. Query Windows
|
|
32
|
-
# PowerShell rather than guessing a package path.
|
|
33
|
-
$windowsPowerShell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
34
|
-
$text = & $windowsPowerShell -NoProfile -NonInteractive -Command "Get-AppxPackage -Name 'OpenAI.Codex' | Select-Object -First 1 Name,Version,InstallLocation,PackageFullName,PackageFamilyName | ConvertTo-Json -Compress"
|
|
35
|
-
if ($LASTEXITCODE -ne 0) { throw 'Cannot inspect the Desktop package; supply -DesktopExe and -CodexBin explicitly.' }
|
|
36
|
-
if ($text) { return $text | ConvertFrom-Json }
|
|
37
|
-
return $null
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function Resolve-Executable([string]$Value) {
|
|
41
|
-
if (Test-Path -LiteralPath $Value -PathType Leaf) {
|
|
42
|
-
return (Resolve-Path -LiteralPath $Value).Path
|
|
43
|
-
}
|
|
44
|
-
$command = Get-Command -Name $Value -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
45
|
-
if (-not $command) { throw "Executable not found: $Value" }
|
|
46
|
-
return $command.Source
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function Get-BridgeStatus {
|
|
50
|
-
$text = & $Python -B -m harness_reins.harness.codex.desktop.bridge --codex-home $CodexHome --metadata-file $metadata --status
|
|
51
|
-
if ($LASTEXITCODE -notin @(0, 1)) { throw 'Cannot safely inspect the existing bridge state.' }
|
|
52
|
-
try { $status = $text | ConvertFrom-Json } catch { throw 'The bridge status response is invalid.' }
|
|
53
|
-
if ($null -eq $status -or $status.running -isnot [bool]) { throw 'The bridge status response has no valid running state.' }
|
|
54
|
-
return $status
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function Get-WrapperVersion {
|
|
58
|
-
# --version is transparently delegated to REAL_CODEX by the wrapper. Only
|
|
59
|
-
# this child receives its override; the launching shell is never mutated.
|
|
60
|
-
$info = New-Object System.Diagnostics.ProcessStartInfo
|
|
61
|
-
$info.FileName = $CoreWrapper
|
|
62
|
-
$info.Arguments = '--version'
|
|
63
|
-
$info.UseShellExecute = $false
|
|
64
|
-
$info.CreateNoWindow = $true
|
|
65
|
-
$info.RedirectStandardOutput = $true
|
|
66
|
-
$info.RedirectStandardError = $true
|
|
67
|
-
$info.EnvironmentVariables['REINS_DESKTOP_REAL_CODEX'] = $CodexBin
|
|
68
|
-
$info.EnvironmentVariables['CODEX_HOME'] = $CodexHome
|
|
69
|
-
$info.EnvironmentVariables['PYTHONDONTWRITEBYTECODE'] = '1'
|
|
70
|
-
$probe = New-Object System.Diagnostics.Process
|
|
71
|
-
$probe.StartInfo = $info
|
|
72
|
-
try {
|
|
73
|
-
if (-not $probe.Start()) { throw 'Cannot start the Core wrapper version check.' }
|
|
74
|
-
$output = $probe.StandardOutput.ReadToEndAsync()
|
|
75
|
-
$errors = $probe.StandardError.ReadToEndAsync()
|
|
76
|
-
if (-not $probe.WaitForExit(15000)) {
|
|
77
|
-
$probe.Kill()
|
|
78
|
-
$probe.WaitForExit()
|
|
79
|
-
throw 'The Core wrapper version check timed out.'
|
|
80
|
-
}
|
|
81
|
-
$version = $output.Result.Trim()
|
|
82
|
-
if ($probe.ExitCode -ne 0 -or $version -ne $coreVersion) {
|
|
83
|
-
throw 'The Core wrapper did not report the selected Desktop Core version; reinstall the matching Reins package.'
|
|
84
|
-
}
|
|
85
|
-
return $version
|
|
86
|
-
} finally {
|
|
87
|
-
$probe.Dispose()
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function Get-DesktopLaunchProbe {
|
|
92
|
-
$probeScript = Join-Path $scriptDirectory 'probe-desktop-launch.py'
|
|
93
|
-
if (-not (Test-Path -LiteralPath $probeScript -PathType Leaf)) {
|
|
94
|
-
throw 'The native launch probe is missing. Reinstall the complete Reins package.'
|
|
95
|
-
}
|
|
96
|
-
$info = New-Object System.Diagnostics.ProcessStartInfo
|
|
97
|
-
$info.FileName = $Python
|
|
98
|
-
$info.Arguments = '-B "{0}" "{1}"' -f $probeScript, $DesktopExe
|
|
99
|
-
$info.UseShellExecute = $false
|
|
100
|
-
$info.CreateNoWindow = $true
|
|
101
|
-
$info.RedirectStandardOutput = $true
|
|
102
|
-
$info.RedirectStandardError = $true
|
|
103
|
-
foreach ($key in $settings.Keys) {
|
|
104
|
-
if ($null -eq $settings[$key]) {
|
|
105
|
-
$info.EnvironmentVariables.Remove($key)
|
|
106
|
-
} else {
|
|
107
|
-
$info.EnvironmentVariables[$key] = $settings[$key]
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
$probe = New-Object System.Diagnostics.Process
|
|
111
|
-
$probe.StartInfo = $info
|
|
112
|
-
try {
|
|
113
|
-
if (-not $probe.Start()) { throw 'Cannot start the native Desktop launch probe.' }
|
|
114
|
-
$output = $probe.StandardOutput.ReadToEndAsync()
|
|
115
|
-
$errors = $probe.StandardError.ReadToEndAsync()
|
|
116
|
-
if (-not $probe.WaitForExit(15000)) {
|
|
117
|
-
# Do not kill a probe that might still be cleaning up its suspended
|
|
118
|
-
# child. In particular, never substitute a PID-based GUI kill.
|
|
119
|
-
throw "The launch probe did not finish cleanup (probe PID $($probe.Id)). No normal Desktop launch was attempted."
|
|
120
|
-
}
|
|
121
|
-
if ($probe.ExitCode -ne 0) {
|
|
122
|
-
throw "The native launch probe failed or could not confirm cleanup: $($errors.Result.Trim())"
|
|
123
|
-
}
|
|
124
|
-
try { $result = $output.Result | ConvertFrom-Json } catch { throw 'Invalid native launch probe response.' }
|
|
125
|
-
if ($result.can_create_suspended -isnot [bool] -or
|
|
126
|
-
$result.cleanup_complete -ne $true -or $result.probe_resumed -ne $false) {
|
|
127
|
-
throw 'The native launch probe did not confirm safe completion.'
|
|
128
|
-
}
|
|
129
|
-
return $result
|
|
130
|
-
} finally {
|
|
131
|
-
$probe.Dispose()
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function Invoke-PackageDesktop([bool]$ProbeOnly) {
|
|
136
|
-
# Invoke-CommandInDesktopPackage does not guarantee inheritance of our
|
|
137
|
-
# shell environment. Transfer only the seven intended overrides in a
|
|
138
|
-
# temporary request, and apply them inside the package-identity helper.
|
|
139
|
-
$basePython = (& $Python -I -c 'import sys; print(sys._base_executable)').Trim()
|
|
140
|
-
if ($LASTEXITCODE -ne 0 -or -not $basePython) { throw 'Cannot find the base Python interpreter.' }
|
|
141
|
-
$windowlessPython = Join-Path (Split-Path -Parent $basePython) 'pythonw.exe'
|
|
142
|
-
if (-not (Test-Path -LiteralPath $windowlessPython -PathType Leaf)) {
|
|
143
|
-
throw 'PackageContext requires pythonw.exe beside the base Python interpreter to keep the diagnostic helper hidden.'
|
|
144
|
-
}
|
|
145
|
-
$helper = Join-Path $scriptDirectory 'desktop-package-launch.py'
|
|
146
|
-
$facade = Join-Path $scriptDirectory 'invoke-desktop-package.ps1'
|
|
147
|
-
foreach ($file in @($helper, $facade)) {
|
|
148
|
-
if (-not (Test-Path -LiteralPath $file -PathType Leaf)) { throw "Package launch helper is missing: $file" }
|
|
149
|
-
}
|
|
150
|
-
$requestDirectory = Join-Path ([IO.Path]::GetTempPath()) ('reins-desktop-launch-' + [Guid]::NewGuid().ToString('N'))
|
|
151
|
-
[void](New-Item -ItemType Directory -Path $requestDirectory)
|
|
152
|
-
$requestFile = Join-Path $requestDirectory 'request.json'
|
|
153
|
-
$resultFile = Join-Path $requestDirectory 'result.json'
|
|
154
|
-
$request = @{
|
|
155
|
-
expected_package_full_name = $package.PackageFullName
|
|
156
|
-
desktop_executable = $DesktopExe
|
|
157
|
-
environment = $settings
|
|
158
|
-
result_file = $resultFile
|
|
159
|
-
check_only = $ProbeOnly
|
|
160
|
-
}
|
|
161
|
-
$invoker = $null
|
|
162
|
-
$helperFinished = $false
|
|
163
|
-
try {
|
|
164
|
-
[IO.File]::WriteAllText($requestFile, ($request | ConvertTo-Json -Depth 4), (New-Object Text.UTF8Encoding($false)))
|
|
165
|
-
$info = New-Object System.Diagnostics.ProcessStartInfo
|
|
166
|
-
$info.FileName = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
167
|
-
$info.Arguments = '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File "{0}" -PackageFamilyName "{1}" -Python "{2}" -Helper "{3}" -RequestFile "{4}"' -f $facade, $package.PackageFamilyName, $windowlessPython, $helper, $requestFile
|
|
168
|
-
$info.UseShellExecute = $false
|
|
169
|
-
$info.CreateNoWindow = $true
|
|
170
|
-
$info.RedirectStandardOutput = $true
|
|
171
|
-
$info.RedirectStandardError = $true
|
|
172
|
-
$invoker = New-Object System.Diagnostics.Process
|
|
173
|
-
$invoker.StartInfo = $info
|
|
174
|
-
if (-not $invoker.Start()) { throw 'Cannot start the Windows package diagnostic launcher.' }
|
|
175
|
-
$output = $invoker.StandardOutput.ReadToEndAsync()
|
|
176
|
-
$errors = $invoker.StandardError.ReadToEndAsync()
|
|
177
|
-
if (-not $invoker.WaitForExit(15000)) {
|
|
178
|
-
throw "Package activation did not return. Do not retry until the helper's outcome is resolved. Diagnostic files: $requestDirectory"
|
|
179
|
-
}
|
|
180
|
-
if ($invoker.ExitCode -ne 0) {
|
|
181
|
-
throw "Windows package activation failed: $($errors.Result.Trim()). Diagnostic files: $requestDirectory"
|
|
182
|
-
}
|
|
183
|
-
$deadline = [DateTime]::UtcNow.AddSeconds(20)
|
|
184
|
-
$result = $null
|
|
185
|
-
do {
|
|
186
|
-
if (Test-Path -LiteralPath $resultFile -PathType Leaf) {
|
|
187
|
-
try { $result = [IO.File]::ReadAllText($resultFile) | ConvertFrom-Json } catch { $result = $null }
|
|
188
|
-
}
|
|
189
|
-
if ($null -ne $result) { break }
|
|
190
|
-
Start-Sleep -Milliseconds 100
|
|
191
|
-
} while ([DateTime]::UtcNow -lt $deadline)
|
|
192
|
-
if ($null -eq $result) {
|
|
193
|
-
throw "Package helper did not report completion. Do not retry until its outcome is resolved. Diagnostic files: $requestDirectory"
|
|
194
|
-
}
|
|
195
|
-
$helperFinished = $true
|
|
196
|
-
if ($result.ok -ne $true) {
|
|
197
|
-
$nativeDetail = ''
|
|
198
|
-
if ($null -ne $result.native_launch_probe) {
|
|
199
|
-
$nativeDetail = " Win32 error $($result.native_launch_probe.native_error_code): $($result.native_launch_probe.native_error_message)."
|
|
200
|
-
}
|
|
201
|
-
throw "Package helper failed: $($result.error_type): $($result.message).$nativeDetail"
|
|
202
|
-
}
|
|
203
|
-
if ($result.package_full_name -ne $package.PackageFullName -or
|
|
204
|
-
$result.native_launch_probe.cleanup_complete -ne $true -or
|
|
205
|
-
$result.native_launch_probe.probe_resumed -ne $false) {
|
|
206
|
-
throw 'Package helper did not confirm the expected identity and probe cleanup.'
|
|
207
|
-
}
|
|
208
|
-
return $result
|
|
209
|
-
} finally {
|
|
210
|
-
if ($null -ne $invoker) { $invoker.Dispose() }
|
|
211
|
-
# Never remove input while an uncertain helper might still need it.
|
|
212
|
-
# No recursive deletion: these are the two exact temporary files only.
|
|
213
|
-
if ($helperFinished) {
|
|
214
|
-
$cleanupComplete = $false
|
|
215
|
-
$cleanupDeadline = [DateTime]::UtcNow.AddSeconds(3)
|
|
216
|
-
do {
|
|
217
|
-
try {
|
|
218
|
-
foreach ($file in @($requestFile, $resultFile)) {
|
|
219
|
-
if (Test-Path -LiteralPath $file -PathType Leaf) { Remove-Item -LiteralPath $file -Force }
|
|
220
|
-
}
|
|
221
|
-
[IO.Directory]::Delete($requestDirectory, $false)
|
|
222
|
-
$cleanupComplete = $true
|
|
223
|
-
} catch {
|
|
224
|
-
# A complete result can be readable just before pythonw
|
|
225
|
-
# closes it. Retry sharing conflicts without masking launch.
|
|
226
|
-
Start-Sleep -Milliseconds 50
|
|
227
|
-
}
|
|
228
|
-
} while (-not $cleanupComplete -and [DateTime]::UtcNow -lt $cleanupDeadline)
|
|
229
|
-
if (-not $cleanupComplete) { Write-Warning "Temporary diagnostic files were retained: $requestDirectory" }
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
$Python = (Resolve-Path -LiteralPath $Python).Path
|
|
235
|
-
$CodexHome = (Resolve-Path -LiteralPath $CodexHome).Path
|
|
236
|
-
if (-not $DesktopExe -or $PackageContext) {
|
|
237
|
-
$package = Get-DesktopPackage
|
|
238
|
-
if (-not $package) { throw 'Codex Desktop package not found; supply -DesktopExe with its actual executable.' }
|
|
239
|
-
[xml]$manifest = Get-Content -LiteralPath (Join-Path $package.InstallLocation 'AppxManifest.xml') -Raw
|
|
240
|
-
$application = $manifest.SelectSingleNode("/*[local-name()='Package']/*[local-name()='Applications']/*[local-name()='Application'][@Id='App']")
|
|
241
|
-
if (-not $application -or -not $application.Executable) {
|
|
242
|
-
throw 'Cannot identify the main Desktop application in its manifest; supply -DesktopExe explicitly.'
|
|
243
|
-
}
|
|
244
|
-
$manifestExecutable = Join-Path $package.InstallLocation $application.Executable
|
|
245
|
-
if ($DesktopExe -and (Resolve-Path -LiteralPath $DesktopExe).Path -ine (Resolve-Path -LiteralPath $manifestExecutable).Path) {
|
|
246
|
-
throw 'PackageContext accepts only the installed package manifest main executable.'
|
|
247
|
-
}
|
|
248
|
-
$DesktopExe = $manifestExecutable
|
|
249
|
-
}
|
|
250
|
-
$DesktopExe = (Resolve-Path -LiteralPath $DesktopExe).Path
|
|
251
|
-
$desktopDirectory = Split-Path -Parent $DesktopExe
|
|
252
|
-
$bundledCore = Join-Path $desktopDirectory 'resources\codex.exe'
|
|
253
|
-
$coreSource = 'explicit override'
|
|
254
|
-
if (-not $CodexBin) {
|
|
255
|
-
if (-not (Test-Path -LiteralPath $bundledCore -PathType Leaf)) {
|
|
256
|
-
throw 'The Desktop Core was not found beside the GUI; supply -CodexBin with the matching Core executable.'
|
|
257
|
-
}
|
|
258
|
-
$bundledInfo = Get-Item -LiteralPath $bundledCore
|
|
259
|
-
$bundledHash = (Get-FileHash -LiteralPath $bundledCore -Algorithm SHA256).Hash
|
|
260
|
-
$cacheRoot = Join-Path $env:LOCALAPPDATA 'OpenAI\Codex\bin'
|
|
261
|
-
# Packaged resources may deny direct execution. Accept a per-user cache
|
|
262
|
-
# copy only after hashing it against this Desktop's bundle; no PATH fallback.
|
|
263
|
-
if (Test-Path -LiteralPath $cacheRoot -PathType Container) {
|
|
264
|
-
$directories = Get-ChildItem -LiteralPath $cacheRoot -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 64
|
|
265
|
-
foreach ($directory in $directories) {
|
|
266
|
-
$candidate = Join-Path $directory.FullName 'codex.exe'
|
|
267
|
-
if (-not (Test-Path -LiteralPath $candidate -PathType Leaf)) { continue }
|
|
268
|
-
$candidateInfo = Get-Item -LiteralPath $candidate
|
|
269
|
-
if ($candidateInfo.Length -ne $bundledInfo.Length) { continue }
|
|
270
|
-
if ((Get-FileHash -LiteralPath $candidate -Algorithm SHA256).Hash -eq $bundledHash) {
|
|
271
|
-
$CodexBin = $candidate
|
|
272
|
-
$coreSource = 'Desktop cache copy with matching bundle SHA256'
|
|
273
|
-
break
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (-not $CodexBin) {
|
|
278
|
-
$CodexBin = $bundledCore
|
|
279
|
-
$coreSource = 'Desktop bundled Core'
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
$CodexBin = Resolve-Executable $CodexBin
|
|
283
|
-
if ([IO.Path]::GetExtension($CodexBin) -ine '.exe') {
|
|
284
|
-
throw 'The Desktop wrapper requires the actual Core .exe; supply -CodexBin with the Desktop Core instead of a command shim.'
|
|
285
|
-
}
|
|
286
|
-
try {
|
|
287
|
-
$coreVersion = ((& $CodexBin --version 2>&1) | Out-String).Trim()
|
|
288
|
-
if ($LASTEXITCODE -ne 0 -or $coreVersion -notmatch '^codex-cli \S+$') { throw 'Unexpected Core version response.' }
|
|
289
|
-
} catch {
|
|
290
|
-
throw 'The selected Core cannot be executed. Supply -CodexBin with a runnable Core matching this Desktop version; global CLI fallback is intentionally disabled.'
|
|
291
|
-
}
|
|
292
|
-
if (-not $CoreWrapper) {
|
|
293
|
-
$CoreWrapper = Join-Path (Split-Path -Parent $Python) 'reins-desktop-core.exe'
|
|
294
|
-
}
|
|
295
|
-
if (-not (Test-Path -LiteralPath $CoreWrapper -PathType Leaf)) {
|
|
296
|
-
throw 'The reins-desktop-core.exe wrapper is not installed beside the selected Python. Install the current Reins package or supply -CoreWrapper explicitly.'
|
|
297
|
-
}
|
|
298
|
-
$CoreWrapper = (Resolve-Path -LiteralPath $CoreWrapper).Path
|
|
299
|
-
if ([IO.Path]::GetExtension($CoreWrapper) -ine '.exe' -or $CoreWrapper -ieq $CodexBin) {
|
|
300
|
-
throw 'The Core wrapper must be a separate Windows executable.'
|
|
301
|
-
}
|
|
302
|
-
$wrapperVersion = Get-WrapperVersion
|
|
303
|
-
if ($BridgeFile) {
|
|
304
|
-
$bridgeRoot = [IO.Path]::GetPathRoot($BridgeFile)
|
|
305
|
-
# IsPathRooted alone accepts drive-relative C:foo and current-drive \foo.
|
|
306
|
-
if (-not $bridgeRoot -or $bridgeRoot -match '^[\\/]{1}$' -or $bridgeRoot -match '^[A-Za-z]:$') {
|
|
307
|
-
throw 'BridgeFile must be an absolute metadata path.'
|
|
308
|
-
}
|
|
309
|
-
$metadata = [IO.Path]::GetFullPath($BridgeFile)
|
|
310
|
-
} else {
|
|
311
|
-
$metadata = Join-Path $CodexHome 'harness-reins\desktop-bridge.json'
|
|
312
|
-
}
|
|
313
|
-
$settings = @{
|
|
314
|
-
CODEX_HOME = $CodexHome
|
|
315
|
-
CODEX_CLI_PATH = $CoreWrapper
|
|
316
|
-
CODEX_APP_SERVER_FORCE_CLI = '1'
|
|
317
|
-
CODEX_APP_SERVER_WS_URL = $null
|
|
318
|
-
REINS_DESKTOP_REAL_CODEX = $CodexBin
|
|
319
|
-
REINS_DESKTOP_BRIDGE_FILE = $metadata
|
|
320
|
-
REINS_DESKTOP_APP_SERVER = '1'
|
|
321
|
-
}
|
|
322
|
-
$guiPaths = @($DesktopExe, (Join-Path $desktopDirectory 'ChatGPT.exe'), (Join-Path $desktopDirectory 'Codex.exe'))
|
|
323
|
-
$guiNames = @('ChatGPT', 'Codex', [IO.Path]::GetFileNameWithoutExtension($DesktopExe)) | Select-Object -Unique
|
|
324
|
-
$existing = @()
|
|
325
|
-
$uninspectable = @()
|
|
326
|
-
foreach ($process in @(Get-Process -Name $guiNames -ErrorAction SilentlyContinue)) {
|
|
327
|
-
$processPath = $null
|
|
328
|
-
try { $processPath = $process.Path } catch { }
|
|
329
|
-
if (-not $processPath) {
|
|
330
|
-
$uninspectable += $process.Id
|
|
331
|
-
} elseif ($guiPaths -contains $processPath) {
|
|
332
|
-
$existing += $process.Id
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if ($CheckOnly) {
|
|
336
|
-
$packageResult = $null
|
|
337
|
-
if ($PackageContext) {
|
|
338
|
-
$packageResult = Invoke-PackageDesktop $true
|
|
339
|
-
$launchProbe = $packageResult.native_launch_probe
|
|
340
|
-
} else {
|
|
341
|
-
$launchProbe = Get-DesktopLaunchProbe
|
|
342
|
-
}
|
|
343
|
-
$blockers = @()
|
|
344
|
-
if (-not $launchProbe.can_create_suspended) { $blockers += "Native GUI creation failed: Win32 error $($launchProbe.native_error_code)." }
|
|
345
|
-
if ($existing.Count -gt 0) { $blockers += 'Desktop is already running.' }
|
|
346
|
-
if ($uninspectable.Count -gt 0) { $blockers += 'A matching Desktop process could not be inspected.' }
|
|
347
|
-
if (Test-Path -LiteralPath $metadata) {
|
|
348
|
-
try {
|
|
349
|
-
if ((Get-BridgeStatus).running) { $blockers += 'A live bridge already exists.' }
|
|
350
|
-
} catch {
|
|
351
|
-
$blockers += "Existing bridge state could not be inspected: $($_.Exception.Message)"
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
[pscustomobject]@{
|
|
355
|
-
check_only = $true
|
|
356
|
-
preflight_passed = ($blockers.Count -eq 0)
|
|
357
|
-
native_creation_passed = $launchProbe.can_create_suspended
|
|
358
|
-
launch_blockers = $blockers
|
|
359
|
-
launch_mode = $(if ($PackageContext) { 'experimental package diagnostic context' } else { 'direct native creation' })
|
|
360
|
-
verified_package_identity = $(if ($null -ne $packageResult) { $packageResult.package_full_name } else { $null })
|
|
361
|
-
python = $Python
|
|
362
|
-
codex_home = $CodexHome
|
|
363
|
-
desktop_executable = $DesktopExe
|
|
364
|
-
core_executable = $CodexBin
|
|
365
|
-
core_source = $coreSource
|
|
366
|
-
core_version = $coreVersion
|
|
367
|
-
core_wrapper = $CoreWrapper
|
|
368
|
-
wrapper_core_version = $wrapperVersion
|
|
369
|
-
bridge_metadata = $metadata
|
|
370
|
-
child_environment = $settings
|
|
371
|
-
desktop_running = ($existing.Count -gt 0)
|
|
372
|
-
desktop_process_ids = $existing
|
|
373
|
-
uninspectable_process_ids = $uninspectable
|
|
374
|
-
native_launch_probe = $launchProbe
|
|
375
|
-
launch_validation = 'Only suspended native process creation was tested. GUI execution, wrapper inheritance, App Tools and original-session ACK remain unverified.'
|
|
376
|
-
} | ConvertTo-Json -Depth 3
|
|
377
|
-
if ($blockers.Count -gt 0) { exit 1 }
|
|
378
|
-
return
|
|
379
|
-
}
|
|
380
|
-
if ($existing.Count -gt 0 -or $uninspectable.Count -gt 0) {
|
|
381
|
-
throw 'Codex Desktop is running, or a matching process could not be inspected. Save work and close Desktop before switching its App Server connection. No process was stopped.'
|
|
382
|
-
}
|
|
383
|
-
if (Test-Path -LiteralPath $metadata) {
|
|
384
|
-
$status = Get-BridgeStatus
|
|
385
|
-
if ($status.running -eq $true) { throw 'A bridge already exists. Inspect it and use its documented connection, or stop it after its clients close.' }
|
|
386
|
-
}
|
|
387
|
-
if ($PackageContext) {
|
|
388
|
-
Write-Output 'Using the experimental Windows package diagnostic context. It is not guaranteed equivalent to normal app activation.'
|
|
389
|
-
$packageResult = Invoke-PackageDesktop $false
|
|
390
|
-
if (-not $packageResult.native_launch_probe.can_create_suspended -or -not $packageResult.desktop_pid) {
|
|
391
|
-
throw 'Package helper did not confirm native creation and a Desktop launch request.'
|
|
392
|
-
}
|
|
393
|
-
$deadline = [DateTime]::UtcNow.AddSeconds(20)
|
|
394
|
-
$bridgeReady = $false
|
|
395
|
-
do {
|
|
396
|
-
if (Test-Path -LiteralPath $metadata -PathType Leaf) {
|
|
397
|
-
try {
|
|
398
|
-
$bridgeStatus = Get-BridgeStatus
|
|
399
|
-
$bridgeReady = ($bridgeStatus.running -eq $true -and
|
|
400
|
-
$bridgeStatus.codex_home -ieq $CodexHome -and
|
|
401
|
-
$bridgeStatus.active_clients -ge 1)
|
|
402
|
-
} catch { $bridgeReady = $false }
|
|
403
|
-
}
|
|
404
|
-
if ($bridgeReady) { break }
|
|
405
|
-
Start-Sleep -Milliseconds 250
|
|
406
|
-
} while ([DateTime]::UtcNow -lt $deadline)
|
|
407
|
-
if (-not $bridgeReady) {
|
|
408
|
-
throw "Desktop launch was requested (PID $($packageResult.desktop_pid)), but a live bridge was not observed. Do not assume callback support or retry blindly. Inspect $metadata and Desktop's startup logs; no existing process was stopped."
|
|
409
|
-
}
|
|
410
|
-
Write-Output "A live bridge with a connected client was observed for this Codex profile: $metadata"
|
|
411
|
-
Write-Output 'Validate App Tools and original-session delivery/ACK before relying on this experimental startup path.'
|
|
412
|
-
return
|
|
413
|
-
}
|
|
414
|
-
$launchProbe = Get-DesktopLaunchProbe
|
|
415
|
-
if (-not $launchProbe.can_create_suspended) {
|
|
416
|
-
throw "Desktop native launch is unavailable (Win32 error $($launchProbe.native_error_code): $($launchProbe.native_error_message)). Executable: $DesktopExe. This launcher cannot yet start this packaged Desktop with its bridge environment. Repeating a restart or using an elevated shell is not a verified fix. No existing Desktop process was stopped and no server was started."
|
|
417
|
-
}
|
|
418
|
-
# Desktop creates the wrapper itself and supplies fresh App Tools IPC settings
|
|
419
|
-
# and exact Core arguments. Never prestart an external server with stale IPC.
|
|
420
|
-
$launchInfo = New-Object System.Diagnostics.ProcessStartInfo
|
|
421
|
-
$launchInfo.FileName = $DesktopExe
|
|
422
|
-
$launchInfo.WorkingDirectory = $desktopDirectory
|
|
423
|
-
$launchInfo.UseShellExecute = $false
|
|
424
|
-
foreach ($key in $settings.Keys) {
|
|
425
|
-
if ($null -eq $settings[$key]) {
|
|
426
|
-
$launchInfo.EnvironmentVariables.Remove($key)
|
|
427
|
-
} else {
|
|
428
|
-
$launchInfo.EnvironmentVariables[$key] = $settings[$key]
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
try {
|
|
432
|
-
# UseShellExecute=false passes this child-only environment directly. Do not
|
|
433
|
-
# substitute ShellAppsFolder activation: override inheritance is unverified.
|
|
434
|
-
$desktopProcess = [System.Diagnostics.Process]::Start($launchInfo)
|
|
435
|
-
if (-not $desktopProcess) { throw 'Desktop process creation returned no process.' }
|
|
436
|
-
$desktopProcess.Dispose()
|
|
437
|
-
} catch {
|
|
438
|
-
$launchError = $_.Exception
|
|
439
|
-
while ($launchError.InnerException) { $launchError = $launchError.InnerException }
|
|
440
|
-
$errorCode = if ($launchError -is [System.ComponentModel.Win32Exception]) {
|
|
441
|
-
"Win32 error $($launchError.NativeErrorCode)"
|
|
442
|
-
} else {
|
|
443
|
-
$launchError.GetType().FullName
|
|
444
|
-
}
|
|
445
|
-
throw "Desktop launch failed ($errorCode): $($launchError.Message). Executable: $DesktopExe. No server was prestarted and no existing Desktop process was stopped."
|
|
446
|
-
}
|
|
447
|
-
Write-Output 'Desktop launch was requested with its experimental Core wrapper. Open the original conversation and validate tools and callback delivery before relying on it.'
|
|
448
|
-
Write-Output "For Reins setup in another terminal, set REINS_DESKTOP_BRIDGE_FILE to: $metadata"
|
|
449
|
-
Write-Output 'Desktop owns the wrapper and its App Server. Closing Desktop closes its stdio connection and the wrapper-managed bridge.'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pip
|