Fix Homebrew update detection and skill guidance
This commit is contained in:
1 parent
53453cf512
commit
48ebccd086
10 files changed
+274
-222
No files matched your search
+86
-44
@@ -1,5 +1,5 @@
|
||||
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
import { basename, dirname, isAbsolute, join, relative } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { isCompiledBinary } from "../../core/runtime.js";
|
||||
import { readInstalledSkillVersion } from "../../core/embedded-skill.js";
|
||||
@@ -136,7 +136,7 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
releaseNotes: latestRelease?.notes ?? "",
|
||||
releaseUrl: latestRelease?.htmlUrl ?? "",
|
||||
mode: "source",
|
||||
message: "Running in source development mode. Run 'seal-use update' to git pull & bun install."
|
||||
message: "当前运行的是开发版。正式用户请安装正式版后使用 seal-use update。"
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
try {
|
||||
runCommand("git", ["-C", runtime.appRoot, "pull", "--ff-only"]);
|
||||
} catch (err) {
|
||||
console.error(`git pull skipped: ${err instanceof Error ? err.message : String(err)}`);
|
||||
console.error(`⚠️ 开发版更新同步失败,继续刷新本地依赖: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
runCommand("bun", ["install"], { cwd: runtime.appRoot });
|
||||
|
||||
@@ -212,6 +212,18 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetVersion && !options.checkOnly) {
|
||||
printJson({
|
||||
updated: false,
|
||||
currentVersion: VERSION,
|
||||
targetVersion,
|
||||
latestVersion,
|
||||
mode: "homebrew",
|
||||
message: "Homebrew-managed installations follow the formula version and do not support selecting a historical release. Use Homebrew directly for version pinning."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.checkOnly) {
|
||||
printJson({
|
||||
updated: false,
|
||||
@@ -390,21 +402,34 @@ function detectArch(): "arm64" | "x64" {
|
||||
return process.arch === "arm64" ? "arm64" : "x64";
|
||||
}
|
||||
|
||||
export function isHomebrewInstall(execPath = process.execPath): boolean {
|
||||
function homebrewFormulaPrefix(): string | undefined {
|
||||
try {
|
||||
const resolved = realpathSync(execPath);
|
||||
return (
|
||||
resolved.includes("/Cellar/seal-use/") ||
|
||||
resolved.includes("/homebrew/Cellar/seal-use/") ||
|
||||
resolved.includes("/.linuxbrew/Cellar/seal-use/") ||
|
||||
execPath.includes("/Cellar/seal-use/") ||
|
||||
execPath.includes("/homebrew/bin/seal-use")
|
||||
);
|
||||
const result = spawnSync("brew", ["--prefix", "seal-use"], {
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
encoding: "utf-8"
|
||||
});
|
||||
if (result.status !== 0 || typeof result.stdout !== "string") return undefined;
|
||||
const prefix = result.stdout.trim();
|
||||
return prefix || undefined;
|
||||
} catch {
|
||||
return (
|
||||
execPath.includes("/Cellar/seal-use/") ||
|
||||
execPath.includes("/homebrew/bin/seal-use")
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function isHomebrewInstall(
|
||||
execPath = process.execPath,
|
||||
formulaPrefix = homebrewFormulaPrefix()
|
||||
): boolean {
|
||||
if (!formulaPrefix) return false;
|
||||
|
||||
try {
|
||||
const resolvedExec = realpathSync(execPath);
|
||||
const resolvedPrefix = realpathSync(formulaPrefix);
|
||||
const fromFormula = relative(resolvedPrefix, resolvedExec);
|
||||
const parentPrefix = `..${process.platform === "win32" ? "\\" : "/"}`;
|
||||
return Boolean(fromFormula && fromFormula !== ".." && !fromFormula.startsWith(parentPrefix) && !isAbsolute(fromFormula));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,37 +505,54 @@ async function handleHomebrewUpdate(
|
||||
const wasRunning = serviceStatus(serviceConfig).running;
|
||||
if (wasRunning) await runServiceCommand("stop", serviceConfig);
|
||||
|
||||
// 1. Fast update of the dedicated tap
|
||||
const tapUpdate = spawnSync("brew", ["update", "yunyingk/tap"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, NONINTERACTIVE: "1" }
|
||||
});
|
||||
let alreadyLatest = false;
|
||||
let updateError: unknown;
|
||||
try {
|
||||
// 1. Fast update of the dedicated tap
|
||||
const tapUpdate = spawnSync("brew", ["update", "yunyingk/tap"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, NONINTERACTIVE: "1" }
|
||||
});
|
||||
|
||||
if (tapUpdate.status !== 0) {
|
||||
const msg = tapUpdate.stderr?.trim() || tapUpdate.stdout?.trim();
|
||||
if (msg) console.error(`⚠️ brew update yunyingk/tap 提示: ${msg}`);
|
||||
if (tapUpdate.status !== 0) {
|
||||
const msg = tapUpdate.stderr?.trim() || tapUpdate.stdout?.trim();
|
||||
if (msg) console.error(`⚠️ brew update yunyingk/tap 提示: ${msg}`);
|
||||
}
|
||||
|
||||
// 2. Upgrade the formula
|
||||
const upgradeRes = spawnSync("brew", ["upgrade", "seal-use"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, NONINTERACTIVE: "1" }
|
||||
});
|
||||
|
||||
const outCombined = `${upgradeRes.stdout || ""} ${upgradeRes.stderr || ""}`;
|
||||
alreadyLatest =
|
||||
outCombined.includes("already installed") || outCombined.includes("latest version already installed");
|
||||
|
||||
if (upgradeRes.status !== 0 && !alreadyLatest) {
|
||||
throw new Error(
|
||||
`brew upgrade seal-use failed (exit ${upgradeRes.status}): ${upgradeRes.stderr?.trim() || upgradeRes.stdout?.trim()}`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
updateError = err;
|
||||
throw err;
|
||||
} finally {
|
||||
if (wasRunning) {
|
||||
try {
|
||||
await runServiceCommand("start", serviceConfig);
|
||||
} catch (startError) {
|
||||
if (updateError) {
|
||||
console.error(`⚠️ 更新失败后服务恢复启动也失败: ${startError instanceof Error ? startError.message : String(startError)}`);
|
||||
} else {
|
||||
throw startError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Upgrade the formula
|
||||
const upgradeRes = spawnSync("brew", ["upgrade", "seal-use"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, NONINTERACTIVE: "1" }
|
||||
});
|
||||
|
||||
const outCombined = `${upgradeRes.stdout || ""} ${upgradeRes.stderr || ""}`;
|
||||
const alreadyLatest =
|
||||
outCombined.includes("already installed") || outCombined.includes("latest version already installed");
|
||||
|
||||
if (upgradeRes.status !== 0 && !alreadyLatest) {
|
||||
throw new Error(
|
||||
`brew upgrade seal-use failed (exit ${upgradeRes.status}): ${upgradeRes.stderr?.trim() || upgradeRes.stdout?.trim()}`
|
||||
);
|
||||
}
|
||||
|
||||
if (wasRunning) await runServiceCommand("start", serviceConfig);
|
||||
|
||||
// Refresh installed skill through new binary
|
||||
try {
|
||||
spawnSync("seal-use", ["skill", "install"], { stdio: "ignore" });
|
||||
|
||||
Reference in new issue
Block a user