@tscgoods/codex-effort-discovery 0.5.0 → 0.5.1
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 +26 -0
- package/commands/efforts.md +2 -2
- package/package.json +1 -1
- package/scripts/guard.mjs +149 -0
- package/scripts/lib.mjs +54 -0
- package/scripts/sync-catalog.mjs +2 -17
- package/skills/effort-probe/SKILL.md +13 -4
package/README.md
CHANGED
|
@@ -36,6 +36,32 @@ node scripts/sync-catalog.mjs --write
|
|
|
36
36
|
|
|
37
37
|
插件还提供 `/efforts` 命令和 `effort-probe` 技能,让 agent 代跑这两步。
|
|
38
38
|
|
|
39
|
+
## 防覆盖:guard.mjs
|
|
40
|
+
|
|
41
|
+
cc-switch 之类的工具会**重新生成自己的 catalog 文件并把 config.toml 的指针改回去**,
|
|
42
|
+
导致修好的档位被覆盖。`guard.mjs` 的思路是不跟它抢指针——不论 config 指向哪份文件,
|
|
43
|
+
直接**就地**把实测档位修补进那份文件本身(cc-switch 的文件也修),指针改不改都无所谓:
|
|
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」的并集。
|
|
64
|
+
|
|
39
65
|
## 哪个证据可信
|
|
40
66
|
|
|
41
67
|
DeepSeek 官方文档(https://api-docs.deepseek.com/zh-cn/guides/thinking_mode)明确写着 `reasoning_effort` 只接受 `low / high / max`,`medium` 和 `xhigh` 都会被映射成 `high`;Anthropic 格式是 `none/low/high/max`。
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscgoods/codex-effort-discovery",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Codex CLI plugin: probe which reasoning-effort levels your gateway accepts, then generate a model catalog that makes Codex offer exactly those.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, statSync } from "node:fs"
|
|
3
|
+
import {
|
|
4
|
+
cachePath,
|
|
5
|
+
catalogPath,
|
|
6
|
+
codexHome,
|
|
7
|
+
configCatalogTarget,
|
|
8
|
+
patchCatalog,
|
|
9
|
+
readJson,
|
|
10
|
+
writeJson,
|
|
11
|
+
} from "./lib.mjs"
|
|
12
|
+
|
|
13
|
+
const HELP = `用法: node guard.mjs [--write] [--watch] [--json]
|
|
14
|
+
|
|
15
|
+
防止 cc-switch 等工具重新生成 catalog 后档位被覆盖回错误值。
|
|
16
|
+
|
|
17
|
+
原理:不论 config.toml 的 model_catalog_json 指向哪份文件,直接把
|
|
18
|
+
${cachePath()} 里的实测档位【就地修补】进那份文件本身(cc-switch 的文件也修),
|
|
19
|
+
这样指针被改来改去都无所谓,文件内容永远是对的。同时修补 ${catalogPath()} 副本。
|
|
20
|
+
|
|
21
|
+
(无参数) dry-run,只显示会修什么
|
|
22
|
+
--write 实际修补一次
|
|
23
|
+
--watch 修补一次后常驻,轮询 ~/.codex 下的 catalog 文件,被重写就自动再修
|
|
24
|
+
(纯前台进程,不注册计划任务/服务;想停 Ctrl+C)
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
function parse(argv) {
|
|
28
|
+
const args = {}
|
|
29
|
+
for (const item of argv) {
|
|
30
|
+
if (item === "--write") args.write = true
|
|
31
|
+
else if (item === "--watch") args.watch = true
|
|
32
|
+
else if (item === "--json") args.json = true
|
|
33
|
+
else if (item === "--help" || item === "-h") args.help = true
|
|
34
|
+
}
|
|
35
|
+
return args
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const args = parse(process.argv.slice(2))
|
|
39
|
+
if (args.help) {
|
|
40
|
+
process.stdout.write(HELP)
|
|
41
|
+
process.exit(0)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 收集需要修补的 catalog 文件:config 当前指向的 + 我们的 efforts.json */
|
|
45
|
+
function targetFiles() {
|
|
46
|
+
const files = new Set()
|
|
47
|
+
const pointed = configCatalogTarget()
|
|
48
|
+
if (pointed) files.add(pointed)
|
|
49
|
+
files.add(catalogPath())
|
|
50
|
+
return [...files]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function repair({ write }) {
|
|
54
|
+
const cache = readJson(cachePath())
|
|
55
|
+
if (!cache?.models) {
|
|
56
|
+
return { error: `no cache at ${cachePath()} — run probe.mjs first` }
|
|
57
|
+
}
|
|
58
|
+
const report = []
|
|
59
|
+
for (const file of targetFiles()) {
|
|
60
|
+
if (!existsSync(file)) {
|
|
61
|
+
report.push({ file, skipped: "missing" })
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
const catalog = readJson(file)
|
|
65
|
+
if (!catalog?.models) {
|
|
66
|
+
report.push({ file, skipped: "not a catalog" })
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
const changes = patchCatalog(catalog, cache.models)
|
|
70
|
+
if (changes.length === 0) {
|
|
71
|
+
report.push({ file, ok: true, changes: [] })
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
if (write) writeJson(file, catalog)
|
|
75
|
+
report.push({ file, ok: true, changes })
|
|
76
|
+
}
|
|
77
|
+
return { report }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function print(result, write) {
|
|
81
|
+
for (const entry of result.report ?? []) {
|
|
82
|
+
if (entry.skipped) {
|
|
83
|
+
process.stdout.write(`skip ${entry.file} (${entry.skipped})\n`)
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
if (entry.changes.length === 0) {
|
|
87
|
+
process.stdout.write(`ok ${entry.file} (already correct)\n`)
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
for (const change of entry.changes) {
|
|
91
|
+
process.stdout.write(
|
|
92
|
+
`${write ? "fix" : "would-fix"} ${change.model}: ${change.before} -> ${change.after} [${entry.file}]\n`,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (result.error) process.stderr.write(result.error + "\n")
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const result = repair({ write: args.write || args.watch })
|
|
100
|
+
if (args.json) process.stdout.write(JSON.stringify(result, null, 2) + "\n")
|
|
101
|
+
else print(result, args.write || args.watch)
|
|
102
|
+
|
|
103
|
+
if (!args.watch) {
|
|
104
|
+
if (!args.write && !args.json) process.stdout.write("\n(dry-run) 加 --write 实际修补,加 --watch 常驻自动修\n")
|
|
105
|
+
process.exit(result.error ? 2 : 0)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// --watch:轮询 mtime+size,变化就重修。不用 fs.watch:Windows 目录监听对"写入后重命名"不稳定。
|
|
109
|
+
process.stdout.write(`\nwatching ${codexHome()} (Ctrl+C 停止)\n`)
|
|
110
|
+
const snapshot = new Map()
|
|
111
|
+
const snap = () => {
|
|
112
|
+
for (const file of targetFiles()) {
|
|
113
|
+
try {
|
|
114
|
+
const stat = statSync(file)
|
|
115
|
+
snapshot.set(file, `${stat.mtimeMs}:${stat.size}`)
|
|
116
|
+
} catch {
|
|
117
|
+
snapshot.set(file, "missing")
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
snap()
|
|
122
|
+
const timer = setInterval(() => {
|
|
123
|
+
let dirty = false
|
|
124
|
+
for (const file of targetFiles()) {
|
|
125
|
+
let sig = "missing"
|
|
126
|
+
try {
|
|
127
|
+
const stat = statSync(file)
|
|
128
|
+
sig = `${stat.mtimeMs}:${stat.size}`
|
|
129
|
+
} catch {}
|
|
130
|
+
if (snapshot.get(file) !== sig) {
|
|
131
|
+
snapshot.set(file, sig)
|
|
132
|
+
dirty = true
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!dirty) return
|
|
136
|
+
const again = repair({ write: true })
|
|
137
|
+
const fixes = (again.report ?? []).flatMap((entry) => entry.changes ?? [])
|
|
138
|
+
const stamp = new Date().toISOString().slice(11, 19)
|
|
139
|
+
if (fixes.length > 0) {
|
|
140
|
+
process.stdout.write(`[${stamp}] catalog rewritten externally, re-applied:\n`)
|
|
141
|
+
print(again, true)
|
|
142
|
+
} else {
|
|
143
|
+
process.stdout.write(`[${stamp}] change detected, levels still correct\n`)
|
|
144
|
+
}
|
|
145
|
+
}, 3000)
|
|
146
|
+
process.on("SIGINT", () => {
|
|
147
|
+
clearInterval(timer)
|
|
148
|
+
process.exit(0)
|
|
149
|
+
})
|
package/scripts/lib.mjs
CHANGED
|
@@ -143,6 +143,60 @@ export async function nativeCatalog({ baseURL, apiKey, headers = {}, timeoutMs =
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* 把探测缓存里的正确档位修补进 catalog(就地修改传入对象)。
|
|
148
|
+
* cacheModels 的键可能是带 provider 前缀的 slug(ccs-newapi/xxx),也可能是裸模型 id;
|
|
149
|
+
* catalog slug 先精确匹配,再按 "/" 后缀退化匹配。
|
|
150
|
+
* 返回变更列表。
|
|
151
|
+
*/
|
|
152
|
+
export function patchCatalog(catalog, cacheModels) {
|
|
153
|
+
const changes = []
|
|
154
|
+
if (!catalog?.models || !cacheModels) return changes
|
|
155
|
+
|
|
156
|
+
const lookup = (slug) => {
|
|
157
|
+
const exact = cacheModels[slug]
|
|
158
|
+
if (exact) return exact
|
|
159
|
+
const bare = String(slug).split("/").pop()
|
|
160
|
+
// 裸 id 匹配:缓存键自身是裸 id,或者缓存键的后缀等于裸 id
|
|
161
|
+
const candidates = Object.entries(cacheModels).filter(([key]) => {
|
|
162
|
+
const tail = key.split("/").pop()
|
|
163
|
+
return key === bare || tail === bare
|
|
164
|
+
})
|
|
165
|
+
return candidates.length === 1 ? candidates[0][1] : undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
for (const model of catalog.models) {
|
|
169
|
+
const info = lookup(model.slug)
|
|
170
|
+
if (!info?.levels?.length) continue
|
|
171
|
+
const desired = info.levels.filter((level) => level !== "off")
|
|
172
|
+
const before = (model.supported_reasoning_levels ?? []).map((item) =>
|
|
173
|
+
typeof item === "string" ? item : item.effort,
|
|
174
|
+
)
|
|
175
|
+
if (before.join(",") === desired.join(",")) continue
|
|
176
|
+
model.supported_reasoning_levels = desired.map((effort) => ({ effort, description: effort }))
|
|
177
|
+
if (!desired.includes(model.default_reasoning_level)) {
|
|
178
|
+
model.default_reasoning_level = desired.includes("medium") ? "medium" : desired[0]
|
|
179
|
+
}
|
|
180
|
+
changes.push({
|
|
181
|
+
model: model.slug,
|
|
182
|
+
before: before.join(",") || "(none)",
|
|
183
|
+
after: desired.join(","),
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
return changes
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** config.toml 当前指向的 catalog 文件路径(没有则为 undefined) */
|
|
190
|
+
export function configCatalogTarget() {
|
|
191
|
+
try {
|
|
192
|
+
const config = readFileSync(join(codexHome(), "config.toml"), "utf8")
|
|
193
|
+
const match = /^\s*model_catalog_json\s*=\s*['"](.+?)['"]/m.exec(config)
|
|
194
|
+
return match ? match[1].replace(/\\\\/g, "\\") : undefined
|
|
195
|
+
} catch {
|
|
196
|
+
return undefined
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
146
200
|
/** 读取当前生效的 catalog(codex debug models 优先,其次 config.toml 的 model_catalog_json) */
|
|
147
201
|
export function currentCatalog() {
|
|
148
202
|
const config = readFileSync(join(codexHome(), "config.toml"), "utf8")
|
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, cachePath, currentCatalog, patchCatalog, readJson, writeJson } from "./lib.mjs"
|
|
3
3
|
|
|
4
4
|
function parse(argv) {
|
|
5
5
|
const args = {}
|
|
@@ -42,22 +42,7 @@ if (!current) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
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
|
-
}
|
|
45
|
+
const changes = patchCatalog(catalog, cache.models)
|
|
61
46
|
|
|
62
47
|
if (args.json) process.stdout.write(JSON.stringify(changes, null, 2) + "\n")
|
|
63
48
|
else if (changes.length === 0) process.stdout.write("no changes\n")
|
|
@@ -15,19 +15,28 @@ Codex 的档位列表来自 **model catalog**(`model_catalog_json`),插件
|
|
|
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
|
+
不论指针指向哪,文件内容都是对的——能抵抗 cc-switch 重新生成 catalog 造成的覆盖:
|
|
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'
|