@ziniao-open/cli 0.1.0-beta.93 → 0.1.0-beta.97

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/README.md CHANGED
@@ -28,7 +28,16 @@ Windows PowerShell 执行:
28
28
  ziniao-cli doctor fix-path
29
29
  ```
30
30
 
31
+ 遍历当前 PATH 并清理正式目录之外的 `ziniao.exe` 文件(默认只预览):
32
+
33
+ ```powershell
34
+ & "$(npm root -g)\@ziniao-open\cli\scripts\remove-ziniao-cli-shims.ps1"
35
+ & "$(npm root -g)\@ziniao-open\cli\scripts\remove-ziniao-cli-shims.ps1" -Apply
36
+ ```
37
+
31
38
  脚本只探测 `ziniao.app` / `ziniao` 的安装目录;Windows 会优先查询卸载注册表中 `DisplayIcon` 包含 `ziniao.exe` 的条目,再从本体目录的 `resources/app.asar.unpacked/envkit/cli` 查找 CLI。Windows 使用 `%APPDATA%\ziniaobrowser\cli`,macOS/Linux 使用 `~/.local/bin`,在目标目录缺少 CLI 或文件内容发生变化时同步最新文件,并注册当前用户 PATH。找不到源文件时只提示并继续,不阻断 PATH 配置。若安装目录无法自动探测,可设置 `ZINIAO_INSTALL_DIR`;若目标位置不同,可设置 `ZINIAO_APP_CACHE_DIR`。
39
+ Windows 同时会把找到的紫鸟本体绝对路径写入 `%APPDATA%\ziniaobrowser\gui-path`,供 CLI 定位桌面客户端。
40
+ macOS/Linux 也会在找到桌面本体时写入对应的 `gui-path`(macOS 为 `~/Library/Application Support/ziniao/gui-path`,Linux 为 `${XDG_CONFIG_HOME:-~/.config}/ziniao/gui-path`)。
32
41
 
33
42
  安装时会自动下载当前平台对应的预编译二进制(支持 macOS / Linux / Windows × amd64 / arm64),并做 SHA-256 校验。
34
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziniao-open/cli",
3
- "version": "0.1.0-beta.93",
3
+ "version": "0.1.0-beta.97",
4
4
  "description": "紫鸟开放平台命令行工具,为开发者和 AI Agent 提供统一的接口调用入口。",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -14,7 +14,8 @@
14
14
  "scripts/install.js",
15
15
  "scripts/run.js",
16
16
  "scripts/setup-ziniao-cli.sh",
17
- "scripts/setup-ziniao-cli.ps1"
17
+ "scripts/setup-ziniao-cli.ps1",
18
+ "scripts/remove-ziniao-cli-shims.ps1"
18
19
  ],
19
20
  "engines": {
20
21
  "node": ">=18"
@@ -0,0 +1,43 @@
1
+ # Find and optionally remove ziniao.exe shims created in PATH directories.
2
+ # Run without -Apply first to preview the files that would be removed.
3
+
4
+ [CmdletBinding(SupportsShouldProcess)]
5
+ param(
6
+ [switch]$Apply
7
+ )
8
+
9
+ $ErrorActionPreference = "Stop"
10
+
11
+ function Write-Log([string]$Message) {
12
+ Write-Output "[ziniao-cli-shims] $Message"
13
+ }
14
+
15
+ $targetDir = Join-Path $env:APPDATA "ziniaobrowser\cli"
16
+ $candidates = @()
17
+ foreach ($pathEntry in @($env:Path -split ";" | Where-Object { $_ })) {
18
+ $directory = $pathEntry.TrimEnd('\')
19
+ if (-not $directory -or $directory -ieq $targetDir.TrimEnd('\')) { continue }
20
+ $shimPath = Join-Path $directory "ziniao.exe"
21
+ if (-not (Test-Path -LiteralPath $shimPath -PathType Leaf)) { continue }
22
+ $candidates += $shimPath
23
+ }
24
+
25
+ if (-not $candidates) {
26
+ Write-Log "No ziniao.exe shims found in PATH directories."
27
+ exit 0
28
+ }
29
+
30
+ foreach ($candidate in ($candidates | Select-Object -Unique)) {
31
+ if (-not $Apply) {
32
+ Write-Log "Would remove: $candidate"
33
+ continue
34
+ }
35
+ if ($PSCmdlet.ShouldProcess($candidate, "Remove CLI shim")) {
36
+ Remove-Item -LiteralPath $candidate -Force
37
+ Write-Log "Removed: $candidate"
38
+ }
39
+ }
40
+
41
+ if (-not $Apply) {
42
+ Write-Log "Preview only. Re-run with -Apply to remove these files."
43
+ }
@@ -26,6 +26,7 @@ $sourceRelative = Join-Path "envkit\cli\win32\$archDir" $sourceName
26
26
  $resourceRoot = "resources\app.asar.unpacked"
27
27
 
28
28
  $sourcePath = $null
29
+ $guiExecutablePath = $null
29
30
  $checkedSourcePaths = @()
30
31
  if ($env:ZINIAO_CLI_SOURCE -and (Test-Path -LiteralPath $env:ZINIAO_CLI_SOURCE -PathType Leaf)) {
31
32
  $sourcePath = $env:ZINIAO_CLI_SOURCE
@@ -54,6 +55,8 @@ if (-not $sourcePath) {
54
55
  } else {
55
56
  continue
56
57
  }
58
+ if (-not (Test-Path -LiteralPath $executablePath -PathType Leaf)) { continue }
59
+ $guiExecutablePath = $executablePath
57
60
  $installDir = Split-Path -Parent $executablePath
58
61
  $candidate = Join-Path $installDir "$resourceRoot\$sourceRelative"
59
62
  $checkedSourcePaths += $candidate
@@ -75,6 +78,32 @@ $targetDir = Join-Path $appCacheDir "cli"
75
78
  $targetPath = Join-Path $targetDir $sourceName
76
79
  New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
77
80
 
81
+ if ($guiExecutablePath) {
82
+ $guiPathFile = Join-Path $env:APPDATA "ziniaobrowser\gui-path"
83
+ try {
84
+ New-Item -ItemType Directory -Path (Split-Path -Parent $guiPathFile) -Force | Out-Null
85
+ [System.IO.File]::WriteAllText(
86
+ $guiPathFile,
87
+ "$guiExecutablePath$([Environment]::NewLine)",
88
+ [System.Text.Encoding]::ASCII
89
+ )
90
+ Write-Log "Wrote GUI path hint: $guiPathFile"
91
+ } catch {
92
+ Write-Log "WARN: Could not write GUI path hint: $($_.Exception.Message)"
93
+ }
94
+ }
95
+
96
+ function Get-FileSha256([string]$Path) {
97
+ $sha256 = [System.Security.Cryptography.SHA256]::Create()
98
+ $stream = [System.IO.File]::OpenRead($Path)
99
+ try {
100
+ return ([BitConverter]::ToString($sha256.ComputeHash($stream))).Replace("-", "")
101
+ } finally {
102
+ $stream.Dispose()
103
+ $sha256.Dispose()
104
+ }
105
+ }
106
+
78
107
  if (-not $sourcePath) {
79
108
  foreach ($checkedPath in ($checkedSourcePaths | Select-Object -Unique)) {
80
109
  Write-Log "Checked CLI source path: $checkedPath"
@@ -87,7 +116,7 @@ if (-not $sourcePath) {
87
116
  } else {
88
117
  $needsCopy = -not (Test-Path -LiteralPath $targetPath -PathType Leaf)
89
118
  if (-not $needsCopy) {
90
- $needsCopy = (Get-FileHash -LiteralPath $sourcePath -Algorithm SHA256).Hash -ne (Get-FileHash -LiteralPath $targetPath -Algorithm SHA256).Hash
119
+ $needsCopy = (Get-FileSha256 $sourcePath) -ne (Get-FileSha256 $targetPath)
91
120
  }
92
121
  if ($needsCopy) {
93
122
  Copy-Item -LiteralPath $sourcePath -Destination $targetPath -Force
@@ -82,6 +82,30 @@ find_source() {
82
82
  return 1
83
83
  }
84
84
 
85
+ find_gui_executable() {
86
+ case "$platform_dir" in
87
+ darwin)
88
+ for candidate in \
89
+ "/Applications/ziniao.app/Contents/MacOS/ziniaobrowser" \
90
+ "/Applications/ziniao.app/Contents/MacOS/ziniao" \
91
+ "$home_dir/Applications/ziniao.app/Contents/MacOS/ziniaobrowser" \
92
+ "$home_dir/Applications/ziniao.app/Contents/MacOS/ziniao"; do
93
+ [ -f "$candidate" ] && { printf '%s\n' "$candidate"; return 0; }
94
+ done
95
+ ;;
96
+ linux)
97
+ for candidate in \
98
+ "/opt/ziniao/ziniaobrowser" \
99
+ "/opt/ziniao/ziniao" \
100
+ "/usr/lib/ziniaobrowser/ziniaobrowser" \
101
+ "/usr/lib/ziniaobrowser/ziniao"; do
102
+ [ -f "$candidate" ] && { printf '%s\n' "$candidate"; return 0; }
103
+ done
104
+ ;;
105
+ esac
106
+ return 1
107
+ }
108
+
85
109
  if [ -n "${ZINIAO_APP_CACHE_DIR:-}" ]; then
86
110
  target_dir="$ZINIAO_APP_CACHE_DIR/cli"
87
111
  else
@@ -90,8 +114,24 @@ else
90
114
  fi
91
115
 
92
116
  source_path="$(find_source || true)"
117
+ gui_executable_path="$(find_gui_executable || true)"
93
118
  target_path="$target_dir/$source_name"
94
119
  mkdir -p "$target_dir"
120
+
121
+ if [ -n "$gui_executable_path" ]; then
122
+ case "$platform_dir" in
123
+ darwin) gui_path_file="$home_dir/Library/Application Support/ziniao/gui-path" ;;
124
+ *)
125
+ xdg_config_home="${XDG_CONFIG_HOME:-$home_dir/.config}"
126
+ gui_path_file="$xdg_config_home/ziniao/gui-path"
127
+ ;;
128
+ esac
129
+ if mkdir -p "$(dirname "$gui_path_file")" && printf '%s\n' "$gui_executable_path" > "$gui_path_file"; then
130
+ log "已写入 GUI 路径提示: $gui_path_file"
131
+ else
132
+ log "WARN: 无法写入 GUI 路径提示: $gui_path_file"
133
+ fi
134
+ fi
95
135
  if [ -z "$source_path" ]; then
96
136
  if [ -f "$target_path" ]; then
97
137
  log "未找到安装目录中的 CLI 源文件,保留现有 AppCache CLI: $target_path"