@yhong91/cpac 0.1.36 → 0.1.37
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/README.md +4 -13
- package/dist/cpac.js +3 -9
- package/package.json +1 -1
- package/dist/targets/opencode.js +0 -59
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ CPAC 将 Codex 和 Claude Code 接入远端 CLIProxyAPI(CPA):
|
|
|
10
10
|
## 要求
|
|
11
11
|
|
|
12
12
|
- [Node.js](https://nodejs.org/) 20 或更新版本(npm 随 Node 安装)
|
|
13
|
-
- 已安装需要使用的 agent:`codex`、`claude`、`pi`、`kimi` 或 `
|
|
13
|
+
- 已安装需要使用的 agent:`codex`、`claude`、`pi`、`kimi` 或 `grok`
|
|
14
14
|
- 有权访问的 CPA API key
|
|
15
15
|
|
|
16
16
|
## 安装
|
|
@@ -45,7 +45,6 @@ cpac restore codex # 撤掉注入;注入期间的用户改
|
|
|
45
45
|
|
|
46
46
|
# 4b. 临时接管(退出无痕,不写任何配置文件)
|
|
47
47
|
cpac claude # Claude Code 走 CPA
|
|
48
|
-
cpac opencode # opencode 走 CPA(模型选 cpac/<模型名>)
|
|
49
48
|
|
|
50
49
|
# 5. 可选:Agent 配置向导与模型选择(只写配置,不启动)
|
|
51
50
|
cpac setup codex # Codex 配置向导 → 注入
|
|
@@ -62,7 +61,7 @@ cpac upgrade
|
|
|
62
61
|
|
|
63
62
|
本节面向 AI agent:按顺序执行即可完成安装与配置,**全程无交互**。注意:`cpac codex --config` 和 `cpac claude --config` 的交互向导是 TTY-only,agent 必须走下方直接写配置 JSON 的路径。
|
|
64
63
|
|
|
65
|
-
1. **检查前置**:`node --version` ≥ 20;确认用户需要哪些 agent(`codex`/`claude`/`pi`/`kimi`/`
|
|
64
|
+
1. **检查前置**:`node --version` ≥ 20;确认用户需要哪些 agent(`codex`/`claude`/`pi`/`kimi`/`grok` 在 PATH 上)。向用户索取 CPA API key。
|
|
66
65
|
|
|
67
66
|
2. **安装与密钥**:
|
|
68
67
|
|
|
@@ -91,7 +90,7 @@ cpac status # 验证:各 target 显示 ready/injected
|
|
|
91
90
|
```
|
|
92
91
|
|
|
93
92
|
1. **统一启动与配置**:
|
|
94
|
-
- 启动:`cpac <codex|claude|kimi|grok|pi
|
|
93
|
+
- 启动:`cpac <codex|claude|kimi|grok|pi> [args...]`(所有原生参数如 `-c` 等原样透明传递)
|
|
95
94
|
- `setup` / `--setup`:配置 Codex/Claude,然后启动
|
|
96
95
|
- `clear`:还原原生配置
|
|
97
96
|
- 只写配置、不启动:`cpac setup [claude|codex]`;查看当前:`cpac setup`
|
|
@@ -162,7 +161,7 @@ cpac --help
|
|
|
162
161
|
|
|
163
162
|
### 统一管理(detect / install / sync / restore / uninstall / upgrade)
|
|
164
163
|
|
|
165
|
-
参考 vibetime 的目标式命令,对 `codex`、`pi`、`kimi`
|
|
164
|
+
参考 vibetime 的目标式命令,对 `codex`、`pi`、`kimi`、`grok` 四个持久注入目标统一管理(claude 是临时接管,用 `cpac claude` 启动,不属于 install 目标):
|
|
166
165
|
|
|
167
166
|
```bash
|
|
168
167
|
cpac detect [--json]
|
|
@@ -269,14 +268,6 @@ restore / `<agent> clear` 会删掉该 agent 的备份目录和 state.json 里
|
|
|
269
268
|
|
|
270
269
|
为防止误删或覆盖,`state_dir` 不能是文件系统根目录、用户 home、系统临时目录,也不能包含 Codex 配置文件。
|
|
271
270
|
|
|
272
|
-
### OpenCode(临时接管)
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
cpac opencode [--] [opencode args...]
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
通过 `OPENCODE_CONFIG_CONTENT` 内联注入一个 `cpac` OpenAI 兼容 provider(baseURL 直指 CPA,模型列表来自 CPA 目录),不触碰任何 opencode 配置文件,退出即无痕。首次使用时 opencode 会自行安装 `@ai-sdk/openai-compatible` 适配器。模型选择用 `cpac/<模型名>`。
|
|
279
|
-
|
|
280
271
|
### Pi
|
|
281
272
|
|
|
282
273
|
安装 CPA provider 扩展到 Pi:
|
package/dist/cpac.js
CHANGED
|
@@ -8,7 +8,6 @@ import { runClaude, runClaudeConfig } from "./targets/claude.js";
|
|
|
8
8
|
import { multiAgentV2Enabled } from "./targets/codex.js";
|
|
9
9
|
import { isGrokConfigInstalled } from "./targets/grok.js";
|
|
10
10
|
import { isKimiConfigInstalled } from "./targets/kimi.js";
|
|
11
|
-
import { runOpencode } from "./targets/opencode.js";
|
|
12
11
|
import { isPiExtensionInstalled } from "./targets/pi.js";
|
|
13
12
|
import { defaultConfigPath, loadConfig, originalBytes, pickSpawnModels, readState, saveSpawnModels, stateProxy, catalogMaxContextLive, } from "./config.js";
|
|
14
13
|
import { proxyIsHealthy, runProxyChild } from "./proxy.js";
|
|
@@ -21,7 +20,6 @@ export { claudeTierSlots, createClaudeProxy, runClaude, } from "./targets/claude
|
|
|
21
20
|
export { detectClientVersion, detectTargets, runInstall, runRestore, runSync, runTargetLauncher, } from "./agents.js";
|
|
22
21
|
export { installGrokConfig, isGrokConfigInstalled, uninstallGrokConfig, } from "./targets/grok.js";
|
|
23
22
|
export { installKimiConfig, isKimiConfigInstalled, uninstallKimiConfig, } from "./targets/kimi.js";
|
|
24
|
-
export { runOpencode } from "./targets/opencode.js";
|
|
25
23
|
export { installPiExtension, isPiExtensionInstalled, uninstallPiExtension, } from "./targets/pi.js";
|
|
26
24
|
export async function status(config) {
|
|
27
25
|
const apiKey = process.env[config.api_key_env]?.trim();
|
|
@@ -82,7 +80,7 @@ export async function status(config) {
|
|
|
82
80
|
return 0;
|
|
83
81
|
}
|
|
84
82
|
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
|
|
83
|
+
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) 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
84
|
cpac detect Show supported targets and install status
|
|
87
85
|
cpac install [codex|pi|kimi|grok...] Install CPA into detected targets, or named agents
|
|
88
86
|
cpac sync Refresh installed Codex/Pi/Kimi/Grok injections from CPA
|
|
@@ -96,12 +94,10 @@ async function guide(config) {
|
|
|
96
94
|
console.log(`\nSaved ${config.api_key_env} to ${profile}. Open a new terminal or run:\n source ${profile}`);
|
|
97
95
|
return 0;
|
|
98
96
|
}
|
|
99
|
-
// opencode's config schema rejects a limit block with context but no output;
|
|
100
|
-
// the catalog has no output field, so a safe budget stands in, clamped to the
|
|
101
97
|
function usage() {
|
|
102
98
|
return [
|
|
103
99
|
"Usage: cpac",
|
|
104
|
-
" cpac <codex|kimi|grok|pi|claude
|
|
100
|
+
" cpac <codex|kimi|grok|pi|claude> [args...]",
|
|
105
101
|
" setup|--setup configure Codex/Claude, then launch",
|
|
106
102
|
" clear restore native config",
|
|
107
103
|
" cpac setup Show current Codex/Claude setup",
|
|
@@ -225,7 +221,7 @@ function parseArgs(args) {
|
|
|
225
221
|
}
|
|
226
222
|
return parsed;
|
|
227
223
|
}
|
|
228
|
-
if (["codex", "kimi", "grok", "pi", "claude"
|
|
224
|
+
if (["codex", "kimi", "grok", "pi", "claude"].includes(args[0])) {
|
|
229
225
|
const targetId = args[0];
|
|
230
226
|
let configPath = defaultConfigPath();
|
|
231
227
|
const raw = args.slice(1);
|
|
@@ -610,8 +606,6 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
610
606
|
return code;
|
|
611
607
|
return await runTargetLauncher(loadConfig(parsed.configPath, true), "codex", parsed.args ?? [], "codex", { skipSync: true });
|
|
612
608
|
}
|
|
613
|
-
if (parsed.command === "opencode")
|
|
614
|
-
return await runOpencode(config, parsed.args);
|
|
615
609
|
if (parsed.command === "codex") {
|
|
616
610
|
let launcherConfig = config;
|
|
617
611
|
if (parsed.v2Models) {
|
package/package.json
CHANGED
package/dist/targets/opencode.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { apiBase, catalogModelId, fetchCatalog, } from "../config.js";
|
|
3
|
-
import { CPACError } from "../util.js";
|
|
4
|
-
const OPENCODE_OUTPUT_BUDGET = 32_000;
|
|
5
|
-
// Ephemeral takeover: inline a CPA provider via OPENCODE_CONFIG_CONTENT so no
|
|
6
|
-
// opencode config file is touched; the session ends with zero residue.
|
|
7
|
-
export async function runOpencode(config, args, executable = "opencode") {
|
|
8
|
-
const apiKey = process.env[config.api_key_env]?.trim();
|
|
9
|
-
if (!apiKey)
|
|
10
|
-
throw new CPACError(`environment variable ${config.api_key_env} is not set`);
|
|
11
|
-
const catalog = await fetchCatalog(config.cpa_url, apiKey);
|
|
12
|
-
let document;
|
|
13
|
-
try {
|
|
14
|
-
document = JSON.parse(new TextDecoder().decode(catalog.bytes));
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
throw new CPACError("invalid CPA catalog");
|
|
18
|
-
}
|
|
19
|
-
const models = {};
|
|
20
|
-
for (const row of document.models) {
|
|
21
|
-
const id = catalogModelId(row);
|
|
22
|
-
if (!id)
|
|
23
|
-
continue;
|
|
24
|
-
const window = typeof row.context_window === "number" && row.context_window > 0
|
|
25
|
-
? Math.floor(row.context_window)
|
|
26
|
-
: 0;
|
|
27
|
-
models[id] =
|
|
28
|
-
window > 0
|
|
29
|
-
? {
|
|
30
|
-
limit: {
|
|
31
|
-
context: window,
|
|
32
|
-
output: Math.min(OPENCODE_OUTPUT_BUDGET, window),
|
|
33
|
-
},
|
|
34
|
-
}
|
|
35
|
-
: {};
|
|
36
|
-
}
|
|
37
|
-
const content = JSON.stringify({
|
|
38
|
-
provider: {
|
|
39
|
-
cpac: {
|
|
40
|
-
npm: "@ai-sdk/openai-compatible",
|
|
41
|
-
options: { baseURL: apiBase(config.cpa_url), apiKey },
|
|
42
|
-
models,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
const env = {
|
|
47
|
-
...process.env,
|
|
48
|
-
OPENCODE_CONFIG_CONTENT: content,
|
|
49
|
-
};
|
|
50
|
-
return await new Promise((resolve, reject) => {
|
|
51
|
-
const child = spawn(executable, args, { env, stdio: "inherit" });
|
|
52
|
-
child.once("error", (error) => {
|
|
53
|
-
reject(new CPACError(error instanceof Error && "code" in error && error.code === "ENOENT"
|
|
54
|
-
? `${executable} not found`
|
|
55
|
-
: `cannot start ${executable}: ${error.message}`));
|
|
56
|
-
});
|
|
57
|
-
child.once("close", (code) => resolve(code ?? 1));
|
|
58
|
-
});
|
|
59
|
-
}
|