@andyqiu/codeforge 0.8.19 → 0.8.20

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/bin/codeforge.mjs CHANGED
@@ -251,11 +251,10 @@ async function cmdUpgrade(args) {
251
251
  }
252
252
 
253
253
  const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
254
- // 有明确版本号时用精确版本,绕过 @latest dist-tag 缓存
255
- const installTarget = latestVersion
256
- ? `@andyqiu/codeforge@${latestVersion}`
257
- : "@andyqiu/codeforge@latest"
258
- const npmArgs = ["install", "-g", installTarget, "--no-audit", "--no-fund", "--prefer-offline"]
254
+ // 始终用 @latest 安装,避免 CDN 同步延迟导致的 ETARGET 错误
255
+ // 精确版本号仅用于展示,不用于 npm install
256
+ const installTarget = "@andyqiu/codeforge@latest"
257
+ const npmArgs = ["install", "-g", installTarget, "--no-audit", "--no-fund"]
259
258
 
260
259
  if (dryRun) {
261
260
  const displayNew = latestVersion ?? "未知(版本查询失败)"
@@ -264,7 +263,7 @@ async function cmdUpgrade(args) {
264
263
  return 0
265
264
  }
266
265
 
267
- let r = spawnSync(npmCmd, npmArgs, {
266
+ const r = spawnSync(npmCmd, npmArgs, {
268
267
  stdio: "inherit",
269
268
  env: {
270
269
  ...process.env,
@@ -273,20 +272,6 @@ async function cmdUpgrade(args) {
273
272
  },
274
273
  })
275
274
 
276
- // ETARGET:版本刚发布,CDN 节点尚未同步,fallback 到 @latest 重试一次
277
- if (r.status !== 0 && latestVersion !== null) {
278
- const fallbackArgs = ["install", "-g", "@andyqiu/codeforge@latest", "--no-audit", "--no-fund", "--prefer-offline"]
279
- log(`版本 ${latestVersion} 暂未同步,尝试 @latest...`)
280
- r = spawnSync(npmCmd, fallbackArgs, {
281
- stdio: "inherit",
282
- env: {
283
- ...process.env,
284
- npm_config_audit: "false",
285
- npm_config_fund: "false",
286
- },
287
- })
288
- }
289
-
290
275
  if (r.status !== 0) {
291
276
  err(`npm install 失败 (exit=${r.status ?? 1})`)
292
277
  err(`提示:可手动跑 npm install -g ${installTarget}`)
package/dist/index.js CHANGED
@@ -33417,7 +33417,7 @@ import * as https from "node:https";
33417
33417
  // lib/version-injected.ts
33418
33418
  function getInjectedVersion() {
33419
33419
  try {
33420
- const v = "0.8.19";
33420
+ const v = "0.8.20";
33421
33421
  if (typeof v === "string" && /^\d+\.\d+\.\d+/.test(v)) {
33422
33422
  return v;
33423
33423
  }
package/install.mjs CHANGED
@@ -305,6 +305,42 @@ function fixGlobalPluginEntry() {
305
305
  }
306
306
 
307
307
 
308
+ /**
309
+ * 修正 opencode plugin cache 里的版本锁,让 opencode 下次启动重新拉最新 bundle。
310
+ * opencode 在 {cacheDir}/packages/@andyqiu/codeforge@latest/package.json 里记录已安装版本,
311
+ * 如果版本号是精确值(如 0.6.5),opencode 认为 cache 有效不重新下载——导致旧版 bundle 永远被加载。
312
+ * 把精确版本改成 "latest" 后,opencode 下次启动会重新 resolve 并安装最新版。
313
+ */
314
+ function fixOpencodePluginCache() {
315
+ const cacheRoot = process.env["XDG_CACHE_HOME"] ?? path.join(os.homedir(), ".cache")
316
+ const cachePkg = path.join(cacheRoot, "opencode", "packages", "@andyqiu", "codeforge@latest", "package.json")
317
+ if (!fs.existsSync(cachePkg)) {
318
+ vlog(`fixOpencodePluginCache: cache 不存在,跳过(${cachePkg})`)
319
+ return
320
+ }
321
+ if (DRY_RUN) {
322
+ vlog(`[dry-run] fixOpencodePluginCache: 将修正 ${cachePkg}`)
323
+ return
324
+ }
325
+ try {
326
+ const data = JSON.parse(fs.readFileSync(cachePkg, "utf8"))
327
+ if (!data.dependencies?.["@andyqiu/codeforge"]) {
328
+ vlog(`fixOpencodePluginCache: 无版本锁字段,跳过`)
329
+ return
330
+ }
331
+ const locked = data.dependencies["@andyqiu/codeforge"]
332
+ if (locked === "latest") {
333
+ vlog(`fixOpencodePluginCache: 已是 latest,无需修正`)
334
+ return
335
+ }
336
+ data.dependencies["@andyqiu/codeforge"] = "latest"
337
+ atomicWriteJson(cachePkg, data)
338
+ vok(`opencode cache 版本锁已修正:${locked} → latest(重启 opencode 后生效)`)
339
+ } catch (e) {
340
+ addWarn(`fixOpencodePluginCache 失败:${e?.message ?? e}(非致命)`)
341
+ }
342
+ }
343
+
308
344
  function removePluginEntry({ targetRoot }) {
309
345
  const cfg = opencodeCfgPath(targetRoot)
310
346
  if (!fs.existsSync(cfg)) return
@@ -907,6 +943,7 @@ function main() {
907
943
  installSkills({ targetRoot })
908
944
  installAssets({ targetRoot })
909
945
  if (opts.mode === "global") fixGlobalPluginEntry()
946
+ if (opts.mode === "global") fixOpencodePluginCache()
910
947
  configureDefaultAgent({ mode: opts.mode })
911
948
  installKhConfig({ mode: opts.mode, codeforgeCfgDir })
912
949
  regenerateDevShim()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andyqiu/codeforge",
3
- "version": "0.8.19",
3
+ "version": "0.8.20",
4
4
  "description": "CodeForge — opencode 的零侵入扩展包",
5
5
  "type": "module",
6
6
  "private": false,