codex-copilot-dx 1.2.28 → 1.2.30
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 +5 -5
- package/bin/cli.mjs +1 -0
- package/docs/ARCHITECTURE.md +47 -5
- package/docs/REFERENCE.md +69 -7
- package/package.json +2 -1
- package/src/adapter.mjs +1 -1
- package/src/claude-gateway.mjs +2 -1
- package/src/cli-options.mjs +1 -1
- package/src/cli-web.mjs +1 -0
- package/src/connection-runtime.mjs +40 -6
- package/src/dashboard/connections.js +25 -1
- package/src/dashboard/index.html +5 -2
- package/src/dashboard/language.js +22 -0
- package/src/dashboard/tools.js +48 -4
- package/src/dashboard/ui.css +8 -0
- package/src/dashboard/ui.js +18 -2
- package/src/dashboard-api.mjs +2 -1
- package/src/messages-history-transfer.mjs +74 -23
- package/src/nightly-update.mjs +11 -4
- package/src/package-update.mjs +45 -14
- package/src/profile-model-runtime.mjs +9 -3
- package/src/provider-runtime.mjs +19 -10
- package/src/providers/m365-catalog-diagnostic.mjs +12 -0
- package/src/providers/m365.mjs +22 -6
- package/src/release-install.mjs +37 -10
- package/src/response-failures.mjs +7 -0
package/src/provider-runtime.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { providerDescriptors } from "./provider-descriptors.mjs";
|
|
|
3
3
|
import { autoReviewPreference, writeAutoReviewModel } from "./user-settings.mjs";
|
|
4
4
|
import { autoReviewReasoningEfforts, DEFAULT_CODEX_AUTO_REVIEW_MODEL, responsesModelIdsFromCopilotModels } from "./models.mjs";
|
|
5
5
|
import { publicModelCatalog } from "./provider-metadata.mjs";
|
|
6
|
+
import { selectableCopilotModels } from "./live-models.mjs";
|
|
6
7
|
import { createGithubProvider } from "./providers/github.mjs";
|
|
7
8
|
import { readProviderSettings, writeProviderSettings } from "./provider-settings.mjs";
|
|
8
9
|
import { readM365Settings, updateM365Settings, m365Paths, ensureM365GatewayKey, readM365Account, m365AccountKey } from "./m365-settings.mjs";
|
|
@@ -15,6 +16,7 @@ import { createConnectionRuntime } from "./connection-runtime.mjs";
|
|
|
15
16
|
import { accessSettingsPath, readAccessSettings } from "./access-settings.mjs";
|
|
16
17
|
import { createStreamPerformanceMetrics } from "./stream-performance.mjs";
|
|
17
18
|
import { M365_API_HOST } from "./providers/m365-endpoint.mjs";
|
|
19
|
+
import { m365CatalogDiagnostic, m365CatalogMessage } from "./providers/m365-catalog-diagnostic.mjs";
|
|
18
20
|
|
|
19
21
|
const unavailable = reason => Object.assign(new Error(`Microsoft 365 is unavailable (${reason}); GitHub routing was not substituted`),
|
|
20
22
|
{ code: reason, statusCode: 503 });
|
|
@@ -24,16 +26,12 @@ const unavailable = reason => Object.assign(new Error(`Microsoft 365 is unavaila
|
|
|
24
26
|
export function createProviderRuntime(options = {}) {
|
|
25
27
|
options = { ...options, corePort: options.corePort ?? Number((options.env || process.env).ADAPTER_PORT || 2026) };
|
|
26
28
|
let connections;
|
|
27
|
-
const legacy = createBuiltinProviderRuntime({ ...options, managedClaude: () =>
|
|
28
|
-
|
|
29
|
-
const graph = readAccessSettings(options);
|
|
30
|
-
return graph.claude_private_keys || !["claude_app", "claude_code"].every(id => graph.clients[id].enabled && graph.clients[id].source === "m365" && graph.clients[id].allowed.includes("m365"));
|
|
31
|
-
},
|
|
32
|
-
onClaudeReady: () => connections?.syncClients() });
|
|
29
|
+
const legacy = createBuiltinProviderRuntime({ ...options, managedClaude: () => connections?.managesClaude() !== false,
|
|
30
|
+
onClaudeReady: () => connections?.syncSourceClients("m365") });
|
|
33
31
|
connections = createConnectionRuntime({ ...options, legacy });return connections;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
function createBuiltinProviderRuntime({ githubClient, githubRegistry, githubCredentialFingerprint = "", githubClientConfigured = true, home, env = process.env, platform = process.platform,
|
|
34
|
+
function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGithubCatalog, githubCredentialFingerprint = "", githubClientConfigured = true, home, env = process.env, platform = process.platform,
|
|
37
35
|
corePort = Number(env.ADAPTER_PORT || 2026), log = () => {}, createM365, startGateway, configureClients, restoreClients,
|
|
38
36
|
discoverM365 = requestM365Accounts, managedClaude, onClaudeReady, preserveClientConfiguration } = {}) {
|
|
39
37
|
const options = { home, env, platform }, github = { ...createGithubProvider({ client: githubClient,
|
|
@@ -230,7 +228,11 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
230
228
|
if (changingAccount) { res.writeHead(409, { "Content-Type": "application/json", "Cache-Control": "no-store" });res.end(JSON.stringify({ error: { code: "m365_account_busy", message: m365AccountMessage("m365_account_busy") } }));return; }
|
|
231
229
|
if (!enabled || !gateway?.handle) {
|
|
232
230
|
res.writeHead(503, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
233
|
-
|
|
231
|
+
const diagnostic = enabled ? m365CatalogDiagnostic(m365?.snapshot().catalog_diagnostic) : null;
|
|
232
|
+
const code = claudeReason || reason || "m365_claude_unavailable";
|
|
233
|
+
res.end(JSON.stringify({ type: "error", error: { type: "api_error", code,
|
|
234
|
+
message: m365CatalogMessage(diagnostic) || (code === "m365_no_claude_models" ? "The model directory did not include Claude models. Check the directory read details."
|
|
235
|
+
: "Claude is unavailable; check the model service settings."), ...(diagnostic ? { diagnostic } : {}) } }));return;
|
|
234
236
|
}
|
|
235
237
|
return gateway.handle(req, res);
|
|
236
238
|
},
|
|
@@ -242,7 +244,14 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
242
244
|
definitions: providerRegistry.list() });
|
|
243
245
|
},
|
|
244
246
|
async dashboardCatalog({ provider = selection.codex } = {}) {
|
|
245
|
-
if (provider === "github")
|
|
247
|
+
if (provider === "github") {
|
|
248
|
+
if (!refreshGithubCatalog) return null;
|
|
249
|
+
const catalog = await refreshGithubCatalog();
|
|
250
|
+
const selected = new Set(selectableCopilotModels(catalog).models.map(model => model.id));
|
|
251
|
+
const upstreamHost = githubClient.runtimeStatus?.().upstream_host;
|
|
252
|
+
return { source: "live", checkedAt: new Date().toISOString(), upstreamHost: upstreamHost && upstreamHost !== "unknown" ? upstreamHost : "GitHub Copilot", advertised: catalog.data.length,
|
|
253
|
+
models: publicModelCatalog(catalog.data, { selectable: model => selected.has(model.id), clients: model => selected.has(model.id) ? ["codex"] : [] }) };
|
|
254
|
+
}
|
|
246
255
|
if (provider !== "m365") throw Object.assign(new Error("Unknown provider"), { statusCode: 400 });
|
|
247
256
|
if (!enabled || !["darwin", "win32"].includes(platform)) throw unavailable(!enabled ? "m365_disabled" : "m365_unsupported");
|
|
248
257
|
if (!m365) throw unavailable(reason || "m365_not_ready");
|
|
@@ -251,7 +260,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
251
260
|
if (closed || !enabled || source !== m365 || changingAccount) throw unavailable("m365_refresh_cancelled");
|
|
252
261
|
reason = null;
|
|
253
262
|
const eligible = new Set([...source.models("gpt"), ...source.models("claude")]);
|
|
254
|
-
return { source: "catalog", checkedAt: m365.snapshot().models.refreshed_at, upstreamHost: M365_API_HOST,
|
|
263
|
+
return { source: "catalog", checkedAt: m365.snapshot().models.refreshed_at, upstreamHost: M365_API_HOST, catalogRead: source.snapshot().catalog_read,
|
|
255
264
|
advertised: m365.catalog().length, models: publicModelCatalog(m365.catalog(), {
|
|
256
265
|
selectable: model => eligible.has(model),
|
|
257
266
|
clients: model => !eligible.has(model) ? [] : model.publisher?.toLowerCase() === "anthropic" ? ["claude_code", "claude_app"] : ["codex"],
|
|
@@ -36,3 +36,15 @@ export function catalogFailure(response, body, { checkedAt, lastSuccessAt } = {}
|
|
|
36
36
|
return m365CatalogDiagnostic({ stage: "catalog", cause_code, http_status: code, checked_at: checkedAt,
|
|
37
37
|
last_success_at: lastSuccessAt, request_id: response.headers.get("request-id") || response.headers.get("x-ms-request-id") });
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
export function m365CatalogRead(value) {
|
|
41
|
+
if (!value || !["network", "cache"].includes(value.source) || !date(value.checked_at)
|
|
42
|
+
|| !["total", "claude", "gpt", "filtered"].every(key => Number.isInteger(value[key]) && value[key] >= 0 && value[key] <= 1000)
|
|
43
|
+
|| value.claude + value.gpt + value.filtered !== value.total) return null;
|
|
44
|
+
const identifier = id => typeof id === "string" && /^[a-zA-Z0-9_-]{1,80}$/.test(id) && !/^(?:github_pat_|gh[pousr]_|sk-|eyJ)/.test(id) ? id : null;
|
|
45
|
+
return { source: value.source, checked_at: value.checked_at, total: value.total, claude: value.claude, gpt: value.gpt, filtered: value.filtered,
|
|
46
|
+
request_id: identifier(value.request_id), client_correlation_id: identifier(value.client_correlation_id),
|
|
47
|
+
http_status: value.source === "network" && value.http_status === 200 ? 200 : null,
|
|
48
|
+
local_cache_used: value.source === "cache", http_revalidation_requested: value.source === "network" && value.http_revalidation_requested === true,
|
|
49
|
+
response_age_seconds: Number.isSafeInteger(value.response_age_seconds) && value.response_age_seconds >= 0 && value.response_age_seconds <= 604800 ? value.response_age_seconds : null };
|
|
50
|
+
}
|
package/src/providers/m365.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { resolveClaudeModel } from "../claude-models.mjs";
|
|
|
16
16
|
import { modelReasoningEfforts } from "../provider-metadata.mjs";
|
|
17
17
|
import { limitM365CacheTtl } from "./m365-messages-policy.mjs";
|
|
18
18
|
import { createM365ConversationGuard } from "./m365-conversation-accounts.mjs";
|
|
19
|
-
import { catalogFailure, m365CatalogDiagnostic } from "./m365-catalog-diagnostic.mjs";
|
|
19
|
+
import { catalogFailure, m365CatalogDiagnostic, m365CatalogRead } from "./m365-catalog-diagnostic.mjs";
|
|
20
20
|
import { m365NetworkDiagnostic } from "./m365-network-diagnostic.mjs";
|
|
21
21
|
|
|
22
22
|
import { M365_API_BASE, M365_API_ORIGIN } from "./m365-endpoint.mjs";
|
|
@@ -77,7 +77,7 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
77
77
|
const guardConversation = createM365ConversationGuard({ home });
|
|
78
78
|
let catalog = null, account = null, catalogAt = 0, state = "idle", reason = null, flight = null, controller = null, generation = 0;
|
|
79
79
|
let network = null, networkFlight = null, cacheTtlAdjustments = 0;
|
|
80
|
-
let networkDiagnostic = null, catalogDiagnostic = null;
|
|
80
|
+
let networkDiagnostic = null, catalogDiagnostic = null, catalogRead = null, lastCatalogResponse = null;
|
|
81
81
|
const registry = { models: null, source: "unavailable", cacheState: "none", cacheSavedAtMs: null,
|
|
82
82
|
refreshInFlight: false, generation: 0, lastError: null, lastErrorAtMs: null };
|
|
83
83
|
const profile = () => account ? `m365:${M365_API_ORIGIN}:${m365AccountKey(account)}` : "m365:unavailable";
|
|
@@ -95,17 +95,23 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
95
95
|
}
|
|
96
96
|
return networkFlight;
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function readObservation(value, source, savedAt, evidence = {}) {
|
|
99
|
+
const claude = m365Models(value, "claude").length, gpt = m365Models(value, "gpt").length;
|
|
100
|
+
return m365CatalogRead({ ...evidence, source: source === "live" ? "network" : "cache", checked_at: new Date(savedAt).toISOString(),
|
|
101
|
+
total: value.data.length, claude, gpt, filtered: value.data.length - claude - gpt });
|
|
102
|
+
}
|
|
103
|
+
function applyCatalog(value, source, savedAt, evidence) {
|
|
99
104
|
catalog = m365Catalog(value);catalogAt = savedAt;
|
|
100
105
|
registry.models = { data: m365Models(catalog, "gpt").map(model => ({ ...model,
|
|
101
106
|
vendor: "OpenAI", model_picker_enabled: true, policy: { state: "enabled" } })) };
|
|
102
107
|
registry.source = source;registry.cacheSavedAtMs = savedAt;registry.cacheState = now() - savedAt < SOFT_TTL_MS ? "fresh" : "stale";
|
|
108
|
+
catalogRead = readObservation(catalog, source, savedAt, source === "live" ? lastCatalogResponse : evidence);
|
|
103
109
|
}
|
|
104
110
|
try {
|
|
105
111
|
account = accountOverride || readM365Account({ home });
|
|
106
112
|
const saved = readM365Json(paths.catalog);
|
|
107
113
|
if (account && saved?.service_origin === M365_API_ORIGIN && saved.account_key === m365AccountKey(account) && Number.isFinite(saved.saved_at)
|
|
108
|
-
&& now() - saved.saved_at < HARD_TTL_MS) applyCatalog(saved.models, "cache", saved.saved_at);
|
|
114
|
+
&& now() - saved.saved_at < HARD_TTL_MS) applyCatalog(saved.models, "cache", saved.saved_at, m365CatalogRead(saved.catalog_read));
|
|
109
115
|
} catch { reason = "m365_cache_unavailable"; }
|
|
110
116
|
|
|
111
117
|
async function request(endpoint, body, options = {}) {
|
|
@@ -116,6 +122,7 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
116
122
|
const requestHeaders = m365Headers(credential.token, { ...options,
|
|
117
123
|
conversationId: body ? m365ConversationId(body, options.headers, m365AccountKey(credential.account)) : undefined,
|
|
118
124
|
stream: body?.stream === true });
|
|
125
|
+
if (endpoint === "/models") { requestHeaders["Cache-Control"] = "no-cache";requestHeaders.Pragma = "no-cache"; }
|
|
119
126
|
const serialized = body ? options.bodyText ?? JSON.stringify(body) : undefined;
|
|
120
127
|
if (serialized !== undefined) requestHeaders["Content-Length"] = String(Buffer.byteLength(serialized));
|
|
121
128
|
options.onUpstreamStart?.();
|
|
@@ -124,6 +131,12 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
124
131
|
const send = fetchImpl || await transport(options.signal);
|
|
125
132
|
const response = await send(`${M365_API_BASE}${endpoint}`, { method: body ? "POST" : "GET", headers: requestHeaders,
|
|
126
133
|
...(serialized !== undefined ? { body: serialized } : {}), signal: options.signal, redirect: "manual" });
|
|
134
|
+
if (endpoint === "/models") {
|
|
135
|
+
const age = response.headers.get("age");
|
|
136
|
+
lastCatalogResponse = { http_status: response.status, request_id: response.headers.get("request-id") || response.headers.get("x-ms-request-id") || response.headers.get("x-request-id"),
|
|
137
|
+
client_correlation_id: requestHeaders["X-ClientCorrelationId"], http_revalidation_requested: true,
|
|
138
|
+
response_age_seconds: age !== null && /^\d+$/.test(age) ? Number(age) : null };
|
|
139
|
+
}
|
|
127
140
|
if (response.ok) return response;
|
|
128
141
|
const raw = await readBoundedResponseText(response, { maxBytes: MAX_UPSTREAM_ERROR_BODY_BYTES, label: "M365 error", signal: options.signal });
|
|
129
142
|
const safe = raw.split(credential.token).join("[redacted]");
|
|
@@ -155,7 +168,8 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
155
168
|
if (current !== generation || signal.aborted) throw m365Error("m365_refresh_cancelled");
|
|
156
169
|
const savedAt = now();
|
|
157
170
|
const nextAccount = { ...credential.account, ...(account?.history_isolation ? { history_isolation: true } : {}) };
|
|
158
|
-
if (persist) writeM365Binding(nextAccount, { account_key: m365AccountKey(nextAccount), service_origin: M365_API_ORIGIN, saved_at: savedAt, models: value
|
|
171
|
+
if (persist) writeM365Binding(nextAccount, { account_key: m365AccountKey(nextAccount), service_origin: M365_API_ORIGIN, saved_at: savedAt, models: value,
|
|
172
|
+
catalog_read: readObservation(value, "live", savedAt, lastCatalogResponse) }, { home, expectedAccount: account });
|
|
159
173
|
account = nextAccount;
|
|
160
174
|
applyCatalog(value, "live", savedAt);catalogDiagnostic = null;state = "ready";reason = null;registry.lastError = null;registry.lastErrorAtMs = null;
|
|
161
175
|
try { await onCatalog(value); } catch { log("warn", "M365 models are ready; optional client configuration could not be updated"); }
|
|
@@ -253,7 +267,8 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
253
267
|
},
|
|
254
268
|
commitSelection(expectedAccount) {
|
|
255
269
|
if (!catalog || state !== "ready" || !account) throw m365Error("m365_not_ready");
|
|
256
|
-
writeM365Binding(account, { account_key: m365AccountKey(account), service_origin: M365_API_ORIGIN, saved_at: catalogAt, models: catalog
|
|
270
|
+
writeM365Binding(account, { account_key: m365AccountKey(account), service_origin: M365_API_ORIGIN, saved_at: catalogAt, models: catalog,
|
|
271
|
+
catalog_read: m365CatalogRead(catalogRead) }, { home, expectedAccount });
|
|
257
272
|
persist = true;
|
|
258
273
|
},
|
|
259
274
|
snapshot: () => ({ ...auth.snapshot(), state, reason: reason || auth.snapshot().reason, account: account ? { login: account.login, tenant: account.tenant, selection_source: account.selection_source || "legacy" } : null,
|
|
@@ -261,6 +276,7 @@ export function createM365Provider({ home, env = process.env, account: accountOv
|
|
|
261
276
|
network: network?.snapshot() || null,
|
|
262
277
|
network_diagnostic: networkDiagnostic ? { ...networkDiagnostic } : null,
|
|
263
278
|
catalog_diagnostic: m365CatalogDiagnostic(catalogDiagnostic),
|
|
279
|
+
catalog_read: m365CatalogRead(catalogRead),
|
|
264
280
|
cache_ttl_adjustments: cacheTtlAdjustments,
|
|
265
281
|
models: { total: catalog?.data.length || 0, claude: m365Models(catalog, "claude").length, gpt: m365Models(catalog, "gpt").length,
|
|
266
282
|
source: registry.source, refreshed_at: catalogAt ? new Date(catalogAt).toISOString() : null }, refresh_in_flight: Boolean(flight) }),
|
package/src/release-install.mjs
CHANGED
|
@@ -66,8 +66,8 @@ export function releaseChecksum(manifest, name) {
|
|
|
66
66
|
if (lines.length !== 1 || !/^[a-f0-9]{64} [\w.-]+$/.test(lines[0])) throw new Error("Release checksum is missing or invalid");
|
|
67
67
|
return lines[0].slice(0, 64);
|
|
68
68
|
}
|
|
69
|
-
export function packageMetadata(bytes) {
|
|
70
|
-
const tar = gunzipSync(bytes, { maxOutputLength: 64 * 1024 * 1024 });
|
|
69
|
+
export function packageMetadata(bytes, { complete = false } = {}) {
|
|
70
|
+
const tar = gunzipSync(bytes, { maxOutputLength: (complete ? 256 : 64) * 1024 * 1024 });
|
|
71
71
|
let metadata;
|
|
72
72
|
for (let offset = 0; offset + 512 <= tar.length;) {
|
|
73
73
|
const header = tar.subarray(offset, offset + 512), name = header.subarray(0, 100).toString().replace(/\0.*$/s, "");
|
|
@@ -85,15 +85,41 @@ export function packageMetadata(bytes) {
|
|
|
85
85
|
if (metadata?.name !== "codex-copilot-dx" || !stableVersion(metadata.version)) throw new Error("Release package identity is invalid");
|
|
86
86
|
return metadata;
|
|
87
87
|
}
|
|
88
|
-
export
|
|
88
|
+
export function runtimeReleaseTarget({ platform = process.platform, arch = process.arch, libc } = {}) {
|
|
89
|
+
if (!["darwin", "win32", "linux"].includes(platform) || !["x64", "arm64"].includes(arch)) throw new Error("No complete Release package is available for this platform");
|
|
90
|
+
if (platform !== "linux") return `${platform}-${arch}`;
|
|
91
|
+
libc ||= process.report?.getReport().header.glibcVersionRuntime ? "glibc" : "musl";
|
|
92
|
+
if (!["glibc", "musl"].includes(libc)) throw new Error("Unsupported Linux runtime");
|
|
93
|
+
return `${platform}-${arch}-${libc}`;
|
|
94
|
+
}
|
|
95
|
+
export function remoteDownloadDenied(error) {
|
|
96
|
+
return error?.npmCode === "EALLOWREMOTE" || /(?:^|\n)npm (?:error|ERR!) code EALLOWREMOTE(?:\r?\n|$)/.test(String(error?.stderr || ""));
|
|
97
|
+
}
|
|
98
|
+
export async function downloadRelease(tag, { fetchImpl = fetch, directory, signal, complete = false, preferComplete = false, platform, arch, libc } = {}) {
|
|
89
99
|
const version = stableVersion(tag);if (!version) throw new Error("A valid stable GitHub release tag is required");
|
|
90
|
-
const
|
|
100
|
+
const base = `${RELEASE_BASE}/v${version}`;
|
|
91
101
|
const manifest = await releaseBytes(`${base}/SHA256SUMS`, { fetchImpl, maxBytes: 65536, signal });
|
|
102
|
+
let name = `codex-copilot-dx-${version}.tgz`, target;
|
|
103
|
+
if (complete || preferComplete) {
|
|
104
|
+
if (complete) target = runtimeReleaseTarget({ platform, arch, libc });
|
|
105
|
+
else {
|
|
106
|
+
try { target = runtimeReleaseTarget({ platform, arch, libc }); } catch { /* Other platforms retain the source-only bootstrap path. */ }
|
|
107
|
+
}
|
|
108
|
+
if (target) {
|
|
109
|
+
const runtimeName = `codex-copilot-dx-${version}-${target}.tgz`;
|
|
110
|
+
if (complete || manifest.toString("utf8").split(/\r?\n/).some(line => line.endsWith(` ${runtimeName}`))) { name = runtimeName;complete = true; }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
92
113
|
const expected = releaseChecksum(manifest, name);
|
|
93
|
-
const bytes = await releaseBytes(`${base}/${name}`, { fetchImpl, maxBytes: 16 * 1024 * 1024, signal });
|
|
114
|
+
const bytes = await releaseBytes(`${base}/${name}`, { fetchImpl, maxBytes: (complete ? 64 : 16) * 1024 * 1024, signal });
|
|
94
115
|
if (createHash("sha256").update(bytes).digest("hex") !== expected) throw new Error("Release checksum mismatch; no installation was started");
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
const metadata = packageMetadata(bytes, { complete });
|
|
117
|
+
if (metadata.version !== version) throw new Error("Release package version does not match its tag");
|
|
118
|
+
if (complete && (metadata.ccdx_runtime?.schema !== 1 || metadata.ccdx_runtime.target !== target
|
|
119
|
+
|| !Array.isArray(metadata.bundleDependencies) || !["sharp", "smol-toml", "@azure/msal-node-runtime"].every(name => metadata.bundleDependencies.includes(name)))) {
|
|
120
|
+
throw new Error("Complete Release package does not match this runtime or lacks bundled dependencies");
|
|
121
|
+
}
|
|
122
|
+
const file = path.join(directory, name);fs.writeFileSync(file, bytes, { flag: "wx", mode: 0o600 });return { file, name, version, complete };
|
|
97
123
|
}
|
|
98
124
|
|
|
99
125
|
// Preserve only this package and its command entries. Never snapshot credentials
|
|
@@ -190,11 +216,12 @@ async function bootstrap() {
|
|
|
190
216
|
const target = path.join(prefix, ...(process.platform === "win32" ? [] : ["lib"]), "node_modules", "codex-copilot-dx");
|
|
191
217
|
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "ccdx-install-"));let transaction;
|
|
192
218
|
try {
|
|
193
|
-
const release = await downloadRelease(tag, { directory, fetchImpl: createNpmReleaseFetch(npmCli) });
|
|
219
|
+
const release = await downloadRelease(tag, { directory, fetchImpl: createNpmReleaseFetch(npmCli), preferComplete: true });
|
|
194
220
|
transaction = protectInstallation({ target, prefix });
|
|
195
221
|
const npmVersion = execFileSync(process.execPath, [npmCli, "--version"], { encoding: "utf8", timeout: 10000 }).trim();
|
|
196
222
|
const args = [npmCli, "install", "--global", "--prefix", prefix, "--ignore-scripts", "--no-audit", "--no-fund"];
|
|
197
|
-
if (
|
|
223
|
+
if (release.complete) args.push("--offline");
|
|
224
|
+
else if (permission && Number(npmVersion.split(".")[0]) >= 12) args.push("--allow-remote=all");
|
|
198
225
|
args.push(release.file);
|
|
199
226
|
execFileSync(process.execPath, args, { stdio: "inherit", timeout: 300000 });
|
|
200
227
|
verifyPackageRuntime(target, release.version, { brokerRequired: ["darwin", "win32"].includes(process.platform) });
|
|
@@ -202,7 +229,7 @@ async function bootstrap() {
|
|
|
202
229
|
transaction.commit();transaction = null;
|
|
203
230
|
console.log(`Installed CCDX ${release.version}. Existing services keep running until restarted.`);
|
|
204
231
|
} catch (error) {
|
|
205
|
-
transaction?.rollback();throw new Error("Installation failed. Previous CCDX package and commands were restored. Check
|
|
232
|
+
transaction?.rollback();throw new Error("Installation failed. Previous CCDX package and commands were restored. Check the Release package, platform, proxy, certificates and npm policy. Older source-only releases still need registry access.", { cause: error });
|
|
206
233
|
} finally { fs.rmSync(directory, { recursive: true, force: true }); }
|
|
207
234
|
}
|
|
208
235
|
if (process.argv[1] && path.basename(process.argv[1]) === "ccdx-install.mjs" && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
@@ -176,6 +176,13 @@ export function buildHttpFailureDetails({ statusCode, route, requestId, model, c
|
|
|
176
176
|
ccdx_model_ambiguous: "This model name matches multiple sources. Select its source-specific entry.",
|
|
177
177
|
ccdx_model_catalog_unavailable: "The selected model is not currently available in its source catalog.",
|
|
178
178
|
ccdx_client_source_disabled: "This app or its model source is turned off." };
|
|
179
|
+
for (const prefix of ["source_changed", "prefix_changed"]) {
|
|
180
|
+
reasons[`${prefix}_tool_call_pending`] = "A tool call is still waiting for its result. Finish the current turn before switching.";
|
|
181
|
+
reasons[`${prefix}_tool_result_unmatched`] = "A tool result has no matching call. Restore complete history before switching.";
|
|
182
|
+
reasons[`${prefix}_tool_history_invalid`] = "The tool history is incomplete. Restore complete history before switching.";
|
|
183
|
+
reasons[`${prefix}_active_tool_turn`] = prefix === "prefix_changed" ? "History changed during a tool turn. Finish the current turn before switching."
|
|
184
|
+
: "A tool turn is still active on the previous source. Finish it before switching.";
|
|
185
|
+
}
|
|
179
186
|
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."
|
|
180
187
|
: code === "ccdx_api_network_unavailable" ? "Connection to the model source failed."
|
|
181
188
|
: origin === "client_validation" ? "The request was rejected locally before an upstream call."
|