codex-copilot-dx 1.2.32 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -113
- package/bin/cli.mjs +61 -103
- package/docs/ARCHITECTURE.md +51 -3
- package/docs/README.md +9 -76
- package/docs/REFERENCE.md +137 -1827
- package/package.json +11 -4
- package/src/access-settings.mjs +2 -2
- package/src/adapter.mjs +1 -1
- package/src/auth-credentials.mjs +1 -1
- package/src/auto-review-model.mjs +2 -2
- 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 +325 -0
- package/src/cli-image.mjs +4 -4
- package/src/cli-limits.mjs +2 -2
- package/src/cli-m365.mjs +1 -1
- package/src/cli-management.mjs +344 -0
- package/src/cli-options.mjs +73 -443
- package/src/cli-status.mjs +7 -7
- package/src/cli-tools.mjs +3 -2
- package/src/client-integration.mjs +7 -3
- package/src/config.mjs +4 -3
- package/src/connection-runtime.mjs +1414 -350
- package/src/copilot-token-session.mjs +1 -1
- package/src/dashboard/connections.js +23 -4
- package/src/dashboard/ui.css +9 -2
- package/src/dashboard-api.mjs +5 -5
- 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/provider-runtime.mjs +1 -1
- package/src/providers/m365-accounts.mjs +1 -1
- package/src/release-install.mjs +11 -15
- package/src/service-control.mjs +1 -1
- package/src/settings-preferences.mjs +6 -4
- package/src/startup-ui.mjs +34 -2
- package/src/terminal-console.mjs +32 -30
- package/src/terminal-state.mjs +69 -0
- 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
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { terminalCell } from "./terminal-text.mjs";
|
|
2
|
+
|
|
3
|
+
const integer = value => Number.isSafeInteger(value) && value >= 0;
|
|
4
|
+
const appIds = { codex_app: "codex", codex_cli: "codex", codex: "codex", claude_app: "claude_app", claude_code: "claude_code" };
|
|
5
|
+
export const TERMINAL_CLIENT_NAMES = Object.freeze({ codex: "Codex", claude_app: "Claude App", claude_code: "Claude Code" });
|
|
6
|
+
const labels = { configured: "Configured", paused: "Paused", disabled: "Disabled", not_configured: "Not configured", not_installed: "Not installed",
|
|
7
|
+
preserved: "Unchanged", partially_preserved: "Partly unchanged", manual_sync: "Manual sync", default_unavailable: "Default unavailable", configuration_unavailable: "Unreadable", unavailable: "Unavailable" };
|
|
8
|
+
export function terminalUptime(milliseconds) {
|
|
9
|
+
if (!Number.isFinite(milliseconds) || milliseconds < 0) return "unknown";
|
|
10
|
+
const minutes = Math.floor(milliseconds / 60000), hours = Math.floor(minutes / 60), days = Math.floor(hours / 24);
|
|
11
|
+
return days ? `${days}d ${hours % 24}h` : hours ? `${hours}h ${minutes % 60}m` : `${minutes}m`;
|
|
12
|
+
}
|
|
13
|
+
export function clientSetup(client = {}) {
|
|
14
|
+
if (client.enabled === false) return "Disabled";
|
|
15
|
+
if (client.enabled && (Array.isArray(client.deployments) ? !client.deployments.length : client.source === null)) return "Paused";
|
|
16
|
+
return labels[client.setup] || "Not checked";
|
|
17
|
+
}
|
|
18
|
+
export function projectTerminalState(data = {}) {
|
|
19
|
+
const routes = data.requests?.by_route, names = ["responses", "responses_compact", "messages"];
|
|
20
|
+
const partialRoutes = routes && names.some(name => routes[name]);
|
|
21
|
+
const active = partialRoutes ? names.reduce((sum, name) => sum + (routes[name]?.active || 0), 0) : null;
|
|
22
|
+
const requests = partialRoutes ? names.reduce((sum, name) => sum + (routes[name]?.total || 0), 0) : null;
|
|
23
|
+
const claude = (data.providers?.claude || data.providers?.m365?.claude)?.requests?.performance;
|
|
24
|
+
const performance = [data.stream_performance, claude].filter(Boolean);
|
|
25
|
+
const outcomes = Object.fromEntries(["completed", "incomplete", "failed", "cancelled", "unknown"].map(key => [key,
|
|
26
|
+
performance.flatMap(part => Object.entries(part.by_route || {}).filter(([route]) => part === claude ? route === "messages" : ["responses", "responses_compact"].includes(route)).map(([, row]) => row.terminal_outcomes?.totals || {}))
|
|
27
|
+
.reduce((sum, row) => sum + (integer(row[key]) ? row[key] : 0), 0)]));
|
|
28
|
+
const activity = Object.hasOwn(data.model_activity || {}, "active") ? integer(data.model_activity.active) ? data.model_activity.active : null : active;
|
|
29
|
+
const running = [...new Map(performance.flatMap(part => (part.active_requests || []).filter(row => part === claude ? !row.route || row.route === "messages" : !row.route || ["responses", "responses_compact"].includes(row.route))).map((row, i) => [row.request_id || `unknown-${i}`, row])).values()];
|
|
30
|
+
const byApp = new Map();let unidentified = 0;
|
|
31
|
+
for (const row of running) {
|
|
32
|
+
const app = appIds[row.application];if (app) byApp.set(app, (byApp.get(app) || 0) + 1);else unidentified++;
|
|
33
|
+
}
|
|
34
|
+
const connection = data.providers?.connections, clientRows = connection?.clients;
|
|
35
|
+
const clients = (clientRows || [
|
|
36
|
+
{ id: "codex", setup: null },
|
|
37
|
+
...[["app", "claude_app"], ["code", "claude_code"]].map(([key, id]) => ({ id, setup: data.providers?.m365?.claude?.clients?.[key] })),
|
|
38
|
+
]).map(client => ({ id: client.id, name: TERMINAL_CLIENT_NAMES[client.id] || terminalCell(client.name || client.id),
|
|
39
|
+
setup: clientSetup(client.id === "codex" && !connection?.managed && !client.setup && data.client_integrations?.codex?.setup ? { ...client, setup: data.client_integrations.codex.setup } : client), active: running.length || active === 0 ? byApp.get(client.id) || 0 : null, observed_at: client.observed_at || null }));
|
|
40
|
+
if (integer(active) && active > running.length) unidentified += active - running.length;
|
|
41
|
+
if (unidentified) clients.push({ id: "other", name: "Other clients", setup: "Not identified", active: unidentified });
|
|
42
|
+
const sources = connection?.providers?.filter(item => item.enabled && !(item.id === "m365" && data.providers?.m365?.enabled === false)).map(item => ({ id: item.id, name: terminalCell(item.name || item.id) }))
|
|
43
|
+
|| (data.providers ? [{ id: "github", name: "GitHub Copilot" }, ...(data.providers.m365?.enabled ? [{ id: "m365", name: "Microsoft 365" }] : [])] : null);
|
|
44
|
+
const lastFailure = data.http_errors?.actionable_recent?.at(-1);
|
|
45
|
+
let issue = null;
|
|
46
|
+
if (lastFailure) {
|
|
47
|
+
const app = TERMINAL_CLIENT_NAMES[appIds[lastFailure.application]] || "Unidentified client";
|
|
48
|
+
const source = connection?.providers?.find(item => item.id === lastFailure.provider)?.name || ({ github: "GitHub Copilot", m365: "Microsoft 365" }[lastFailure.provider]) || lastFailure.provider || "Unknown source";
|
|
49
|
+
const causes = { m365_network_error: "Network request failed", m365_catalog_http_403: "Model catalog access denied", ccdx_api_model_unavailable: "Selected model is unavailable", ccdx_client_source_disabled: "Model access is paused" };
|
|
50
|
+
const message = causes[lastFailure.code] || (lastFailure.route === "messages_count_tokens" ? "Token-count check failed" : lastFailure.http_status === 401 ? "Sign-in was rejected" : lastFailure.http_status === 403 ? "Access was denied" : lastFailure.http_status === 429 ? "Request limit reached" : "Request failed");
|
|
51
|
+
issue = { label: `${terminalCell(app)} / ${terminalCell(source)}: ${message}`, request_id: lastFailure.request_id, application: lastFailure.application };
|
|
52
|
+
}
|
|
53
|
+
return { sources, clients, requests, active, activity, outcomes, issue };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function retainedRequests(data = {}) {
|
|
57
|
+
const claude = (data.providers?.claude || data.providers?.m365?.claude)?.requests?.performance;
|
|
58
|
+
const parts = [data.stream_performance, claude].filter(Boolean), rows = new Map();
|
|
59
|
+
for (const part of parts) {
|
|
60
|
+
for (const record of part.recent_requests || []) if (record.request_id) rows.set(record.request_id, { ...record, state: record.outcome || record.terminal_outcome || "unknown", active: false });
|
|
61
|
+
for (const record of part.active_requests || []) if (record.request_id) rows.set(record.request_id, { ...record, state: record.phase || "active", active: true });
|
|
62
|
+
}
|
|
63
|
+
for (const record of data.http_errors?.recent || data.http_errors?.actionable_recent || []) if (record.request_id) {
|
|
64
|
+
const existing = rows.get(record.request_id);
|
|
65
|
+
rows.set(record.request_id, { ...existing, ...record, error: true, active: existing?.active === true, state: ["cancelled", "incomplete"].includes(existing?.state) ? existing.state : "failed" });
|
|
66
|
+
}
|
|
67
|
+
const time = row => { const value = Date.parse(row.at || row.time || "");return Number.isFinite(value) ? value : 0; };
|
|
68
|
+
return [...rows.values()].sort((a, b) => Number(a.active) - Number(b.active) || time(a) - time(b));
|
|
69
|
+
}
|
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
|
-
}
|