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
|
@@ -128,7 +128,7 @@ export function createCopilotTokenSession({
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
if (usesDefaultTokenStore) return githubReauthMessage(reason, resolveHome(home));
|
|
131
|
-
return `${reason}\
|
|
131
|
+
return `${reason}\nReconnect the affected account in its application; other saved accounts were kept.`;
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
async function loadCredentials(home) {
|
|
@@ -144,9 +144,23 @@
|
|
|
144
144
|
const count = value => !value ? format("cap_unknown") : value >= 1000000 ? `${Number((value / 1000000).toFixed(2))}M` : value >= 1000 ? `${Number((value / 1000).toFixed(1))}K` : String(value);
|
|
145
145
|
const reasoningText = values => values.reasoning === false ? format("cap_unsupported") : values.reasoning_efforts?.length ? values.reasoning_efforts.join(" / ") : values.reasoning === true ? format("cap_supported") : format("cap_unknown");
|
|
146
146
|
const searchText = values => values.web_search === undefined ? format("cap_unknown") : values.web_search.length ? values.web_search.map(protocol => protocol === "messages" ? "Messages" : protocol === "responses" ? "Responses" : "Chat").join(" / ") : format("cap_unsupported");
|
|
147
|
-
function
|
|
147
|
+
function closeModelDetail() {
|
|
148
|
+
const detail = el("connection-model-detail");
|
|
149
|
+
const row = detail.closest(".connection-detail-row");
|
|
150
|
+
detail.hidden = true;
|
|
151
|
+
el("connection-models").closest("fieldset").append(detail);
|
|
152
|
+
row?.remove();
|
|
153
|
+
for (const button of el("connection-models").querySelectorAll("[data-model-details]")) button.setAttribute("aria-expanded", "false");
|
|
154
|
+
}
|
|
155
|
+
function modelDetail(model, modelRow, trigger) {
|
|
156
|
+
if (trigger.getAttribute("aria-expanded") === "true") { closeModelDetail();return; }
|
|
157
|
+
closeModelDetail();
|
|
148
158
|
const detail = el("connection-model-detail");detail.hidden = false;detail.replaceChildren();
|
|
149
|
-
const
|
|
159
|
+
const row = node("tr", undefined, "connection-detail-row"), cell = node("td");
|
|
160
|
+
cell.colSpan = modelRow.children.length;
|
|
161
|
+
cell.append(detail);row.append(cell);modelRow.after(row);
|
|
162
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
163
|
+
const heading = node("div", undefined, "panel-heading");heading.append(node("h3", model.id), button("close", () => { closeModelDetail();trigger.focus(); }));detail.append(heading);
|
|
150
164
|
const protocol = choice(model.protocols.map(id => ({ id, name: id === "messages" ? "Messages" : id === "responses" ? "Responses" : "Chat" })), model.protocols.includes("messages") ? "messages" : model.protocols[0], false);
|
|
151
165
|
protocol.setAttribute("aria-label", format("cap_api"));detail.append(protocol);
|
|
152
166
|
const status = node("p", undefined, "hint"), table = node("table"), body = node("tbody");table.append(body);detail.append(status, table);
|
|
@@ -196,7 +210,7 @@
|
|
|
196
210
|
override[key] = numeric.includes(key) ? Number(text) : flags.includes(key) ? text === "true" : arrays.includes(key) ? text === "[]" ? [] : text.split(/[,,]\s*/).filter(Boolean) : text;
|
|
197
211
|
}
|
|
198
212
|
model.capabilities = override;delete model.context_window;delete model.reasoning_efforts;modelRows();detail.hidden = true;message("cap_details_draft");
|
|
199
|
-
});advanced.append(save);
|
|
213
|
+
});advanced.append(save);
|
|
200
214
|
}
|
|
201
215
|
function syncPreview(preview) {
|
|
202
216
|
const c = client(editingClient), result = el("connection-sync-result");result.hidden = false;result.replaceChildren();
|
|
@@ -215,6 +229,7 @@
|
|
|
215
229
|
}
|
|
216
230
|
}
|
|
217
231
|
function modelRows() {
|
|
232
|
+
closeModelDetail();
|
|
218
233
|
const body = el("connection-models");body.replaceChildren();
|
|
219
234
|
for (const model of models) {
|
|
220
235
|
const tr = node("tr"), name = node("td"), apis = node("td"), actions = node("td"), group = node("div", undefined, "connection-checks");
|
|
@@ -233,7 +248,11 @@
|
|
|
233
248
|
}
|
|
234
249
|
const capability = resolved(model);
|
|
235
250
|
const context = node("td", count(capability.context_window)), reasoning = node("td", reasoningText(capability)), search = node("td", searchText(capability));
|
|
236
|
-
|
|
251
|
+
const details = button("cap_details", () => modelDetail(model, tr, details));
|
|
252
|
+
details.dataset.modelDetails = "";
|
|
253
|
+
details.setAttribute("aria-expanded", "false");
|
|
254
|
+
details.setAttribute("aria-controls", "connection-model-detail");
|
|
255
|
+
apis.append(group);actions.append(details, button("api_remove_model", () => { models = models.filter(item => item !== model);selectedModels.delete(model.id);modelRows(); }));tr.append(name, apis, context, reasoning, search, actions);body.append(tr);
|
|
237
256
|
}
|
|
238
257
|
}
|
|
239
258
|
function setEndpoints(base, endpoints) { for (const [api, path] of [["messages", "messages"], ["responses", "responses"], ["chat", "chat/completions"]]) apiForm.elements[api + "_url"].value = endpoints?.[api] || base.replace(/\/+$/, "") + "/" + path; }
|
package/src/dashboard/ui.css
CHANGED
|
@@ -207,12 +207,18 @@ footer { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; color:
|
|
|
207
207
|
.provider-tabs button, .install-platforms button { text-align: center; }
|
|
208
208
|
.provider-tabs [aria-selected="true"], .provider-tabs [aria-selected="true"]:hover, .install-platforms [aria-pressed="true"], .install-platforms [aria-pressed="true"]:hover { color: var(--page); border-color: var(--accent); background: var(--accent); }
|
|
209
209
|
.model-catalog table, .model-catalog td { color: var(--text); font-size: 13px; background: var(--surface); }
|
|
210
|
+
.model-catalog table { table-layout: fixed; }
|
|
211
|
+
.model-catalog th:first-child { width: 40%; }
|
|
212
|
+
.model-catalog th:nth-child(2) { width: 25%; }
|
|
213
|
+
.model-catalog th:last-child { width: 35%; }
|
|
214
|
+
.model-catalog td { white-space: normal; overflow-wrap: anywhere; vertical-align: top; }
|
|
210
215
|
.model-catalog th { color: var(--text); font-size: 12px; }
|
|
211
216
|
.model-catalog > summary h2 { color: var(--strong); }
|
|
212
217
|
.model-catalog .model-name { color: var(--strong); font-weight: 600; }
|
|
213
218
|
.model-catalog td:last-child { white-space: normal; }
|
|
214
219
|
.model-catalog td details { margin: 0; }
|
|
215
|
-
.model-catalog .failure-detail { min-width:
|
|
220
|
+
.model-catalog .failure-detail { min-width: 0; }
|
|
221
|
+
@media (max-width: 700px) { .model-catalog .failure-detail { grid-template-columns: minmax(0, 1fr); gap: 3px; } }
|
|
216
222
|
#provider-auth td, #provider-clients td { overflow-wrap: anywhere; }
|
|
217
223
|
.details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
218
224
|
@media (max-width: 700px) { .details { grid-template-columns: 1fr; } }
|
|
@@ -540,7 +546,8 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
540
546
|
/* Model capability and application binding controls share the existing palette. */
|
|
541
547
|
.client-segments { margin-bottom: 18px; }
|
|
542
548
|
.client-segments button[aria-pressed="true"], .binding-table button[aria-pressed="true"] { color: var(--page); background: var(--accent); border-color: var(--accent); }
|
|
543
|
-
#connection-model-detail { margin
|
|
549
|
+
#connection-model-detail { margin: 0; padding: 18px 0; }
|
|
550
|
+
.connection-detail-row > td { white-space: normal; }
|
|
544
551
|
#connection-model-detail h3 { overflow-wrap: anywhere; }
|
|
545
552
|
#connection-model-detail .connection-fields { margin-bottom: 18px; }
|
|
546
553
|
#connection-models td:last-child { min-width: 130px; }
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -42,10 +42,10 @@ function safeText(value, length = 160) {
|
|
|
42
42
|
function liveModelError(error) {
|
|
43
43
|
const message = String(error?.message || error || "");
|
|
44
44
|
const status = /\bHTTP (\d{3})\b/.exec(message)?.[1];
|
|
45
|
-
if (status) return `Live model lookup failed (HTTP ${status}). Run ccdx models for details.`;
|
|
46
|
-
if (/timed out/i.test(message)) return "Live model lookup timed out. Retry or run ccdx models.";
|
|
45
|
+
if (status) return `Live model lookup failed (HTTP ${status}). Run ccdx app codex models for details.`;
|
|
46
|
+
if (/timed out/i.test(message)) return "Live model lookup timed out. Retry or run ccdx app codex models.";
|
|
47
47
|
if (/GitHub token not found/i.test(message)) return "GitHub token not found. Start ccdx to sign in.";
|
|
48
|
-
return "Live model lookup failed. Run ccdx models for details.";
|
|
48
|
+
return "Live model lookup failed. Run ccdx app codex models for details.";
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function animationState(env, home, { includeFrames = false } = {}) {
|
|
@@ -252,7 +252,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
252
252
|
const query = new URL(req.url, "http://localhost").searchParams;
|
|
253
253
|
sendJson(res, 200, animationState(env, home, { includeFrames: query.get("frames") !== "0" }));
|
|
254
254
|
} catch {
|
|
255
|
-
sendJson(res, 409, { error: "Animation settings are invalid; inspect them with ccdx animation" });
|
|
255
|
+
sendJson(res, 409, { error: "Animation settings are invalid; inspect them with ccdx config animation" });
|
|
256
256
|
}
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
@@ -286,7 +286,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
286
286
|
applyAnimation?.(body.theme);
|
|
287
287
|
sendJson(res, 200, { changed: result.changed, ...animationState(env, home) });
|
|
288
288
|
} catch {
|
|
289
|
-
sendJson(res, 409, { error: "Animation setting was not saved; check ccdx animation" });
|
|
289
|
+
sendJson(res, 409, { error: "Animation setting was not saved; check ccdx config animation" });
|
|
290
290
|
}
|
|
291
291
|
return;
|
|
292
292
|
}
|
package/src/doctor.mjs
CHANGED
|
@@ -224,11 +224,11 @@ export async function collectDoctorChecks({
|
|
|
224
224
|
const environment = inspectPredictionEnvironmentFn({ env, platform });
|
|
225
225
|
checks.push({ kind: environment.summary.tls.extra_ca === "unreadable_or_invalid" ? "warn" : "info", message: formatPredictionEnvironment(environment.summary) });
|
|
226
226
|
} else checks.push({ kind: "warn", message: "Native predictions require macOS or Windows; existing settings preserved" });
|
|
227
|
-
} catch { checks.push({ kind: "warn", message: "Prediction environment could not be verified; existing routing and trust settings preserved", fix: "ccdx prediction status" }); }
|
|
227
|
+
} catch { checks.push({ kind: "warn", message: "Prediction environment could not be verified; existing routing and trust settings preserved", fix: "ccdx app codex prediction status" }); }
|
|
228
228
|
try {
|
|
229
229
|
const image = readImageProviderConfigFn({ home, env, strict: true });
|
|
230
230
|
checks.push({ kind: "info", message: image ? "Image generation configured; no provider request was made" : "Image generation is off; optional checks skipped" });
|
|
231
|
-
} catch { checks.push({ kind: "warn", message: "Image provider configuration is invalid; core service is unaffected", fix: "ccdx image
|
|
231
|
+
} catch { checks.push({ kind: "warn", message: "Image provider configuration is invalid; core service is unaffected", fix: "ccdx app codex image status" }); }
|
|
232
232
|
const updateEnvironment = inspectUpdateEnvironmentFn();
|
|
233
233
|
const updateMessage = updateEnvironment.state === "different" ? "npm update target differs from this CCDX installation; review PATH/prefix before updating"
|
|
234
234
|
: updateEnvironment.state === "unavailable" ? "npm update environment could not be verified; installer settings were not changed"
|
|
@@ -252,8 +252,8 @@ export async function collectDoctorChecks({
|
|
|
252
252
|
const ready = result.state?.m365?.state === "ready" && result.models?.length > 0;
|
|
253
253
|
checks.push({ kind: ready ? "ok" : "warn", id: "provider", message: ready
|
|
254
254
|
? `Microsoft 365 is ready; ${result.models.length} GPT models available`
|
|
255
|
-
: "Microsoft 365 is not ready; inspect ccdx m365 status. No GitHub fallback was selected" });
|
|
256
|
-
} catch { checks.push({ kind: "warn", id: "provider", message: "Microsoft 365 could not be checked through the running adapter; start ccdx and inspect ccdx m365 status" }); }
|
|
255
|
+
: "Microsoft 365 is not ready; inspect ccdx source m365 status. No GitHub fallback was selected" });
|
|
256
|
+
} catch { checks.push({ kind: "warn", id: "provider", message: "Microsoft 365 could not be checked through the running adapter; start ccdx and inspect ccdx source m365 status" }); }
|
|
257
257
|
} else if (!sourceError) checks.push(...await inspectAuthProfilesOnline({
|
|
258
258
|
home,
|
|
259
259
|
profile,
|
package/src/image-mcp.mjs
CHANGED
|
@@ -221,7 +221,7 @@ export function createImageMcpHandler({
|
|
|
221
221
|
instructions: config && isEnabled()
|
|
222
222
|
? `CCDX handles the configured image API and credentials; no Python or SDK setup. Embed returned image Markdown in the final reply. Redisplay reuses it without tool calls. Keep each image_id with its own image. Do not automatically retry failed/timed-out requests or switch providers.${supportsImageEditing(config) ? " Use generate_image for new images; edit_image requires the exact retained source ID." : " Use generate_image for new images. Editing is unsupported; do not substitute generation."}`
|
|
223
223
|
: config ? "Image calls are paused. Resume them in the CCDX WebUI; the provider and retained edit handles are preserved."
|
|
224
|
-
: "Image generation is disabled. Enable it with ccdx
|
|
224
|
+
: "Image generation is disabled. Enable it with ccdx app codex image setup before requesting images.",
|
|
225
225
|
});
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
@@ -248,7 +248,7 @@ export function createImageMcpHandler({
|
|
|
248
248
|
if (!config || !isEnabled()) {
|
|
249
249
|
metrics.failed += 1;
|
|
250
250
|
if (!config) imageReferences.clear();
|
|
251
|
-
reply({ content: [{ type: "text", text: config ? "Image calls are paused. Resume them in the CCDX WebUI." : "Image generation is disabled. Run ccdx
|
|
251
|
+
reply({ content: [{ type: "text", text: config ? "Image calls are paused. Resume them in the CCDX WebUI." : "Image generation is disabled. Run ccdx app codex image setup first." }], isError: true });
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
254
|
const editing = request.params.name === EDIT_TOOL_NAME;
|
|
@@ -9,7 +9,7 @@ export async function requestPredictionFix({ host = "127.0.0.1", port = 2026, fe
|
|
|
9
9
|
requiredCapabilities: [PREDICTION_FIX_CAPABILITY] });
|
|
10
10
|
if (!probe.ok) throw new Error(probe.incompatible
|
|
11
11
|
? "The running adapter lacks compatible prediction repair. Upgrade and restart the CCDX service once; the App was not restarted."
|
|
12
|
-
: "Could not reach a running CCDX adapter. Start ccdx, then retry ccdx prediction
|
|
12
|
+
: "Could not reach a running CCDX adapter. Start ccdx, then retry ccdx app codex prediction repair.");
|
|
13
13
|
const signal = AbortSignal.timeout(timeoutMs);
|
|
14
14
|
const response = await fetchImpl(probe.baseUrl + ADAPTER_PREDICTION_FIX_PATH, {
|
|
15
15
|
method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
@@ -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/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 {
|
package/src/service-control.mjs
CHANGED
|
@@ -34,7 +34,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
34
34
|
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Invalid setting action");
|
|
35
35
|
const allowed = { preference: ["action", "key", "value"], nightly_update: ["action", "enabled"], animation: ["action", "theme"], color_theme: ["action", "theme"],
|
|
36
36
|
history_limit: ["action", "mib"], history_clean: ["action"], prediction_fix: ["action"],
|
|
37
|
-
preferences: ["action", "values", "revision"], reset_preferences: ["action", "revision", "backup_id"], restore_preferences: ["action", "revision", "backup_id"],
|
|
37
|
+
preferences: ["action", "values", "revision"], reset_preferences: ["action", "revision", "backup_id", "scope"], restore_preferences: ["action", "revision", "backup_id", "scope"],
|
|
38
38
|
provider: ["action", "operation", "provider", "model", "auto_review_model", "auto_review_effort", "account_id"] }[input.action];
|
|
39
39
|
if (!allowed || Object.keys(input).some(key => !allowed.includes(key))) throw new Error("Unknown setting action or field");
|
|
40
40
|
if (["preferences", "reset_preferences", "restore_preferences"].includes(input.action)) {
|
|
@@ -16,9 +16,9 @@ const idValid = value => typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{
|
|
|
16
16
|
const valuesFor = settings => Object.fromEntries(keys.map(key => [key, key === "terminal_animation" && !isTerminalAnimationTheme(settings[key])
|
|
17
17
|
? SETTINGS_DEFAULTS[key] : settings[key] ?? SETTINGS_DEFAULTS[key]]));
|
|
18
18
|
const revisionFor = values => createHash("sha256").update(JSON.stringify(keys.map(key => values[key]))).digest("hex");
|
|
19
|
-
export const settingsBackupPath = options => path.join(path.dirname(userSettingsPath(options)), "settings-preferences-backup.json");
|
|
19
|
+
export const settingsBackupPath = options => path.join(path.dirname(userSettingsPath(options)), options?.backupScope === "service" ? "service-settings-preferences-backup.json" : "settings-preferences-backup.json");
|
|
20
20
|
|
|
21
|
-
function
|
|
21
|
+
export function checkedPreferenceValues(values) {
|
|
22
22
|
if (!values || typeof values !== "object" || Array.isArray(values) || Object.keys(values).some(key => !keys.includes(key)
|
|
23
23
|
|| (key === "terminal_color_theme" ? !isColorTheme(values[key]) : key === "terminal_animation" ? !isTerminalAnimationTheme(values[key]) : typeof values[key] !== "boolean"))) {
|
|
24
24
|
throw fail("ccdx_settings_values_invalid", "Choose valid settings on this page", 400);
|
|
@@ -31,7 +31,7 @@ function readBackup(options) {
|
|
|
31
31
|
if (value?.version !== 1 || !idValid(value.id) || typeof value.created_at !== "string" || !Number.isFinite(Date.parse(value.created_at))
|
|
32
32
|
|| Object.keys(value).some(key => !["version", "id", "created_at", "values"].includes(key))
|
|
33
33
|
|| keys.some(key => !Object.hasOwn(value.values || {}, key))) throw Error();
|
|
34
|
-
|
|
34
|
+
checkedPreferenceValues(value.values);return value;
|
|
35
35
|
} catch (error) {
|
|
36
36
|
if (error.code === "ENOENT") return null;
|
|
37
37
|
throw fail("ccdx_settings_backup_invalid", "The settings backup could not be read; existing files were preserved");
|
|
@@ -48,6 +48,8 @@ export function settingsPreferencesSnapshot(options = {}) {
|
|
|
48
48
|
// Only this page's preferences enter its backup. Routing, auth, business flags
|
|
49
49
|
// and unknown settings are retained in the current file, never copied here.
|
|
50
50
|
export function writeSettingsPreferences(input, options = {}) {
|
|
51
|
+
if (input.scope !== undefined && (!["reset_preferences", "restore_preferences"].includes(input.action) || input.scope !== "service")) throw fail("ccdx_settings_action_invalid", "Unknown backup scope", 400);
|
|
52
|
+
if (input.scope === "service") options = { ...options, backupScope: "service" };
|
|
51
53
|
const file = userSettingsPath(options);
|
|
52
54
|
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
53
55
|
return withFileLockSync(`${file}.lock`, () => {
|
|
@@ -58,7 +60,7 @@ export function writeSettingsPreferences(input, options = {}) {
|
|
|
58
60
|
throw fail("ccdx_settings_changed", "Settings changed elsewhere. Review the current settings before saving again");
|
|
59
61
|
}
|
|
60
62
|
let values;
|
|
61
|
-
if (input.action === "preferences") values =
|
|
63
|
+
if (input.action === "preferences") values = checkedPreferenceValues(input.values);
|
|
62
64
|
else {
|
|
63
65
|
if (!idValid(input.backup_id)) throw fail("ccdx_settings_backup_invalid", "Choose the current settings backup", 400);
|
|
64
66
|
if (input.action === "restore_preferences") {
|
package/src/startup-ui.mjs
CHANGED
|
@@ -2,6 +2,9 @@ import { status } from "./status.mjs";
|
|
|
2
2
|
import { terminalCell } from "./terminal-text.mjs";
|
|
3
3
|
import { colorTerminalText } from "./terminal-colors.mjs";
|
|
4
4
|
import { terminalColorPreference } from "./user-settings.mjs";
|
|
5
|
+
import { format } from "node:util";
|
|
6
|
+
import { displayWidth } from "./cli-table.mjs";
|
|
7
|
+
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
5
8
|
|
|
6
9
|
// The favicon's three ellipses, rasterized as terminal half-blocks. No runtime
|
|
7
10
|
// graphics library or terminal cursor control is needed.
|
|
@@ -18,7 +21,7 @@ export function startupBanner({ commandName = "ccdx", version, stream = process.
|
|
|
18
21
|
const title = `${terminalCell(commandName)} v${terminalCell(version)} by Dale Xiao`;
|
|
19
22
|
const color = stream.isTTY === true && !Object.hasOwn(env, "NO_COLOR") && env.TERM !== "dumb";
|
|
20
23
|
if (!color || Number(stream.columns || 80) < 72) return `${title}\nLocal model services for Codex and Claude`;
|
|
21
|
-
const labels = new Map([[1, `${terminalCell(commandName).toUpperCase()} v${terminalCell(version)}`], [2, "by Dale Xiao"], [4, "
|
|
24
|
+
const labels = new Map([[1, `${terminalCell(commandName).toUpperCase()} v${terminalCell(version)}`], [2, "by Dale Xiao"], [4, "Local model gateway"]]);
|
|
22
25
|
const theme = colorTheme || terminalColorPreference({ env, home });
|
|
23
26
|
return ATOM.map((line, i) => `${colorTerminalText(line, theme, { output: stream, env })}${labels.has(i) ? ` ${labels.get(i)}` : ""}`).join("\n");
|
|
24
27
|
}
|
|
@@ -42,6 +45,35 @@ export function startupLogger(name, output = console.log) {
|
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
// One transient startup row. Authorization instructions and warnings remain
|
|
49
|
+
// visible; only ordinary structured checks are replaced by the live region.
|
|
50
|
+
export function createStartupPresentation({ output = process.stdout, errorOutput = process.stderr, env = process.env, verbose = false } = {}) {
|
|
51
|
+
const enabled = !verbose && output.isTTY === true && errorOutput.isTTY === true && env.TERM !== "dumb"
|
|
52
|
+
&& (!env.CI || /^(0|false|no|off)$/i.test(env.CI)) && (output.columns || 80) >= 40 && (output.rows || 24) >= 16;
|
|
53
|
+
let visible = false;const warnings = [];
|
|
54
|
+
function clear() { if (visible) output.write("\r\x1b[2K");visible = false; }
|
|
55
|
+
return { enabled, warnings, finish: clear,
|
|
56
|
+
log(method, args) {
|
|
57
|
+
const message = redactDiagnosticText(format(...args));
|
|
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;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
45
77
|
export function predictionStartupCheck(prediction) {
|
|
46
78
|
if (!prediction?.configured) return startupCheck("info", "Suggestions", "Off");
|
|
47
79
|
const environment = prediction.environment?.status;
|
|
@@ -53,7 +85,7 @@ export function predictionStartupCheck(prediction) {
|
|
|
53
85
|
const warning = prediction.bridge !== "running" || problem || prediction.launch_route === "unverified";
|
|
54
86
|
const lines = [startupCheck(warning ? "warn" : "info", "Suggestions", detail)];
|
|
55
87
|
if (prediction.bridge !== "running" && prediction.reason) lines.push(startupCheck("warn", "Reason", prediction.reason));
|
|
56
|
-
if (warning) lines.push(startupCheck("info", "Details", "ccdx prediction status"));
|
|
88
|
+
if (warning) lines.push(startupCheck("info", "Details", "ccdx app codex prediction status"));
|
|
57
89
|
return lines.join("\n");
|
|
58
90
|
}
|
|
59
91
|
|
package/src/terminal-console.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
|
4
4
|
import { DEFAULT_TERMINAL_ANIMATION_THEME, TERMINAL_ANIMATION_THEMES, isTerminalAnimationTheme, renderTerminalAnimationFrame,
|
|
5
5
|
getTerminalAnimationCycleLength, getTerminalAnimationFrameDelay } from "./terminal-animation.mjs";
|
|
6
6
|
import { displayWidth } from "./cli-table.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { projectTerminalState, terminalUptime } from "./terminal-state.mjs";
|
|
8
8
|
import { colorTerminalText, colorTerminalMotion } from "./terminal-colors.mjs";
|
|
9
9
|
|
|
10
10
|
const clear = "\r\x1b[2K";
|
|
@@ -14,7 +14,7 @@ const flagOff = value => /^(0|false|no|off)$/i.test(String(value || ""));
|
|
|
14
14
|
export function createTerminalConsole({ output = process.stdout, errorOutput = process.stderr, env = process.env,
|
|
15
15
|
snapshot = () => ({}), preferences = () => ({}), baseUrl = "", verbose = false,
|
|
16
16
|
timers = { setTimeout, clearTimeout }, now = Date.now } = {}) {
|
|
17
|
-
let running = false, timer = null, lines = 0,
|
|
17
|
+
let running = false, timer = null, lines = 0, frame = 0, lastRead = 0, data = {}, projection = projectTerminalState();
|
|
18
18
|
let notices = 0, lastNotice = "", lastPrintedNotice = "", previous = [];
|
|
19
19
|
let content = [], dirty = true, readFailed = false, updatedAt = null, fits = true;
|
|
20
20
|
let current = { theme: DEFAULT_TERMINAL_ANIMATION_THEME, color_theme: "green", terminal_animation_enabled: true };
|
|
@@ -44,7 +44,7 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
44
44
|
function table(width, usage, requests, inferenceActive, sum, compactTitle = false) {
|
|
45
45
|
const left = Math.floor((width - 3) / 2), right = width - 3 - left;
|
|
46
46
|
const cell = (label, value, size) => {
|
|
47
|
-
const number = value === undefined ? "" : updatedAt === null && readFailed ? "—" : typeof value === "string" ? value : compact(value), inner = size - 2;
|
|
47
|
+
const number = value === undefined ? "" : updatedAt === null && readFailed ? "—" : value === null ? "—" : typeof value === "string" ? value : compact(value), inner = size - 2;
|
|
48
48
|
const text = clip(label, Math.max(0, inner - displayWidth(number) - (number ? 1 : 0)));
|
|
49
49
|
return ` ${text}${" ".repeat(Math.max(0, inner - displayWidth(text) - displayWidth(number)))}${number} `;
|
|
50
50
|
};
|
|
@@ -52,18 +52,20 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
52
52
|
const rule = (a, b, c) => `${a}${"─".repeat(left)}${b}${"─".repeat(right)}${c}`;
|
|
53
53
|
const rate = usage.cache_hit_rate;
|
|
54
54
|
const cacheHit = Number.isFinite(rate) && rate >= 0 && rate <= 1 ? `${usage.cache_hit_rate_partial ? "~" : ""}${(rate * 100).toFixed(1)}%` : "—";
|
|
55
|
-
const usageRows = [[left < 23 ? "Records" : "Usage records", usage.records
|
|
56
|
-
["Output", usage.output_tokens], ["Partial
|
|
57
|
-
const requestRows = [["
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const usageRows = [[left < 23 ? "Records" : "Usage records", usage.records ?? null], ["Input", usage.input_tokens ?? null], [left < 23 ? "Reused" : "Reused input", usage.cached_input_tokens ?? null],
|
|
56
|
+
["Output", usage.output_tokens ?? null], [left < 23 ? "Partial" : "Partial records", usage.partial_records ?? null], ["Cache hit", cacheHit]];
|
|
57
|
+
const requestRows = [["Total", requests], ["Active", inferenceActive], ["Completed", sum("completed")], ["Incomplete", sum("incomplete")], ["Failed", sum("failed")], ["Cancelled", sum("cancelled")]];
|
|
58
|
+
if (sum("unknown")) { usageRows.push(["", ""]);requestRows.push(["Unknown", sum("unknown")]); }
|
|
59
|
+
const title = compactTitle ? [`┌─ Usage ${"─".repeat(left - 8)}┬─ Requests ${"─".repeat(right - 11)}┐`]
|
|
60
|
+
: [rule("┌", "┬", "┐"), row(cell("Usage / this run", undefined, left), cell(right < 23 ? "Requests" : "Model requests", undefined, right)), rule("├", "┼", "┤")];
|
|
60
61
|
return [...title,
|
|
61
|
-
...usageRows.map(([label, value], index) => row(cell(label, value
|
|
62
|
+
...usageRows.map(([label, value], index) => row(cell(label, value === undefined ? (label ? null : undefined) : value, left), cell(...requestRows[index], right))), rule("└", "┴", "┘")];
|
|
62
63
|
}
|
|
63
64
|
function render() {
|
|
64
65
|
if (!running || !supported() || verbose) { frameDelay = 1000;return; }
|
|
65
66
|
const width = Math.max(1, Math.min(160, Number(output.columns) || 80) - 1);
|
|
66
|
-
|
|
67
|
+
const active = readFailed ? null : projection.activity;
|
|
68
|
+
let motion = active === null ? "?" : active ? "●" : "○";
|
|
67
69
|
frameDelay = 1000;
|
|
68
70
|
if (active && current.terminal_animation_enabled && !flagOff(env.CCDX_TERMINAL_ANIMATION) && width >= 24) {
|
|
69
71
|
frame %= getTerminalAnimationCycleLength(current.theme);
|
|
@@ -75,30 +77,30 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
75
77
|
frameDelay = getTerminalAnimationFrameDelay(current.theme, index) + (frame === 0 ? metadata.loopPauseMs : 0);
|
|
76
78
|
}
|
|
77
79
|
if (dirty) {
|
|
78
|
-
const usage = data.runtime_usage || {},
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
content = [clip(heading, width)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
content.push(clip(`${notices} notices${lastNotice ? ` · latest: ${lastNotice}` : " / details in WebUI"}`, width));
|
|
80
|
+
const usage = data.runtime_usage || {}, view = projection;
|
|
81
|
+
const heading = readFailed ? updatedAt === null ? "Status unavailable" : `Previous data / ${new Date(updatedAt).toLocaleTimeString("en-GB")}`
|
|
82
|
+
: `Running · up ${terminalUptime(data.uptime_ms)}`;
|
|
83
|
+
const webAddress = baseUrl ? `Web UI: ${baseUrl}` : "Web UI: address unavailable";
|
|
84
|
+
const sourceHeader = view.sources ? `Enabled sources: ${view.sources.length}` : "Enabled sources: unknown";
|
|
85
|
+
const appSize = width < 64 ? 13 : 15, setupSize = Math.max(10, Math.min(20, width - appSize - 7));
|
|
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)}`);
|
|
87
|
+
const issue = view.issue?.label;
|
|
88
|
+
const notice = notices ? `${notices} ${notices === 1 ? "notice" : "notices"}${issue ? ` · last model issue: ${issue}` : " · ccdx status --details"}` : issue ? `Last model issue: ${issue}` : "No notices";
|
|
89
|
+
content = [clip(heading, width), clip(webAddress, width), sourceHeader,
|
|
90
|
+
...(view.sources ? wrap(view.sources.map(source => source.name).join(" · "), width) : []),
|
|
91
|
+
`${"App".padEnd(appSize)}${"Setup".padEnd(setupSize)}${"Active".padStart(6)}`, ...appRows,
|
|
92
|
+
...table(width, usage, view.requests, readFailed ? null : view.active, key => view.outcomes[key]),
|
|
93
|
+
clip("Help: ccdx help · Stop: Ctrl+C", width), clip(notice, width)];
|
|
93
94
|
if (content.length + 1 >= (Number(output.rows) || 24)) {
|
|
94
|
-
const
|
|
95
|
-
content = [clip(
|
|
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(" · ");
|
|
96
|
+
content = [clip(readFailed ? heading : webAddress, width), sourceHeader, clip(`Apps: ${grouped}`, width),
|
|
97
|
+
...table(width, usage, view.requests, readFailed ? null : view.active, key => view.outcomes[key], true), clip(notice, width)];
|
|
96
98
|
}
|
|
97
99
|
dirty = false;
|
|
98
100
|
}
|
|
99
101
|
// Apply color after clipping/layout so escape sequences never consume columns.
|
|
100
102
|
const body = [...content.map(line => ["klein", "pink"].includes(current.color_theme) && /^[┌│├└]/.test(line)
|
|
101
|
-
? colorTerminalText(line, current.color_theme, { output, env }) : line), `${motion} ${active ? "
|
|
103
|
+
? colorTerminalText(line, current.color_theme, { output, env }) : line), `${motion} ${active === null ? "Status unknown" : active ? "Active" : "Idle"}`];
|
|
102
104
|
fits = body.length < (Number(output.rows) || 24);
|
|
103
105
|
if (!fits) { frameDelay = 1000;return; }
|
|
104
106
|
// Animation ticks update only the final line; data stays on its 1s cadence.
|
|
@@ -120,7 +122,7 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
120
122
|
if (now() - lastRead >= 1000 || !lastRead) {
|
|
121
123
|
try {
|
|
122
124
|
const next = snapshot(), nextPreferences = preferences();
|
|
123
|
-
data = next;current = { ...current, ...nextPreferences };readFailed = false;updatedAt = now();
|
|
125
|
+
data = next;projection = projectTerminalState(data);current = { ...current, ...nextPreferences };readFailed = false;updatedAt = now();
|
|
124
126
|
if (!isTerminalAnimationTheme(current.theme)) current.theme = DEFAULT_TERMINAL_ANIMATION_THEME;
|
|
125
127
|
} catch { readFailed = true; }
|
|
126
128
|
lastRead = now();
|
|
@@ -133,7 +135,7 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
133
135
|
get enabled() { return supported() && fits && !verbose; },
|
|
134
136
|
start() { if (running) return;running = true;tick(); },
|
|
135
137
|
pause() { running = false;if (timer) timers.clearTimeout(timer);timer = null;if (lines) output.write("\n");lines = 0;previous = [];dirty = true; },
|
|
136
|
-
beginRequest() {
|
|
138
|
+
beginRequest() { dirty = true;return () => { dirty = true; }; },
|
|
137
139
|
log(method, args) {
|
|
138
140
|
const message = redactDiagnosticText(format(...args));
|
|
139
141
|
if (verbose) { (method === "error" || method === "warn" ? errorOutput : output).write(`${message}\n`);return; }
|