codex-copilot-dx 1.2.33 → 1.3.1
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 +65 -110
- package/bin/cli.mjs +38 -102
- package/docs/ARCHITECTURE.md +33 -7
- package/docs/README.md +10 -76
- package/docs/REFERENCE.md +147 -1936
- package/package.json +11 -4
- package/src/access-settings.mjs +2 -2
- package/src/adapter.mjs +6 -1
- package/src/auth-credentials.mjs +1 -1
- package/src/auto-review-model.mjs +2 -2
- package/src/claude-gateway.mjs +4 -1
- package/src/cli-animation.mjs +2 -2
- package/src/cli-auth.mjs +3 -3
- package/src/cli-cache.mjs +2 -2
- package/src/cli-command-spec.mjs +260 -58
- package/src/cli-image.mjs +2 -2
- package/src/cli-limits.mjs +2 -2
- package/src/cli-m365.mjs +1 -1
- package/src/cli-management.mjs +7 -3
- package/src/cli-options.mjs +71 -408
- package/src/connection-runtime.mjs +1408 -377
- package/src/context-metrics.mjs +63 -0
- package/src/copilot-token-session.mjs +1 -1
- package/src/dashboard/connections.js +23 -4
- package/src/dashboard/console.js +1 -0
- package/src/dashboard/context.js +124 -0
- package/src/dashboard/flow.js +1 -1
- package/src/dashboard/icons.js +6 -2
- package/src/dashboard/index.html +12 -0
- package/src/dashboard/language.js +23 -0
- package/src/dashboard/ui.css +36 -3
- package/src/dashboard/ui.js +12 -4
- package/src/dashboard-api.mjs +11 -5
- package/src/dashboard.mjs +1 -0
- package/src/doctor.mjs +4 -4
- package/src/image-mcp.mjs +2 -2
- package/src/native-prediction-fix.mjs +1 -1
- package/src/native-prediction-profile.mjs +1 -1
- package/src/native-prediction-windows.mjs +1 -1
- package/src/native-prediction.mjs +6 -6
- package/src/nightly-update.mjs +2 -2
- package/src/optional-routes.mjs +2 -2
- package/src/provider-runtime.mjs +1 -1
- package/src/providers/m365-accounts.mjs +1 -1
- package/src/release-install.mjs +11 -15
- package/src/responses-handler.mjs +3 -0
- package/src/startup-ui.mjs +15 -11
- package/src/stream-performance.mjs +9 -0
- package/src/terminal-console.mjs +5 -4
- package/src/terminal-state.mjs +1 -1
- package/src/usage-store.mjs +2 -1
- package/src/usage.mjs +5 -5
- package/src/windows-command.mjs +2 -2
- package/bin/codex-copilot-dx.mjs +0 -11
- package/src/cli-models.mjs +0 -94
- package/src/legacy-command-warning.mjs +0 -38
|
@@ -114,7 +114,7 @@ export function readPredictionCertificate(directory, { allowExpired = false, pla
|
|
|
114
114
|
if (!x509.publicKey.export({ type: "spki", format: "der" }).equals(publicKey)
|
|
115
115
|
|| (!allowExpired && Date.parse(x509.validTo) <= Date.now()) || !x509.checkHost("chatgpt.com") || !x509.checkHost("ab.chatgpt.com")
|
|
116
116
|
|| !x509.verify(ca.publicKey) || !ca.ca || x509.ca) {
|
|
117
|
-
throw new Error("Prediction certificate needs renewal; quit Codex and run ccdx prediction
|
|
117
|
+
throw new Error("Prediction certificate needs renewal; quit Codex and run ccdx app codex prediction setup");
|
|
118
118
|
}
|
|
119
119
|
return { cert, key, ca: ca.toString(), hash: createHash("sha256").update(ca.raw).digest("hex").toUpperCase(), der: ca.raw };
|
|
120
120
|
}
|
|
@@ -88,7 +88,7 @@ export function windowsPredictionProfile({ app, env = process.env, preferredProf
|
|
|
88
88
|
const profiles = [...new Set(candidates)].filter(candidate => fs.existsSync(path.win32.join(candidate, "Local State")));
|
|
89
89
|
if (profiles.length !== 1) throw new Error(profiles.length
|
|
90
90
|
? "Multiple Codex App profiles found; set CODEX_ELECTRON_USER_DATA_PATH to the active profile"
|
|
91
|
-
: "Open Codex App once, fully quit it, then run ccdx prediction
|
|
91
|
+
: "Open Codex App once, fully quit it, then run ccdx app codex prediction setup; its Windows profile was not found");
|
|
92
92
|
return profiles[0];
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -35,7 +35,7 @@ async function runPredictionCommandUnlocked({ action = "status", env = process.e
|
|
|
35
35
|
const settings = readPredictionSettings(opts);
|
|
36
36
|
if (action === "fix") {
|
|
37
37
|
if (!settings.enabled) {
|
|
38
|
-
output("Input suggestions are off. Nothing changed.\nTo enable: ccdx prediction
|
|
38
|
+
output("Input suggestions are off. Nothing changed.\nTo enable: ccdx app codex prediction setup");
|
|
39
39
|
return { status: "disabled", exitCode: 0 };
|
|
40
40
|
}
|
|
41
41
|
if (!repairRuntime) throw new Error("Start a CCDX version that supports suggestion repair.");
|
|
@@ -45,12 +45,12 @@ async function runPredictionCommandUnlocked({ action = "status", env = process.e
|
|
|
45
45
|
if (prediction.environment) output(formatPredictionEnvironment(prediction.environment));
|
|
46
46
|
if (result.status === "disabled") output("The running adapter has predictions off; no feature was enabled.");
|
|
47
47
|
else if (result.status === "needs_service_restart") output("Node trust settings changed. Restart the CCDX service to apply them; no certificate or App was changed.");
|
|
48
|
-
else if (result.status === "environment_preserved") output(`Network recheck failed; the existing bridge and routes were preserved. ${result.environment_error?.message || "Check ccdx prediction status."}`);
|
|
48
|
+
else if (result.status === "environment_preserved") output(`Network recheck failed; the existing bridge and routes were preserved. ${result.environment_error?.message || "Check ccdx app codex prediction status."}`);
|
|
49
49
|
else if (prediction.bridge !== "running") output(prediction.reason || "Prediction bridge is unavailable; core service was not changed.");
|
|
50
50
|
else if (prediction.environment?.status === "needs_app_relaunch") output("Network settings changed. The bridge uses the new snapshot, but the App may cache its earlier PAC. Fully quit Codex, then run ccdx; no App was restarted.");
|
|
51
51
|
else if (result.app_route === "verified") output("App launch route verified. A visible suggestion still needs an App-side check.");
|
|
52
52
|
else if (result.app_route === "closed") output("Bridge is ready. Run ccdx to open Codex with its prediction route.");
|
|
53
|
-
else if (result.status === "route_unverified") output("Bridge is ready, but App route inspection was unavailable or ambiguous. Check ccdx prediction status; no App was restarted.");
|
|
53
|
+
else if (result.status === "route_unverified") output("Bridge is ready, but App route inspection was unavailable or ambiguous. Check ccdx app codex prediction status; no App was restarted.");
|
|
54
54
|
else output("Bridge is ready, but the running App route is not verified. No App was restarted. Fully quit Codex, then run ccdx to attach the route.");
|
|
55
55
|
return { ...result, exitCode: ["ready", "disabled"].includes(result.status) ? 0 : 1 };
|
|
56
56
|
}
|
|
@@ -88,7 +88,7 @@ async function runPredictionCommandUnlocked({ action = "status", env = process.e
|
|
|
88
88
|
if (certificate.hash !== settings.certificateHash) throw new Error("Prediction certificate changed; trust cleanup was skipped");
|
|
89
89
|
await updatePredictionTrust(settings.store, certificate, { remove: true });
|
|
90
90
|
} catch (error) {
|
|
91
|
-
output(`Predictions disabled. ${error.message}. Quit Codex and run ccdx prediction
|
|
91
|
+
output(`Predictions disabled. ${error.message}. Quit Codex and run ccdx app codex prediction remove again to finish cleanup.`);
|
|
92
92
|
return { ...settings, enabled: false, cleanupPending: true };
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -171,7 +171,7 @@ export async function startNativePrediction({ env = process.env, platform = proc
|
|
|
171
171
|
const current = (options.resolveApp || installedPredictionApp)({ ...opts,
|
|
172
172
|
...(platform === "win32" && settings.app?.profile ? { preferredProfile: settings.app.profile } : {}) });
|
|
173
173
|
if (current.app !== settings.app?.app || (platform === "win32" && current.profile !== settings.app?.profile)) {
|
|
174
|
-
throw new Error("Codex App identity/profile changed; run ccdx prediction
|
|
174
|
+
throw new Error("Codex App identity/profile changed; run ccdx app codex prediction setup after quitting it to recheck compatibility");
|
|
175
175
|
}
|
|
176
176
|
const settingsFile = predictionPaths(opts).settings;
|
|
177
177
|
await withFileLock(`${settingsFile}.lock`, () => {
|
|
@@ -183,7 +183,7 @@ export async function startNativePrediction({ env = process.env, platform = proc
|
|
|
183
183
|
warning("Codex App compatibility rechecked; prediction port and trust were preserved");
|
|
184
184
|
}
|
|
185
185
|
const paths = predictionPaths({ ...opts, app: settings.app });
|
|
186
|
-
if (settings.store !== paths.store || !fs.existsSync(paths.store)) throw new Error("Prediction profile trust is unavailable; run ccdx prediction
|
|
186
|
+
if (settings.store !== paths.store || !fs.existsSync(paths.store)) throw new Error("Prediction profile trust is unavailable; run ccdx app codex prediction setup after quitting Codex");
|
|
187
187
|
const certificate = readPredictionCertificate(certificateDirectory(settings, paths), opts);
|
|
188
188
|
if (certificate.hash !== settings.certificateHash) throw new Error("Prediction certificate changed; setup must be checked again");
|
|
189
189
|
const [{ startPredictionTransport }, { applyNativePredictionOverlay, normalizeStatsigRequest }, { createProxyAgent }] = await Promise.all([
|
package/src/nightly-update.mjs
CHANGED
|
@@ -30,11 +30,11 @@ export function installedUpdateEnvironment(options = {}) {
|
|
|
30
30
|
if (inspectWindowsCommand({ packageRoot: environment.target }).status !== 'ready') throw new Error('command_not_owned');
|
|
31
31
|
} else {
|
|
32
32
|
const privateInstall = options.env?.CCDX_PRIVATE_INSTALL_PREFIX || process.env.CCDX_PRIVATE_INSTALL_PREFIX;
|
|
33
|
-
for (const name of ['ccdx'
|
|
33
|
+
for (const name of ['ccdx']) {
|
|
34
34
|
const file = path.join(environment.prefix,'bin',name);
|
|
35
35
|
if (privateInstall && path.resolve(privateInstall) === path.resolve(environment.prefix)) {
|
|
36
36
|
if (readBoundedFileSync(file,{encoding:'utf8',maxBytes:16384}) !== privateUnixLauncher({...environment,name})) throw new Error('command_not_owned');
|
|
37
|
-
} else if (fs.realpathSync(file) !== fs.realpathSync(path.join(environment.target,'bin',
|
|
37
|
+
} else if (fs.realpathSync(file) !== fs.realpathSync(path.join(environment.target,'bin','cli.mjs'))) throw new Error('command_not_owned');
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return { ...environment, npmCli: cli };
|
package/src/optional-routes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/time.js", "/animation.js", "/status.js", "/view-boundary.js", "/activity.js", "/flow.js", "/usage.js", "/ui.js", "/console.js", "/updates.js", "/preferences.js", "/icons.js", "/disclosure.js", "/tools.js", "/connections.js"]);
|
|
2
|
-
export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers", "/_ccdx/ui/settings", "/_ccdx/ui/m365/accounts", "/_ccdx/ui/updates", "/_ccdx/ui/account", "/_ccdx/ui/checks", "/_ccdx/ui/connections"]);
|
|
1
|
+
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/time.js", "/animation.js", "/status.js", "/view-boundary.js", "/activity.js", "/flow.js", "/usage.js", "/context.js", "/ui.js", "/console.js", "/updates.js", "/preferences.js", "/icons.js", "/disclosure.js", "/tools.js", "/connections.js"]);
|
|
2
|
+
export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers", "/_ccdx/ui/settings", "/_ccdx/ui/m365/accounts", "/_ccdx/ui/updates", "/_ccdx/ui/account", "/_ccdx/ui/checks", "/_ccdx/ui/connections", "/_ccdx/ui/context"]);
|
|
3
3
|
|
|
4
4
|
export function isOptionalRoute(method, pathname) {
|
|
5
5
|
return DASHBOARD_API_PATHS.has(pathname) || pathname === "/mcp/image"
|
package/src/provider-runtime.mjs
CHANGED
|
@@ -132,7 +132,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
|
|
|
132
132
|
return { ...result, binding: readM365Account(options) };
|
|
133
133
|
}
|
|
134
134
|
async function selectAccount(id) {
|
|
135
|
-
if (typeof id !== "string" || !/^[a-f0-9]{64}$/.test(id)) throw Object.assign(new Error("Use an account ID from ccdx m365 accounts"), { statusCode: 400 });
|
|
135
|
+
if (typeof id !== "string" || !/^[a-f0-9]{64}$/.test(id)) throw Object.assign(new Error("Use an account ID from ccdx source m365 accounts"), { statusCode: 400 });
|
|
136
136
|
if (!enabled) throw unavailable("m365_disabled");
|
|
137
137
|
if (activeM365Requests > 0 || gateway?.snapshot?.().active > 0 || pending) {
|
|
138
138
|
throw Object.assign(new Error(m365AccountMessage("m365_account_busy")), { code: "m365_account_busy", statusCode: 409 });
|
|
@@ -54,7 +54,7 @@ export function publicM365Accounts(accounts, { binding, windowsLogin } = {}) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export function m365AccountMessage(code) {
|
|
57
|
-
return ({ m365_account_ambiguous: "Choose a company account in Model sources or run ccdx m365 account.",
|
|
57
|
+
return ({ m365_account_ambiguous: "Choose a company account in Model sources or run ccdx source m365 account.",
|
|
58
58
|
m365_account_unavailable: "Company account unavailable. Connect it in Windows or macOS, then check again.",
|
|
59
59
|
m365_account_conflict: "Account records conflict. Check your company sign-in, then check again.",
|
|
60
60
|
m365_interaction_required: "Complete your company sign-in, then check again.",
|
package/src/release-install.mjs
CHANGED
|
@@ -85,26 +85,22 @@ export function packageMetadata(bytes, { complete = false } = {}) {
|
|
|
85
85
|
if (metadata?.name !== "codex-copilot-dx" || !stableVersion(metadata.version)) throw new Error("Release package identity is invalid");
|
|
86
86
|
return metadata;
|
|
87
87
|
}
|
|
88
|
-
export function runtimeReleaseTarget({ platform = process.platform, arch = process.arch
|
|
89
|
-
if (!["darwin", "win32"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return `${platform}-${arch}-${libc}`;
|
|
88
|
+
export function runtimeReleaseTarget({ platform = process.platform, arch = process.arch } = {}) {
|
|
89
|
+
if (!["darwin", "win32"].includes(platform) || !["x64", "arm64"].includes(arch)) {
|
|
90
|
+
throw new Error("CCDX supports macOS and Windows on x64 or arm64");
|
|
91
|
+
}
|
|
92
|
+
return `${platform}-${arch}`;
|
|
94
93
|
}
|
|
95
94
|
export function remoteDownloadDenied(error) {
|
|
96
95
|
return error?.npmCode === "EALLOWREMOTE" || /(?:^|\n)npm (?:error|ERR!) code EALLOWREMOTE(?:\r?\n|$)/.test(String(error?.stderr || ""));
|
|
97
96
|
}
|
|
98
|
-
export async function downloadRelease(tag, { fetchImpl = fetch, directory, signal, complete = false, preferComplete = false, platform, arch
|
|
97
|
+
export async function downloadRelease(tag, { fetchImpl = fetch, directory, signal, complete = false, preferComplete = false, platform, arch } = {}) {
|
|
98
|
+
const target = runtimeReleaseTarget({ platform, arch });
|
|
99
99
|
const version = stableVersion(tag);if (!version) throw new Error("A valid stable GitHub release tag is required");
|
|
100
100
|
const base = `${RELEASE_BASE}/v${version}`;
|
|
101
101
|
const manifest = await releaseBytes(`${base}/SHA256SUMS`, { fetchImpl, maxBytes: 65536, signal });
|
|
102
|
-
let name = `codex-copilot-dx-${version}.tgz
|
|
102
|
+
let name = `codex-copilot-dx-${version}.tgz`;
|
|
103
103
|
if (complete || preferComplete) {
|
|
104
|
-
if (complete) target = runtimeReleaseTarget({ platform, arch, libc });
|
|
105
|
-
else {
|
|
106
|
-
try { target = runtimeReleaseTarget({ platform, arch, libc }); } catch { /* Other platforms retain the source-only bootstrap path. */ }
|
|
107
|
-
}
|
|
108
104
|
if (target) {
|
|
109
105
|
const runtimeName = `codex-copilot-dx-${version}-${target}.tgz`;
|
|
110
106
|
if (complete || manifest.toString("utf8").split(/\r?\n/).some(line => line.endsWith(` ${runtimeName}`))) { name = runtimeName;complete = true; }
|
|
@@ -191,14 +187,14 @@ export function verifyPackageRuntime(target, version, { brokerRequired = false }
|
|
|
191
187
|
|
|
192
188
|
export function privateUnixLauncher({ prefix, target, name, node = process.execPath }) {
|
|
193
189
|
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
194
|
-
const cli = path.join(target, "bin",
|
|
190
|
+
const cli = path.join(target, "bin", "cli.mjs");
|
|
195
191
|
return `#!/bin/sh\nPATH=${quote(path.dirname(node))}:"$PATH"\nexport PATH\nCCDX_PRIVATE_INSTALL_PREFIX=${quote(prefix)}\nexport CCDX_PRIVATE_INSTALL_PREFIX\nif [ -z "\${npm_config_prefix:-}\${NPM_CONFIG_PREFIX:-}" ]; then npm_config_prefix=${quote(prefix)}; export npm_config_prefix; fi\nexec ${quote(node)} ${quote(cli)} "$@"\n`;
|
|
196
192
|
}
|
|
197
193
|
export async function writePrivateLaunchers({ prefix, target }) {
|
|
198
194
|
const windows = process.platform === "win32"
|
|
199
195
|
? await import(pathToFileURL(path.join(target, "src", "windows-command.mjs")).href) : null;
|
|
200
|
-
for (const name of ["ccdx"
|
|
201
|
-
const cli = path.join(target, "bin",
|
|
196
|
+
for (const name of ["ccdx"]) {
|
|
197
|
+
const cli = path.join(target, "bin", "cli.mjs");
|
|
202
198
|
if (windows) {
|
|
203
199
|
fs.writeFileSync(path.join(prefix, `${name}.cmd`), windows.privateWindowsCommand({ node: process.execPath, cli, prefix }));
|
|
204
200
|
} else {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defaultGithubProvider } from "./providers/github.mjs";
|
|
2
|
+
import { observeContextSession } from "./context-metrics.mjs";
|
|
2
3
|
import {
|
|
3
4
|
createRequestAbort,
|
|
4
5
|
logRequestFailure,
|
|
@@ -218,6 +219,7 @@ export function createResponsesHandler(options) {
|
|
|
218
219
|
if (provider.id !== "github") openAIModelEnv = { ...openAIModelEnv, CCDX_AUTO_REVIEW_MODEL: "" };
|
|
219
220
|
}
|
|
220
221
|
options.validateConversation?.(parsed, req.headers, provider);
|
|
222
|
+
observeContextSession(parsed, req.headers, provider);
|
|
221
223
|
activeDeadline = now() + upstreamTimeoutMs;
|
|
222
224
|
activeTimeoutReason = "responses_prepare_timeout";
|
|
223
225
|
abort.setTimeout(upstreamTimeoutMs, "responses_prepare_timeout");
|
|
@@ -503,6 +505,7 @@ export function createResponsesCompactHandler(options) {
|
|
|
503
505
|
if (provider.id !== "github") openAIModelEnv = { ...openAIModelEnv, CCDX_AUTO_REVIEW_MODEL: "" };
|
|
504
506
|
}
|
|
505
507
|
options.validateConversation?.(parsed, req.headers, provider);
|
|
508
|
+
observeContextSession(parsed, req.headers, provider);
|
|
506
509
|
activeDeadline = now() + upstreamTimeoutMs;
|
|
507
510
|
activeTimeoutReason = "responses_prepare_timeout";
|
|
508
511
|
abort.setTimeout(upstreamTimeoutMs, "responses_prepare_timeout");
|
package/src/startup-ui.mjs
CHANGED
|
@@ -55,17 +55,21 @@ export function createStartupPresentation({ output = process.stdout, errorOutput
|
|
|
55
55
|
return { enabled, warnings, finish: clear,
|
|
56
56
|
log(method, args) {
|
|
57
57
|
const message = redactDiagnosticText(format(...args));
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
for (const line of message.split("\n")) {
|
|
59
|
+
const warning = method === "error" || method === "warn" || /^\s*\[(?:WARN|ERR)\]/.test(line);
|
|
60
|
+
const check = /^\[(?:OK|INFO|WAIT)\]\s+([A-Za-z-]+)\s+(.*)$/.exec(line);
|
|
61
|
+
if (!enabled || warning || !check || ["Sign-in", "GitHub"].includes(check[1]) && !/GitHub token found|saved sign-in/i.test(check[2])) {
|
|
62
|
+
clear();
|
|
63
|
+
(warning ? errorOutput : output).write(line + "\n");
|
|
64
|
+
if (warning && warnings.length < 100) warnings.push([method, [line]]);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const scope = ["App", "Config", "Suggestions", "Images"].includes(check[1]) ? "Codex" : check[1] === "Claude" ? "Apps" : check[1];
|
|
68
|
+
let text = `Starting · ${scope}`;
|
|
69
|
+
if (["Service", "Models", "Sources", "M365"].includes(scope)) text += ` · ${check[2]}`;
|
|
70
|
+
while (displayWidth(text) >= (output.columns || 80)) text = [...text].slice(0, -1).join("");
|
|
71
|
+
clear();output.write(`\r\x1b[2K${text}`);visible = true;
|
|
63
72
|
}
|
|
64
|
-
const scope = ["App", "Config", "Suggestions", "Images"].includes(check[1]) ? "Codex" : check[1] === "Claude" ? "Apps" : check[1];
|
|
65
|
-
let text = `Starting · ${scope}`;
|
|
66
|
-
if (["Service", "Models", "Sources", "M365"].includes(scope)) text += ` · ${check[2]}`;
|
|
67
|
-
while (displayWidth(text) >= (output.columns || 80)) text = [...text].slice(0, -1).join("");
|
|
68
|
-
clear();output.write(`\r\x1b[2K${text}`);visible = true;
|
|
69
73
|
},
|
|
70
74
|
};
|
|
71
75
|
}
|
|
@@ -81,7 +85,7 @@ export function predictionStartupCheck(prediction) {
|
|
|
81
85
|
const warning = prediction.bridge !== "running" || problem || prediction.launch_route === "unverified";
|
|
82
86
|
const lines = [startupCheck(warning ? "warn" : "info", "Suggestions", detail)];
|
|
83
87
|
if (prediction.bridge !== "running" && prediction.reason) lines.push(startupCheck("warn", "Reason", prediction.reason));
|
|
84
|
-
if (warning) lines.push(startupCheck("info", "Details", "ccdx prediction status"));
|
|
88
|
+
if (warning) lines.push(startupCheck("info", "Details", "ccdx app codex prediction status"));
|
|
85
89
|
return lines.join("\n");
|
|
86
90
|
}
|
|
87
91
|
|
|
@@ -2,6 +2,7 @@ import { performance } from "node:perf_hooks";
|
|
|
2
2
|
import { currentRequestContext } from "./request-context.mjs";
|
|
3
3
|
import { isProviderId } from "./provider-metadata.mjs";
|
|
4
4
|
import { applicationLabel } from "./request-application.mjs";
|
|
5
|
+
import { createContextMetrics } from "./context-metrics.mjs";
|
|
5
6
|
|
|
6
7
|
const PERFORMANCE_ROUTES = Object.freeze(["responses", "responses_compact"]);
|
|
7
8
|
const PREPARATION_STAGES = Object.freeze(["admission", "body", "history", "images", "serialization"]);
|
|
@@ -215,6 +216,7 @@ function routeSnapshot(route) {
|
|
|
215
216
|
export function createStreamPerformanceMetrics({ now = () => performance.now(), wallNow = () => new Date().toISOString(), routeNames = PERFORMANCE_ROUTES } = {}) {
|
|
216
217
|
const routes = Object.fromEntries(routeNames.map((name) => [name, createRoutePerformance()]));
|
|
217
218
|
const recentRequests = [];
|
|
219
|
+
const contexts = createContextMetrics();
|
|
218
220
|
const activeRequests = new Map();
|
|
219
221
|
let activeTotal = 0, activeSequence = 0;
|
|
220
222
|
|
|
@@ -234,6 +236,8 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
|
|
|
234
236
|
let failed = false;
|
|
235
237
|
let finished = false;
|
|
236
238
|
let model = "other";
|
|
239
|
+
let session = null;
|
|
240
|
+
let cachedInput = null;
|
|
237
241
|
let provider = null;
|
|
238
242
|
let sourceStats = null;
|
|
239
243
|
let terminalOutcome = null;
|
|
@@ -323,10 +327,12 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
|
|
|
323
327
|
model = modelLabel(value, configured);
|
|
324
328
|
},
|
|
325
329
|
setProvider: assignProvider,
|
|
330
|
+
observeSession(key) { if (!finished && typeof key === "string" && /^[a-f0-9]{64}$/.test(key)) session = key; },
|
|
326
331
|
attemptCount() { return attempts; },
|
|
327
332
|
attemptTimings() { return attemptTimings.map(attempt => ({ ...attempt })); },
|
|
328
333
|
observeContext(values) {
|
|
329
334
|
if (finished || !values || typeof values !== "object") return;
|
|
335
|
+
if (Number.isSafeInteger(values.cached_input_tokens) && values.cached_input_tokens >= 0) cachedInput = values.cached_input_tokens;
|
|
330
336
|
for (const key of [...Object.keys(context), "capability_revision", "capability_constraints"]) {
|
|
331
337
|
const value = values[key];
|
|
332
338
|
if (["capability_revision", "capability_constraints"].includes(key)) {
|
|
@@ -379,6 +385,8 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
|
|
|
379
385
|
for (const stage of PREPARATION_STAGES) observe(sourceStats.preparation[stage], preparationMs[stage]);
|
|
380
386
|
}
|
|
381
387
|
const finishedAt = now();
|
|
388
|
+
contexts.record({ session, application: client, provider, model, route: routeName, at, started: requestStartedAt,
|
|
389
|
+
finished: finishedAt, request_id: safeRequestId, outcome, context, cached_input_tokens: cachedInput });
|
|
382
390
|
// Only scalar, allowlisted metadata survives the request; never retain payloads.
|
|
383
391
|
recentRequests.push({
|
|
384
392
|
request_id: safeRequestId, application: client,
|
|
@@ -427,6 +435,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
|
|
|
427
435
|
},
|
|
428
436
|
};
|
|
429
437
|
},
|
|
438
|
+
contextSnapshot: () => contexts.snapshot(),
|
|
430
439
|
snapshot() {
|
|
431
440
|
return {
|
|
432
441
|
by_route: Object.fromEntries(routeNames.map((name) => [name, routeSnapshot(routes[name])])),
|
package/src/terminal-console.mjs
CHANGED
|
@@ -79,20 +79,21 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
79
79
|
if (dirty) {
|
|
80
80
|
const usage = data.runtime_usage || {}, view = projection;
|
|
81
81
|
const heading = readFailed ? updatedAt === null ? "Status unavailable" : `Previous data / ${new Date(updatedAt).toLocaleTimeString("en-GB")}`
|
|
82
|
-
:
|
|
82
|
+
: `Running · up ${terminalUptime(data.uptime_ms)}`;
|
|
83
|
+
const webAddress = baseUrl ? `Web UI: ${baseUrl}` : "Web UI: address unavailable";
|
|
83
84
|
const sourceHeader = view.sources ? `Enabled sources: ${view.sources.length}` : "Enabled sources: unknown";
|
|
84
85
|
const appSize = width < 64 ? 13 : 15, setupSize = Math.max(10, Math.min(20, width - appSize - 7));
|
|
85
86
|
const appRows = view.clients.map(client => `${clip(client.name, appSize - 1).padEnd(appSize)}${clip(client.setup, setupSize - 1).padEnd(setupSize)}${String(readFailed || client.active === null ? "—" : client.active).padStart(6)}`);
|
|
86
87
|
const issue = view.issue?.label;
|
|
87
88
|
const notice = notices ? `${notices} ${notices === 1 ? "notice" : "notices"}${issue ? ` · last model issue: ${issue}` : " · ccdx status --details"}` : issue ? `Last model issue: ${issue}` : "No notices";
|
|
88
|
-
content = [clip(heading, width), sourceHeader,
|
|
89
|
+
content = [clip(heading, width), clip(webAddress, width), sourceHeader,
|
|
89
90
|
...(view.sources ? wrap(view.sources.map(source => source.name).join(" · "), width) : []),
|
|
90
91
|
`${"App".padEnd(appSize)}${"Setup".padEnd(setupSize)}${"Active".padStart(6)}`, ...appRows,
|
|
91
92
|
...table(width, usage, view.requests, readFailed ? null : view.active, key => view.outcomes[key]),
|
|
92
|
-
clip("
|
|
93
|
+
clip("Help: ccdx help · Stop: Ctrl+C", width), clip(notice, width)];
|
|
93
94
|
if (content.length + 1 >= (Number(output.rows) || 24)) {
|
|
94
95
|
const grouped = Object.entries(view.clients.reduce((counts, client) => ({ ...counts, [client.setup]: (counts[client.setup] || 0) + 1 }), {})).map(([state, count]) => `${count} ${state.toLowerCase()}`).join(" · ");
|
|
95
|
-
content = [clip(heading, width), sourceHeader, clip(`Apps: ${grouped}`, width),
|
|
96
|
+
content = [clip(readFailed ? heading : webAddress, width), sourceHeader, clip(`Apps: ${grouped}`, width),
|
|
96
97
|
...table(width, usage, view.requests, readFailed ? null : view.active, key => view.outcomes[key], true), clip(notice, width)];
|
|
97
98
|
}
|
|
98
99
|
dirty = false;
|
package/src/terminal-state.mjs
CHANGED
|
@@ -4,7 +4,7 @@ const integer = value => Number.isSafeInteger(value) && value >= 0;
|
|
|
4
4
|
const appIds = { codex_app: "codex", codex_cli: "codex", codex: "codex", claude_app: "claude_app", claude_code: "claude_code" };
|
|
5
5
|
export const TERMINAL_CLIENT_NAMES = Object.freeze({ codex: "Codex", claude_app: "Claude App", claude_code: "Claude Code" });
|
|
6
6
|
const labels = { configured: "Configured", paused: "Paused", disabled: "Disabled", not_configured: "Not configured", not_installed: "Not installed",
|
|
7
|
-
preserved: "
|
|
7
|
+
preserved: "Unchanged", partially_preserved: "Partly unchanged", manual_sync: "Manual sync", default_unavailable: "Default unavailable", configuration_unavailable: "Unreadable", unavailable: "Unavailable" };
|
|
8
8
|
export function terminalUptime(milliseconds) {
|
|
9
9
|
if (!Number.isFinite(milliseconds) || milliseconds < 0) return "unknown";
|
|
10
10
|
const minutes = Math.floor(milliseconds / 60000), hours = Math.floor(minutes / 60), days = Math.floor(hours / 24);
|
package/src/usage-store.mjs
CHANGED
|
@@ -223,7 +223,8 @@ export function recordUsage(record) {
|
|
|
223
223
|
|
|
224
224
|
export function recordResponsesUsage(args) {
|
|
225
225
|
const response = args.response || args.event?.response || args.event;
|
|
226
|
-
markRequestObservation({ input_tokens: response?.usage?.input_tokens
|
|
226
|
+
markRequestObservation({ input_tokens: response?.usage?.input_tokens,
|
|
227
|
+
cached_input_tokens: response?.usage?.input_tokens_details?.cached_tokens ?? response?.usage?.cached_input_tokens });
|
|
227
228
|
return recordUsage(buildResponsesUsageRecord(args));
|
|
228
229
|
}
|
|
229
230
|
|
package/src/usage.mjs
CHANGED
|
@@ -36,28 +36,28 @@ function cacheHitPercent(usage) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function providerSummaryLines(summary) {
|
|
39
|
-
if (summary.provider_filter) return [`Provider: ${summary.provider_filter}`];
|
|
39
|
+
if (summary.provider_filter) return [`Provider: ${terminalCell(summary.provider_filter)}`];
|
|
40
40
|
const sources = Object.entries(summary.providers || {}).filter(([, count]) => count > 0);
|
|
41
41
|
return sources.some(([id]) => id !== "github")
|
|
42
|
-
? [`Providers: ${sources.map(([id, count]) => `${id} ${fmt(count)}`).join(" / ")} (combined totals; use --provider to separate)`] : [];
|
|
42
|
+
? [`Providers: ${sources.map(([id, count]) => `${terminalCell(id)} ${fmt(count)}`).join(" / ")} (combined totals; use --provider to separate)`] : [];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function formatPlainUsageSummary(summary, filePath, { sanitize = false } = {}) {
|
|
46
|
-
const lines = [`Usage log: ${filePath}`];
|
|
46
|
+
const lines = [`Usage log: ${terminalCell(filePath)}`];
|
|
47
47
|
lines.push(...providerSummaryLines(summary));
|
|
48
48
|
if (summary.requests === 0) {
|
|
49
49
|
lines.push("No usage records yet.");
|
|
50
50
|
return (sanitize ? lines.map((line) => terminalCell(line, { fallback: "" })) : lines).join("\n");
|
|
51
51
|
}
|
|
52
52
|
lines.push(
|
|
53
|
-
`
|
|
53
|
+
`Records: ${fmt(summary.requests)}`,
|
|
54
54
|
`Tokens: input=${fmt(summary.totals.input_tokens)} cache_read=${fmt(cacheReadTokens(summary.totals))} output=${fmt(summary.totals.output_tokens)} total=${fmt(summary.totals.total_tokens)}`,
|
|
55
55
|
`Cache hit: ${cacheHitPercent(summary.totals)} (cached/input tokens)`,
|
|
56
56
|
"",
|
|
57
57
|
"By model:",
|
|
58
58
|
);
|
|
59
59
|
for (const [model, row] of Object.entries(usageModelGroups(summary))) {
|
|
60
|
-
lines.push(` ${model}:
|
|
60
|
+
lines.push(` ${terminalCell(model)}: records=${fmt(row.requests)} input=${fmt(row.input_tokens)} cache_read=${fmt(cacheReadTokens(row))} output=${fmt(row.output_tokens)} total=${fmt(row.total_tokens)} cache_hit=${cacheHitPercent(row)}`);
|
|
61
61
|
}
|
|
62
62
|
return (sanitize ? lines.map((line) => terminalCell(line, { fallback: "" })) : lines).join("\n");
|
|
63
63
|
}
|
package/src/windows-command.mjs
CHANGED
|
@@ -56,13 +56,13 @@ export function inspectWindowsCommand({ platform = process.platform,
|
|
|
56
56
|
try {
|
|
57
57
|
const pkg = JSON.parse(readBoundedFileSync(path.join(root, "package.json"), { encoding: "utf8", maxBytes: 64 * 1024 }));
|
|
58
58
|
if (pkg.name !== "codex-copilot-dx" || pkg.bin?.ccdx !== "bin/cli.mjs"
|
|
59
|
-
|
|
59
|
+
) throw new Error();
|
|
60
60
|
} catch { return { status: "preserved", changed: false }; }
|
|
61
61
|
if (repair && !locked) return withFileLockSync(path.join(root, ".ccdx-command.lock"),
|
|
62
62
|
() => inspectWindowsCommand({ platform, packageRoot, repair, locked: true }), { timeoutMs: 1000 });
|
|
63
63
|
const prefix = path.dirname(path.dirname(root));
|
|
64
64
|
const results = [];
|
|
65
|
-
for (const [name, script] of [["ccdx", "cli.mjs"]
|
|
65
|
+
for (const [name, script] of [["ccdx", "cli.mjs"]]) {
|
|
66
66
|
const ps1 = path.join(prefix, `${name}.ps1`), cmd = path.join(prefix, `${name}.cmd`);
|
|
67
67
|
const target = `node_modules/codex-copilot-dx/bin/${script}`;
|
|
68
68
|
try {
|
package/bin/codex-copilot-dx.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const configDoctor = ["doctor", "--doctor"].includes(process.argv[2]) && process.argv[3] === "config";
|
|
4
|
-
if (process.stderr.isTTY === true && !configDoctor) {
|
|
5
|
-
const {
|
|
6
|
-
LEGACY_COMMAND_WARNING,
|
|
7
|
-
shouldShowLegacyCommandWarning,
|
|
8
|
-
} = await import("../src/legacy-command-warning.mjs");
|
|
9
|
-
if (shouldShowLegacyCommandWarning({ interactive: true })) console.warn(LEGACY_COMMAND_WARNING);
|
|
10
|
-
}
|
|
11
|
-
await import("./cli.mjs");
|
package/src/cli-models.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { status } from "./status.mjs";
|
|
2
|
-
import {
|
|
3
|
-
cliOutputFormat,
|
|
4
|
-
cliOutputWidth,
|
|
5
|
-
formatResponsiveCliTable,
|
|
6
|
-
terminalCell,
|
|
7
|
-
} from "./cli-table.mjs";
|
|
8
|
-
|
|
9
|
-
export { fetchLiveCopilotModels, selectableCopilotModels } from "./live-models.mjs";
|
|
10
|
-
|
|
11
|
-
function safeText(value, fallback = "") {
|
|
12
|
-
const text = String(value ?? "")
|
|
13
|
-
.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ")
|
|
14
|
-
.replace(/\s+/g, " ")
|
|
15
|
-
.trim();
|
|
16
|
-
return text || fallback;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function liveCatalogHeader(catalog, { commandName, models }) {
|
|
20
|
-
const responses = models.filter((model) => model.endpoints.includes("responses")).length;
|
|
21
|
-
const chat = models.filter((model) => model.endpoints.includes("chat")).length;
|
|
22
|
-
return [
|
|
23
|
-
`${commandName} models`,
|
|
24
|
-
status("ok", catalog?.source === "configured" ? `Configured models from ${safeText(catalog.upstreamHost)}: ${models.length}; access not checked`
|
|
25
|
-
: `${catalog?.source === "catalog" ? "Available catalog" : "Live catalog"} from ${safeText(catalog?.upstreamHost, "GitHub Copilot")}: ${models.length} selectable GPT models of ${Number(catalog?.advertised) || 0} advertised`),
|
|
26
|
-
status("info", `Responses: ${responses}; Chat: ${chat}`),
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function formatLiveCopilotModelsPlain(catalog, { commandName, models }, { sanitize = false } = {}) {
|
|
31
|
-
const lines = liveCatalogHeader(catalog, { commandName, models });
|
|
32
|
-
if (!models.length) {
|
|
33
|
-
lines.push(status("warn", "No selectable GPT models listed."));
|
|
34
|
-
return (sanitize ? lines.map((line) => terminalCell(line, { fallback: "" })) : lines).join("\n");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let vendor = "";
|
|
38
|
-
for (const model of models) {
|
|
39
|
-
if (model.vendor !== vendor) {
|
|
40
|
-
vendor = model.vendor;
|
|
41
|
-
lines.push("", `${vendor}:`);
|
|
42
|
-
}
|
|
43
|
-
const flags = [...model.endpoints, ...(model.preview ? ["preview"] : [])];
|
|
44
|
-
lines.push(` ${model.id} [${flags.join(", ")}]`);
|
|
45
|
-
}
|
|
46
|
-
return (sanitize ? lines.map((line) => terminalCell(line, { fallback: "" })) : lines).join("\n");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function formatLiveCopilotModels(catalog, {
|
|
50
|
-
commandName = "ccdx",
|
|
51
|
-
format = "plain",
|
|
52
|
-
output = process.stdout,
|
|
53
|
-
width = cliOutputWidth(output),
|
|
54
|
-
} = {}) {
|
|
55
|
-
const models = Array.isArray(catalog?.models) ? catalog.models : [];
|
|
56
|
-
const context = { commandName, models };
|
|
57
|
-
if (cliOutputFormat(format, output) === "plain") {
|
|
58
|
-
return formatLiveCopilotModelsPlain(catalog, context);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const lines = liveCatalogHeader(catalog, context);
|
|
62
|
-
if (!models.length) {
|
|
63
|
-
lines.push(status("warn", "No selectable GPT models listed."));
|
|
64
|
-
return lines.join("\n");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const rows = models.map((model) => ({
|
|
68
|
-
vendor: model.vendor,
|
|
69
|
-
model: model.id,
|
|
70
|
-
vendorModel: `${model.vendor}/${model.id}`,
|
|
71
|
-
apis: model.endpoints.join(", "),
|
|
72
|
-
preview: model.preview ? "yes" : "no",
|
|
73
|
-
}));
|
|
74
|
-
const table = formatResponsiveCliTable({
|
|
75
|
-
columns: [
|
|
76
|
-
{ key: "vendor", label: "VENDOR" },
|
|
77
|
-
{ key: "model", label: "MODEL" },
|
|
78
|
-
{ key: "apis", label: "APIS" },
|
|
79
|
-
{ key: "preview", label: "PREVIEW" },
|
|
80
|
-
],
|
|
81
|
-
compactColumns: [
|
|
82
|
-
{ key: "vendorModel", label: "VENDOR/MODEL" },
|
|
83
|
-
{ key: "apis", label: "APIS" },
|
|
84
|
-
{ key: "preview", label: "PREVIEW" },
|
|
85
|
-
],
|
|
86
|
-
rows,
|
|
87
|
-
width,
|
|
88
|
-
});
|
|
89
|
-
if (format === "auto" && table.overflow) {
|
|
90
|
-
return formatLiveCopilotModelsPlain(catalog, context, { sanitize: true });
|
|
91
|
-
}
|
|
92
|
-
lines.push("", table.output);
|
|
93
|
-
return lines.join("\n");
|
|
94
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { atomicWriteFileSync } from "./atomic-file.mjs";
|
|
5
|
-
|
|
6
|
-
export const LEGACY_COMMAND_WARNING_INTERVAL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
7
|
-
export const LEGACY_COMMAND_WARNING = "codex-copilot-dx is deprecated; use ccdx instead. The compatibility alias will be removed in a future breaking release.";
|
|
8
|
-
|
|
9
|
-
export function legacyCommandWarningPath({ env = process.env, home = os.homedir() } = {}) {
|
|
10
|
-
const xdgCacheHome = String(env.XDG_CACHE_HOME || "").trim();
|
|
11
|
-
const cacheRoot = xdgCacheHome || path.join(home, ".cache");
|
|
12
|
-
return path.join(cacheRoot, "codex-copilot-dx", "legacy-command-warning");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function shouldShowLegacyCommandWarning({
|
|
16
|
-
env = process.env,
|
|
17
|
-
home = os.homedir(),
|
|
18
|
-
interactive = process.stderr.isTTY === true,
|
|
19
|
-
now = Date.now(),
|
|
20
|
-
} = {}) {
|
|
21
|
-
if (!interactive) return false;
|
|
22
|
-
const filePath = legacyCommandWarningPath({ env, home });
|
|
23
|
-
try {
|
|
24
|
-
const previous = Number.parseInt(fs.readFileSync(filePath, "utf8"), 10);
|
|
25
|
-
if (Number.isFinite(previous) && Math.abs(now - previous) < LEGACY_COMMAND_WARNING_INTERVAL_MS) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
// A missing or unreadable cache must not prevent the compatibility command.
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
atomicWriteFileSync(filePath, `${now}\n`, { mode: 0o600 });
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
// Stay silent when the throttle cannot persist, otherwise every invocation would warn.
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|