codex-copilot-dx 0.9.37 → 0.9.39

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.
@@ -51,10 +51,36 @@ export function normalizeUpdateSource(value) {
51
51
  return Object.hasOwn(UPDATE_SPECS, source) ? source : "";
52
52
  }
53
53
 
54
- export function globalUpdateCommand(source, { platform = process.platform, releaseTag } = {}) {
54
+ // Read only named, non-secret fields. Never inspect the complete npm config,
55
+ // rewrite .npmrc, or probe this policy on the adapter's startup/request path.
56
+ export function inspectNpmDownloadPolicy({ env = process.env, platform = process.platform, exec = execFileSync } = {}) {
57
+ const result = { version: null, allowRemote: null, registryOrigin: null, supported: null };
58
+ const query = args => {
59
+ const launch = npmLaunch(args, { platform, env });
60
+ return exec(launch.command, launch.args, { env, shell: false, stdio: ["ignore", "pipe", "pipe"],
61
+ encoding: "utf8", timeout: 3000, maxBuffer: 64 * 1024, ...launch.options }).trim();
62
+ };
63
+ try {
64
+ const version = query(["--version"]);
65
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) return result;
66
+ result.version = version;
67
+ if (Number(version.split(".")[0]) < 11) { result.supported = false;return result; }
68
+ const values = Object.fromEntries(query(["config", "get", "--global", "allow-remote", "registry"]).split(/\r?\n/)
69
+ .map(line => /^(allow-remote|registry)=(.*)$/.exec(line)).filter(Boolean).map(match => [match[1], match[2]]));
70
+ if (["all", "none", "root"].includes(values["allow-remote"])) {
71
+ result.allowRemote = values["allow-remote"];result.supported = true;
72
+ } else if (values["allow-remote"] === "undefined") result.supported = false;
73
+ try { const url = new URL(values.registry);if (["https:", "http:"].includes(url.protocol)) result.registryOrigin = url.origin; } catch {}
74
+ } catch { /* A failed readonly probe must not replace npm's own error handling. */ }
75
+ return result;
76
+ }
77
+
78
+ export function globalUpdateCommand(source, { platform = process.platform, releaseTag, allowRemote = false } = {}) {
79
+ if (typeof allowRemote !== "boolean") throw new Error("Remote download permission must be a boolean");
55
80
  const normalized = normalizeUpdateSource(source);
56
81
  if (!normalized) throw new Error(`Update source must be npm or github: ${source}`);
57
82
  const args = ["install", "--global"];
83
+ if (allowRemote) args.push("--allow-remote=all");
58
84
  if (normalized === "github") {
59
85
  if (!githubReleaseVersion(releaseTag)) throw new Error("A valid stable GitHub release tag is required");
60
86
  args.push("--allow-git=all", `${UPDATE_SPECS.github}#${releaseTag}`);
@@ -79,7 +105,7 @@ function waitForExit(child) {
79
105
  child.once("error", (error) => finish(reject, error));
80
106
  child.once("exit", (code, signal) => {
81
107
  if (signal) finish(reject, new Error(`npm update was interrupted by ${signal}`));
82
- else if (code !== 0) finish(reject, new Error(`npm update exited with status ${code}`));
108
+ else if (code !== 0) finish(reject, Object.assign(new Error(`npm update exited with status ${code}`), { npmExitCode: code }));
83
109
  else finish(resolve);
84
110
  });
85
111
  });
@@ -104,11 +130,15 @@ export async function runPackageUpdateCommand({
104
130
  platform = process.platform,
105
131
  prompt,
106
132
  source,
133
+ allowRemote = false,
107
134
  spawnImpl = spawn,
108
135
  fetchImpl = fetch,
109
136
  inspectEnvironmentFn = inspectPackageUpdateEnvironment,
137
+ inspectPolicyFn = inspectNpmDownloadPolicy,
110
138
  verifyInstalledFn = verifyInstalledPackage,
139
+ repairCommandFn,
111
140
  } = {}) {
141
+ if (typeof allowRemote !== "boolean") throw new Error("Remote download permission must be a boolean");
112
142
  let selectedSource = normalizeUpdateSource(source);
113
143
  if (source && !selectedSource) throw new Error(`Update source must be npm or github: ${source}`);
114
144
 
@@ -147,9 +177,15 @@ export async function runPackageUpdateCommand({
147
177
  output.write("Checking the latest stable GitHub release...\n");
148
178
  release = await lookupLatestRelease({ fetchImpl, timeoutMs: 10000 });
149
179
  }
150
- const update = globalUpdateCommand(selectedSource, { platform, releaseTag: release?.tagName });
180
+ const policy = inspectPolicyFn({ env, platform });
181
+ if (allowRemote && policy.supported === null) throw new Error("Could not verify npm's remote-download option; no installation was started. Check npm --version and npm config get allow-remote.");
182
+ const permitRemote = allowRemote && policy.supported === true;
183
+ const update = globalUpdateCommand(selectedSource, { platform, releaseTag: release?.tagName, allowRemote: permitRemote });
151
184
  const sourceLabel = selectedSource === "npm" ? "npm registry" : `GitHub release ${release.tagName}`;
152
185
  output.write(`Updating ${PACKAGE_NAME} from ${sourceLabel}...\n`);
186
+ if (policy.allowRemote) output.write(`npm ${terminalCell(policy.version)}: saved allow-remote=${policy.allowRemote}${policy.registryOrigin ? `; registry ${terminalCell(policy.registryOrigin)}` : ""}.\n`);
187
+ if (permitRemote) output.write("Explicit permission for this update only: npm may download URL dependencies throughout the selected package's dependency tree. Registry and persistent npm settings are unchanged.\n");
188
+ else if (allowRemote) output.write("This npm does not expose the remote-download restriction; no unsupported permission flag was added.\n");
153
189
  const environment = inspectEnvironmentFn({ env, platform });
154
190
  if (environment?.state === "different") {
155
191
  output.write(`Warning: npm targets ${terminalCell(environment.target)}, not the running package at ${terminalCell(environment.package_root)}. Existing PATH and prefix choices were preserved.\n`);
@@ -163,10 +199,23 @@ export async function runPackageUpdateCommand({
163
199
  stdio: "inherit",
164
200
  ...launch.options,
165
201
  });
166
- await waitForExit(child);
202
+ try { await waitForExit(child); }
203
+ catch (error) {
204
+ if (Number.isInteger(error.npmExitCode) && !allowRemote && ["none", "root"].includes(policy.allowRemote)) {
205
+ error.message += `. npm allow-remote=${policy.allowRemote} was preserved. If npm reported EALLOWREMOTE, its registry/mirror tarball URL was refused; only if you trust this update and policy permits it, retry explicitly with ${terminalCell(commandName)} update ${selectedSource} --allow-remote. This grants URL downloads to this installation's dependency tree, not just one hostname. No automatic retry or config change was made.`;
206
+ }
207
+ throw error;
208
+ }
167
209
  const installedVersion = verifyInstalledFn(environment?.target, { expectedVersion: release?.version });
168
210
  if (installedVersion) {
169
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
+ }
170
219
  } else {
171
220
  output.write("Installer finished; the global target was unavailable, so the installed version was not verified. Run ccdx doctor.\n");
172
221
  }
@@ -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
+ }