codex-copilot-dx 0.9.38 → 0.9.40

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/src/launcher.mjs CHANGED
@@ -3,6 +3,7 @@ import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { installedWindowsPredictionApp, windowsPredictionAppProcesses } from "./native-prediction-windows.mjs";
5
5
  import { status } from "./status.mjs";
6
+ import { isPredictionPacUrl } from "./prediction-pac.mjs";
6
7
 
7
8
  export { ensureAuth } from "./auth.mjs";
8
9
 
@@ -50,7 +51,7 @@ export function macPredictionAppProcesses(app, { exec = execFileSync } = {}) {
50
51
  const pid = Number(match[1]);
51
52
  try {
52
53
  const args = exec("/bin/ps", ["-p", String(pid), "-o", "args="], options);
53
- const route = args.match(/(?:^|\s)--proxy-pac-url=(?:"(http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac)"|(http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac)(?=\s|$))/);
54
+ const route = args.match(/(?:^|\s)--proxy-pac-url=(?:"(http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac(?:\?v=2)?)"|(http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac(?:\?v=2)?)(?=\s|$))/);
54
55
  const readable = args.trim() === match[2] || args.trimStart().startsWith(`${match[2]} `);
55
56
  const uniqueRoute = (args.match(/(?:^|\s)--proxy-pac-url=/g) || []).length === 1;
56
57
  rows.push({ pid, readable, route: readable && uniqueRoute ? route?.[1] || route?.[2] || null : null });
@@ -64,8 +65,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
64
65
  preparePredictionRoute, persistedPredictionRoute = false, onPredictionRoute = () => {}, log = console.log,
65
66
  resolveWindowsApp = installedWindowsPredictionApp, windowsAppProcesses = windowsPredictionAppProcesses,
66
67
  macAppProcesses = macPredictionAppProcesses } = {}) {
67
- if (platform === "win32" && autoLaunchEnabled(env) && typeof predictionPacUrl === "string"
68
- && /^http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac$/.test(predictionPacUrl)
68
+ if (platform === "win32" && autoLaunchEnabled(env) && isPredictionPacUrl(predictionPacUrl)
69
69
  && typeof predictionApp === "string" && path.win32.isAbsolute(predictionApp)) {
70
70
  try {
71
71
  if (typeof predictionProfile !== "string" || !path.win32.isAbsolute(predictionProfile)
@@ -124,7 +124,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
124
124
  return false;
125
125
  }
126
126
 
127
- const extraArgs = typeof predictionPacUrl === "string" && /^http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac$/.test(predictionPacUrl)
127
+ const extraArgs = isPredictionPacUrl(predictionPacUrl)
128
128
  && APP_PATH_CANDIDATES.includes(predictionApp)
129
129
  ? ["--args", `--proxy-pac-url=${predictionPacUrl}`] : [];
130
130
  if (extraArgs.length) {
package/src/lock.mjs CHANGED
@@ -71,11 +71,21 @@ function readStaleLockSnapshot(lockPath, io) {
71
71
  fd = io.openSync(lockPath, io.constants.O_RDONLY | noFollow);
72
72
  const opened = io.fstatSync(fd);
73
73
  if (!opened.isFile()
74
- || opened.dev !== before.dev
74
+ || (before.dev !== 0 && opened.dev !== before.dev)
75
75
  || opened.ino !== before.ino
76
76
  || opened.size !== before.size) {
77
77
  return { safe: false };
78
78
  }
79
+ // Node 22 on Windows can return dev=0 from path lstat but a real device
80
+ // from fstat. Do not waive device identity: verify a second path handle.
81
+ if (before.dev === 0 && opened.dev !== 0) {
82
+ const pathFd = io.openSync(lockPath, io.constants.O_RDONLY | noFollow);
83
+ try {
84
+ const current = io.fstatSync(pathFd);
85
+ if (!current.isFile() || current.dev !== opened.dev || current.ino !== opened.ino
86
+ || current.size !== opened.size) return { safe: false };
87
+ } finally { io.closeSync(pathFd); }
88
+ }
79
89
  const text = io.readFileSync(fd, "utf8");
80
90
  const after = io.fstatSync(fd);
81
91
  if (after.dev !== opened.dev
@@ -4,9 +4,9 @@ import { isDeepStrictEqual } from "node:util";
4
4
  import { readBoundedFileSync } from "./bounded-file.mjs";
5
5
  import { atomicWriteFileSync } from "./atomic-file.mjs";
6
6
  import { withFileLock } from "./lock.mjs";
7
+ import { isPredictionPacUrl } from "./prediction-pac.mjs";
7
8
 
8
- const validPac = value => typeof value === "string" && /^http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac$/.test(value)
9
- && Number(new URL(value).port) >= 1024 && Number(new URL(value).port) <= 65535;
9
+ const validPac = isPredictionPacUrl;
10
10
  const object = value => value && typeof value === "object" && !Array.isArray(value);
11
11
 
12
12
  function regularFile(file) {
@@ -4,6 +4,7 @@ import { promisify } from "node:util";
4
4
  import { gunzip, inflate, brotliDecompress } from "node:zlib";
5
5
  import { networkPredictionPac } from "./network-route.mjs";
6
6
  import { operationErrorDetails } from "./operation-error.mjs";
7
+ import { PREDICTION_PAC_PATH, predictionProxyExpression } from "./prediction-pac.mjs";
7
8
 
8
9
  export const PREDICTION_HOSTS = Object.freeze(["chatgpt.com", "ab.chatgpt.com"]);
9
10
  const CONFIG_LIMIT = 16 * 1024 * 1024;
@@ -20,7 +21,7 @@ export function predictionRoute(host, pathname) {
20
21
  export function predictionPac(port, networkRoute) {
21
22
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Invalid prediction proxy port");
22
23
  if (networkRoute) return networkPredictionPac(port, networkRoute);
23
- return `function FindProxyForURL(url, host) { if (url.indexOf('https:') === 0 && (host === 'chatgpt.com' || host === 'ab.chatgpt.com')) return 'PROXY 127.0.0.1:${port}; DIRECT'; return 'DIRECT'; }\n`;
24
+ return `function FindProxyForURL(url, host) { if (url.indexOf('https:') === 0 && (host === 'chatgpt.com' || host === 'ab.chatgpt.com')) return ${predictionProxyExpression(port)}+'; DIRECT'; return 'DIRECT'; }\n`;
24
25
  }
25
26
 
26
27
  function cleanHeaders(headers) {
@@ -220,7 +221,7 @@ export async function startPredictionTransport({
220
221
  gateway.on("tlsClientError", (error, socket) => { onEvent({ type: "tls_error", error: operationErrorDetails(error) }); socket.destroy(); });
221
222
  gateway.on("clientError", (_error, socket) => socket.destroy());
222
223
  const proxy = http.createServer((req, res) => {
223
- if (req.method === "GET" && req.url === "/proxy.pac" && !req.headers.origin
224
+ if (req.method === "GET" && ["/proxy.pac", PREDICTION_PAC_PATH].includes(req.url) && !req.headers.origin
224
225
  && ["127.0.0.1", "localhost"].includes(String(req.headers.host || "").split(":")[0])) {
225
226
  res.writeHead(200, { "Content-Type": "application/x-ns-proxy-autoconfig", "Cache-Control": "no-store" });
226
227
  res.end(pacImpl ? pacImpl(proxy.address().port) : predictionPac(proxy.address().port, networkRoute)); return;
@@ -249,7 +250,7 @@ export async function startPredictionTransport({
249
250
  try { port = await listen(proxy, listenPort); }
250
251
  catch (error) { agent?.destroy();gateway.close();throw error; }
251
252
  return {
252
- port, pacUrl: `http://127.0.0.1:${port}/proxy.pac`,
253
+ port, pacUrl: `http://127.0.0.1:${port}${PREDICTION_PAC_PATH}`,
253
254
  healthy() { return !closing && !listenerError && proxy.listening; },
254
255
  async close() {
255
256
  closing = true;
@@ -35,7 +35,7 @@ export function windowsPredictionAppProcesses(app, { env = process.env, ...optio
35
35
  $_.ExecutablePath -eq $env:CCDX_PREDICTION_APP_PATH -and ($_.CommandLine -notmatch '--type(?:=|\\s)')
36
36
  } | ForEach-Object {
37
37
  $route=$null;
38
- if($_.CommandLine -match '--proxy-pac-url=(?:"(http://127\\.0\\.0\\.1:\\d{1,5}/proxy\\.pac)"|(http://127\\.0\\.0\\.1:\\d{1,5}/proxy\\.pac))'){
38
+ if($_.CommandLine -match '--proxy-pac-url=(?:"(http://127\\.0\\.0\\.1:\\d{1,5}/proxy\\.pac(?:\\?v=2)?)"|(http://127\\.0\\.0\\.1:\\d{1,5}/proxy\\.pac(?:\\?v=2)?)(?=\\s|$))'){
39
39
  $route=if($Matches[1]){$Matches[1]}else{$Matches[2]}
40
40
  };
41
41
  @{pid=[int]$_.ProcessId;route=$route;readable=![string]::IsNullOrWhiteSpace($_.CommandLine)}
@@ -43,7 +43,7 @@ export function windowsPredictionAppProcesses(app, { env = process.env, ...optio
43
43
  let rows;
44
44
  try { rows = JSON.parse(raw); } catch { throw new Error("Could not verify the running Windows App route; launch was skipped"); }
45
45
  if (!Array.isArray(rows) || rows.length > 8 || rows.some(row => !Number.isInteger(row?.pid) || typeof row.readable !== "boolean"
46
- || (row.route !== null && (typeof row.route !== "string" || !/^http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac$/.test(row.route))))) {
46
+ || (row.route !== null && (typeof row.route !== "string" || !/^http:\/\/127\.0\.0\.1:\d{1,5}\/proxy\.pac(?:\?v=2)?$/.test(row.route))))) {
47
47
  throw new Error("Unknown running Windows App route; launch was skipped");
48
48
  }
49
49
  return rows;
@@ -55,7 +55,7 @@ async function runPredictionCommandUnlocked({ action = "status", env = process.e
55
55
  }
56
56
  if (action === "status") {
57
57
  output(`Native prediction preference: ${settings.enabled ? "on" : "off"} (default: off)`);
58
- output("Uses the conversation's model. No prediction MCP, Hook, or panel.");
58
+ output("Uses the conversation's model.");
59
59
  if (settings.enabled && !predictionAppMatches(settings.app)) output("Codex App changed; bridge startup will recheck compatibility. Unsupported changes still require explicit setup.");
60
60
  if (runtimeSnapshot) {
61
61
  try {
@@ -1,5 +1,6 @@
1
1
  import net from "node:net";
2
2
  import { compileBypassRules, matchesBypass, bypassPacSource } from "./network-bypass.mjs";
3
+ import { predictionProxyExpression } from "./prediction-pac.mjs";
3
4
 
4
5
  const OFFICIAL_API = "https://chatgpt.com/backend-api";
5
6
  const routeError = (code, message) => Object.assign(new Error(message), { code });
@@ -80,7 +81,7 @@ function FindProxyForURL(url,host) {
80
81
  var authority=url.split('/')[2]||'', explicit=/:([0-9]+)$/.exec(authority);if(explicit)p=Number(explicit[1]);
81
82
  var skip=matchesBypass(host,p,ccdxRoute.rules,ccdxRoute.excludeSimple);
82
83
  var original=skip?'DIRECT':secure?ccdxRoute.https:ccdxRoute.http;
83
- if(secure&&(host==='chatgpt.com'||host==='ab.chatgpt.com'))return 'PROXY 127.0.0.1:${port}; '+original;
84
+ if(secure&&(host==='chatgpt.com'||host==='ab.chatgpt.com'))return ${predictionProxyExpression(port)}+'; '+original;
84
85
  return original;
85
86
  }\n`;
86
87
  }
@@ -136,6 +136,7 @@ export async function runPackageUpdateCommand({
136
136
  inspectEnvironmentFn = inspectPackageUpdateEnvironment,
137
137
  inspectPolicyFn = inspectNpmDownloadPolicy,
138
138
  verifyInstalledFn = verifyInstalledPackage,
139
+ repairCommandFn,
139
140
  } = {}) {
140
141
  if (typeof allowRemote !== "boolean") throw new Error("Remote download permission must be a boolean");
141
142
  let selectedSource = normalizeUpdateSource(source);
@@ -208,6 +209,13 @@ export async function runPackageUpdateCommand({
208
209
  const installedVersion = verifyInstalledFn(environment?.target, { expectedVersion: release?.version });
209
210
  if (installedVersion) {
210
211
  output.write(`Updated ${PACKAGE_NAME}: installed v${terminalCell(installedVersion)} at ${terminalCell(environment.target)}.\n`);
212
+ if (platform === "win32") {
213
+ try {
214
+ const repair = repairCommandFn || (await import("./windows-command.mjs")).inspectWindowsCommand;
215
+ const result = repair({ platform, packageRoot: environment.target, repair: true });
216
+ if (result.status !== "ready") output.write("Command launcher was preserved; use ccdx.cmd doctor --fix to inspect it. PowerShell policy is unchanged.\n");
217
+ } catch { output.write("Installed package verified; optional command setup could not finish. Use ccdx.cmd doctor --fix.\n"); }
218
+ }
211
219
  } else {
212
220
  output.write("Installer finished; the global target was unavailable, so the installed version was not verified. Run ccdx doctor.\n");
213
221
  }
@@ -0,0 +1,17 @@
1
+ // A stable format revision, not the CCDX package version. Existing Apps must
2
+ // load it once; later adapter upgrades keep the same URL, port and trust.
3
+ export const PREDICTION_PAC_PATH = "/proxy.pac?v=2";
4
+
5
+ export function isPredictionPacUrl(value) {
6
+ const match = typeof value === "string" && /^http:\/\/127\.0\.0\.1:(\d{1,5})\/proxy\.pac(?:\?v=2)?$/.exec(value);
7
+ return Boolean(match && Number(match[1]) >= 1024 && Number(match[1]) <= 65535);
8
+ }
9
+
10
+ // Chromium caches failed proxy endpoints separately from the PAC URL. A fresh
11
+ // loopback-only name lets its next resolution retry a restored listener without
12
+ // waiting for that failed endpoint's retry cache. No timer, DNS lookup in Node,
13
+ // new port, process, or system proxy mutation is involved.
14
+ export function predictionProxyExpression(port) {
15
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Invalid prediction proxy port");
16
+ return `'PROXY 127.0.0.1:${port}; PROXY ccdx-'+Math.floor(Date.now()/10000)+'.localhost:${port}'`;
17
+ }
@@ -60,7 +60,11 @@ export function retirePredictionIntegration(options = {}) {
60
60
  // No registration/settings means no lock directory or other write on startup.
61
61
  const env = options.env || process.env;
62
62
  const settings = path.resolve(env.CCDX_SUGGESTION_CONFIG || path.join(path.dirname(userSettingsPath(options)), "suggestion.json"));
63
- if (!fs.existsSync(config) && !fs.existsSync(settings)) return { changed: false, preserved: false };
63
+ if (!fs.existsSync(settings)) {
64
+ let content;
65
+ try { content = fs.readFileSync(config, "utf8"); } catch (error) { if (error.code !== "ENOENT") throw error; }
66
+ if (!content?.includes("ccdx_suggestion") && !content?.includes("ccdx:suggestion-auto:start")) return { changed: false, preserved: false };
67
+ }
64
68
  return withFileLockSync(`${config}.ccdx.lock`, () => retirePredictionIntegrationUnlocked(options));
65
69
  }
66
70
  function retirePredictionIntegrationUnlocked({ env = process.env, home = os.homedir(), dryRun = false } = {}) {
@@ -5,23 +5,19 @@ import { formatPredictionEnvironment } from "./native-prediction-state.mjs";
5
5
  // The favicon's three ellipses, rasterized as terminal half-blocks. No runtime
6
6
  // graphics library or terminal cursor control is needed.
7
7
  const ATOM = [
8
- " ▄█▀█▄▄ ▄▄█▀█▄ ",
9
- " █ ███ █ ",
10
- " █ ▄▄▄█▄█▄▄▄ █ ",
11
- " ▄▄▀▀█▀█▀ ▀█▀█▀▀▄▄ ",
12
- " █▀ ▀█ ▄█▄ █▀ ▀█ ",
13
- " ▀█▄ █▀▄ ▀ ▄▀█ ▄█▀ ",
14
- " ▀█▀███▄▄▄███▀█▀ ",
15
- " █ █▄█ █ ",
16
- " █▄ ▄▄█▀█▄▄ ▄█ ",
17
- " ▀▀▀ ▀▀▀ ",
8
+ " ▄▀█▄ ▄█▀▄ ",
9
+ " █ ▄███▄ █ ",
10
+ " ▄▀▀█▀ ▄ ▀█▀▀▄ ",
11
+ " ▀▄▄█▄ ▀ ▄█▄▄▀ ",
12
+ " █ ▀███▀ █ ",
13
+ " ▀▄█▀ ▀█▄▀ ",
18
14
  ];
19
15
 
20
16
  export function startupBanner({ commandName = "ccdx", version, stream = process.stdout, env = process.env } = {}) {
21
17
  const title = `${terminalCell(commandName)} v${terminalCell(version)} by Dale Xiao`;
22
18
  const color = stream.isTTY === true && !Object.hasOwn(env, "NO_COLOR") && env.TERM !== "dumb";
23
19
  if (!color || Number(stream.columns || 80) < 72) return `${title}\nUse Codex App with GitHub Copilot`;
24
- const labels = new Map([[3, `${terminalCell(commandName).toUpperCase()} v${terminalCell(version)}`], [4, "by Dale Xiao"], [6, "Codex App + GitHub Copilot"]]);
20
+ const labels = new Map([[1, `${terminalCell(commandName).toUpperCase()} v${terminalCell(version)}`], [2, "by Dale Xiao"], [4, "Codex App + GitHub Copilot"]]);
25
21
  return ATOM.map((line, i) => `\x1b[38;2;166;245;168m${line}\x1b[0m${labels.has(i) ? ` ${labels.get(i)}` : ""}`).join("\n");
26
22
  }
27
23
 
@@ -0,0 +1,77 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { readBoundedFileSync } from "./bounded-file.mjs";
5
+ import { withFileLockSync } from "./lock.mjs";
6
+
7
+ // Match npm's generated launcher, not an arbitrary script mentioning CCDX.
8
+ function npmPowerShellShim(target) {
9
+ return `#!/usr/bin/env pwsh
10
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
11
+
12
+ $exe=""
13
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
14
+ # Fix case when both the Windows and Linux builds of Node
15
+ # are installed in the same directory
16
+ $exe=".exe"
17
+ }
18
+ $ret=0
19
+ if (Test-Path "$basedir/node$exe") {
20
+ # Support pipeline input
21
+ if ($MyInvocation.ExpectingInput) {
22
+ $input | & "$basedir/node$exe" "$basedir/${target}" $args
23
+ } else {
24
+ & "$basedir/node$exe" "$basedir/${target}" $args
25
+ }
26
+ $ret=$LASTEXITCODE
27
+ } else {
28
+ # Support pipeline input
29
+ if ($MyInvocation.ExpectingInput) {
30
+ $input | & "node$exe" "$basedir/${target}" $args
31
+ } else {
32
+ & "node$exe" "$basedir/${target}" $args
33
+ }
34
+ $ret=$LASTEXITCODE
35
+ }
36
+ exit $ret
37
+ `;
38
+ }
39
+
40
+ export function inspectWindowsCommand({ platform = process.platform,
41
+ packageRoot = fileURLToPath(new URL("../", import.meta.url)), repair = false, locked = false } = {}) {
42
+ if (platform !== "win32") return { status: "not_applicable", changed: false };
43
+ const root = path.resolve(packageRoot);
44
+ if (path.basename(path.dirname(root)).toLowerCase() !== "node_modules"
45
+ || path.basename(root) !== "codex-copilot-dx") return { status: "checkout", changed: false };
46
+ try {
47
+ const pkg = JSON.parse(readBoundedFileSync(path.join(root, "package.json"), { encoding: "utf8", maxBytes: 64 * 1024 }));
48
+ if (pkg.name !== "codex-copilot-dx" || pkg.bin?.ccdx !== "bin/cli.mjs"
49
+ || pkg.bin?.["codex-copilot-dx"] !== "bin/codex-copilot-dx.mjs") throw new Error();
50
+ } catch { return { status: "preserved", changed: false }; }
51
+ if (repair && !locked) return withFileLockSync(path.join(root, ".ccdx-command.lock"),
52
+ () => inspectWindowsCommand({ platform, packageRoot, repair, locked: true }), { timeoutMs: 1000 });
53
+ const prefix = path.dirname(path.dirname(root));
54
+ const results = [];
55
+ for (const [name, script] of [["ccdx", "cli.mjs"], ["codex-copilot-dx", "codex-copilot-dx.mjs"]]) {
56
+ const ps1 = path.join(prefix, `${name}.ps1`), cmd = path.join(prefix, `${name}.cmd`);
57
+ const target = `node_modules/codex-copilot-dx/bin/${script}`;
58
+ try {
59
+ if (!fs.lstatSync(cmd).isFile() || fs.statSync(cmd).size > 8192) throw new Error();
60
+ const batch = fs.readFileSync(cmd, "utf8");
61
+ if (!batch.startsWith("@ECHO off") || !batch.includes(`"%dp0%\\${target.replaceAll("/", "\\")}" %*`)) throw new Error();
62
+ let stat;
63
+ try { stat = fs.lstatSync(ps1); } catch (error) { if (error.code !== "ENOENT") throw error; }
64
+ if (!stat) { results.push({ name, status: "ready", changed: false });continue; }
65
+ if (!stat.isFile() || stat.size > 8192 || fs.readFileSync(ps1, "utf8").replaceAll("\r\n", "\n") !== npmPowerShellShim(target)) {
66
+ results.push({ name, status: "custom_preserved", changed: false });continue;
67
+ }
68
+ if (repair) fs.unlinkSync(ps1);
69
+ results.push({ name, status: repair ? "ready" : "repairable", changed: repair });
70
+ } catch {
71
+ results.push({ name, status: "unavailable", changed: false });
72
+ }
73
+ }
74
+ return { status: results.every(item => item.status === "ready") ? "ready"
75
+ : results.some(item => item.status === "repairable") ? "repairable" : "preserved",
76
+ changed: results.some(item => item.changed), commands: results };
77
+ }
@@ -4,6 +4,7 @@ import { spawn } from "node:child_process";
4
4
  import { PassThrough, Writable } from "node:stream";
5
5
  import { Script } from "node:vm";
6
6
  import { windowsPowerShellEnvironment } from "./native-prediction-windows.mjs";
7
+ import { predictionProxyExpression } from "./prediction-pac.mjs";
7
8
 
8
9
  function failure(code) {
9
10
  return Object.assign(new Error(`Windows prediction network failed (${code}); existing company routes were preserved`), { code });
@@ -12,7 +13,7 @@ function failure(code) {
12
13
  export function companyPredictionPac(script, port) {
13
14
  if (typeof script !== "string" || Buffer.byteLength(script) > 1024 * 1024 || !Number.isInteger(port) || port < 1 || port > 65535) throw failure("proxy_pac_invalid");
14
15
  // Compile only for syntax validation; never execute a downloaded PAC in Node.
15
- const combined = `var ccdxCompanyRoute=(function(){\n${script}\n;return FindProxyForURL;})();\nfunction FindProxyForURL(url,host){var original=ccdxCompanyRoute(url,host);if(url.indexOf('https:')===0&&(host==='chatgpt.com'||host==='ab.chatgpt.com'))return 'PROXY 127.0.0.1:${port}; '+original;return original;}\n`;
16
+ const combined = `var ccdxCompanyRoute=(function(){\n${script}\n;return FindProxyForURL;})();\nfunction FindProxyForURL(url,host){var original=ccdxCompanyRoute(url,host);if(url.indexOf('https:')===0&&(host==='chatgpt.com'||host==='ab.chatgpt.com'))return ${predictionProxyExpression(port)}+'; '+original;return original;}\n`;
16
17
  try { new Script(combined); } catch { throw failure("proxy_pac_invalid"); }
17
18
  return combined;
18
19
  }