codex-copilot-dx 1.3.26 → 1.3.28

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.
Files changed (42) hide show
  1. package/README.md +5 -2
  2. package/bin/cli.mjs +5 -2
  3. package/docs/ARCHITECTURE.md +16 -3
  4. package/docs/REFERENCE.md +28 -4
  5. package/package.json +1 -1
  6. package/src/adapter.mjs +4 -2
  7. package/src/claude-app-contract.mjs +96 -0
  8. package/src/claude-capability-config.mjs +26 -10
  9. package/src/claude-client-config.mjs +56 -7
  10. package/src/claude-gateway.mjs +7 -5
  11. package/src/claude-models.mjs +4 -2
  12. package/src/cli-command-spec.mjs +8 -2
  13. package/src/cli-management.mjs +26 -6
  14. package/src/client-versions.mjs +17 -13
  15. package/src/connection-client-sync.mjs +1 -0
  16. package/src/connection-management.mjs +5 -0
  17. package/src/connection-policy.mjs +2 -2
  18. package/src/connection-routing.mjs +2 -1
  19. package/src/connection-runtime.mjs +26 -2
  20. package/src/connection-view.mjs +11 -2
  21. package/src/dashboard/connections.js +33 -3
  22. package/src/dashboard/console.js +1 -1
  23. package/src/dashboard/context.js +8 -4
  24. package/src/dashboard/gemini.js +3 -7
  25. package/src/dashboard/index.html +5 -2
  26. package/src/dashboard/language.js +24 -0
  27. package/src/dashboard/status.js +8 -1
  28. package/src/dashboard/ui.js +3 -0
  29. package/src/dashboard-api.mjs +2 -2
  30. package/src/doctor-compat.mjs +1 -1
  31. package/src/model-capabilities.mjs +17 -4
  32. package/src/provider-cooldown.mjs +43 -0
  33. package/src/providers/api-model-metadata.mjs +7 -0
  34. package/src/providers/api.mjs +32 -11
  35. package/src/request-context.mjs +5 -0
  36. package/src/response-failures.mjs +4 -2
  37. package/src/safe-upstream-error.mjs +36 -4
  38. package/src/source-import.mjs +51 -0
  39. package/src/stream-performance.mjs +7 -5
  40. package/src/usage-analysis.mjs +2 -2
  41. package/src/usage-query.mjs +5 -2
  42. package/src/usage-store.mjs +2 -1
@@ -1,5 +1,5 @@
1
1
  import { performance } from "node:perf_hooks";
2
- import { currentRequestContext } from "./request-context.mjs";
2
+ import { currentRequestContext, requestPurpose } from "./request-context.mjs";
3
3
  import { isProviderId } from "./provider-metadata.mjs";
4
4
  import { applicationLabel } from "./request-application.mjs";
5
5
  import { createContextMetrics } from "./context-metrics.mjs";
@@ -225,13 +225,14 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
225
225
 
226
226
  return {
227
227
  subscribe: changes.subscribe,
228
- begin(routeName, { requestId, application } = {}) {
228
+ begin(routeName, { requestId, application, purpose } = {}) {
229
229
  const route = routes[routeName];
230
230
  if (!route) return null;
231
231
  const requestStartedAt = now();
232
232
  const activeId = ++activeSequence;
233
233
  const safeRequestId = typeof requestId === "string" && /^[a-zA-Z0-9_-]{1,80}$/.test(requestId) ? requestId : null;
234
234
  const client = applicationLabel(application);
235
+ const purposeLabel = requestPurpose(purpose);
235
236
  activeTotal++;
236
237
  let upstreamStartedAt = null;
237
238
  let firstOutputAt = null;
@@ -261,7 +262,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
261
262
  let stopReason = null;
262
263
  const elapsed = (time) => time === null ? null : Number(Math.max(0, time - requestStartedAt).toFixed(1));
263
264
  if (activeRequests.size < MAX_ACTIVE_REQUESTS) activeRequests.set(activeId, () => ({
264
- request_id: safeRequestId, session_id: session ? session.slice(0, 16) : null, application: client, route: routeName, provider, model, phase,
265
+ request_id: safeRequestId, session_id: session ? session.slice(0, 16) : null, application: client, purpose: purposeLabel, route: routeName, provider, model, phase,
265
266
  started_at: at, elapsed_ms: elapsed(now()), first_output_ms: elapsed(firstOutputAt),
266
267
  upstream_attempts: attempts, terminal_outcome: terminalOutcome,
267
268
  previous_request: session ? (() => {
@@ -347,8 +348,9 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
347
348
  observeContext(values) {
348
349
  if (finished || !values || typeof values !== "object") return;
349
350
  if (Number.isSafeInteger(values.cached_input_tokens) && values.cached_input_tokens >= 0) cachedInput = values.cached_input_tokens;
350
- for (const key of [...Object.keys(context), "requested_model", "usage_state", "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "privacy_state", "privacy_pending_bytes", "privacy_new_bytes", "privacy_pending_windows", "privacy_wait_budget_ms", "privacy_error", "privacy_event_type", "privacy_channel_type", "privacy_buffered_bytes", "privacy_terminal_seen", "client_tool_errors_received"]) {
351
+ for (const key of [...Object.keys(context), "requested_model", "reasoning_effort_requested", "reasoning_effort_sent", "usage_state", "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "privacy_state", "privacy_pending_bytes", "privacy_new_bytes", "privacy_pending_windows", "privacy_wait_budget_ms", "privacy_error", "privacy_event_type", "privacy_channel_type", "privacy_buffered_bytes", "privacy_terminal_seen", "client_tool_errors_received"]) {
351
352
  const value = values[key];
353
+ if (["reasoning_effort_requested", "reasoning_effort_sent"].includes(key)) { if (["none", "minimal", "low", "medium", "high", "xhigh", "max"].includes(value)) context[key] = value;continue; }
352
354
  if (key === "requested_model") { if (typeof value === "string" && /^[\w][\w./:@+-]{0,159}$/.test(value) && redactDiagnosticText(value) === value) context[key] = value;continue; }
353
355
  if (key === "usage_state") { if (["pending", "reported", "partial", "missing", "unavailable"].includes(value)) context[key] = value;continue; }
354
356
  if (key === "privacy_state") { if (["checked", "failed", "cancelled"].includes(value)) context[key] = value;continue; }
@@ -413,7 +415,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
413
415
  // Only scalar, allowlisted metadata survives the request; never retain payloads.
414
416
  recentRequests.push({
415
417
  request_id: safeRequestId, ...(session ? { session_id: session.slice(0, 16) } : {}), application: client,
416
- at, route: routeName, model, outcome, origin, phase,
418
+ at, route: routeName, purpose: purposeLabel, model, outcome, origin, phase,
417
419
  ...(["ccdx_model_not_selected", "ccdx_client_source_disabled"].includes(rejectionReason) ? { rejection_reason: rejectionReason } : {}),
418
420
  ...(stopReason ? { stop_reason: stopReason } : {}),
419
421
  ...(provider ? { provider } : {}),
@@ -57,8 +57,8 @@ function observe() {
57
57
  });
58
58
  }
59
59
 
60
- export async function analyzeUsageLogs(filePath = usageLogPath(), { timeZone = "UTC", now = Date.now(), warn = console.error, provider = "", model = "", days = "all", from = "", to = "", signal } = {}) {
61
- const selection = createUsageQuery({ provider, model, days, from, to, timeZone, now });
60
+ export async function analyzeUsageLogs(filePath = usageLogPath(), { timeZone = "UTC", now = Date.now(), warn = console.error, provider = "", model = "", purpose = "", days = "all", from = "", to = "", signal } = {}) {
61
+ const selection = createUsageQuery({ provider, model, purpose, days, from, to, timeZone, now });
62
62
  const zone = new Intl.DateTimeFormat("sv-SE", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" });
63
63
  const file = path.resolve(filePath), query = `${file}\0${selection.key}\0${zone.format(new Date(now))}`;
64
64
  const version = warn === console.error ? await usageSummaryVersion(file, { settled: false }) : null;
@@ -1,12 +1,14 @@
1
1
  import { isProviderId } from "./provider-metadata.mjs";
2
2
  import { usageProvider } from "./usage-store.mjs";
3
+ import { REQUEST_PURPOSES, requestPurpose } from "./request-context.mjs";
3
4
 
4
5
  const DAY_MS = 86400000;
5
6
  const dateValue = value => /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value))
6
7
  && new Date(value).toISOString().slice(0, 10) === value;
7
8
 
8
- export function createUsageQuery({ provider = "", model = "", days = "all", from = "", to = "", timeZone = "UTC", now = Date.now() } = {}) {
9
+ export function createUsageQuery({ provider = "", model = "", purpose = "", days = "all", from = "", to = "", timeZone = "UTC", now = Date.now() } = {}) {
9
10
  if (typeof provider !== "string" || provider && !isProviderId(provider)) throw new Error("Select a valid usage source");
11
+ if (purpose !== "" && !REQUEST_PURPOSES.includes(purpose)) throw new Error("Select a valid request purpose");
10
12
  if (typeof model !== "string" || model.length > 200 || /[\u0000-\u001f\u007f]/.test(model)) throw new Error("Select a valid usage model");
11
13
  if (String(days) !== "all" && (!/^\d+$/.test(String(days)) || Number(days) < 1 || Number(days) > 365)) throw new Error("Usage days must be all or an integer from 1 to 365");
12
14
  if (typeof timeZone !== "string" || timeZone.length > 100) throw new Error("Select a valid usage time zone");
@@ -19,11 +21,12 @@ export function createUsageQuery({ provider = "", model = "", days = "all", from
19
21
  }
20
22
  if (from && !to) to = today;
21
23
  if (from && to && from > to) throw new Error("Usage start date must not follow its end date");
22
- const filters = { provider, model, days: String(days), from, to, time_zone: zone.resolvedOptions().timeZone };
24
+ const filters = { provider, model, purpose, days: String(days), from, to, time_zone: zone.resolvedOptions().timeZone };
23
25
  return {
24
26
  filters,
25
27
  key: JSON.stringify(filters),
26
28
  matches(record) {
29
+ if (purpose && requestPurpose(record.purpose, "unknown") !== purpose) return false;
27
30
  if (provider && usageProvider(record) !== provider) return false;
28
31
  if (model && model !== record.model && model !== `${usageProvider(record)} / ${record.model || "unknown"}`) return false;
29
32
  if (!from && !to) return true;
@@ -8,7 +8,7 @@ import readline from "node:readline";
8
8
  import { appendRotatingLines, parseByteLimit, rotatedFilePath } from "./file-rotation.mjs";
9
9
  import { withFileLock } from "./lock.mjs";
10
10
  import { terminalCell } from "./terminal-text.mjs";
11
- import { currentRequestContext } from "./request-context.mjs";
11
+ import { currentRequestContext, requestPurpose } from "./request-context.mjs";
12
12
 
13
13
  const DEFAULT_USAGE_PATH = path.join(os.homedir(), ".local", "share", "codex-copilot-dx", "usage.jsonl");
14
14
  const DEFAULT_USAGE_MAX_BYTES = 32 * 1024 * 1024;
@@ -203,6 +203,7 @@ function scheduleUsageWriteDrain() {
203
203
 
204
204
  export function recordUsage(record) {
205
205
  if (!record) return Promise.resolve();
206
+ record = { ...record, purpose: requestPurpose(record.purpose ?? currentRequestContext()?.purpose, "unknown") };
206
207
  const usage = record.usage || {};
207
208
  const { cached } = usageCacheEvidence(usage);
208
209
  const provider = usageProvider(record), label = runtimeUsageByProvider.has(provider) || runtimeUsageByProvider.size < 18 ? provider : "other";