@tscgoods/codex-effort-discovery 0.5.0 → 0.5.2
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/.codex-plugin/plugin.json +3 -3
- package/README.md +35 -9
- package/commands/efforts.md +2 -2
- package/package.json +2 -2
- package/scripts/guard.mjs +151 -0
- package/scripts/lib.mjs +55 -5
- package/scripts/probe.mjs +10 -4
- package/scripts/sync-catalog.mjs +7 -18
- package/skills/effort-probe/SKILL.md +16 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effort-discovery",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "Inspect gateway reasoning-effort evidence and prepare a Codex model catalog.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tscgoods"
|
|
7
7
|
},
|
|
@@ -27,4 +27,4 @@
|
|
|
27
27
|
"Probe my gateway for the effort levels each model accepts"
|
|
28
28
|
]
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tscgoods/codex-effort-discovery
|
|
2
2
|
|
|
3
|
-
Codex CLI
|
|
3
|
+
Codex CLI 插件:根据网关错误回显或原生 catalog,生成/更新一份 **model catalog**。需自行确认探针与 Codex 使用同一路由和协议。
|
|
4
4
|
|
|
5
5
|
## 为什么需要
|
|
6
6
|
|
|
@@ -34,20 +34,46 @@ node scripts/sync-catalog.mjs --write
|
|
|
34
34
|
# model_catalog_json = 'C:\Users\<you>\.codex\model-catalogs\efforts.json'
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
插件提供 `effort-probe` 技能;`commands/efforts.md` 是兼容性参考文件,当前 Codex 插件文档没有将其列为支持的插件组件,不能保证 `/efforts` 可用。
|
|
38
|
+
|
|
39
|
+
## 防覆盖:guard.mjs
|
|
40
|
+
|
|
41
|
+
cc-switch 之类的工具会**重新生成自己的 catalog 文件并把 config.toml 的指针改回去**,
|
|
42
|
+
导致修好的档位被覆盖。`guard.mjs` 的思路是不跟它抢指针——不论 config 指向哪份文件,
|
|
43
|
+
直接**就地**把缓存档位修补进那份文件本身(cc-switch 的文件也修)。目前只检查用户级 `config.toml`,不解析 profile 等覆盖项,使用前应确认实际路径:
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
# 查看会修什么(dry-run)
|
|
47
|
+
node scripts/guard.mjs
|
|
48
|
+
|
|
49
|
+
# 修补一次
|
|
50
|
+
node scripts/guard.mjs --write
|
|
51
|
+
|
|
52
|
+
# 常驻前台,catalog 被重写就自动再修(不注册计划任务/服务,Ctrl+C 停止)
|
|
53
|
+
node scripts/guard.mjs --watch
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
日常使用建议:探测+修复一次到位——
|
|
57
|
+
|
|
58
|
+
```powershell
|
|
59
|
+
node scripts/probe.mjs; node scripts/guard.mjs --write
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`sync-catalog.mjs` 仍然保留(生成独立的 efforts.json 副本),guard 修的文件集合是
|
|
63
|
+
「config 当前指向的文件」+「efforts.json」的并集。
|
|
38
64
|
|
|
39
65
|
## 哪个证据可信
|
|
40
66
|
|
|
41
|
-
|
|
67
|
+
证据按网关和协议分别看待:同名模型在不同代理、不同协议下可能有不同处理。Codex 通常使用 Responses,脚本的主动探针使用 Chat Completions,**不能默认两者等价**。
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
某个网关的原生 catalog 与错误回显可能不一致;这并不能单独证明另一条协议路由的 catalog 错误。
|
|
44
70
|
|
|
45
71
|
因此 `probe.mjs` 的默认优先级是:
|
|
46
72
|
|
|
47
|
-
1. **上游错误回显**(`/v1/chat/completions`
|
|
73
|
+
1. **上游错误回显**(`/v1/chat/completions` 的非法值错误,反映该路由的声明)→ `source: validated`;
|
|
48
74
|
2. **原生 catalog** 兜底(错误回显拿不到时)→ `source: native-catalog`。
|
|
49
75
|
|
|
50
|
-
`none`
|
|
76
|
+
脚本只写已知的普通档位,忽略 `none` 和未知值;没有可写档位时保留原菜单。旧版缓存和超过 6 小时的结果需要重新探测,配置的 provider 与 URL 不匹配时也不会写入。`--no-native` 只看错误回显;自动回显优先的结果写入前必须人工确认适用于 Codex 实际路由。模型 slug 只做精确匹配,不按同名后缀跨 provider 匹配。
|
|
51
77
|
|
|
52
78
|
## 更省事的替代
|
|
53
79
|
|
|
@@ -59,10 +85,10 @@ base_url = "http://127.0.0.1:7891/v1"
|
|
|
59
85
|
model_catalog_url = "http://127.0.0.1:7891/v1/models" # 必须与 base_url 同源同端口
|
|
60
86
|
```
|
|
61
87
|
|
|
62
|
-
|
|
88
|
+
cc-switch 等工具可能重新生成 catalog;写入前应先核对来源。
|
|
63
89
|
|
|
64
90
|
## 注意
|
|
65
91
|
|
|
66
92
|
- Codex 只在启动时读 catalog,改完需要重开会话。
|
|
67
|
-
-
|
|
68
|
-
- `(unknown)` 的模型不会被写进 catalog,保留原值。
|
|
93
|
+
- 本机 0.172.0 的内置 catalog 包含 `ultra`(自动任务委派语义);脚本不会从网关回显中自动生成该项。
|
|
94
|
+
- `(unknown)` 的模型不会被写进 catalog,保留原值。
|
package/commands/efforts.md
CHANGED
|
@@ -7,6 +7,6 @@ allowed-tools: Bash(node:*)
|
|
|
7
7
|
# /efforts
|
|
8
8
|
|
|
9
9
|
1. 运行 `node "${PLUGIN_ROOT}/scripts/probe.mjs"` 并展示 **模型 / 可用档位 / 证据** 表格。
|
|
10
|
-
2. 再运行 `node "${PLUGIN_ROOT}/scripts/
|
|
11
|
-
3. 只有用户明确同意后,才执行 `--write
|
|
10
|
+
2. 再运行 `node "${PLUGIN_ROOT}/scripts/guard.mjs"` 展示将要修补的 catalog 条目(dry-run,就地修,能抵抗 cc-switch 覆盖)。
|
|
11
|
+
3. 只有用户明确同意后,才执行 `--write`;若用户需要长期防覆盖,可建议 `guard.mjs --watch` 前台常驻。
|
|
12
12
|
4. 任何 `(unknown)` 的模型都明确说明“网关不校验,无法确定”,不要写进 catalog。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscgoods/codex-effort-discovery",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Codex CLI plugin:
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "Codex CLI plugin: inspect gateway effort evidence and update a model catalog after verifying the route.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, statSync } from "node:fs"
|
|
3
|
+
import {
|
|
4
|
+
cachePath,
|
|
5
|
+
cacheMatchesProvider,
|
|
6
|
+
catalogPath,
|
|
7
|
+
codexHome,
|
|
8
|
+
configCatalogTarget,
|
|
9
|
+
patchCatalog,
|
|
10
|
+
readJson,
|
|
11
|
+
writeJson,
|
|
12
|
+
} from "./lib.mjs"
|
|
13
|
+
|
|
14
|
+
const HELP = `用法: node guard.mjs [--write] [--watch] [--json]
|
|
15
|
+
|
|
16
|
+
在确认缓存适用于当前路由后,修补 cc-switch 等工具重新生成的 catalog。
|
|
17
|
+
|
|
18
|
+
原理:不论 config.toml 的 model_catalog_json 指向哪份文件,直接把
|
|
19
|
+
${cachePath()} 里的实测档位【就地修补】进那份文件本身(cc-switch 的文件也修),
|
|
20
|
+
同时修补 ${catalogPath()} 副本。只读取 config.toml 中的路径,不能识别所有 profile 覆盖。
|
|
21
|
+
|
|
22
|
+
(无参数) dry-run,只显示会修什么
|
|
23
|
+
--write 实际修补一次
|
|
24
|
+
--watch 修补一次后常驻,轮询 ~/.codex 下的 catalog 文件,被重写就自动再修
|
|
25
|
+
(纯前台进程,不注册计划任务/服务;想停 Ctrl+C)
|
|
26
|
+
`
|
|
27
|
+
|
|
28
|
+
function parse(argv) {
|
|
29
|
+
const args = {}
|
|
30
|
+
for (const item of argv) {
|
|
31
|
+
if (item === "--write") args.write = true
|
|
32
|
+
else if (item === "--watch") args.watch = true
|
|
33
|
+
else if (item === "--json") args.json = true
|
|
34
|
+
else if (item === "--help" || item === "-h") args.help = true
|
|
35
|
+
}
|
|
36
|
+
return args
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const args = parse(process.argv.slice(2))
|
|
40
|
+
if (args.help) {
|
|
41
|
+
process.stdout.write(HELP)
|
|
42
|
+
process.exit(0)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 收集需要修补的 catalog 文件:config 当前指向的 + 我们的 efforts.json */
|
|
46
|
+
function targetFiles() {
|
|
47
|
+
const files = new Set()
|
|
48
|
+
const pointed = configCatalogTarget()
|
|
49
|
+
if (pointed) files.add(pointed)
|
|
50
|
+
files.add(catalogPath())
|
|
51
|
+
return [...files]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function repair({ write }) {
|
|
55
|
+
const cache = readJson(cachePath())
|
|
56
|
+
if (!cache?.models) {
|
|
57
|
+
return { error: `no cache at ${cachePath()} — run probe.mjs first` }
|
|
58
|
+
}
|
|
59
|
+
if (!cacheMatchesProvider(cache)) return { error: "cached provider/URL differs from current configuration — run probe.mjs again" }
|
|
60
|
+
const report = []
|
|
61
|
+
for (const file of targetFiles()) {
|
|
62
|
+
if (!existsSync(file)) {
|
|
63
|
+
report.push({ file, skipped: "missing" })
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
const catalog = readJson(file)
|
|
67
|
+
if (!catalog?.models) {
|
|
68
|
+
report.push({ file, skipped: "not a catalog" })
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
const changes = patchCatalog(catalog, cache.models)
|
|
72
|
+
if (changes.length === 0) {
|
|
73
|
+
report.push({ file, ok: true, changes: [] })
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
if (write) writeJson(file, catalog)
|
|
77
|
+
report.push({ file, ok: true, changes })
|
|
78
|
+
}
|
|
79
|
+
return { report }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function print(result, write) {
|
|
83
|
+
for (const entry of result.report ?? []) {
|
|
84
|
+
if (entry.skipped) {
|
|
85
|
+
process.stdout.write(`skip ${entry.file} (${entry.skipped})\n`)
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
88
|
+
if (entry.changes.length === 0) {
|
|
89
|
+
process.stdout.write(`skip ${entry.file} (no applicable changes; cache may be stale or unmatched)\n`)
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
for (const change of entry.changes) {
|
|
93
|
+
process.stdout.write(
|
|
94
|
+
`${write ? "fix" : "would-fix"} ${change.model}: ${change.before} -> ${change.after} [${entry.file}]\n`,
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (result.error) process.stderr.write(result.error + "\n")
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const result = repair({ write: args.write || args.watch })
|
|
102
|
+
if (args.json) process.stdout.write(JSON.stringify(result, null, 2) + "\n")
|
|
103
|
+
else print(result, args.write || args.watch)
|
|
104
|
+
|
|
105
|
+
if (!args.watch) {
|
|
106
|
+
if (!args.write && !args.json) process.stdout.write("\n(dry-run) 加 --write 实际修补,加 --watch 常驻自动修\n")
|
|
107
|
+
process.exit(result.error ? 2 : 0)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// --watch:轮询 mtime+size,变化就重修。不用 fs.watch:Windows 目录监听对"写入后重命名"不稳定。
|
|
111
|
+
process.stdout.write(`\nwatching ${codexHome()} (Ctrl+C 停止)\n`)
|
|
112
|
+
const snapshot = new Map()
|
|
113
|
+
const snap = () => {
|
|
114
|
+
for (const file of targetFiles()) {
|
|
115
|
+
try {
|
|
116
|
+
const stat = statSync(file)
|
|
117
|
+
snapshot.set(file, `${stat.mtimeMs}:${stat.size}`)
|
|
118
|
+
} catch {
|
|
119
|
+
snapshot.set(file, "missing")
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
snap()
|
|
124
|
+
const timer = setInterval(() => {
|
|
125
|
+
let dirty = false
|
|
126
|
+
for (const file of targetFiles()) {
|
|
127
|
+
let sig = "missing"
|
|
128
|
+
try {
|
|
129
|
+
const stat = statSync(file)
|
|
130
|
+
sig = `${stat.mtimeMs}:${stat.size}`
|
|
131
|
+
} catch {}
|
|
132
|
+
if (snapshot.get(file) !== sig) {
|
|
133
|
+
snapshot.set(file, sig)
|
|
134
|
+
dirty = true
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!dirty) return
|
|
138
|
+
const again = repair({ write: true })
|
|
139
|
+
const fixes = (again.report ?? []).flatMap((entry) => entry.changes ?? [])
|
|
140
|
+
const stamp = new Date().toISOString().slice(11, 19)
|
|
141
|
+
if (fixes.length > 0) {
|
|
142
|
+
process.stdout.write(`[${stamp}] catalog rewritten externally, re-applied:\n`)
|
|
143
|
+
print(again, true)
|
|
144
|
+
} else {
|
|
145
|
+
process.stdout.write(`[${stamp}] change detected, levels still correct\n`)
|
|
146
|
+
}
|
|
147
|
+
}, 3000)
|
|
148
|
+
process.on("SIGINT", () => {
|
|
149
|
+
clearInterval(timer)
|
|
150
|
+
process.exit(0)
|
|
151
|
+
})
|
package/scripts/lib.mjs
CHANGED
|
@@ -45,6 +45,13 @@ export function loadConfig() {
|
|
|
45
45
|
return config && typeof config === "object" ? config : {}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
export function cacheMatchesProvider(cache) {
|
|
49
|
+
const entry = loadConfig().providers?.[cache?.provider]
|
|
50
|
+
const clean = (value) => typeof value === "string" ? value.replace(/\/+$/, "") : ""
|
|
51
|
+
return Boolean(entry && (!entry.api || entry.api === "openai") && clean(cache?.baseURL) &&
|
|
52
|
+
clean(cache.baseURL) === clean(entry.baseURL ?? entry.url))
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
export function resolveSecret(value) {
|
|
49
56
|
if (typeof value !== "string") return undefined
|
|
50
57
|
const raw = value.trim()
|
|
@@ -143,12 +150,55 @@ export async function nativeCatalog({ baseURL, apiKey, headers = {}, timeoutMs =
|
|
|
143
150
|
}
|
|
144
151
|
}
|
|
145
152
|
|
|
153
|
+
/**
|
|
154
|
+
* 把探测缓存里的正确档位修补进 catalog(就地修改传入对象)。
|
|
155
|
+
* 只按 slug 精确匹配;相同后缀可能代表不同 provider 或路由。
|
|
156
|
+
* 返回变更列表。
|
|
157
|
+
*/
|
|
158
|
+
export function patchCatalog(catalog, cacheModels, now = Date.now()) {
|
|
159
|
+
const changes = []
|
|
160
|
+
if (!catalog?.models || !cacheModels) return changes
|
|
161
|
+
|
|
162
|
+
for (const model of catalog.models) {
|
|
163
|
+
const info = cacheModels[model.slug]
|
|
164
|
+
if (info?.evidenceVersion !== 2 || !["validated", "native-catalog"].includes(info.source) || !info?.levels?.length ||
|
|
165
|
+
!Number.isFinite(info.at) || info.at > now || now - info.at >= 6 * 60 * 60 * 1000) continue
|
|
166
|
+
const desired = [...new Set(info.levels.filter((level) => CODEX_EFFORTS.includes(level)))]
|
|
167
|
+
// Unknown/non-representable values must never produce an invalid or empty catalog.
|
|
168
|
+
if (desired.length === 0) continue
|
|
169
|
+
const before = (model.supported_reasoning_levels ?? []).map((item) =>
|
|
170
|
+
typeof item === "string" ? item : item.effort,
|
|
171
|
+
)
|
|
172
|
+
if (before.join(",") === desired.join(",")) continue
|
|
173
|
+
model.supported_reasoning_levels = desired.map((effort) => ({ effort, description: effort }))
|
|
174
|
+
if (!desired.includes(model.default_reasoning_level)) {
|
|
175
|
+
model.default_reasoning_level = desired.includes("medium") ? "medium" : desired[0]
|
|
176
|
+
}
|
|
177
|
+
changes.push({
|
|
178
|
+
model: model.slug,
|
|
179
|
+
before: before.join(",") || "(none)",
|
|
180
|
+
after: desired.join(","),
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
return changes
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** config.toml 当前指向的 catalog 文件路径(没有则为 undefined) */
|
|
187
|
+
export function configCatalogTarget() {
|
|
188
|
+
try {
|
|
189
|
+
const config = readFileSync(join(codexHome(), "config.toml"), "utf8")
|
|
190
|
+
const match = /^\s*model_catalog_json\s*=\s*['"](.+?)['"]/m.exec(config)
|
|
191
|
+
return match ? match[1].replace(/\\\\/g, "\\") : undefined
|
|
192
|
+
} catch {
|
|
193
|
+
return undefined
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
146
197
|
/** 读取当前生效的 catalog(codex debug models 优先,其次 config.toml 的 model_catalog_json) */
|
|
147
198
|
export function currentCatalog() {
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (fromConfig?.models) return { catalog: fromConfig, source: match[1] }
|
|
199
|
+
const target = configCatalogTarget()
|
|
200
|
+
const fromConfig = target ? readJson(target) : undefined
|
|
201
|
+
if (fromConfig?.models) return { catalog: fromConfig, source: target }
|
|
152
202
|
|
|
153
203
|
try {
|
|
154
204
|
const output = execSync("codex debug models", { encoding: "utf8", timeout: 60_000, windowsHide: true })
|
|
@@ -157,4 +207,4 @@ export function currentCatalog() {
|
|
|
157
207
|
} catch {}
|
|
158
208
|
|
|
159
209
|
return undefined
|
|
160
|
-
}
|
|
210
|
+
}
|
package/scripts/probe.mjs
CHANGED
|
@@ -25,8 +25,9 @@ function parse(argv) {
|
|
|
25
25
|
|
|
26
26
|
const HELP = `用法: node probe.mjs [--provider <id>] [--model <slug> ...] [--no-native] [--json]
|
|
27
27
|
|
|
28
|
-
1)
|
|
29
|
-
2)
|
|
28
|
+
1) 获取网关原生 catalog(GET {baseURL}/models 里的 supported_reasoning_levels);
|
|
29
|
+
2) 对每个模型探测 Chat Completions 的非法 reasoning_effort(最多 4 次极小请求);
|
|
30
|
+
错误回显优先,原生 catalog 兜底。Codex 使用 Responses,结果需要按实际路由核对。
|
|
30
31
|
provider 来自 ${"~/.config/effort-discovery.json"},默认取第一个 openai provider。
|
|
31
32
|
结果写入 ${cachePath()}。
|
|
32
33
|
`
|
|
@@ -48,6 +49,10 @@ if (!entry) {
|
|
|
48
49
|
process.stderr.write(`no provider: add one to ~/.config/effort-discovery.json\n`)
|
|
49
50
|
process.exit(2)
|
|
50
51
|
}
|
|
52
|
+
if (entry.api && entry.api !== "openai") {
|
|
53
|
+
process.stderr.write(`provider "${providerID}" is not configured for OpenAI-compatible requests\n`)
|
|
54
|
+
process.exit(2)
|
|
55
|
+
}
|
|
51
56
|
|
|
52
57
|
const baseURL = entry.baseURL ?? entry.url
|
|
53
58
|
const apiKey = resolveSecret(entry.apiKey)
|
|
@@ -67,10 +72,11 @@ for (const model of models) {
|
|
|
67
72
|
// 上游错误回显优先(它反映实际接受的 effort),原生 catalog 兜底
|
|
68
73
|
const levels = validated
|
|
69
74
|
? probed.levels.filter((level) => CODEX_EFFORTS.includes(level))
|
|
70
|
-
: nativeLevels
|
|
75
|
+
: nativeLevels ? nativeLevels.filter((level) => CODEX_EFFORTS.includes(level)) : null
|
|
71
76
|
|
|
72
77
|
result.models[model] = {
|
|
73
78
|
levels,
|
|
79
|
+
evidenceVersion: 2,
|
|
74
80
|
source: validated
|
|
75
81
|
? "validated"
|
|
76
82
|
: nativeLevels
|
|
@@ -100,4 +106,4 @@ if (args.json) {
|
|
|
100
106
|
row.map((cell, index) => String(cell ?? "").padEnd(widths[index])).join(" ") + "\n",
|
|
101
107
|
)
|
|
102
108
|
}
|
|
103
|
-
}
|
|
109
|
+
}
|
package/scripts/sync-catalog.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { catalogPath, cachePath, currentCatalog, readJson, writeJson } from "./lib.mjs"
|
|
2
|
+
import { catalogPath, cacheMatchesProvider, cachePath, currentCatalog, patchCatalog, readJson, writeJson } from "./lib.mjs"
|
|
3
3
|
|
|
4
4
|
function parse(argv) {
|
|
5
5
|
const args = {}
|
|
@@ -34,6 +34,10 @@ if (!cache?.models) {
|
|
|
34
34
|
process.stderr.write(`no cache at ${cachePath()} — run probe.mjs first\n`)
|
|
35
35
|
process.exit(2)
|
|
36
36
|
}
|
|
37
|
+
if (!cacheMatchesProvider(cache)) {
|
|
38
|
+
process.stderr.write("cached provider/URL differs from current configuration — run probe.mjs again\n")
|
|
39
|
+
process.exit(2)
|
|
40
|
+
}
|
|
37
41
|
|
|
38
42
|
const current = currentCatalog()
|
|
39
43
|
if (!current) {
|
|
@@ -42,22 +46,7 @@ if (!current) {
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
const catalog = structuredClone(current.catalog)
|
|
45
|
-
const changes =
|
|
46
|
-
|
|
47
|
-
for (const model of catalog.models ?? []) {
|
|
48
|
-
const info = cache.models[model.slug]
|
|
49
|
-
if (!info?.levels?.length) continue
|
|
50
|
-
const desired = info.levels.filter((level) => level !== "off")
|
|
51
|
-
const before = (model.supported_reasoning_levels ?? []).map((item) =>
|
|
52
|
-
typeof item === "string" ? item : item.effort,
|
|
53
|
-
)
|
|
54
|
-
if (before.join(",") === desired.join(",")) continue
|
|
55
|
-
model.supported_reasoning_levels = desired.map((effort) => ({ effort, description: effort }))
|
|
56
|
-
if (!desired.includes(model.default_reasoning_level)) {
|
|
57
|
-
model.default_reasoning_level = desired.includes("medium") ? "medium" : desired[0]
|
|
58
|
-
}
|
|
59
|
-
changes.push({ model: model.slug, before: before.join(",") || "(none)", after: desired.join(",") })
|
|
60
|
-
}
|
|
49
|
+
const changes = patchCatalog(catalog, cache.models)
|
|
61
50
|
|
|
62
51
|
if (args.json) process.stdout.write(JSON.stringify(changes, null, 2) + "\n")
|
|
63
52
|
else if (changes.length === 0) process.stdout.write("no changes\n")
|
|
@@ -73,4 +62,4 @@ if (!args.write) {
|
|
|
73
62
|
|
|
74
63
|
writeJson(catalogPath(), catalog)
|
|
75
64
|
process.stdout.write(`written: ${catalogPath()}\n`)
|
|
76
|
-
process.stdout.write(`现在在 config.toml 里设置:\n model_catalog_json = '${catalogPath()}'\n`)
|
|
65
|
+
process.stdout.write(`现在在 config.toml 里设置:\n model_catalog_json = '${catalogPath()}'\n`)
|
|
@@ -9,25 +9,34 @@ Codex 的档位列表来自 **model catalog**(`model_catalog_json`),插件
|
|
|
9
9
|
|
|
10
10
|
## 步骤
|
|
11
11
|
|
|
12
|
-
1.
|
|
12
|
+
1. 获取网关原生 catalog,并用 Chat Completions 发极小请求;Codex 的 Responses 路由可能不同:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
node "${PLUGIN_ROOT}/scripts/probe.mjs" --json
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
2.
|
|
18
|
+
2. 就地修补 catalog(默认 dry-run)。guard 会修「config 当前指向的文件」+ efforts.json,
|
|
19
|
+
但结果仅按精确 slug 修补,且必须人工确认路由对应关系:
|
|
19
20
|
|
|
20
21
|
```bash
|
|
21
|
-
node "${PLUGIN_ROOT}/scripts/
|
|
22
|
+
node "${PLUGIN_ROOT}/scripts/guard.mjs"
|
|
22
23
|
```
|
|
23
24
|
|
|
24
25
|
3. 用户确认后再写:
|
|
25
26
|
|
|
26
27
|
```bash
|
|
27
|
-
node "${PLUGIN_ROOT}/scripts/
|
|
28
|
+
node "${PLUGIN_ROOT}/scripts/guard.mjs" --write
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
4.
|
|
31
|
+
4. 如果用户希望长期自动防覆盖,可建议前台常驻:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
node "${PLUGIN_ROOT}/scripts/guard.mjs" --watch
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
(纯前台进程,不注册计划任务/服务。)
|
|
38
|
+
|
|
39
|
+
5. 如果 config.toml 的 model_catalog_json 尚未设置过,提醒用户设置:
|
|
31
40
|
|
|
32
41
|
```toml
|
|
33
42
|
model_catalog_json = 'C:\Users\<you>\.codex\model-catalogs\efforts.json'
|
|
@@ -38,6 +47,7 @@ model_catalog_json = 'C:\Users\<you>\.codex\model-catalogs\efforts.json'
|
|
|
38
47
|
## 规则
|
|
39
48
|
|
|
40
49
|
- `(unknown)` 的模型不要写 catalog,保留原值。
|
|
50
|
+
- 不要把 Chat Completions 或其他代理的回显自动视为 Responses 路由的确证。
|
|
41
51
|
- 不要删 `off`/`minimal` 之类没探测到的档位之外的内容;只替换 `supported_reasoning_levels` 和必要的 `default_reasoning_level`。
|
|
42
52
|
- catalog 是整体替换文件:务必从当前生效的 catalog 复制后再改(脚本已经这么做)。
|
|
43
|
-
- 改动 `config.toml` 属于用户配置,必须先征得同意。
|
|
53
|
+
- 改动 `config.toml` 属于用户配置,必须先征得同意。
|