@bitkyc08/opencodex 2.55.0 → 2.56.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/gui/dist/assets/{index-VuoiWj9J.js → index-D4zuyIxQ.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +2 -1
- package/src/adapters/base.ts +21 -0
- package/src/adapters/cursor/transport-retry.ts +46 -1
- package/src/adapters/cursor.ts +4 -0
- package/src/adapters/kiro/adapter.ts +42 -1
- package/src/adapters/kiro-retry.ts +23 -4
- package/src/adapters/openai-chat/errors.ts +116 -0
- package/src/adapters/openai-chat/messages.ts +346 -0
- package/src/adapters/openai-chat/passthrough.ts +146 -0
- package/src/adapters/openai-chat/response-events.ts +117 -0
- package/src/adapters/openai-chat/tool-call-validation.ts +200 -0
- package/src/adapters/openai-chat/tool-schema.ts +477 -0
- package/src/adapters/openai-chat/wire.ts +50 -0
- package/src/adapters/openai-chat.ts +33 -1445
- package/src/adapters/openai-responses/canonical-forward.ts +202 -0
- package/src/adapters/openai-responses/image-gen.ts +406 -0
- package/src/adapters/openai-responses/internal.ts +3 -0
- package/src/adapters/openai-responses/passthrough.ts +611 -0
- package/src/adapters/openai-responses/prompt-cache.ts +83 -0
- package/src/adapters/openai-responses/reasoning.ts +220 -0
- package/src/adapters/openai-responses/request-strips.ts +185 -0
- package/src/adapters/openai-responses/tool-output-recovery.ts +509 -0
- package/src/adapters/openai-responses/tool-schema.ts +293 -0
- package/src/adapters/openai-responses/web-search.ts +156 -0
- package/src/adapters/openai-responses.ts +4 -2625
- package/src/bridge/errors.ts +34 -0
- package/src/bridge/internal.ts +174 -0
- package/src/bridge/response-json.ts +624 -0
- package/src/bridge/sse.ts +1444 -0
- package/src/bridge.ts +5 -2204
- package/src/chat/inbound.ts +12 -1
- package/src/codex/account-lifecycle.ts +3 -0
- package/src/codex/account-store.ts +71 -9
- package/src/codex/auth-api/account-list.ts +507 -0
- package/src/codex/auth-api/http.ts +32 -0
- package/src/codex/auth-api/login-flow.ts +554 -0
- package/src/codex/auth-api/login-state.ts +64 -0
- package/src/codex/auth-api/main-account-probe.ts +331 -0
- package/src/codex/auth-api/pool-mode-gate.ts +274 -0
- package/src/codex/auth-api/pool-quota-probe.ts +512 -0
- package/src/codex/auth-api/reset-credit-service.ts +422 -0
- package/src/codex/auth-api/routes.ts +425 -0
- package/src/codex/auth-api/runtime-config.ts +48 -0
- package/src/codex/auth-api.ts +27 -3118
- package/src/codex/auth-context.ts +95 -28
- package/src/codex/catalog/auto-review.ts +507 -0
- package/src/codex/catalog/build-entries.ts +981 -0
- package/src/codex/catalog/combo-member.ts +375 -0
- package/src/codex/catalog/derive-entry.ts +229 -0
- package/src/codex/catalog/effort.ts +0 -1
- package/src/codex/catalog/gated-native-warn.ts +63 -0
- package/src/codex/catalog/gather-capture.ts +533 -0
- package/src/codex/catalog/model-hints.ts +691 -0
- package/src/codex/catalog/model-visibility.ts +304 -0
- package/src/codex/catalog/provider-fetch.ts +52 -2942
- package/src/codex/catalog/provider-models.ts +685 -0
- package/src/codex/catalog/restore.ts +132 -0
- package/src/codex/catalog/retained-sync.ts +706 -0
- package/src/codex/catalog/routed-gather.ts +858 -0
- package/src/codex/catalog/subagent-roster.ts +176 -0
- package/src/codex/catalog/sync.ts +52 -2698
- package/src/codex/inject/config-toml.ts +563 -0
- package/src/codex/inject/remove.ts +192 -0
- package/src/codex/inject/restore.ts +540 -0
- package/src/codex/inject/routing-classify.ts +109 -0
- package/src/codex/inject/routing-target.ts +125 -0
- package/src/codex/inject.ts +81 -1436
- package/src/codex/lineage.ts +458 -0
- package/src/codex/pool-refresh-backoff.ts +152 -0
- package/src/codex/routing/active-account.ts +194 -0
- package/src/codex/routing/cooldown-math.ts +275 -0
- package/src/codex/routing/health-store.ts +402 -0
- package/src/codex/routing/probe-lease.ts +358 -0
- package/src/codex/routing/selection.ts +703 -0
- package/src/codex/routing/thread-affinity.ts +538 -0
- package/src/codex/routing.ts +353 -2234
- package/src/codex/shim-fingerprint.ts +223 -0
- package/src/codex/shim-inspect.ts +175 -0
- package/src/codex/shim-probe.ts +367 -0
- package/src/codex/shim-restore-lock.ts +169 -0
- package/src/codex/shim-state-file.ts +151 -0
- package/src/codex/shim-templates.ts +265 -0
- package/src/codex/shim.ts +48 -1268
- package/src/config/diagnostics.ts +705 -0
- package/src/config/feature-flags.ts +55 -0
- package/src/config/live-reconcile.ts +403 -0
- package/src/config/load-degrade.ts +880 -0
- package/src/config/mutation-lock.ts +244 -0
- package/src/config/openai-tier-backup.ts +268 -0
- package/src/config/persist-unlocked.ts +92 -0
- package/src/config/proxy-env.ts +188 -0
- package/src/config/salvage.ts +244 -0
- package/src/config/schema/config-schema.ts +640 -0
- package/src/config/schema/leaf-validators.ts +855 -0
- package/src/config/warn-memo.ts +28 -0
- package/src/config.ts +234 -4481
- package/src/generated/compatibility-version.json +539 -39
- package/src/lib/request-execution-budget.ts +69 -20
- package/src/lib/spend-reservation-ledger.ts +940 -0
- package/src/lib/upstream-retry.ts +55 -11
- package/src/lib/workflow-budget.ts +553 -30
- package/src/providers/quota/account-cache.ts +441 -0
- package/src/providers/quota/antigravity.ts +295 -0
- package/src/providers/quota/report-cache.ts +320 -0
- package/src/providers/quota/vendor-probes-key.ts +1243 -0
- package/src/providers/quota/vendor-probes-oauth.ts +590 -0
- package/src/providers/quota.ts +324 -3079
- package/src/providers/registry/entries-core.ts +1221 -0
- package/src/providers/registry/entries-extended.ts +1204 -0
- package/src/providers/registry/model-seeds.ts +908 -0
- package/src/providers/registry/types.ts +352 -0
- package/src/providers/registry.ts +24 -3536
- package/src/responses/continuation-ownership.ts +29 -0
- package/src/responses/state/replay-fingerprint.ts +80 -0
- package/src/responses/state/snapshot-codec.ts +104 -0
- package/src/responses/state/spill-failure.ts +118 -0
- package/src/responses/state/spill-queue.ts +665 -0
- package/src/responses/state/temp-recovery.ts +257 -0
- package/src/responses/state.ts +82 -1143
- package/src/routing/identity-domains.ts +449 -0
- package/src/routing/probe-lease.ts +511 -0
- package/src/server/index/bounded-request.ts +88 -0
- package/src/server/index/live-sideband.ts +565 -0
- package/src/server/index/serve-options.ts +1766 -0
- package/src/server/index/startup-warnings.ts +213 -0
- package/src/server/index/websocket-handler.ts +335 -0
- package/src/server/index.ts +40 -2547
- package/src/server/management/route-registry.ts +26 -23
- package/src/server/management/shared.ts +8 -5
- package/src/server/management/workflow-budget-routes.ts +133 -0
- package/src/server/management-api.ts +12 -0
- package/src/server/request-log-conversation.ts +9 -7
- package/src/server/request-log.ts +245 -1
- package/src/server/responses/account-change-state.ts +233 -0
- package/src/server/responses/adapter-continuation.ts +514 -0
- package/src/server/responses/adapter-delivery.ts +214 -0
- package/src/server/responses/adapter-dispatch.ts +971 -0
- package/src/server/responses/compact.ts +59 -4
- package/src/server/responses/completion-policy.ts +33 -0
- package/src/server/responses/core-auth.ts +527 -0
- package/src/server/responses/core-codex-account.ts +859 -0
- package/src/server/responses/core-combo-failure.ts +210 -0
- package/src/server/responses/core-combo.ts +707 -0
- package/src/server/responses/core-errors.ts +152 -0
- package/src/server/responses/core-lifetime.ts +95 -0
- package/src/server/responses/core-normalize.ts +350 -0
- package/src/server/responses/core-opaque-recovery.ts +380 -0
- package/src/server/responses/core-options.ts +159 -0
- package/src/server/responses/core-replay.ts +225 -0
- package/src/server/responses/core.ts +192 -8893
- package/src/server/responses/passthrough-delivery.ts +856 -0
- package/src/server/responses/passthrough-dispatch.ts +1476 -0
- package/src/server/responses/passthrough-execution.ts +54 -0
- package/src/server/responses/request-prepare.ts +970 -0
- package/src/server/responses/request-send-budget.ts +164 -0
- package/src/server/responses/request-sidecar-auth.ts +149 -0
- package/src/server/responses/request-transport.ts +744 -0
- package/src/server/responses/response-effects.ts +157 -0
- package/src/server/responses/run-turn-execution.ts +448 -0
- package/src/server/responses/sidecar-execution.ts +469 -0
- package/src/server/responses-image-gen-repair.ts +1 -1
- package/src/server/workflow-refusal.ts +84 -0
- package/src/types/config.ts +30 -0
- package/src/usage/log.ts +146 -0
- package/src/usage/summary.ts +171 -21
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { BUN_RUNTIME_PATH_ENV, BUN_RUNTIME_SOURCE_ENV } from "../lib/bun-runtime";
|
|
2
|
+
import type { BunRuntimeSource } from "../lib/bun-runtime";
|
|
3
|
+
import { serviceApiTokenFilePath } from "../lib/service-secrets";
|
|
4
|
+
import { windowsEnvIndirectBatchValue } from "../lib/win-paths";
|
|
5
|
+
|
|
6
|
+
const SHIM_MARKER = "opencodex codex autostart shim";
|
|
7
|
+
const UNIX_SHIM_REVISION_MARKER = "opencodex unix codex shim revision 2";
|
|
8
|
+
|
|
9
|
+
const CODEX_SHIM_REENTRY_EXIT_CODE = 126;
|
|
10
|
+
const CODEX_SHIM_REENTRY_DIAGNOSTIC = "opencodex: saved Codex launcher resolved back to the autostart shim; run ocx codex-shim uninstall and reinstall Codex before enabling codexAutoStart.";
|
|
11
|
+
|
|
12
|
+
const CODEX_INTERNAL_COMMANDS = [
|
|
13
|
+
"app-server",
|
|
14
|
+
"archive",
|
|
15
|
+
"apply",
|
|
16
|
+
"cloud",
|
|
17
|
+
"completion",
|
|
18
|
+
"debug",
|
|
19
|
+
"delete",
|
|
20
|
+
"doctor",
|
|
21
|
+
"exec-server",
|
|
22
|
+
"features",
|
|
23
|
+
"fork",
|
|
24
|
+
"help",
|
|
25
|
+
"login",
|
|
26
|
+
"logout",
|
|
27
|
+
"mcp",
|
|
28
|
+
"plugin",
|
|
29
|
+
"sandbox",
|
|
30
|
+
"unarchive",
|
|
31
|
+
"update",
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// Codex accepts global options before a subcommand. The shim must skip the value belonging to
|
|
35
|
+
// these options before it decides which first positional token is the real subcommand. Keep this
|
|
36
|
+
// list aligned with `codex --help`; `--option=value` and attached short forms stay one token.
|
|
37
|
+
const CODEX_GLOBAL_OPTIONS_WITH_VALUE = [
|
|
38
|
+
"-c", "--config",
|
|
39
|
+
"--enable", "--disable",
|
|
40
|
+
"--remote", "--remote-auth-token-env",
|
|
41
|
+
"-i", "--image",
|
|
42
|
+
"-m", "--model",
|
|
43
|
+
"--local-provider",
|
|
44
|
+
"-p", "--profile",
|
|
45
|
+
"-s", "--sandbox",
|
|
46
|
+
"-C", "--cd",
|
|
47
|
+
"--add-dir",
|
|
48
|
+
"-a", "--ask-for-approval",
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
function shQuote(value: string): string {
|
|
52
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Provenance is required rather than defaulted: a default would let a caller pass an
|
|
56
|
+
// override binary and silently label it something else, which is precisely the
|
|
57
|
+
// path/marker disagreement this feature exists to prevent.
|
|
58
|
+
//
|
|
59
|
+
// The marker is scoped to the `ensure` invocation in every flavor below and is never
|
|
60
|
+
// exported into the shim's own environment. A shim wraps the real `codex`, so an
|
|
61
|
+
// exported marker would be inherited by Codex and everything it spawns — a shell that
|
|
62
|
+
// then ran a *different* Bun directly would carry a provenance describing a binary it
|
|
63
|
+
// is not executing.
|
|
64
|
+
|
|
65
|
+
export function buildUnixCodexShim(realCodexPath: string, bunPath: string, cliPath: string, bunRuntimeSource: BunRuntimeSource, tokenFile = serviceApiTokenFilePath()): string {
|
|
66
|
+
const internalCommands = CODEX_INTERNAL_COMMANDS.join("|");
|
|
67
|
+
const valueOptions = CODEX_GLOBAL_OPTIONS_WITH_VALUE.join("|");
|
|
68
|
+
return `#!/usr/bin/env sh
|
|
69
|
+
# ${SHIM_MARKER}
|
|
70
|
+
# ${UNIX_SHIM_REVISION_MARKER}
|
|
71
|
+
if [ "\${OCX_SHIM_PROBE:-}" = "1" ]; then
|
|
72
|
+
if [ "\${OCX_SHIM_PROBE_ACTIVE:-}" = "1" ]; then
|
|
73
|
+
if [ -n "\${OCX_SHIM_PROBE_REENTRY_PATH:-}" ]; then
|
|
74
|
+
(umask 077; printf '%s\n' recursive > "$OCX_SHIM_PROBE_REENTRY_PATH") 2>/dev/null || true
|
|
75
|
+
fi
|
|
76
|
+
printf '%s\n' ${shQuote(CODEX_SHIM_REENTRY_DIAGNOSTIC)} >&2
|
|
77
|
+
exit ${CODEX_SHIM_REENTRY_EXIT_CODE}
|
|
78
|
+
fi
|
|
79
|
+
OCX_SHIM_PROBE_ACTIVE=1
|
|
80
|
+
export OCX_SHIM_PROBE_ACTIVE
|
|
81
|
+
fi
|
|
82
|
+
if [ "\${OCX_SHIM_ACTIVE_PID:-}" = "$$" ]; then
|
|
83
|
+
printf '%s\n' ${shQuote(CODEX_SHIM_REENTRY_DIAGNOSTIC)} >&2
|
|
84
|
+
exit ${CODEX_SHIM_REENTRY_EXIT_CODE}
|
|
85
|
+
fi
|
|
86
|
+
case "\${OCX_SHIM_ACTIVE_DEPTH:-0}" in
|
|
87
|
+
0)
|
|
88
|
+
OCX_SHIM_ACTIVE_DEPTH=1
|
|
89
|
+
;;
|
|
90
|
+
1)
|
|
91
|
+
OCX_SHIM_ACTIVE_DEPTH=2
|
|
92
|
+
;;
|
|
93
|
+
*)
|
|
94
|
+
printf '%s\n' ${shQuote(CODEX_SHIM_REENTRY_DIAGNOSTIC)} >&2
|
|
95
|
+
exit ${CODEX_SHIM_REENTRY_EXIT_CODE}
|
|
96
|
+
;;
|
|
97
|
+
esac
|
|
98
|
+
# Dynamic launchers such as mise exec -- codex may resolve the command name
|
|
99
|
+
# back to this wrapper. An exec chain keeps the same PID. A legitimate nested
|
|
100
|
+
# Codex invocation may enter once with a new PID; repeated child-process
|
|
101
|
+
# redispatch reaches depth 2 and is rejected before it can form an infinite chain.
|
|
102
|
+
OCX_SHIM_ACTIVE_PID=$$
|
|
103
|
+
export OCX_SHIM_ACTIVE_PID OCX_SHIM_ACTIVE_DEPTH
|
|
104
|
+
if [ -z "$OPENCODEX_API_AUTH_TOKEN" ] && [ -f ${shQuote(tokenFile)} ]; then
|
|
105
|
+
OPENCODEX_API_AUTH_TOKEN="$(cat ${shQuote(tokenFile)})"
|
|
106
|
+
export OPENCODEX_API_AUTH_TOKEN
|
|
107
|
+
fi
|
|
108
|
+
ocx_subcommand=""
|
|
109
|
+
ocx_skip_next=0
|
|
110
|
+
for ocx_arg in "$@"; do
|
|
111
|
+
if [ "$ocx_skip_next" -eq 1 ]; then
|
|
112
|
+
ocx_skip_next=0
|
|
113
|
+
continue
|
|
114
|
+
fi
|
|
115
|
+
case "$ocx_arg" in
|
|
116
|
+
--)
|
|
117
|
+
break
|
|
118
|
+
;;
|
|
119
|
+
${valueOptions})
|
|
120
|
+
ocx_skip_next=1
|
|
121
|
+
;;
|
|
122
|
+
--help|-h|--version|-V)
|
|
123
|
+
ocx_subcommand="$ocx_arg"
|
|
124
|
+
break
|
|
125
|
+
;;
|
|
126
|
+
-*)
|
|
127
|
+
;;
|
|
128
|
+
*)
|
|
129
|
+
ocx_subcommand="$ocx_arg"
|
|
130
|
+
break
|
|
131
|
+
;;
|
|
132
|
+
esac
|
|
133
|
+
done
|
|
134
|
+
case "$ocx_subcommand" in
|
|
135
|
+
${internalCommands}|--help|-h|--version|-V)
|
|
136
|
+
;;
|
|
137
|
+
*)
|
|
138
|
+
if [ -z "$OCX_SHIM_BYPASS" ]; then
|
|
139
|
+
${BUN_RUNTIME_SOURCE_ENV}=${shQuote(bunRuntimeSource)} ${BUN_RUNTIME_PATH_ENV}=${shQuote(bunPath)} ${shQuote(bunPath)} ${shQuote(cliPath)} ensure >/dev/null 2>&1 || true
|
|
140
|
+
fi
|
|
141
|
+
;;
|
|
142
|
+
esac
|
|
143
|
+
exec ${shQuote(realCodexPath)} "$@"
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function windowsBatchValue(value: string): string {
|
|
148
|
+
return value
|
|
149
|
+
.replace(/%/g, "%%")
|
|
150
|
+
.replace(/\^/g, "^^")
|
|
151
|
+
.replace(/"/g, "")
|
|
152
|
+
.replace(/[\r\n]/g, "");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function windowsBatchSet(name: string, value: string): string {
|
|
156
|
+
// Paths are rewritten to %USERPROFILE%-style env indirection: cmd.exe parses .cmd
|
|
157
|
+
// files in the OEM codepage, so a literal non-ASCII profile prefix (Korean/Chinese
|
|
158
|
+
// usernames) written as UTF-8 turns to mojibake. The env token expands natively in
|
|
159
|
+
// the right codepage at parse time; no `chcp` here — this shim runs in the USER's
|
|
160
|
+
// console and must not leak a codepage change into it.
|
|
161
|
+
return `set "${name}=${windowsEnvIndirectBatchValue(value, windowsBatchValue)}"`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function buildWindowsCodexShim(realCodexPath: string, bunPath: string, cliPath: string, bunRuntimeSource: BunRuntimeSource): string {
|
|
165
|
+
const internalCommandChecks = CODEX_INTERNAL_COMMANDS.map(command => `if /I "%~1"=="${command}" goto run_codex`).join("\r\n");
|
|
166
|
+
const valueOptionChecks = CODEX_GLOBAL_OPTIONS_WITH_VALUE.map(option => `if /I "%~1"=="${option}" goto skip_option_value`).join("\r\n");
|
|
167
|
+
return `@echo off\r
|
|
168
|
+
rem ${SHIM_MARKER}\r
|
|
169
|
+
setlocal\r
|
|
170
|
+
${windowsBatchSet("OCX_REAL_CODEX", realCodexPath)}\r
|
|
171
|
+
${windowsBatchSet("OCX_BUN", bunPath)}\r
|
|
172
|
+
${windowsBatchSet("OCX_CLI", cliPath)}\r
|
|
173
|
+
${windowsBatchSet("OCX_API_TOKEN_FILE", serviceApiTokenFilePath())}\r
|
|
174
|
+
if "%OPENCODEX_API_AUTH_TOKEN%"=="" if exist "%OCX_API_TOKEN_FILE%" set /p OPENCODEX_API_AUTH_TOKEN=<"%OCX_API_TOKEN_FILE%"\r
|
|
175
|
+
if not "%OCX_SHIM_BYPASS%"=="" goto run_codex\r
|
|
176
|
+
goto scan_codex_args\r
|
|
177
|
+
:scan_codex_args\r
|
|
178
|
+
if "%~1"=="" goto ensure_ocx\r
|
|
179
|
+
if "%~1"=="--" goto ensure_ocx\r
|
|
180
|
+
${valueOptionChecks}\r
|
|
181
|
+
${internalCommandChecks}\r
|
|
182
|
+
if /I "%~1"=="--help" goto run_codex\r
|
|
183
|
+
if /I "%~1"=="-h" goto run_codex\r
|
|
184
|
+
if /I "%~1"=="--version" goto run_codex\r
|
|
185
|
+
if /I "%~1"=="-V" goto run_codex\r
|
|
186
|
+
set "OCX_SCAN_ARG=%~1"\r
|
|
187
|
+
if "%OCX_SCAN_ARG:~0,1%"=="-" goto shift_codex_arg\r
|
|
188
|
+
goto ensure_ocx\r
|
|
189
|
+
:skip_option_value\r
|
|
190
|
+
shift\r
|
|
191
|
+
if "%~1"=="" goto ensure_ocx\r
|
|
192
|
+
:shift_codex_arg\r
|
|
193
|
+
shift\r
|
|
194
|
+
goto scan_codex_args\r
|
|
195
|
+
:ensure_ocx\r
|
|
196
|
+
setlocal\r
|
|
197
|
+
${windowsBatchSet(BUN_RUNTIME_SOURCE_ENV, bunRuntimeSource)}\r
|
|
198
|
+
${windowsBatchSet(BUN_RUNTIME_PATH_ENV, bunPath)}\r
|
|
199
|
+
"%OCX_BUN%" "%OCX_CLI%" ensure >nul 2>nul\r
|
|
200
|
+
endlocal\r
|
|
201
|
+
:run_codex\r
|
|
202
|
+
"%OCX_REAL_CODEX%" %*\r
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function psString(value: string): string {
|
|
207
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function buildWindowsPowerShellCodexShim(realCodexPath: string, bunPath: string, cliPath: string, bunRuntimeSource: BunRuntimeSource): string {
|
|
211
|
+
const internalCommands = CODEX_INTERNAL_COMMANDS.map(command => psString(command)).join(", ");
|
|
212
|
+
const valueOptions = CODEX_GLOBAL_OPTIONS_WITH_VALUE.map(option => psString(option)).join(", ");
|
|
213
|
+
const tokenFile = serviceApiTokenFilePath();
|
|
214
|
+
return `#!/usr/bin/env pwsh
|
|
215
|
+
# ${SHIM_MARKER}
|
|
216
|
+
$hadApiAuthToken = Test-Path Env:\\OPENCODEX_API_AUTH_TOKEN
|
|
217
|
+
$priorApiAuthToken = $env:OPENCODEX_API_AUTH_TOKEN
|
|
218
|
+
try {
|
|
219
|
+
if (-not $env:OPENCODEX_API_AUTH_TOKEN -and (Test-Path -LiteralPath ${psString(tokenFile)})) {
|
|
220
|
+
$env:OPENCODEX_API_AUTH_TOKEN = (Get-Content -Raw -LiteralPath ${psString(tokenFile)}).Trim()
|
|
221
|
+
}
|
|
222
|
+
$internalCommands = @(${internalCommands})
|
|
223
|
+
$valueOptions = @(${valueOptions})
|
|
224
|
+
$subcommand = ""
|
|
225
|
+
$skipNext = $false
|
|
226
|
+
foreach ($argValue in $args) {
|
|
227
|
+
$argText = [string]$argValue
|
|
228
|
+
if ($skipNext) { $skipNext = $false; continue }
|
|
229
|
+
if ($argText -eq "--") { break }
|
|
230
|
+
if ($valueOptions -contains $argText) { $skipNext = $true; continue }
|
|
231
|
+
if (@("--help", "-h", "--version", "-V") -contains $argText) { $subcommand = $argText; break }
|
|
232
|
+
if ($argText.StartsWith("-")) { continue }
|
|
233
|
+
$subcommand = $argText
|
|
234
|
+
break
|
|
235
|
+
}
|
|
236
|
+
$skipEnsure = $env:OCX_SHIM_BYPASS -or $internalCommands -contains $subcommand -or @("--help", "-h", "--version", "-V") -contains $subcommand
|
|
237
|
+
if (-not $skipEnsure) {
|
|
238
|
+
$priorRuntimeSource = $env:${BUN_RUNTIME_SOURCE_ENV}
|
|
239
|
+
$priorRuntimePath = $env:${BUN_RUNTIME_PATH_ENV}
|
|
240
|
+
$env:${BUN_RUNTIME_SOURCE_ENV} = ${psString(bunRuntimeSource)}
|
|
241
|
+
$env:${BUN_RUNTIME_PATH_ENV} = ${psString(bunPath)}
|
|
242
|
+
try { & ${psString(bunPath)} ${psString(cliPath)} ensure *> $null }
|
|
243
|
+
finally {
|
|
244
|
+
if ($null -eq $priorRuntimeSource) { Remove-Item Env:\\${BUN_RUNTIME_SOURCE_ENV} -ErrorAction SilentlyContinue }
|
|
245
|
+
else { $env:${BUN_RUNTIME_SOURCE_ENV} = $priorRuntimeSource }
|
|
246
|
+
if ($null -eq $priorRuntimePath) { Remove-Item Env:\\${BUN_RUNTIME_PATH_ENV} -ErrorAction SilentlyContinue }
|
|
247
|
+
else { $env:${BUN_RUNTIME_PATH_ENV} = $priorRuntimePath }
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
& ${psString(realCodexPath)} @args
|
|
251
|
+
$codexExitCode = $LASTEXITCODE
|
|
252
|
+
} finally {
|
|
253
|
+
if ($hadApiAuthToken) { $env:OPENCODEX_API_AUTH_TOKEN = $priorApiAuthToken }
|
|
254
|
+
else { Remove-Item Env:\\OPENCODEX_API_AUTH_TOKEN -ErrorAction SilentlyContinue }
|
|
255
|
+
}
|
|
256
|
+
exit $codexExitCode
|
|
257
|
+
`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Git-Bash accepts `C:/...` but not backslashed paths inside sh scripts. */
|
|
261
|
+
function gitBashPath(path: string): string {
|
|
262
|
+
return path.replace(/\\/g, "/");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export { SHIM_MARKER, UNIX_SHIM_REVISION_MARKER, CODEX_SHIM_REENTRY_EXIT_CODE, CODEX_SHIM_REENTRY_DIAGNOSTIC, shQuote, windowsBatchSet, psString, gitBashPath };
|