diff --git a/README.md b/README.md index 7e815a5..b2953ba 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,10 @@ An incoming Hose/合思 `thirdparty.html` assistance link can be imported direct ## Quick Install (Standalone Binary) -No Node.js, Bun, or external runtime required. Run the one-line installer for macOS and Linux: +No Node.js, Bun, or external runtime required. Run the one-line installer: ```bash +# macOS & Linux (Bash) # 国内高速安装(Gitea 镜像源,免代理、秒级完成) curl -fsSL https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.sh | bash @@ -25,13 +26,22 @@ curl -fsSL https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/insta curl -fsSL https://raw.githubusercontent.com/yunyingk/seal-use/main/scripts/install.sh | bash ``` +```powershell +# Windows (PowerShell) +# 国内高速安装(Gitea 镜像源,免代理、秒级完成) +irm https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.ps1 | iex + +# Global / GitHub Direct +irm https://raw.githubusercontent.com/yunyingk/seal-use/main/scripts/install.ps1 | iex +``` + Or download the native binary directly from [GitHub Releases](https://github.com/yunyingk/seal-use/releases/latest) or [Gitea Releases](https://git.ying-qing.cn/gitea/seal-use/releases): - **macOS (Apple Silicon)**: `curl -fsSL https://github.com/yunyingk/seal-use/releases/latest/download/seal-use-darwin-arm64 -o /usr/local/bin/seal-use && chmod +x /usr/local/bin/seal-use` - **macOS (Intel)**: `curl -fsSL https://github.com/yunyingk/seal-use/releases/latest/download/seal-use-darwin-x64 -o /usr/local/bin/seal-use && chmod +x /usr/local/bin/seal-use` - **Linux (x86_64)**: `curl -fsSL https://github.com/yunyingk/seal-use/releases/latest/download/seal-use-linux-x64 -o /usr/local/bin/seal-use && chmod +x /usr/local/bin/seal-use` - **Linux (ARM64)**: `curl -fsSL https://github.com/yunyingk/seal-use/releases/latest/download/seal-use-linux-arm64 -o /usr/local/bin/seal-use && chmod +x /usr/local/bin/seal-use` -- **Windows (x64)**: Download `seal-use-windows-x64.zip` from Releases and extract `seal-use-windows-x64.exe`. +- **Windows (x64)**: One-liner via PowerShell above, or download `seal-use-windows-x64.zip` from Releases and extract `seal-use-windows-x64.exe`. After installation: diff --git a/scripts/README.md b/scripts/README.md index 2109763..db0319e 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -20,7 +20,8 @@ scripts/ ├── bump-version.ts # 多清单版本原子同步(package.json / plugin.json / SKILL.md 等) ├── release.ts # 受控保护分支发布流水线(严格遵循 merge-before-tag) ├── dev-override.ts # 本地开发二进制编译与全局 PATH 覆盖测试 -├── install.sh # 生产级免 sudo 快速安装 Shell 脚本(公开 cURL 入口,不可移动) +├── install.sh # 生产级免 sudo 快速安装 Shell 脚本(macOS / Linux 公开 cURL 入口,不可移动) +├── install.ps1 # 生产级免管理员提权快速安装 PowerShell 脚本(Windows 原生公开 irm 入口) │ ├── generate-cli-md.mjs # 从 CLI 注册表自动生成 references/cli.md ├── check-cli-md.mjs # CLI 文档防漂移校验 @@ -36,6 +37,6 @@ scripts/ 1. **绝对隔离**:`src/` 业务代码不可依赖 `scripts/`。`scripts/` 是外部工具,不是领域服务。 2. **高危受限脚本**: - `release.ts` 与 `bump-version.ts` 具有强版本与 Git 标签推进副作用,**必须且仅能在人类明确发出发布指令时**通过 `bun run release` 调度,任何 Agent 不得擅自调用。 - - `install.sh` 是被公开文档直接通过 `curl .../scripts/install.sh | bash` 引用的外部入口,路径不可擅改。 + - `install.sh` 与 `install.ps1` 是被公开文档直接通过 `curl .../install.sh | bash` 与 `irm .../install.ps1 | iex` 引用的外部安装入口,路径不可擅改。 3. **治理优先**: - 日常执行 `bun test` 会自动回归 `scripts/governance/*.test.ts`,确保治理规则与真实文件不漂移。 diff --git a/scripts/install.ps1 b/scripts/install.ps1 new file mode 100644 index 0000000..bb5ad5a --- /dev/null +++ b/scripts/install.ps1 @@ -0,0 +1,310 @@ +# scripts/install.ps1 - Native Windows PowerShell installer for seal-use CLI. +# Usage: +# irm https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.ps1 | iex +# Or with parameters: +# & ([scriptblock]::Create((irm ...))) -Version 0.11.22 + +[CmdletBinding()] +param( + [string]$Version = "", + [string]$InstallDir = "" +) + +$ErrorActionPreference = "Stop" + +# Enable modern TLS protocols on older PowerShell 5.1 hosts +try { + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 +} catch { + # Ignore if TLS12 is already default or unsupported +} + +Write-Host "==> Detecting Windows platform and architecture..." -ForegroundColor Cyan + +if (-not [System.Environment]::Is64BitOperatingSystem) { + Write-Error "seal-use requires a 64-bit Windows operating system (x64)." + exit 1 +} + +$ARCH_NAME = "x64" +$PLATFORM = "windows" +$REPO = if ($env:SEAL_USE_GITHUB_REPO) { $env:SEAL_USE_GITHUB_REPO } + elseif ($env:SEAL_HOME_GITHUB_REPO) { $env:SEAL_HOME_GITHUB_REPO } + else { "yunyingk/seal-use" } + +$REQ_VERSION = if ($Version) { $Version } + elseif ($env:SEAL_USE_VERSION) { $env:SEAL_USE_VERSION } + elseif ($env:SEAL_HOME_VERSION) { $env:SEAL_HOME_VERSION } + else { "latest" } + +if ($REQ_VERSION -ne "latest" -and -not $REQ_VERSION.StartsWith("v")) { + $REQ_VERSION = "v$REQ_VERSION" +} + +# Resolve target directory without requiring administrator privileges +$TARGET_DIR = if ($InstallDir) { $InstallDir } + elseif ($env:SEAL_USE_INSTALL_DIR) { $env:SEAL_USE_INSTALL_DIR } + elseif ($env:SEAL_HOME_INSTALL_DIR) { $env:SEAL_HOME_INSTALL_DIR } + else { "" } + +if (-not $TARGET_DIR) { + $existing = Get-Command "seal-use" -ErrorAction SilentlyContinue + if ($existing -and $existing.Source -and (Test-Path $existing.Source)) { + $existingDir = Split-Path -Parent $existing.Source + if ($existingDir -notlike "*WindowsApps*" -and (Test-Path $existingDir)) { + $TARGET_DIR = $existingDir + } + } +} + +if (-not $TARGET_DIR) { + $TARGET_DIR = Join-Path $HOME ".local\bin" +} + +if (-not (Test-Path $TARGET_DIR)) { + New-Item -ItemType Directory -Path $TARGET_DIR -Force | Out-Null +} + +$ASSET_NAME = "seal-use-$PLATFORM-$ARCH_NAME.exe" +$ARCHIVE_NAME = "seal-use-$PLATFORM-$ARCH_NAME.zip" +$TARGET_PATH = Join-Path $TARGET_DIR "seal-use.exe" + +function Format-Bytes([long]$bytes) { + if ($bytes -ge 1048576) { + return ("{0:N2} MB ({1:N0} bytes)" -f ($bytes / 1MB), $bytes) + } elseif ($bytes -ge 1024) { + return ("{0:N2} KB ({1:N0} bytes)" -f ($bytes / 1KB), $bytes) + } else { + return ("{0} bytes" -f $bytes) + } +} + +function Extract-Host([string]$url) { + try { + $uri = [System.Uri]$url + return $uri.Host + } catch { + return $url + } +} + +$GITEA_TAG = if ($REQ_VERSION -eq "latest") { "latest" } else { $REQ_VERSION } +$GH_RELEASE_PATH = if ($REQ_VERSION -eq "latest") { "latest/download" } else { $REQ_VERSION } + +$MIRROR_MODE = if ($env:SEAL_USE_MIRROR) { $env:SEAL_USE_MIRROR } + elseif ($env:SEAL_HOME_MIRROR) { $env:SEAL_HOME_MIRROR } + else { "auto" } + +function Get-CandidateUrls([string]$asset) { + $urls = [System.Collections.Generic.List[string]]::new() + if ($MIRROR_MODE -ne "github") { + $urls.Add("https://git.ying-qing.cn/gitea/seal-use/releases/download/$GITEA_TAG/$asset") + $urls.Add("https://git.ying-qing.cn/gitea/seal-home/releases/download/$GITEA_TAG/$asset") + } + if ($MIRROR_MODE -ne "gitea") { + $urls.Add("https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/$asset") + $urls.Add("https://ghfast.top/https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/$asset") + } + return $urls +} + +function Download-Candidate([string]$url, [string]$dest) { + $hostName = Extract-Host $url + Write-Host "==> Downloading from $hostName" -ForegroundColor Cyan + Write-Host " Source Host: $hostName" + Write-Host " Source URL: $url" + + try { + # Test headers and download using Invoke-WebRequest with basic parsing + Invoke-WebRequest -Uri $url -OutFile $dest -UseBasicParsing -TimeoutSec 45 -ErrorAction Stop + if (Test-Path $dest) { + $item = Get-Item $dest + if ($item.Length -gt 1000000) { + Write-Host "✓ Download complete! Total size: $(Format-Bytes $item.Length)" -ForegroundColor Green + Write-Host "✓ Successfully fetched from host: $hostName" -ForegroundColor Green + return $true + } + } + } catch { + Write-Host " ↳ Source unreachable or asset not ready ($($_.Exception.Message)), falling back to next mirror..." -ForegroundColor Yellow + } + + if (Test-Path $dest) { + Remove-Item -Path $dest -Force -ErrorAction SilentlyContinue + } + return $false +} + +function Verify-Checksum([string]$filePath, [string]$assetName) { + $checksumUrls = [System.Collections.Generic.List[string]]::new() + if ($MIRROR_MODE -ne "github") { + $checksumUrls.Add("https://git.ying-qing.cn/gitea/seal-use/releases/download/$GITEA_TAG/checksums.txt") + $checksumUrls.Add("https://git.ying-qing.cn/gitea/seal-home/releases/download/$GITEA_TAG/checksums.txt") + } + if ($MIRROR_MODE -ne "gitea") { + $checksumUrls.Add("https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/checksums.txt") + $checksumUrls.Add("https://ghfast.top/https://github.com/$REPO/releases/download/$GH_RELEASE_PATH/checksums.txt") + } + + $tmpSum = [System.IO.Path]::GetTempFileName() + $checksumFound = $false + + foreach ($cUrl in $checksumUrls) { + try { + Invoke-WebRequest -Uri $cUrl -OutFile $tmpSum -UseBasicParsing -TimeoutSec 15 -ErrorAction Stop + if (Test-Path $tmpSum) { + $checksumFound = $true + break + } + } catch { + continue + } + } + + if ($checksumFound) { + try { + $lines = Get-Content -Path $tmpSum -ErrorAction SilentlyContinue + $expectedHash = "" + foreach ($line in $lines) { + $parts = -split $line.Trim() + if ($parts.Length -ge 2 -and $parts[1] -eq $assetName) { + $expectedHash = $parts[0] + break + } + } + + if ($expectedHash) { + $actualHash = (Get-FileHash -Path $filePath -Algorithm SHA256).Hash.ToLowerInvariant() + if ($actualHash -eq $expectedHash.ToLowerInvariant()) { + Write-Host "✓ Checksum verification passed (SHA-256: $($actualHash.Substring(0, 12))...)" -ForegroundColor Green + } else { + Write-Warning "Checksum mismatch for $assetName! Expected: $expectedHash, got: $actualHash" + } + } + } finally { + Remove-Item -Path $tmpSum -Force -ErrorAction SilentlyContinue + } + } +} + +Write-Host "==> Target install location: $TARGET_PATH" +Write-Host "==> Requested version: $REQ_VERSION" + +$TMP_ZIP = Join-Path ([System.IO.Path]::GetTempPath()) ("seal-use-download-" + [System.Guid]::NewGuid().ToString("N") + ".zip") +$TMP_EXE = Join-Path ([System.IO.Path]::GetTempPath()) ("seal-use-download-" + [System.Guid]::NewGuid().ToString("N") + ".exe") +$TMP_FILE = "" +$DOWNLOAD_SUCCESS = $false +$IS_ARCHIVE = $false +$USED_ASSET = "" + +# Prefer compressed archive (zip) over raw binary: smaller download (~44MB vs ~107MB) +foreach ($url in (Get-CandidateUrls $ARCHIVE_NAME)) { + if (Download-Candidate -url $url -dest $TMP_ZIP) { + $DOWNLOAD_SUCCESS = $true + $IS_ARCHIVE = $true + $USED_ASSET = $ARCHIVE_NAME + $TMP_FILE = $TMP_ZIP + break + } +} + +if (-not $DOWNLOAD_SUCCESS) { + foreach ($url in (Get-CandidateUrls $ASSET_NAME)) { + if (Download-Candidate -url $url -dest $TMP_EXE) { + $DOWNLOAD_SUCCESS = $true + $IS_ARCHIVE = $false + $USED_ASSET = $ASSET_NAME + $TMP_FILE = $TMP_EXE + break + } + } +} + +if (-not $DOWNLOAD_SUCCESS) { + Write-Error "Failed to download $ARCHIVE_NAME or $ASSET_NAME ($REQ_VERSION) from all candidate mirrors." + if (Test-Path $TMP_FILE) { Remove-Item -Path $TMP_FILE -Force -ErrorAction SilentlyContinue } + exit 1 +} + +Verify-Checksum -filePath $TMP_FILE -assetName $USED_ASSET + +if ($IS_ARCHIVE) { + $EXTRACT_DIR = Join-Path ([System.IO.Path]::GetTempPath()) ("seal-use-extract-" + [System.Guid]::NewGuid().ToString("N")) + Write-Host "==> Extracting $USED_ASSET..." -ForegroundColor Cyan + try { + Expand-Archive -Path $TMP_FILE -DestinationPath $EXTRACT_DIR -Force + $extractedExe = Get-ChildItem -Path $EXTRACT_DIR -Filter "*seal-use*.exe" -Recurse | Select-Object -First 1 + if (-not $extractedExe) { + Write-Error "$USED_ASSET did not contain a seal-use binary." + exit 1 + } + + # Handle locked running binary by moving old image first + if (Test-Path $TARGET_PATH) { + $oldPath = "$TARGET_PATH.old.$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())" + try { + Move-Item -Path $TARGET_PATH -Destination $oldPath -Force -ErrorAction SilentlyContinue + } catch { + # Ignore if file is not locked + } + } + + Move-Item -Path $extractedExe.FullName -Destination $TARGET_PATH -Force + } finally { + Remove-Item -Path $EXTRACT_DIR -Recurse -Force -ErrorAction SilentlyContinue + Remove-Item -Path $TMP_FILE -Force -ErrorAction SilentlyContinue + } +} else { + if (Test-Path $TARGET_PATH) { + $oldPath = "$TARGET_PATH.old.$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())" + try { + Move-Item -Path $TARGET_PATH -Destination $oldPath -Force -ErrorAction SilentlyContinue + } catch {} + } + Move-Item -Path $TMP_FILE -Destination $TARGET_PATH -Force +} + +# Ensure TARGET_DIR is in Windows User PATH environment variable +try { + $userPath = [Environment]::GetEnvironmentVariable("Path", "User") + $paths = ($userPath -split ';') | Where-Object { $_ -and $_.Trim() -ne "" } + if ($paths -notcontains $TARGET_DIR) { + $newUserPath = if ([string]::IsNullOrEmpty($userPath)) { $TARGET_DIR } else { "$userPath;$TARGET_DIR" } + [Environment]::SetEnvironmentVariable("Path", $newUserPath, "User") + Write-Host "==> Added $TARGET_DIR to User PATH environment variable." -ForegroundColor Cyan + } +} catch { + Write-Warning "Could not update User PATH environment variable automatically. Please add $TARGET_DIR to your PATH manually." +} + +# Update current session environment PATH +$sessionPaths = ($env:Path -split ';') | Where-Object { $_ -and $_.Trim() -ne "" } +if ($sessionPaths -notcontains $TARGET_DIR) { + $env:Path = "$TARGET_DIR;$env:Path" +} + +# Clean legacy skill to avoid model routing collisions +$LEGACY_SKILL_DIR = Join-Path $HOME ".agents\skills\seal-home" +if (Test-Path $LEGACY_SKILL_DIR) { + Write-Host "==> Removing legacy agent skill at $LEGACY_SKILL_DIR..." -ForegroundColor Cyan + Remove-Item -Path $LEGACY_SKILL_DIR -Recurse -Force -ErrorAction SilentlyContinue +} + +# Initialize agent skill +Write-Host "==> Initializing agent skill to ~/.agents/skills/seal-use..." -ForegroundColor Cyan +try { + & $TARGET_PATH skill install 2>$null | Out-Null + Write-Host "✓ Agent skill installed to ~/.agents/skills/seal-use" -ForegroundColor Green +} catch { + Write-Warning "Could not initialize agent skill automatically. Run 'seal-use skill install' to complete." +} + +Write-Host "" +Write-Host "✨ seal-use successfully installed to $TARGET_PATH!" -ForegroundColor Green +& $TARGET_PATH version +Write-Host "" +Write-Host "Quick start:" +Write-Host " 1. Add enterprise: seal-use corps add-hose-persistent --json '{...}'" +Write-Host " 2. View MCP config: seal-use mcp-config" +Write-Host " 3. Self-update: seal-use update" +Write-Host "" diff --git a/skills/seal-use/SKILL.md b/skills/seal-use/SKILL.md index 46df88c..527db30 100644 --- a/skills/seal-use/SKILL.md +++ b/skills/seal-use/SKILL.md @@ -15,8 +15,10 @@ CLI 是主执行通道。运行 `seal-use help` 获取完整命令清单,使 在执行具体业务前,先通过 `command -v seal-use` 检查 CLI 是否已就绪。若命令未安装或需要升级: ### 1. 一键免环境安装(推荐) -独立预编译原生二进制分发,无需 Node.js 或 Bun 运行环境,自动识别系统架构(macOS Apple Silicon/Intel、Linux x64/arm64): +独立预编译原生二进制分发,无需 Node.js 或 Bun 运行环境,自动识别系统架构(macOS、Linux、Windows x64): + ```bash +# macOS & Linux (Bash) # 国内高速镜像(免代理推荐,秒级完成) curl -fsSL https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.sh | bash @@ -24,6 +26,15 @@ curl -fsSL https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/insta curl -fsSL https://raw.githubusercontent.com/yunyingk/seal-use/main/scripts/install.sh | bash ``` +```powershell +# Windows (PowerShell) +# 国内高速镜像(免代理推荐,秒级完成) +irm https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.ps1 | iex + +# GitHub 直连 +irm https://raw.githubusercontent.com/yunyingk/seal-use/main/scripts/install.ps1 | iex +``` + ### 2. 下载预编译原生二进制 亦可从 Releases 页面直接下载对应平台可执行文件并放入 PATH: - **Gitea Releases(国内高速)**:`https://git.ying-qing.cn/gitea/seal-use/releases`