codex-copilot-dx 1.3.14 → 1.3.16
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/README.md +1 -1
- package/bin/cli.mjs +7 -7
- package/bin/codex-image-host.mjs +11 -0
- package/docs/ARCHITECTURE.md +4 -2
- package/docs/REFERENCE.md +9 -4
- package/package.json +1 -1
- package/src/claude-capability-config.mjs +3 -2
- package/src/claude-models.mjs +3 -1
- package/src/cli-image.mjs +1 -1
- package/src/client-integration.mjs +4 -0
- package/src/clients/claude-models.mjs +3 -3
- package/src/codex-image-host-launch.mjs +38 -0
- package/src/codex-image-host.mjs +218 -0
- package/src/launcher.mjs +14 -4
- package/src/model-capabilities.mjs +9 -0
- package/src/prediction-control.mjs +1 -0
- package/src/startup-ui.mjs +6 -0
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Use `ccdx help` or `ccdx <command> --help` for options. The CLI uses English; th
|
|
|
63
63
|
Use the Web UI for accounts, APIs, models, client access, input suggestions, native images, local masking, appearance, diagnostics and updates. CLI commands remain available for automation and recovery. See the [control reference](docs/REFERENCE.md#webui-and-cli-controls).
|
|
64
64
|
|
|
65
65
|
- **Input suggestions:** new integrations attempt setup by default when Codex is closed. Saved off choices are retained. The Web UI can enable, disable, finish setup, open Codex and repair the bridge. Setup synchronizes Show predictions, adds App-profile trust and locally decrypts the prediction hosts' HTTPS traffic. App/thread eligibility still applies. [Details](docs/REFERENCE.md#optional-native-predictions).
|
|
66
|
-
- **Images:** Codex
|
|
66
|
+
- **Images:** Codex native host tools use the selected GitHub image model, with GPT Image 2.5 Flare as the default. Images start enabled; saved off choices are retained. On macOS with Codex 0.166+, fully quit a running App that lacks the host, start Codex through CCDX, and use a new chat. ChatGPT sign-in and Apps are retained. The Web UI provides model selection without an extra API key, MCP or CCDX image skill. [Details](docs/REFERENCE.md#native-image-generation).
|
|
67
67
|
- **Updates:** Settings → Install update downloads and verifies a stable release, then switches the installed service when idle. Busy work postpones the switch. Unmanaged launches require the installer or an installed command. [Details](docs/REFERENCE.md#installation-and-updates).
|
|
68
68
|
|
|
69
69
|
Web UI activity updates through server push; the terminal uses the same in-process activity feed. Reconnecting restores current state and bounded recent records.
|
package/bin/cli.mjs
CHANGED
|
@@ -282,7 +282,7 @@ const { createProfileModelRuntime } = await import("../src/profile-model-runtime
|
|
|
282
282
|
const { createCodexModelCatalog } = await import("../src/codex-model-catalog.mjs");
|
|
283
283
|
const { createProviderRuntime } = await import("../src/provider-runtime.mjs");
|
|
284
284
|
const { setResponseHistoryMaxBytes } = await import("../src/response-history.mjs");
|
|
285
|
-
const { startupBanner, startupCheck, startupReady, startupLogger, predictionStartupCheck, providerStartupChecks, createStartupPresentation } = await import("../src/startup-ui.mjs");
|
|
285
|
+
const { startupBanner, startupCheck, startupReady, startupLogger, predictionStartupCheck, imageStartupCheck, providerStartupChecks, createStartupPresentation } = await import("../src/startup-ui.mjs");
|
|
286
286
|
const { createTerminalConsole } = await import("../src/terminal-console.mjs");
|
|
287
287
|
const { createServiceControl } = await import("../src/service-control.mjs");
|
|
288
288
|
const { openDashboard } = await import("../src/browser-launch.mjs");
|
|
@@ -375,11 +375,11 @@ async function reuseRunningAdapterIfAvailable() {
|
|
|
375
375
|
if (!predictionPacUrl) console.warn(status("warn", "Restart ccdx to activate the newly enabled prediction bridge"));
|
|
376
376
|
}
|
|
377
377
|
} catch (error) { console.warn(status("warn", error.message)); }
|
|
378
|
-
|
|
378
|
+
const imageHost = codexEnabled && imageEnabled ? await (await clientIntegrations()).imageHostLaunch() : null;
|
|
379
|
+
if (codexEnabled) await openCodex({ predictionPacUrl, predictionApp, predictionProfile, persistedPredictionRoute, imageHost,
|
|
379
380
|
onPredictionRoute: route => { launchRoute = route; }, log: startupLogger("App") });
|
|
380
381
|
console.log(predictionStartupCheck({ configured: predictionConfigured, bridge: predictionPacUrl ? "running" : "unknown", launch_route: launchRoute }));
|
|
381
|
-
console.log(
|
|
382
|
-
? imageMcpSkipped ? "App setup skipped; see warning" : "Configured; not tested" : "Off"));
|
|
382
|
+
console.log(imageStartupCheck({ enabled: imageEnabled, prepared: Boolean(imageHost), skipped: imageMcpSkipped }));
|
|
383
383
|
console.log(providerStartupChecks((await serviceStatus)?.data));
|
|
384
384
|
console.log(startupReady({ baseUrl: running.baseUrl, commandName: CLI_NAME, reused: true }));
|
|
385
385
|
await launchDashboard();
|
|
@@ -532,12 +532,12 @@ try {
|
|
|
532
532
|
const persistentRoute = await nativePrediction?.prepareRoute();
|
|
533
533
|
|
|
534
534
|
// Launch Codex when available. A running App is never forcibly restarted.
|
|
535
|
-
|
|
535
|
+
const imageHost = codexEnabled && imageEnabled ? await clientIntegration.imageHostLaunch() : null;
|
|
536
|
+
if (codexEnabled) await openCodex({ predictionPacUrl: nativePrediction?.pacUrl, predictionApp: nativePrediction?.app, predictionProfile: nativePrediction?.profile, imageHost,
|
|
536
537
|
preparePredictionRoute: () => nativePrediction?.prepareRoute(), persistedPredictionRoute: persistentRoute?.status === "installed",
|
|
537
538
|
onPredictionRoute: route => clientIntegration?.launched(route), log: startupLogger("App") });
|
|
538
539
|
console.log(predictionStartupCheck(clientIntegration?.snapshot().prediction));
|
|
539
|
-
console.log(
|
|
540
|
-
? imageMcpSkipped ? "App setup skipped; see warning" : "Configured; not tested" : "Off"));
|
|
540
|
+
console.log(imageStartupCheck({ enabled: imageEnabled, prepared: Boolean(imageHost), skipped: imageMcpSkipped }));
|
|
541
541
|
console.log(providerStartupChecks(activeServer.ccdxSnapshot?.()));
|
|
542
542
|
|
|
543
543
|
// Periodically refresh the model list + endpoint cache so a long-running
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { runCodexImageHost } from "../src/codex-image-host.mjs";
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2), split = args.indexOf("--");
|
|
6
|
+
const hostArgs = args.slice(0, split), argv = args.slice(split + 1);
|
|
7
|
+
const codex = hostArgs[hostArgs.indexOf("--codex") + 1];
|
|
8
|
+
const baseUrl = hostArgs[hostArgs.indexOf("--base-url") + 1];
|
|
9
|
+
if (split < 0 || !path.isAbsolute(codex || "") || !baseUrl) { console.error("Invalid CCDX image host launch configuration");process.exit(2); }
|
|
10
|
+
try { process.exitCode = await runCodexImageHost({ codex, argv, baseUrl }); }
|
|
11
|
+
catch { console.error("CCDX image host could not start the configured Codex runtime");process.exitCode = 1; }
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -11,7 +11,7 @@ Client integration, image tools and the dashboard are not a general plugin frame
|
|
|
11
11
|
| Provider composition | `provider-runtime.mjs`, `connection-runtime.mjs`, provider/access settings | Explicit selection, lifecycle, history namespaces and snapshots |
|
|
12
12
|
| Claude clients | `claude-gateway.mjs`, `claude-client-lifecycle.mjs`, `claude-client-config.mjs`, `claude-models.mjs` | Native Messages relay and field-owned reversible client setup |
|
|
13
13
|
| Client integration | `client-integration.mjs`, Codex config, native prediction | Client setup, optional start/stop, diagnostic snapshots |
|
|
14
|
-
| Native images | Images routes, GHC client, preference controls and legacy retirement | Native
|
|
14
|
+
| Native images | Images routes, native SDK host tools, GHC client, preference controls and legacy retirement | Native tool progress and image content through the existing GitHub account; ChatGPT Apps and sign-in retained, no image MCP or separate credential |
|
|
15
15
|
| Management | CLI, dashboard, observability, package updates | Bounded metadata and explicit user actions |
|
|
16
16
|
| Shared foundations | Codex paths, file locks, atomic files, network routes | No dependency on inference or dashboard rendering |
|
|
17
17
|
|
|
@@ -1077,6 +1077,8 @@ Claude passthrough now holds incomplete SSE frames and validates complete data b
|
|
|
1077
1077
|
|
|
1078
1078
|
`image-setup.mjs` projects native GHC image availability and selection; `service-control.mjs` serializes toggle and model-selection changes. `image-retirement.mjs` removes the independent image credential, recognizable old MCP declarations and unmodified guidance. Customized files are preserved with a warning. Codex’s native image extension sends separate JSON generation/edit requests through its configured provider, saves the resulting pixels and emits image items to the App; CCDX reuses GHC authentication and maps the native alias to the saved GHC image selection. `image-models.mjs` interprets declared image capabilities independently of conversation picker flags; `clients.codex.image_model` is the canonical selection shared by controls, model configuration and the Images route. Image-only selection does not change conversation bindings or history isolation. The browser has no image API address/key form. The model compatibility action uses `doctor-compat.mjs` through local tools and requires explicit quota confirmation.
|
|
1079
1079
|
|
|
1080
|
+
On macOS, the owned Codex launcher supplies the stdio host adapter to a new App process without changing the signed App or account. The host reads the loopback dashboard settings route with its required dashboard header before registering the image tool; disabled or unreadable settings leave it unregistered. A running App retains its old environment, so startup explains how to activate a missing host without restarting that App.
|
|
1081
|
+
|
|
1080
1082
|
The existing supervisor accepts a bounded manual update request as well as its optional nightly scheduler. Both use the same staged package verification, immutable worker, state-transfer, installation commit and rollback path. Manual and scheduled updates are mutually exclusive; settings operations contribute to busy state and stable prediction intent/trust participate in the state fingerprint; the legacy image credential path remains in this fingerprint for old-worker compatibility, and legacy image cleanup runs only after activation; native port allocation and App stat bookkeeping do not. Warm handoff suppresses first-time prediction setup and pending display writes. Explicit prediction reconfiguration replaces the old bridge after committing trust. An unowned installation falls back to the existing standalone launch and exposes that self-update is unavailable. No inference protocol, privacy transport or native authentication path is changed by these controls.
|
|
1081
1083
|
|
|
1082
1084
|
Native discovery, configuration and startup environment inspection run in bounded temporary `prediction-operations.mjs` workers. PowerShell, certificate and filesystem work do not block the gateway event loop. Registered-App discovery precedes default trust/proxy setup; missing Apps leave core startup available. Private environment results feed only bridge initialization and are not returned by WebUI actions.
|
|
@@ -1105,6 +1107,6 @@ Performance comparison is separate from runtime logic and reports paired timing
|
|
|
1105
1107
|
|
|
1106
1108
|
The 1.3.13 native helper groups uncached short CPU sequences under the existing shared core budget. Groups retain at most 512 total tokens and 16 KiB text. The existing core budget is divided between sequence workers, including its remainder, instead of repeatedly creating a full-budget partition for every short field. Tokenization, position IDs, attention scope and dynamic quantization remain per sequence. Already-known windows and single uncached sequences retain their previous paths; long and accelerator-eligible windows use the existing reader. Cancellation waits for physical acknowledgement, completed windows remain reusable, and the complete check still precedes upstream calls. Status advertises cpu_short_batch and reports cpu_batch_groups/cpu_batch_windows without retaining values.
|
|
1107
1109
|
|
|
1108
|
-
Claude App 3.x and 4.x share the inspected effort-capable adapter. Later unknown major versions retain conservative routes and preserve existing shared capability settings.
|
|
1110
|
+
Claude App 3.x and 4.x share the inspected effort-capable adapter. Later unknown major versions retain conservative routes and preserve existing shared capability settings. Contiguous effort declarations select the source-qualified reasoning route; a gapped declaration with at least two lower contiguous levels can expose that safe prefix with an App maximum cap, while retaining the complete upstream declaration and reporting the hidden levels as limited. Prior route spellings remain accepted for existing conversations. Resynchronization carries long-context preference and model order between the two known source-qualified spellings, and replaces only owned shared capability fields. No undeclared effort is added. The sidebar brand places its shared atom icon and text in one grid row so the intro icon's two-row span cannot offset the label.
|
|
1109
1111
|
|
|
1110
1112
|
Usage presentation maps configured api_ identifiers to current provider labels after aggregation. Rows, chart filters and historical statistics keep their original keys. Provider-label changes refresh only the table/model labels, preserving the selected raw model key, day and existing chart nodes. The native capability replay disables usage persistence and gives its process a temporary usage path; no production filter recognizes test model names or response IDs.
|
package/docs/REFERENCE.md
CHANGED
|
@@ -212,9 +212,12 @@ heuristic or original-vendor limit is applied to an arbitrary relay deployment.
|
|
|
212
212
|
Claude configuration and gateway catalogs use the same compiled model plan.
|
|
213
213
|
Explicit App bindings use opaque source-qualified aliases and actual model/source
|
|
214
214
|
labels. Verified 3.x and 4.x App adapters can use a reasoning-compatible route when the
|
|
215
|
-
advertised levels form a client-expressible contiguous set.
|
|
216
|
-
|
|
217
|
-
levels are reported as limited
|
|
215
|
+
advertised levels form a client-expressible contiguous set. When a declaration has
|
|
216
|
+
a gap after at least two lower levels, the App can select that safe lower prefix;
|
|
217
|
+
the higher levels are reported as limited and remain in the source declaration.
|
|
218
|
+
For example, `low/medium/high/max` shows `low/medium/high` without inventing
|
|
219
|
+
`xhigh`. Older compatibility routes remain resolvable for that authorized
|
|
220
|
+
deployment. Unsupported effort requests fail explicitly.
|
|
218
221
|
No tool permission or safety-review setting is disabled for compatibility.
|
|
219
222
|
|
|
220
223
|
The App Code host and independent Code share some settings. CCDX plans them once,
|
|
@@ -579,7 +582,9 @@ was recreated on the original address, not that gray text appeared.
|
|
|
579
582
|
|
|
580
583
|
Codex’s built-in `image_gen.imagegen` tool uses the current CCDX address for separate Images API requests. CCDX serves `POST /v1/images/generations` and `POST /v1/images/edits`, reuses the existing GitHub Copilot authentication, and maps the native client’s `gpt-image-2` request to the selected available GHC image model. GPT Image 2.5 Flare is the default when advertised. The `X-CCDX-Image-Model` response header identifies the actual model. Image usage counts toward the GitHub account’s image credits; organization model policies still apply. The image model does not replace the selected conversation model.
|
|
581
584
|
|
|
582
|
-
Codex
|
|
585
|
+
On macOS with Codex 0.166 or later, CCDX launches the unchanged Codex CLI through a local stdio host adapter. The adapter registers `ccdx_images.imagegen` using Codex’s native `dynamicTools` interface. Codex emits native tool progress and includes image content in the chat history; display in the signed App depends on the client and requires a real-window check. CCDX saves image files under the active Codex home’s `generated_images/ccdx/` directory and uses these files for later edits, including after a host restart. No separate image address or key, image MCP registration, or CCDX image skill is required. Windows continues to expose the Images API; automatic host activation on Windows is not yet provided.
|
|
586
|
+
|
|
587
|
+
The adapter uses `CODEX_CLI_PATH` only for the App launch requested by CCDX. It does not modify App binaries, ChatGPT authentication files, credential storage mode or account-plan declarations. All other app-server traffic, including Apps and approval requests, passes through to the original CLI. Existing custom CLI routes and unowned launcher files are preserved. A running App retains its existing launch environment. If its image tool is missing, fully quit the App, start Codex through CCDX, and use a new chat. CCDX does not forcibly restart the App. Native built-in image tool availability still depends on the installed client and thread. A successful direct API request alone does not establish visible App behavior.
|
|
583
588
|
|
|
584
589
|
The WebUI’s image switch is on by default and pauses or resumes new requests. A previously saved off choice is preserved. Available GHC image models appear below the switch; multiple models use one radio selection. The same image purpose appears in Model sources and Codex model configuration. Image models stay out of Codex’s conversation-model picker and conversation default selection. Saved pause choices survive upgrades, and active calls may finish. The CLI uses the same preference:
|
|
585
590
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { readBoundedFileSync } from "./bounded-file.mjs";
|
|
4
4
|
import { m365Paths, readM365Json } from "./m365-settings.mjs";
|
|
5
|
-
import { claudeEffortsExpressible } from "./model-capabilities.mjs";
|
|
5
|
+
import { claudeEffortsExpressible, claudeEffortPrefix } from "./model-capabilities.mjs";
|
|
6
6
|
import { claudeModelEntries } from "./claude-models.mjs";
|
|
7
7
|
import { claudeClientPaths, reconcileClaudeConfiguration } from "./claude-client-config.mjs";
|
|
8
8
|
|
|
@@ -41,7 +41,8 @@ export function claudeSharedCapabilityPlan({ app = [], code = [], support = {} }
|
|
|
41
41
|
output = Math.max(output, values.max_output_tokens || 0);
|
|
42
42
|
const efforts = values.reasoning === false ? [] : values.reasoning_efforts || [];
|
|
43
43
|
if (efforts.length && !claudeEffortsExpressible(values)) limitations.push({ model: model.id, code: "reasoning_levels_limited" });
|
|
44
|
-
|
|
44
|
+
const visibleEfforts = desktop && /^mythos-ccdx-\d+$/.test(id) ? claudeEffortPrefix(values) : claudeEffortsExpressible(values) ? efforts : [];
|
|
45
|
+
if (visibleEfforts.length) caps.push(`${id.toLowerCase()}=${["effort", ...(visibleEfforts.includes("xhigh") ? ["xhigh_effort"] : []), ...(visibleEfforts.includes("max") ? ["max_effort"] : [])].join(",")}`);
|
|
45
46
|
if (values.web_search && !values.web_search.includes("messages")) limitations.push({ model: model.id, code: "search_messages_unavailable" });
|
|
46
47
|
}
|
|
47
48
|
if (!safeContext) context = 0;
|
package/src/claude-models.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { modelReasoningEfforts } from "./provider-metadata.mjs";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { modelDisplayName } from "./model-display.mjs";
|
|
4
|
+
import { claudeEffortPrefix } from "./model-capabilities.mjs";
|
|
4
5
|
|
|
5
6
|
const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
6
7
|
|
|
@@ -25,7 +26,8 @@ export function claudeModelEntries(models, { desktopAliases = false } = {}) {
|
|
|
25
26
|
if (ids.has(name) || name !== model.id && upstreamIds.has(name)) throw Object.assign(new Error("Claude model aliases collide; refresh the provider catalog"), { code: "claude_model_alias_collision", statusCode: 503 });
|
|
26
27
|
ids.add(name);
|
|
27
28
|
const advertised = model.capability?.values.reasoning === false ? [] : model.capability?.values.reasoning_efforts || modelReasoningEfforts(model);
|
|
28
|
-
const
|
|
29
|
+
const prefix = /^mythos-ccdx-\d+$/.test(name) ? claudeEffortPrefix(model.capability?.values) : [];
|
|
30
|
+
const maxEffort = prefix.at(-1) || EFFORTS.filter(value => advertised?.includes(value)).at(-1);
|
|
29
31
|
return { name, ...(model.display_name || name !== claudeClientModelId(model.id) ? { labelOverride: modelDisplayName(model) } : {}),
|
|
30
32
|
...(model.capability?.values.context_window >= 1000000 ? { supports1m: true } : {}), ...(maxEffort ? { maxEffort } : {}) };
|
|
31
33
|
});
|
package/src/cli-image.mjs
CHANGED
|
@@ -22,6 +22,6 @@ export async function runImageCommand({ action, model, output = process.stdout,
|
|
|
22
22
|
if (result.availability === "selected_unavailable") output.write("Saved image model is unavailable; choose an available model.\n");
|
|
23
23
|
for (const item of result.models || []) output.write(`${item.id === result.selected_model ? "*" : " "} ${terminalCell(item.name || item.id)} (${terminalCell(item.id)})\n`);
|
|
24
24
|
if (!result.models?.length) output.write("Read the GitHub catalog in Model sources or use source github models --refresh.\n");
|
|
25
|
-
output.write("Uses
|
|
25
|
+
output.write("Uses Codex native host tools and the existing GitHub account. Start Codex through CCDX, then use a new chat.\n");
|
|
26
26
|
return result;
|
|
27
27
|
}
|
|
@@ -60,6 +60,10 @@ export function createClientIntegration({ port, host, info = () => {}, warning =
|
|
|
60
60
|
} catch { warning("Legacy image cleanup was incomplete; review the old image files before the next CCDX start. The old image service is retired."); }
|
|
61
61
|
}
|
|
62
62
|
return {
|
|
63
|
+
async imageHostLaunch(options = {}) {
|
|
64
|
+
try { return await (await import("./codex-image-host-launch.mjs")).prepareImageHostLaunch({ host, port, ...options }); }
|
|
65
|
+
catch (error) { warning(error.message);return null; }
|
|
66
|
+
},
|
|
63
67
|
retireImages,
|
|
64
68
|
async configure() {
|
|
65
69
|
try {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { claudeModelEntries } from "../claude-models.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { claudeEffortPrefix } from "../model-capabilities.mjs";
|
|
3
3
|
|
|
4
4
|
export function claudeDeploymentId(model, route, { desktopEffortAliases = false } = {}) {
|
|
5
5
|
const number = route.slice("ccdx/model-".length);
|
|
6
6
|
const native = /^claude-(?:opus|sonnet|haiku)-\d[\d.-]*(?:-latest)?$/.test(model.id);
|
|
7
|
-
// This host alias is used only when
|
|
7
|
+
// This host alias is used only when a safe contiguous effort menu is supported.
|
|
8
8
|
// Both spellings remain accepted routes when capability evidence changes.
|
|
9
9
|
return native ? `ccdx-${number}.anthropic.${model.id.replace(/(\d)\.(\d)/g, "$1-$2")}`
|
|
10
|
-
: desktopEffortAliases &&
|
|
10
|
+
: desktopEffortAliases && claudeEffortPrefix(model.capability?.values).length ? `mythos-ccdx-${number}` : `ccdx/claude-compatible-${number}`;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function claudeRouteAliases(model, route, desktop) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { userSettingsPath, servicePreferences } from "./user-settings.mjs";
|
|
7
|
+
import { atomicWriteFileIfChangedSync } from "./atomic-file.mjs";
|
|
8
|
+
import { installedPredictionApp } from "./native-prediction-app.mjs";
|
|
9
|
+
import { autoLaunchEnabled } from "./launcher.mjs";
|
|
10
|
+
import { adapterBaseUrl } from "./running-adapter.mjs";
|
|
11
|
+
|
|
12
|
+
const execute = promisify(execFile);
|
|
13
|
+
const PREFIX = "#!/bin/sh\n# CCDX native image host\n";
|
|
14
|
+
const quote = value => "'" + value.replaceAll("'", "'\"'\"'") + "'";
|
|
15
|
+
|
|
16
|
+
export function imageHostLauncherPath(options = {}) {
|
|
17
|
+
return path.join(path.dirname(userSettingsPath(options)), "native-image-host", "codex-cli");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function prepareImageHostLaunch({ env = process.env, home, platform = process.platform, host = "127.0.0.1", port = 2026,
|
|
21
|
+
discoverApp = installedPredictionApp, exec = execute, node = process.execPath,
|
|
22
|
+
entry = fileURLToPath(new URL("../bin/codex-image-host.mjs", import.meta.url)) } = {}) {
|
|
23
|
+
if (platform !== "darwin" || !autoLaunchEnabled(env) || !servicePreferences({ env, home }).image_enabled) return null;
|
|
24
|
+
const wrapper = imageHostLauncherPath({ env, home });
|
|
25
|
+
if (env.CODEX_CLI_PATH?.trim() && path.resolve(env.CODEX_CLI_PATH) !== wrapper) throw new Error("A custom Codex CLI route is already configured; image host setup was preserved");
|
|
26
|
+
const app = await discoverApp({ env, platform });
|
|
27
|
+
const codex = path.join(app.app, "Contents", "Resources", "codex-cli", "CodexCLI.app", "Contents", "MacOS", "codex");
|
|
28
|
+
if (!fs.statSync(codex).isFile()) throw new Error("The verified App has no native Codex runtime");
|
|
29
|
+
const result = await exec(codex, ["--version"], { encoding: "utf8", timeout: 3000, maxBuffer: 4096 });
|
|
30
|
+
const match = /codex-cli\s+0\.(\d+)\./.exec(String(result?.stdout ?? result));
|
|
31
|
+
if (!match || Number(match[1]) < 166) throw new Error("Native host tools require Codex 0.166 or later");
|
|
32
|
+
for (const value of [node, entry, codex]) if (!path.isAbsolute(value) || /[\0\r\n]/.test(value)) throw new Error("Invalid image host executable path");
|
|
33
|
+
if (fs.existsSync(wrapper) && !fs.readFileSync(wrapper, "utf8").startsWith(PREFIX)) throw new Error("Image host launcher ownership conflict; existing file preserved");
|
|
34
|
+
const content = PREFIX + "exec " + [node, entry, "--codex", codex, "--base-url", adapterBaseUrl(host, port) + "/v1", "--"].map(quote).join(" ") + ' "$@"\n';
|
|
35
|
+
fs.mkdirSync(path.dirname(wrapper), { recursive: true, mode: 0o700 });
|
|
36
|
+
atomicWriteFileIfChangedSync(wrapper, content, { mode: 0o700 });fs.chmodSync(wrapper, 0o700);
|
|
37
|
+
return { app: app.app, env: { CODEX_CLI_PATH: wrapper } };
|
|
38
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { once } from "node:events";
|
|
6
|
+
import { StringDecoder } from "node:string_decoder";
|
|
7
|
+
|
|
8
|
+
export const IMAGE_HOST_NAMESPACE = "ccdx_images";
|
|
9
|
+
export const IMAGE_HOST_TOOL = Object.freeze({
|
|
10
|
+
type: "namespace", name: IMAGE_HOST_NAMESPACE,
|
|
11
|
+
description: "Codex host image generation and editing through CCDX. Generated images appear in the native image gallery.",
|
|
12
|
+
tools: [{ type: "function", name: "imagegen", deferLoading: false,
|
|
13
|
+
description: "Generate an image or edit reference images. Use this host tool for image requests in this chat. Edit defaults to the last generated image when no references are supplied. Results include native image content and a saved local file.",
|
|
14
|
+
inputSchema: { type: "object", additionalProperties: false, required: ["mode", "prompt"], properties: {
|
|
15
|
+
mode: { type: "string", enum: ["generate", "edit"] }, prompt: { type: "string" },
|
|
16
|
+
transparent_background: { type: "boolean" },
|
|
17
|
+
referenced_image_paths: { type: "array", maxItems: 5, items: { type: "string" }, description: "Images within this workspace, attached by the user, or generated in this chat." },
|
|
18
|
+
num_last_images_to_include: { type: "integer", minimum: 0, maximum: 5 },
|
|
19
|
+
quality: { type: "string", enum: ["auto", "low", "medium", "high"] },
|
|
20
|
+
size: { type: "string", enum: ["auto", "1024x1024", "1536x1024", "1024x1536"] },
|
|
21
|
+
} } }],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export function addImageHostTool(params) {
|
|
25
|
+
const existing = params.dynamicTools || [];
|
|
26
|
+
if (!Array.isArray(existing) || existing.some(tool => tool?.name === IMAGE_HOST_NAMESPACE)) {
|
|
27
|
+
throw new Error("The CCDX image host namespace is already configured");
|
|
28
|
+
}
|
|
29
|
+
return { ...params, dynamicTools: [...existing, IMAGE_HOST_TOOL] };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function imageHostBaseUrl(value) {
|
|
33
|
+
const url = new URL(value);
|
|
34
|
+
if (url.protocol !== "http:" || !["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)
|
|
35
|
+
|| url.pathname !== "/v1" || url.username || url.password || url.search || url.hash) {
|
|
36
|
+
throw new Error("Image host requires the local CCDX /v1 endpoint");
|
|
37
|
+
}
|
|
38
|
+
return url.href.replace(/\/$/, "");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function boundedJson(response) {
|
|
42
|
+
let size = 0;const chunks = [];
|
|
43
|
+
for await (const chunk of response.body) {
|
|
44
|
+
size += chunk.length;
|
|
45
|
+
if (size > 48 * 1024 * 1024) throw new Error("Image backend response exceeds its limit");
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
}
|
|
48
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function imageType(bytes) {
|
|
52
|
+
if (bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) return ["png", "image/png"];
|
|
53
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return ["jpg", "image/jpeg"];
|
|
54
|
+
if (bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP") return ["webp", "image/webp"];
|
|
55
|
+
throw new Error("The image backend did not return a supported image");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const inside = (root, file) => file === root || file.startsWith(root + path.sep);
|
|
59
|
+
|
|
60
|
+
export function createImageHostBridge({ baseUrl, codexHome, sendToCodex, fetchImpl = fetch, imageEnabled,
|
|
61
|
+
now = Date.now } = {}) {
|
|
62
|
+
baseUrl = imageHostBaseUrl(baseUrl);
|
|
63
|
+
const requests = new Map(), threads = new Map(), active = new Map();
|
|
64
|
+
let experimental = false, sequence = 0;
|
|
65
|
+
const root = path.join(codexHome, "generated_images", "ccdx");
|
|
66
|
+
const folder = id => path.join(root, createHash("sha256").update(id).digest("hex").slice(0, 32));
|
|
67
|
+
const enabled = imageEnabled || (async () => {
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetchImpl(baseUrl.replace(/\/v1$/, "/_ccdx/ui/settings"), {
|
|
70
|
+
headers: { "X-CCDX-Dashboard": "1" }, signal: AbortSignal.timeout(1000),
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) return false;
|
|
73
|
+
const settings = await boundedJson(response);return settings.features?.image?.enabled === true;
|
|
74
|
+
} catch { return false; }
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
async function readReference(value, context, id) {
|
|
78
|
+
if (value.startsWith("data:image/")) return value;
|
|
79
|
+
let file;
|
|
80
|
+
try {
|
|
81
|
+
file = await fs.realpath(path.resolve(context.cwd, value));
|
|
82
|
+
const own = await fs.realpath(folder(id)).catch(() => folder(id));
|
|
83
|
+
const attached = await Promise.all(context.attachments.filter(v => !v.startsWith("data:")).map(v => fs.realpath(v).catch(() => null)));
|
|
84
|
+
const roots = await Promise.all([context.cwd, ...context.roots].map(v => fs.realpath(v).catch(() => null)));
|
|
85
|
+
const generated = await Promise.all(context.generated.map(v => fs.realpath(v).catch(() => null)));
|
|
86
|
+
if (!inside(own, file) && !generated.includes(file) && !attached.includes(file)
|
|
87
|
+
&& !roots.some(v => v && inside(v, file))) throw new Error("scope");
|
|
88
|
+
const stat = await fs.stat(file);
|
|
89
|
+
if (!stat.isFile() || stat.size > 10 * 1024 * 1024) throw new Error("size");
|
|
90
|
+
const bytes = await fs.readFile(file), [, mime] = imageType(bytes);
|
|
91
|
+
return "data:" + mime + ";base64," + bytes.toString("base64");
|
|
92
|
+
} catch { throw new Error("Reference images must be readable images in this workspace, user attachments, or this chat"); }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function recentImages(id, context, count) {
|
|
96
|
+
let disk = [];
|
|
97
|
+
try { disk = (await fs.readdir(folder(id))).filter(v => /\.(png|jpg|webp)$/.test(v)).sort().map(v => path.join(folder(id), v)); }
|
|
98
|
+
catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
99
|
+
return [...new Set([...disk, ...context.generated])].slice(-count);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function runImage(params, signal) {
|
|
103
|
+
const args = params.arguments;
|
|
104
|
+
if (!args || typeof args !== "object" || Array.isArray(args) || !["generate", "edit"].includes(args.mode)
|
|
105
|
+
|| typeof args.prompt !== "string" || !args.prompt.trim()) throw new Error("Choose generate or edit and supply an image prompt");
|
|
106
|
+
const id = params.threadId, context = threads.get(id);
|
|
107
|
+
if (!context) throw new Error("Resume this chat through CCDX before using the image host");
|
|
108
|
+
const references = args.referenced_image_paths || [];
|
|
109
|
+
if (!Array.isArray(references) || references.some(v => typeof v !== "string") || references.length > 5) throw new Error("Choose up to five image references");
|
|
110
|
+
const count = args.num_last_images_to_include;
|
|
111
|
+
if (count !== undefined && (!Number.isInteger(count) || count < 0 || count > 5)) throw new Error("Choose zero to five recent images");
|
|
112
|
+
const body = { model: "gpt-image-2", prompt: args.prompt,
|
|
113
|
+
background: args.transparent_background === true ? "transparent" : "auto",
|
|
114
|
+
quality: args.quality || "auto", size: args.size || "auto" };
|
|
115
|
+
if (args.mode === "edit") {
|
|
116
|
+
let selected = references.length ? references : context.attachments;
|
|
117
|
+
if (count !== undefined ? count > 0 : !selected.length) selected = [...selected, ...await recentImages(id, context, count ?? 1)];
|
|
118
|
+
if (!selected.length || selected.length > 5) throw new Error("Editing requires one to five images");
|
|
119
|
+
body.images = await Promise.all(selected.map(async value => ({ image_url: await readReference(value, context, id) })));
|
|
120
|
+
} else if (references.length || count) throw new Error("Use edit mode with image references");
|
|
121
|
+
const response = await fetchImpl(baseUrl + "/images/" + (args.mode === "edit" ? "edits" : "generations"), {
|
|
122
|
+
method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), signal,
|
|
123
|
+
});
|
|
124
|
+
const result = await boundedJson(response);
|
|
125
|
+
if (!response.ok) throw new Error(result.error?.message || "Image backend returned HTTP " + response.status);
|
|
126
|
+
const pixels = result.data?.[0]?.b64_json;
|
|
127
|
+
if (typeof pixels !== "string") throw new Error("Image backend returned no image");
|
|
128
|
+
const bytes = Buffer.from(pixels, "base64");
|
|
129
|
+
if (!bytes.length || bytes.length > 32 * 1024 * 1024 || bytes.toString("base64") !== pixels) throw new Error("Image backend returned invalid image data");
|
|
130
|
+
const [ext, mime] = imageType(bytes);
|
|
131
|
+
signal.throwIfAborted();
|
|
132
|
+
const directory = folder(id);await fs.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
133
|
+
const savedPath = path.join(directory, String(now()).padStart(16, "0") + "-" + String(sequence++).padStart(6, "0") + "-" + randomUUID() + "." + ext);
|
|
134
|
+
await fs.writeFile(savedPath, bytes, { mode: 0o600, flag: "wx" });
|
|
135
|
+
if (signal.aborted) { await fs.unlink(savedPath);signal.throwIfAborted(); }
|
|
136
|
+
context.generated.push(savedPath);
|
|
137
|
+
return { success: true, contentItems: [{ type: "inputImage", imageUrl: "data:" + mime + ";base64," + pixels },
|
|
138
|
+
{ type: "inputText", text: JSON.stringify({ savedPath, model: response.headers.get("x-ccdx-image-model") || "selected GitHub image model" }) }] };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
async client(message) {
|
|
143
|
+
if (message.method === "initialize") experimental = message.params?.capabilities?.experimentalApi === true;
|
|
144
|
+
if (["thread/start", "thread/resume", "thread/fork"].includes(message.method)) {
|
|
145
|
+
requests.set(JSON.stringify(message.id), { method: message.method, params: message.params || {} });
|
|
146
|
+
if (message.method === "thread/start" && experimental && await enabled()) return { ...message, params: addImageHostTool(message.params || {}) };
|
|
147
|
+
}
|
|
148
|
+
if (message.method === "turn/start") {
|
|
149
|
+
const context = threads.get(message.params?.threadId);
|
|
150
|
+
if (context) context.attachments = (message.params.input || []).flatMap(value => value.type === "localImage" ? [path.resolve(context.cwd, value.path)]
|
|
151
|
+
: value.type === "image" && typeof value.url === "string" && value.url.startsWith("data:image/") ? [value.url] : []);
|
|
152
|
+
}
|
|
153
|
+
if (message.method === "turn/interrupt") for (const value of active.values()) if (value.threadId === message.params?.threadId) value.controller.abort(new Error("Image request cancelled"));
|
|
154
|
+
return message;
|
|
155
|
+
},
|
|
156
|
+
codex(message) {
|
|
157
|
+
const pending = requests.get(JSON.stringify(message.id));
|
|
158
|
+
if (pending && !message.method) {
|
|
159
|
+
requests.delete(JSON.stringify(message.id));const thread = message.result?.thread;
|
|
160
|
+
if (thread?.id && thread.cwd) threads.set(thread.id, { cwd: thread.cwd, roots: pending.params.runtimeWorkspaceRoots || [], attachments: [], generated: [] });
|
|
161
|
+
}
|
|
162
|
+
if (message.method === "item/completed" && message.params?.item?.type === "imageGeneration" && message.params.item.savedPath) {
|
|
163
|
+
threads.get(message.params.threadId)?.generated.push(message.params.item.savedPath);
|
|
164
|
+
}
|
|
165
|
+
if (message.id === undefined || message.method !== "item/tool/call" || message.params?.namespace !== IMAGE_HOST_NAMESPACE || message.params?.tool !== "imagegen") return false;
|
|
166
|
+
const controller = new AbortController(), key = JSON.stringify(message.id);
|
|
167
|
+
active.set(key, { controller, threadId: message.params.threadId });
|
|
168
|
+
void runImage(message.params, AbortSignal.any([controller.signal, AbortSignal.timeout(180000)]))
|
|
169
|
+
.then(result => sendToCodex({ id: message.id, result }))
|
|
170
|
+
.catch(error => sendToCodex({ id: message.id, result: { success: false, contentItems: [{ type: "inputText", text: error.message }] } }))
|
|
171
|
+
.finally(() => active.delete(key));
|
|
172
|
+
return true;
|
|
173
|
+
},
|
|
174
|
+
close() { for (const value of active.values()) value.controller.abort(new Error("Image host closed")); },
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function lines(stream, accept) {
|
|
179
|
+
const decoder = new StringDecoder("utf8");let buffer = "";
|
|
180
|
+
const data = chunk => {
|
|
181
|
+
buffer += decoder.write(chunk);let boundary;
|
|
182
|
+
while ((boundary = buffer.indexOf("\n")) >= 0) { const line = buffer.slice(0, boundary);buffer = buffer.slice(boundary + 1);accept(line); }
|
|
183
|
+
};
|
|
184
|
+
const end = () => { buffer += decoder.end();if (buffer) accept(buffer); };
|
|
185
|
+
stream.on("data", data);stream.on("end", end);
|
|
186
|
+
return () => { stream.removeListener("data", data);stream.removeListener("end", end); };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export async function runCodexImageHost({ codex, argv, baseUrl, env = process.env, input = process.stdin, output = process.stdout, error = process.stderr, spawnImpl = spawn } = {}) {
|
|
190
|
+
const args = argv || [], at = args.indexOf("app-server"), rest = args.slice(at + 1);
|
|
191
|
+
const stdio = at >= 0 && !["daemon", "proxy", "generate-ts", "generate-json-schema"].includes(rest[0])
|
|
192
|
+
&& !rest.some(value => /^--listen=(?!stdio:\/\/)/.test(value))
|
|
193
|
+
&& (rest.indexOf("--listen") < 0 || rest[rest.indexOf("--listen") + 1] === "stdio://");
|
|
194
|
+
const childEnv = { ...env, CODEX_APP_RUNTIME_CLI_PATH: codex };delete childEnv.CODEX_CLI_PATH;
|
|
195
|
+
const child = spawnImpl(codex, args, { env: childEnv, stdio: ["pipe", "pipe", "pipe"] });
|
|
196
|
+
child.stdin.on("error", () => {});child.stderr.pipe(error, { end: false });
|
|
197
|
+
let bridge, queue = Promise.resolve();const cleanups = [];
|
|
198
|
+
const write = message => { if (!child.stdin.destroyed) child.stdin.write(JSON.stringify(message) + "\n"); };
|
|
199
|
+
if (!stdio) { input.pipe(child.stdin);child.stdout.pipe(output, { end: false }); }
|
|
200
|
+
else {
|
|
201
|
+
bridge = createImageHostBridge({ baseUrl, codexHome: path.resolve(env.CODEX_HOME || path.join(env.HOME || process.env.HOME, ".codex")), sendToCodex: write });
|
|
202
|
+
cleanups.push(lines(input, raw => {
|
|
203
|
+
queue = queue.then(async () => {
|
|
204
|
+
let message;try { message = JSON.parse(raw); } catch { child.stdin.write(raw + "\n");return; }
|
|
205
|
+
try { const next = await bridge.client(message);if (next === message) child.stdin.write(raw + "\n");else write(next); }
|
|
206
|
+
catch (failure) { output.write(JSON.stringify({ id: message.id, error: { code: -32602, message: failure.message } }) + "\n"); }
|
|
207
|
+
});
|
|
208
|
+
}));
|
|
209
|
+
cleanups.push(lines(child.stdout, raw => { let value;try { value = JSON.parse(raw); } catch {}if (!value || !bridge.codex(value)) output.write(raw + "\n"); }));
|
|
210
|
+
const end = () => { void queue.finally(() => { bridge.close();child.stdin.end(); }); };
|
|
211
|
+
input.on("end", end);cleanups.push(() => input.removeListener("end", end));
|
|
212
|
+
}
|
|
213
|
+
const stop = signal => { bridge?.close();child.kill(signal); };
|
|
214
|
+
const interrupt = () => stop("SIGINT"), terminate = () => stop("SIGTERM");
|
|
215
|
+
process.once("SIGINT", interrupt);process.once("SIGTERM", terminate);
|
|
216
|
+
try { const [code, signal] = await once(child, "exit");await queue;return code ?? (signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 1); }
|
|
217
|
+
finally { bridge?.close();for (const cleanup of cleanups) cleanup();input.unpipe(child.stdin);input.pause();process.removeListener("SIGINT", interrupt);process.removeListener("SIGTERM", terminate); }
|
|
218
|
+
}
|
package/src/launcher.mjs
CHANGED
|
@@ -61,7 +61,7 @@ export function macPredictionAppProcesses(app, { exec = execFileSync } = {}) {
|
|
|
61
61
|
return rows;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export async function openCodex({ env = process.env, spawnImpl = spawn, platform = process.platform, predictionPacUrl = null, predictionApp = null, predictionProfile = null,
|
|
64
|
+
export async function openCodex({ env = process.env, spawnImpl = spawn, platform = process.platform, predictionPacUrl = null, predictionApp = null, predictionProfile = null, imageHost = null,
|
|
65
65
|
preparePredictionRoute, persistedPredictionRoute = false, onPredictionRoute = () => {}, log = console.log,
|
|
66
66
|
resolveWindowsApp = installedWindowsPredictionApp, windowsAppProcesses = windowsPredictionAppProcesses,
|
|
67
67
|
macAppProcesses = macPredictionAppProcesses } = {}) {
|
|
@@ -124,6 +124,11 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
124
124
|
return false;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
const imageArgs = platform === "darwin" && imageHost?.env?.CODEX_CLI_PATH
|
|
128
|
+
? ["--env", "CODEX_CLI_PATH=" + imageHost.env.CODEX_CLI_PATH] : [];
|
|
129
|
+
if (imageArgs.length) log(status("info", "Image host configured for the next Codex launch and new chats; a running App is not restarted"));
|
|
130
|
+
const imageApp = imageArgs.length && APP_PATH_CANDIDATES.includes(imageHost.app) ? imageHost.app : null;
|
|
131
|
+
const warnRunningImageApp = () => log(status("warn", "Codex is already running. If the image tool is missing, fully quit the App and start it through CCDX."));
|
|
127
132
|
const extraArgs = isPredictionPacUrl(predictionPacUrl)
|
|
128
133
|
&& APP_PATH_CANDIDATES.includes(predictionApp)
|
|
129
134
|
? ["--args", `--proxy-pac-url=${predictionPacUrl}`] : [];
|
|
@@ -131,6 +136,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
131
136
|
try {
|
|
132
137
|
const running = macAppProcesses(predictionApp);
|
|
133
138
|
if (running.length) {
|
|
139
|
+
if (imageApp === predictionApp) warnRunningImageApp();
|
|
134
140
|
if (running.length === 1 && running[0].readable && running[0].route === predictionPacUrl) {
|
|
135
141
|
onPredictionRoute("verified");log(status("ok", "Codex already running"));return true;
|
|
136
142
|
}
|
|
@@ -140,7 +146,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
140
146
|
throw new Error("Running Codex App uses an old or unverified prediction route. Fully quit the App, then run ccdx again; no process was stopped");
|
|
141
147
|
}
|
|
142
148
|
await preparePredictionRoute?.();
|
|
143
|
-
if (!await tryOpen([predictionApp, ...extraArgs], { spawnImpl })) {
|
|
149
|
+
if (!await tryOpen([predictionApp, ...imageArgs, ...extraArgs], { spawnImpl })) {
|
|
144
150
|
onPredictionRoute("unverified");log(status("warn", "Could not open Codex App"));return false;
|
|
145
151
|
}
|
|
146
152
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
@@ -157,9 +163,13 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
157
163
|
onPredictionRoute("unverified");log(status("warn", `Optional macOS prediction launch skipped: ${error.message}`));return false;
|
|
158
164
|
}
|
|
159
165
|
}
|
|
160
|
-
|
|
166
|
+
if (imageApp) {
|
|
167
|
+
try { if (macAppProcesses(imageApp).length) warnRunningImageApp(); }
|
|
168
|
+
catch { log(status("warn", "Could not check the running Codex App. If the image tool is missing, start the App through CCDX after quitting it.")); }
|
|
169
|
+
}
|
|
170
|
+
const attempts = imageArgs.length && APP_PATH_CANDIDATES.includes(imageHost.app) ? [[imageHost.app]] : launchAttempts();
|
|
161
171
|
for (const attempt of attempts) {
|
|
162
|
-
const args = [...attempt, ...extraArgs];
|
|
172
|
+
const args = [...attempt, ...imageArgs, ...extraArgs];
|
|
163
173
|
if (await tryOpen(args, { spawnImpl })) {
|
|
164
174
|
log(status("ok", "Codex opened"));
|
|
165
175
|
return true;
|
|
@@ -75,6 +75,15 @@ export function claudeEffortsExpressible(values = {}) {
|
|
|
75
75
|
return levels.length > 0 && levels.every(value => native.includes(value)) && native.slice(0, Math.max(...levels.map(value => native.indexOf(value))) + 1).every(value => levels.includes(value));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
export function claudeEffortPrefix(values = {}) {
|
|
79
|
+
const levels = values.reasoning === false ? [] : values.reasoning_efforts || [];
|
|
80
|
+
const native = ["low", "medium", "high", "xhigh", "max"];
|
|
81
|
+
if (!Array.isArray(levels) || !levels.length || new Set(levels).size !== levels.length || levels.some(value => !native.includes(value))) return [];
|
|
82
|
+
const missing = native.findIndex(value => !levels.includes(value));
|
|
83
|
+
const prefix = native.slice(0, missing < 0 ? native.length : missing);
|
|
84
|
+
return prefix.length === levels.length || prefix.length >= 2 ? prefix : [];
|
|
85
|
+
}
|
|
86
|
+
|
|
78
87
|
export function constrainModelRequest(body, capability, protocol) {
|
|
79
88
|
const values = capability?.values || {}, outputKey = protocol === "messages" ? "max_tokens" : protocol === "responses" ? "max_output_tokens" : "max_completion_tokens";
|
|
80
89
|
let result = body;const applied = [];
|
|
@@ -29,6 +29,7 @@ export async function controlPrediction(operation, { integration, nativeOperatio
|
|
|
29
29
|
if (!native) throw new Error("Prediction bridge is unavailable");
|
|
30
30
|
await native.prepareRoute?.();
|
|
31
31
|
return { opened: await openCodex({ predictionPacUrl: native.pacUrl, predictionApp: native.app, predictionProfile: native.profile,
|
|
32
|
+
imageHost: await integration.imageHostLaunch?.({ env: { ...(options.env || process.env), CCDX_AUTO_LAUNCH: "1" } }),
|
|
32
33
|
env: { ...(options.env || process.env), CCDX_AUTO_LAUNCH: "1" }, persistedPredictionRoute: false,
|
|
33
34
|
preparePredictionRoute: () => native.prepareRoute?.(), onPredictionRoute: value => integration.launched(value) }) };
|
|
34
35
|
}
|
package/src/startup-ui.mjs
CHANGED
|
@@ -89,6 +89,12 @@ export function predictionStartupCheck(prediction) {
|
|
|
89
89
|
return lines.join("\n");
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
export function imageStartupCheck({ enabled, prepared, skipped } = {}) {
|
|
93
|
+
if (!enabled) return startupCheck("info", "Images", "Off");
|
|
94
|
+
if (!prepared || skipped) return startupCheck("warn", "Images", "App host not prepared");
|
|
95
|
+
return startupCheck("info", "Images", "App launch prepared; not tested");
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
// Catalog discovery, client configuration and inference access are distinct.
|
|
93
99
|
export function providerStartupSummary(data = {}) {
|
|
94
100
|
if (!data.providers) return { catalogs: "Status unavailable; see WebUI", claude: "Configuration not checked", warning: false };
|