codex-copilot-dx 1.3.6 → 1.3.8
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 +7 -16
- package/bin/cli.mjs +55 -31
- package/docs/ARCHITECTURE.md +14 -2
- package/docs/REFERENCE.md +38 -5
- package/package.json +6 -2
- package/src/claude-gateway.mjs +2 -1
- package/src/cli-command-spec.mjs +3 -2
- package/src/cli-image.mjs +2 -80
- package/src/cli-options.mjs +1 -1
- package/src/client-integration.mjs +11 -4
- package/src/dashboard/connections.js +4 -0
- package/src/dashboard/console.js +12 -6
- package/src/dashboard/features.js +68 -0
- package/src/dashboard/index.html +11 -9
- package/src/dashboard/language.js +57 -14
- package/src/dashboard/status.js +2 -1
- package/src/dashboard/tools.js +4 -1
- package/src/dashboard/ui.js +1 -1
- package/src/dashboard-api.mjs +2 -2
- package/src/dashboard-tools.mjs +2 -1
- package/src/dashboard.mjs +1 -0
- package/src/doctor-compat.mjs +19 -13
- package/src/doctor.mjs +1 -1
- package/src/image-setup.mjs +110 -0
- package/src/local-privacy.mjs +1 -0
- package/src/local-tools.mjs +8 -2
- package/src/native-prediction-profile.mjs +5 -2
- package/src/native-prediction.mjs +18 -2
- package/src/optional-routes.mjs +1 -1
- package/src/prediction-control.mjs +64 -0
- package/src/prediction-operations.mjs +68 -0
- package/src/prediction-preference.mjs +75 -0
- package/src/privacy-model.mjs +6 -4
- package/src/privacy-transform.mjs +39 -25
- package/src/response-failures.mjs +8 -2
- package/src/responses-handler.mjs +2 -2
- package/src/responses-proxy.mjs +1 -1
- package/src/service-control.mjs +33 -7
- package/src/service-supervisor.mjs +39 -18
- package/src/service-worker.mjs +13 -1
- package/src/stream-performance.mjs +2 -2
|
@@ -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
|
-
|
|
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 === "
|
|
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 });
|
|
@@ -399,7 +399,7 @@ export function createResponsesHandler(options) {
|
|
|
399
399
|
res.end(JSON.stringify(response));
|
|
400
400
|
} catch (error) {
|
|
401
401
|
const responseError = applyAdaptiveTimeout(error);
|
|
402
|
-
markResponseErrorOrigin(responseError?.statusCode >= 400 && responseError.statusCode < 500
|
|
402
|
+
markResponseErrorOrigin(responseError?.origin === "privacy" ? "privacy" : responseError?.statusCode >= 400 && responseError.statusCode < 500
|
|
403
403
|
? "client_validation" : "transport");
|
|
404
404
|
logRequestFailure("Responses", responseError, abort);
|
|
405
405
|
sendJsonError(res, responseError, 502);
|
|
@@ -410,7 +410,7 @@ export function createResponsesHandler(options) {
|
|
|
410
410
|
}
|
|
411
411
|
} catch (error) {
|
|
412
412
|
const responseError = applyAdaptiveTimeout(error);
|
|
413
|
-
markResponseErrorOrigin(responseError?.statusCode >= 400 && responseError.statusCode < 500
|
|
413
|
+
markResponseErrorOrigin(responseError?.origin === "privacy" ? "privacy" : responseError?.statusCode >= 400 && responseError.statusCode < 500
|
|
414
414
|
? "client_validation" : "transport");
|
|
415
415
|
logRequestFailure("Responses", responseError, abort);
|
|
416
416
|
sendJsonError(res, responseError, 502);
|
package/src/responses-proxy.mjs
CHANGED
|
@@ -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();
|
package/src/service-control.mjs
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { serviceSettingsSnapshot, servicePreferences, writeServicePreference,
|
|
2
2
|
writeTerminalAnimationTheme, writeTerminalColorTheme, responseHistoryLimitPreference, writeResponseHistoryLimitMib,
|
|
3
|
-
nightlyUpdatePreference, writeNightlyUpdatePreference } from "./user-settings.mjs";
|
|
3
|
+
nightlyUpdatePreference, writeNightlyUpdatePreference, decodedBodyLimitPreference, writeDecodedBodyLimitMib } from "./user-settings.mjs";
|
|
4
4
|
import { readImageProviderConfig } from "./image-provider-config.mjs";
|
|
5
5
|
import { readPredictionSettings } from "./native-prediction-profile.mjs";
|
|
6
6
|
import { cacheRuntimeSnapshot, cleanRuntimeCaches, setHistoryCacheLimit } from "./cache-control.mjs";
|
|
7
7
|
import { isTerminalAnimationTheme } from "./terminal-animation.mjs";
|
|
8
8
|
import { settingsPreferencesSnapshot, writeSettingsPreferences } from "./settings-preferences.mjs";
|
|
9
|
+
import { predictionControlSnapshot, controlPrediction } from "./prediction-control.mjs";
|
|
10
|
+
import { imageSetupSummary, configureImageSetup } from "./image-setup.mjs";
|
|
9
11
|
|
|
10
12
|
export function createServiceControl({ env = process.env, home, providerRuntime, clientIntegration, terminal,
|
|
11
13
|
nightlyStatus = () => null, nightlyChanged = () => {},
|
|
14
|
+
manualUpdate, predictionControl = controlPrediction, imageControl = configureImageSetup,
|
|
15
|
+
adapterPort = 2026, adapterHost = "127.0.0.1",
|
|
12
16
|
readImages = () => readImageProviderConfig({ env, home }), readPrediction = () => readPredictionSettings({ env, home }) } = {}) {
|
|
13
17
|
const options = { env, home };
|
|
14
|
-
let serial = Promise.resolve();
|
|
18
|
+
let serial = Promise.resolve(), lastOperation = null, pending = 0;
|
|
19
|
+
const featureSnapshot = read => { try { return read(options); } catch { return { status: "unavailable" }; } };
|
|
15
20
|
function snapshot() {
|
|
16
21
|
const { saved, theme, color_theme, historyLimit } = serviceSettingsSnapshot(options), prediction = clientIntegration?.snapshot().prediction;
|
|
17
22
|
let imageConfigured = false, predictionConfigured = false;
|
|
@@ -19,6 +24,8 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
19
24
|
try { predictionConfigured = readPrediction().enabled === true; } catch {}
|
|
20
25
|
const enabled = nightlyUpdatePreference(options), nightly = nightlyStatus();
|
|
21
26
|
return { source: "service_settings", saved, theme, color_theme, preferences: settingsPreferencesSnapshot(options), local_privacy: providerRuntime?.privacy?.snapshot(),
|
|
27
|
+
features: { prediction: { ...featureSnapshot(predictionControlSnapshot), bridge: prediction?.bridge || "stopped", active: prediction?.active === true }, image: featureSnapshot(imageSetupSummary) },
|
|
28
|
+
decoded_body: decodedBodyLimitPreference(options), manual_update: { available: typeof manualUpdate === "function" }, last_operation: lastOperation,
|
|
22
29
|
nightly_update: { enabled, ...nightly, effect: enabled && !nightly ? "next_start" : "immediate" },
|
|
23
30
|
effective: {
|
|
24
31
|
terminal_animation_enabled: { value: terminal?.enabled === true && saved.terminal_animation_enabled && !/^(0|false|no|off)$/i.test(env.CCDX_TERMINAL_ANIMATION || ""),
|
|
@@ -34,10 +41,26 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
34
41
|
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Invalid setting action");
|
|
35
42
|
const allowed = { preference: ["action", "key", "value"], nightly_update: ["action", "enabled"], animation: ["action", "theme"], color_theme: ["action", "theme"],
|
|
36
43
|
history_limit: ["action", "mib"], history_clean: ["action"], prediction_fix: ["action"],
|
|
44
|
+
prediction: ["action", "operation"], image: ["action", "operation", "endpoint", "key", "model"],
|
|
45
|
+
update: ["action", "confirmed"], decoded_limit: ["action", "mib"],
|
|
37
46
|
preferences: ["action", "values", "revision"], reset_preferences: ["action", "revision", "backup_id", "scope"], restore_preferences: ["action", "revision", "backup_id", "scope"],
|
|
38
47
|
provider: ["action", "operation", "provider", "model", "auto_review_model", "auto_review_effort", "account_id"] }[input.action];
|
|
39
48
|
if (!allowed || Object.keys(input).some(key => !allowed.includes(key))) throw new Error("Unknown setting action or field");
|
|
40
|
-
|
|
49
|
+
lastOperation = null;
|
|
50
|
+
if (input.action === "prediction") {
|
|
51
|
+
lastOperation = { feature: "prediction", result: await predictionControl(input.operation, { ...options, integration: clientIntegration }) };
|
|
52
|
+
} else if (input.action === "image") {
|
|
53
|
+
for (const [key, limit] of [["endpoint", 2048], ["key", 8192], ["model", 200]]) if (input[key] !== undefined && (typeof input[key] !== "string" || input[key].length > limit)) throw new Error("Invalid image setup input");
|
|
54
|
+
if (["pause", "resume"].includes(input.operation)) writeServicePreference("image_enabled", input.operation === "resume", options);
|
|
55
|
+
else lastOperation = { feature: "image", result: await imageControl(input, { ...options, adapterPort, adapterHost }) };
|
|
56
|
+
} else if (input.action === "update") {
|
|
57
|
+
if (input.confirmed !== true) throw new Error("Confirm installation and the idle service switch");
|
|
58
|
+
if (!manualUpdate) throw new Error("This launch cannot update itself; use the installer or start CCDX from its installed command");
|
|
59
|
+
lastOperation = { feature: "update", result: await manualUpdate() };
|
|
60
|
+
} else if (input.action === "decoded_limit") {
|
|
61
|
+
if (decodedBodyLimitPreference(options).source === "environment") throw new Error("Request limit is controlled by the launch environment");
|
|
62
|
+
writeDecodedBodyLimitMib(input.mib, options);
|
|
63
|
+
} else if (["preferences", "reset_preferences", "restore_preferences"].includes(input.action)) {
|
|
41
64
|
const before = nightlyUpdatePreference(options);
|
|
42
65
|
writeSettingsPreferences(input, options);
|
|
43
66
|
if (input.action !== "preferences" || Object.keys(input.values || {}).some(key => key.startsWith("privacy_"))) providerRuntime?.privacy?.settingsChanged();
|
|
@@ -47,8 +70,8 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
47
70
|
} else if (input.action === "nightly_update") {
|
|
48
71
|
writeNightlyUpdatePreference(input.enabled, options);nightlyChanged(input.enabled);
|
|
49
72
|
} else if (input.action === "preference") {
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
if (input.key === "prediction_enabled") await predictionControl(input.value ? "enable" : "disable", { ...options, integration: clientIntegration });
|
|
74
|
+
else writeServicePreference(input.key, input.value, options);
|
|
52
75
|
terminal?.apply?.({ ...servicePreferences(options) });
|
|
53
76
|
} else if (input.action === "color_theme") {
|
|
54
77
|
writeTerminalColorTheme(input.theme, options);terminal?.apply?.({ color_theme: input.theme });
|
|
@@ -57,7 +80,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
57
80
|
writeTerminalAnimationTheme(input.theme, options);terminal?.apply?.({ theme: input.theme });
|
|
58
81
|
} else if (input.action === "prediction_fix") {
|
|
59
82
|
if (!clientIntegration) throw new Error("Prediction integration is unavailable");
|
|
60
|
-
await clientIntegration
|
|
83
|
+
await predictionControl("repair", { ...options, integration: clientIntegration });
|
|
61
84
|
} else if (input.action === "history_limit") {
|
|
62
85
|
if (responseHistoryLimitPreference(options).source === "environment") throw new Error("History limit is controlled by CCDX_RESPONSE_HISTORY_MAX_BYTES");
|
|
63
86
|
if (!Number.isSafeInteger(input.mib)) throw new Error("History limit must be an integer MiB value");
|
|
@@ -74,5 +97,8 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
74
97
|
}
|
|
75
98
|
return snapshot();
|
|
76
99
|
}
|
|
77
|
-
return { snapshot,
|
|
100
|
+
return { snapshot, busy: () => pending > 0, action(input) {
|
|
101
|
+
const counted = input?.action !== "update";if (counted) pending++;
|
|
102
|
+
const operation = serial.then(() => apply(input)).finally(() => { if (counted) pending--; });serial = operation.catch(() => {});return operation;
|
|
103
|
+
} };
|
|
78
104
|
}
|
|
@@ -4,9 +4,10 @@ import { fork } from 'node:child_process';
|
|
|
4
4
|
import { nightlyUpdatePreference, userSettingsPath } from './user-settings.mjs';
|
|
5
5
|
import { atomicWriteFileIfChangedSync } from './atomic-file.mjs';
|
|
6
6
|
import { createNpmReleaseFetch } from './release-install.mjs';
|
|
7
|
+
import { isVersionGreater } from './version.mjs';
|
|
7
8
|
import { installedUpdateEnvironment, retainCurrentRuntime, lookupNightlyRelease, eligiblePatch, nightlyWindow, nightlyDay, NIGHTLY_IDLE_MS, prepareNightlyRelease, verifyNightlyRuntime, readNightlyState } from './nightly-update.mjs';
|
|
8
9
|
|
|
9
|
-
export function launchServiceWorker(target, { args = [], env = process.env, state, preserve = false, warm = false, sources = [], onPreference = () => {}, forkImpl = fork } = {}) {
|
|
10
|
+
export function launchServiceWorker(target, { args = [], env = process.env, state, preserve = false, warm = false, sources = [], onPreference = () => {}, onManualUpdate = () => {}, forkImpl = fork } = {}) {
|
|
10
11
|
const child = forkImpl(path.join(target,'bin/cli.mjs'),preserve ? [...args.filter(value=>value!=='--no-browser'),'--no-browser'] : args, {
|
|
11
12
|
env:{...env,CCDX_SUPERVISED_SERVICE:'1',...(preserve?{CCDX_AUTO_LAUNCH:'0'}:{})},stdio:['inherit','inherit','inherit','ipc'],serialization:'advanced',windowsHide:true,
|
|
12
13
|
});
|
|
@@ -21,6 +22,7 @@ export function launchServiceWorker(target, { args = [], env = process.env, stat
|
|
|
21
22
|
if(message?.type==='ccdx:boot'){child.send({type:'ccdx:init',protocol:1,preserve,warm,sources,state});state=undefined;}
|
|
22
23
|
else if(message?.type==='ccdx:ready'){settled=true;clearTimeout(timer);readyResolve(message.value);}
|
|
23
24
|
else if(message?.type==='ccdx:preference')onPreference(message.enabled===true);
|
|
25
|
+
else if(message?.type==='ccdx:manual-update')onManualUpdate();
|
|
24
26
|
else if(message?.type==='ccdx:reply'){
|
|
25
27
|
const entry=pending.get(message.id);if(!entry)return;pending.delete(message.id);message.error?entry.reject(new Error(message.error)):entry.resolve(message.value);
|
|
26
28
|
}
|
|
@@ -130,9 +132,9 @@ export async function runServiceSupervisor({args=process.argv.slice(2),env=proce
|
|
|
130
132
|
now=()=>new Date(),launch=launchServiceWorker,prepare=prepareNightlyRelease,lookup,processObj=process,log=message=>console.log(message),
|
|
131
133
|
retain=retainCurrentRuntime,verify=verifyNightlyRuntime,timers={setInterval,clearInterval}}={}) {
|
|
132
134
|
let current=retain(environment),version=JSON.parse(fs.readFileSync(path.join(current.target,'package.json'))).version;
|
|
133
|
-
let stopping=false,worker,pendingWorker,timer,scheduler;const retired=new Set();
|
|
134
|
-
const start=(target,options={})=>pendingWorker=launch(target,{args,env,...options,onPreference:enabled=>{if(!enabled)scheduler?.cancel();}});
|
|
135
|
-
const stop=()=>{if(stopping)return;stopping=true;timers.clearInterval(timer);scheduler?.cancel();void worker?.stop().catch(()=>{});if(pendingWorker!==worker)void pendingWorker?.stop().catch(()=>{});for(const item of retired)void item.worker.stop().catch(()=>{});};
|
|
135
|
+
let stopping=false,worker,pendingWorker,timer,scheduler,manualFlight=null,manualController=null,requestManualUpdate;const retired=new Set();
|
|
136
|
+
const start=(target,options={})=>pendingWorker=launch(target,{args,env,...options,onPreference:enabled=>{if(!enabled)scheduler?.cancel();},onManualUpdate:()=>{void requestManualUpdate?.();}});
|
|
137
|
+
const stop=()=>{if(stopping)return;stopping=true;timers.clearInterval(timer);scheduler?.cancel();manualController?.abort();void worker?.stop().catch(()=>{});if(pendingWorker!==worker)void pendingWorker?.stop().catch(()=>{});for(const item of retired)void item.worker.stop().catch(()=>{});};
|
|
136
138
|
processObj.once('SIGINT',stop);processObj.once('SIGTERM',stop);
|
|
137
139
|
try{
|
|
138
140
|
await verify(current.target,version,{brokerRequired:fs.existsSync(path.join(current.target,'node_modules/@azure/msal-node-runtime'))});
|
|
@@ -142,27 +144,46 @@ export async function runServiceSupervisor({args=process.argv.slice(2),env=proce
|
|
|
142
144
|
const stateFile=path.join(path.dirname(userSettingsPath({env})),'nightly-update-state.json');let state;
|
|
143
145
|
try{state=readNightlyState(stateFile);}catch{state=null;worker.status({phase:'unavailable'});worker.notice('update_records_unreadable');}
|
|
144
146
|
let fetchImpl;
|
|
145
|
-
|
|
147
|
+
const readRelease=lookup|| (async options=>{fetchImpl||=createNpmReleaseFetch(environment.npmCli,{env});return lookupNightlyRelease(fetchImpl,options);});
|
|
148
|
+
async function installCandidate(candidate,baseline,options,manual=false) {
|
|
149
|
+
try {
|
|
150
|
+
if(JSON.parse(fs.readFileSync(path.join(environment.target,'package.json'))).version!==version){candidate.cleanup();throw new Error('installation_changed');}
|
|
151
|
+
const result=await switchServiceVersion({worker,current,candidate,baseline,launch:start,stopped:()=>stopping,
|
|
152
|
+
cancelled:()=>stopping||!manual&&(!nightlyUpdatePreference({env})||!nightlyWindow(now())),onPhase:phase=>worker.status({phase,version:candidate.version}),signal:options.signal});
|
|
153
|
+
worker=result.worker;current=result.current;version=result.version;
|
|
154
|
+
if(result.retired)retired.add(result.retired);
|
|
155
|
+
}catch(error){if(error.restoredWorker)worker=error.restoredWorker;throw error;}
|
|
156
|
+
}
|
|
157
|
+
async function manualUpdate() {
|
|
158
|
+
if(stopping||manualFlight)return;
|
|
159
|
+
scheduler?.cancel();
|
|
160
|
+
manualController=new AbortController();
|
|
161
|
+
manualFlight=(async()=>{
|
|
162
|
+
await scheduler?.wait();worker.status({phase:'checking',manual:true});
|
|
163
|
+
const baseline=await worker.call('inspect');
|
|
164
|
+
if(baseline.busy||baseline.activity.active)throw new Error('service_busy');
|
|
165
|
+
const release=await readRelease({currentVersion:version,signal:manualController.signal});
|
|
166
|
+
if(!release||!isVersionGreater(release.version,version)){worker.status({phase:'current',manual:true});return;}
|
|
167
|
+
worker.status({phase:'preparing',version:release.version,manual:true});
|
|
168
|
+
const candidate=await prepare(release,{environment,env,fetchImpl,signal:manualController.signal});
|
|
169
|
+
try {await installCandidate(candidate,baseline,{signal:manualController.signal},true);worker.status({phase:'updated',version,manual:true});}
|
|
170
|
+
catch(error){candidate.cleanup();throw error;}
|
|
171
|
+
})().catch(error=>{worker.status({phase:error.message==='service_busy'?'deferred':'failed',manual:true});worker.notice('manual_update_failed');}).finally(()=>{manualFlight=null;manualController=null;});
|
|
172
|
+
await manualFlight;
|
|
173
|
+
}
|
|
174
|
+
requestManualUpdate=manualUpdate;
|
|
175
|
+
scheduler=createNightlyScheduler({enabled:()=>!stopping&&!manualFlight&&retired.size===0&&state!==null&&nightlyUpdatePreference({env}),now,currentVersion:()=>version,state:state||undefined,
|
|
146
176
|
persist:value=>atomicWriteFileIfChangedSync(stateFile,JSON.stringify(value)+'\n',{mode:0o600}),
|
|
147
177
|
inspect:()=>worker.call('inspect'),status:value=>worker.status(value),
|
|
148
178
|
onFailure:code=>worker.notice(code),
|
|
149
|
-
lookup:
|
|
179
|
+
lookup:readRelease,
|
|
150
180
|
prepare:(release,options)=>prepare(release,{environment,env,...options,fetchImpl}),
|
|
151
|
-
apply:
|
|
152
|
-
try{
|
|
153
|
-
const globalVersion=JSON.parse(fs.readFileSync(path.join(environment.target,'package.json'))).version;
|
|
154
|
-
if(globalVersion!==version){candidate.cleanup();throw new Error('installation_changed');}
|
|
155
|
-
const result=await switchServiceVersion({worker,current,candidate,baseline,launch:start,stopped:()=>stopping,
|
|
156
|
-
cancelled:()=>stopping||!nightlyUpdatePreference({env})||!nightlyWindow(now()),onPhase:phase=>worker.status({phase,version:candidate.version}),signal:options.signal});
|
|
157
|
-
worker=result.worker;current=result.current;version=result.version;
|
|
158
|
-
if(result.retired)retired.add(result.retired);
|
|
159
|
-
}catch(error){if(error.restoredWorker)worker=error.restoredWorker;throw error;}
|
|
160
|
-
},
|
|
181
|
+
apply:installCandidate,
|
|
161
182
|
});
|
|
162
183
|
timer=timers.setInterval(()=>scheduler.tick(),60000);timer.unref?.();
|
|
163
184
|
// An unexpected worker exit is reported once. A deliberate Ctrl+C never restarts it.
|
|
164
|
-
while(!stopping){const observed=worker;await observed.exited;if(scheduler.busy)
|
|
185
|
+
while(!stopping){const observed=worker;await observed.exited;if(manualFlight)await manualFlight;if(scheduler.busy)await scheduler.wait();if(worker!==observed)continue;break;}
|
|
165
186
|
const deliberate=stopping;stop();await scheduler.close();await worker.stop();return deliberate?0:1;
|
|
166
187
|
}catch(error){if(!worker&&!stopping)throw error;if(!stopping)log('[WARN] Nightly supervisor could not continue; run ccdx again.');const deliberate=stopping;stop();return deliberate?0:1;}
|
|
167
|
-
finally{timers.clearInterval(timer);processObj.off('SIGINT',stop);processObj.off('SIGTERM',stop);if(stopping)await worker?.stop();for(const item of retired){try{await item.worker.stop();item.current.cleanup();}catch{}}current.cleanup();}
|
|
188
|
+
finally{timers.clearInterval(timer);processObj.off('SIGINT',stop);processObj.off('SIGTERM',stop);if(stopping)await worker?.stop();if(manualFlight)await manualFlight;for(const item of retired){try{await item.worker.stop();item.current.cleanup();}catch{}}current.cleanup();}
|
|
168
189
|
}
|
package/src/service-worker.mjs
CHANGED
|
@@ -8,13 +8,15 @@ import { userSettingsPath } from './user-settings.mjs';
|
|
|
8
8
|
import { readBoundedFileSync } from './bounded-file.mjs';
|
|
9
9
|
import { authProfilePaths, readAuthProfileCredentials } from './auth-profile.mjs';
|
|
10
10
|
import { m365Paths } from './m365-settings.mjs';
|
|
11
|
+
import { imageProviderConfigPath } from './image-provider-config.mjs';
|
|
12
|
+
import { readPredictionSettings } from './native-prediction-profile.mjs';
|
|
11
13
|
|
|
12
14
|
export const HANDOFF_MAX_BYTES = 64 * 1024 * 1024;
|
|
13
15
|
export function clientStateFingerprint(options = {}) {
|
|
14
16
|
const codex = codexPaths(options), connections = accessSettingsPath(options);
|
|
15
17
|
const github = authProfilePaths('codex', options);
|
|
16
18
|
const files = [codex.config, path.join(codex.directory, 'auth.json'), connections, userSettingsPath(options),
|
|
17
|
-
github.tokenPath, m365Paths(options).settings, m365Paths(options).gateway,
|
|
19
|
+
github.tokenPath, imageProviderConfigPath(options), m365Paths(options).settings, m365Paths(options).gateway,
|
|
18
20
|
path.join(path.dirname(connections), 'client-gateway-keys.json'), path.join(path.dirname(connections), 'codex-gateway-owner.json'), ...Object.values(claudeClientPaths(options))];
|
|
19
21
|
const hash = createHash('sha256');
|
|
20
22
|
const credentials = readAuthProfileCredentials('codex', options);
|
|
@@ -23,6 +25,11 @@ export function clientStateFingerprint(options = {}) {
|
|
|
23
25
|
hash.update(file);try { hash.update(readBoundedFileSync(file, { maxBytes: 8 * 1024 * 1024 })); }
|
|
24
26
|
catch (error) { if (error.code !== 'ENOENT') throw error;hash.update('missing'); }
|
|
25
27
|
}
|
|
28
|
+
const prediction = readPredictionSettings(options);
|
|
29
|
+
// Port allocation and App stat bookkeeping can change when the new listener
|
|
30
|
+
// starts. User intent and trust ownership must stay stable across handoff.
|
|
31
|
+
hash.update(JSON.stringify([prediction.enabled, prediction.store ?? null, prediction.certificateHash ?? null,
|
|
32
|
+
prediction.credentialsDirectory ?? null, prediction.app?.app ?? null, prediction.app?.profile ?? null]));
|
|
26
33
|
return hash.digest('hex');
|
|
27
34
|
}
|
|
28
35
|
export function serviceBusinessState(runtime) {
|
|
@@ -81,6 +88,11 @@ export async function createServiceWorker({ processObj = process } = {}) {
|
|
|
81
88
|
takeState() { const state = boot.state;boot.state = undefined;return state; },
|
|
82
89
|
status: () => updateStatus,
|
|
83
90
|
preferenceChanged(enabled) { if (processObj.connected !== false) processObj.send({ type: 'ccdx:preference', enabled }, () => {}); },
|
|
91
|
+
requestUpdate() {
|
|
92
|
+
if (warming || draining || processObj.connected === false) throw new Error('Service update is unavailable during a version switch');
|
|
93
|
+
processObj.send({ type: 'ccdx:manual-update' });
|
|
94
|
+
return { status: 'queued' };
|
|
95
|
+
},
|
|
84
96
|
reused() { processObj.send({ type: 'ccdx:ready', protocol: 1, value: { reused: true } }); },
|
|
85
97
|
async ready(value) { handlers = value;if (stopRequested) { await handlers.stop();return; }processObj.send({ type: 'ccdx:ready', protocol: 1, value: handlers.inspect() }); },
|
|
86
98
|
};
|
|
@@ -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", "privacy_count", "privacy_ms"]) {
|
|
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;
|