@andyqiu/codeforge 0.7.9 → 0.7.10

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.
Files changed (3) hide show
  1. package/README.md +5 -1
  2. package/dist/index.js +63 -34
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -133,8 +133,12 @@ export KNOWLEDGE_API_KEY=你的-token
133
133
 
134
134
  ## 升级
135
135
 
136
+ opencode 启动时会自动检查并升级,无需手动操作。
137
+
138
+ 如需手动升级:
139
+
136
140
  ```bash
137
- npm update -g @andyqiu/codeforge
141
+ npm install -g @andyqiu/codeforge@latest
138
142
  ```
139
143
 
140
144
  ## 卸载
package/dist/index.js CHANGED
@@ -18892,7 +18892,7 @@ var handler18 = toolPolicyServer;
18892
18892
  import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync6, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
18893
18893
  import { homedir as homedir8 } from "node:os";
18894
18894
  import { dirname as dirname15, join as join25 } from "node:path";
18895
- import { spawnSync as spawnSync2 } from "node:child_process";
18895
+ import { spawn } from "node:child_process";
18896
18896
 
18897
18897
  // lib/update-checker-impl.ts
18898
18898
  import { readFileSync as readFileSync5 } from "node:fs";
@@ -18903,7 +18903,7 @@ import * as https from "node:https";
18903
18903
  // lib/version-injected.ts
18904
18904
  function getInjectedVersion() {
18905
18905
  try {
18906
- const v = "0.7.9";
18906
+ const v = "0.7.10";
18907
18907
  if (typeof v === "string" && /^\d+\.\d+\.\d+/.test(v)) {
18908
18908
  return v;
18909
18909
  }
@@ -19051,41 +19051,75 @@ function writeLastInstalledVersion(v) {
19051
19051
  writeFileSync2(f, JSON.stringify({ installedVersion: v }, null, 2), "utf8");
19052
19052
  } catch {}
19053
19053
  }
19054
- function resolveNodeBin() {
19054
+ function spawnAsync(cmd, args, opts = {}) {
19055
+ return new Promise((resolve16) => {
19056
+ const chunks = [];
19057
+ const errChunks = [];
19058
+ const proc = spawn(cmd, args, {
19059
+ stdio: "pipe",
19060
+ shell: opts.shell ?? false,
19061
+ cwd: opts.cwd
19062
+ });
19063
+ proc.stdout?.on("data", (d) => chunks.push(d));
19064
+ proc.stderr?.on("data", (d) => errChunks.push(d));
19065
+ let timer = null;
19066
+ if (opts.timeout) {
19067
+ timer = setTimeout(() => {
19068
+ proc.kill();
19069
+ resolve16({ status: -1, stdout: "", stderr: "timeout" });
19070
+ }, opts.timeout);
19071
+ }
19072
+ proc.on("close", (code) => {
19073
+ if (timer)
19074
+ clearTimeout(timer);
19075
+ resolve16({
19076
+ status: code ?? -1,
19077
+ stdout: Buffer.concat(chunks).toString("utf8"),
19078
+ stderr: Buffer.concat(errChunks).toString("utf8")
19079
+ });
19080
+ });
19081
+ proc.on("error", () => {
19082
+ if (timer)
19083
+ clearTimeout(timer);
19084
+ resolve16({ status: -1, stdout: "", stderr: "spawn error" });
19085
+ });
19086
+ });
19087
+ }
19088
+ async function resolveNodeBin() {
19055
19089
  const w = process.platform === "win32";
19056
19090
  try {
19057
- const r = spawnSync2(w ? "where" : "which", ["node"], { encoding: "utf8", stdio: "pipe" });
19091
+ const r = await spawnAsync(w ? "where" : "which", ["node"], { timeout: 3000 });
19058
19092
  if (r.status === 0 && r.stdout.trim())
19059
19093
  return r.stdout.trim().split(/\r?\n/)[0].trim();
19060
19094
  } catch {}
19061
19095
  for (const c of w ? ["C:\\Program Files\\nodejs\\node.exe"] : ["/usr/local/bin/node", "/usr/bin/node", "/opt/homebrew/bin/node", "/opt/homebrew/opt/node/bin/node"]) {
19062
19096
  try {
19063
- if (spawnSync2(c, ["--version"], { stdio: "pipe", timeout: 2000 }).status === 0)
19097
+ const r = await spawnAsync(c, ["--version"], { timeout: 2000 });
19098
+ if (r.status === 0)
19064
19099
  return c;
19065
19100
  } catch {}
19066
19101
  }
19067
19102
  return process.execPath;
19068
19103
  }
19069
- function resolveNpmBin() {
19104
+ async function resolveNpmBin() {
19070
19105
  const w = process.platform === "win32";
19071
19106
  try {
19072
- const r = spawnSync2(w ? "where" : "which", ["npm"], { encoding: "utf8", stdio: "pipe" });
19107
+ const r = await spawnAsync(w ? "where" : "which", ["npm"], { timeout: 3000 });
19073
19108
  if (r.status === 0 && r.stdout.trim())
19074
19109
  return r.stdout.trim().split(/\r?\n/)[0].trim();
19075
19110
  } catch {}
19076
19111
  for (const c of w ? ["C:\\Program Files\\nodejs\\npm.cmd"] : ["/usr/local/bin/npm", "/usr/bin/npm", "/opt/homebrew/bin/npm"]) {
19077
19112
  try {
19078
- if (spawnSync2(c, ["--version"], { stdio: "pipe", timeout: 2000 }).status === 0)
19113
+ const r = await spawnAsync(c, ["--version"], { timeout: 2000 });
19114
+ if (r.status === 0)
19079
19115
  return c;
19080
19116
  } catch {}
19081
19117
  }
19082
19118
  return "npm";
19083
19119
  }
19084
- function getNpmGlobalRoot(npmBin) {
19120
+ async function getNpmGlobalRoot(npmBin) {
19085
19121
  try {
19086
- const r = spawnSync2(npmBin, ["root", "-g"], {
19087
- encoding: "utf8",
19088
- stdio: "pipe",
19122
+ const r = await spawnAsync(npmBin, ["root", "-g"], {
19089
19123
  timeout: 1e4,
19090
19124
  shell: process.platform === "win32"
19091
19125
  });
@@ -19096,7 +19130,7 @@ function getNpmGlobalRoot(npmBin) {
19096
19130
  }
19097
19131
  logLifecycle(PLUGIN_NAME19, "import", { version: PLUGIN_VERSION });
19098
19132
  var updateCheckerServer = async (ctx) => {
19099
- const yieldResult = shouldYieldToLocalPlugin({ directory: ctx.directory });
19133
+ const yieldResult = shouldYieldToLocalPlugin();
19100
19134
  if (yieldResult.yield) {
19101
19135
  safeWriteLog(PLUGIN_NAME19, {
19102
19136
  level: "info",
@@ -19164,22 +19198,29 @@ var updateCheckerServer = async (ctx) => {
19164
19198
  return;
19165
19199
  }
19166
19200
  await safeAsync(PLUGIN_NAME19, "auto_install", async () => {
19167
- const nodeBin = resolveNodeBin();
19168
- const npmBin = resolveNpmBin();
19201
+ const nodeBin = await resolveNodeBin();
19202
+ const npmBin = await resolveNpmBin();
19169
19203
  safeWriteLog(PLUGIN_NAME19, { level: "info", msg: "auto_install_start", local, remote, nodeBin, npmBin });
19170
- const r1 = spawnSync2(npmBin, ["install", "-g", `${u.package}@${remote}`], {
19171
- stdio: "pipe",
19172
- encoding: "utf8",
19204
+ const r1 = await spawnAsync(npmBin, ["install", "-g", `${u.package}@${remote}`], {
19173
19205
  timeout: 120000,
19174
19206
  shell: process.platform === "win32"
19175
19207
  });
19176
19208
  if (r1.status !== 0) {
19177
- safeWriteLog(PLUGIN_NAME19, { level: "warn", msg: "npm_install_failed", status: r1.status, stderr: (r1.stderr ?? "").slice(0, 300) });
19209
+ safeWriteLog(PLUGIN_NAME19, { level: "warn", msg: "npm_install_failed", status: r1.status, stderr: r1.stderr.slice(0, 300) });
19178
19210
  await postToast(ctx, `[codeforge] 自动升级失败(${local} → ${remote}),请手动运行:codeforge upgrade`);
19179
19211
  return;
19180
19212
  }
19181
19213
  safeWriteLog(PLUGIN_NAME19, { level: "info", msg: "npm_install_success", remote });
19182
- const npmRoot = getNpmGlobalRoot(npmBin);
19214
+ try {
19215
+ const opencodeCache = join25(homedir8(), ".cache", "opencode", "packages", "@andyqiu", "codeforge@latest");
19216
+ if (existsSync5(opencodeCache)) {
19217
+ rmSync(opencodeCache, { recursive: true, force: true });
19218
+ safeWriteLog(PLUGIN_NAME19, { level: "info", msg: "opencode_cache_cleared", path: opencodeCache });
19219
+ }
19220
+ } catch (e) {
19221
+ safeWriteLog(PLUGIN_NAME19, { level: "warn", msg: "opencode_cache_clear_failed", error: e.message });
19222
+ }
19223
+ const npmRoot = await getNpmGlobalRoot(npmBin);
19183
19224
  const pkgRoot = npmRoot ? join25(npmRoot, "@andyqiu", "codeforge") : null;
19184
19225
  const installMjs = pkgRoot ? join25(pkgRoot, "install.mjs") : null;
19185
19226
  if (!installMjs || !existsSync5(installMjs)) {
@@ -19187,27 +19228,15 @@ var updateCheckerServer = async (ctx) => {
19187
19228
  await postToast(ctx, `[codeforge] ⚠ npm 包已升级 ${local} → ${remote},但资产部署未完成。下次启动将重试,或手动运行:codeforge upgrade`);
19188
19229
  return;
19189
19230
  }
19190
- const r2 = spawnSync2(nodeBin, [installMjs, "--global", "--skip-build", "--skip-plugin-entry"], {
19191
- stdio: "pipe",
19192
- encoding: "utf8",
19231
+ const r2 = await spawnAsync(nodeBin, [installMjs, "--global", "--skip-build", "--skip-plugin-entry"], {
19193
19232
  timeout: 60000,
19194
- shell: false,
19195
19233
  cwd: pkgRoot ?? undefined
19196
19234
  });
19197
19235
  if (r2.status !== 0) {
19198
- safeWriteLog(PLUGIN_NAME19, { level: "warn", msg: "codeforge_install_failed", status: r2.status, stderr: (r2.stderr ?? "").slice(0, 300) });
19236
+ safeWriteLog(PLUGIN_NAME19, { level: "warn", msg: "codeforge_install_failed", status: r2.status, stderr: r2.stderr.slice(0, 300) });
19199
19237
  await postToast(ctx, `[codeforge] ⚠ npm 包已升级 ${local} → ${remote},但资产部署失败。下次启动将重试,或手动运行:codeforge upgrade`);
19200
19238
  return;
19201
19239
  }
19202
- try {
19203
- const opencodeCache = join25(homedir8(), ".cache", "opencode", "packages", "@andyqiu", "codeforge@latest");
19204
- if (existsSync5(opencodeCache)) {
19205
- rmSync(opencodeCache, { recursive: true, force: true });
19206
- safeWriteLog(PLUGIN_NAME19, { level: "info", msg: "opencode_cache_cleared", path: opencodeCache });
19207
- }
19208
- } catch (e) {
19209
- safeWriteLog(PLUGIN_NAME19, { level: "warn", msg: "opencode_cache_clear_failed", error: e.message });
19210
- }
19211
19240
  writeLastInstalledVersion(remote);
19212
19241
  safeWriteLog(PLUGIN_NAME19, { level: "info", msg: "auto_install_full_success", local, remote, nodeBin, npmBin });
19213
19242
  await postToast(ctx, `[codeforge] ✅ 已升级 ${local} → ${remote}(重启 opencode 生效)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andyqiu/codeforge",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "description": "CodeForge — opencode 的零侵入扩展包",
5
5
  "type": "module",
6
6
  "private": false,