codex-copilot-dx 1.2.21 → 1.2.22

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.
@@ -0,0 +1,87 @@
1
+ import path from 'node:path';
2
+ import { createHash } from 'node:crypto';
3
+ import { serialize } from 'node:v8';
4
+ import { codexPaths } from './codex-paths.mjs';
5
+ import { claudeClientPaths } from './claude-client-config.mjs';
6
+ import { accessSettingsPath } from './access-settings.mjs';
7
+ import { userSettingsPath } from './user-settings.mjs';
8
+ import { readBoundedFileSync } from './bounded-file.mjs';
9
+ import { authProfilePaths, readAuthProfileCredentials } from './auth-profile.mjs';
10
+ import { m365Paths } from './m365-settings.mjs';
11
+
12
+ export const HANDOFF_MAX_BYTES = 64 * 1024 * 1024;
13
+ export function clientStateFingerprint(options = {}) {
14
+ const codex = codexPaths(options), connections = accessSettingsPath(options);
15
+ const github = authProfilePaths('codex', options);
16
+ const files = [codex.config, path.join(codex.directory, 'auth.json'), connections, userSettingsPath(options),
17
+ github.tokenPath, m365Paths(options).settings, m365Paths(options).gateway,
18
+ path.join(path.dirname(connections), 'client-gateway-keys.json'), path.join(path.dirname(connections), 'codex-gateway-owner.json'), ...Object.values(claudeClientPaths(options))];
19
+ const hash = createHash('sha256');
20
+ const credentials = readAuthProfileCredentials('codex', options);
21
+ hash.update(JSON.stringify([credentials.valid, credentials.identity?.id ?? null, credentials.identity?.login ?? null]));
22
+ for (const file of files) {
23
+ hash.update(file);try { hash.update(readBoundedFileSync(file, { maxBytes: 8 * 1024 * 1024 })); }
24
+ catch (error) { if (error.code !== 'ENOENT') throw error;hash.update('missing'); }
25
+ }
26
+ return hash.digest('hex');
27
+ }
28
+ export function serviceBusinessState(runtime) {
29
+ const graph = runtime.connections();
30
+ return graph.clients.map(client => ({ id: client.id, enabled: client.enabled, source: client.source, default_model: client.default_model ?? client.model ?? null,
31
+ scopes: runtime.privateScopes?.(client.id) || [],
32
+ models: client.model_plan?.models.map(model => [model.source, model.public_id]).sort((a,b) => JSON.stringify(a).localeCompare(JSON.stringify(b))) || [],
33
+ default_unavailable: client.model_plan?.default_unavailable === true }));
34
+ }
35
+
36
+ export async function createServiceWorker({ processObj = process } = {}) {
37
+ let preserving = false, draining = false, warming = false, handlers, stopRequested = false, updateStatus = { phase: 'watching' };
38
+ const boot = await new Promise((resolve, reject) => {
39
+ const timer = setTimeout(() => { processObj.off('message', receive);reject(new Error('Supervisor initialization timed out')); }, 15000);
40
+ function receive(message) {
41
+ if (message?.type !== 'ccdx:init' || message.protocol !== 1) return;
42
+ clearTimeout(timer);processObj.off('message', receive);resolve(message);
43
+ }
44
+ processObj.on('message', receive);processObj.send({ type: 'ccdx:boot', protocol: 1 });
45
+ });
46
+ preserving = boot.preserve === true;
47
+ warming = boot.warm === true;
48
+ draining = preserving;
49
+ const stop = () => { stopRequested = true;void handlers?.stop(); };
50
+ processObj.once('disconnect', stop);
51
+ processObj.on('message', async message => {
52
+ if (message?.type === 'ccdx:stop') { stop();return; }
53
+ if (!message || !handlers) return;
54
+ if (message.type === 'ccdx:notice' && /^[a-z_]{1,64}$/.test(message.code || '')) { handlers.notice?.(message.code);return; }
55
+ if (message.type === 'ccdx:update-status') { updateStatus = message.value;return; }
56
+ if (message.type !== 'ccdx:call' || !Number.isSafeInteger(message.id)) return;
57
+ try {
58
+ let value;
59
+ if (message.action === 'inspect') value = handlers.inspect();
60
+ else if (message.action === 'commit') { value = handlers.inspect();await handlers.activate?.();preserving = false;draining = false; }
61
+ else if (message.action === 'resume') { await handlers.resume?.();draining = false;value = handlers.inspect(); }
62
+ else if (message.action === 'release') { if (!draining) throw new Error('service_busy');await handlers.release();value = handlers.inspect(); }
63
+ else if (message.action === 'import') { if (!warming) throw new Error('service_busy');await handlers.importState(message.value);value = handlers.inspect(); }
64
+ else if (message.action === 'promote') { if (!warming) throw new Error('service_busy');await handlers.promote();warming = false;value = handlers.inspect(); }
65
+ else if (message.action === 'quiesce') {
66
+ if (handlers.inspect().busy) throw new Error('service_busy');
67
+ draining = true;
68
+ const state = await handlers.exportState();
69
+ if (state.history.bytes + state.optional.bytes + (state.providers?.bytes || 0) > HANDOFF_MAX_BYTES || serialize(state).byteLength > HANDOFF_MAX_BYTES) { draining = false;throw new Error('state_too_large'); }
70
+ value = { ...handlers.inspect(), state };
71
+ } else throw new Error('unknown_action');
72
+ processObj.send({ type: 'ccdx:reply', id: message.id, value });
73
+ } catch (error) {
74
+ const code = ['service_busy', 'state_too_large', 'unknown_action'].includes(error.message) ? error.message : 'handoff_unavailable';
75
+ processObj.send({ type: 'ccdx:reply', id: message.id, error: code });
76
+ }
77
+ });
78
+ return {
79
+ get preserving() { return preserving; }, get draining() { return draining; }, get warming() { return warming; },
80
+ get needsGithub() { return warming && Array.isArray(boot.sources) && boot.sources.includes('github'); },
81
+ takeState() { const state = boot.state;boot.state = undefined;return state; },
82
+ status: () => updateStatus,
83
+ preferenceChanged(enabled) { if (processObj.connected !== false) processObj.send({ type: 'ccdx:preference', enabled }, () => {}); },
84
+ reused() { processObj.send({ type: 'ccdx:ready', protocol: 1, value: { reused: true } }); },
85
+ async ready(value) { handlers = value;if (stopRequested) { await handlers.stop();return; }processObj.send({ type: 'ccdx:ready', protocol: 1, value: handlers.inspect() }); },
86
+ };
87
+ }
@@ -132,6 +132,7 @@ export function createTerminalConsole({ output = process.stdout, errorOutput = p
132
132
  return {
133
133
  get enabled() { return supported() && fits && !verbose; },
134
134
  start() { if (running) return;running = true;tick(); },
135
+ pause() { running = false;if (timer) timers.clearTimeout(timer);timer = null;if (lines) output.write("\n");lines = 0;previous = [];dirty = true; },
135
136
  beginRequest() { active++;dirty = true;let done = false;return () => { if (!done) { done = true;active = Math.max(0, active - 1);dirty = true; } }; },
136
137
  log(method, args) {
137
138
  const message = redactDiagnosticText(format(...args));
@@ -51,6 +51,10 @@ export function readUserSettings({ env = process.env, home = os.homedir(), stric
51
51
  delete parsed[key];
52
52
  }
53
53
  }
54
+ if (Object.hasOwn(parsed, "nightly_updates") && typeof parsed.nightly_updates !== "boolean") {
55
+ if (strict) throw invalidSettings(filePath, "nightly_updates must be a boolean");
56
+ delete parsed.nightly_updates;
57
+ }
54
58
  if (Object.hasOwn(parsed, "terminal_color_theme") && !isColorTheme(parsed.terminal_color_theme)) {
55
59
  if (strict) throw invalidSettings(filePath, "terminal_color_theme must be green, klein or pink");
56
60
  delete parsed.terminal_color_theme;
@@ -123,6 +127,17 @@ export function servicePreferences(options = {}) {
123
127
  const settings = readUserSettings({ ...options, strict: true });
124
128
  return serviceFlags(settings);
125
129
  }
130
+ export function nightlyUpdatePreference(options = {}) {
131
+ return readUserSettings({ ...options, strict: true }).nightly_updates === true;
132
+ }
133
+ export function writeNightlyUpdatePreference(enabled, options = {}) {
134
+ if (typeof enabled !== "boolean") throw new Error("Nightly updates require a boolean");
135
+ return withFileLockSync(`${userSettingsPath(options)}.lock`, () => {
136
+ const settings = readUserSettings({ ...options, strict: true });
137
+ atomicWriteFileIfChangedSync(userSettingsPath(options), `${JSON.stringify({ ...settings, nightly_updates: enabled }, null, 2)}\n`, { mode: 0o600 });
138
+ return enabled;
139
+ });
140
+ }
126
141
  const serviceFlags = settings => Object.fromEntries(SERVICE_FLAGS.map(key => [key, settings[key] !== false]));
127
142
 
128
143
  // One strict read gives each status update a coherent view; no stale cache.