codex-copilot-dx 1.3.5 → 1.3.7

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.
@@ -27,13 +27,14 @@ export function createProviderRuntime(options = {}) {
27
27
  options = { ...options, corePort: options.corePort ?? Number((options.env || process.env).ADAPTER_PORT || 2026) };
28
28
  let connections;
29
29
  const legacy = createBuiltinProviderRuntime({ ...options, managedClaude: () => connections?.managesClaude() !== false,
30
+ privacy: { wrap: (fn, context) => connections?.privacy.wrap(fn, context) || fn },
30
31
  onClaudeReady: () => connections?.syncSourceClients("m365") });
31
32
  connections = createConnectionRuntime({ ...options, legacy });return connections;
32
33
  }
33
34
 
34
35
  function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGithubCatalog, githubCredentialFingerprint = "", githubClientConfigured = true, home, env = process.env, platform = process.platform,
35
36
  corePort = Number(env.ADAPTER_PORT || 2026), log = () => {}, createM365, startGateway, configureClients, restoreClients,
36
- discoverM365 = requestM365Accounts, managedClaude, onClaudeReady, preserveClientConfiguration } = {}) {
37
+ discoverM365 = requestM365Accounts, managedClaude, onClaudeReady, preserveClientConfiguration, privacy } = {}) {
37
38
  const options = { home, env, platform }, github = { ...createGithubProvider({ client: githubClient,
38
39
  profileId: () => { const value = typeof githubCredentialFingerprint === "function" ? githubCredentialFingerprint() : githubCredentialFingerprint;
39
40
  return value ? `codex:${value}` : "codex"; } }), registry: githubRegistry };
@@ -85,7 +86,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
85
86
  const apiKey = ensureM365GatewayKey({ ...options, create: !preserveClientConfiguration?.() });
86
87
  if (!gateway) {
87
88
  const start = startGateway || (await import("./claude-gateway.mjs")).createClaudeGateway;
88
- const opened = await start({ provider: m365, apiKey, port: corePort, env, log, performance: claudePerformance,
89
+ const opened = await start({ privacy, provider: m365, apiKey, port: corePort, env, log, performance: claudePerformance,
89
90
  onRequest({ client }) { lastClients[client] = new Date().toISOString(); } });
90
91
  if (closed || !enabled) { await opened.close();return null; }
91
92
  gateway = opened;
@@ -152,7 +153,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
152
153
  if (closed) throw unavailable("m365_runtime_closed");
153
154
  if (candidate.models("claude").length) {
154
155
  const start = startGateway || (await import("./claude-gateway.mjs")).createClaudeGateway;
155
- opened = await start({ provider: candidate, apiKey: ensureM365GatewayKey(options), port: corePort, env, log, performance: claudePerformance,
156
+ opened = await start({ privacy, provider: candidate, apiKey: ensureM365GatewayKey(options), port: corePort, env, log, performance: claudePerformance,
156
157
  onRequest({ client }) { lastClients[client] = new Date().toISOString(); } });
157
158
  }
158
159
  candidate.commitSelection(discovered.binding);
@@ -127,7 +127,12 @@ export function requestOptionsEvidence(body) {
127
127
  if (["text", "json_object", "json_schema"].includes(body.text?.format?.type)) result.output_format = body.text.format.type;
128
128
  if (Number.isSafeInteger(body.max_output_tokens) && body.max_output_tokens >= 0) result.max_output_tokens = body.max_output_tokens;
129
129
  if (Number.isSafeInteger(body.max_tokens) && body.max_tokens >= 0) result.max_tokens = body.max_tokens;
130
- if (Array.isArray(body.tools)) result.tools = body.tools.length;
130
+ const countTools = tools => Array.isArray(tools) ? tools.reduce((n, tool) => n + (tool?.type === "namespace" ? countTools(tool.tools) : 1), 0) : 0;
131
+ const inline = Array.isArray(body.input) ? body.input.filter(item => ["additional_tools", "tool_search_output"].includes(item?.type)) : [];
132
+ if (Array.isArray(body.tools) || inline.length) result.tools = countTools(body.tools) + inline.reduce((n, item) => n + countTools(item.tools), 0);
133
+ const last = Array.isArray(body.messages) ? body.messages.at(-1) : null;
134
+ const clientErrors = last?.role === "user" && Array.isArray(last.content) ? last.content.filter(block => block?.type === "tool_result" && block.is_error === true).length : 0;
135
+ if (clientErrors) result.client_tool_errors_received = clientErrors;
131
136
  if (Array.isArray(body.input)) result.input_items = body.input.length;
132
137
  return result;
133
138
  }
@@ -192,7 +197,8 @@ export function buildHttpFailureDetails({ statusCode, route, requestId, model, c
192
197
  }
193
198
  const message = (Object.hasOwn(reasons, reason) ? reasons[reason] : null) || (route === "messages_count_tokens" && statusCode === 404 ? "The source's token-count endpoint returned HTTP 404. Message generation is separate."
194
199
  : code === "ccdx_api_network_unavailable" ? "Connection to the model source failed."
195
- : origin === "client_validation" ? "The request was rejected locally before an upstream call."
200
+ : origin === "privacy" ? "Local privacy processing failed. Review its error code and request timeline."
201
+ : origin === "client_validation" ? "The request was rejected locally before an upstream call."
196
202
  : error_body === "empty" ? "Upstream returned no error details." : "HTTP request failed; original response was preserved.");
197
203
  const details = responseFailureDetails({ model, error: { code: typeof code === "string" && /^[a-z\d_.:-]{1,80}$/i.test(code) ? code : `http_${statusCode}`,
198
204
  message: model_error ? "The model source reported an error; the original HTTP response was preserved." : message } }, model_error ? "model.error" : "http.error", { headers, provider });
@@ -270,6 +270,11 @@ export function createResponsesHandler(options) {
270
270
  prepared = selected instanceof Promise ? await selected : selected;
271
271
  if (prepared.historyParentId === null) releaseHistorySnapshot();
272
272
  provider.applyRequestPolicies(prepared.body);
273
+ if (options.privacy) {
274
+ prepared.privacyRestore = value => options.privacy.restoreResponse(res, value);
275
+ responsesFn = options.privacy.wrap(responsesFn, { res, protocol: "responses", client: "codex" });
276
+ chatCompletionsFn = options.privacy.wrap(chatCompletionsFn, { res, protocol: "chat", client: "codex" });
277
+ }
273
278
  if (routePlan.protocol === "openai-responses") {
274
279
  const restorePlaintextHistory = async (context, { reserveHistory } = {}) => {
275
280
  assertPrepareActive();
@@ -322,7 +327,7 @@ export function createResponsesHandler(options) {
322
327
  const written = await writeOrDrain(res, `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`, { signal: abort.signal });
323
328
  if (!written) return false;
324
329
  if (event === "response.completed" || event === "response.incomplete") {
325
- if (event === "response.completed") rememberResponseHistory(prepared, data.response);
330
+ if (event === "response.completed") rememberResponseHistory(prepared, prepared.privacyRestore?.(data.response) || data.response);
326
331
  recordResponsesUsage({ surface: prepared.surface, mode: "stream", model, response: data.response, event: data });
327
332
  }
328
333
  return true;
@@ -385,7 +390,7 @@ export function createResponsesHandler(options) {
385
390
  markResponseTerminal(response.status, {
386
391
  model: response.model || model, origin: "chat_completion", reason: response.incomplete_details?.reason,
387
392
  });
388
- rememberResponseHistory(prepared, response);
393
+ rememberResponseHistory(prepared, prepared.privacyRestore?.(response) || response);
389
394
  if (response.status === "completed") imagePressure?.markSuccess?.(responseHistoryPressureRootId(prepared));
390
395
  recordResponsesUsage({ surface: prepared.surface, mode: "json", model, response, event: response });
391
396
  res.writeHead(200, safeUpstreamResponseHeaders(upstream.headers, {
@@ -394,7 +399,7 @@ export function createResponsesHandler(options) {
394
399
  res.end(JSON.stringify(response));
395
400
  } catch (error) {
396
401
  const responseError = applyAdaptiveTimeout(error);
397
- markResponseErrorOrigin(responseError?.statusCode >= 400 && responseError.statusCode < 500
402
+ markResponseErrorOrigin(responseError?.origin === "privacy" ? "privacy" : responseError?.statusCode >= 400 && responseError.statusCode < 500
398
403
  ? "client_validation" : "transport");
399
404
  logRequestFailure("Responses", responseError, abort);
400
405
  sendJsonError(res, responseError, 502);
@@ -405,7 +410,7 @@ export function createResponsesHandler(options) {
405
410
  }
406
411
  } catch (error) {
407
412
  const responseError = applyAdaptiveTimeout(error);
408
- markResponseErrorOrigin(responseError?.statusCode >= 400 && responseError.statusCode < 500
413
+ markResponseErrorOrigin(responseError?.origin === "privacy" ? "privacy" : responseError?.statusCode >= 400 && responseError.statusCode < 500
409
414
  ? "client_validation" : "transport");
410
415
  logRequestFailure("Responses", responseError, abort);
411
416
  sendJsonError(res, responseError, 502);
@@ -553,6 +558,10 @@ export function createResponsesCompactHandler(options) {
553
558
  prepared = selected instanceof Promise ? await selected : selected;
554
559
  releaseHistorySnapshot();
555
560
  provider.applyRequestPolicies(prepared.body);
561
+ if (options.privacy) {
562
+ prepared.privacyRestore = value => options.privacy.restoreResponse(res, value);
563
+ responsesCompactFn = options.privacy.wrap(responsesCompactFn, { res, protocol: "responses", client: "codex" });
564
+ }
556
565
  const result = await proxyCopilotResponses(prepared, req, res, responsesCompactFn, {
557
566
  compatibility: provider.compatibility,
558
567
  assertPrepareActive,
@@ -316,7 +316,7 @@ function parseSuccessfulResponsesResult(text) {
316
316
 
317
317
  function storeCompletedResponse(reqContext, completed) {
318
318
  if (!completed) return;
319
- rememberResponseHistory(reqContext, completed.response);
319
+ rememberResponseHistory(reqContext, reqContext.privacyRestore?.(completed.response) || completed.response);
320
320
  recordResponsesUsage({
321
321
  surface: reqContext.surface,
322
322
  mode: "stream",
@@ -520,7 +520,7 @@ async function proxyStreamingResponses(opened, res, upstream, options) {
520
520
  if (!res.writableEnded) res.end();
521
521
  return { successful: Boolean(streamState.completed), compacted: false };
522
522
  } catch (error) {
523
- markResponseErrorOrigin("transport");
523
+ markResponseErrorOrigin(error.origin === "privacy" ? "privacy" : "transport");
524
524
  markStreamFailure();
525
525
  logRequestFailure("Responses", error, options.abort);
526
526
  writeHeaders();
@@ -571,7 +571,7 @@ export async function proxyCopilotResponses(reqContext, req, res, upstream = cop
571
571
  compactionInputWithoutTrigger(reqContext.body.input),
572
572
  data,
573
573
  );
574
- rememberResponseHistory(reqContext, response);
574
+ rememberResponseHistory(reqContext, reqContext.privacyRestore?.(response) || response);
575
575
  recordResponsesUsage({
576
576
  surface: reqContext.surface,
577
577
  mode: "json",
@@ -620,7 +620,7 @@ export async function proxyCopilotResponses(reqContext, req, res, upstream = cop
620
620
  continue;
621
621
  }
622
622
  }
623
- rememberResponseHistory(reqContext, response);
623
+ rememberResponseHistory(reqContext, reqContext.privacyRestore?.(response) || response);
624
624
  recordResponsesUsage({
625
625
  surface: reqContext.surface,
626
626
  mode: "json",
@@ -18,7 +18,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
18
18
  try { imageConfigured = Boolean(readImages()); } catch {}
19
19
  try { predictionConfigured = readPrediction().enabled === true; } catch {}
20
20
  const enabled = nightlyUpdatePreference(options), nightly = nightlyStatus();
21
- return { source: "service_settings", saved, theme, color_theme, preferences: settingsPreferencesSnapshot(options),
21
+ return { source: "service_settings", saved, theme, color_theme, preferences: settingsPreferencesSnapshot(options), local_privacy: providerRuntime?.privacy?.snapshot(),
22
22
  nightly_update: { enabled, ...nightly, effect: enabled && !nightly ? "next_start" : "immediate" },
23
23
  effective: {
24
24
  terminal_animation_enabled: { value: terminal?.enabled === true && saved.terminal_animation_enabled && !/^(0|false|no|off)$/i.test(env.CCDX_TERMINAL_ANIMATION || ""),
@@ -40,6 +40,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
40
40
  if (["preferences", "reset_preferences", "restore_preferences"].includes(input.action)) {
41
41
  const before = nightlyUpdatePreference(options);
42
42
  writeSettingsPreferences(input, options);
43
+ if (input.action !== "preferences" || Object.keys(input.values || {}).some(key => key.startsWith("privacy_"))) providerRuntime?.privacy?.settingsChanged();
43
44
  const current = settingsPreferencesSnapshot(options).values;
44
45
  terminal?.apply?.({ ...servicePreferences(options), theme: current.terminal_animation, color_theme: current.terminal_color_theme });
45
46
  if (before !== current.nightly_updates) nightlyChanged(current.nightly_updates);
@@ -9,7 +9,7 @@ import { atomicWriteFileIfChangedSync, atomicWriteFilePairSync } from "./atomic-
9
9
  import { withFileLockSync } from "./lock.mjs";
10
10
 
11
11
  export const SETTINGS_DEFAULTS = Object.freeze({ terminal_color_theme: "green", terminal_animation: DEFAULT_TERMINAL_ANIMATION_THEME,
12
- terminal_animation_enabled: true, open_webui: true, nightly_updates: false, auto_save_settings: true });
12
+ terminal_animation_enabled: true, open_webui: true, nightly_updates: false, auto_save_settings: true, privacy_enabled: false, privacy_personal: false });
13
13
  const keys = Object.keys(SETTINGS_DEFAULTS);
14
14
  const fail = (code, message, statusCode = 409) => Object.assign(new Error(message), { code, statusCode });
15
15
  const idValid = value => typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(value);
@@ -30,7 +30,8 @@ function readBackup(options) {
30
30
  const value = JSON.parse(readBoundedFileSync(settingsBackupPath(options), { encoding: "utf8", maxBytes: 8192 }));
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
- || keys.some(key => !Object.hasOwn(value.values || {}, key))) throw Error();
33
+ || keys.filter(key => !key.startsWith("privacy_")).some(key => !Object.hasOwn(value.values || {}, key))) throw Error();
34
+ value.values = { privacy_enabled: false, privacy_personal: false, ...value.values };
34
35
  checkedPreferenceValues(value.values);return value;
35
36
  } catch (error) {
36
37
  if (error.code === "ENOENT") return null;
@@ -11,7 +11,7 @@ const TERMINAL_OUTCOMES = Object.freeze(["completed", "incomplete", "failed", "c
11
11
  const INCOMPLETE_REASONS = new Set(["max_output_tokens", "max_messages", "content_filter", "steered"]);
12
12
  const TERMINAL_ORIGINS = new Set([
13
13
  "upstream_response", "upstream_event", "chat_completion", "client_validation",
14
- "upstream_http", "transport", "client_disconnect", "unclassified",
14
+ "upstream_http", "transport", "privacy", "client_disconnect", "unclassified",
15
15
  ]);
16
16
  const MAX_MODEL_OUTCOME_LABELS = 32;
17
17
  const MAX_RECENT_REQUESTS = 20;
@@ -342,7 +342,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
342
342
  observeContext(values) {
343
343
  if (finished || !values || typeof values !== "object") return;
344
344
  if (Number.isSafeInteger(values.cached_input_tokens) && values.cached_input_tokens >= 0) cachedInput = values.cached_input_tokens;
345
- for (const key of [...Object.keys(context), "capability_revision", "capability_constraints"]) {
345
+ for (const key of [...Object.keys(context), "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "client_tool_errors_received"]) {
346
346
  const value = values[key];
347
347
  if (["capability_revision", "capability_constraints"].includes(key)) {
348
348
  if (typeof value === "string" && /^[a-z0-9_,]{1,80}$/.test(value)) context[key] = value;continue;
@@ -51,7 +51,7 @@ export function readUserSettings({ env = process.env, home = os.homedir(), stric
51
51
  delete parsed[key];
52
52
  }
53
53
  }
54
- for (const key of ["nightly_updates", "auto_save_settings"]) if (Object.hasOwn(parsed, key) && typeof parsed[key] !== "boolean") {
54
+ for (const key of ["nightly_updates", "auto_save_settings", "privacy_enabled", "privacy_personal"]) if (Object.hasOwn(parsed, key) && typeof parsed[key] !== "boolean") {
55
55
  if (strict) throw invalidSettings(filePath, `${key} must be a boolean`);
56
56
  delete parsed[key];
57
57
  }