codex-copilot-dx 1.1.0 → 1.2.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 +4 -4
- package/bin/cli.mjs +27 -24
- package/docs/ARCHITECTURE.md +22 -3
- package/docs/README.md +1 -0
- package/docs/REFERENCE.md +35 -10
- package/package.json +1 -1
- package/src/auth-device-flow.mjs +1 -1
- package/src/auth-status.mjs +1 -1
- package/src/auto-review-model.mjs +2 -2
- package/src/claude-client-lifecycle.mjs +33 -0
- package/src/claude-gateway.mjs +15 -6
- package/src/cli-auth.mjs +6 -6
- package/src/cli-cache.mjs +5 -5
- package/src/cli-image.mjs +1 -1
- package/src/cli-m365.mjs +5 -5
- package/src/cli-models.mjs +2 -2
- package/src/cli-options.mjs +26 -26
- package/src/cli-status.mjs +6 -1
- package/src/dashboard/console.js +58 -26
- package/src/dashboard/index.html +95 -87
- package/src/dashboard/language.js +779 -362
- package/src/dashboard/status.js +53 -41
- package/src/dashboard/ui.css +4 -4
- package/src/dashboard/ui.js +31 -28
- package/src/dashboard/usage.js +16 -16
- package/src/dashboard-api.mjs +1 -0
- package/src/doctor.mjs +4 -4
- package/src/http-transport.mjs +4 -2
- package/src/launcher.mjs +14 -14
- package/src/native-prediction.mjs +3 -3
- package/src/operation-error.mjs +12 -7
- package/src/package-update.mjs +3 -3
- package/src/provider-registry.mjs +19 -0
- package/src/provider-runtime.mjs +22 -27
- package/src/provider-settings.mjs +2 -1
- package/src/response-failures.mjs +2 -1
- package/src/service-control.mjs +4 -5
- package/src/startup-ui.mjs +45 -11
- package/src/stream-performance.mjs +29 -1
- package/src/terminal-console.mjs +82 -27
- package/src/usage-store.mjs +10 -5
- package/src/user-settings.mjs +16 -3
package/src/terminal-console.mjs
CHANGED
|
@@ -4,6 +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 { providerStartupSummary } from "./startup-ui.mjs";
|
|
7
8
|
|
|
8
9
|
const clear = "\r\x1b[2K";
|
|
9
10
|
const flagOff = value => /^(0|false|no|off)$/i.test(String(value || ""));
|
|
@@ -13,12 +14,13 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
13
14
|
snapshot = () => ({}), preferences = () => ({}), baseUrl = "", verbose = false,
|
|
14
15
|
timers = { setTimeout, clearTimeout }, now = Date.now } = {}) {
|
|
15
16
|
let running = false, timer = null, lines = 0, active = 0, frame = 0, lastRead = 0, data = {};
|
|
16
|
-
let notices = 0, lastNotice = "", lastPrintedNotice = "",
|
|
17
|
+
let notices = 0, lastNotice = "", lastPrintedNotice = "", previous = [];
|
|
18
|
+
let content = [], dirty = true, readFailed = false, updatedAt = null, fits = true;
|
|
17
19
|
let current = { theme: DEFAULT_TERMINAL_ANIMATION_THEME, terminal_animation_enabled: true };
|
|
18
20
|
let frameDelay = 1000;
|
|
19
21
|
const tty = output.isTTY === true && errorOutput.isTTY === true && (!env.CI || flagOff(env.CI)) && env.TERM !== "dumb";
|
|
20
|
-
const supported = () => tty && (Number(output.columns) || 80) >= 40;
|
|
21
|
-
const resized = () => { if (lines) output.write("\n");lines = 0;
|
|
22
|
+
const supported = () => tty && (Number(output.columns) || 80) >= 40 && (Number(output.rows) || 24) >= 16;
|
|
23
|
+
const resized = () => { if (lines) output.write("\n");lines = 0;previous = [];frame = 0;dirty = true; };
|
|
22
24
|
output.on?.("resize", resized);
|
|
23
25
|
const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
24
26
|
const clip = (value, width) => {
|
|
@@ -28,14 +30,36 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
28
30
|
}
|
|
29
31
|
return text;
|
|
30
32
|
};
|
|
31
|
-
const
|
|
33
|
+
const numbers = new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 });
|
|
34
|
+
const compact = value => numbers.format(Number(value) || 0);
|
|
35
|
+
const wrap = (value, width) => {
|
|
36
|
+
const rows = [];let row = "";
|
|
37
|
+
for (const word of terminalCell(value, { fallback: "" }).split(/\s+/)) {
|
|
38
|
+
if (row && displayWidth(`${row} ${word}`) > width) { rows.push(row);row = ""; }
|
|
39
|
+
row += `${row ? " " : ""}${word}`;
|
|
40
|
+
}
|
|
41
|
+
if (row) rows.push(clip(row, width));return rows;
|
|
42
|
+
};
|
|
43
|
+
function table(width, usage, requests, inferenceActive, sum, compactTitle = false) {
|
|
44
|
+
const left = Math.floor((width - 3) / 2), right = width - 3 - left;
|
|
45
|
+
const cell = (label, value, size) => {
|
|
46
|
+
const number = value === undefined ? "" : updatedAt === null && readFailed ? "—" : compact(value), inner = size - 2;
|
|
47
|
+
const text = clip(label, Math.max(0, inner - displayWidth(number) - (number ? 1 : 0)));
|
|
48
|
+
return ` ${text}${" ".repeat(Math.max(0, inner - displayWidth(text) - displayWidth(number)))}${number} `;
|
|
49
|
+
};
|
|
50
|
+
const row = (a, b) => `│${a}│${b}│`;
|
|
51
|
+
const rule = (a, b, c) => `${a}${"─".repeat(left)}${b}${"─".repeat(right)}${c}`;
|
|
52
|
+
const usageRows = [[left < 23 ? "Records" : "Usage records", usage.records || 0], ["Input", usage.input_tokens], [left < 23 ? "Reused" : "Reused input", usage.cached_input_tokens],
|
|
53
|
+
["Output", usage.output_tokens], ["Partial usage", usage.partial_records || 0], ["", undefined]];
|
|
54
|
+
const requestRows = [["Requests", requests], ["Active", inferenceActive], ["Completed", sum("completed")], ["Incomplete", sum("incomplete")], ["Failed", sum("failed")], ["Cancelled", sum("cancelled")]];
|
|
55
|
+
const title = compactTitle ? [`┌─ Usage ${"─".repeat(left - 8)}┬─ Inference ${"─".repeat(right - 12)}┐`]
|
|
56
|
+
: [rule("┌", "┬", "┐"), row(cell("Usage / this run", undefined, left), cell("Inference", undefined, right)), rule("├", "┼", "┤")];
|
|
57
|
+
return [...title,
|
|
58
|
+
...usageRows.map(([label, value], index) => row(cell(label, value ?? (label ? 0 : undefined), left), cell(...requestRows[index], right))), rule("└", "┴", "┘")];
|
|
59
|
+
}
|
|
32
60
|
function render() {
|
|
33
61
|
if (!running || !supported() || verbose) { frameDelay = 1000;return; }
|
|
34
62
|
const width = Math.max(1, Math.min(160, Number(output.columns) || 80) - 1);
|
|
35
|
-
const usage = data.runtime_usage || {}, routes = data.requests?.by_route || {};
|
|
36
|
-
const outcomes = [data.stream_performance?.by_route?.responses, data.stream_performance?.by_route?.responses_compact, data.providers?.m365?.claude?.requests?.performance?.by_route?.messages]
|
|
37
|
-
.map(route => route?.terminal_outcomes?.totals || {});
|
|
38
|
-
const sum = key => outcomes.reduce((total, item) => total + (Number(item[key]) || 0), 0);
|
|
39
63
|
let motion = active ? "●" : "○";
|
|
40
64
|
frameDelay = 1000;
|
|
41
65
|
if (active && current.terminal_animation_enabled && !flagOff(env.CCDX_TERMINAL_ANIMATION) && width >= 24) {
|
|
@@ -46,41 +70,72 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
|
|
|
46
70
|
frame = (frame + 1) % getTerminalAnimationCycleLength(current.theme);
|
|
47
71
|
frameDelay = getTerminalAnimationFrameDelay(current.theme, index) + (frame === 0 ? metadata.loopPauseMs : 0);
|
|
48
72
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
if (dirty) {
|
|
74
|
+
const usage = data.runtime_usage || {}, routes = data.requests?.by_route || {};
|
|
75
|
+
const outcomes = [data.stream_performance?.by_route?.responses, data.stream_performance?.by_route?.responses_compact, data.providers?.m365?.claude?.requests?.performance?.by_route?.messages]
|
|
76
|
+
.map(route => route?.terminal_outcomes?.totals || {});
|
|
77
|
+
const sum = key => outcomes.reduce((total, item) => total + (Number(item[key]) || 0), 0);
|
|
78
|
+
const requests = ["responses", "responses_compact", "messages"].reduce((total, key) => total + (routes[key]?.total || 0), 0);
|
|
79
|
+
const inferenceActive = ["responses", "responses_compact", "messages"].reduce((total, key) => total + (routes[key]?.active || 0), 0);
|
|
80
|
+
const providers = providerStartupSummary(data);
|
|
81
|
+
const heading = readFailed ? updatedAt === null ? "CCDX / No data received" : `CCDX / ${width < 80 ? "Previous data" : "Showing previous data / updated"} / ${new Date(updatedAt).toLocaleTimeString("en-GB")}`
|
|
82
|
+
: `CCDX RUNNING / uptime ${Math.floor((data.uptime_ms || 0) / 60000)}m / ${baseUrl}`;
|
|
83
|
+
content = [clip(heading, width)];
|
|
84
|
+
for (const group of [[`Sources / ${providers.catalogs}`, providers.sourceLines], [`Claude / ${providers.claude}`, providers.claudeLines]]) {
|
|
85
|
+
content.push(...(displayWidth(group[0]) <= width ? [group[0]] : (group[1] || [group[0]]).flatMap(line => wrap(line, width))));
|
|
86
|
+
}
|
|
87
|
+
content.push(...table(width, usage, requests, inferenceActive, sum));
|
|
88
|
+
content.push(clip(`${notices} notices${lastNotice ? ` · latest: ${lastNotice}` : " / details in WebUI"}`, width));
|
|
89
|
+
if (content.length + 1 >= (Number(output.rows) || 24)) {
|
|
90
|
+
const summaries = [...(providers.compactSources || ["Sources: not checked"]), ...(providers.compactClaude || ["Claude: not checked"])];
|
|
91
|
+
content = [clip(heading, width), ...summaries.flatMap(line => wrap(line, width)), ...table(width, usage, requests, inferenceActive, sum, true), content.at(-1)];
|
|
92
|
+
}
|
|
93
|
+
dirty = false;
|
|
94
|
+
}
|
|
95
|
+
const body = [...content, `${motion} ${active ? "Working" : "Idle"}`];
|
|
96
|
+
fits = body.length < (Number(output.rows) || 24);
|
|
97
|
+
if (!fits) { frameDelay = 1000;return; }
|
|
98
|
+
// Animation ticks update only the final line; data stays on its 1s cadence.
|
|
99
|
+
let update = "";
|
|
100
|
+
if (lines && lines !== body.length) {
|
|
101
|
+
update = `${lines > 1 ? `\x1b[${lines - 1}A` : ""}\r\x1b[J`;lines = 0;previous = [];
|
|
102
|
+
}
|
|
103
|
+
if (!lines) update += `${body.map(line => clear + line).join("\n")}\r`;
|
|
104
|
+
else for (let index = 0; index < body.length; index++) {
|
|
105
|
+
if (body[index] === previous[index]) continue;
|
|
106
|
+
const offset = body.length - 1 - index;
|
|
107
|
+
update += `${offset ? `\x1b[${offset}A` : ""}${clear}${body[index]}\r${offset ? `\x1b[${offset}B` : ""}`;
|
|
108
|
+
}
|
|
109
|
+
if (update) output.write(update);
|
|
110
|
+
previous = body;lines = body.length;
|
|
62
111
|
}
|
|
63
112
|
function tick() {
|
|
64
113
|
if (!running) return;
|
|
65
114
|
if (now() - lastRead >= 1000 || !lastRead) {
|
|
66
|
-
try {
|
|
115
|
+
try {
|
|
116
|
+
const next = snapshot(), nextPreferences = preferences();
|
|
117
|
+
data = next;current = { ...current, ...nextPreferences };readFailed = false;updatedAt = now();
|
|
118
|
+
if (!isTerminalAnimationTheme(current.theme)) current.theme = DEFAULT_TERMINAL_ANIMATION_THEME;
|
|
119
|
+
} catch { readFailed = true; }
|
|
67
120
|
lastRead = now();
|
|
121
|
+
dirty = true;
|
|
68
122
|
}
|
|
69
123
|
render();
|
|
70
124
|
timer = timers.setTimeout(tick, frameDelay);timer?.unref?.();
|
|
71
125
|
}
|
|
72
126
|
return {
|
|
73
|
-
get enabled() { return supported() && !verbose; },
|
|
127
|
+
get enabled() { return supported() && fits && !verbose; },
|
|
74
128
|
start() { if (running) return;running = true;tick(); },
|
|
75
|
-
beginRequest() { active++;let done = false;return () => { if (!done) { done = true;active = Math.max(0, active - 1); } }; },
|
|
129
|
+
beginRequest() { active++;dirty = true;let done = false;return () => { if (!done) { done = true;active = Math.max(0, active - 1);dirty = true; } }; },
|
|
76
130
|
log(method, args) {
|
|
77
131
|
const message = redactDiagnosticText(format(...args));
|
|
78
132
|
if (verbose) { (method === "error" || method === "warn" ? errorOutput : output).write(`${message}\n`);return; }
|
|
79
133
|
if (method !== "error" && method !== "warn" && !/^\[(WARN|ERR)\]/.test(message.trim())) return;
|
|
80
|
-
notices++;lastNotice = message.replace(/\s+/g, " ").slice(0, 240);
|
|
81
|
-
if (!supported() && lastNotice !== lastPrintedNotice) { errorOutput.write(`${lastNotice}\n`);lastPrintedNotice = lastNotice; }
|
|
134
|
+
notices++;lastNotice = message.replace(/\s+/g, " ").slice(0, 240);dirty = true;
|
|
135
|
+
if ((!supported() || !fits) && lastNotice !== lastPrintedNotice) { errorOutput.write(`${lastNotice}\n`);lastPrintedNotice = lastNotice; }
|
|
82
136
|
},
|
|
83
|
-
snapshot() { return { notices, last_notice: lastNotice || null, mode: verbose ? "verbose" : supported() ? "status" : "plain"
|
|
137
|
+
snapshot() { return { notices, last_notice: lastNotice || null, mode: verbose ? "verbose" : supported() && fits ? "status" : "plain",
|
|
138
|
+
data_state: readFailed ? updatedAt === null ? "unavailable" : "stale" : updatedAt === null ? "unknown" : "current", updated_at: updatedAt === null ? null : new Date(updatedAt).toISOString() }; },
|
|
84
139
|
apply(value) { if (value.theme && value.theme !== current.theme) frame = 0;current = { ...current, ...value };lastRead = 0; },
|
|
85
140
|
cleanup() { running = false;if (timer) timers.clearTimeout(timer);timer = null;if (lines) output.write("\n");lines = 0;output.off?.("resize", resized); },
|
|
86
141
|
};
|
package/src/usage-store.mjs
CHANGED
|
@@ -25,8 +25,9 @@ let pendingBytes = 0;
|
|
|
25
25
|
let droppedRecords = 0;
|
|
26
26
|
let writeFailures = 0;
|
|
27
27
|
const runtimeUsage = { since: new Date().toISOString(), records: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, partial_records: 0 };
|
|
28
|
+
const runtimeUsageByProvider = new Map();
|
|
28
29
|
|
|
29
|
-
export function runtimeUsageSnapshot() { return { ...runtimeUsage }; }
|
|
30
|
+
export function runtimeUsageSnapshot() { return { ...runtimeUsage, by_provider: Object.fromEntries([...runtimeUsageByProvider].map(([id, totals]) => [id, { ...totals }])) }; }
|
|
30
31
|
|
|
31
32
|
export function usageLoggingStats() {
|
|
32
33
|
return { pending_records: pendingRecords, pending_bytes: pendingBytes, dropped_records: droppedRecords,
|
|
@@ -185,11 +186,15 @@ function scheduleUsageWriteDrain() {
|
|
|
185
186
|
export function recordUsage(record) {
|
|
186
187
|
if (!record) return Promise.resolve();
|
|
187
188
|
const usage = record.usage || {};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const provider = usageProvider(record), label = runtimeUsageByProvider.has(provider) || runtimeUsageByProvider.size < 16 ? provider : "other";
|
|
190
|
+
if (!runtimeUsageByProvider.has(label)) runtimeUsageByProvider.set(label, { records: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, partial_records: 0 });
|
|
191
|
+
for (const totals of [runtimeUsage, runtimeUsageByProvider.get(label)]) {
|
|
192
|
+
totals.records++;
|
|
193
|
+
for (const [target, value] of [["input_tokens", usage.input_tokens], ["cached_input_tokens", cacheReadTokens(usage)], ["output_tokens", usage.output_tokens]]) {
|
|
194
|
+
if (Number.isFinite(value) && value >= 0) totals[target] += value;
|
|
195
|
+
}
|
|
196
|
+
if (!Number.isFinite(usage.input_tokens) || !Number.isFinite(usage.output_tokens) || cacheReadTokens(usage) === undefined) totals.partial_records++;
|
|
191
197
|
}
|
|
192
|
-
if (!Number.isFinite(usage.input_tokens) || !Number.isFinite(usage.output_tokens) || cacheReadTokens(usage) === undefined) runtimeUsage.partial_records++;
|
|
193
198
|
if (process.env.CCDX_DISABLE_USAGE === "1") return Promise.resolve();
|
|
194
199
|
const filePath = usageLogPath();
|
|
195
200
|
const line = `${JSON.stringify(record)}\n`;
|
package/src/user-settings.mjs
CHANGED
|
@@ -116,7 +116,15 @@ export function savedAutoReviewModel(options = {}) {
|
|
|
116
116
|
|
|
117
117
|
export function servicePreferences(options = {}) {
|
|
118
118
|
const settings = readUserSettings({ ...options, strict: true });
|
|
119
|
-
return
|
|
119
|
+
return serviceFlags(settings);
|
|
120
|
+
}
|
|
121
|
+
const serviceFlags = settings => Object.fromEntries(SERVICE_FLAGS.map(key => [key, settings[key] !== false]));
|
|
122
|
+
|
|
123
|
+
// One strict read gives each status update a coherent view; no stale cache.
|
|
124
|
+
export function serviceSettingsSnapshot(options = {}) {
|
|
125
|
+
const settings = readUserSettings({ ...options, strict: true });
|
|
126
|
+
return { saved: serviceFlags(settings), theme: animationPreference(settings).theme,
|
|
127
|
+
historyLimit: historyLimitPreference(settings, options.env || process.env) };
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
export function writeServicePreference(key, value, options = {}) {
|
|
@@ -150,17 +158,22 @@ export function savedTerminalAnimationTheme(options = {}) {
|
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
export function terminalAnimationPreference({ env = process.env, home = os.homedir() } = {}) {
|
|
153
|
-
|
|
161
|
+
return animationPreference(readUserSettings({ env, home }));
|
|
162
|
+
}
|
|
163
|
+
function animationPreference(settings) {
|
|
164
|
+
const savedTheme = isTerminalAnimationTheme(settings[TERMINAL_ANIMATION_KEY]) ? settings[TERMINAL_ANIMATION_KEY] : "";
|
|
154
165
|
if (savedTheme) return { theme: savedTheme, source: "settings" };
|
|
155
166
|
return { theme: DEFAULT_TERMINAL_ANIMATION_THEME, source: "default" };
|
|
156
167
|
}
|
|
157
168
|
|
|
158
169
|
export function responseHistoryLimitPreference({ env = process.env, home = os.homedir() } = {}) {
|
|
170
|
+
return historyLimitPreference(readUserSettings({ env, home }), env);
|
|
171
|
+
}
|
|
172
|
+
function historyLimitPreference(settings, env) {
|
|
159
173
|
const environment = String(env.CCDX_RESPONSE_HISTORY_MAX_BYTES || "").trim();
|
|
160
174
|
if (environment) {
|
|
161
175
|
return { bytes: loadRuntimeConfig(env).responseHistoryMaxBytes, source: "environment" };
|
|
162
176
|
}
|
|
163
|
-
const settings = readUserSettings({ env, home });
|
|
164
177
|
const mib = settings[RESPONSE_HISTORY_MAX_MIB_KEY];
|
|
165
178
|
if (Number.isSafeInteger(mib)) return { bytes: mib * MIB, mib, source: "settings" };
|
|
166
179
|
return { bytes: RESPONSE_HISTORY_DEFAULT_MIB * MIB, mib: RESPONSE_HISTORY_DEFAULT_MIB, source: "default" };
|