From 4bee16008649bb089b2ace091014ef7effc5fb2a Mon Sep 17 00:00:00 2001 From: yunyingk Date: Mon, 12 Oct 2026 13:16:51 +0800 Subject: [PATCH] Remove Homebrew integration and tap promotion --- .github/workflows/release.yml | 2 +- AGENTS.md | 4 +- README.md | 8 +- scripts/dev-override.ts | 3 +- scripts/install.sh | 18 +- scripts/release.ts | 4 +- src/cli/commands/homebrew-skill.test.ts | 45 --- src/cli/commands/update.test.ts | 81 +++-- src/cli/commands/update.ts | 292 +----------------- src/core/doctor/diagnose.ts | 3 +- src/core/doctor/knowledge.ts | 2 +- wsl-infra/README.md | 8 +- wsl-infra/infra-healthcheck.sh | 2 +- wsl-infra/release-sync.sh | 45 +-- .../systemd/seal-use-release-sync.service | 2 +- 15 files changed, 95 insertions(+), 424 deletions(-) delete mode 100644 src/cli/commands/homebrew-skill.test.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c76f9e..e638257 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -118,5 +118,5 @@ jobs: path: dist/bin/ retention-days: 1 - # Gitea asset promotion and Homebrew tap updates are owned by the WSL + # Gitea asset promotion is owned by the WSL # seal-use-release-sync.timer after this GitHub Release is published. diff --git a/AGENTS.md b/AGENTS.md index 8f3b8d0..37d70fa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,7 +19,7 @@ Tests are colocated as `*.test.ts` files in `src/`. - `bun run lint`: lint with `oxlint src` (zero-warning gate; CI fails on warnings). - `bun test`: run all colocated Bun tests. - `bun run bump `: bump version across all manifest and skill files. -- `bun run dev:override`: compile the host binary with Git dev version metadata, macOS sign, atomically override the Mac global command (`/opt/homebrew/bin/seal-use`), and sync the local Agent Skill. +- `bun run dev:override`: compile the host binary with Git dev version metadata, macOS sign, atomically override the existing global command found on PATH (falling back to a standalone bin directory), and sync the local Agent Skill. ## Coding Style & Naming Conventions @@ -102,7 +102,7 @@ Recent commits use concise imperative subjects, often `Add ...` or `Refine ...`, git push origin refs/tags/vX.Y.Z ``` - GitHub Actions (`release.yml`) is responsible only for cross-compiling all 5 target binaries and publishing the GitHub Release. - - **Gitea & Homebrew Pull-Based Promotion**: Do not manually push branches or tags to `home` (Gitea). On WSL (`wsl-dev`), `seal-use-release-sync.timer` polls the latest GitHub Release every 15 minutes (or can be triggered immediately via `systemctl start seal-use-release-sync.service`), pulls the release and assets from GitHub into Gitea, and updates the Homebrew tap (`wsl-infra/systemd/`). + - **Gitea Pull-Based Promotion**: Do not manually push branches or tags to `home` (Gitea). On WSL (`wsl-dev`), `seal-use-release-sync.timer` polls the latest GitHub Release every 15 minutes (or can be triggered immediately via `systemctl start seal-use-release-sync.service`), pulls the release and assets from GitHub into Gitea (`wsl-infra/systemd/`). - The workflow enforces the merge-before-tag rule rather than trusting the operator: `release.yml` refuses to publish unless the tagged commit is an ancestor of `origin/main`. Actions in both workflows are pinned to commit SHAs rather than moving tags for supply-chain integrity. ## Security & Configuration Tips diff --git a/README.md b/README.md index 4eca36a..a3dc772 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ After installation: seal-use version # Check version seal-use skill install # Install Agent skill to ~/.agents/skills/seal-use seal-use mcp-config # Print an MCP server snippet (for Cursor / Claude Desktop / Codex) -seal-use update # Self-update (GitHub Releases binary, Homebrew, or source) +seal-use update # Self-update (release binary or source checkout) ``` ## Source Setup & Development @@ -62,7 +62,7 @@ npm link seal-use version ``` -`npm link` creates a symlink from `/opt/homebrew/lib/node_modules/seal-use` → your local checkout. The `seal-use` binary on PATH then runs source files directly via bun — **no reinstall needed after editing source code**. +`npm link` creates a symlink from the global npm package directory (`npm root -g`) to your local checkout. The `seal-use` binary on PATH then runs source files directly via bun — **no reinstall needed after editing source code**. > ⚠️ **Do NOT use `npm install -g .`** for development. That copies files into the global node_modules directory and the copy becomes stale as soon as you edit the source. Always use `npm link` so edits take effect immediately. @@ -129,7 +129,7 @@ Update an existing checkout: seal-use update ``` -`seal-use update` adapts to how it was installed: from a source checkout it runs `git pull --ff-only` and refreshes dependencies with `bun install`; a standalone binary downloads the matching GitHub Release asset and replaces itself; a Homebrew install upgrades through `brew upgrade seal-use`. +`seal-use update` adapts to how it was installed: from a source checkout it runs `git pull --ff-only` and refreshes dependencies with `bun install`; a standalone binary downloads the matching GitHub Release asset and replaces itself. Because `npm link` makes the global command a symlink into your checkout, **updating the checkout is sufficient** — no reinstall step required. The symlink continues to point to the updated source. @@ -330,4 +330,4 @@ bun run bump 0.8.5 **CI & Promotion Pipeline:** - GitHub Actions triggers automatically upon pushing a `v*` tag to `origin`; - Cross-compiles standalone binaries for 5 target platforms (macOS Apple Silicon/Intel, Linux x86_64/ARM64, Windows x64) and publishes them to **[GitHub Releases](https://github.com/yunyingk/seal-use/releases)**; -- WSL `seal-use-release-sync.timer` polls the latest GitHub Release and promotes all assets to **[Gitea Releases](https://git.ying-qing.cn/gitea/seal-use/releases)** and the Homebrew tap (`ops/README.md`). +- WSL `seal-use-release-sync.timer` polls the latest GitHub Release and promotes all assets to **[Gitea Releases](https://git.ying-qing.cn/gitea/seal-use/releases)** (`wsl-infra/README.md`). diff --git a/scripts/dev-override.ts b/scripts/dev-override.ts index a84f23c..762308a 100755 --- a/scripts/dev-override.ts +++ b/scripts/dev-override.ts @@ -14,7 +14,7 @@ export function resolveTargetBinaryPath(): string { if (whichRes.status === 0 && whichRes.stdout) { const p = whichRes.stdout.trim(); if (p && existsSync(p)) { - // Preserve native binary symlinks (Homebrew), but never overwrite an npm-linked source entry. + // Preserve native binary symlinks, but never overwrite an npm-linked source entry. const target = realpathSync(p); return /\.(?:[cm]?[jt]sx?|sh)$/i.test(target) ? p : target; } @@ -25,7 +25,6 @@ export function resolveTargetBinaryPath(): string { // 2. Fallback candidate paths in order of preference const candidates = [ - "/opt/homebrew/bin/seal-use", "/usr/local/bin/seal-use", join(homedir(), ".local", "bin", "seal-use"), join(homedir(), "bin", "seal-use") diff --git a/scripts/install.sh b/scripts/install.sh index 2756f4b..a6f726d 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -44,12 +44,18 @@ TARGET_DIR="${SEAL_USE_INSTALL_DIR:-${SEAL_HOME_INSTALL_DIR:-}}" if [ -n "$TARGET_DIR" ]; then mkdir -p "$TARGET_DIR" else - for candidate in "/opt/homebrew/bin" "/usr/local/bin" "$HOME/.local/bin" "$HOME/bin"; do - if [ -d "$candidate" ] && [ -w "$candidate" ]; then - TARGET_DIR="$candidate" - break - fi - done + # Reuse an existing command's directory so a second installation does not get shadowed on PATH. + EXISTING_COMMAND="$(command -v seal-use || true)" + if [ -n "$EXISTING_COMMAND" ] && [ -f "$EXISTING_COMMAND" ] && [ -w "$(dirname "$EXISTING_COMMAND")" ]; then + TARGET_DIR="$(dirname "$EXISTING_COMMAND")" + else + for candidate in "/usr/local/bin" "$HOME/.local/bin" "$HOME/bin"; do + if [ -d "$candidate" ] && [ -w "$candidate" ]; then + TARGET_DIR="$candidate" + break + fi + done + fi fi if [ -z "$TARGET_DIR" ]; then diff --git a/scripts/release.ts b/scripts/release.ts index 5f15356..c6046be 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -131,7 +131,7 @@ if (isDryRun) { console.log(` 4. git commit -m "Release ${tag}: ..."`); console.log(` 5. git push origin HEAD:refs/heads/${releaseBranch}`); console.log(` 6. gh pr create && gh pr checks --watch && gh pr merge --merge`); - console.log(` 7. 同步 main,打标 ${tag} 并推送到 origin(Gitea 与 Homebrew 由 WSL seal-use-release-sync 主动拉取)`); + console.log(` 7. 同步 main,打标 ${tag} 并推送到 origin(Gitea 由 WSL seal-use-release-sync 主动拉取)`); process.exit(0); } @@ -229,6 +229,6 @@ if (success) { console.log(`🎉 恭喜!Seal Use ${tag} 已成功发布并触发多平台自动化编译!`); console.log(" • GitHub Actions 构建中心: https://github.com/yunyingk/seal-use/actions"); console.log(` • GitHub Release 页面: https://github.com/yunyingk/seal-use/releases/tag/${tag}`); - console.log(" • Gitea 与 Homebrew Tap 将由 WSL seal-use-release-sync.timer 自动拉取晋升"); + console.log(" • Gitea 将由 WSL seal-use-release-sync.timer 自动拉取晋升"); console.log("========================================================\n"); } diff --git a/src/cli/commands/homebrew-skill.test.ts b/src/cli/commands/homebrew-skill.test.ts deleted file mode 100644 index 475011c..0000000 --- a/src/cli/commands/homebrew-skill.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { describe, expect, test } from "bun:test"; -import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; -import { tmpdir } from "node:os"; -import { join } from "node:path"; -import { handleUpdateCommand, homebrewFormulaPrefix, installHomebrewSkill } from "./update.js"; - -describe("Homebrew skill refresh", () => { - test("a copied source package cannot update its parent application's Git repository", async () => { - const dir = mkdtempSync(join(tmpdir(), "seal-source-update-test-")); - try { - await expect(handleUpdateCommand({ appRoot: dir, entryFile: join(dir, "src", "cli.ts") })) - .rejects.toMatchObject({ exitCode: 13 }); - expect(existsSync(join(dir, "bun.lock"))).toBe(false); - } finally { rmSync(dir, { recursive: true, force: true }); } - }); - - test("uses the upgraded formula executable even when PATH contains an older standalone CLI", () => { - const dir = mkdtempSync(join(tmpdir(), "seal-brew-skill-test-")); - const originalPath = process.env.PATH; - try { - const prefix = join(dir, "formula"); - const bin = join(prefix, "bin"); - const skill = join(dir, "skill"); - mkdirSync(bin, { recursive: true }); - mkdirSync(skill); - writeFileSync(join(skill, "SKILL.md"), "---\nmetadata:\n version: 1.2.3\n---\n"); - // Shell fixtures touch only this temp directory; no real brew upgrade or global skill installation. - writeFileSync(join(dir, "brew"), `#!/bin/sh\nprintf '%s\\n' '${prefix}'\n`, { mode: 0o755 }); - writeFileSync(join(dir, "seal-use"), `#!/bin/sh\ntouch '${join(dir, "wrong-cli")}'\nexit 1\n`, { mode: 0o755 }); - writeFileSync(join(bin, "seal-use"), `#!/bin/sh\ntouch '${join(dir, "right-cli")}'\nprintf '%s\\n' '{"targetDir":"${skill}"}'\n`, { mode: 0o755 }); - process.env.PATH = `${dir}:${originalPath ?? ""}`; - // Fail before any install call if child-process PATH isolation is ever broken. - expect(homebrewFormulaPrefix()).toBe(prefix); - expect(installHomebrewSkill("1.2.3")).toEqual({ targetDir: skill, version: "1.2.3" }); - expect(existsSync(join(dir, "right-cli"))).toBe(true); - expect(existsSync(join(dir, "wrong-cli"))).toBe(false); - writeFileSync(join(skill, "SKILL.md"), "---\nmetadata:\n version: 1.2.2\n---\n"); - expect(() => installHomebrewSkill("1.2.3")).toThrow("1.2.2"); - try { installHomebrewSkill("1.2.3"); } catch (error) { expect(error).toMatchObject({ exitCode: 13 }); } - } finally { - if (originalPath === undefined) delete process.env.PATH; else process.env.PATH = originalPath; - rmSync(dir, { recursive: true, force: true }); - } - }); -}); diff --git a/src/cli/commands/update.test.ts b/src/cli/commands/update.test.ts index 6af388f..d10663d 100644 --- a/src/cli/commands/update.test.ts +++ b/src/cli/commands/update.test.ts @@ -1,8 +1,8 @@ import { describe, expect, test } from "bun:test"; -import { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { compareSemVer, getMirrorMode, isHomebrewInstall, isNewerVersion, matchAssetForPlatform, pruneUpdateLeftovers } from "./update.js"; +import { compareSemVer, getMirrorMode, handleUpdateCommand, isNewerVersion, matchAssetForPlatform, pruneUpdateLeftovers } from "./update.js"; type Asset = { name: string; downloadUrl: string; size: number }; @@ -241,33 +241,58 @@ describe("update command bgSave and cache integration", () => { rmSync(tempDir, { recursive: true, force: true }); } }); +}); - describe("isHomebrewInstall", () => { - test("requires the executable to resolve inside Homebrew's registered formula prefix", () => { - const root = mkdtempSync(join(tmpdir(), "seal-use-homebrew-detect-")); - try { - const formulaPrefix = join(root, "opt", "seal-use"); - const cellarBin = join(root, "Cellar", "seal-use", "0.10.33", "bin"); - const nativeBin = join(root, "bin"); - const formulaExecutable = join(cellarBin, "seal-use"); - const nativeExecutable = join(nativeBin, "seal-use"); +describe("update installation modes", () => { + test("a copied source package cannot update its parent application's Git repository", async () => { + const dir = mkdtempSync(join(tmpdir(), "seal-source-update-test-")); + try { + await expect(handleUpdateCommand({ appRoot: dir, entryFile: join(dir, "src", "cli.ts") })) + .rejects.toMatchObject({ exitCode: 13 }); + expect(existsSync(join(dir, "bun.lock"))).toBe(false); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); - mkdirSync(cellarBin, { recursive: true }); - mkdirSync(nativeBin, { recursive: true }); - mkdirSync(join(root, "opt"), { recursive: true }); - writeFileSync(formulaExecutable, "homebrew binary"); - writeFileSync(nativeExecutable, "native binary"); - symlinkSync(join(root, "Cellar", "seal-use", "0.10.33"), formulaPrefix); - - expect(isHomebrewInstall(formulaExecutable, formulaPrefix)).toBe(true); - expect(isHomebrewInstall(nativeExecutable, formulaPrefix)).toBe(false); - } finally { - rmSync(root, { recursive: true, force: true }); - } - }); - - test("does not infer Homebrew from a matching directory name alone", () => { - expect(isHomebrewInstall("/opt/homebrew/bin/seal-use", "/tmp/not-installed-seal-use")).toBe(false); - }); + test("native updates ignore package managers and allow selecting a release", async () => { + const dir = mkdtempSync(join(tmpdir(), "seal-native-update-test-")); + const originalExecPath = process.execPath; + const originalEnv = { ...process.env }; + const originalFetch = globalThis.fetch; + const originalLog = console.log; + try { + // Every executable, cache and response is a temp fixture; never update the running test engine. + const binary = join(dir, "seal-use"); + const invoked = join(dir, "package-manager-invoked"); + writeFileSync(binary, "native fixture"); + writeFileSync(join(dir, "brew"), `#!/bin/sh\ntouch '${invoked}'\nprintf '%s\\n' '${dir}'\n`, { mode: 0o755 }); + process.execPath = binary; + process.env.PATH = `${dir}:${originalEnv.PATH ?? ""}`; + process.env.SEAL_USE_UPDATE_CACHE_FILE = join(dir, "update-cache.json"); + process.env.SEAL_USE_MIRROR = "github"; + globalThis.fetch = Object.assign(async () => new Response(JSON.stringify([ + { tag_name: "v100.0.0", assets: [] }, + { tag_name: "v99.0.0", assets: [] } + ]), { headers: { "Content-Type": "application/json" } }), { preconnect: originalFetch.preconnect }); + let stdout = ""; + console.log = (message: string) => { stdout += message; }; + const runtime = { appRoot: dir, entryFile: join(dir, "src", "cli.ts") }; + await handleUpdateCommand(runtime, { checkOnly: true, targetVersion: "99.0.0" }); + expect(JSON.parse(stdout)).toMatchObject({ mode: "binary", latestVersion: "99.0.0", updateAvailable: true }); + stdout = ""; + // Reaching asset selection proves explicit versions are not blocked by a removed installation mode. + await expect(handleUpdateCommand(runtime, { targetVersion: "v99.0.0" })) + .rejects.toThrow("in release v99.0.0"); + expect(stdout).toBe(""); + expect(existsSync(invoked)).toBe(false); + expect(readFileSync(binary, "utf8")).toBe("native fixture"); + } finally { + process.execPath = originalExecPath; + process.env = originalEnv; + globalThis.fetch = originalFetch; + console.log = originalLog; + rmSync(dir, { recursive: true, force: true }); + } }); }); diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 025c1bf..26d2036 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -1,13 +1,13 @@ -import { chmodSync, existsSync, mkdirSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs"; -import { basename, dirname, isAbsolute, join, relative } from "node:path"; -import { spawn, spawnSync } from "node:child_process"; +import { chmodSync, existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs"; +import { basename, dirname, join } from "node:path"; +import { spawnSync } from "node:child_process"; import { isCompiledBinary } from "../../core/runtime.js"; import { normalizeBeijingIso } from "../../core/config/timestamps.js"; import { readInstalledSkillVersion } from "../../core/embedded-skill.js"; import { saveUpdateCache } from "../../core/update-cache.js"; import { VERSION, IS_RELEASE } from "../../version.js"; import { printJson } from "../printer.js"; -import { CliError, validationError } from "../../core/errors.js"; +import { validationError } from "../../core/errors.js"; import type { CliRuntime } from "../types.js"; const DEFAULT_GITHUB_REPO = "yunyingk/seal-use"; @@ -150,20 +150,7 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp return; } - // 3. Homebrew managed mode - if (isHomebrewInstall()) { - try { - await handleHomebrewUpdate(options, repo, targetVersion); - return; - } catch (err) { - if (err instanceof CliError) throw err; - console.error( - `⚠️ Homebrew 自动更新失败,回退至原生二进制更新: ${err instanceof Error ? err.message : String(err)}` - ); - } - } - - // 4. Standalone binary mode: check GitHub Releases + // 3. Standalone binary mode: check GitHub Releases const platform = detectPlatform(); const arch = detectArch(); @@ -207,18 +194,6 @@ 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, @@ -436,18 +411,6 @@ function installSkillFromInstalledBinary( return { targetDir, version }; } -/** Homebrew may change the formula prefix; PATH can still contain an older standalone command. */ -export function installHomebrewSkill(targetVersion: string): { targetDir?: string; version?: string } { - const prefix = homebrewFormulaPrefix(); - if (!prefix) throw validationError("Cannot resolve the updated Homebrew seal-use formula prefix."); - try { - return installSkillFromInstalledBinary(join(prefix, "bin", "seal-use"), targetVersion); - } catch (error) { - // The formula was already upgraded. Do not fall back to replacing the old running Cellar image. - throw validationError(error instanceof Error ? error.message : String(error)); - } -} - function detectPlatform(): "darwin" | "linux" | "windows" { if (process.platform === "darwin") return "darwin"; if (process.platform === "win32") return "windows"; @@ -458,251 +421,6 @@ function detectArch(): "arm64" | "x64" { return process.arch === "arm64" ? "arm64" : "x64"; } -export function homebrewFormulaPrefix(): string | undefined { - try { - const result = spawnSync("brew", ["--prefix", "seal-use"], { - stdio: ["ignore", "pipe", "ignore"], - encoding: "utf-8", - env: { ...process.env } - }); - if (result.status !== 0 || typeof result.stdout !== "string") return undefined; - const prefix = result.stdout.trim(); - return prefix || undefined; - } catch { - return undefined; - } -} - -function homebrewInstalledVersion(): string | undefined { - try { - const result = spawnSync("brew", ["list", "--versions", "seal-use"], { - stdio: ["ignore", "pipe", "ignore"], - encoding: "utf-8" - }); - if (result.status !== 0 || typeof result.stdout !== "string") return undefined; - const parts = result.stdout.trim().split(/\s+/); - return parts.length >= 2 ? parts[parts.length - 1] : undefined; - } catch { - 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; - } -} - -async function handleHomebrewUpdate( - options: UpdateOptions, - repo: string, - targetVersion?: string -): Promise { - const releases = await fetchGitHubReleases(repo, 30); - const release = targetVersion - ? (releases.find((r) => r.version === targetVersion || r.tagName === targetVersion || r.tagName === `v${targetVersion}`) ?? - await fetchGitHubRelease(repo, targetVersion)) - : (releases[0] ?? await fetchGitHubRelease(repo)); - - const latestVersion = release?.version ?? VERSION; - const isUpgrade = isNewerVersion(latestVersion, VERSION); - const shouldUpdate = isUpgrade || Boolean(options.force); - - if (release?.version) { - saveUpdateCache({ - latestVersion: release.version, - publishedAt: release.publishedAt, - releaseUrl: release.htmlUrl - }); - } - - if (options.bgSave) { - return; - } - - if (options.checkOnly) { - const currentRelease = releases.find((r) => r.version === VERSION); - const pendingReleases = releases.filter((r) => isNewerVersion(r.version, VERSION)); - printJson({ - updated: false, - updateAvailable: isUpgrade, - currentVersion: VERSION, - currentVersionPublishedAt: currentRelease?.publishedAt, - latestVersion, - latestVersionPublishedAt: release?.publishedAt, - behindCount: pendingReleases.length, - pendingReleases: pendingReleases.map((r) => ({ - version: r.version, - tagName: r.tagName, - publishedAt: r.publishedAt, - author: r.author, - releaseNotes: r.notes, - releaseUrl: r.htmlUrl - })), - releaseNotes: release?.notes ?? "", - releaseUrl: release?.htmlUrl ?? "", - mode: "homebrew" - }); - return; - } - - if (!shouldUpdate) { - printJson({ - updated: false, - currentVersion: VERSION, - latestVersion, - mode: "homebrew", - message: `seal-use is already up to date (v${VERSION})` - }); - return; - } - - console.error("ℹ️ 检测到当前 seal-use 由 Homebrew 管理。"); - console.error("📦 正在通过 Homebrew 极速更新: brew update && brew upgrade seal-use ..."); - - const installedBefore = homebrewInstalledVersion(); - const alreadyLatestBeforeUpdate = installedBefore - ? !isNewerVersion(latestVersion, installedBefore) - : false; - let alreadyLatest = alreadyLatestBeforeUpdate; - // `brew update` refreshes all configured taps. Passing a tap name here is - // parsed as a formula upgrade by newer Homebrew versions (and fails with - // "No available formula ... tap"). - const tapUpdate = await runHomebrewCommand( - ["update"], - "🔄 [1/2] 正在刷新 Homebrew 软件源(可能需要几分钟)..." - ); - - if (tapUpdate.status !== 0) { - const msg = tapUpdate.stderr?.trim() || tapUpdate.stdout?.trim(); - throw new Error(`brew update failed (exit ${tapUpdate.status}): ${msg || "unknown error"}`); - } - - // 2. Upgrade the formula - const upgradeRes = await runHomebrewCommand( - ["upgrade", "seal-use"], - "⬆️ [2/2] 正在升级 seal-use..." - ); - - const outCombined = `${upgradeRes.stdout || ""} ${upgradeRes.stderr || ""}`; - const brewReportsAlreadyLatest = - outCombined.includes("already installed") || outCombined.includes("latest version already installed"); - - if (upgradeRes.status !== 0 && !brewReportsAlreadyLatest) { - throw new Error( - `brew upgrade seal-use failed (exit ${upgradeRes.status}): ${upgradeRes.stderr.trim() || upgradeRes.stdout.trim()}` - ); - } - - const installedVersion = homebrewInstalledVersion(); - if (installedVersion && isNewerVersion(latestVersion, installedVersion)) { - throw new Error( - `Homebrew still has seal-use v${installedVersion}; expected v${latestVersion}. ` + - "Refresh the tap and run `brew upgrade seal-use` again." - ); - } - alreadyLatest = alreadyLatestBeforeUpdate; - - // Refresh installed skill through new binary - installHomebrewSkill(latestVersion); - - console.error( - alreadyLatest - ? "ℹ️ seal-use 已是 Homebrew 中的最新版本。" - : "✅ seal-use 已通过 Homebrew 成功更新!" - ); - - printJson({ - updated: !alreadyLatest, - previousVersion: VERSION, - latestVersion, - mode: "homebrew", - message: alreadyLatest - ? `seal-use is already at the latest version v${latestVersion} in Homebrew` - : `Successfully upgraded seal-use to v${latestVersion} via Homebrew` - }); -} - -type HomebrewCommandResult = { - status: number | null; - signal: NodeJS.Signals | null; - stdout: string; - stderr: string; -}; - -/** - * Runs Homebrew without buffering its output until completion. Homebrew can spend several minutes - * refreshing taps or downloading a formula, so its output belongs on stderr as live diagnostics; - * stdout must remain reserved for the command's final machine-readable JSON payload. - */ -function runHomebrewCommand(args: string[], startMessage: string): Promise { - console.error(startMessage); - - return new Promise((resolve, reject) => { - let child; - try { - child = spawn("brew", args, { - stdio: ["ignore", "pipe", "pipe"], - env: { ...process.env, NONINTERACTIVE: "1" } - }); - } catch (error) { - reject(error); - return; - } - - let stdout = ""; - let stderr = ""; - let lastOutputAt = Date.now(); - let settled = false; - - const forward = (chunk: Buffer, stream: "stdout" | "stderr") => { - const text = chunk.toString(); - if (stream === "stdout") stdout += text; - else stderr += text; - lastOutputAt = Date.now(); - try { - process.stderr.write(text); - } catch { - // Ignore a closed diagnostic stream; the child process still needs to complete normally. - } - }; - - child.stdout?.on("data", (chunk: Buffer) => forward(chunk, "stdout")); - child.stderr?.on("data", (chunk: Buffer) => forward(chunk, "stderr")); - - const heartbeat = setInterval(() => { - if (Date.now() - lastOutputAt >= 15000) { - console.error("⏳ Homebrew 仍在运行,当前没有新的输出,请稍候..."); - lastOutputAt = Date.now(); - } - }, 15000); - heartbeat.unref?.(); - - const finish = (callback: () => void) => { - if (settled) return; - settled = true; - clearInterval(heartbeat); - callback(); - }; - - child.once("error", (error) => finish(() => reject(error))); - child.once("close", (status, signal) => - finish(() => resolve({ status, signal, stdout, stderr })) - ); - }); -} - type GitHubAsset = { name: string; downloadUrl: string; diff --git a/src/core/doctor/diagnose.ts b/src/core/doctor/diagnose.ts index a58b214..30503e9 100644 --- a/src/core/doctor/diagnose.ts +++ b/src/core/doctor/diagnose.ts @@ -120,12 +120,11 @@ export function diagnoseSystem(): DoctorDiagnosis { const exportDir = join(home, "Downloads"); const globalBinaryCandidates = [ - "/opt/homebrew/bin/seal-use", "/usr/local/bin/seal-use", join(home, ".local", "bin", "seal-use"), join(home, "bin", "seal-use") ]; - const detectedBinary = globalBinaryCandidates.find((p) => existsSync(p)) ?? process.execPath; + const detectedBinary = Bun.which("seal-use") ?? globalBinaryCandidates.find((p) => existsSync(p)) ?? process.execPath; const directories: Record = { configDir: { diff --git a/src/core/doctor/knowledge.ts b/src/core/doctor/knowledge.ts index 5825b92..eb9ef2b 100644 --- a/src/core/doctor/knowledge.ts +++ b/src/core/doctor/knowledge.ts @@ -71,7 +71,7 @@ export const EMBEDDED_DIRECTORY_SPECS: DirectorySpec[] = [ { name: "全局命令行程序", category: "binary", - standardPath: "/opt/homebrew/bin/seal-use", + standardPath: "/usr/local/bin/seal-use", purpose: "macOS / Linux 全局独立单文件二进制程序;旧版 seal-home 命令仅保留解析兼容,不再新建全局别名。", accessMode: "executable", retention: "persistent" diff --git a/wsl-infra/README.md b/wsl-infra/README.md index 0362261..ad8711a 100644 --- a/wsl-infra/README.md +++ b/wsl-infra/README.md @@ -11,9 +11,9 @@ Release. On WSL, `seal-use-release-sync.timer` polls the latest release every 3. the remaining archives 4. raw platform binaries -The Homebrew tap is updated immediately after the first two assets are present -in Gitea and the macOS arm64 checksum is available. The remaining assets are -idempotent retries and do not make a valid Homebrew installation unavailable. +The first archive becomes available as soon as it is present in Gitea. +The remaining assets retry idempotently on later timer runs if needed. +Promotion only mirrors release assets; it does not update package-manager repositories. The WSL worker uses its local mihomo listener at `http://127.0.0.1:7897` only for GitHub. It does not enable TUN or expose a LAN listener. Local Gitea @@ -47,7 +47,7 @@ From mac15, run: It emits JSON checks for mac15, the Mac15-to-WSL Tailscale/SSH path, WSL, Windows, mac13, and Aliyun, including the release-sync timer state and the last -successful Gitea/Homebrew promotion. The script is read-only; a failed check +successful Gitea promotion. The script is read-only; a failed check does not restart or mutate any service. ## Workspace backups diff --git a/wsl-infra/infra-healthcheck.sh b/wsl-infra/infra-healthcheck.sh index 180dacc..9560d45 100755 --- a/wsl-infra/infra-healthcheck.sh +++ b/wsl-infra/infra-healthcheck.sh @@ -60,7 +60,7 @@ results=( "$(check_ssh wsl_frp wsl-dev 'docker inspect -f "{{.State.Status}}" frpc-wsl-gateway')" "$(check_ssh wsl_mihomo wsl-dev 'systemctl is-active --quiet mihomo.service && ss -ltn | grep -q "127.0.0.1:7897" && printf "service=active,listener=127.0.0.1:7897"')" "$(check_ssh wsl_release_sync_timer wsl-dev 'test "$(systemctl is-enabled seal-use-release-sync.timer 2>/dev/null)" = enabled && test "$(systemctl is-active seal-use-release-sync.timer 2>/dev/null)" = active && printf "timer=enabled,active"')" - "$(check_ssh wsl_release_sync_recent_success wsl-dev 'journalctl -q -u seal-use-release-sync.service --since "24 hours ago" --no-pager | grep -E "fully synchronized to Gitea and Homebrew" | tail -1')" + "$(check_ssh wsl_release_sync_recent_success wsl-dev 'journalctl -q -u seal-use-release-sync.service --since "24 hours ago" --no-pager | grep -E "fully synchronized to Gitea" | tail -1')" "$(check_ssh wsl_gitea wsl-dev 'curl -sS -o /dev/null -w "gitea_http=%{http_code}" http://127.0.0.1:3001/api/v1/version')" "$(check_ssh wsl_github_proxy wsl-dev 'NO_PROXY= no_proxy= curl -sS -o /dev/null --proxy http://127.0.0.1:7897 --connect-timeout 8 --max-time 15 -w "github_http=%{http_code}" https://github.com 2>/dev/null')" "$(check_ssh windows_tailscale windows '"C:\Program Files\Tailscale\tailscale.exe" ip -4')" diff --git a/wsl-infra/release-sync.sh b/wsl-infra/release-sync.sh index c60950a..93008ed 100755 --- a/wsl-infra/release-sync.sh +++ b/wsl-infra/release-sync.sh @@ -2,17 +2,16 @@ set -Eeuo pipefail # GitHub is the release source of truth. This worker promotes a published -# release to the local Gitea mirror, then updates Homebrew after the macOS -# arm64 archive and checksums are present in Gitea. +# release assets to the local Gitea mirror. The macOS arm64 archive and +# checksums are promoted first; other assets retry independently. umask 077 STATE_DIR="${SEAL_USE_SYNC_STATE_DIR:-$HOME/.local/state/seal-use-release-sync}" WORK_DIR="${SEAL_USE_SYNC_WORK_DIR:-$STATE_DIR/work}" GITHUB_REPO="${SEAL_USE_GITHUB_REPO:-yunyingk/seal-use}" -HOMEBREW_REPO="${SEAL_USE_HOMEBREW_REPO:-yunyingk/homebrew-tap}" GITEA_BASE="${SEAL_USE_GITEA_BASE:-http://127.0.0.1:3001}" GITEA_REPO="${SEAL_USE_GITEA_REPO:-gitea/seal-use}" -PROXY_URL="${SEAL_USE_PROXY_URL:-http://192.168.3.62:7897}" +PROXY_URL="${SEAL_USE_PROXY_URL:-http://127.0.0.1:7897}" NO_PROXY_LIST="${NO_PROXY:-127.0.0.1,localhost,100.82.151.105,git.ying-qing.cn}" GITHUB_TOKEN_FILE="${SEAL_USE_GITHUB_TOKEN_FILE:-$HOME/.config/seal-use/github-token}" GITEA_TOKEN_FILE="${SEAL_USE_GITEA_TOKEN_FILE:-$HOME/.config/seal-use/gitea-token}" @@ -142,7 +141,7 @@ sync_asset() { fi file="$release_dir/$name" - log "download $name ($size bytes) through mac13 proxy" + log "download $name ($size bytes) through WSL-local mihomo proxy" github_curl -L -H 'Accept: application/octet-stream' "$url" -o "$file" [ "$(wc -c < "$file" | tr -d ' ')" = "$size" ] || die "size mismatch for $name" @@ -165,38 +164,8 @@ sync_asset() { sync_asset "seal-use-darwin-arm64.tar.gz" sync_asset "checksums.txt" -checksums_file="$release_dir/checksums.txt" -if [ ! -s "$checksums_file" ] || ! grep -q 'seal-use-darwin-arm64.tar.gz' "$checksums_file"; then - rm -f "$checksums_file" - asset=$(github_asset "checksums.txt") - github_curl -L -H 'Accept: application/octet-stream' \ - "$(jq -r '.url' <<< "$asset")" -o "$checksums_file" -fi -arm_sha=$(awk '$2 == "seal-use-darwin-arm64.tar.gz" { print $1 }' "$checksums_file") -[ -n "$arm_sha" ] || die "checksums.txt has no macOS arm64 checksum" - -formula_response=$(github_curl -sS -H 'Accept: application/vnd.github+json' \ - "https://api.github.com/repos/$HOMEBREW_REPO/contents/Formula/seal-use.rb?ref=main") -formula_sha=$(jq -r '.sha // empty' <<< "$formula_response") -formula_file="$release_dir/seal-use.rb" -jq -r '.content' <<< "$formula_response" | tr -d '\r\n' | base64 -d > "$formula_file" - -if ! grep -q "version \"${tag#v}\"" "$formula_file" || ! grep -q "sha256 \"$arm_sha\"" "$formula_file"; then - sed -i -E "s/version \"[^\"]+\"/version \"${tag#v}\"/" "$formula_file" - sed -i -E "s/sha256 \"[^\"]+\"/sha256 \"$arm_sha\"/" "$formula_file" - formula_content=$(base64 -w0 "$formula_file") - formula_payload=$(jq -n --arg message "chore(release): bump seal-use to ${tag#v}" \ - --arg content "$formula_content" --arg sha "$formula_sha" \ - '{message:$message,content:$content,sha:$sha,branch:"main"}') - log "update Homebrew tap to ${tag#v} after ARM gate" - github_curl -sS -X PUT -H 'Content-Type: application/json' -d "$formula_payload" \ - "https://api.github.com/repos/$HOMEBREW_REPO/contents/Formula/seal-use.rb" >/dev/null -else - log "Homebrew tap already points to ${tag#v}" -fi - # Remaining archives and raw binaries are retried by the next timer run if -# one upload fails. The Homebrew ARM path is already valid at this point. +# one upload fails. The first archive is already available from Gitea. mirror_failed=0 for name in \ seal-use-darwin-x64.tar.gz seal-use-linux-arm64.tar.gz seal-use-linux-x64.tar.gz seal-use-windows-x64.zip \ @@ -208,7 +177,7 @@ for name in \ done if [ "$mirror_failed" -ne 0 ]; then - log "ARM/Homebrew gate succeeded; some secondary assets will retry" + log "Primary assets synchronized to Gitea; some secondary assets will retry" exit 2 fi -log "release $tag fully synchronized to Gitea and Homebrew" +log "release $tag fully synchronized to Gitea" diff --git a/wsl-infra/systemd/seal-use-release-sync.service b/wsl-infra/systemd/seal-use-release-sync.service index cb84add..257b5de 100644 --- a/wsl-infra/systemd/seal-use-release-sync.service +++ b/wsl-infra/systemd/seal-use-release-sync.service @@ -1,5 +1,5 @@ [Unit] -Description=Promote GitHub releases to Gitea and Homebrew +Description=Promote GitHub releases to Gitea After=network-online.target docker.service mihomo.service Wants=network-online.target Requires=mihomo.service