@yhong91/cpac 0.1.34 → 0.1.36

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 +21 -18
  2. package/dist/cpac.js +60 -20
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -47,9 +47,10 @@ cpac restore codex # 撤掉注入;注入期间的用户改
47
47
  cpac claude # Claude Code 走 CPA
48
48
  cpac opencode # opencode 走 CPA(模型选 cpac/<模型名>)
49
49
 
50
- # 5. 可选:Agent 配置向导与模型选择
51
- cpac setup codex # Codex 配置向导 → 注入 → 启动
52
- cpac setup claude # Claude 模型向导 → 启动
50
+ # 5. 可选:Agent 配置向导与模型选择(只写配置,不启动)
51
+ cpac setup codex # Codex 配置向导 → 注入
52
+ cpac setup claude # Claude 模型向导
53
+ cpac claude setup # 配置完再启动(agent 下的 setup 才会 launch)
53
54
 
54
55
  # 6. 升级(装上新版本后自动 sync 已接入的 agent)
55
56
  cpac upgrade
@@ -91,12 +92,13 @@ cpac status # 验证:各 target 显示 ready/injected
91
92
 
92
93
  1. **统一启动与配置**:
93
94
  - 启动:`cpac <codex|claude|kimi|grok|pi|opencode> [args...]`(所有原生参数如 `-c` 等原样透明传递)
94
- - 配置并启动:`cpac setup <codex|claude>`(向导结束后注入并拉起)
95
- - 还原:`cpac <agent> clear`(还原或重置配置)
95
+ - `setup` / `--setup`:配置 Codex/Claude,然后启动
96
+ - `clear`:还原原生配置
97
+ - 只写配置、不启动:`cpac setup [claude|codex]`;查看当前:`cpac setup`
96
98
 
97
99
  2. **已安装后升级**:npm 发布新版本后,等 publish 成功再执行 `cpac upgrade`。它会按需 `npm install -g`,再对已接入的 Codex / Pi / Kimi / Grok 做 `sync`。不要拆成 `npm install -g @yhong91/cpac` 再手动 `cpac sync`。只刷新配置、不升 CLI 时才用 `cpac sync`。
98
100
 
99
- 失败处理:任何一步报错时先跑 `cpac status`;密钥未配置回到步骤 2;注入后异常用 `cpac <agent> clear` 或 `cpac restore <id>` 恢复原配置。
101
+ 失败处理:任何一步报错时先跑 `cpac status`;密钥未配置回到步骤 2;注入后异常用 `cpac <agent> clear` 或 `cpac restore <codex|pi|kimi|grok>` 恢复原配置。
100
102
 
101
103
  ## 首次引导
102
104
 
@@ -109,10 +111,10 @@ CPA: http://124.223.178.52:8317
109
111
  CPA_API_KEY: configured / not configured
110
112
 
111
113
  Commands:
112
- cpac claude [args...] Launch Claude Code through CPA
113
- cpac setup <codex|claude> Configure then launch
114
- cpac status Show Codex injection status
115
- cpac restore <id> | --all Detach injected agents
114
+ cpac <agent> [args...] Launch an agent through CPA
115
+ cpac setup Show current Codex/Claude setup
116
+ cpac status Show agent support status
117
+ cpac restore <codex|pi|kimi|grok> | --all Detach injected agents
116
118
  cpac --help Show command usage
117
119
  ```
118
120
 
@@ -163,10 +165,10 @@ cpac --help
163
165
  参考 vibetime 的目标式命令,对 `codex`、`pi`、`kimi` 三个持久注入目标统一管理(claude/opencode 是临时接管,用 `cpac claude` / `cpac opencode` 启动,不属于 install 目标):
164
166
 
165
167
  ```bash
166
- cpac detect [--json] [--home PATH]
167
- cpac install [codex|pi|kimi|grok...] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context] [--home PATH]
168
- cpac sync [codex|pi|kimi|grok...] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context] [--home PATH]
169
- cpac restore <id...> | --all [--dry-run] [--home PATH]
168
+ cpac detect [--json]
169
+ cpac install [codex|pi|kimi|grok...] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context]
170
+ cpac sync [codex|pi|kimi|grok...] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context]
171
+ cpac restore <codex|pi|kimi|grok...> | --all [--dry-run]
170
172
  cpac uninstall [--dry-run]
171
173
  cpac upgrade [--check]
172
174
  cpac -v | --version
@@ -179,7 +181,6 @@ cpac -v | --version
179
181
  - `--v2_models` 进入 arrow-key 复选框选择最多 5 个 spawn_agent 模型(勾选顺序即推荐顺序),选择结果存入配置文件的 `spawn_models`,注入时把这些模型排到 `codex-models.json` 最前——Codex 客户端只把 catalog 前 5 个可见模型广告为 spawn 覆盖项。
180
182
  - `restore` 必须带 agent 名或 `--all`,卸掉指定(或全部)已注入目标。`--all` 时未安装的目标静默跳过。
181
183
  - `uninstall` 先用和 `cpac setup codex` 相同的方向键选择器确认(默认 Cancel),再 `restore --all`,最后 `npm uninstall -g @yhong91/cpac`。不要跟 agent 名;卸载的是 cpac 包本身。非终端取消。`--dry-run` 跳过确认。
182
- - `--home PATH` 临时把 `HOME` 指向给定目录,便于在隔离环境中试验。
183
184
  - `upgrade` 是发布后更新本机的一次性入口:查 npm → 需要时 `npm install -g` → 对**已接入**的 Codex / Pi / Kimi 执行 `sync`。已是最新也会 sync。不要先手动 `npm install -g` 再 `cpac sync`。`--check` 只报告版本,不安装也不 sync。没有已安装目标时跳过 sync,不报错。只刷新配置、不升 CLI 时用 `cpac sync`。
184
185
 
185
186
  ### Claude Code
@@ -196,7 +197,8 @@ cpac claude -- -p "检查当前项目"
196
197
  #### 配置与清除
197
198
 
198
199
  ```bash
199
- cpac setup claude # 交互式依次配置 Sonnet / Haiku / Opus,然后启动
200
+ cpac setup claude # 交互式依次配置 Sonnet / Haiku / Opus(不启动)
201
+ cpac claude setup # 同上,完成后启动
200
202
  cpac claude clear # 重置所有覆盖,恢复自动选择
201
203
  ```
202
204
 
@@ -225,14 +227,15 @@ cpac codex exec "帮我写一个测试"
225
227
  #### 配置与清除
226
228
 
227
229
  ```bash
228
- cpac setup codex # 交互式配置后注入并启动 Codex
230
+ cpac setup codex # 交互式配置后注入(不启动)
231
+ cpac codex setup # 同上,完成后启动 Codex
229
232
  cpac codex clear # 还原 Codex 原生配置并关闭代理
230
233
  ```
231
234
 
232
235
  #### 注入(`cpac install codex`)
233
236
 
234
237
  ```bash
235
- cpac install codex [--v2_off] [--v2_models] [--max_context] [--config PATH]
238
+ cpac install codex [--v2_off] [--v2_models] [--max_context]
236
239
  cpac restore codex
237
240
  ```
238
241
 
package/dist/cpac.js CHANGED
@@ -82,9 +82,9 @@ export async function status(config) {
82
82
  return 0;
83
83
  }
84
84
  async function guide(config) {
85
- 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 <agent> [args...] Launch an agent (codex, kimi, grok, pi, claude, opencode) through CPA\n cpac setup <codex|claude> Configure Codex or Claude, then launch\n cpac status Show agent support status (Codex, Claude, Pi, Kimi, Grok)\n cpac restore <id> | --all Detach injected agents
85
+ 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 <agent> [args...] Launch an agent (codex, kimi, grok, pi, claude, opencode) through CPA\n cpac setup Show current Codex/Claude setup; cpac setup <codex|claude> to change\n cpac status Show agent support status (Codex, Claude, Pi, Kimi, Grok)\n cpac restore <codex|pi|kimi|grok> | --all Detach injected agents
86
86
  cpac detect Show supported targets and install status
87
- cpac install [ids...] Install CPA into detected targets, or named agents
87
+ cpac install [codex|pi|kimi|grok...] Install CPA into detected targets, or named agents
88
88
  cpac sync Refresh installed Codex/Pi/Kimi/Grok injections from CPA
89
89
  cpac uninstall Detach all agents, then remove the cpac package (confirms first)\n cpac upgrade Update cpac from npm and sync installed agents\n cpac --help Show command usage`);
90
90
  if (process.env[config.api_key_env]?.trim())
@@ -102,25 +102,29 @@ function usage() {
102
102
  return [
103
103
  "Usage: cpac",
104
104
  " cpac <codex|kimi|grok|pi|claude|opencode> [args...]",
105
- " cpac setup <codex|claude> [options]",
106
- " cpac <codex|claude|kimi|grok|pi> clear",
107
- " cpac restore <id...> | --all [--dry-run] [--config PATH]",
108
- " cpac status [--config PATH]",
109
- " cpac detect [--json] [--home PATH]",
110
- " cpac install [codex|pi|kimi|grok...] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context] [--home PATH]",
111
- " cpac sync [codex|pi|kimi|grok...] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context] [--home PATH]",
105
+ " setup|--setup configure Codex/Claude, then launch",
106
+ " clear restore native config",
107
+ " cpac setup Show current Codex/Claude setup",
108
+ " claude [--opus [M]] [--sonnet [M]] [--haiku [M]] [--reset]",
109
+ " codex [--v2_off] [--v2_models] [--max_context]",
110
+ " cpac restore <codex|pi|kimi|grok...> | --all [--dry-run]",
111
+ " cpac status",
112
+ " cpac detect [--json]",
113
+ " cpac install [codex|pi|kimi|grok...] [--all] [--dry-run] [--force] [--v2_off] [--v2_models] [--max_context]",
114
+ " cpac sync [codex|pi|kimi|grok...] [--all] [--dry-run] [--v2_off] [--v2_models] [--max_context]",
112
115
  " cpac uninstall [--dry-run]",
113
116
  " cpac upgrade [--check]",
114
117
  " cpac -v | --version",
115
118
  "",
116
- "launch an agent directly with `cpac <agent> [args...]` (all args forwarded).",
117
- "configure then launch with `cpac setup <codex|claude>`; restore with `cpac <agent> clear`.",
119
+ "launch an agent with `cpac <agent> [args...]` (remaining args forwarded).",
120
+ "`cpac <agent> setup` configures then launches; `cpac setup [claude|codex]` writes settings only.",
118
121
  ].join("\n");
119
122
  }
120
123
  function setupUsage() {
121
124
  return [
122
- "Usage: cpac setup claude [--opus [M]] [--sonnet [M]] [--haiku [M]] [--reset] [--config PATH]",
123
- " cpac setup codex [--v2_off] [--v2_models] [--max_context] [--config PATH]",
125
+ "Usage: cpac setup Show current Codex/Claude setup",
126
+ " claude [--opus [M]] [--sonnet [M]] [--haiku [M]] [--reset]",
127
+ " codex [--v2_off] [--v2_models] [--max_context]",
124
128
  "",
125
129
  "Claude slots (saved to config, applied on every `cpac claude`):",
126
130
  " --opus heavy reasoning / planning fallback (ANTHROPIC_DEFAULT_OPUS_MODEL)",
@@ -128,9 +132,22 @@ function setupUsage() {
128
132
  " --haiku high-frequency small tasks (ANTHROPIC_DEFAULT_HAIKU_MODEL)",
129
133
  "",
130
134
  "A slot without a value opens an arrow-key picker; --reset clears overrides.",
131
- "No flags on a TTY opens the wizard, then launches.",
135
+ "No flags on a TTY opens the wizard. Does not launch; use `cpac claude setup` / `cpac codex setup` to start.",
132
136
  ].join("\n");
133
137
  }
138
+ function printSetup(config, configPath) {
139
+ const claude = config.claude_models ?? {};
140
+ const auto = (value) => typeof value === "string" && value.trim() ? value.trim() : "(auto)";
141
+ console.log(`config ${configPath}`);
142
+ console.log(`codex spawn_models ${(config.spawn_models ?? []).join(", ") || "(catalog order)"}`);
143
+ console.log(`codex max_context ${config.max_context ? "on" : "off"}`);
144
+ console.log(`codex v2 ${config.v2_off ? "off" : "on"}`);
145
+ console.log(`claude opus ${auto(claude.opus)}`);
146
+ console.log(`claude sonnet ${auto(claude.sonnet)}`);
147
+ console.log(`claude haiku ${auto(claude.haiku)}`);
148
+ console.log("");
149
+ console.log(setupUsage());
150
+ }
134
151
  function parseArgs(args) {
135
152
  if (args.length === 0) {
136
153
  return { command: "guide", configPath: defaultConfigPath() };
@@ -346,11 +363,33 @@ function parseArgs(args) {
346
363
  console.log(setupUsage());
347
364
  return null;
348
365
  }
349
- const agent = args[1];
366
+ let configPath = defaultConfigPath();
367
+ let agent;
368
+ const flags = [];
369
+ for (let index = 1; index < args.length; index++) {
370
+ const arg = args[index];
371
+ if (arg === "--config") {
372
+ const value = args[++index];
373
+ if (!value)
374
+ throw new CPACError("--config requires a path");
375
+ configPath = resolve(expandUserPath(value));
376
+ }
377
+ else if (!arg.startsWith("-") && agent === undefined) {
378
+ agent = arg;
379
+ }
380
+ else {
381
+ flags.push(arg);
382
+ }
383
+ }
384
+ if (agent === undefined) {
385
+ if (flags.length > 0)
386
+ throw new CPACError(`unknown option: ${flags[0]}`);
387
+ return { command: "setup-show", configPath };
388
+ }
350
389
  if (agent !== "claude" && agent !== "codex") {
351
390
  throw new CPACError("setup requires claude or codex");
352
391
  }
353
- let configPath = defaultConfigPath();
392
+ args = ["setup", agent, ...flags];
354
393
  if (agent === "codex") {
355
394
  let v2Off = false;
356
395
  let v2Models = false;
@@ -380,8 +419,6 @@ function parseArgs(args) {
380
419
  maxContext,
381
420
  reset: false,
382
421
  interactive: true,
383
- launch: true,
384
- args: [],
385
422
  };
386
423
  }
387
424
  const models = {};
@@ -423,7 +460,6 @@ function parseArgs(args) {
423
460
  pick,
424
461
  reset,
425
462
  interactive,
426
- launch: interactive && !reset,
427
463
  };
428
464
  }
429
465
  if (args[0] === "claude-models") {
@@ -535,10 +571,14 @@ export async function main(args = process.argv.slice(2)) {
535
571
  });
536
572
  if (parsed.command === "uninstall") {
537
573
  if (parsed.targets.length || parsed.all) {
538
- throw new CPACError("uninstall removes the cpac package; detach agents with: cpac restore <id> | --all");
574
+ throw new CPACError("uninstall removes the cpac package; detach agents with: cpac restore <codex|pi|kimi|grok> | --all");
539
575
  }
540
576
  return await runUninstall(config, { dryRun: parsed.dryRun });
541
577
  }
578
+ if (parsed.command === "setup-show") {
579
+ printSetup(config, parsed.configPath);
580
+ return 0;
581
+ }
542
582
  if (parsed.command === "upgrade")
543
583
  return await runUpgrade(config, parsed.check);
544
584
  if (parsed.command === "claude")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yhong91/cpac",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "Connect Codex and Claude Code to a remote CLIProxyAPI gateway",
5
5
  "type": "module",
6
6
  "bin": {