@yhong91/cpac 0.1.46 → 0.1.47

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/dist/agents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { spawn, spawnSync } from "node:child_process";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
- import { dirname, join } from "node:path";
4
+ import { basename, dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { MAX_SPAWN_MODELS, loadCatalogSlugs, pickSpawnModels, saveCodexSetup, saveSpawnModels, } from "./config.js";
7
7
  import { MANAGED_MARKER, inject, restore } from "./targets/codex.js";
@@ -450,6 +450,19 @@ export async function runUninstall(config, options) {
450
450
  }
451
451
  return 0;
452
452
  }
453
+ function runningNpmPrefix() {
454
+ const dist = dirname(fileURLToPath(import.meta.url));
455
+ const pkg = dirname(dist);
456
+ const scoped = dirname(pkg);
457
+ const modules = dirname(scoped);
458
+ if (basename(pkg) !== "cpac" ||
459
+ basename(scoped) !== "@yhong91" ||
460
+ basename(modules) !== "node_modules") {
461
+ return undefined;
462
+ }
463
+ const parent = dirname(modules);
464
+ return basename(parent) === "lib" ? dirname(parent) : parent;
465
+ }
453
466
  export async function runUpgrade(config, checkOnly) {
454
467
  console.log(`Current version: ${CPAC_VERSION}`);
455
468
  let latest;
@@ -485,7 +498,11 @@ export async function runUpgrade(config, checkOnly) {
485
498
  }
486
499
  else {
487
500
  console.log(`Installing @yhong91/cpac@${latest}`);
488
- const result = spawnSync("npm", ["install", "-g", `@yhong91/cpac@${latest}`], { stdio: "inherit" });
501
+ const prefix = runningNpmPrefix();
502
+ const args = ["install", "-g", `@yhong91/cpac@${latest}`];
503
+ if (prefix)
504
+ args.splice(2, 0, `--prefix=${prefix}`);
505
+ const result = spawnSync("npm", args, { stdio: "inherit" });
489
506
  if (result.status !== 0) {
490
507
  console.error("npm install failed");
491
508
  return result.status ?? 1;
@@ -498,7 +515,7 @@ export async function runUpgrade(config, checkOnly) {
498
515
  }
499
516
  console.log(`Syncing ${installed.join(", ")}`);
500
517
  if (!upToDate) {
501
- const cli = fileURLToPath(new URL("./cpac.js", import.meta.url));
518
+ const cli = join(dirname(fileURLToPath(import.meta.url)), "cpac.js");
502
519
  const result = spawnSync(process.execPath, [cli, "sync"], {
503
520
  stdio: "inherit",
504
521
  });
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, } from "node:fs";
2
2
  import { homedir } from "node:os";
3
- import { dirname, join } from "node:path";
3
+ import { basename, dirname, join } from "node:path";
4
4
  import { catalogModelId, catalogModelRows, dropAgent, fetchCatalog, readState, recordWrittenConfig, restoreOwnedConfig, } from "../config.js";
5
5
  import { ensureLoopbackProxy, stopProxyProcess } from "../proxy.js";
6
6
  import { CPACError, atomicWrite, ensureCpacBackup, expandUserPath, resolveApiKey, } from "../util.js";
@@ -15,23 +15,38 @@ export function hermesHome() {
15
15
  }
16
16
  return join(homedir(), ".hermes");
17
17
  }
18
+ export function hermesRoot() {
19
+ const home = hermesHome();
20
+ const parent = dirname(home);
21
+ if (basename(parent) === "profiles")
22
+ return dirname(parent);
23
+ return home;
24
+ }
18
25
  export function hermesConfigPath() {
19
- return join(hermesHome(), "config.yaml");
26
+ return join(hermesRoot(), "config.yaml");
20
27
  }
21
28
  export function hermesConfigPaths() {
22
- const home = hermesHome();
23
- const paths = [hermesConfigPath()];
24
- let entries;
29
+ const root = hermesRoot();
30
+ const paths = [join(root, "config.yaml")];
31
+ let names;
25
32
  try {
26
- entries = readdirSync(join(home, "profiles"), { withFileTypes: true });
33
+ names = readdirSync(join(root, "profiles"));
27
34
  }
28
35
  catch {
29
36
  return paths;
30
37
  }
31
- for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
32
- if (!entry.isDirectory() || entry.name.startsWith("."))
38
+ for (const name of names.sort()) {
39
+ if (name.startsWith(".") || name === "default")
33
40
  continue;
34
- paths.push(join(home, "profiles", entry.name, "config.yaml"));
41
+ const dir = join(root, "profiles", name);
42
+ try {
43
+ if (!statSync(dir).isDirectory())
44
+ continue;
45
+ }
46
+ catch {
47
+ continue;
48
+ }
49
+ paths.push(join(dir, "config.yaml"));
35
50
  }
36
51
  return paths;
37
52
  }
@@ -261,7 +276,9 @@ export async function installHermesConfig(config) {
261
276
  await stopProxyProcess(proxy);
262
277
  throw error;
263
278
  }
264
- console.log(`Installed Hermes provider "${HERMES_PROVIDER_ID}": ${targets.join(", ")}`);
279
+ console.log(`Installed Hermes provider "${HERMES_PROVIDER_ID}":`);
280
+ for (const target of targets)
281
+ console.log(` ${target}`);
265
282
  }
266
283
  export async function uninstallHermesConfig(config) {
267
284
  const targets = hermesConfigPaths();
@@ -276,5 +293,7 @@ export async function uninstallHermesConfig(config) {
276
293
  const { stopProxy } = dropAgent(config.state_dir, "hermes");
277
294
  if (stopProxy)
278
295
  await stopProxyProcess(stopProxy);
279
- console.log(`Removed Hermes provider "${HERMES_PROVIDER_ID}": ${targets.join(", ")}`);
296
+ console.log(`Removed Hermes provider "${HERMES_PROVIDER_ID}":`);
297
+ for (const target of targets)
298
+ console.log(` ${target}`);
280
299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yhong91/cpac",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "description": "Connect Codex and Claude Code to a remote CLIProxyAPI gateway",
5
5
  "type": "module",
6
6
  "bin": {