codex-copilot-dx 1.3.18 → 1.3.20

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.
@@ -0,0 +1,67 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { isPredictionPacUrl } from "./prediction-pac.mjs";
4
+
5
+ const execute = promisify(execFile);
6
+ const apps = new Set(["/Applications/Codex.app", "/Applications/ChatGPT.app"]);
7
+
8
+ // AppKit asks an existing application to quit normally or become active. It
9
+ // never launches a new process and never force-quits an application.
10
+ const appScript = `ObjC.import("AppKit");
11
+ function run(argv) {
12
+ var app = $.NSRunningApplication.runningApplicationWithProcessIdentifier(Number(argv[0]));
13
+ if (app.isNil()) return "absent";
14
+ if (ObjC.unwrap(app.bundleIdentifier) !== "com.openai.codex" || ObjC.unwrap(app.bundleURL.path) !== argv[1]) return "different";
15
+ var sent = argv[2] === "quit" ? app.terminate : app.activateWithOptions($.NSApplicationActivateIgnoringOtherApps);
16
+ return sent ? "sent" : "refused";
17
+ }`;
18
+
19
+ export async function inspectCodexApp(app, hosts = [], { platform = process.platform, exec = execute, predictionPacUrl } = {}) {
20
+ if (platform !== "darwin") return { status: "unsupported" };
21
+ if (!apps.has(app)) throw new Error("Unrecognized Codex App path");
22
+ const result = await exec("/bin/ps", ["-axo", "pid=,ppid=,comm="], { encoding: "utf8", timeout: 3000, maxBuffer: 4 * 1024 * 1024 });
23
+ const processes = new Map();
24
+ for (const line of String(result?.stdout ?? result).split("\n")) {
25
+ const match = /^\s*(\d+)\s+(\d+)\s+(.+?)\s*$/.exec(line);
26
+ if (match) processes.set(Number(match[1]), { pid: Number(match[1]), parent: Number(match[2]), command: match[3] });
27
+ }
28
+ const matches = [...processes.values()].filter(row => [`${app}/Contents/MacOS/ChatGPT`, `${app}/Contents/MacOS/Codex`].includes(row.command));
29
+ if (!matches.length) return { status: "stopped" };
30
+ if (matches.length !== 1) return { status: "multiple" };
31
+ const pid = matches[0].pid;
32
+ const belongsToApp = host => {
33
+ if (!host.connected) return false;
34
+ let node = processes.get(host.pid);const visited = new Set();
35
+ while (node && !visited.has(node.pid)) {
36
+ if (node.pid === pid) return true;
37
+ visited.add(node.pid);node = processes.get(node.parent);
38
+ }
39
+ return false;
40
+ };
41
+ const linked = hosts.filter(belongsToApp);
42
+ let predictionRoute;
43
+ if (isPredictionPacUrl(predictionPacUrl)) {
44
+ predictionRoute = "unconfirmed";
45
+ try {
46
+ const result = await exec("/bin/ps", ["-p", String(pid), "-o", "args="], { encoding: "utf8", timeout: 3000, maxBuffer: 64 * 1024 });
47
+ const args = String(result?.stdout ?? result).trim(), executable = matches[0].command;
48
+ const route = /(?:^|\s)--proxy-pac-url=(?:"(http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac(?:\?v=2)?)"|(http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac(?:\?v=2)?)(?=\s|$))/.exec(args);
49
+ if ((args === executable || args.startsWith(executable + " ")) && (args.match(/(?:^|\s)--proxy-pac-url=/g) || []).length === 1
50
+ && (route?.[1] || route?.[2]) === predictionPacUrl) predictionRoute = "verified";
51
+ } catch { /* A missing route is not proof that the App uses one. */ }
52
+ }
53
+ return { status: "running", pid, host: linked.length ? "connected" : "unconfirmed",
54
+ ...(predictionRoute ? { prediction_route: predictionRoute } : {}),
55
+ tool_registration: linked.some(host => host.threads?.length) ? "observed" : "unconfirmed" };
56
+ }
57
+
58
+ export async function controlCodexApp(app, pid, action, { platform = process.platform, exec = execute } = {}) {
59
+ if (platform !== "darwin" || !apps.has(app) || !Number.isSafeInteger(pid) || pid <= 0 || !["quit", "activate"].includes(action)) {
60
+ throw new Error("Invalid Codex App control request");
61
+ }
62
+ const result = await exec("/usr/bin/osascript", ["-l", "JavaScript", "-e", appScript, String(pid), app, action],
63
+ { encoding: "utf8", timeout: 5000, maxBuffer: 4096 });
64
+ const value = String(result?.stdout ?? result).trim();
65
+ if (!["sent", "absent", "different", "refused"].includes(value)) throw new Error("Could not control the verified Codex App");
66
+ return value;
67
+ }
@@ -75,7 +75,9 @@ export async function inspectCodexClient({
75
75
  } else if (observed) {
76
76
  const version = /^[0-9]+\.[0-9]+\.[0-9]+$/.test(observed.client_version || "") ? observed.client_version : "unknown";
77
77
  const app = ["ChatGPT.app", "Codex.app", "custom binary"].includes(observed.application) ? observed.application : "unknown App";
78
- checks.push({ kind: "info", message: `Last catalog request: client ${version}, ${app}, ${observed.source === "bundled" ? "bundled" : "unavailable"}; version match ${observed.matched === true ? "observed" : "not verified"}` });
78
+ const source = observed.source === "cached_bundled" ? "previously verified bundled" : observed.source === "bundled" ? "bundled" : "unavailable";
79
+ const precision = observed.match_precision === "exact" ? "exact version" : observed.match_precision === "core_only" ? "base version only" : "not specified";
80
+ checks.push({ kind: "info", message: `Last catalog request: client ${version}, ${app}, ${source}; version match ${observed.matched === true ? "observed" : "not verified"} (${precision})` });
79
81
  } else checks.push({ kind: "info", message: "No client model-catalog request observed by this adapter" });
80
82
  } catch { checks.push({ kind: "info", message: "Client model-catalog diagnostics unavailable from the running adapter" }); }
81
83
  }
@@ -0,0 +1,132 @@
1
+ import { prepareImageHostLaunch } from "./codex-image-host-launch.mjs";
2
+ import { imageSetupSummary } from "./image-setup.mjs";
3
+ import { openCodex } from "./launcher.mjs";
4
+ import { installedPredictionApp } from "./native-prediction-app.mjs";
5
+ import { inspectCodexApp, controlCodexApp } from "./codex-app-control.mjs";
6
+ import { predictionControlSnapshot } from "./prediction-control.mjs";
7
+ import { predictionPaths, readPredictionSettings, writePredictionSettings } from "./native-prediction-profile.mjs";
8
+ import { servicePreferences } from "./user-settings.mjs";
9
+ import { runPredictionOperation } from "./prediction-operations.mjs";
10
+ import { withFileLock } from "./lock.mjs";
11
+
12
+ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
13
+ const publicAppState = value => ({ status: value.status, ...(value.host ? { host: value.host } : {}),
14
+ ...(value.tool_registration ? { tool_registration: value.tool_registration } : {}),
15
+ ...(value.prediction_route ? { prediction_route: value.prediction_route } : {}),
16
+ ...(typeof value.needs_restart === "boolean" ? { needs_restart: value.needs_restart } : {}) });
17
+
18
+ async function applyPendingPrediction(options, nativeOperation) {
19
+ try {
20
+ if (!readPredictionSettings(options).displayPending) return true;
21
+ const enabled = servicePreferences(options).prediction_enabled;
22
+ const result = await nativeOperation("display", { ...options, enabled, requireClosed: true });
23
+ if (result?.pending !== false) return false;
24
+ return await withFileLock(`${predictionPaths(options).settings}.lock`, () => {
25
+ const current = readPredictionSettings(options);
26
+ if (!current.displayPending) return true;
27
+ if (servicePreferences(options).prediction_enabled !== enabled) return false;
28
+ writePredictionSettings({ ...current, displayPending: false }, options);return true;
29
+ });
30
+ } catch { return false; }
31
+ }
32
+
33
+ export async function controlCodexLaunch(operation, { intent = "image", integration, state, host, port, models = [],
34
+ prepare = prepareImageHostLaunch, launch = openCodex, readSummary = imageSetupSummary,
35
+ readPrediction = predictionControlSnapshot, nativeOperation = runPredictionOperation,
36
+ discover = installedPredictionApp, inspect = inspectCodexApp, appControl = controlCodexApp,
37
+ confirmed = false, wait = sleep, now = Date.now, quitTimeoutMs = 10000, ...options } = {}) {
38
+ if (!["check", "repair", "open", "focus", "restart"].includes(operation) || !["image", "prediction"].includes(intent)) throw new Error("Unknown Codex App control");
39
+ if (operation === "restart" && confirmed !== true) throw new Error("Confirm that restarting Codex can interrupt its running tasks");
40
+ const platform = options.platform || process.platform;
41
+ let image, prediction;
42
+ try { image = readSummary({ ...options, models }); }
43
+ catch { image = { enabled: servicePreferences(options).image_enabled, configured: false, selected_available: false, availability: "unavailable" }; }
44
+ try { prediction = readPrediction(options); }
45
+ catch { prediction = { enabled: false, configured: false, status: "unavailable" }; }
46
+ const runtime = () => state?.snapshot();
47
+ const inspectApp = async app => {
48
+ const current = await inspect(app, runtime()?.hosts || [], { ...options, predictionPacUrl: integration?.pacUrl?.() });
49
+ if (current.status === "running") {
50
+ const imagePending = image.enabled && image.configured && image.selected_available && current.host !== "connected";
51
+ const predictionPending = prediction.display_pending || prediction.configured && prediction.enabled && current.prediction_route !== "verified";
52
+ current.needs_restart = Boolean(imagePending || predictionPending);
53
+ }
54
+ return current;
55
+ };
56
+ if (operation === "check") {
57
+ let app = { status: platform === "darwin" ? "unknown" : "unsupported" };
58
+ if (platform === "darwin") try { app = await inspectApp((await discover(options)).app); } catch { /* Unknown is not stopped. */ }
59
+ return { status: "checked", app: publicAppState(app), prediction, image: { enabled: image.enabled, availability: image.availability } };
60
+ }
61
+ if (operation === "focus") {
62
+ if (platform !== "darwin") return { status: "unsupported", app: { status: "unsupported" } };
63
+ let app, current;
64
+ try { app = (await discover(options)).app;current = await inspectApp(app); }
65
+ catch { return { status: "app_check_failed", app: { status: "unknown" } }; }
66
+ if (current.status !== "running") return { status: "app_not_running", app: publicAppState(current) };
67
+ let result;
68
+ try { result = await appControl(app, current.pid, "activate", options); }
69
+ catch { return { status: "focus_unavailable", app: { status: "unknown" } }; }
70
+ return { status: result === "sent" ? "focused" : "focus_unavailable", app: result === "sent" ? publicAppState(current) : { status: "unknown" } };
71
+ }
72
+ if (!integration) throw new Error("Start CCDX before opening Codex from this control");
73
+ if (intent === "image" && !image.enabled) throw new Error("Enable images before repairing image access");
74
+ if (intent === "prediction" && !prediction.configured && !prediction.display_pending) throw new Error("Enable predictions before opening Codex");
75
+ const env = { ...(options.env || process.env), CCDX_AUTO_LAUNCH: "1" };
76
+ await integration.configure();
77
+ let imageHost = null, imagePrepFailed = false, imageWarning = intent === "prediction" && image.enabled && (!image.configured || !image.selected_available);
78
+ if (image.enabled) {
79
+ try { imageHost = await prepare({ ...options, env, host, port }); }
80
+ catch (error) { if (intent === "image") throw error;imageWarning = true;imagePrepFailed = true; }
81
+ if (!imageHost) { if (intent === "image") return { status: "unsupported", prepared: false };imageWarning = true;imagePrepFailed = true; }
82
+ }
83
+ let app = imageHost?.app;
84
+ if (!app) { try { app = (await discover(options)).app; } catch { return { status: "app_check_failed", prepared: false }; } }
85
+ let current;
86
+ try { current = await inspectApp(app); } catch { return { status: "app_check_failed", prepared: true }; }
87
+ if (current.status === "unsupported") return { status: "unsupported", prepared: true };
88
+ if (current.status === "multiple") return { status: "multiple_apps", prepared: true, app: publicAppState(current) };
89
+ if (!["running", "stopped"].includes(current.status)) return { status: "app_check_failed", prepared: true };
90
+ if (operation !== "restart" && current.status === "running") return { status: current.needs_restart ? "needs_app_relaunch" : "already_connected",
91
+ prepared: true, runtime: runtime(), app: publicAppState(current) };
92
+ if (operation === "repair") return { status: "prepared", prepared: true, runtime: runtime(), app: publicAppState(current) };
93
+ if (operation === "restart" && intent === "image" && (!image.configured || !image.selected_available)) return { status: "image_unavailable", prepared: true, app: publicAppState(current) };
94
+ if (operation === "restart" && current.status === "running" && !current.needs_restart) return { status: "already_connected", prepared: true, app: publicAppState(current) };
95
+ // Never lose a currently connected image host due to a failed preparation.
96
+ if (imagePrepFailed && current.status === "running" && current.host === "connected") return { status: "image_unavailable", prepared: true, app: publicAppState(current) };
97
+ const native = await integration.start();
98
+ if (prediction.status === "unavailable") return { status: "prediction_unavailable", prepared: true, app: publicAppState(current) };
99
+ if (!native && prediction.configured && prediction.enabled) return { status: "prediction_unavailable", prepared: true, app: publicAppState(current) };
100
+ await native?.prepareRoute?.();
101
+ if (native?.pacUrl && native.app && native.app !== app) return { status: "app_route_conflict", prepared: true };
102
+ if (operation === "restart") {
103
+ const previous = current;
104
+ try { current = await inspectApp(app); } catch { return { status: "app_check_failed", prepared: true }; }
105
+ if (current.status === "running" && !current.needs_restart) return { status: "already_connected", prepared: true, app: publicAppState(current) };
106
+ if (!["running", "stopped"].includes(current.status) || current.status === "running" && (previous.status !== "running" || current.pid !== previous.pid)) {
107
+ return { status: "app_changed", prepared: true, app: publicAppState(current) };
108
+ }
109
+ if (current.status === "running") {
110
+ const originalPid = current.pid;
111
+ let requested;
112
+ try { requested = await appControl(app, originalPid, "quit", options); }
113
+ catch { return { status: "quit_refused", prepared: true, app: publicAppState(current) }; }
114
+ if (!["sent", "absent"].includes(requested)) return { status: "quit_refused", prepared: true, app: publicAppState(current) };
115
+ const deadline = now() + quitTimeoutMs;
116
+ do {
117
+ try { current = await inspectApp(app); } catch { return { status: "app_check_failed", prepared: true }; }
118
+ if (current.status === "stopped") break;
119
+ if (current.status !== "running" || current.pid !== originalPid) return { status: "app_changed", prepared: true, app: publicAppState(current) };
120
+ if (now() >= deadline) return { status: "quit_timeout", prepared: true, app: publicAppState(current) };
121
+ await wait(Math.min(250, Math.max(1, deadline - now())));
122
+ } while (true);
123
+ }
124
+ }
125
+ const predictionReady = await applyPendingPrediction(options, nativeOperation);
126
+ const opened = await launch({ env, imageHost, predictionPacUrl: native?.pacUrl, predictionApp: native?.app,
127
+ predictionProfile: native?.profile, preparePredictionRoute: () => native?.prepareRoute?.(),
128
+ onPredictionRoute: value => integration.launched?.(value) });
129
+ return { status: opened ? !predictionReady || imageWarning ? "opened_with_pending" : "opened_new_chat_required" : "open_failed",
130
+ prepared: true, runtime: runtime(), app: { status: "unknown" }, ...(opened && !predictionReady ? { prediction_pending: true } : {}),
131
+ ...(opened && imageWarning ? { image_pending: true } : {}) };
132
+ }
@@ -260,6 +260,8 @@ export function createCodexModelCatalog({
260
260
  const versionFailures = new Map();
261
261
  const versionPending = new Map();
262
262
  const catalogCache = new Map();
263
+ const exactCatalogCache = new Map();
264
+ const ambiguousVersions = new Set();
263
265
  const catalogFailures = new Map();
264
266
  const catalogPending = new Map();
265
267
  let activeBinaryKeys = new Set();
@@ -280,8 +282,8 @@ export function createCodexModelCatalog({
280
282
  const promise = (async () => {
281
283
  try {
282
284
  const stdout = await runCodexCommand(execFileFn, candidate.binaryPath, ["--version"], commandOptions);
283
- const version = wholeSemver(parsedCodexVersion(stdout));
284
- if (!version) throw new Error("Invalid Codex version output");
285
+ const version = parsedCodexVersion(stdout);
286
+ if (!wholeSemver(version)) throw new Error("Invalid Codex version output");
285
287
  if (activeBinaryKeys.has(candidate.key)) {
286
288
  versionCache.set(candidate.key, version);
287
289
  versionFailures.delete(candidate.key);
@@ -313,8 +315,10 @@ export function createCodexModelCatalog({
313
315
  if (!rawVersion) return installed[0];
314
316
  const expectedVersion = wholeSemver(rawVersion);
315
317
  if (!expectedVersion) return null;
318
+ const exact = rawVersion !== expectedVersion;
316
319
  for (const candidate of installed) {
317
- if (await probeVersion(candidate) === expectedVersion) return candidate;
320
+ const version = await probeVersion(candidate);
321
+ if (version && (exact ? version === rawVersion : wholeSemver(version) === expectedVersion)) return { ...candidate, fullVersion: version, precision: exact ? "exact" : "core_only" };
318
322
  }
319
323
  return null;
320
324
  }
@@ -356,14 +360,33 @@ export function createCodexModelCatalog({
356
360
  }
357
361
 
358
362
  async function load({ clientVersion = "" } = {}) {
363
+ const requested = String(clientVersion || "").trim(), core = wholeSemver(requested);
364
+ const exact = Boolean(core && requested !== core);
359
365
  const candidate = await selectBinary(clientVersion);
360
- const catalog = candidate ? await loadCatalog(candidate) : null;
361
- const app = candidate?.binaryPath.match(/(?:^|\/)(ChatGPT|Codex)\.app\//)?.[1];
366
+ let catalog = candidate ? await loadCatalog(candidate) : null;
367
+ let app = candidate?.binaryPath.match(/(?:^|\/)(ChatGPT|Codex)\.app\//)?.[1];
368
+ let source = catalog ? "bundled" : "unavailable";
369
+ if (candidate && catalog && exact && !ambiguousVersions.has(requested)) {
370
+ const previous = exactCatalogCache.get(requested);
371
+ if (previous && previous.key !== candidate.key) {
372
+ exactCatalogCache.delete(requested);ambiguousVersions.add(requested);
373
+ if (ambiguousVersions.size > 8) ambiguousVersions.delete(ambiguousVersions.values().next().value);
374
+ } else if (!previous) try {
375
+ const stats = await statFn(candidate.binaryPath);
376
+ if (stats?.isFile?.() && binaryCacheKey(candidate.binaryPath, stats) === candidate.key) {
377
+ exactCatalogCache.set(requested, { key: candidate.key, catalog, app: app || null });
378
+ while (exactCatalogCache.size > 2) exactCatalogCache.delete(exactCatalogCache.keys().next().value);
379
+ }
380
+ } catch { /* A changing App cannot supply a verified retained catalog. */ }
381
+ } else if (!candidate && exact && exactCatalogCache.has(requested) && !ambiguousVersions.has(requested)) {
382
+ const previous = exactCatalogCache.get(requested);catalog = previous.catalog;app = previous.app;source = "cached_bundled";
383
+ }
362
384
  lastObservation = {
363
- client_version: wholeSemver(clientVersion) || null,
364
- application: app ? `${app}.app` : candidate ? "custom binary" : null,
365
- source: catalog ? "bundled" : "unavailable",
366
- matched: Boolean(catalog && wholeSemver(clientVersion)),
385
+ client_version: core || null,
386
+ application: app ? `${app}.app` : candidate || source === "cached_bundled" ? "custom binary" : null,
387
+ source,
388
+ matched: Boolean(catalog && core),
389
+ match_precision: catalog && core ? exact ? "exact" : "core_only" : null,
367
390
  observed_at: new Date(now()).toISOString(),
368
391
  };
369
392
  return catalog;
@@ -371,7 +394,7 @@ export function createCodexModelCatalog({
371
394
 
372
395
  return { load, snapshot: () => ({
373
396
  last_request: lastObservation ? { ...lastObservation } : null,
374
- observed_versions: [...new Set(versionCache.values())].slice(0, 8),
397
+ observed_versions: [...new Set([...versionCache.values()].map(wholeSemver).filter(Boolean))].slice(0, 8),
375
398
  client_cache_verified: false,
376
399
  }) };
377
400
  }
@@ -35,6 +35,7 @@ import { codexClientCatalog, codexSourceCatalog } from "./clients/codex-models.m
35
35
  import { currentRequestContext } from "./request-context.mjs";
36
36
  import {
37
37
  claudeSharedCapabilityPlan,
38
+ claudeSupportForSync,
38
39
  syncClaudeCapabilities,
39
40
  inspectClaudeCapabilitySupport,
40
41
  inspectClaudeCapabilityConfiguration,
@@ -61,6 +62,7 @@ export function createConnectionRuntime({
61
62
  inspectDesktop = inspectClaudeDesktopPolicy,
62
63
  clientAccessChanged,
63
64
  preserveClientConfiguration,
65
+ clientVersionsSnapshot,
64
66
  now = Date.now,
65
67
  log = () => {},
66
68
  } = {}) {
@@ -105,6 +107,12 @@ export function createConnectionRuntime({
105
107
  onState: (id, state) => (state ? discoveries.set(id, state) : discoveries.delete(id)),
106
108
  });
107
109
  const capabilitySupport = inspectClaudeCapabilitySupport(options);
110
+ function capabilitySupportForSync() {
111
+ try {
112
+ return claudeSupportForSync(capabilitySupport, clientVersionsSnapshot?.());
113
+ } catch { /* Optional observations cannot change routing or interrupt synchronization. */ }
114
+ return capabilitySupport;
115
+ }
108
116
  let sharedSync = null,
109
117
  syncFlight = null,
110
118
  syncAgain = false,
@@ -608,7 +616,7 @@ export function createConnectionRuntime({
608
616
  const shared = claudeSharedCapabilityPlan({
609
617
  app: setup.claude_app === "configured" ? plan("claude_app").models : [],
610
618
  code: setup.claude_code === "configured" ? plan("claude_code").models : [],
611
- support: capabilitySupport,
619
+ support: capabilitySupportForSync(),
612
620
  });
613
621
  if (["claude_app", "claude_code"].some(id => setup[id] === "manual_sync")) {
614
622
  sharedSync = {
@@ -1008,7 +1016,7 @@ export function createConnectionRuntime({
1008
1016
  : claudeSharedCapabilityPlan({
1009
1017
  app: input.id === "claude_app" ? proposed.models : plan("claude_app").models,
1010
1018
  code: input.id === "claude_code" ? proposed.models : plan("claude_code").models,
1011
- support: capabilitySupport,
1019
+ support: capabilitySupportForSync(),
1012
1020
  });
1013
1021
  return {
1014
1022
  ...snapshot(),
@@ -1413,7 +1421,7 @@ export function createConnectionRuntime({
1413
1421
  }),
1414
1422
  }),
1415
1423
  },
1416
- codexCatalog: codexClientCatalog(compiled),
1424
+ codexCatalog: codexClientCatalog(compiled, () => getSource("github")?.registry?.models),
1417
1425
  };
1418
1426
  }
1419
1427
  if (Array.isArray(c.deployments) && compiled.defaultUnavailable) {
@@ -8,6 +8,17 @@
8
8
  let settingsReadAt = null;
9
9
  let accountsPending = false;
10
10
  const accountReasons = new Set(["m365_account_ambiguous", "m365_account_unavailable", "m365_account_conflict", "m365_interaction_required", "m365_llm_permission_unavailable", "m365_account_busy", "m365_account_selection_stale"]);
11
+ function renderClientVersions(value) {
12
+ for (const client of ["codex", "claude"]) {
13
+ const node = el(`client-version-${client}`);if (!node) continue;
14
+ const rows = Array.isArray(value?.[client]) ? value[client] : [];
15
+ if (!rows.length) { node.removeAttribute("data-i18n");node.textContent = "—";node.title = "";continue; }
16
+ const version = rows.map(row => `${rows.length > 1 ? `${row.name} ` : ""}${row.version}${row.build && row.build !== row.version ? ` (${row.build})` : ""}${row.cli_version ? ` · CLI ${row.cli_version}` : ""}`).join(" / ");
17
+ label(node, rows.some(row => row.changed_at) ? "client_version_changed" : "client_version_observed", { version });
18
+ node.title = rows.filter(row => row.changed_at).map(row => `${row.previous?.version || "—"} → ${row.version} · ${time(row.changed_at, { date: true })}`).join(" / ");
19
+ }
20
+ }
21
+ globalThis.ccdxClientVersions = { render: renderClientVersions };
11
22
  function syncAccountControls() {
12
23
  el("m365-accounts-refresh").disabled = accountsPending || settingsPending;
13
24
  el("m365-account-choice").disabled = accountsPending || settingsPending;
@@ -68,7 +79,7 @@
68
79
  async function api(body) {
69
80
  const response = await fetch("/_ccdx/ui/settings", { method: body ? "POST" : "GET", cache: "no-store",
70
81
  headers: { "X-CCDX-Dashboard": "1", ...(body ? { "Content-Type": "application/json" } : {}) },
71
- ...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout((body?.action === "prediction" || body?.action === "image" && body?.operation === "open") ? 210000 : body?.action === "image" || body?.operation === "account" ? 65000 : 15000) });
82
+ ...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout((body?.action === "prediction" || ["image", "codex_app"].includes(body?.action) && ["open", "restart"].includes(body?.operation)) ? 210000 : ["image", "codex_app"].includes(body?.action) || body?.operation === "account" ? 65000 : 15000) });
72
83
  const data = await response.json();if (!response.ok) throw Object.assign(new Error(data.error || `HTTP ${response.status}`), { code: data.code });return data;
73
84
  }
74
85
  const preferences = globalThis.ccdxDashboardPreferences?.create({ element: el, api, applied: applySettings, time,
@@ -115,6 +126,7 @@
115
126
  window.addEventListener("ccdx:providers", () => { syncSources();if (current === "codex") void loadSourceModels(); });
116
127
  function applySettings(data, meta) {
117
128
  globalThis.ccdxPrivacy?.sync(data.local_privacy);
129
+ renderClientVersions(data.client_versions);
118
130
  settings = data;
119
131
  features?.render(data);
120
132
  const nightly = data.nightly_update;
@@ -194,18 +206,18 @@
194
206
  }
195
207
  finally { settingsPending = false;el("m365-enabled").disabled = !settings;el("terminal-color-theme").disabled = !settings;el("apply-source").disabled = !sourceReady();syncReviewButton();syncAccountControls(); }
196
208
  }
197
- async function change(body, button) {
209
+ async function change(body, button, { quiet = false } = {}) {
198
210
  if (settingsPending) return;
199
211
  settingsPending = true;
200
212
  syncAccountControls();
201
213
  const controls = [...document.querySelectorAll("[role=switch], #save-history, #clean-history, #fix-prediction, #apply-source, #save-review, #source-provider, #source-model, #source-review, #source-review-effort, #terminal-color-theme, #m365-enabled, #prediction-continue, #prediction-open, #prediction-setup, #prediction-remove, #image-models input, #image-check, #image-repair, #image-open, #decoded-limit, #decoded-limit-save, #decoded-limit-default, #install-update")];
202
214
  controls.forEach(input => { input.disabled = true; });
203
- const note = el(body.action === "prediction" ? "prediction-action-note" : body.action === "image" ? "effect-image_enabled" : body.action === "update" ? "manual-update-note" : body.action === "decoded_limit" ? "decoded-limit-note" : body.action === "nightly_update" ? "nightly-state" : body.key ? `effect-${body.key}` : body.action === "color_theme" ? "terminal-color-note"
215
+ const note = el(body.action === "codex_app" ? body.intent === "prediction" ? "prediction-open-note" : "image-action-note" : body.action === "prediction" ? body.operation === "open" ? "prediction-open-note" : "prediction-action-note" : body.action === "image" ? "effect-image_enabled" : body.action === "update" ? "manual-update-note" : body.action === "decoded_limit" ? "decoded-limit-note" : body.action === "nightly_update" ? "nightly-state" : body.key ? `effect-${body.key}` : body.action === "color_theme" ? "terminal-color-note"
204
216
  : body.action.startsWith("history_") ? "effect-history" : body.action === "prediction_fix" ? "prediction-note"
205
217
  : body.operation === "switch" ? "source-control-note" : body.operation === "auto-review" ? "review-control-note"
206
218
  : body.operation === "account" ? "m365-account-note" : "m365-control-note");
207
219
  const initialSourceSave = body.operation === "switch" && Boolean(body.auto_review_model);
208
- label(note, "applying");
220
+ if (!quiet) { if (note.id === "prediction-open-note") note.hidden = false;label(note, "applying"); }
209
221
  if (button) button.setAttribute("aria-busy", "true");
210
222
  try {
211
223
  const data = await api(body);
@@ -214,6 +226,7 @@
214
226
  if (body.action === "provider" && body.operation === "off") { sourceDirty = false;reviewDirty = false; }
215
227
  el("review-control-note").textContent = "";
216
228
  applySettings(data);
229
+ if (body.action === "prediction" && body.operation === "open") { note.hidden = false;label(note, data.last_operation?.result?.opened ? "codex_action_opened" : "image_action_open_failed"); }
217
230
  if (body.action === "image") void globalThis.ccdxConnections?.load();
218
231
  if (initialSourceSave) label(el("source-control-note"), "source_initial_review_saved");
219
232
  if (body.operation === "account") {
@@ -227,6 +240,7 @@
227
240
  }
228
241
  catch (error) {
229
242
  if (settings) applySettings(settings);
243
+ if (note.id === "prediction-open-note") note.hidden = false;
230
244
  if (body.operation === "account") { label(el("m365-account-note"), "company_account_not_saved", { reason: { key: accountReasons.has(error.code) ? error.code : error.message } });return; }
231
245
  if (body.action === "color_theme") { label(el("terminal-color-note"), "not_saved_error", { error: error.message });return; }
232
246
  if (error.code === "ccdx_prediction_app_open") label(note, error.code);
@@ -43,7 +43,8 @@
43
43
  if (!valid(point.input_tokens)) { continuing = false;return; }
44
44
  path += `${continuing ? "L" : "M"}${x(index)} ${y(point.input_tokens)} `;continuing = true;
45
45
  const dot = shape("circle", { cx: x(index), cy: y(point.input_tokens), r: 3, class: "context-point" });
46
- const title = document.createElementNS(ns, "title");title.textContent = `${time(point.at)} · ${number(point.input_tokens)} tokens`;dot.append(title);
46
+ const description = language.format("context_point_usage", { time: time(point.at), input: number(point.input_tokens), reuse: ratio(point.cached_input_tokens, point.input_tokens) });
47
+ const title = document.createElementNS(ns, "title");title.textContent = description;dot.setAttribute("aria-label", description);dot.append(title);
47
48
  });
48
49
  if (!entry.concurrent) shape("path", { d: path, class: "context-line" });
49
50
  for (const index of new Set([0, Math.floor((points.length - 1) / 2), points.length - 1])) {
@@ -1,20 +1,63 @@
1
1
  (() => {
2
2
  function create({ element: el, change, localize }) {
3
- let saved = null, limitDirty = false, imageSignature = "";
4
- for (const operation of ["check", "repair", "open"]) el("image-" + operation).addEventListener("click", async () => {
5
- const data = await change({ action: "image", operation }, el("image-" + operation));
3
+ let saved = null, limitDirty = false, imageSignature = "", imageApp = { status: "unknown" }, appInspectionStarted = false;
4
+ function renderImageApp() {
5
+ const connected = imageApp.status === "running" && imageApp.host === "connected";
6
+ const restart = imageApp.status === "running" && (imageApp.needs_restart === true || saved?.features?.prediction?.display_pending === true);
7
+ const action = restart ? "image_restart" : imageApp.status === "running" ? "image_focus" : imageApp.status === "stopped" ? "image_open" : "image_inspect";
8
+ localize(el("image-open"), action);
9
+ localize(el("prediction-open"), imageApp.status === "unsupported" ? "prediction_open" : action);
10
+ el("image-restart-warning").hidden = !restart;
11
+ el("prediction-restart-warning").hidden = !restart;
12
+ localize(el("image-host-note"), imageApp.status === "stopped" ? "image_app_stopped" : imageApp.status === "multiple" ? "image_action_multiple_apps"
13
+ : connected ? imageApp.tool_registration === "observed" ? "image_host_registered" : "image_host_connected" : "image_host_unconfirmed");
14
+ }
15
+ async function codexAction(operation, intent, button, { quiet = false } = {}) {
16
+ const data = await change({ action: "codex_app", operation, intent, ...(operation === "restart" ? { confirmed: true } : {}) }, button, { quiet });
17
+ const result = data?.last_operation?.feature === "codex_app" ? data.last_operation.result : null;
18
+ if (!result) return;
19
+ if (result.app) imageApp = result.app;
20
+ if (!quiet) {
21
+ const note = el(intent === "prediction" ? "prediction-open-note" : "image-action-note");
22
+ note.dataset.operation = operation;note.hidden = false;
23
+ const key = operation === "check" ? "codex_action_checked" : result.status === "opened_with_pending"
24
+ ? result.prediction_pending && result.image_pending ? "codex_action_both_pending" : result.prediction_pending ? "codex_action_prediction_pending" : "codex_action_image_pending"
25
+ : result.status === "already_connected" ? "codex_action_ready"
26
+ : result.status === "opened_new_chat_required" && intent === "prediction" ? "codex_action_opened" : "image_action_" + result.status;
27
+ localize(note, key);
28
+ }
29
+ renderImageApp();
30
+ }
31
+ async function imageAction(operation, button, { quiet = false } = {}) {
32
+ const data = await change({ action: "image", operation, ...(operation === "restart" ? { confirmed: true } : {}) }, button);
6
33
  const result = data?.last_operation?.feature === "image" ? data.last_operation.result : null;
7
34
  if (result) {
8
- el("image-action-note").dataset.operation = operation;
9
- el("image-action-note").hidden = false;
10
- localize(el("image-action-note"), operation === "check" ? "image_connection_" + result.connection?.state : "image_action_" + result.status);
35
+ if (result.app) imageApp = result.app;
36
+ if (!quiet) {
37
+ el("image-action-note").dataset.operation = operation;
38
+ el("image-action-note").hidden = false;
39
+ localize(el("image-action-note"), operation === "check" ? "image_connection_" + result.connection?.state : "image_action_" + result.status);
40
+ }
41
+ renderImageApp();
11
42
  }
43
+ }
44
+ el("image-check").addEventListener("click", () => void imageAction("check", el("image-check")));
45
+ el("image-repair").addEventListener("click", () => void imageAction("repair", el("image-repair")));
46
+ const appButton = (intent, button) => {
47
+ if (imageApp.status === "unsupported" && intent === "prediction") { void prediction("open");return; }
48
+ const operation = imageApp.status === "running" ? imageApp.needs_restart || saved?.features?.prediction?.display_pending ? "restart" : "focus"
49
+ : imageApp.status === "stopped" ? "open" : "check";
50
+ void codexAction(operation, intent, button);
51
+ };
52
+ el("image-open").addEventListener("click", () => appButton("image", el("image-open")));
53
+ el("additional-capabilities").addEventListener("toggle", () => {
54
+ if (el("additional-capabilities").open) void codexAction("check", "image", el("image-check"), { quiet: true });
12
55
  });
13
- const prediction = operation => change({ action: "prediction", operation }, el("prediction-continue"));
56
+ const prediction = operation => change({ action: "prediction", operation }, el(operation === "open" ? "prediction-open" : "prediction-continue"));
14
57
  el("setting-prediction_enabled").addEventListener("change", () => void prediction(el("setting-prediction_enabled").checked ? "enable" : "disable"));
15
58
  el("prediction-continue").addEventListener("click", () => void prediction(saved?.features?.prediction?.enabled ? "enable" : "disable"));
16
59
  el("fix-prediction").addEventListener("click", () => void prediction("repair"));
17
- el("prediction-open").addEventListener("click", () => void prediction("open"));
60
+ el("prediction-open").addEventListener("click", () => appButton("prediction", el("prediction-open")));
18
61
  el("prediction-setup").addEventListener("click", () => void prediction("setup"));
19
62
  el("prediction-remove").addEventListener("click", () => { if (window.confirm(globalThis.ccdxLanguage.format("prediction_remove_confirm"))) void prediction("remove"); });
20
63
  el("decoded-limit").addEventListener("input", () => { limitDirty = true; });
@@ -34,14 +77,17 @@
34
77
  el("setting-prediction_enabled").checked = value?.enabled === true;
35
78
  el("setting-prediction_enabled").disabled = !value || value.status === "unavailable";
36
79
  const pending = value?.display_pending || value?.enabled && (!value.configured || value.display?.enabled === false);
80
+ el("prediction-continue-actions").hidden = !pending;
37
81
  el("prediction-continue").hidden = !pending;
38
- el("prediction-open").disabled = !value?.configured;
82
+ el("prediction-open").disabled = !value?.configured && !value?.display_pending;
39
83
  el("prediction-remove").disabled = !value?.configured;
40
- if (notes) localize(el("prediction-action-note"), !value ? "feature_unavailable" : value.status === "unavailable" ? "feature_read_failed" : pending ? "prediction_quit_continue" : value.enabled && value.bridge !== "running" ? "prediction_bridge_missing" : value.enabled ? "prediction_ready" : "prediction_disabled");
84
+ if (notes) {
85
+ el("prediction-open-note").hidden = true;
86
+ localize(el("prediction-action-note"), !value ? "feature_unavailable" : value.status === "unavailable" ? "feature_read_failed" : pending ? "prediction_quit_continue" : value.enabled && value.bridge !== "running" ? "prediction_bridge_missing" : value.enabled ? "prediction_ready" : "prediction_disabled");
87
+ }
41
88
  el("effect-prediction_enabled").hidden = !pending;
42
89
  if (pending) localize(el("effect-prediction_enabled"), "feature_pending");
43
- const runtime = data.features?.image?.runtime;
44
- localize(el("image-host-note"), runtime?.tool_registration === "observed" ? "image_host_registered" : runtime?.connected ? "image_host_connected" : "image_host_unconfirmed");
90
+ renderImageApp();
45
91
  const image = data.features?.image, signature = JSON.stringify(image ? { ...image, runtime: undefined } : null);
46
92
  if (signature !== imageSignature) {
47
93
  imageSignature = signature;
@@ -68,6 +114,9 @@
68
114
  el("install-update").disabled = !data.manual_update?.available;
69
115
  const update = data.nightly_update;
70
116
  if (notes) localize(el("manual-update-note"), !data.manual_update?.available ? "update_external_launch" : update?.manual ? `manual_update_${update.phase}` : "update_idle_switch");
117
+ if (!appInspectionStarted && el("prediction-open").closest('[data-view="codex"]')?.hidden === false) {
118
+ appInspectionStarted = true;setTimeout(() => void codexAction("check", "prediction", el("prediction-open"), { quiet: true }), 0);
119
+ }
71
120
  }
72
121
  return { render };
73
122
  }
@@ -121,13 +121,15 @@
121
121
  <details class="panel dashboard-section" id="prediction-settings" open>
122
122
  <summary class="panel-heading"><h2 data-i18n="codex_input_predictions">INPUT SUGGESTIONS</h2></summary>
123
123
  <div class="setting-row"><label for="setting-prediction_enabled" data-i18n="predictions_enable">Input suggestions</label><input id="setting-prediction_enabled" type="checkbox" role="switch" disabled><span id="effect-prediction_enabled" class="hint" role="status"></span></div>
124
- <p id="prediction-action-note" class="hint" role="status"></p><div class="section-actions"><button id="prediction-continue" type="button" data-i18n="feature_continue" hidden>Continue setup</button><button id="prediction-open" type="button" data-i18n="prediction_open">Open Codex</button></div>
124
+ <p id="prediction-action-note" class="hint" role="status"></p><div id="prediction-continue-actions" class="section-actions" hidden><button id="prediction-continue" type="button" data-i18n="feature_continue" hidden>Continue setup</button></div>
125
125
  <details class="tool-details"><summary data-i18n="status_and_repair">Status and repair</summary>
126
126
  <dl class="stats"><div><dt data-i18n="prediction_integration_setup">Suggestion setup</dt><dd id="prediction-preference">—</dd></div><div><dt data-i18n="local_bridge">Local service</dt><dd id="prediction-bridge">—</dd></div><div><dt data-i18n="client_route">App settings requests</dt><dd id="prediction-route">—</dd></div><div><dt data-i18n="visible_candidate">Suggestion displayed</dt><dd id="prediction-candidate">—</dd></div></dl>
127
127
  <p id="prediction-note" class="hint">—</p>
128
128
 
129
129
 
130
- <div class="section-actions"><button id="fix-prediction" type="button" data-i18n="check_and_repair">Check and repair</button><button id="prediction-setup" type="button" data-i18n="prediction_setup_again">Set up again</button><button id="prediction-remove" type="button" data-i18n="feature_remove">Remove setup</button></div>
130
+ <div class="section-actions"><button id="fix-prediction" type="button" data-i18n="check_and_repair">Check and repair</button><button id="prediction-setup" type="button" data-i18n="prediction_setup_again">Set up again</button><button id="prediction-open" type="button" data-i18n="prediction_open">Open Codex</button><button id="prediction-remove" type="button" data-i18n="feature_remove">Remove setup</button></div>
131
+ <p id="prediction-restart-warning" class="hint" role="status" data-i18n="image_restart_warning" hidden>Restarting Codex interrupts its running tasks. Finish or save them first.</p>
132
+ <p id="prediction-open-note" class="hint" role="status" hidden></p>
131
133
  </details>
132
134
  </details>
133
135
  <details class="panel dashboard-section" id="additional-capabilities">
@@ -135,6 +137,7 @@
135
137
  <div class="setting-row"><label for="setting-image_enabled" data-i18n="allow_new_image_calls">Allow image requests</label><input id="setting-image_enabled" type="checkbox" role="switch" disabled><span id="effect-image_enabled" class="hint" role="status"></span></div>
136
138
  <div id="image-models" class="image-models" role="group" aria-label="Image model" data-i18n-label="image_model"></div>
137
139
  <div class="section-actions"><button id="image-check" type="button" data-i18n="image_check">Check access</button><button id="image-repair" type="button" data-i18n="image_repair">Repair access</button><button id="image-open" type="button" data-i18n="image_open">Open Codex</button></div>
140
+ <p id="image-restart-warning" class="hint" role="status" data-i18n="image_restart_warning" hidden>Restarting Codex interrupts its running tasks. Finish or save them first.</p>
138
141
  <p id="image-host-note" class="hint" role="status"></p>
139
142
  <p id="image-action-note" class="hint" role="status" hidden></p>
140
143
  <p id="image-model-note" class="hint" role="status" hidden></p>
@@ -268,6 +271,9 @@
268
271
  <section class="panel dashboard-section">
269
272
  <h2 data-i18n="tools_check_local">Check this computer</h2>
270
273
  <p class="hint" data-i18n="tools_local_scope">Local checks do not contact external services.</p>
274
+ <p>Codex App: <strong id="client-version-codex">—</strong></p>
275
+ <p>Claude App: <strong id="client-version-claude">—</strong></p>
276
+ <p class="hint" data-i18n="client_versions_scope">Installed versions only; running App adoption and compatibility are separate.</p>
271
277
  <div class="section-actions"><button id="check-local" type="button" data-i18n="tools_check_local">Check this computer</button></div>
272
278
  <p id="checks-note" class="table-note" role="status" aria-live="polite" data-i18n="tools_checks_empty">Run a check to see the results.</p>
273
279
  <div class="table-wrap" id="checks-results" hidden><table class="checks-table"><thead><tr><th data-i18n="tools_check_item">Check</th><th data-i18n="state">State</th><th data-i18n="tools_details">Details</th></tr></thead><tbody id="checks-body"></tbody></table></div>