codex-copilot-dx 1.2.25 → 1.2.27
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 +4 -4
- package/docs/ARCHITECTURE.md +29 -1
- package/docs/REFERENCE.md +72 -4
- package/package.json +1 -1
- package/src/claude-client-config.mjs +46 -3
- package/src/cli-m365.mjs +3 -1
- package/src/dashboard/animation.js +8 -0
- package/src/dashboard/console.js +18 -7
- package/src/dashboard/index.html +15 -0
- package/src/dashboard/language.js +40 -0
- package/src/dashboard/preferences.js +194 -0
- package/src/dashboard/status.js +32 -15
- package/src/dashboard/theme.js +10 -3
- package/src/dashboard/ui.css +19 -0
- package/src/dashboard/ui.js +26 -13
- package/src/dashboard-api.mjs +1 -1
- package/src/dashboard.mjs +1 -0
- package/src/management-routes.mjs +3 -1
- package/src/optional-routes.mjs +1 -1
- package/src/provider-runtime.mjs +2 -1
- package/src/providers/m365-endpoint.mjs +4 -0
- package/src/providers/m365-network.mjs +3 -3
- package/src/providers/m365.mjs +7 -5
- package/src/service-control.mjs +10 -2
- package/src/settings-preferences.mjs +76 -0
- package/src/status-summary.mjs +6 -0
- package/src/user-settings.mjs +3 -3
- package/src/windows-http-network.mjs +2 -1
- package/src/windows-prediction-network.cs +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { readUserSettings, userSettingsPath } from "./user-settings.mjs";
|
|
5
|
+
import { isColorTheme } from "./terminal-colors.mjs";
|
|
6
|
+
import { DEFAULT_TERMINAL_ANIMATION_THEME, isTerminalAnimationTheme } from "./terminal-animation.mjs";
|
|
7
|
+
import { readBoundedFileSync } from "./bounded-file.mjs";
|
|
8
|
+
import { atomicWriteFileIfChangedSync, atomicWriteFilePairSync } from "./atomic-file.mjs";
|
|
9
|
+
import { withFileLockSync } from "./lock.mjs";
|
|
10
|
+
|
|
11
|
+
export const SETTINGS_DEFAULTS = Object.freeze({ terminal_color_theme: "green", terminal_animation: DEFAULT_TERMINAL_ANIMATION_THEME,
|
|
12
|
+
terminal_animation_enabled: true, open_webui: true, nightly_updates: false, auto_save_settings: true });
|
|
13
|
+
const keys = Object.keys(SETTINGS_DEFAULTS);
|
|
14
|
+
const fail = (code, message, statusCode = 409) => Object.assign(new Error(message), { code, statusCode });
|
|
15
|
+
const idValid = value => typeof value === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(value);
|
|
16
|
+
const valuesFor = settings => Object.fromEntries(keys.map(key => [key, key === "terminal_animation" && !isTerminalAnimationTheme(settings[key])
|
|
17
|
+
? SETTINGS_DEFAULTS[key] : settings[key] ?? SETTINGS_DEFAULTS[key]]));
|
|
18
|
+
const revisionFor = values => createHash("sha256").update(JSON.stringify(keys.map(key => values[key]))).digest("hex");
|
|
19
|
+
export const settingsBackupPath = options => path.join(path.dirname(userSettingsPath(options)), "settings-preferences-backup.json");
|
|
20
|
+
|
|
21
|
+
function checkedValues(values) {
|
|
22
|
+
if (!values || typeof values !== "object" || Array.isArray(values) || Object.keys(values).some(key => !keys.includes(key)
|
|
23
|
+
|| (key === "terminal_color_theme" ? !isColorTheme(values[key]) : key === "terminal_animation" ? !isTerminalAnimationTheme(values[key]) : typeof values[key] !== "boolean"))) {
|
|
24
|
+
throw fail("ccdx_settings_values_invalid", "Choose valid settings on this page", 400);
|
|
25
|
+
}
|
|
26
|
+
return values;
|
|
27
|
+
}
|
|
28
|
+
function readBackup(options) {
|
|
29
|
+
try {
|
|
30
|
+
const value = JSON.parse(readBoundedFileSync(settingsBackupPath(options), { encoding: "utf8", maxBytes: 8192 }));
|
|
31
|
+
if (value?.version !== 1 || !idValid(value.id) || typeof value.created_at !== "string" || !Number.isFinite(Date.parse(value.created_at))
|
|
32
|
+
|| Object.keys(value).some(key => !["version", "id", "created_at", "values"].includes(key))
|
|
33
|
+
|| keys.some(key => !Object.hasOwn(value.values || {}, key))) throw Error();
|
|
34
|
+
checkedValues(value.values);return value;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code === "ENOENT") return null;
|
|
37
|
+
throw fail("ccdx_settings_backup_invalid", "The settings backup could not be read; existing files were preserved");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function settingsPreferencesSnapshot(options = {}) {
|
|
41
|
+
const values = valuesFor(readUserSettings({ ...options, strict: true }));
|
|
42
|
+
let backup = null, backup_error = null;
|
|
43
|
+
try { const saved = readBackup(options);if (saved) backup = { id: saved.id, created_at: saved.created_at }; }
|
|
44
|
+
catch (error) { backup_error = error.code; }
|
|
45
|
+
return { values, defaults: SETTINGS_DEFAULTS, revision: revisionFor(values), backup, backup_error };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Only this page's preferences enter its backup. Routing, auth, business flags
|
|
49
|
+
// and unknown settings are retained in the current file, never copied here.
|
|
50
|
+
export function writeSettingsPreferences(input, options = {}) {
|
|
51
|
+
const file = userSettingsPath(options);
|
|
52
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
53
|
+
return withFileLockSync(`${file}.lock`, () => {
|
|
54
|
+
const current = readUserSettings({ ...options, strict: true }), before = valuesFor(current);
|
|
55
|
+
const backup = input.action === "preferences" ? null : readBackup(options);
|
|
56
|
+
if (input.action === "reset_preferences" && backup?.id === input.backup_id && revisionFor(before) === revisionFor(SETTINGS_DEFAULTS)) return;
|
|
57
|
+
if (typeof input.revision !== "string" || input.revision !== revisionFor(before)) {
|
|
58
|
+
throw fail("ccdx_settings_changed", "Settings changed elsewhere. Review the current settings before saving again");
|
|
59
|
+
}
|
|
60
|
+
let values;
|
|
61
|
+
if (input.action === "preferences") values = checkedValues(input.values);
|
|
62
|
+
else {
|
|
63
|
+
if (!idValid(input.backup_id)) throw fail("ccdx_settings_backup_invalid", "Choose the current settings backup", 400);
|
|
64
|
+
if (input.action === "restore_preferences") {
|
|
65
|
+
if (!backup || input.backup_id !== backup.id) throw fail("ccdx_settings_changed", "The settings backup changed. Review it before restoring");
|
|
66
|
+
values = backup.values;
|
|
67
|
+
} else if (input.action === "reset_preferences") values = SETTINGS_DEFAULTS;
|
|
68
|
+
else throw fail("ccdx_settings_action_invalid", "Unknown settings action", 400);
|
|
69
|
+
}
|
|
70
|
+
const next = { ...current, ...values }, data = `${JSON.stringify(next, null, 2)}\n`;
|
|
71
|
+
if (input.action === "reset_preferences") {
|
|
72
|
+
const saved = { version: 1, id: input.backup_id, created_at: new Date().toISOString(), values: before };
|
|
73
|
+
atomicWriteFilePairSync(settingsBackupPath(options), `${JSON.stringify(saved, null, 2)}\n`, file, data);
|
|
74
|
+
} else atomicWriteFileIfChangedSync(file, data, { mode: 0o600 });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// An explicit projection, never a partial replacement for the full diagnostic
|
|
2
|
+
// snapshot. Old callers keep the complete status contract by default.
|
|
3
|
+
export function statusSummary(snapshot) {
|
|
4
|
+
return Object.fromEntries([...['ok', 'name', 'version', 'pid', 'uptime_ms', 'model_activity', 'runtime_usage']
|
|
5
|
+
.map(key => [key, snapshot[key]]), ['scope', 'summary']]);
|
|
6
|
+
}
|
package/src/user-settings.mjs
CHANGED
|
@@ -51,9 +51,9 @@ export function readUserSettings({ env = process.env, home = os.homedir(), stric
|
|
|
51
51
|
delete parsed[key];
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
if (Object.hasOwn(parsed,
|
|
55
|
-
if (strict) throw invalidSettings(filePath,
|
|
56
|
-
delete parsed
|
|
54
|
+
for (const key of ["nightly_updates", "auto_save_settings"]) if (Object.hasOwn(parsed, key) && typeof parsed[key] !== "boolean") {
|
|
55
|
+
if (strict) throw invalidSettings(filePath, `${key} must be a boolean`);
|
|
56
|
+
delete parsed[key];
|
|
57
57
|
}
|
|
58
58
|
if (Object.hasOwn(parsed, "terminal_color_theme") && !isColorTheme(parsed.terminal_color_theme)) {
|
|
59
59
|
if (strict) throw invalidSettings(filePath, "terminal_color_theme must be green, klein or pink");
|
|
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { PassThrough, Writable } from "node:stream";
|
|
5
5
|
import { windowsPowerShellEnvironment } from "./windows-process.mjs";
|
|
6
|
+
import { M365_API_HOST } from "./providers/m365-endpoint.mjs";
|
|
6
7
|
|
|
7
8
|
function failure(code) {
|
|
8
9
|
return Object.assign(new Error(`Windows network failed (${code}); existing company routes were preserved`), { code });
|
|
@@ -16,7 +17,7 @@ export async function startWindowsHttpNetwork({ settings = {}, target = "predict
|
|
|
16
17
|
if (target === "api" && (!Array.isArray(apiTargets) || !apiTargets.length || apiTargets.length > 8 || apiTargets.some(raw => {
|
|
17
18
|
try { const url = new URL(raw);return url.protocol !== "https:" || url.username || url.password || url.search || url.hash || url.href !== raw; } catch { return true; }
|
|
18
19
|
}))) throw failure("proxy_target_invalid");
|
|
19
|
-
const allowedHosts = target === "api" ? apiTargets.map(raw => new URL(raw).hostname) : target === "m365" ? [
|
|
20
|
+
const allowedHosts = target === "api" ? apiTargets.map(raw => new URL(raw).hostname) : target === "m365" ? [M365_API_HOST] : ["chatgpt.com", "ab.chatgpt.com"];
|
|
20
21
|
const command = path.win32.join(env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
21
22
|
const source = fileURLToPath(new URL("./windows-prediction-network.cs", import.meta.url));
|
|
22
23
|
const child = spawnImpl(command, ["-NoProfile", "-NonInteractive", "-Command",
|
|
@@ -84,7 +84,7 @@ public static class CCDXPredictionNetwork {
|
|
|
84
84
|
IntPtr connection=IntPtr.Zero;
|
|
85
85
|
try {
|
|
86
86
|
var uri=new Uri((string)data["url"]);
|
|
87
|
-
if(uri.Scheme!="https" || uri.UserInfo.Length!=0 || uri.Fragment.Length!=0 || (target=="api" ? !ApiTargetAllowed(uri,(string)data["method"]) : (uri.Port!=443 || (target=="m365" ? (uri.Host!="
|
|
87
|
+
if(uri.Scheme!="https" || uri.UserInfo.Length!=0 || uri.Fragment.Length!=0 || (target=="api" ? !ApiTargetAllowed(uri,(string)data["method"]) : (uri.Port!=443 || (target=="m365" ? (uri.Host!="loki.delve.office.com" || !uri.AbsolutePath.StartsWith("/api/v1/llmapi/",StringComparison.Ordinal)) : (uri.Host!="chatgpt.com"&&uri.Host!="ab.chatgpt.com"))))) throw new IOException("winhttp_target_invalid");
|
|
88
88
|
var method=(string)data["method"];
|
|
89
89
|
if(method!="GET"&&method!="POST"&&method!="HEAD"&&method!="PUT"&&method!="DELETE"&&method!="OPTIONS"&&method!="PATCH")throw new IOException("winhttp_method_invalid");
|
|
90
90
|
var headers=(string)data["headers"];
|