codex-copilot-dx 1.2.6 → 1.2.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.
- package/README.md +3 -3
- package/bin/cli.mjs +42 -2
- package/docs/ARCHITECTURE.md +6 -0
- package/docs/README.md +4 -0
- package/docs/REFERENCE.md +22 -2
- package/package.json +1 -1
- package/src/account-tools.mjs +121 -0
- package/src/adapter.mjs +2 -0
- package/src/auth-credentials.mjs +18 -8
- package/src/auth-status.mjs +21 -7
- package/src/auth.mjs +1 -0
- package/src/cli-auth.mjs +38 -1
- package/src/cli-options.mjs +46 -13
- package/src/cli-tools.mjs +25 -0
- package/src/cli-web.mjs +37 -0
- package/src/codex-config-doctor.mjs +4 -0
- package/src/copilot-client.mjs +1 -0
- package/src/copilot-token-session.mjs +9 -0
- package/src/dashboard/console.js +1 -1
- package/src/dashboard/icons.js +24 -0
- package/src/dashboard/index.html +57 -15
- package/src/dashboard/language.js +86 -0
- package/src/dashboard/status.js +9 -0
- package/src/dashboard/tools.js +151 -0
- package/src/dashboard/ui.css +23 -0
- package/src/dashboard/ui.js +4 -1
- package/src/dashboard-api.mjs +5 -0
- package/src/dashboard-tools.mjs +43 -0
- package/src/dashboard.mjs +2 -0
- package/src/doctor.mjs +3 -2
- package/src/local-tools.mjs +53 -0
- package/src/native-prediction-environment.mjs +1 -1
- package/src/optional-routes.mjs +9 -3
- package/src/provider-runtime.mjs +2 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const el = id => document.getElementById(id), language = globalThis.ccdxLanguage;
|
|
3
|
+
const label = (node, key, values) => language.set(node, key, values);
|
|
4
|
+
const text = (id, key, values) => label(el(id), key, values);
|
|
5
|
+
let account = null, pending = false, pollTimer = null, stopped = false, repairPreview = null;
|
|
6
|
+
const activeFlow = () => ["starting", "authorizing", "verifying"].includes(account?.operation?.state);
|
|
7
|
+
async function api(path, body) {
|
|
8
|
+
const response = await fetch(`/_ccdx/ui/${path}`, { method: body ? "POST" : "GET", cache: "no-store",
|
|
9
|
+
headers: { "X-CCDX-Dashboard": "1", ...(body ? { "Content-Type": "application/json" } : {}) },
|
|
10
|
+
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(35000) });
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
if (!response.ok) throw Object.assign(new Error("tools_action_failed"), { code: data.code || "tools_action_failed" });
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function status(id, key, kind, values) { globalThis.ccdxIcons.set(el(id), key, kind, values); }
|
|
16
|
+
function field(list, key, value, kind) {
|
|
17
|
+
const term = document.createElement("dt"), detail = document.createElement("dd");label(term, key);
|
|
18
|
+
if (kind) globalThis.ccdxIcons.set(detail, value, kind);else detail.textContent = value;
|
|
19
|
+
list.append(term, detail);
|
|
20
|
+
}
|
|
21
|
+
function syncSource() {
|
|
22
|
+
const github = selectedProvider === "github";
|
|
23
|
+
el("github-account").hidden = !github;
|
|
24
|
+
el("m365-source-access").hidden = selectedProvider !== "m365";
|
|
25
|
+
el("source-account-panel").setAttribute("aria-labelledby", `model-provider-${selectedProvider}`);
|
|
26
|
+
}
|
|
27
|
+
function renderAccount(data) {
|
|
28
|
+
account = data;
|
|
29
|
+
const online = data.online, op = data.operation;
|
|
30
|
+
const invalid = online?.reason === "github_token_invalid", failed = online?.checked && !online.ok;
|
|
31
|
+
text("github-account-name", data.login || (data.saved ? "tools_saved_account" : "tools_not_signed_in"));
|
|
32
|
+
status("github-account-state", invalid ? "tools_signin_invalid" : online?.ok ? "tools_verified" : data.saved ? "saved_locally" : "tools_not_signed_in",
|
|
33
|
+
invalid ? "warning" : online?.ok ? "ok" : data.saved ? "unknown" : "unavailable");
|
|
34
|
+
text("github-account-hint", !data.saved ? "tools_login_hint" : invalid ? "tools_saved_not_valid" : failed ? "tools_access_hint" : "tools_account_hint");
|
|
35
|
+
const fields = el("github-account-fields");fields.replaceChildren();
|
|
36
|
+
field(fields, "tools_saved_signin", data.saved ? "saved_locally" : "tools_not_signed_in", data.saved ? "ok" : "unavailable");
|
|
37
|
+
for (const [id, key] of [["identity", "tools_github_identity"], ["access", "tools_copilot_access"], ["models", "tools_catalog_read"]]) {
|
|
38
|
+
const result = online?.stages?.[id] || "not_checked";
|
|
39
|
+
field(fields, key, result === "passed" ? "tools_verified" : result === "invalid" ? "tools_signin_invalid" : result === "unavailable" ? "tools_unavailable" : "tools_not_checked",
|
|
40
|
+
result === "passed" ? "ok" : result === "invalid" ? "warning" : result === "unavailable" ? "unavailable" : "unknown");
|
|
41
|
+
}
|
|
42
|
+
field(fields, "last_verified", data.checked_at ? new Date(data.checked_at).toLocaleString() : "—");
|
|
43
|
+
label(el("github-signin"), data.saved ? "tools_reauth" : "tools_login");
|
|
44
|
+
el("github-signin").hidden = data.saved && !invalid;
|
|
45
|
+
el("github-signin").disabled = pending || activeFlow();el("github-check").disabled = pending || activeFlow() || !data.saved;
|
|
46
|
+
el("github-logout").disabled = pending || activeFlow() || !data.saved;
|
|
47
|
+
el("github-force-reauth").disabled = pending || activeFlow();
|
|
48
|
+
el("github-login-flow").hidden = !activeFlow();
|
|
49
|
+
text("github-flow-state", op?.state === "verifying" ? "tools_verifying" : "tools_waiting");
|
|
50
|
+
el("github-user-code").textContent = op?.user_code || "—";
|
|
51
|
+
el("github-authorize").hidden = op?.state !== "authorizing";
|
|
52
|
+
el("github-authorize").href = op?.verification_uri === "https://github.com/login/device" ? op.verification_uri : "https://github.com/login/device";
|
|
53
|
+
el("github-cancel").disabled = pending;
|
|
54
|
+
el("github-check-code").textContent = online?.reason || "—";
|
|
55
|
+
el("github-check-http").textContent = online?.http_status || "—";
|
|
56
|
+
text("github-store", data.store === "ccdx" ? "tools_ccdx_store" : "tools_legacy_store");
|
|
57
|
+
if (op?.state === "complete") text("github-account-note", op.reason === "auth_restart_required" ? "auth_restart_required" : "tools_signin_complete");
|
|
58
|
+
else if (["failed", "cancelled"].includes(op?.state)) text("github-account-note", op.reason || "tools_action_failed");
|
|
59
|
+
else if (failed) text("github-account-note", online.reason === "github_token_invalid" ? "tools_reauth_hint" : online.reason === "copilot_access_denied" ? "tools_access_denied" : "tools_network_hint");
|
|
60
|
+
else if (online?.ok) text("github-account-note", "tools_check_complete");
|
|
61
|
+
else if (!activeFlow()) el("github-account-note").textContent = "";
|
|
62
|
+
schedulePoll();
|
|
63
|
+
}
|
|
64
|
+
function schedulePoll() {
|
|
65
|
+
clearTimeout(pollTimer);pollTimer = null;
|
|
66
|
+
if (stopped || !activeFlow() || document.visibilityState !== "visible") return;
|
|
67
|
+
pollTimer = setTimeout(async () => {
|
|
68
|
+
try {
|
|
69
|
+
const before = account.operation.state, data = await api("account");renderAccount(data);
|
|
70
|
+
if (before !== data.operation?.state && data.operation?.state === "complete") {
|
|
71
|
+
dashboardRefresh.invalidate("auth");dashboardRefresh.invalidate("models", { clear: true });
|
|
72
|
+
void dashboardRefresh.refreshVisible({ force: true });
|
|
73
|
+
}
|
|
74
|
+
} catch { text("github-account-note", "tools_read_failed");schedulePoll(); }
|
|
75
|
+
}, 1500);
|
|
76
|
+
}
|
|
77
|
+
async function accountAction(action) {
|
|
78
|
+
if (pending) return;
|
|
79
|
+
pending = true;if (account) renderAccount(account);text("github-account-note", "checking");
|
|
80
|
+
let failureCode = null;
|
|
81
|
+
try { renderAccount(await api("account", action)); }
|
|
82
|
+
catch (error) { failureCode = error.code; }
|
|
83
|
+
finally { pending = false;if (account) renderAccount(account);if (failureCode) text("github-account-note", failureCode); }
|
|
84
|
+
}
|
|
85
|
+
el("github-signin").addEventListener("click", () => void accountAction({ action: "start", reauth: account?.saved === true }));
|
|
86
|
+
el("github-force-reauth").addEventListener("click", () => void accountAction({ action: "start", reauth: true }));
|
|
87
|
+
el("github-check").addEventListener("click", () => void accountAction({ action: "check" }));
|
|
88
|
+
el("github-cancel").addEventListener("click", () => { if (account?.operation) void accountAction({ action: "cancel", id: account.operation.id }); });
|
|
89
|
+
el("github-logout").addEventListener("click", () => { if (window.confirm(language.format("tools_logout_confirm"))) void accountAction({ action: "logout", confirmed: true }); });
|
|
90
|
+
async function loadAccount() { try { renderAccount(await api("account")); } catch { text("github-account-note", "tools_read_failed"); } }
|
|
91
|
+
function renderChecks(data) {
|
|
92
|
+
const body = el("checks-body");body.replaceChildren();
|
|
93
|
+
const groups = new Map();
|
|
94
|
+
for (const check of data.checks || []) { if (!groups.has(check.id)) groups.set(check.id, []);groups.get(check.id).push(check); }
|
|
95
|
+
for (const [id, checks] of groups) {
|
|
96
|
+
const row = document.createElement("tr"), name = document.createElement("td"), result = document.createElement("td"), details = document.createElement("td");
|
|
97
|
+
const kind = checks.some(check => check.kind === "err" || check.kind === "warn") ? "warning" : checks.some(check => check.kind === "ok") ? "ok" : "unknown";
|
|
98
|
+
label(name, ({ "github-auth": "tools_github_signin", "codex-config": "tools_codex_settings", "windows-command": "tools_windows_command", provider: "source" })[id] || "tools_environment");
|
|
99
|
+
globalThis.ccdxIcons.set(result, kind === "warning" ? "tools_needs_attention" : kind === "ok" ? "tools_verified" : "tools_observed", kind);
|
|
100
|
+
const disclosure = document.createElement("details"), summary = document.createElement("summary");label(summary, "tools_details");disclosure.append(summary);
|
|
101
|
+
for (const check of checks) { const p = document.createElement("p");p.className = "hint";p.textContent = check.message;disclosure.append(p); }
|
|
102
|
+
details.append(disclosure);row.append(name, result, details);body.append(row);
|
|
103
|
+
}
|
|
104
|
+
if (!groups.size) text("checks-note", "tools_checks_empty");
|
|
105
|
+
else text("checks-note", "tools_checks_completed", { time: new Date(data.checked_at).toLocaleTimeString() });
|
|
106
|
+
}
|
|
107
|
+
async function localAction(action, button) {
|
|
108
|
+
button.disabled = true;text("checks-note", "checking");
|
|
109
|
+
try {
|
|
110
|
+
const data = await api("checks", action);
|
|
111
|
+
if (action.action === "check") renderChecks(data);
|
|
112
|
+
else if (action.action === "preview") {
|
|
113
|
+
repairPreview = data;el("config-repair-preview").hidden = false;
|
|
114
|
+
const fields = el("config-repair-fields");fields.replaceChildren();
|
|
115
|
+
field(fields, "tools_managed_fields", data.managed_keys.join(", "));
|
|
116
|
+
field(fields, "tools_backup", data.backup);
|
|
117
|
+
el("config-preview-details").textContent = data.checks.map(check => check.message).join("\n");
|
|
118
|
+
text("checks-note", "tools_review_repair");
|
|
119
|
+
} else if (action.action === "repair") {
|
|
120
|
+
el("config-repair-preview").hidden = true;repairPreview = null;
|
|
121
|
+
if (data.local?.checked_at) renderChecks(data.local);
|
|
122
|
+
text("checks-note", ["verified", "unchanged"].includes(data.status) ? "tools_repair_complete" : "tools_repair_preserved");
|
|
123
|
+
} else if (action.action === "network") { el("network-check-result").textContent = data.summary;text("checks-note", "tools_network_read_only"); }
|
|
124
|
+
else if (action.action === "report") {
|
|
125
|
+
const url = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], { type: "application/json" }));
|
|
126
|
+
const link = document.createElement("a");link.href = url;link.download = "ccdx-diagnostic-report.json";link.click();
|
|
127
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);text("checks-note", "tools_report_saved");
|
|
128
|
+
}
|
|
129
|
+
} catch (error) { text("checks-note", error.code); }
|
|
130
|
+
finally { button.disabled = false; }
|
|
131
|
+
}
|
|
132
|
+
for (const [id, action] of [["check-local", "check"], ["check-network", "network"], ["export-report", "report"], ["preview-config-repair", "preview"]]) {
|
|
133
|
+
el(id).addEventListener("click", () => void localAction({ action }, el(id)));
|
|
134
|
+
}
|
|
135
|
+
el("apply-config-repair").addEventListener("click", () => { if (repairPreview) void localAction({ action: "repair", revision: repairPreview.revision }, el("apply-config-repair")); });
|
|
136
|
+
el("cancel-config-repair").addEventListener("click", () => { repairPreview = null;el("config-repair-preview").hidden = true; });
|
|
137
|
+
el("check-account-link").addEventListener("click", () => { chooseProvider("github");location.hash = "models"; });
|
|
138
|
+
async function navigate() {
|
|
139
|
+
syncSource();
|
|
140
|
+
if (location.hash === "#models") await loadAccount();
|
|
141
|
+
if (location.hash === "#checks") { try { const data = await api("checks");if (data.checked_at) renderChecks(data); } catch { text("checks-note", "tools_read_failed"); } }
|
|
142
|
+
}
|
|
143
|
+
window.addEventListener("ccdx:source-view", syncSource);
|
|
144
|
+
window.addEventListener("ccdx:providers", () => { queueMicrotask(() => { syncSource();if (location.hash === "#models" && !pending) void loadAccount(); }); });
|
|
145
|
+
el("refresh").addEventListener("click", () => { if (location.hash === "#models" && !pending) void loadAccount(); });
|
|
146
|
+
window.addEventListener("hashchange", () => void navigate());
|
|
147
|
+
window.addEventListener("pagehide", () => { stopped = true;clearTimeout(pollTimer); });
|
|
148
|
+
window.addEventListener("pageshow", () => { stopped = false;schedulePoll(); });
|
|
149
|
+
document.addEventListener("visibilitychange", schedulePoll);
|
|
150
|
+
void navigate();
|
|
151
|
+
})();
|
package/src/dashboard/ui.css
CHANGED
|
@@ -285,3 +285,26 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
285
285
|
|
|
286
286
|
:root[data-theme="light"] #animation-settings { --ansi-white:#234231;--ansi-159:#116b64;--ansi-123:#0d7771;--ansi-87:#116b75;--ansi-51:#14697e;--ansi-45:#1a6183;--ansi-39:#265f8d;--ansi-33:#365a8d; }
|
|
287
287
|
:root[data-theme="light"] #animation-settings[data-terminal-palette="klein"] { --ansi-white:#002fa7;--ansi-159:#002fa7;--ansi-123:#002fa7;--ansi-87:#002fa7;--ansi-51:#002fa7;--ansi-45:#002fa7;--ansi-39:#002fa7;--ansi-33:#002fa7; }
|
|
288
|
+
|
|
289
|
+
.state-label { display:inline-flex; align-items:center; gap:8px; max-width:100%; vertical-align:middle; white-space:normal; }
|
|
290
|
+
.state-icon { width:16px; height:16px; flex:none; fill:none; stroke:currentColor; stroke-width:1.6; stroke-linecap:round; stroke-linejoin:round; }
|
|
291
|
+
.state-label.state-ok, .state-label.state-running { color:var(--accent); }
|
|
292
|
+
.state-label.state-warning { color:var(--bad); }
|
|
293
|
+
.state-label.state-unavailable, .state-label.state-unknown { color:var(--muted); }
|
|
294
|
+
.state-label > span { color:inherit; white-space:normal; }
|
|
295
|
+
.badge:has(.state-label)::before { display:none; }
|
|
296
|
+
.source-browse-note { margin:12px 0 20px; }
|
|
297
|
+
.account-name { margin:18px 0 6px; font-size:19px; color:var(--strong); font-weight:650; }
|
|
298
|
+
.account-fields { display:grid; grid-template-columns:minmax(110px,150px) minmax(0,1fr); gap:10px 18px; margin:20px 0; font-size:12px; line-height:1.7; }
|
|
299
|
+
.account-fields dt { color:var(--muted); }
|
|
300
|
+
.account-fields dd { margin:0; min-width:0; }
|
|
301
|
+
.tool-details, .tool-flow { margin-top:18px; padding-top:16px; border-top:1px solid var(--border); }
|
|
302
|
+
.tool-details summary, .tool-flow h3 { color:var(--heading); font-size:12px; }
|
|
303
|
+
.device-code { display:block; color:var(--accent); font-size:23px; letter-spacing:.1em; margin:16px 0; }
|
|
304
|
+
.tool-link { display:inline-flex; min-height:36px; align-items:center; color:var(--accent); margin-right:16px; }
|
|
305
|
+
.tool-code { background:var(--page); border:1px solid var(--border); padding:14px; font:inherit; font-size:12px; line-height:1.7; white-space:pre-wrap; overflow-wrap:anywhere; }
|
|
306
|
+
.checks-table td { vertical-align:top; white-space:normal; }
|
|
307
|
+
.checks-table th:first-child { width:23%; }
|
|
308
|
+
.checks-table th:nth-child(2) { width:21%; }
|
|
309
|
+
.checks-table details p { margin:8px 0; }
|
|
310
|
+
@media(max-width:640px) { .account-fields { grid-template-columns:100px minmax(0,1fr); gap:10px; } .checks-table { min-width:530px; } }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -269,6 +269,7 @@ function chooseProvider(id) {
|
|
|
269
269
|
if (previous) applyModels(previous, { changed: true });
|
|
270
270
|
else { emptyTable("live-models-body", 6, "reading_provider_catalog");text("models-note", "reading_provider_catalog"); }
|
|
271
271
|
element("live-models-body").setAttribute("aria-labelledby", `model-provider-${id}`);
|
|
272
|
+
window.dispatchEvent(new CustomEvent("ccdx:source-view"));
|
|
272
273
|
void loadModels();
|
|
273
274
|
}
|
|
274
275
|
|
|
@@ -303,7 +304,7 @@ function applyProviders(data, { changed }) {
|
|
|
303
304
|
let button = providerTabs.get(provider.id);
|
|
304
305
|
if (!button) {
|
|
305
306
|
button = document.createElement("button");button.type = "button";button.setAttribute("role", "tab");
|
|
306
|
-
button.id = `model-provider-${provider.id}`;button.setAttribute("aria-controls", "
|
|
307
|
+
button.id = `model-provider-${provider.id}`;button.setAttribute("aria-controls", "source-account-panel");
|
|
307
308
|
button.addEventListener("click", () => chooseProvider(provider.id));
|
|
308
309
|
button.addEventListener("keydown", event => {
|
|
309
310
|
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
@@ -393,6 +394,8 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
393
394
|
state: state => {
|
|
394
395
|
text("connection", state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable");
|
|
395
396
|
element("connection").className = `badge ${state.pending ? "neutral" : state.error ? "bad" : "good"}`;
|
|
397
|
+
globalThis.ccdxIcons?.set(element("connection"), state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable",
|
|
398
|
+
state.pending && !state.value ? "unknown" : state.error ? "unavailable" : "running");
|
|
396
399
|
if (state.error) refreshTime(element("updated"), state);
|
|
397
400
|
for (const node of timestamps.get("status")) refreshTime(node, state);
|
|
398
401
|
},
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -148,6 +148,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
148
148
|
updateStatusFn,
|
|
149
149
|
serviceControl,
|
|
150
150
|
applyAnimation,
|
|
151
|
+
tools,
|
|
151
152
|
} = {}) {
|
|
152
153
|
if (!isLoopbackAddress(req.socket?.remoteAddress)
|
|
153
154
|
|| req.headers?.host === undefined
|
|
@@ -160,6 +161,10 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
160
161
|
return;
|
|
161
162
|
}
|
|
162
163
|
|
|
164
|
+
if (["/_ccdx/ui/account", "/_ccdx/ui/checks"].includes(pathname)) {
|
|
165
|
+
return tools.handle(req, res, pathname, sendJson, sameOrigin);
|
|
166
|
+
}
|
|
167
|
+
|
|
163
168
|
if (pathname === PROVIDERS_PATH && req.method === "GET") {
|
|
164
169
|
try { sendJson(res, 200, { source: "provider_status", providers: dashboardProviders(providerStateFn, authStatusFn) }); }
|
|
165
170
|
catch { sendJson(res, 500, { error: "Could not read provider status" }); }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createAccountTools } from "./account-tools.mjs";
|
|
2
|
+
import { createLocalTools } from "./local-tools.mjs";
|
|
3
|
+
import { createRequestAbort, readJsonBody } from "./http-transport.mjs";
|
|
4
|
+
|
|
5
|
+
export const TOOL_PATHS = new Set(["/_ccdx/ui/account", "/_ccdx/ui/checks"]);
|
|
6
|
+
export function createDashboardTools(options = {}) {
|
|
7
|
+
const accounts = options.accountTools || createAccountTools({ ...options, onChanged: options.credentialsChanged });
|
|
8
|
+
const local = options.localTools || createLocalTools(options);
|
|
9
|
+
return {
|
|
10
|
+
dispose() { accounts.dispose(); },
|
|
11
|
+
async handle(req, res, pathname, sendJson, sameOrigin) {
|
|
12
|
+
const account = pathname === "/_ccdx/ui/account";
|
|
13
|
+
if (req.method === "GET") {
|
|
14
|
+
try { sendJson(res, 200, account ? accounts.snapshot() : local.snapshot()); }
|
|
15
|
+
catch { sendJson(res, 409, { error: "tools_read_failed", code: "tools_read_failed" }); }
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (req.method !== "POST") { sendJson(res, 405, { error: "Use GET or POST" });return; }
|
|
19
|
+
if (!sameOrigin(req)) { sendJson(res, 403, { error: "Tools require the same-origin dashboard" });return; }
|
|
20
|
+
if (!/^application\/json(?:\s*;|$)/i.test(req.headers["content-type"] || "")) { sendJson(res, 415, { error: "Expected application/json" });return; }
|
|
21
|
+
const abort = createRequestAbort(req, res);abort.setTimeout(5000, "request_body_timeout");
|
|
22
|
+
try {
|
|
23
|
+
const input = await readJsonBody(req, { maxBodyBytes: 4096, maxDecodedBodyBytes: 4096, signal: abort.signal });
|
|
24
|
+
abort.clearTimeout();
|
|
25
|
+
const fields = account ? { check: ["action"], start: ["action", "reauth"], cancel: ["action", "id"], logout: ["action", "confirmed"], reload: ["action"] }
|
|
26
|
+
: { check: ["action"], preview: ["action"], repair: ["action", "revision"], network: ["action"], report: ["action"] };
|
|
27
|
+
const allowed = input && typeof input === "object" && !Array.isArray(input) && fields[input.action];
|
|
28
|
+
if (!allowed || Object.keys(input).some(key => !allowed.includes(key)) || (input.action === "start" && input.reauth !== undefined && typeof input.reauth !== "boolean")) {
|
|
29
|
+
sendJson(res, 400, { error: "tools_invalid_action", code: "tools_invalid_action" });return;
|
|
30
|
+
}
|
|
31
|
+
const target = account ? accounts : local;
|
|
32
|
+
if (!account && input.action === "report" && !local.snapshot().checked_at) await local.check();
|
|
33
|
+
const value = await (input.action === "start" ? target.start({ reauth: input.reauth })
|
|
34
|
+
: input.action === "cancel" ? target.cancel(input.id) : input.action === "logout" ? target.logout(input)
|
|
35
|
+
: input.action === "repair" ? target.repair(input) : target[input.action]());
|
|
36
|
+
if (!res.destroyed && !res.writableEnded) sendJson(res, 200, value);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const code = /^(auth|copilot|config|tools)_[a-z_]+$/.test(error.code || "") ? error.code : "tools_action_failed";
|
|
39
|
+
sendJson(res, error.statusCode || 409, { error: code, code });
|
|
40
|
+
} finally { abort.cleanup(); }
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/src/dashboard.mjs
CHANGED
|
@@ -12,6 +12,8 @@ const ASSETS = new Map([
|
|
|
12
12
|
["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
|
|
13
13
|
["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
|
|
14
14
|
["/refresh.js", ["./dashboard/refresh.js", "text/javascript; charset=utf-8"]],
|
|
15
|
+
["/icons.js", ["./dashboard/icons.js", "text/javascript; charset=utf-8"]],
|
|
16
|
+
["/tools.js", ["./dashboard/tools.js", "text/javascript; charset=utf-8"]],
|
|
15
17
|
]);
|
|
16
18
|
|
|
17
19
|
export async function serveDashboard(req, res, pathname) {
|
package/src/doctor.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import net from "node:net";
|
|
5
|
-
import { githubTokenPath, readGithubTokenMetadata, validateGithubToken } from "./auth.mjs";
|
|
5
|
+
import { githubTokenPath, managedGithubTokenPath, readGithubTokenMetadata, validateGithubToken } from "./auth.mjs";
|
|
6
6
|
import {
|
|
7
7
|
AUTH_PROFILE_CODEX,
|
|
8
8
|
readAuthProfileCredentials,
|
|
@@ -65,7 +65,8 @@ export function inspectGitHubToken({ home = os.homedir() } = {}) {
|
|
|
65
65
|
export function inspectAuthProfiles({ home = os.homedir() } = {}) {
|
|
66
66
|
return [
|
|
67
67
|
...inspectGitHubToken({ home }),
|
|
68
|
-
{ kind: "
|
|
68
|
+
{ kind: "info", message: githubTokenPath(home) === managedGithubTokenPath(home)
|
|
69
|
+
? "Codex authentication profile uses the CCDX-owned store" : "Codex authentication profile uses the legacy path" },
|
|
69
70
|
];
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { collectDoctorChecks } from "./doctor.mjs";
|
|
5
|
+
import { inspectCodexConfig, repairCodexConfig } from "./codex-config-doctor.mjs";
|
|
6
|
+
import { codexPaths } from "./codex-paths.mjs";
|
|
7
|
+
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
8
|
+
import { inspectPredictionEnvironment } from "./native-prediction-environment.mjs";
|
|
9
|
+
import { formatPredictionEnvironment } from "./native-prediction-state.mjs";
|
|
10
|
+
import { localPackageVersion } from "./version.mjs";
|
|
11
|
+
|
|
12
|
+
export function createLocalTools({ home = os.homedir(), env = process.env, host = "127.0.0.1", port = 2026,
|
|
13
|
+
platform = process.platform, collect = collectDoctorChecks, inspectConfig = inspectCodexConfig, repairConfig = repairCodexConfig,
|
|
14
|
+
inspectNetwork = inspectPredictionEnvironment } = {}) {
|
|
15
|
+
const options = { home, env, host, port, platform };
|
|
16
|
+
let last = null, flight = null;
|
|
17
|
+
const safe = text => redactDiagnosticText(String(text || "")).split(home).join("~")
|
|
18
|
+
.replace(/[\w.+-]+@[\w.-]+/g, "[account]").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 600);
|
|
19
|
+
const project = checks => checks.slice(0, 80).map(check => ({ id: /^[a-z-]{1,60}$/.test(check.id || "") ? check.id : "local",
|
|
20
|
+
kind: ["ok", "info", "warn", "err"].includes(check.kind) ? check.kind : "info", message: safe(check.message) }));
|
|
21
|
+
function snapshot() { return { source: "local_tools", ...last }; }
|
|
22
|
+
async function check() {
|
|
23
|
+
if (flight) return flight;
|
|
24
|
+
flight = Promise.resolve().then(async () => {
|
|
25
|
+
last = { checked_at: new Date().toISOString(), checks: project(await collect({ ...options, checkAdapter: false })) };
|
|
26
|
+
return snapshot();
|
|
27
|
+
}).finally(() => { flight = null; });
|
|
28
|
+
return flight;
|
|
29
|
+
}
|
|
30
|
+
function revision() {
|
|
31
|
+
try { return createHash("sha256").update(fs.readFileSync(codexPaths(options).config)).digest("hex"); }
|
|
32
|
+
catch (error) { if (error.code === "ENOENT") return "missing";throw error; }
|
|
33
|
+
}
|
|
34
|
+
function preview() {
|
|
35
|
+
return { source: "config_repair_preview", revision: revision(), checks: project(inspectConfig(options)),
|
|
36
|
+
managed_keys: ["openai_base_url", "model_context_window", "model_auto_compact_token_limit", "shell_environment_policy", "features.context_management"],
|
|
37
|
+
backup: "config.toml.ccdx-doctor.bak" };
|
|
38
|
+
}
|
|
39
|
+
function repair(input) {
|
|
40
|
+
if (typeof input.revision !== "string" || input.revision !== revision()) throw Object.assign(new Error("config_preview_changed"), { code: "config_preview_changed", statusCode: 409 });
|
|
41
|
+
const result = repairConfig({ ...options, expectedRevision: input.revision });
|
|
42
|
+
const checks = project(inspectConfig(options).map(check => ({ ...check, id: "codex-config" })));
|
|
43
|
+
if (last) last = { checked_at: new Date().toISOString(), checks: [...last.checks.filter(check => check.id !== "codex-config"), ...checks] };
|
|
44
|
+
return { source: "config_repair_result", status: result.status, changed: result.changed === true,
|
|
45
|
+
checks, local: snapshot() };
|
|
46
|
+
}
|
|
47
|
+
function network() {
|
|
48
|
+
const value = inspectNetwork({ env, platform });
|
|
49
|
+
return { source: "network_check", checked_at: new Date().toISOString(), summary: safe(formatPredictionEnvironment(value.summary)) };
|
|
50
|
+
}
|
|
51
|
+
return { snapshot, check, preview, repair, network, report: () => ({ version: localPackageVersion(),
|
|
52
|
+
exported_at: new Date().toISOString(), scope: "local checks only; accounts and credentials omitted", ...snapshot() }) };
|
|
53
|
+
}
|
|
@@ -42,7 +42,7 @@ export function inspectPredictionEnvironment({ env = process.env, platform = pro
|
|
|
42
42
|
network = { settings };
|
|
43
43
|
}
|
|
44
44
|
} else {
|
|
45
|
-
const systemProxy = exec("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 2000, maxBuffer: 64 * 1024 });
|
|
45
|
+
const systemProxy = platform === "darwin" ? exec("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 2000, maxBuffer: 64 * 1024 }) : "";
|
|
46
46
|
network = { networkRoute: resolveNetworkRoute({ env, systemProxy }) };
|
|
47
47
|
}
|
|
48
48
|
} catch (error) {
|
package/src/optional-routes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/status.js", "/usage.js", "/ui.js", "/console.js", "/updates.js"]);
|
|
2
|
-
export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers", "/_ccdx/ui/settings", "/_ccdx/ui/m365/accounts", "/_ccdx/ui/updates"]);
|
|
1
|
+
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/status.js", "/usage.js", "/ui.js", "/console.js", "/updates.js", "/icons.js", "/tools.js"]);
|
|
2
|
+
export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers", "/_ccdx/ui/settings", "/_ccdx/ui/m365/accounts", "/_ccdx/ui/updates", "/_ccdx/ui/account", "/_ccdx/ui/checks"]);
|
|
3
3
|
|
|
4
4
|
export function isOptionalRoute(method, pathname) {
|
|
5
5
|
return DASHBOARD_API_PATHS.has(pathname) || pathname === "/mcp/image"
|
|
@@ -10,12 +10,18 @@ export function isOptionalRoute(method, pathname) {
|
|
|
10
10
|
// shared HTTP dispatcher and cannot initialize or change core inference.
|
|
11
11
|
export function createOptionalRoutes(options = {}) {
|
|
12
12
|
let imageMcpHandler = options.imageMcpHandler || null;
|
|
13
|
+
let tools = null;
|
|
13
14
|
return {
|
|
15
|
+
dispose() { tools?.dispose(); },
|
|
14
16
|
imageStats() { return imageMcpHandler?.stats?.(); },
|
|
15
17
|
async handle(req, res, pathname) {
|
|
16
18
|
if (DASHBOARD_API_PATHS.has(pathname)) {
|
|
17
19
|
const { handleDashboardApi } = await import("./dashboard-api.mjs");
|
|
18
|
-
|
|
20
|
+
if (["/_ccdx/ui/account", "/_ccdx/ui/checks"].includes(pathname)) {
|
|
21
|
+
const { createDashboardTools } = await import("./dashboard-tools.mjs");
|
|
22
|
+
tools ||= createDashboardTools(options.dashboardOptions);
|
|
23
|
+
}
|
|
24
|
+
return handleDashboardApi(req, res, pathname, { ...options.dashboardOptions, tools });
|
|
19
25
|
}
|
|
20
26
|
if ((req.method === "GET" || req.method === "HEAD") && DASHBOARD_PATHS.has(pathname)) {
|
|
21
27
|
const { serveDashboard } = await import("./dashboard.mjs");
|
package/src/provider-runtime.mjs
CHANGED
|
@@ -16,7 +16,7 @@ const unavailable = reason => Object.assign(new Error(`Microsoft 365 is unavaila
|
|
|
16
16
|
|
|
17
17
|
// Composition owns source selection. Providers never modify Codex, prediction,
|
|
18
18
|
// image configuration or each other's credentials.
|
|
19
|
-
export function createProviderRuntime({ githubClient, githubRegistry, githubCredentialFingerprint = "", home, env = process.env, platform = process.platform,
|
|
19
|
+
export function createProviderRuntime({ githubClient, githubRegistry, githubCredentialFingerprint = "", githubClientConfigured = true, home, env = process.env, platform = process.platform,
|
|
20
20
|
corePort = Number(env.ADAPTER_PORT || 2026), log = () => {}, createM365, startGateway, configureClients, restoreClients,
|
|
21
21
|
discoverM365 = requestM365Accounts } = {}) {
|
|
22
22
|
const options = { home, env, platform }, github = { ...createGithubProvider({ client: githubClient,
|
|
@@ -206,7 +206,7 @@ export function createProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
206
206
|
{ id: "github", name: "GitHub Copilot", generation: dashboardGeneration(github), enabled: true, state: service.token_cached ? "ready" : "unknown",
|
|
207
207
|
auth: { state: "unknown", token_cached: service.token_cached === true, expires_in_ms: service.token_expires_in_ms ?? null },
|
|
208
208
|
models: { count: githubRegistry?.models?.data?.length ?? null, source: githubRegistry?.source || "unknown" },
|
|
209
|
-
clients: [{ id: "codex", name: "Codex App", selected: selection.codex === "github", state: "configured" }] },
|
|
209
|
+
clients: [{ id: "codex", name: "Codex App", selected: selection.codex === "github", state: githubClientConfigured ? "configured" : "unknown" }] },
|
|
210
210
|
{ id: "m365", name: "Microsoft 365", generation: m365 ? dashboardGeneration(m365) : 0, enabled, state: ms.state, reason: ms.reason, network_diagnostic: ms.network_diagnostic,
|
|
211
211
|
auth: { state: ms.token_cached ? "authorized" : !enabled ? "disabled" : ms.reason ? "unavailable" : "unknown",
|
|
212
212
|
account: ms.account?.login || "", token_cached: ms.token_cached === true,
|