Files
billion-context/scripts/sync-codex-plugin-version.mjs
ework-agent ec3576b82d fix(review round-3 leftovers): manifest-check coverage on the bugfix lane, missing-manifest gate, autoFold docs
Three unfixed items from the #4725 review ledger (#4757 landed separately via
the ci-fixes sweep):

- release-bugfix.yml lost the #4449 manifest --check when the v3 lane rewrite
  landed (v0.1.208 ran it before Publish guard; master's rewrite dropped it).
  Ported back with the #4576 pre-#4449 lane existence guard, gated on the
  resolve step's actual proceed output (this variant has no path output).
- scripts/sync-codex-plugin-version.mjs silently SKIPPED a missing manifest
  file — in --check mode a missing file greened the gate, neutering the
  release guard. A missing target is now a hard error naming the file; the
  four manifests are a fixed contract. Regression test added (RED on the old
  skip).
- CONFIGURATION.md en+zh: document the autoFold benefit gate (#3444: growth
  folds arm only on ≥4096 tokens over the effective target; sub-4096 saving
  arms the backoff; image-dominant exempt) and the measured floor (irreducible
  baseline raises an unreachable target, never above the window). Both
  languages in sync.

Sync tests 5/5, typecheck clean.
2026-10-26 10:42:20 +08:00

111 lines
4.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 同步 Codex 插件相关的版本号。
*
* 背景:Codex 的 marketplace 更新检测靠的是「marketplace 清单里宣告的版本」
* 与「已安装缓存目录的版本」之间的差异。上游仓库的版本号散落在多处
* (package.json、.claude-plugin/marketplace.json、.claude-plugin/plugin.json),
* 历史上已经出现过 package.json 是 0.1.204 而 .claude-plugin 里还写着
* 0.1.188 的漂移 —— 这会让 Codex 侧看到过期的版本号。
*
* 本脚本把 package.json 的 version 作为唯一真相源,写回:
* 1. .agents/plugins/marketplace.json → Codex marketplace 清单
* 2. plugins/codex/.codex-plugin/plugin.json → Codex 插件清单
* 3. .claude-plugin/marketplace.json → Claude marketplace 清单
* 4. .claude-plugin/plugin.json → Claude 插件清单
*
* 用法:
* node scripts/sync-codex-plugin-version.mjs # 校验 + 写入
* node scripts/sync-codex-plugin-version.mjs --check # 只校验,有漂移则退出码 1
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const CHECK_ONLY = process.argv.includes("--check");
function readJson(rel) {
const abs = path.join(ROOT, rel);
if (!fs.existsSync(abs)) return null;
try {
return JSON.parse(fs.readFileSync(abs, "utf8"));
} catch (err) {
console.error(`[sync-codex-plugin-version] ${rel} 不是合法 JSON:${err.message}`);
process.exit(1);
}
}
function writeJson(rel, data) {
const abs = path.join(ROOT, rel);
fs.mkdirSync(path.dirname(abs), { recursive: true });
fs.writeFileSync(abs, `${JSON.stringify(data, null, 2)}\n`, "utf8");
}
const pkg = readJson("package.json");
if (!pkg) {
console.error("[sync-codex-plugin-version] 找不到 package.json");
process.exit(1);
}
const version = pkg.version;
if (typeof version !== "string" || !version.trim()) {
console.error("[sync-codex-plugin-version] package.json 的 version 缺失");
process.exit(1);
}
const targets = [
{ rel: ".agents/plugins/marketplace.json", apply: (d) => {
for (const p of d.plugins ?? []) {
if (p.name === "billion-context") p.version = version;
}
} },
{ rel: "plugins/codex/.codex-plugin/plugin.json", apply: (d) => {
d.version = version;
} },
{ rel: ".claude-plugin/marketplace.json", apply: (d) => {
for (const p of d.plugins ?? []) {
if (p.name === "billion-context") p.version = version;
}
} },
{ rel: ".claude-plugin/plugin.json", apply: (d) => {
d.version = version;
} },
];
const drifted = [];
for (const t of targets) {
const data = readJson(t.rel);
if (!data) {
// 缺文件不是可跳过状态:四个 manifest 是固定契约,少一个说明仓库
// 树被破坏或 targets 列表过期。写入模式跳过会静默产出一个缺文件
// 的“已同步”;--check 模式跳过等于把发版守卫钻了个洞(缺失照样绿)。
// 例外:预 #4449 的老 lane(release-bugfix.yml 的存在性守卫)本来
// 就没有这个脚本,不会走到这里。
console.error(`[sync-codex-plugin-version] 缺少 manifest:${t.rel} — 不允许跳过,请修复仓库树或更新 targets 列表`);
process.exit(1);
}
const before = JSON.stringify(data);
t.apply(data);
const after = JSON.stringify(data);
if (before === after) {
console.log(`[sync-codex-plugin-version] OK ${t.rel} 已是 ${version}`);
continue;
}
drifted.push(t.rel);
if (CHECK_ONLY) {
console.log(`[sync-codex-plugin-version] 漂移 ${t.rel} 需要同步到 ${version}`);
} else {
writeJson(t.rel, data);
console.log(`[sync-codex-plugin-version] 同步 ${t.rel} → ${version}`);
}
}
if (CHECK_ONLY && drifted.length > 0) {
console.error(`[sync-codex-plugin-version] ${drifted.length} 个文件的版本号与 package.json 不一致`);
process.exit(1);
}
console.log(`[sync-codex-plugin-version] 完成,唯一真相源版本 = ${version}`);