@bitkyc08/opencodex 2.100.3 → 2.100.4
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/AGENTS_INSTALL.md +23 -1
- package/bin/ocx.mjs +8 -1
- package/gui/dist/assets/{App-Dnb6VMsP.js → App-DcpyI78f.js} +20 -19
- package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-CzjPJprT.js} +1 -1
- package/gui/dist/assets/brand-mark-BTIi7e69.js +1 -0
- package/gui/dist/assets/index-DJxM-imn.css +2 -0
- package/gui/dist/assets/index-DVgU6S3y.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bn6Y-g3R.js} +1 -1
- package/gui/dist/classic/assets/{App-DA-scMPq.js → App-eYJAyNHM.js} +19 -18
- package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-xHMYxLkV.js} +1 -1
- package/gui/dist/classic/assets/index-DSaVRW4F.js +138 -0
- package/gui/dist/classic/assets/quota-summary-DyzHlkFl.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/src/cli.rs +5 -3
- package/native/ocx-child/src/codex_home.rs +1 -0
- package/package.json +2 -2
- package/src/adapters/anthropic/per-message-effort.ts +296 -0
- package/src/adapters/anthropic.ts +3 -0
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/devin/cloud-direct/chat.ts +71 -14
- package/src/adapters/google-errors.ts +14 -2
- package/src/adapters/qoder/adapter.ts +9 -1
- package/src/adapters/zed.ts +4 -2
- package/src/claude/desktop-remote-store.ts +60 -10
- package/src/cli/account-api.ts +4 -0
- package/src/cli/account-auth.ts +30 -2
- package/src/cli/account-extended.ts +33 -2
- package/src/cli/capabilities-access-remote.ts +3 -3
- package/src/cli/capabilities-accounts.ts +3 -3
- package/src/cli/capabilities-base.ts +11 -6
- package/src/cli/capabilities-observe-system.ts +2 -2
- package/src/cli/claude.ts +3 -3
- package/src/cli/disconnect-runtime.ts +16 -6
- package/src/cli/dispatch.ts +7 -1
- package/src/cli/index.ts +2 -2
- package/src/cli/link-apply-restart.ts +4 -2
- package/src/cli/link-routes.ts +4 -1
- package/src/cli/link.ts +5 -4
- package/src/cli/preflight-exemptions.ts +3 -0
- package/src/cli/registry.ts +5 -2
- package/src/cli/resolve.ts +23 -8
- package/src/cli/restart-failure.ts +11 -1
- package/src/cli/runtime-api.ts +4 -0
- package/src/cli/status.ts +4 -1
- package/src/cli/system-command.ts +1 -1
- package/src/cli/system-restart-client.ts +9 -3
- package/src/cli/system-settings-parity.ts +2 -1
- package/src/client/connect.ts +63 -9
- package/src/client/desktop-refusal.ts +38 -0
- package/src/client/lifecycle-lock.ts +29 -4
- package/src/client/runtime-restart.ts +27 -15
- package/src/client/runtime.ts +4 -2
- package/src/client/state.ts +14 -0
- package/src/codex/account-pause.ts +4 -0
- package/src/codex/account-runtime-state.ts +4 -0
- package/src/codex/auth-api/main-account-probe.ts +3 -1
- package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
- package/src/codex/auth-context.ts +40 -2
- package/src/codex/catalog/build-entries.ts +10 -0
- package/src/codex/catalog/derive-entry.ts +7 -0
- package/src/codex/catalog/reserve-warn.ts +7 -5
- package/src/codex/catalog/reserve.ts +4 -3
- package/src/codex/catalog/retained-sync.ts +2 -0
- package/src/codex/catalog/routed-defaults.ts +35 -0
- package/src/codex/convergence.ts +2 -0
- package/src/codex/loopback-target.ts +22 -8
- package/src/codex/main-account.ts +88 -29
- package/src/codex/native-main-auth-file.ts +14 -0
- package/src/codex/native-main-credentials.ts +270 -0
- package/src/codex/native-main-owner.ts +3 -0
- package/src/codex/native-main-refresh-mode.ts +14 -1
- package/src/codex/quota.ts +63 -14
- package/src/combos/failover.ts +12 -1
- package/src/combos/index.ts +5 -0
- package/src/combos/resolve.ts +115 -19
- package/src/config/diagnostics.ts +3 -0
- package/src/config/live-reconcile.ts +6 -3
- package/src/config/load-degrade.ts +2 -0
- package/src/config/persisted-mutation.ts +2 -2
- package/src/config/persisted-projections.ts +18 -0
- package/src/config/process-state.ts +4 -3
- package/src/config/reserve-capability.ts +96 -0
- package/src/config/schema/config-schema.ts +6 -0
- package/src/config/schema/leaf-validators.ts +2 -0
- package/src/config/schema/routed-catalog-defaults.ts +49 -0
- package/src/config.ts +7 -7
- package/src/desktop-update/acquire.ts +202 -0
- package/src/desktop-update/cli.ts +168 -0
- package/src/desktop-update/drain.ts +40 -0
- package/src/desktop-update/headless.ts +285 -0
- package/src/desktop-update/image.ts +85 -0
- package/src/desktop-update/install.ts +53 -0
- package/src/desktop-update/msi.ts +72 -0
- package/src/desktop-update/release.ts +128 -0
- package/src/desktop-update/runtime.ts +155 -0
- package/src/desktop-update/staging.ts +118 -0
- package/src/desktop-update/trust.ts +45 -0
- package/src/generated/compatibility-version.json +246 -130
- package/src/images/fulfill-video.ts +3 -3
- package/src/images/loop.ts +6 -2
- package/src/images/plan.ts +147 -11
- package/src/images/types.ts +13 -4
- package/src/images/xai-video-client.ts +72 -10
- package/src/lib/gcp-adc.ts +48 -4
- package/src/lib/offline-resend.ts +150 -0
- package/src/lib/paced-stream.ts +3 -3
- package/src/lib/provider-outbound.ts +17 -6
- package/src/lib/request-failure-model.ts +2 -0
- package/src/lib/response-body-inactivity.ts +23 -1
- package/src/lib/upstream-retry.ts +38 -5
- package/src/link/explicit-route.ts +4 -4
- package/src/link/remote-windows.ts +79 -31
- package/src/link/residual-recovery.ts +20 -8
- package/src/messaging/budget.ts +23 -5
- package/src/messaging/rpc.ts +4 -4
- package/src/oauth/antigravity-risk.ts +126 -0
- package/src/oauth/generic-account-failover.ts +89 -18
- package/src/oauth/generic-session-affinity.ts +10 -3
- package/src/oauth/login-cli.ts +35 -1
- package/src/oauth/pool-kernel.ts +3 -3
- package/src/providers/anthropic-billing-refusal.ts +27 -3
- package/src/providers/google-vertex-model-discovery.ts +6 -1
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/quota/workbuddy.ts +6 -2
- package/src/providers/workbuddy-credit-balance.ts +125 -16
- package/src/responses/effort-history.ts +732 -0
- package/src/routing/history/integrity.ts +41 -4
- package/src/server/auth-cors.ts +13 -3
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/direct-local-http.ts +26 -3
- package/src/server/index/link-listener.ts +20 -14
- package/src/server/index/serve-options.ts +1 -0
- package/src/server/index.ts +3 -2
- package/src/server/link-turn.ts +17 -5
- package/src/server/management/config-routes.ts +39 -3
- package/src/server/management/link-child-preflight.ts +1 -1
- package/src/server/management/link-route-edit.ts +20 -1
- package/src/server/management/oauth-account-routes.ts +22 -5
- package/src/server/management/provider-overwrite-carry.ts +3 -0
- package/src/server/management/provider-routes.ts +4 -4
- package/src/server/management/static-catalog-probe.ts +33 -0
- package/src/server/proxy-liveness.ts +54 -9
- package/src/server/relay.ts +6 -1
- package/src/server/request-log-conversation.ts +2 -2
- package/src/server/request-log.ts +5 -1
- package/src/server/reserve-capability-startup.ts +32 -0
- package/src/server/responses/adapter-delivery.ts +2 -0
- package/src/server/responses/adapter-dispatch.ts +31 -10
- package/src/server/responses/antigravity-fault-rotation.ts +24 -0
- package/src/server/responses/antigravity-validation-refusal.ts +43 -6
- package/src/server/responses/combo-selection-keepalive.ts +254 -0
- package/src/server/responses/core-combo.ts +24 -9
- package/src/server/responses/core-errors.ts +9 -6
- package/src/server/responses/core-options.ts +8 -0
- package/src/server/responses/core.ts +21 -0
- package/src/server/responses/estimated-usage.ts +115 -0
- package/src/server/responses/jev-model-invoke.ts +7 -2
- package/src/server/responses/passthrough-completion.ts +6 -3
- package/src/server/responses/passthrough-delivery.ts +47 -8
- package/src/server/responses/passthrough-dispatch.ts +3 -0
- package/src/server/responses/request-prepare.ts +9 -5
- package/src/server/responses/sidecar-execution.ts +5 -0
- package/src/service/desktop-supervision.d.mts +2 -0
- package/src/service/desktop-supervision.mjs +5 -0
- package/src/stall-timeout.ts +11 -0
- package/src/types/config.ts +15 -92
- package/src/types/provider.ts +13 -0
- package/src/types/request.ts +19 -0
- package/src/types/routed-catalog-defaults.ts +17 -0
- package/src/types/routing-profile.ts +90 -0
- package/src/types.ts +1 -0
- package/src/update/index.ts +1 -1
- package/src/usage/log.ts +14 -4
- package/src/usage/telemetry-contract.ts +1 -0
- package/src/web-search/passthrough-bridge.ts +7 -0
- package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
- package/gui/dist/assets/index-DCdXsMyZ.js +0 -105
- package/gui/dist/assets/index-DQtCRNAw.css +0 -2
- package/gui/dist/classic/assets/index-BqOaGLf5.js +0 -105
- package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
|
@@ -28,20 +28,44 @@ export function powershellArgv(script: string): string[] {
|
|
|
28
28
|
export const WINDOWS_CONTAINMENT_EXIT = 126;
|
|
29
29
|
|
|
30
30
|
const SCRIPT_PACKED_PREFIX = "$ocxPacked='";
|
|
31
|
+
/** First code point of the packed alphabet: 14 bits per character land in U+3400..U+73FF. */
|
|
32
|
+
const PACK_BASE = 0x3400;
|
|
33
|
+
|
|
31
34
|
/**
|
|
32
35
|
* The whole script travels deflated and is inflated on the Child before anything in it exists,
|
|
33
|
-
* including Fail.
|
|
36
|
+
* including Fail. The deflated bytes ride 14 bits per character in U+3400..U+73FF (#8359): every one
|
|
37
|
+
* is plain text inside a single-quoted PowerShell literal (no ASCII, no U+2018..U+201B smart quotes,
|
|
38
|
+
* no surrogates), and the denser alphabet leaves room under cmd.exe's command line for the
|
|
39
|
+
* served-runtime census in the gated scripts. The byte count rides along so padding bits never
|
|
40
|
+
* become a byte. A session that cannot inflate it (Constrained Language Mode blocks the stream
|
|
34
41
|
* types) must still exit 126, so only the inflate is guarded: Invoke-Expression stays outside the
|
|
35
42
|
* try, and the inflated script's own errors and exit status are never relabelled as containment.
|
|
36
43
|
*/
|
|
37
44
|
export function packedPowerShellArgv(script: string): string[] {
|
|
38
45
|
const bytes = deflateRawSync(Buffer.from(script, "utf8"), { level: 9 });
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
let packed = "", bits = 0, pending = 0;
|
|
47
|
+
for (const byte of bytes) {
|
|
48
|
+
pending = (pending << 8) | byte;
|
|
49
|
+
bits += 8;
|
|
50
|
+
while (bits >= 14) { bits -= 14; packed += String.fromCharCode(PACK_BASE + ((pending >> bits) & 0x3fff)); }
|
|
51
|
+
pending &= (1 << bits) - 1;
|
|
52
|
+
}
|
|
53
|
+
if (bits > 0) packed += String.fromCharCode(PACK_BASE + ((pending << (14 - bits)) & 0x3fff));
|
|
54
|
+
return powershellArgv(`${SCRIPT_PACKED_PREFIX}${packed}'\n` + String.raw`$ErrorActionPreference='Stop';try{$m=[IO.MemoryStream]::new();$a=0;$n=0;foreach($c in $ocxPacked.ToCharArray()){$a=($a -shl 14)-bor([int]$c-13312);$n+=14;while($n -ge 8){$n-=8;$m.WriteByte(($a -shr $n)-band 255)};$a=$a-band((1 -shl $n)-1)};$m.SetLength(` + bytes.length + String.raw`);$m.Position=0;$r=[IO.StreamReader]::new([IO.Compression.DeflateStream]::new($m,[IO.Compression.CompressionMode]::Decompress));$s=$r.ReadToEnd()}catch{try{[Console]::Error.WriteLine('Refusing to run ocx.exe outside a kill-on-close job.')}catch{$null=$_};exit ${WINDOWS_CONTAINMENT_EXIT}};Invoke-Expression $s`);
|
|
41
55
|
}
|
|
42
56
|
function unpackPowerShell(script: string): string {
|
|
43
57
|
const match = /\$ocxPacked='([^']+)'/.exec(script);
|
|
44
|
-
|
|
58
|
+
const length = /\$m\.SetLength\((\d+)\)/.exec(script);
|
|
59
|
+
if (!match || !length) return script;
|
|
60
|
+
const bytes: number[] = [];
|
|
61
|
+
let pending = 0, bits = 0;
|
|
62
|
+
for (const ch of match[1]!) {
|
|
63
|
+
pending = (pending << 14) | (ch.charCodeAt(0) - PACK_BASE);
|
|
64
|
+
bits += 14;
|
|
65
|
+
while (bits >= 8) { bits -= 8; bytes.push((pending >> bits) & 0xff); }
|
|
66
|
+
pending &= (1 << bits) - 1;
|
|
67
|
+
}
|
|
68
|
+
return inflateRawSync(Buffer.from(bytes.slice(0, Number(length[1])))).toString("utf8");
|
|
45
69
|
}
|
|
46
70
|
|
|
47
71
|
/**
|
|
@@ -54,13 +78,15 @@ function unpackPowerShell(script: string): string {
|
|
|
54
78
|
* host's. One finally block releases the attribute list, its value buffer and the thread, process
|
|
55
79
|
* and Job handles on every path, and terminates the child through its own handle if anything
|
|
56
80
|
* fails after creation. If Add-Type or any step fails, the host exits 126; there is no
|
|
57
|
-
* uncontained fallback.
|
|
81
|
+
* uncontained fallback. V is the bounded --version probe (ten seconds, at most 256 characters of
|
|
82
|
+
* stdout, exit 0) and Ok is V succeeding; both take an already CRT-quoted argument prefix, empty
|
|
83
|
+
* for a binary and the entry of a served [bun.exe, entry] pair (#8359). Layouts are x64:
|
|
58
84
|
* STARTUPINFOEXW is 112 bytes with the attribute list at byte 104, and LimitFlags sits at byte 16
|
|
59
85
|
* of the 144-byte JOBOBJECT_EXTENDED_LIMIT_INFORMATION. Warnings fail Add-Type in Windows
|
|
60
86
|
* PowerShell, so this source must compile without any.
|
|
61
87
|
*/
|
|
62
88
|
export const OCX_JOB_SOURCE = [
|
|
63
|
-
"using System;using System.Text;using System.Diagnostics;using System.Runtime.InteropServices;",
|
|
89
|
+
"using System;using System.Text;using System.Diagnostics;using System.Runtime.InteropServices;using System.Threading.Tasks;",
|
|
64
90
|
"public static class OcxJob{",
|
|
65
91
|
"[DllImport(\"kernel32\")]static extern IntPtr CreateJobObjectW(IntPtr a,IntPtr n);",
|
|
66
92
|
"[DllImport(\"kernel32\")]static extern bool SetInformationJobObject(IntPtr j,int c,byte[] i,int l);",
|
|
@@ -73,15 +99,12 @@ export const OCX_JOB_SOURCE = [
|
|
|
73
99
|
"[DllImport(\"kernel32\")]static extern bool TerminateProcess(IntPtr p,int c);",
|
|
74
100
|
"[DllImport(\"kernel32\")]static extern bool CloseHandle(IntPtr h);",
|
|
75
101
|
"static void F(bool k){if(!k)throw new Exception();}",
|
|
76
|
-
"public static bool Ok(string x){
|
|
77
|
-
"
|
|
78
|
-
"q.
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"var p=q;var read=System.Threading.Tasks.Task.Run(()=>{var b=new char[257];int n=0,k;while(n<257&&(k=p.StandardOutput.Read(b,n,257-n))>0)n+=k;return n>256?null:new string(b,0,n);});",
|
|
83
|
-
"System.Threading.Tasks.Task.Run(()=>{var b=new char[1024];while(p.StandardError.Read(b,0,b.Length)>0){} });",
|
|
84
|
-
"var clock=Stopwatch.StartNew();var done=System.Threading.Tasks.Task.Run(()=>p.WaitForExit());if(!read.Wait(10000)||read.Result==null||!done.Wait(Math.Max(0,10000-(int)clock.ElapsedMilliseconds))){q.Kill();q.WaitForExit();return null;}return q.ExitCode==0?read.Result:null;",
|
|
102
|
+
"public static bool Ok(string x,string a){return V(x,a)!=null;}",
|
|
103
|
+
"public static string V(string x,string a){Process q=null;try{",
|
|
104
|
+
"q=Process.Start(new ProcessStartInfo(x,a+\"--version\"){UseShellExecute=false,RedirectStandardInput=true,RedirectStandardOutput=true,RedirectStandardError=true});q.StandardInput.Close();",
|
|
105
|
+
"var p=q;var read=Task.Run(()=>{var b=new char[257];int n=0,k;while(n<257&&(k=p.StandardOutput.Read(b,n,257-n))>0)n+=k;return n>256?null:new string(b,0,n);});",
|
|
106
|
+
"Task.Run(()=>{var b=new char[1024];while(p.StandardError.Read(b,0,b.Length)>0){} });",
|
|
107
|
+
"var clock=Stopwatch.StartNew();var done=Task.Run(()=>p.WaitForExit());if(!read.Wait(10000)||read.Result==null||!done.Wait(Math.Max(0,10000-(int)clock.ElapsedMilliseconds))){q.Kill();q.WaitForExit();return null;}return q.ExitCode==0?read.Result:null;",
|
|
85
108
|
"}catch{try{if(q!=null&&!q.HasExited){q.Kill();q.WaitForExit();}}catch{return null;}return null;}finally{if(q!=null)q.Dispose();}}",
|
|
86
109
|
"public static int Run(string x,string c){",
|
|
87
110
|
"IntPtr z=IntPtr.Zero,j=z,l=z,v=z,h=z,t=z;bool listed=false,done=false;",
|
|
@@ -112,6 +135,11 @@ function Quote-Native([string]$v){'"'+[regex]::Replace([regex]::Replace($v,'(\\*
|
|
|
112
135
|
function Invoke-Native([string]$e,[string[]]$a){try{$c=[OcxJob]::Run($e,((@($e)+$a|%{Quote-Native $_}) -join ' '))}catch{Fail};exit $c}
|
|
113
136
|
`;
|
|
114
137
|
|
|
138
|
+
/** A script from this module with its packed payload inflated; any other text comes back unchanged. For tests. */
|
|
139
|
+
export function windowsInflatedScript(script: string): string {
|
|
140
|
+
return unpackPowerShell(script);
|
|
141
|
+
}
|
|
142
|
+
|
|
115
143
|
/** The packed helper a script carries, inflated; for tests that check the transport. */
|
|
116
144
|
export function windowsScriptHelperSource(script: string): string | undefined {
|
|
117
145
|
script = unpackPowerShell(script);
|
|
@@ -161,19 +189,39 @@ $f+=@((Get-Command ocx.exe -Type Application -EA 0).Source)
|
|
|
161
189
|
$k=@("$u\.local\bin\ocx-child.exe","$u\.cache\opencodex\bin\ocx-child.exe");if($env:LOCALAPPDATA){$k+="$env:LOCALAPPDATA\opencodex\bin\ocx-child.exe"};$k+=@((Get-Command ocx-child.exe -Type Application -EA 0).Source)
|
|
162
190
|
$r=if($env:HOME){$env:HOME}elseif($u){$u}else{"."};$h=if($env:OPENCODEX_HOME){$env:OPENCODEX_HOME}else{"$r\.opencodex"};$c=if([IO.File]::Exists("$h\child\state.json")){$k+$f}else{$f+$k}
|
|
163
191
|
`;
|
|
192
|
+
/**
|
|
193
|
+
* The install that last started serving this home (#8359), read from the first record's `command`
|
|
194
|
+
* in `serving-runtimes.json` (src/config/serving-runtimes.ts): `[ocx.exe]`, or `[bun.exe, cli\index.ts]`
|
|
195
|
+
* for an npm install. It moves ahead of every fixed candidate except ocx-child under a Child state,
|
|
196
|
+
* the POSIX order. Its variables ($sx, $sy) are names no other script fragment assigns: the gate loops
|
|
197
|
+
* reuse $a, $s and $p (#8359 review). `A` yields its entry as an argument prefix for the run and `P` the same prefix
|
|
198
|
+
* CRT-quoted for the helper's --version probe; any other candidate gets none. The pair runs only
|
|
199
|
+
* while its entry exists. A census over 64 KiB, a first record without a command, a relative or
|
|
200
|
+
* quoted path, a third element or any read error leaves the fixed order. The census sits where its
|
|
201
|
+
* writer's `getConfigDir()` puts it: a trimmed `OPENCODEX_HOME` (a leading ~ is the profile), else
|
|
202
|
+
* `%USERPROFILE%\.opencodex`, which is what `homedir()` answers on Windows; a Child state in that
|
|
203
|
+
* directory or the legacy `$h` one keeps ocx-child first. Discovery and runtime
|
|
204
|
+
* inspection, the pinned and overwrite syncs and the gated update plan all read it, so every Windows
|
|
205
|
+
* Remote Link command runs the same install the Child serves from.
|
|
206
|
+
*/
|
|
207
|
+
const SERVED_CANDIDATE = String.raw`$sx=$null;$sy=@();try{$o=([string]$env:OPENCODEX_HOME).Trim();if($o -match '^~([\\/]|$)'){$o=$u+$o.Substring(1)};$g=$(if($o){$o}else{"$u\.opencodex"});$j="$g\serving-runtimes.json";if((Get-Item -LiteralPath $j -Force -EA 1).Length -le 65536){$e=@(@(([IO.File]::ReadAllText($j)|ConvertFrom-Json).runtimes)[0].command);if($e.Count -in 1,2 -and !($e|?{$_ -isnot [string] -or $_ -match '["\x00-\x1f]' -or ![IO.Path]::IsPathRooted($_)})-and($e.Count -eq 1 -or [IO.File]::Exists($e[1]))){$sx=$e[0];$sy=@($e|select -Skip 1);$c=if([IO.File]::Exists("$g\child\state.json")-or[IO.File]::Exists("$h\child\state.json")){$k+$sx+$f}else{@($sx)+$f+$k}}}}catch{$null=$_}
|
|
208
|
+
function A($x){if($x -eq $sx){$sy}}
|
|
209
|
+
function P($x){(@(A $x)|%{(Quote-Native $_)+' '}) -join ''}
|
|
210
|
+
`;
|
|
211
|
+
|
|
164
212
|
export function windowsOcxArgv(args: readonly string[]): string[] {
|
|
165
213
|
const sweep = args.includes("--purge") ? String.raw`foreach($r in @($env:LOCALAPPDATA,$env:USERPROFILE)){if($r){foreach($s in @("$r\opencodex\bin","$r\.cache\opencodex\bin")){if([IO.Directory]::Exists($s)){Get-ChildItem -LiteralPath $s -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}}}}}};` : "";
|
|
166
|
-
const run = sweep ? `try{$c=[OcxJob]::Run($x,((@($x)+$d.args|%{Quote-Native $_}) -join ' '))}catch{Fail};${sweep}exit $c` : `Invoke-Native $x @($d.args)`;
|
|
167
|
-
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args }) + OCX_CANDIDATES + String.raw`
|
|
168
|
-
foreach($x in ($c|select -Unique)){if([IO.File]::Exists($x)-and[OcxJob]::Ok($x)){` + run + String.raw`}}
|
|
214
|
+
const run = sweep ? `try{$c=[OcxJob]::Run($x,((@($x)+@(A $x)+$d.args|%{Quote-Native $_}) -join ' '))}catch{Fail};${sweep}exit $c` : `Invoke-Native $x (@(A $x)+@($d.args))`;
|
|
215
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args }) + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`
|
|
216
|
+
foreach($x in ($c|select -Unique)){if([IO.File]::Exists($x)-and[OcxJob]::Ok($x,(P $x))){` + run + String.raw`}}
|
|
169
217
|
[Console]::Error.WriteLine('No runnable ocx.exe found; install the Windows standalone archive.');exit 127
|
|
170
218
|
`);
|
|
171
219
|
}
|
|
172
220
|
|
|
173
221
|
export function windowsInspectRuntimeArgv(): string[] {
|
|
174
|
-
return packedPowerShellArgv(NATIVE_PROCESS + OCX_CANDIDATES + String.raw`
|
|
222
|
+
return packedPowerShellArgv(NATIVE_PROCESS + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`
|
|
175
223
|
[Console]::Out.WriteLine('ocx-inspect:arch:'+[string]$env:PROCESSOR_ARCHITECTURE)
|
|
176
|
-
foreach($x in ($c|select -Unique)){if(![IO.File]::Exists($x)){continue};$v=[OcxJob]::V($x);if($null -ne $v){$k=if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){'ephemeral'}else{'full'};[Console]::Out.WriteLine('ocx-inspect:kind:'+$k);[Console]::Out.WriteLine('ocx-inspect:version:'+$v.Trim());exit 0}}
|
|
224
|
+
foreach($x in ($c|select -Unique)){if(![IO.File]::Exists($x)){continue};$v=[OcxJob]::V($x,(P $x));if($null -ne $v){$k=if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){'ephemeral'}else{'full'};[Console]::Out.WriteLine('ocx-inspect:kind:'+$k);[Console]::Out.WriteLine('ocx-inspect:version:'+$v.Trim());exit 0}}
|
|
177
225
|
[Console]::Out.WriteLine('ocx-inspect:kind:missing');exit 0
|
|
178
226
|
`);
|
|
179
227
|
}
|
|
@@ -203,7 +251,7 @@ export function windowsPurgePlantedChildArgv(): string[] {
|
|
|
203
251
|
return packedPowerShellArgv(NATIVE_PROCESS + WINDOWS_MANAGED_BIN + String.raw`
|
|
204
252
|
$r=if($env:HOME){$env:HOME}elseif($env:USERPROFILE){$env:USERPROFILE}else{"."};$h=if($env:OPENCODEX_HOME){$env:OPENCODEX_HOME}else{"$r\.opencodex"};$cd="$h\child";$cx=if($env:CODEX_HOME){$env:CODEX_HOME}else{"$r\.codex"}
|
|
205
253
|
$rec=@(@("$cd\state.json","$cd\codex-journal.json","$cd\attach-rollback.json","$cx\.ocx-child-owner.json")|?{[IO.File]::Exists($_)-or[IO.Directory]::Exists($_)});$pend=$rec.Count -gt 0;if($pend){$m='ocx-child recovery record remains at '+$rec[0]+'; keeping the planted binary for detach.'}
|
|
206
|
-
try{$dir=Resolve-PlantDir;$dst="$dir\ocx-child.exe";if([IO.File]::Exists($dst)){if([OcxJob]::Ok($dst)){$rc=[OcxJob]::Run($dst,('"'+$dst+'" detach --purge'));if($rc -ne 0){exit $rc};if([IO.File]::Exists($dst)){[Console]::Error.WriteLine('ocx-child kept the planted binary: another ocx-child relay runs from it.')}}elseif($pend){[Console]::Error.WriteLine($m);exit 1}else{try{[IO.File]::Delete($dst)}catch{$null=$_}}}elseif($pend){[Console]::Error.WriteLine($m);exit 1};Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}}}catch{exit 1};exit 0
|
|
254
|
+
try{$dir=Resolve-PlantDir;$dst="$dir\ocx-child.exe";if([IO.File]::Exists($dst)){if([OcxJob]::Ok($dst,'')){$rc=[OcxJob]::Run($dst,('"'+$dst+'" detach --purge'));if($rc -ne 0){exit $rc};if([IO.File]::Exists($dst)){[Console]::Error.WriteLine('ocx-child kept the planted binary: another ocx-child relay runs from it.')}}elseif($pend){[Console]::Error.WriteLine($m);exit 1}else{try{[IO.File]::Delete($dst)}catch{$null=$_}}}elseif($pend){[Console]::Error.WriteLine($m);exit 1};Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}}}catch{exit 1};exit 0
|
|
207
255
|
`);
|
|
208
256
|
}
|
|
209
257
|
|
|
@@ -228,7 +276,7 @@ export function windowsManagedPurgeDisconnectArgv(expectLink?: string): string[]
|
|
|
228
276
|
if (expectLink !== undefined && !/^lnk_[0-9a-f]{16}$/.test(expectLink)) throw new Error("invalid link id");
|
|
229
277
|
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: expectLink === undefined ? [] : [expectLink] }) + WINDOWS_MANAGED_BIN + String.raw`
|
|
230
278
|
try{$dir=Resolve-PlantDir}catch{[Console]::Error.WriteLine('Refusing a reparse point in the managed ocx-child directory.');exit 1}
|
|
231
|
-
$dst="$dir\ocx-child.exe";if(-not([IO.File]::Exists($dst)-and[OcxJob]::Ok($dst))){[Console]::Error.WriteLine('${MANAGED_PURGE_CHILD_MISSING_MARKER}');exit 1}
|
|
279
|
+
$dst="$dir\ocx-child.exe";if(-not([IO.File]::Exists($dst)-and[OcxJob]::Ok($dst,''))){[Console]::Error.WriteLine('${MANAGED_PURGE_CHILD_MISSING_MARKER}');exit 1}
|
|
232
280
|
$x=@($d.args);$e=if($x.Count -gt 0){' --expect-link '+(Quote-Native ([string]$x[0]))}else{''}
|
|
233
281
|
try{$rc=[OcxJob]::Run($dst,('"'+$dst+'" disconnect --purge --json'+$e))}catch{exit 1}
|
|
234
282
|
Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}};exit $rc
|
|
@@ -247,9 +295,9 @@ export interface WindowsGatedCommand {
|
|
|
247
295
|
/**
|
|
248
296
|
* The gated Windows command: select a candidate, refuse below the minimum, optionally refuse ocx-child, then run it
|
|
249
297
|
* contained. OCX_NO_DESKTOP_HANDOFF=1 makes a launcher answer --version and run the command itself. Windows never
|
|
250
|
-
* sends a restart, so the selected-kind report is not built here.
|
|
251
|
-
*
|
|
252
|
-
*
|
|
298
|
+
* sends a restart, so the selected-kind report is not built here. The served install comes first (#8359), and a served
|
|
299
|
+
* [bun.exe, entry] pair passes its entry as an argument prefix. The script still prints no entry marker and the Home
|
|
300
|
+
* infers "binary": Windows never applies an update, so nothing reads the pair/binary distinction there.
|
|
253
301
|
*/
|
|
254
302
|
export function windowsGatedOcxArgv(cmd: WindowsGatedCommand): string[] {
|
|
255
303
|
if (!cmd.versionParts.every(part => /^(0|[1-9][0-9]{0,3})$/.test(part))) throw new Error("invalid gate version");
|
|
@@ -259,16 +307,16 @@ export function windowsGatedOcxArgv(cmd: WindowsGatedCommand): string[] {
|
|
|
259
307
|
const overwriteEphemeral = cmd.lacksMarker === "child-ocx-lacks-overwrite" ? String.raw`if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){[Console]::Error.WriteLine('ocx-fanout:child-ephemeral-no-overwrite');exit 121};` : "";
|
|
260
308
|
const ephemeral = cmd.acceptEphemeral || overwriteEphemeral ? "" : String.raw`if($x -match '(^|[\\/])ocx-child[^\\/]*$'){[Console]::Error.WriteLine('ocx-fanout:child-ocx-ephemeral');exit 121};`;
|
|
261
309
|
const clock = cmd.reportClock ? String.raw`[Console]::Error.WriteLine('ocx-fanout:child-now:'+[DateTimeOffset]::Now.ToUnixTimeMilliseconds());` : "";
|
|
262
|
-
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: cmd.args }) + OCX_CANDIDATES + String.raw`$env:OCX_NO_DESKTOP_HANDOFF='1'
|
|
310
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: cmd.args }) + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`$env:OCX_NO_DESKTOP_HANDOFF='1'
|
|
263
311
|
foreach($x in ($c|select -Unique)){
|
|
264
|
-
if(![IO.File]::Exists($x)){continue};` + overwriteEphemeral + String.raw`$v=[OcxJob]::V($x);if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
312
|
+
if(![IO.File]::Exists($x)){continue};` + overwriteEphemeral + String.raw`$v=[OcxJob]::V($x,(P $x));if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
265
313
|
$m=[regex]::Match($v,'^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$')
|
|
266
314
|
$bad=(!$m.Success -or $v.Length -gt 128);if(!$bad -and $m.Groups[4].Success){foreach($p in $m.Groups[4].Value.Split('.')){if(!$p -or ($p -match '^\d+$' -and $p.Length -gt 1 -and $p[0] -eq '0')){$bad=$true}}}
|
|
267
315
|
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
268
316
|
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + b + String.raw`);$cmp=0
|
|
269
317
|
for($i=0;$i -lt 3;$i++){if($a[$i].Length -ne $b[$i].Length){$cmp=$a[$i].Length-$b[$i].Length;break};$cmp=[string]::CompareOrdinal($a[$i],$b[$i]);if($cmp -ne 0){break}}
|
|
270
318
|
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('ocx-fanout:` + cmd.lacksMarker + String.raw`');exit 121}
|
|
271
|
-
` + ephemeral + String.raw`[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);` + clock + String.raw`[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x @($d.args)
|
|
319
|
+
` + ephemeral + String.raw`[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);` + clock + String.raw`[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x (@(A $x)+@($d.args))
|
|
272
320
|
};exit 127
|
|
273
321
|
`);
|
|
274
322
|
}
|
|
@@ -284,16 +332,16 @@ export function windowsOverwriteSyncArgv(linkId: string, overwriteConflict = fal
|
|
|
284
332
|
const minimum = overwriteConflict ? ROUTE_OVERWRITE_MIN_CHILD_VERSION.split(".").map(part => `'${part}'`).join(",") : "'2','93','0'";
|
|
285
333
|
const lacks = overwriteConflict ? "ocx-fanout:child-ocx-lacks-overwrite" : "ocx-fanout:child-ocx-lacks-expect-link";
|
|
286
334
|
const ephemeral = overwriteConflict ? String.raw`if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){[Console]::Error.WriteLine('ocx-fanout:child-ephemeral-no-overwrite');exit 121};` : "";
|
|
287
|
-
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: ["sync", "--expect-link", linkId, "--json", ...(overwriteConflict ? ["--overwrite-conflict"] : []), ...(overwriteClient ? ["--overwrite-client", overwriteClient] : [])] }) + OCX_CANDIDATES + String.raw`$env:OCX_NO_DESKTOP_HANDOFF=1
|
|
335
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: ["sync", "--expect-link", linkId, "--json", ...(overwriteConflict ? ["--overwrite-conflict"] : []), ...(overwriteClient ? ["--overwrite-client", overwriteClient] : [])] }) + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`$env:OCX_NO_DESKTOP_HANDOFF=1
|
|
288
336
|
foreach($x in $c){
|
|
289
|
-
if(![IO.File]::Exists($x)){continue};` + ephemeral + String.raw`$v=[OcxJob]::V($x);if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
337
|
+
if(![IO.File]::Exists($x)){continue};` + ephemeral + String.raw`$v=[OcxJob]::V($x,(P $x));if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
290
338
|
$m=[regex]::Match($v,'^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$')
|
|
291
339
|
$bad=(!$m.Success -or $v.Length -gt 128);if(!$bad -and $m.Groups[4].Success){foreach($p in $m.Groups[4].Value.Split('.')){if(!$p -or ($p -match '^\d+$' -and $p.Length -gt 1 -and $p[0] -eq '0')){$bad=$true}}}
|
|
292
340
|
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
293
341
|
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + minimum + String.raw`);$cmp=0
|
|
294
342
|
for($i=0;$i -lt 3;$i++){if($a[$i].Length -ne $b[$i].Length){$cmp=$a[$i].Length-$b[$i].Length;break};$cmp=[string]::CompareOrdinal($a[$i],$b[$i]);if($cmp -ne 0){break}}
|
|
295
343
|
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('` + lacks + String.raw`');exit 121}
|
|
296
|
-
[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x @($d.args)
|
|
344
|
+
[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x (@(A $x)+@($d.args))
|
|
297
345
|
};exit 127
|
|
298
346
|
`);
|
|
299
347
|
}
|
|
@@ -18,20 +18,32 @@ const OLDER_LIGHTWEIGHT = "An ocx-child older than that flag refuses it before i
|
|
|
18
18
|
const olderFull = (id: string): string => "An OpenCodex older than that flag refuses it before it acts on the link; then run ocx disconnect and ocx restart only if ocx connect status --json shows " + id
|
|
19
19
|
+ ", right after that check (an enrollment that lands between the two commands would be removed), and otherwise leave the Child as it is.";
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* A purge path that is not found means no planted binary is there: an uncertain journalled plant can stop before it installs
|
|
23
|
+
* one, and a purge removes one only after every recovery record is gone. Either way no ocx-child of this attempt holds the
|
|
24
|
+
* Child, which the bare "not found" of the shell does not say.
|
|
25
|
+
*/
|
|
26
|
+
const PLANT_NOT_FOUND = " If the command is not found there, the binary is not installed (the plant stopped before installing it, or it was purged since), so no ocx-child of this attempt holds the Child: nothing is left to undo on it, and you can retry.";
|
|
27
|
+
|
|
21
28
|
const bound = (id: string): string => "it acts only when the Child's records name this attempt's link (" + id + ") or nothing at all, and leaves a Child that another link, a hub or another Home owns.";
|
|
22
29
|
|
|
23
30
|
/**
|
|
24
31
|
* The lightweight agent's detach by the paths it can have: the managed copy (not necessarily on PATH) for the Child's platform,
|
|
25
|
-
* both Windows locations in Command Prompt, and a copy placed by hand
|
|
32
|
+
* both Windows locations in Command Prompt, and a copy placed by hand: first in ~/.local/bin (%USERPROFILE%\.local\bin on
|
|
33
|
+
* Windows), the place the Home's discovery tries before any other and which need not be on PATH, then through the path
|
|
34
|
+
* command -v (where.exe) prints.
|
|
26
35
|
*/
|
|
27
36
|
function lightweightDetach(id: string, platform: "posix" | "windows" | undefined): { first: string; rest: string; prompt: boolean } {
|
|
28
37
|
const posix = "~/.cache/opencodex/bin/ocx-child detach --expect-link " + id;
|
|
29
38
|
const windows = "\"%LOCALAPPDATA%\\opencodex\\bin\\ocx-child.exe\" detach --expect-link " + id;
|
|
30
39
|
const windowsFallback = "\"%USERPROFILE%\\.cache\\opencodex\\bin\\ocx-child.exe\" detach --expect-link " + id;
|
|
31
|
-
const placed = (lookup: string) => "for a copy placed by hand, the same detach --expect-link " + id + " through
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const placed = (where: string, lookup: string) => "for a copy placed by hand, the same detach --expect-link " + id + " through " + where
|
|
41
|
+
+ ", which need not be on PATH, or through the path " + lookup + " prints";
|
|
42
|
+
const posixPlaced = "~/.local/bin/ocx-child";
|
|
43
|
+
const windowsPlaced = "%USERPROFILE%\\.local\\bin\\ocx-child.exe";
|
|
44
|
+
if (platform === "windows") return { first: windows, rest: " (or " + windowsFallback + " where LOCALAPPDATA is not set; " + placed(windowsPlaced, "where.exe ocx-child") + ")", prompt: true };
|
|
45
|
+
if (platform === "posix") return { first: posix, rest: " (" + placed(posixPlaced, "command -v ocx-child") + ")", prompt: false };
|
|
46
|
+
return { first: posix, rest: " (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set; " + placed(posixPlaced + " (" + windowsPlaced + " on Windows)", "command -v ocx-child, or where.exe ocx-child on Windows,") + ")", prompt: false };
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
export function residualRecovery(kind: ResidualChild, linkId: string | undefined, platform?: "posix" | "windows"): string {
|
|
@@ -42,9 +54,9 @@ export function residualRecovery(kind: ResidualChild, linkId: string | undefined
|
|
|
42
54
|
const posix = "~/.cache/opencodex/bin/ocx-child detach --purge --expect-link " + id;
|
|
43
55
|
const windows = "\"%LOCALAPPDATA%\\opencodex\\bin\\ocx-child.exe\" detach --purge --expect-link " + id;
|
|
44
56
|
const windowsFallback = "\"%USERPROFILE%\\.cache\\opencodex\\bin\\ocx-child.exe\" detach --purge --expect-link " + id;
|
|
45
|
-
if (platform === "windows") return "In Command Prompt on the Child, run " + windows + " (or " + windowsFallback + " where LOCALAPPDATA is not set) before retrying: " + bound(id);
|
|
46
|
-
if (platform === "posix") return "Run " + posix + " on the Child before retrying: " + bound(id);
|
|
47
|
-
return "Run " + posix + " on the Child before retrying (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set): " + bound(id);
|
|
57
|
+
if (platform === "windows") return "In Command Prompt on the Child, run " + windows + " (or " + windowsFallback + " where LOCALAPPDATA is not set) before retrying: " + bound(id) + PLANT_NOT_FOUND;
|
|
58
|
+
if (platform === "posix") return "Run " + posix + " on the Child before retrying: " + bound(id) + PLANT_NOT_FOUND;
|
|
59
|
+
return "Run " + posix + " on the Child before retrying (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set): " + bound(id) + PLANT_NOT_FOUND;
|
|
48
60
|
}
|
|
49
61
|
const light = lightweightDetach(id, platform);
|
|
50
62
|
if (kind === "ephemeral") return (light.prompt ? "In Command Prompt on the Child, run " + light.first + " before retrying" : "Run " + light.first + " on the Child before retrying") + light.rest + ": " + bound(id) + " " + OLDER_LIGHTWEIGHT;
|
package/src/messaging/budget.ts
CHANGED
|
@@ -15,17 +15,21 @@ export class MessageBudget {
|
|
|
15
15
|
}
|
|
16
16
|
this.deadline = performance.now() + timeoutMs;
|
|
17
17
|
this.cancel = () => this.controller.abort(new LocalMessagingError("cancelled", "Messaging operation was cancelled."));
|
|
18
|
-
this.timer = setTimeout(() => this.
|
|
19
|
-
new LocalMessagingError("operation_timeout", "Messaging operation exceeded its deadline.")), timeoutMs);
|
|
18
|
+
this.timer = setTimeout(() => this.expire(), timeoutMs);
|
|
20
19
|
parent?.addEventListener("abort", this.cancel, { once: true });
|
|
21
20
|
if (parent?.aborted) this.cancel();
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
if (!this.signal.aborted
|
|
23
|
+
/** End the operation as timed out unless it already ended for another reason. */
|
|
24
|
+
private expire(): void {
|
|
25
|
+
if (!this.signal.aborted) {
|
|
27
26
|
this.controller.abort(new LocalMessagingError("operation_timeout", "Messaging operation exceeded its deadline."));
|
|
28
27
|
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Reject expired/cancelled work even before the deadline timer receives an event-loop turn. */
|
|
31
|
+
throwIfEnded(): void {
|
|
32
|
+
if (performance.now() >= this.deadline) this.expire();
|
|
29
33
|
if (this.signal.aborted) throw this.signal.reason;
|
|
30
34
|
}
|
|
31
35
|
|
|
@@ -35,6 +39,20 @@ export class MessageBudget {
|
|
|
35
39
|
return Math.max(1, Math.min(limit, Math.ceil(this.deadline - performance.now())));
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Arm one stage timer bounded by the remaining deadline. A timer the deadline capped, or one
|
|
44
|
+
* firing at or after it, ends the operation as operation_timeout (via the signal) instead of
|
|
45
|
+
* calling onStageTimeout, so timer ordering on a loaded event loop cannot relabel the expiry.
|
|
46
|
+
*/
|
|
47
|
+
stageTimer(limit: number, onStageTimeout: () => void): ReturnType<typeof setTimeout> {
|
|
48
|
+
const delay = this.remainingMs(limit);
|
|
49
|
+
const capped = Math.ceil(this.deadline - performance.now()) <= limit;
|
|
50
|
+
return setTimeout(() => {
|
|
51
|
+
if (capped || performance.now() >= this.deadline) this.expire();
|
|
52
|
+
else onStageTimeout();
|
|
53
|
+
}, delay);
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
/** Release timers/listeners and cancel any resources still waiting on this owned budget. */
|
|
39
57
|
dispose(): void {
|
|
40
58
|
clearTimeout(this.timer);
|
package/src/messaging/rpc.ts
CHANGED
|
@@ -53,9 +53,9 @@ export class LocalMessageRpc implements LocalMetadataClient {
|
|
|
53
53
|
socket.onopen = socket.onerror = socket.onclose = null;
|
|
54
54
|
};
|
|
55
55
|
const abort = () => { cleanup(); reject(budget.signal.reason); };
|
|
56
|
-
const timer =
|
|
56
|
+
const timer = budget.stageTimer(rpcTimeoutMs, () => {
|
|
57
57
|
cleanup(); reject(new LocalMessagingError("daemon_unavailable", "Local Codex connection timed out; no daemon was started."));
|
|
58
|
-
}
|
|
58
|
+
});
|
|
59
59
|
budget.signal.addEventListener("abort", abort, { once: true });
|
|
60
60
|
socket.onopen = () => { cleanup(); resolve(); };
|
|
61
61
|
socket.onerror = socket.onclose = () => {
|
|
@@ -208,8 +208,8 @@ export class LocalMessageRpc implements LocalMetadataClient {
|
|
|
208
208
|
if (this.pending.size >= 4) throw new LocalMessagingError("rpc_limit", "Local Codex metadata concurrency limit exceeded.");
|
|
209
209
|
const id = ++this.nextId;
|
|
210
210
|
return new Promise((resolve, reject) => {
|
|
211
|
-
const timer =
|
|
212
|
-
this.
|
|
211
|
+
const timer = this.budget.stageTimer(this.rpcTimeoutMs,
|
|
212
|
+
() => this.close(new LocalMessagingError("rpc_timeout", "Local Codex request timed out.")));
|
|
213
213
|
this.pending.set(id, { resolve, reject, timer, method });
|
|
214
214
|
try { this.socket.send(JSON.stringify({ id, method, params })); onWritten?.(); } catch { this.close(); }
|
|
215
215
|
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Antigravity sign-in can get the Google account disabled.
|
|
3
|
+
*
|
|
4
|
+
* Antigravity's OAuth login is issued for Google's own Antigravity app. Reaching Cloud Code
|
|
5
|
+
* Assist through a third-party proxy with it is the pattern behind the account bans reported
|
|
6
|
+
* against Gemini CLI (google-gemini/gemini-cli #19501, #20813, #27199, #27388), where the
|
|
7
|
+
* account answers every request with {@link ANTIGRAVITY_TOS_BAN_MESSAGE}. The auto-pause policy
|
|
8
|
+
* (`account-auto-pause-policy.ts`) recognises that message once it happens; this module is the
|
|
9
|
+
* other half, making sure nobody reaches it without having been told first.
|
|
10
|
+
*
|
|
11
|
+
* Every way of adding an Antigravity account goes through the management API, except
|
|
12
|
+
* `ocx login`, which runs the flow in-process. The API therefore refuses an Antigravity login
|
|
13
|
+
* or import whose body does not carry {@link ANTIGRAVITY_RISK_ACK_FIELD} set to `true`, and each
|
|
14
|
+
* client sets it only after a person acknowledged the warning: the dashboard through its
|
|
15
|
+
* checkbox, the CLI through a y/N prompt or the explicit {@link ANTIGRAVITY_RISK_CLI_FLAG}.
|
|
16
|
+
* The field is consent evidence from the client, the same weight a dashboard checkbox has; it
|
|
17
|
+
* cannot prove a human read anything, and it is not meant to.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const ANTIGRAVITY_RISK_PROVIDER = "google-antigravity";
|
|
21
|
+
|
|
22
|
+
/** Request-body field that carries the acknowledgement. Only the literal `true` counts. */
|
|
23
|
+
export const ANTIGRAVITY_RISK_ACK_FIELD = "acknowledgeAntigravityRisk";
|
|
24
|
+
|
|
25
|
+
/** CLI flag for non-interactive use. Without it, a CLI that cannot prompt refuses. */
|
|
26
|
+
export const ANTIGRAVITY_RISK_CLI_FLAG = "--accept-antigravity-risk";
|
|
27
|
+
|
|
28
|
+
/** Machine-readable refusal returned by the management API and printed by the CLI. */
|
|
29
|
+
export const ANTIGRAVITY_RISK_REFUSAL_CODE = "antigravity_risk_not_acknowledged";
|
|
30
|
+
|
|
31
|
+
/** The error Cloud Code Assist returns for a disabled account (see account-auto-pause-policy.ts). */
|
|
32
|
+
export const ANTIGRAVITY_TOS_BAN_MESSAGE = "This service has been disabled in this account for violation of Terms of Service.";
|
|
33
|
+
|
|
34
|
+
export function requiresAntigravityRiskAcknowledgement(provider: string): boolean {
|
|
35
|
+
return provider.trim().toLowerCase() === ANTIGRAVITY_RISK_PROVIDER;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function hasAntigravityRiskAcknowledgement(body: unknown): boolean {
|
|
39
|
+
return typeof body === "object" && body !== null
|
|
40
|
+
&& (body as Record<string, unknown>)[ANTIGRAVITY_RISK_ACK_FIELD] === true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The API refusal body, shared by every route that can add an Antigravity account. */
|
|
44
|
+
export function antigravityRiskRefusalBody(): { error: string; code: typeof ANTIGRAVITY_RISK_REFUSAL_CODE } {
|
|
45
|
+
return {
|
|
46
|
+
error: "Google Antigravity sign-in can get Gemini and Antigravity access disabled on the Google account. Acknowledge the risk in the OpenCodex dashboard, or pass "
|
|
47
|
+
+ ANTIGRAVITY_RISK_CLI_FLAG + " to the CLI.",
|
|
48
|
+
code: ANTIGRAVITY_RISK_REFUSAL_CODE,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Terminal warning shown before every CLI Antigravity sign-in or import, flag or not. */
|
|
53
|
+
export const ANTIGRAVITY_RISK_WARNING = [
|
|
54
|
+
"",
|
|
55
|
+
"WARNING: Google may permanently disable Gemini and Antigravity access on the Google account you sign in with.",
|
|
56
|
+
" The Antigravity login is meant for Google's own Antigravity app. OpenCodex is a third-party",
|
|
57
|
+
" proxy, and users of third-party tools have reported that access being disabled with:",
|
|
58
|
+
" \"" + ANTIGRAVITY_TOS_BAN_MESSAGE + "\"",
|
|
59
|
+
" - The ban applies to the Google account: its Gemini Code Assist and Antigravity access can",
|
|
60
|
+
" stop everywhere, including in Google's own tools.",
|
|
61
|
+
" - Getting access back depends on Google's appeal process and is not guaranteed.",
|
|
62
|
+
" - Use only a separate Google account you can afford to lose. Never use your main, personal,",
|
|
63
|
+
" school, or work account.",
|
|
64
|
+
" Safer option: use a Gemini API key (Google AI Studio or Vertex AI) instead.",
|
|
65
|
+
"",
|
|
66
|
+
].join("\n");
|
|
67
|
+
|
|
68
|
+
export const ANTIGRAVITY_RISK_PROMPT = "Continue with Google Antigravity and accept the risk? [y/N]: ";
|
|
69
|
+
|
|
70
|
+
export type AntigravityRiskDecision = "accepted" | "declined" | "noninteractive" | "agent";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Test and platform seams for the CLI gate. Production reads the environment: a coding agent or
|
|
74
|
+
* CI runner is detected by {@link isAgentDriven}, and a prompt counts as visible only when the
|
|
75
|
+
* stream it is written to is a terminal.
|
|
76
|
+
*/
|
|
77
|
+
export interface AntigravityRiskSeams {
|
|
78
|
+
agentDriven?: () => boolean;
|
|
79
|
+
promptVisible?: () => boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The CLI gate. The warning is always shown, even with the flag, so a script's log records what
|
|
84
|
+
* was accepted. Adding an Antigravity account spends the user's Google identity, so the repository
|
|
85
|
+
* rule for such actions applies (AGENTS.md, "User-consent actions"; AGENTS_INSTALL.md): a process
|
|
86
|
+
* driven by a coding agent or CI runner is refused outright, flag or not, because the agent would
|
|
87
|
+
* be the one answering. Otherwise the flag accepts, an interactive terminal may answer, and only
|
|
88
|
+
* an explicit "y" or "yes" accepts: an empty line, EOF, a timeout or a read error all decline.
|
|
89
|
+
*/
|
|
90
|
+
export async function resolveAntigravityRiskAcknowledgement(opts: {
|
|
91
|
+
flag: boolean;
|
|
92
|
+
interactive: boolean;
|
|
93
|
+
agentDriven: boolean;
|
|
94
|
+
warn: (text: string) => void;
|
|
95
|
+
ask: (question: string) => Promise<string>;
|
|
96
|
+
}): Promise<AntigravityRiskDecision> {
|
|
97
|
+
opts.warn(ANTIGRAVITY_RISK_WARNING);
|
|
98
|
+
if (opts.agentDriven) return "agent";
|
|
99
|
+
if (opts.flag) return "accepted";
|
|
100
|
+
if (!opts.interactive) return "noninteractive";
|
|
101
|
+
let answer: string;
|
|
102
|
+
try {
|
|
103
|
+
answer = await opts.ask(ANTIGRAVITY_RISK_PROMPT);
|
|
104
|
+
} catch {
|
|
105
|
+
return "declined";
|
|
106
|
+
}
|
|
107
|
+
const normalized = answer.trim().toLowerCase();
|
|
108
|
+
return normalized === "y" || normalized === "yes" ? "accepted" : "declined";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function antigravityRiskDecisionMessage(decision: Exclude<AntigravityRiskDecision, "accepted">): string {
|
|
112
|
+
switch (decision) {
|
|
113
|
+
case "agent":
|
|
114
|
+
return "Refusing Google Antigravity (" + ANTIGRAVITY_RISK_REFUSAL_CODE + "): this run is driven by a coding agent or CI runner, "
|
|
115
|
+
+ "and only the account owner can accept the risk. Run the command yourself in a terminal, or use the OpenCodex dashboard.";
|
|
116
|
+
case "noninteractive":
|
|
117
|
+
return "Refusing Google Antigravity without acknowledgement (" + ANTIGRAVITY_RISK_REFUSAL_CODE + "): no interactive terminal to confirm. "
|
|
118
|
+
+ "Re-run in a terminal, or pass " + ANTIGRAVITY_RISK_CLI_FLAG + " to accept the risk explicitly.";
|
|
119
|
+
case "declined":
|
|
120
|
+
return "Google Antigravity cancelled: the risk was not accepted. Nothing was changed.";
|
|
121
|
+
default: {
|
|
122
|
+
const exhaustive: never = decision;
|
|
123
|
+
return exhaustive;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|