@yhong91/cpac 0.1.20 → 0.1.22

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.
Files changed (3) hide show
  1. package/README.md +10 -9
  2. package/dist/cpac.js +65 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,9 +51,8 @@ cpac opencode # opencode 走 CPA(模型选 cpac/<模
51
51
  cpac claude-models # 查看当前覆盖
52
52
  cpac claude-models --haiku # 下拉选择 haiku 槽模型
53
53
 
54
- # 6. 升级
55
- cpac upgrade --check
56
- npm install -g @yhong91/cpac@latest
54
+ # 6. 升级(装上新版本后自动 sync 已接入的 agent)
55
+ cpac upgrade
57
56
  ```
58
57
 
59
58
  各命令的完整参数与行为见下方对应章节。
@@ -101,7 +100,7 @@ cpac status # 验证:各 target 显示 ready/injected
101
100
  ```text
102
101
  CPA Companion
103
102
 
104
- CPA: http://cpa.vibetime.cc:8317
103
+ CPA: http://124.223.178.52:8317
105
104
  CPA_API_KEY: configured / not configured
106
105
 
107
106
  Commands:
@@ -112,7 +111,7 @@ Commands:
112
111
  cpac --help Show command usage
113
112
  ```
114
113
 
115
- 默认 CPA 地址内置为 `http://cpa.vibetime.cc:8317`,不需要创建 `~/.config/cpac/`。
114
+ 默认 CPA 地址内置为 `http://124.223.178.52:8317`,不需要创建 `~/.config/cpac/`。
116
115
 
117
116
  若 `CPA_API_KEY` 尚未设置,交互式引导会隐藏输入密钥,并将受 CPAC 标记管理的 export 区块写入当前 shell 的启动文件:
118
117
 
@@ -154,13 +153,14 @@ cpac
154
153
  cpac --help
155
154
  ```
156
155
 
157
- ### 统一管理(detect / install / uninstall / upgrade)
156
+ ### 统一管理(detect / install / sync / uninstall / upgrade)
158
157
 
159
158
  参考 vibetime 的目标式命令,对 `codex`、`pi`、`kimi` 三个持久注入目标统一管理(claude/opencode 是临时接管,用 `cpac claude` / `cpac opencode` 启动,不属于 install 目标):
160
159
 
161
160
  ```bash
162
161
  cpac detect [--json] [--home PATH]
163
162
  cpac install [--target codex,pi,kimi] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context] [--home PATH]
163
+ cpac sync [--target codex,pi,kimi] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context] [--home PATH]
164
164
  cpac uninstall [--target codex,pi,kimi] [--all] [--dry-run] [--home PATH]
165
165
  cpac upgrade [--check]
166
166
  cpac version
@@ -168,11 +168,12 @@ cpac version
168
168
 
169
169
  - `detect` 列出每个目标是否被检测到、是否已接入 CPAC;`--json` 输出机器可读结果。
170
170
  - `install` 默认作用于检测到的目标;`--target` 指定目标、`--all` 全部。各目标映射到既有逻辑:`codex` → `cpac inject`,`pi` → `cpac pi install`,`kimi` → `cpac kimi install`。`--dry-run` 只打印将要做的事,`--force` 允许重装已安装目标。
171
+ - `sync` 按当前 `cpa_url` 和 CPA 目录强制刷新**已经接入**的目标(Codex 重新注入、Pi 扩展重写、Kimi 配置重写),用来在 CPA 地址或模型目录变化后一次对齐本地配置。不带参数只动已安装目标;`--all` 会对检测到的目标做同样的强制刷新(尚未安装的会装上)。`--max_context` 仍只对 `--target codex` 有效。
171
172
  - Codex 注入默认开启 multi-agent v2(写入 `[features.multi_agent_v2] enabled = true`);`install --target codex --v2_off` 写入 `enabled = false`。服务端还需在 CPA 配置中开启 `codex.optimize-multi-agent-v2`。
172
173
  - `--v2_models` 进入 arrow-key 复选框选择最多 5 个 spawn_agent 模型(勾选顺序即推荐顺序),选择结果存入配置文件的 `spawn_models`,注入时把这些模型排到 `codex-models.json` 最前——Codex 客户端只把 catalog 前 5 个可见模型广告为 spawn 覆盖项。
173
174
  - `uninstall` 默认作用于已安装目标,映射到 `cpac restore` / `cpac pi uninstall` / `cpac kimi uninstall`。
174
175
  - `--home PATH` 临时把 `HOME` 指向给定目录,便于在隔离环境中试验。
175
- - `upgrade` 检查 npm 上是否有新版本,`--check` 只报告不提示安装命令。
176
+ - `upgrade` 检查 npm 上是否有新版本;默认会 `npm install -g` 装上最新包,再对**已接入**的 Codex / Pi / Kimi 执行 `sync`。`--check` 只报告版本,不安装也不 sync。没有已安装目标时跳过 sync,不报错。只刷新配置、不升 CLI 时用 `cpac sync`。
176
177
 
177
178
  ### Claude Code
178
179
 
@@ -330,7 +331,7 @@ Kimi Code 配置目录尊重 `KIMI_CODE_HOME` 环境变量。首次写入前若
330
331
  | 变量 | 默认值 | 作用 |
331
332
  | --- | --- | --- |
332
333
  | `CPA_API_KEY` | 无 | CPA Bearer key;可由 `cpac` 首次引导写入 shell 启动文件 |
333
- | `CPA_BASE_URL` | `http://cpa.vibetime.cc:8317` | 覆盖内置 CPA 地址 |
334
+ | `CPA_BASE_URL` | `http://124.223.178.52:8317` | 覆盖内置 CPA 地址 |
334
335
  | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | 覆盖 Pi agent 目录(影响 `cpac pi install` 写入位置) |
335
336
  | `KIMI_CODE_HOME` | `~/.kimi-code` | 覆盖 Kimi Code 目录(影响 `cpac kimi install` 写入位置) |
336
337
  | `CPAC_CONFIG` | `~/.config/cpac/config.json` | 指定可选 JSON 配置路径 |
@@ -342,7 +343,7 @@ CPAC CLI 可临时覆盖 CPA 地址:
342
343
  CPA_BASE_URL='https://cpa.example.com' cpac claude
343
344
  ```
344
345
 
345
- `pi-cpa.ts` 插件不读取此变量,固定连接远程 `http://cpa.vibetime.cc:8317`,并且只从 Pi 进程环境读取 `CPA_API_KEY`;不读取用户 home 中的私有文件。
346
+ `pi-cpa.ts` 插件不读取此变量,固定连接远程 `http://124.223.178.52:8317`,并且只从 Pi 进程环境读取 `CPA_API_KEY`;不读取用户 home 中的私有文件。
346
347
 
347
348
  ## 可选 JSON 配置
348
349
 
package/dist/cpac.js CHANGED
@@ -10,7 +10,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
10
10
  import { createInterface } from "node:readline/promises";
11
11
  import { Writable } from "node:stream";
12
12
  export const PROVIDER = "cpac_cpa";
13
- const DEFAULT_CPA_URL = "http://cpa.vibetime.cc:8317";
13
+ const DEFAULT_CPA_URL = "http://124.223.178.52:8317";
14
14
  const DEFAULT_CODEX_PROXY_PORT = 10101;
15
15
  const MAX_CATALOG_BYTES = 16 * 1024 * 1024;
16
16
  const CONFIG_KEYS = new Set([
@@ -1463,7 +1463,7 @@ export function saveApiKeyExport(profile, name, apiKey) {
1463
1463
  atomicWrite(profile, Buffer.from(content), mode);
1464
1464
  }
1465
1465
  async function guide(config) {
1466
- console.log(`CPA Companion\n\nCPA: ${config.cpa_url}\nCPA_API_KEY: ${process.env[config.api_key_env]?.trim() ? "configured" : "not configured"}\n\nCommands:\n cpac claude [args...] Launch Claude Code through CPA\n cpac inject Inject CPA into Codex and start its loopback proxy\n cpac proxy Run the injected loopback proxy in the foreground\n cpac status Show agent support status (Codex, Claude, Pi, Kimi)\n cpac restore Restore the original Codex config\n cpac pi install Install CPA provider extension for Pi\n cpac pi uninstall Remove the Pi CPA provider extension\n cpac pi status Show Pi extension install status\n cpac kimi install Write CPA provider config for Kimi Code\n cpac kimi uninstall Remove the Kimi Code CPA provider config\n cpac kimi status Show Kimi Code config install status\n cpac detect Show supported targets and install status\n cpac install Install CPA integration into detected targets\n cpac uninstall Remove CPA integration from installed targets\n cpac upgrade Check for cpac updates on npm\n cpac --help Show command usage`);
1466
+ console.log(`CPA Companion\n\nCPA: ${config.cpa_url}\nCPA_API_KEY: ${process.env[config.api_key_env]?.trim() ? "configured" : "not configured"}\n\nCommands:\n cpac claude [args...] Launch Claude Code through CPA\n cpac inject Inject CPA into Codex and start its loopback proxy\n cpac proxy Run the injected loopback proxy in the foreground\n cpac status Show agent support status (Codex, Claude, Pi, Kimi)\n cpac restore Restore the original Codex config\n cpac pi install Install CPA provider extension for Pi\n cpac pi uninstall Remove the Pi CPA provider extension\n cpac pi status Show Pi extension install status\n cpac kimi install Write CPA provider config for Kimi Code\n cpac kimi uninstall Remove the Kimi Code CPA provider config\n cpac kimi status Show Kimi Code config install status\n cpac detect Show supported targets and install status\n cpac install Install CPA integration into detected targets\n cpac sync Refresh installed Codex/Pi/Kimi injections from the current CPA\n cpac uninstall Remove CPA integration from installed targets\n cpac upgrade Update cpac from npm and sync installed agents\n cpac --help Show command usage`);
1467
1467
  if (process.env[config.api_key_env]?.trim())
1468
1468
  return 0;
1469
1469
  const apiKey = await promptSecret(config.api_key_env);
@@ -2050,6 +2050,28 @@ export async function runInstall(config, requested, options) {
2050
2050
  }
2051
2051
  return 0;
2052
2052
  }
2053
+ export async function runSync(config, requested, options) {
2054
+ const installed = TARGETS.filter((target) => target.installed(config)).map((target) => target.id);
2055
+ if (requested.length === 0 && !options.all) {
2056
+ if (installed.length === 0) {
2057
+ throw new CPACError("no installed CPAC integrations found; run cpac install first");
2058
+ }
2059
+ return runInstall(config, installed, {
2060
+ all: false,
2061
+ dryRun: options.dryRun,
2062
+ force: true,
2063
+ v2Off: options.v2Off,
2064
+ maxContext: options.maxContext,
2065
+ });
2066
+ }
2067
+ return runInstall(config, requested, {
2068
+ all: options.all,
2069
+ dryRun: options.dryRun,
2070
+ force: true,
2071
+ v2Off: options.v2Off,
2072
+ maxContext: options.maxContext,
2073
+ });
2074
+ }
2053
2075
  export async function runUninstall(config, requested, options) {
2054
2076
  const eligible = TARGETS.filter((target) => target.installed(config)).map((target) => target.id);
2055
2077
  const selected = selectTargets(requested, options.all, eligible);
@@ -2076,7 +2098,7 @@ function compareVersions(a, b) {
2076
2098
  }
2077
2099
  return 0;
2078
2100
  }
2079
- export async function runUpgrade(checkOnly) {
2101
+ export async function runUpgrade(config, checkOnly) {
2080
2102
  console.log(`Current version: ${CPAC_VERSION}`);
2081
2103
  let latest;
2082
2104
  try {
@@ -2098,16 +2120,32 @@ export async function runUpgrade(checkOnly) {
2098
2120
  return 1;
2099
2121
  }
2100
2122
  console.log(`Latest version: ${latest}`);
2101
- if (compareVersions(CPAC_VERSION, latest) >= 0) {
2102
- console.log("Already up to date.");
2123
+ const upToDate = compareVersions(CPAC_VERSION, latest) >= 0;
2124
+ if (checkOnly) {
2125
+ if (upToDate)
2126
+ console.log("Already up to date.");
2127
+ else
2128
+ console.log("Update available. Run: cpac upgrade");
2103
2129
  return 0;
2104
2130
  }
2105
- if (checkOnly) {
2106
- console.log(`Update available. Run: npm install -g @yhong91/cpac@latest`);
2131
+ if (!upToDate) {
2132
+ console.log(`Installing @yhong91/cpac@${latest}`);
2133
+ const result = spawnSync("npm", ["install", "-g", `@yhong91/cpac@${latest}`], { stdio: "inherit" });
2134
+ if (result.status !== 0) {
2135
+ console.error("npm install failed");
2136
+ return result.status ?? 1;
2137
+ }
2138
+ }
2139
+ else {
2140
+ console.log("Already up to date.");
2141
+ }
2142
+ const installed = TARGETS.filter((target) => target.installed(config)).map((target) => target.id);
2143
+ if (installed.length === 0) {
2144
+ console.log("No installed agents to sync.");
2107
2145
  return 0;
2108
2146
  }
2109
- console.log(`Update available. Run: npm install -g @yhong91/cpac@latest`);
2110
- return 0;
2147
+ console.log(`Syncing ${installed.join(", ")}`);
2148
+ return runSync(config, [], { all: false, dryRun: false });
2111
2149
  }
2112
2150
  function usage() {
2113
2151
  return [
@@ -2122,6 +2160,7 @@ function usage() {
2122
2160
  " cpac kimi <install|uninstall|status> [--config PATH]",
2123
2161
  " cpac detect [--json] [--home PATH]",
2124
2162
  " cpac install [--target codex,pi,kimi] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context] [--home PATH]",
2163
+ " cpac sync [--target codex,pi,kimi] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context] [--home PATH]",
2125
2164
  " cpac uninstall [--target codex,pi,kimi] [--all] [--dry-run] [--home PATH]",
2126
2165
  " cpac upgrade [--check]",
2127
2166
  " cpac version",
@@ -2136,6 +2175,7 @@ function parseArgs(args) {
2136
2175
  }
2137
2176
  if (args[0] === "detect" ||
2138
2177
  args[0] === "install" ||
2178
+ args[0] === "sync" ||
2139
2179
  args[0] === "uninstall" ||
2140
2180
  args[0] === "upgrade" ||
2141
2181
  args[0] === "version") {
@@ -2377,13 +2417,28 @@ export async function main(args = process.argv.slice(2)) {
2377
2417
  maxContext: parsed.maxContext,
2378
2418
  });
2379
2419
  }
2420
+ if (parsed.command === "sync") {
2421
+ let syncConfig = config;
2422
+ if (parsed.v2Models) {
2423
+ const picked = await pickSpawnModels(config);
2424
+ saveSpawnModels(parsed.configPath, picked);
2425
+ console.log(`spawn_models saved to ${parsed.configPath}: ${picked.join(", ")}`);
2426
+ syncConfig = { ...config, spawn_models: picked };
2427
+ }
2428
+ return await runSync(syncConfig, parsed.targets, {
2429
+ all: parsed.all,
2430
+ dryRun: parsed.dryRun,
2431
+ v2Off: parsed.v2Off,
2432
+ maxContext: parsed.maxContext,
2433
+ });
2434
+ }
2380
2435
  if (parsed.command === "uninstall")
2381
2436
  return await runUninstall(config, parsed.targets, {
2382
2437
  all: parsed.all,
2383
2438
  dryRun: parsed.dryRun,
2384
2439
  });
2385
2440
  if (parsed.command === "upgrade")
2386
- return await runUpgrade(parsed.check);
2441
+ return await runUpgrade(config, parsed.check);
2387
2442
  if (parsed.command === "version") {
2388
2443
  console.log(CPAC_VERSION);
2389
2444
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yhong91/cpac",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Connect Codex and Claude Code to a remote CLIProxyAPI gateway",
5
5
  "type": "module",
6
6
  "bin": {